.. _modules-static_maps: ################################### General-purpose static data mapping ################################### This module drives all data-driven choropleth maps not covered under any of the other Map Center :ref:`modules `. It is designed to display category-based and continuous value-based data for any of the available :ref:`map types `, and it includes a variety of useful :ref:`hooks and overrides ` in order to be more useful for creating variations on these types of maps relatively quickly. This module lives in ``lib/map_center/modules/static_maps.js``, and the current data sets used with it live in ``lib/map_center/modules/static_maps_data/`` by convention. .. _modules-static_maps-operation: ********* Operation ********* A page making use of this module must include one additional JavaScript file containing the data to display. As described above, this file should live in ``lib/map_center/modules/static_maps_data/``. That file should define one global variable, ``nhmcStatic``, with a format described :ref:`below `. Depending on whether the page is intended to show one or multiple data sets, the user may have one or two :ref:`tabs ` available; the one that is always available allows the user to select a specific :ref:`map view `, and the one that is available in the case of multiple data sets allows the user to select a specific data set to view. In either case, the states or counties on the map are colored according to the data provided. The :ref:`sidebar ` in this module shows the meaning of each color used on the map, and the :ref:`tooltips ` for each state or county shows the specific data value that caused that state or county to receive the color it has. .. _modules-static_maps-configuration_options: ********************* Configuration options ********************* There are three major configuration options that exist outside the :ref:`data file itself `, all changeable via global variables: * ``nhmcStaticBreakFormatter`` is a function used for rendering the :ref:`sidebar ` entries for each color shown on the map when the data set shown uses :ref:`continuous values `. It accepts six arguments: * ``thisBreak`` is the break value for this particular sidebar entry. * ``prevBreak`` is either ``null`` or the break value for the sidebar entry before this one. * ``isLastBreak`` lets the formatter function know this is the last break value to be included in the sidebar. * ``breakPrefix`` is a string meant to be displayed before a break value. This often is used for currency signs. * ``breakSuffix`` is a string meant to be displayed after a break value. This often is used for units (points, percent, etc.). * ``breakDecimals`` is an integer requesting that a break value be rounded to a specific number of decimal places; for example, small dollar amounts might have ``breakDecimals`` set to ``2`` to properly show a number of cents. By default, this function renders the sidebar as a list of ranges from one break to the next. This function will execute every time the map view is changed. * ``nhmcStaticFlyouts`` is an object that determines whether :ref:`tooltips ` should be rendered as :ref:`flyouts `. No specific properties need to be defined in this object for flyouts to be enabled; the object just needs to exist. By convention, though, to enable flyouts, the following value is used: .. code-block:: javascript var nhmcStaticFlyouts = { enabled: true }; Other properties that get merged with those provided in this object are: * ``corner`` was intended to be a string value setting a position for the flyout (or ``null`` if flyouts should not be used), but now positioning is entirely handled in CSS, so this option should be considered deprecated. * ``strokeHighlight`` is a hexadecimal color code for the color used to outline the state or county targeted by the tooltip. * ``width`` is a number stating the number of pixels wide to render the flyout. (This was here in order to support certain animations.) Positioning and formatting are entirely handled in CSS now, so this option should be considered deprecated. * ``nhmcStaticTooltipFormatter`` is a function used for rendering the content of the :ref:`tooltips ` corresponding to each state or county on the map. It accepts five arguments: * ``thisFIPS`` is a :ref:`county FIPS code ` if the tooltip should show data for a county or an empty string if it should show data for a state. * ``thisState`` is a full state name for the area for which the tooltip should show data. This is included whether the area is a county or a state (since counties *do* exist within states); therefore, ``nhmcStaticTooltipFormatter`` should check the values of the ``thisFIPS`` and ``thisCounty`` arguments to determine the type of area being touched or hovered over. * ``thisCounty`` is a full county name if the tooltip should show data for a county or an empty string if it should show data for a state. * ``countyOnly`` is a Boolean value that, if true, requests that the tooltip show just the name of the county being touched or hovered over as opposed to the name of the county *and* the name of that county's state (e.g., ``Arlington County`` or ``Arlington County, Virginia`` if ``countyOnly`` is ``true`` or ``false`` respectively). * ``currentData`` is the full data set being displayed (as described in :ref:`modules-static_maps-data_structure` below). This function will execute every time a tooltip is created, but not while that tooltip simply updates its position within the same state or county. One additional configuration option exists: * ``nhmcStaticDataIndex`` is an integer with the same interpretation as the `data_index` parameter in the :ref:`fragment identifier `. It will be ignored if the `data_index` fragment parameter is set. .. _modules-static_maps-data_structure: ************** Data structure ************** Two types of data sets can be displayed in a map using this module: * *Category-based* data sets place states and counties in any of a number of categories and color areas that are in the same category with the same color. * *Continuous value-based* data set assign a value to each state and/or county and color those areas based on which of a number of ranges of values happen to include the areas' values. As described in :ref:`modules-static_maps-operation` above, any page using this module must include a JavaScript file (or ``