Time

Incidents styled with a simple render, visual variables, and clusters to show number of days to close

What are time styles?

Time styles include all visualizations that involve date/time data. You can use these styles to visualize when and where an event occurs. Common examples involve the following:

  1. Timeline
  2. Before and after
  3. Age
  4. Time series filter
  5. Time series animation

How time styles work

The following examples describe how each time style works.

Examples

Timeline

A timeline visualization displays date/time data along a continuous color ramp. It provides an immediate view at when phenomena occured or when a value was recorded relative to all other data points.

The following example visualizes hurricane locations in the Atlantic Ocean recorded in the year 2000. This uses a color visual variable to show which hurricanes occured early in the season versus late in the season.

ArcGIS JS API
46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 47 48 49 50 51 52 53 54 55 56 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />

    <title> ArcGIS Developer Guide: Hurricane location and timeline </title>

    <link rel="stylesheet" href="https://js.arcgis.com/4.18//esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.18//"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

    <script>
      require([
        "esri/config",
        "esri/WebMap",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/widgets/Legend",
        "esri/widgets/Expand"
      ], function (esriConfig,WebMap, MapView, FeatureLayer, Legend, Expand) {

        esriConfig.apiKey = "YOUR-API-KEY";

        const renderer = {
          type: "simple",
          label: "Observed hurricane location",
          symbol: {
            type: "simple-marker",
            size: 6,
            outline: {
              width: 0.5,
              color: [255,255,255,0.5]
            }
          },

          visualVariables: [{
            type: "color",
            field: "Date_Time",
            legendOptions: {
              title: "Date of observation"
            },
            stops: [
              { value: new Date(2000, 7, 3).getTime(), color: "#00ffff"},
              { value: new Date(2000, 9, 22).getTime(), color: "#2f3f56"}
            ]
          }]

        };


        const layer = new FeatureLayer({
          url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/0",
          renderer: renderer
        });

        const map = new WebMap({
          portalItem: {
            id: "9cf503b654144873a8e33f996f91ba1d"
          },
          layers: [ layer ]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          scale: 36978595,
          center: [ -44.0632, 33.1567 ],
          constraints: {
            snapToZoom:false
          }
        });

        view.ui.add(new Expand({
          content: new Legend({
            view: view
          }),
          view: view,
          expanded: true
        }), "top-right");

      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
  </body>
</html>

Before and after

You can use a color visual variable with a diverging color ramp to visualize which events occured before and after a specific date.

The following example visualizes clusters of hurricane locations summarized by whether they occurred before or after January 1, 1977 on average.

ArcGIS JS API
44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 45 46 47 48 49 50 51 52 53 54 55 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />

    <title>ArcGIS Developer Guide: Hurricane locations before or after 1977</title>

    <link rel="stylesheet" href="https://js.arcgis.com/4.18//esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.18//"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

    <script>
      require([
        "esri/config",
        "esri/WebMap",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/widgets/Legend",
        "esri/widgets/Expand"
      ], function (esriConfig,WebMap, MapView, FeatureLayer, Legend, Expand) {

        esriConfig.apiKey = "YOUR-API-KEY";

        const colors = [ "#54bebe", "#dedad2", "#c80064" ];
        const renderer = {
          type: "simple",
          label: "Observed hurricane location",
          symbol: {
            type: "simple-marker",
            size: 4,
            outline: null
          },

          visualVariables: [{
            type: "color",
            field: "ISO_time",
            legendOptions: {
              title: "Before and after July 1"
            },
            stops: [
              { value: new Date(2013, 0, 1).getTime(), color: colors[0], label: "January 1" },
              { value: new Date(2013, 6, 1).getTime(), color: colors[1], label: "July 1" },
              { value: new Date(2013, 11, 31).getTime(), color: colors[2], label: "December 31" }
            ]
          }]

        };


        // ISO_time

        const layer = new FeatureLayer({
          title: "2013 Hurricane season",
          portalItem: {
            id: "f14573e9c5ce4b41aecb199d5723209b"
          },
          renderer: renderer,
          definitionExpression: "Season = 2013"
        });

        const map = new WebMap({
          basemap: {
            portalItem: {
              id: "3967a92f547341e28636a8ac159666a3"
            }
          },
          layers: [ layer ]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          scale: 136195673,
          constraints: {
            snapToZoom: false,
            rotationEnabled: false
          }
        });

        view.ui.add(new Expand({
          content: new Legend({
            view: view
          }),
          view: view,
          expanded: true
        }), "top-right");

      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
  </body>
</html>

Age

An age visualization shows the age of a feature (or the elapsed time up to a meaningful date or the current date) based on a date field. Age visualizations may be applied in the following scenarios:

  1. How long has an asset been in commission?
  2. How old is the incident report?
  3. How long has it been since the last inspection?
  4. Is an incident past due for reslution?

Age is typically defined using the DateDiff function in an Arcade expression and mapped with a color or size variable. It specifies a length of time with desired units.

 
valueExpression = "DateDiff( Now(), $feature.date_created, 'hours' )"

The following example visualizes clustered street condition complaints in New York City based on how much time passed before the incident was closed relative to its due date.

ArcGIS JS API
54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 55 56 57 58 59 60 61 62 63 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />

    <title> ArcGIS Developer Guide: Street condition complaints</title>

    <link rel="stylesheet" href="https://js.arcgis.com/4.18//esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.18//"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

    <script>
      require([
        "esri/config",
        "esri/WebMap",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/widgets/Legend",
        "esri/widgets/Expand",
        "esri/smartMapping/labels/clusters",
        "esri/smartMapping/popup/clusters",
        "esri/core/promiseUtils"
      ], function (esriConfig,WebMap, MapView, FeatureLayer, Legend, Expand,
        clusterLabelCreator,
        clusterPopupCreator,
        promiseUtils
      ) {

        esriConfig.apiKey = "YOUR-API-KEY";

        const colors = [ "#2799ff", "#423a3a", "#ff3333" ];
        const renderer = {
          type: "simple",
          label: "Observed hurricane location",
          symbol: {
            type: "simple-marker",
            size: 6,
            outline: {
              width: 0.5,
              color: [255,255,255,0.5]
            }
          },

          visualVariables: [{
            type: "color",
            valueExpression: "DateDiff($feature['closed_time'], $feature['due_time'], 'days')",
            valueExpressionTitle: "Days it took to close incident",
            stops: [
              { value: -21, color: colors[0], label: "21 weeks early" },
              { value: 0, color: colors[1], label: "On time" },
              { value: 21, color: colors[2], label: "21 weeks late" }
            ]
          }]

        };


        const layer = new FeatureLayer({
          portalItem: {
            id: "f624a9f4afa947fe98acd0ed38fbe436"
          },
          title: "Street condition complaints",
          renderer: renderer,
          definitionExpression: "Complaint_Type = 'Street Condition'"
        });

        const map = new WebMap({
          portalItem: {
            id: "75a3ce8990674a5ebd5b9ab66bdab893"
          },
          layers: [ layer ]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          scale: 144447,
          center: [ -73.863, 40.7 ],
          constraints: {
            snapToZoom:false
          }
        });

        view.ui.add(new Expand({
          content: new Legend({
            view: view
          }),
          view: view,
          expanded: true
        }), "top-right");

        view.when()
          .then(generateClusterConfig)
          .then(function(featureReduction){
            layer.featureReduction = featureReduction;
          });

          function generateClusterConfig() {
          // generates default popupTemplate
          const popupPromise = clusterPopupCreator
            .getTemplates({
              layer: layer
            })
            .then(function (popupTemplateResponse) {
              return popupTemplateResponse.primaryTemplate.value;
            });

          // generates default labelingInfo
          const labelPromise = clusterLabelCreator
            .getLabelSchemes({
              layer: layer,
              view: view
            })
            .then(function (labelSchemes) {
              return labelSchemes.primaryScheme;
            });

          return promiseUtils
            .eachAlways([ popupPromise, labelPromise ])
            .then(function (result) {
              const popupTemplate = result[0].value;

              const primaryLabelScheme = result[1].value;
              const labelingInfo = primaryLabelScheme.labelingInfo;
              // Ensures the clusters are large enough to fit labels
              const clusterMinSize = primaryLabelScheme.clusterMinSize;

              return {
                type: "cluster",
                popupTemplate: popupTemplate,
                labelingInfo: labelingInfo,
                clusterMinSize: clusterMinSize,
                clusterRadius: 50
              };
            })
            .catch(function (error) {
              console.error(error);
            });
        }
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
  </body>
</html>

Time series filter

In most cases, time series animations involve assigning a layer a static renderer and filtering features over time. This is effective for features whose positions occur only at specific moments or windows of time (e.g. earthquakes, hurricanes, airplane travel).

This requires a time slider for control over the time window.

140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />

    <title>ArcGIS Developer Guide: Time series filter</title>

    <link rel="stylesheet" href="https://js.arcgis.com/4.18//esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.18//"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #timeSlider {
        position: absolute;
        left: 100px;
        right: 100px;
        bottom: 30px;
      }
    </style>

    <script>
      require([
        "esri/config",
        "esri/WebMap",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/widgets/Legend",
        "esri/widgets/TimeSlider",
        "esri/widgets/Expand"
      ], function (esriConfig,WebMap, MapView, FeatureLayer, Legend, TimeSlider, Expand) {

        esriConfig.apiKey = "YOUR-API-KEY";

        const year = 2005;


        const renderer = {
          type: "simple",
          label: "Observed hurricane location",
          symbol: {
            type: "picture-marker",
            url: "/documentation/images/demos/cyclone-marker.gif",
            height: 20,
            width: 20
          },
          visualVariables: [{
            type: "size",
            field: "Category",
            stops: [
              { value: 1, size: 12 },
              { value: 2, size: 16 },
              { value: 3, size: 20 },
              { value: 4, size: 24 },
              { value: 5, size: 28 }
            ]
          }]
        };


        const layer = new FeatureLayer({
          title: `${year} Hurricane season`,
          portalItem: {
            id: "f14573e9c5ce4b41aecb199d5723209b"
          },
          renderer: renderer,
          definitionExpression: `Season = ${year}`
        });

        const trackRenderer = {
          type: "simple",
          label: "Previous hurricane location",
          symbol: {
            type: "simple-marker",
            color: "rgba(188,46,28,0.05)",
            size: 4,
            outline: null
          },
          visualVariables: [{
            type: "size",
            field: "Category",
            legendOptions: {
              showLegend: false
            },
            stops: [
              { value: 1, size: 4 },
              { value: 2, size: 8 },
              { value: 3, size: 10 },
              { value: 4, size: 12 },
              { value: 5, size: 18 }
            ]
          }]
        };

        const trackLayer = new FeatureLayer({
          title: `${year} Hurricane season`,
          portalItem: {
            id: "f14573e9c5ce4b41aecb199d5723209b"
          },
          renderer: trackRenderer,
          useViewTime: false,
          definitionExpression: `Season = ${year}`
        });

        const map = new WebMap({
          basemap: {
            portalItem: {
              id: "3967a92f547341e28636a8ac159666a3"
            }
          },
          layers: [ layer, trackLayer ]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          scale: 136195673,
          constraints: {
            snapToZoom: false,
            rotationEnabled: false
          }
        });

        view.ui.add(new Expand({
          content: new Legend({
            view: view
          }),
          view: view,
          expanded: false
        }), "top-right");


        const start = new Date(year-1, 9, 1);
        const end = new Date(year+1, 0, 15);
        const next = new Date(year-1, 9, 1, 7);
        const timeSlider = new TimeSlider({
          container: "timeSlider",
          playRate: 30,
          mode: "time-window",
          fullTimeExtent: {
            start,
            end
          },
          values: [ start, next ],
          stops: {
            interval: {
              value: 6,
              unit: "hours"
            }
          },
          view: view
        });

        view.ui.add(timeSlider, "manual");

        view.whenLayerView(trackLayer).then(function(trackLayerView){
          trackLayerView.filter = {
            timeExtent: {
              start,
              end: timeSlider.values[1]
            }
          };

          timeSlider.watch("values", function(values){
            trackLayerView.filter = {
              timeExtent: {
                start,
                end: values[1]
              }
            }
          });
        });

      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="timeSlider"></div>
  </body>
</html>

The layer in this example is rendered with a simple renderer and an animated gif showing a rotating hurricane symbol. This layer shows the current position of a hurricane relative to the slider thumb positions.

Another layer is added to show the previous positions of the hurricanes relative to the time slider values.

ArcGIS JS API
45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />

    <title>ArcGIS Developer Guide: Time series filter</title>

    <link rel="stylesheet" href="https://js.arcgis.com/4.18//esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.18//"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #timeSlider {
        position: absolute;
        left: 100px;
        right: 100px;
        bottom: 30px;
      }
    </style>

    <script>
      require([
        "esri/config",
        "esri/WebMap",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/widgets/Legend",
        "esri/widgets/TimeSlider",
        "esri/widgets/Expand"
      ], function (esriConfig,WebMap, MapView, FeatureLayer, Legend, TimeSlider, Expand) {

        esriConfig.apiKey = "YOUR-API-KEY";

        const year = 2005;


        const renderer = {
          type: "simple",
          label: "Observed hurricane location",
          symbol: {
            type: "picture-marker",
            url: "/documentation/images/demos/cyclone-marker.gif",
            height: 20,
            width: 20
          },
          visualVariables: [{
            type: "size",
            field: "Category",
            stops: [
              { value: 1, size: 12 },
              { value: 2, size: 16 },
              { value: 3, size: 20 },
              { value: 4, size: 24 },
              { value: 5, size: 28 }
            ]
          }]
        };


        const layer = new FeatureLayer({
          title: `${year} Hurricane season`,
          portalItem: {
            id: "f14573e9c5ce4b41aecb199d5723209b"
          },
          renderer: renderer,
          definitionExpression: `Season = ${year}`
        });

        const trackRenderer = {
          type: "simple",
          label: "Previous hurricane location",
          symbol: {
            type: "simple-marker",
            color: "rgba(188,46,28,0.05)",
            size: 4,
            outline: null
          },
          visualVariables: [{
            type: "size",
            field: "Category",
            legendOptions: {
              showLegend: false
            },
            stops: [
              { value: 1, size: 4 },
              { value: 2, size: 8 },
              { value: 3, size: 10 },
              { value: 4, size: 12 },
              { value: 5, size: 18 }
            ]
          }]
        };

        const trackLayer = new FeatureLayer({
          title: `${year} Hurricane season`,
          portalItem: {
            id: "f14573e9c5ce4b41aecb199d5723209b"
          },
          renderer: trackRenderer,
          useViewTime: false,
          definitionExpression: `Season = ${year}`
        });

        const map = new WebMap({
          basemap: {
            portalItem: {
              id: "3967a92f547341e28636a8ac159666a3"
            }
          },
          layers: [ layer, trackLayer ]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          scale: 136195673,
          constraints: {
            snapToZoom: false,
            rotationEnabled: false
          }
        });

        view.ui.add(new Expand({
          content: new Legend({
            view: view
          }),
          view: view,
          expanded: false
        }), "top-right");


        const start = new Date(year-1, 9, 1);
        const end = new Date(year+1, 0, 15);
        const next = new Date(year-1, 9, 1, 7);
        const timeSlider = new TimeSlider({
          container: "timeSlider",
          playRate: 30,
          mode: "time-window",
          fullTimeExtent: {
            start,
            end
          },
          values: [ start, next ],
          stops: {
            interval: {
              value: 6,
              unit: "hours"
            }
          },
          view: view
        });

        view.ui.add(timeSlider, "manual");

        view.whenLayerView(trackLayer).then(function(trackLayerView){
          trackLayerView.filter = {
            timeExtent: {
              start,
              end: timeSlider.values[1]
            }
          };

          timeSlider.watch("values", function(values){
            trackLayerView.filter = {
              timeExtent: {
                start,
                end: values[1]
              }
            }
          });
        });

      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="timeSlider"></div>
  </body>
</html>

Time series animation

Time series animations are animated visualizations showing how features in a dataset change over time based on location and/or a data attribute's value. These typically invove a time slider so users have the ability to explore moments of time or time windows.

For features that have a static position (such as sensors, buildings, countries, etc.), but that have attributes that vary over time (e.g. population, temperature, windspeed), you can dynamically update the renderer to reference data values tied to a specific moment in time, rather than filter features. This removes the need for downloading duplicate geometries to the client.

The renderer udpates with every slider value change.

288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 288 289 290 291 292 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293 293
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>ArcGIS Developer Guide: Time series animation</title>

    <link rel="stylesheet" href="https://js.arcgis.com/4.18//esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.18//"></script>

    <style>
      #containerDiv {
        padding: 10px;
        text-align: center;
        box-shadow: 0;
      }

      #sliderDiv {
        height: 100px;
      }

      #histogram {
        width: 500px;
        height: 150px;
      }
      .labels {
        padding: 5px;
      }

      html,
      body {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #viewDiv {
        position: absolute;
        right: 0;
        left: 0;
        top: 0;
        bottom: 100px;
      }

      #sliderContainer {
        position: absolute;
        bottom: 0;
        height: 100px;
        width: 100%;
        text-align: center;
      }
    </style>

    <script id="highest-temp-arcade" type="arcgis/arcade">
      var highest = -Infinity;
      var ignoreFields = [ "OBJECTID", "x", "y", "Range" ];
      for (var att in $feature){
        var value = $feature[att];
        if( typeof(value) == 'Number' && IndexOf(ignoreFields, att) == -1){
          highest = IIF(value > highest, value, highest);
        }
      }
      return highest;
    </script>

    <script id="lowest-temp-arcade" type="arcgis/arcade">
      var lowest = Infinity;
      var ignoreFields = [ "OBJECTID", "x", "y", "Range" ];
      for (var att in $feature){
        var value = $feature[att];
        if( typeof(value) == 'Number' && IndexOf(ignoreFields, att) == -1){
          lowest = IIF(value < lowest, value, lowest);
        }
      }
      return lowest;
    </script>

    <script>
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/smartMapping/statistics/histogram",
        "esri/smartMapping/statistics/summaryStatistics",
        "esri/widgets/Histogram",
        "esri/widgets/Slider",
        "esri/widgets/Legend",
        "esri/widgets/Expand",
        "esri/core/watchUtils",
        "esri/Color"
      ], function (
        esriConfig,
        Map,
        MapView,
        FeatureLayer,
        histogram,
        summaryStatistics,
        Histogram,
        Slider,
        Legend,
        Expand,
        watchUtils,
        Color
      ) {

        esriConfig.apiKey = "YOUR-API-KEY";
        // Project base layer (world countries) to Equal Earth projection
        const baseLayer = new FeatureLayer({
          portalItem: {
            id: "2b93b06dc0dc4e809d3c8db5cb96ba69"
          },
          legendEnabled: false,
          popupEnabled: false,
          renderer: {
            type: "simple",
            symbol: {
              type: "simple-fill",
              color: [200, 200, 200, 0.75],
              outline: null
            }
          }
        });

        // Set initial temperature anomaly renderer on layer based
        // on data recorded for the year 1880

        const layer = new FeatureLayer({
          url: "https://services.arcgis.com/jIL9msH9OI208GCb/arcgis/rest/services/Global_Temperatures_1880_to_2018/FeatureServer/0",
          outFields: ["*"],
          title: "Temperatures by location (1880 - 2018)",

          renderer: {
            type: "simple",
            label: "Observation point",
            symbol: {
              type: "simple-marker",
              style: "diamond",
              size: "6px",
              color: [226, 226, 226, 0.75],
              outline: {
                color: [255, 255, 255, 0.25],
                width: "0.75px"
              }
            },

            visualVariables: [
              {
                type: "size",
                valueExpression: getSizeValueExpression(1880),
                valueExpressionTitle: "Absolute Value",
                legendOptions: {
                  showLegend: false
                },
                maxDataValue: 35,
                maxSize: "24px",
                minDataValue: 10,
                minSize: "4px"
              }, {
                type: "color",
                field: getColorField(1880),
                legendOptions: {
                  title: "Temperature Anomaly"
                },
                stops: [
                  {
                    value: -2.5,
                    color: [5, 112, 176, 0.75],
                    label: "Less than -2.5 deg C"
                  },
                  { value: -1, color: [208, 209, 230, 0.75] },
                  { value: -0.5, color: [236, 231, 242, 0.75] },
                  {
                    value: 0,
                    color: [226, 226, 226, 0.75],
                    label: "No difference/No Data"
                  },
                  { value: 0.5, color: [254, 232, 200, 0.75] },
                  { value: 1, color: [253, 212, 158, 0.75] },
                  {
                    value: 2.5,
                    color: [215, 48, 31, 0.75],
                    label: "More than 2.5 deg C"
                  }
                ]
              }
            ]

          },

          popupTemplate: {
            expressionInfos: [
              {
                name: "max",
                title: "Warmest anomaly",
                expression: document.getElementById("highest-temp-arcade")
                  .innerText
              },
              {
                name: "min",
                title: "Coldest anomaly",
                expression: document.getElementById("lowest-temp-arcade")
                  .innerText
              }
            ],
            content: [
              {
                type: "fields",
                fieldInfos: [
                  {
                    fieldName: "expression/max",
                    format: {
                      places: 2
                    }
                  },
                  {
                    fieldName: "expression/min",
                    format: {
                      places: 2
                    }
                  }
                ]
              }
            ]
          }
        });

        const map = new Map({
          layers: [baseLayer, layer]
        });

        const spatialReference = {
          wkid: 54035
        };

        const view = new MapView({
          container: "viewDiv",
          map: map,
          scale: 150000000,
          center: { x: 0, y: 0, spatialReference: spatialReference },
          spatialReference: spatialReference,
          popup: {
            dockOptions: {
              position: "top-left"
            }
          },
          constraints: {
            snapToZoom:false
          }
        });

        view.ui.add(
          new Expand({
            view: view,
            content: document.getElementById("containerDiv"),
            expanded: false,
            expandIconClass: "esri-icon-chart"
          }),
          "top-right"
        );

        // This slider will allow the user to update the renderer based on a
        // provided year between 1880 and 2018

        const slider = new Slider({
          min: 1880,
          max: 2018,
          values: [ 1880 ],
          visibleElements: {
            labels: true,
            rangeLabels: true
          },
          labelInputsEnabled: true,
          precision: 0,
          steps: 1,
          container: "sliderDiv"
        });

        // When the user changes the slider's value,
        // change the renderer and histogram to reflect
        // data corresponding to the year indicated on the slider



        slider.on(["thumb-change", "thumb-drag"], function (event) {
          updateRenderer(event.value);
          updateHistogram(event.value);
          updateYearDisplay(event.value);
        });


        let points = null;
        let lv = null;

        // Query all the features in the layer. These will by used
        // for client-side queries as the user slides the thumb of the slider

        view
          .whenLayerView(layer)
          .then(function (layerView) {
            lv = layerView;
            watchUtils.whenFalseOnce(layerView, "updating", function () {
              return layerView
                .queryFeatures()
                .then(function (response) {
                  points = response.features;
                  const year = slider.values[0];
                  updateRenderer(year, layerView);
                  updateHistogram(year);
                })
                .catch(function (e) {
                  console.error(e);
                });
            });
          })
          .catch(function (e) {
            console.error(e);
          });

        // Updates the underlying data value driving the expression
        // based on the given year provided by the slider


        function updateRenderer(value) {
          const renderer = layer.renderer.clone();
          const sizeVariable = renderer.visualVariables[0];
          const colorVariable = renderer.visualVariables[1];
          sizeVariable.valueExpression = getSizeValueExpression(value);
          colorVariable.field = "F" + value;
          renderer.visualVariables = [sizeVariable, colorVariable];
          layer.renderer = renderer;
        }


        // Generate color visual variable based on the given year


        function getColorField(value) {
          return "F" + value;
        }


        // Generate size visual variable based on the given year
        // This is the same expression as "size-arcade" above, but
        // modifiable for any given year

        function getSizeValueExpression(value) {
          return `
            var AbsTEMP = Abs($feature.F${value});
            var vs = $view.scale;
            var TempSize = when(
              AbsTEMP > 5, 35,
              AbsTEMP > 4, 30,
              AbsTEMP > 2.5, 25,
              AbsTEMP > 1, 20,
              AbsTEMP > 0.5, 15,
              AbsTEMP > 0.01, 12,
              AbsTEMP < 0.01, 10,
              8
            );
            when(
              vs >=37000000, TempSize,
              vs >=18500000, 2 + TempSize,
              vs >=9300000, 4 + TempSize,
              vs >=4700000, 6 + TempSize,
              vs >=2000000, 8 + TempSize,
              10 + TempSize
            );
          `
        }

        let histograms = {};
        let histogramChart = null;
        const histMin = -5;
        const histMax = 5;

        let highlight;

        function getAverage(params) {
          return summaryStatistics(params).then(function (statistics) {
            return statistics.avg;
          });
        }

        function updateHistogram(year) {
          if (histograms[year]) {
            histogramChart.bins = histograms[year];
          }

          // params for generating a histogram using the
          // points available on the client

          const params = {
            layer: layer,
            field: "F" + year,
            view: view,
            features: points,
            numBins: 100,
            minValue: histMin,
            maxValue: histMax
          };

          let average = null;

          getAverage(params)
            .then(function (avg) {
              average = avg;
              return histogram(params);
            })
            .then(function (histogramResult) {
              // cache previously used histograms to improve performance
              histograms[year] = histogramResult.bins;

              if (!histogramChart) {
                histogramChart = new Histogram({
                  container: "histogram",
                  min: histMin,
                  max: histMax,
                  bins: histogramResult.bins,
                  average: average,
                  dataLines: [
                    {
                      value: 0
                    }
                  ],
                  dataLineCreatedFunction: function (element, label, index) {
                    if (index === 0) {
                      element.setAttribute("y2", "75%");
                    }
                  },
                  labelFormatFunction: function (value, type) {
                    return type === "average" ? value.toFixed(2) + "°" : value;
                  },
                  barCreatedFunction: function (index, element) {
                    const bin = histogramChart.bins[index];
                    const midValue =
                      (bin.maxValue - bin.minValue) / 2 + bin.minValue;
                    const color = getColorFromValue(midValue);
                    element.setAttribute("fill", color.toHex());
                    element.addEventListener("focus", function () {
                      const { minValue, maxValue, count } = bin;
                      const query = lv.layer.createQuery();
                      const field = "F" + slider.values[0];
                      query.where = `${field} >= ${minValue} AND ${field} <= ${maxValue}`;
                      lv.queryObjectIds(query).then(function (ids) {
                        if (highlight) {
                          highlight.remove();
                          highlight = null;
                        }
                        highlight = lv.highlight(ids);
                      });
                    });

                    element.addEventListener("blur", function () {
                      if (highlight) {
                        highlight.remove();
                        highlight = null;
                      }
                    });
                  }
                });
              } else {
                histogramChart.bins = histogramResult.bins;
                histogramChart.average = average;
              }
            })
            .catch(function (e) {
              console.error(e);
            });
        }

        // Infers the color of the visual variable based on a given value
        // This is used to render and update histogram bars with colors
        // matching the features in the map
        function getColorFromValue(value) {
          const visualVariable = layer.renderer.visualVariables.filter(
            function (vv) {
              return vv.type === "color";
            }
          )[0];
          const stops = visualVariable.stops;
          let minStop = stops[0];
          let maxStop = stops[stops.length - 1];

          let minStopValue = minStop.value;
          let maxStopValue = maxStop.value;

          if (value < minStopValue) {
            return minStop.color;
          }

          if (value > maxStopValue) {
            return maxStop.color;
          }

          const exactMatches = stops.filter(function (stop) {
            return stop.value === value;
          });

          if (exactMatches.length > 0) {
            return exactMatches[0].color;
          }

          minStop = null;
          maxStop = null;
          stops.forEach(function (stop, i) {
            if (!minStop && !maxStop && stop.value >= value) {
              minStop = stops[i - 1];
              maxStop = stop;
            }
          });

          const weightedPosition =
            (value - minStop.value) / (maxStop.value - minStop.value);

          return Color.blendColors(
            minStop.color,
            maxStop.color,
            weightedPosition
          );
        }

        function updateYearDisplay(year) {
          const yearElement = document.getElementById("yearDiv");
          yearElement.innerText = year;
        }
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="containerDiv" class="esri-widget">
      <div class="esri-widget">
        <div id="title" class="esri-widget">
          <h3>Temperature Anomaly (<span id="yearDiv">1880</span>)</h3>
        </div>
        <div id="histogram" class="esri-widget"></div>
        <div class="labels esri-widget">
          <span style="float: left">-5° C</span>
          <span style="float: center">0° C</span>
          <span style="float: right">+5° C</span>
        </div>
      </div>
    </div>
    <div id="sliderContainer" class="esri-widget">
      <div id="sliderDiv"></div>
    </div>
  </body>
</html>
ArcGIS JS API
327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 328 329 330 331 332 333 334 335 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336 336
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>ArcGIS Developer Guide: Time series animation</title>

    <link rel="stylesheet" href="https://js.arcgis.com/4.18//esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.18//"></script>

    <style>
      #containerDiv {
        padding: 10px;
        text-align: center;
        box-shadow: 0;
      }

      #sliderDiv {
        height: 100px;
      }

      #histogram {
        width: 500px;
        height: 150px;
      }
      .labels {
        padding: 5px;
      }

      html,
      body {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #viewDiv {
        position: absolute;
        right: 0;
        left: 0;
        top: 0;
        bottom: 100px;
      }

      #sliderContainer {
        position: absolute;
        bottom: 0;
        height: 100px;
        width: 100%;
        text-align: center;
      }
    </style>

    <script id="highest-temp-arcade" type="arcgis/arcade">
      var highest = -Infinity;
      var ignoreFields = [ "OBJECTID", "x", "y", "Range" ];
      for (var att in $feature){
        var value = $feature[att];
        if( typeof(value) == 'Number' && IndexOf(ignoreFields, att) == -1){
          highest = IIF(value > highest, value, highest);
        }
      }
      return highest;
    </script>

    <script id="lowest-temp-arcade" type="arcgis/arcade">
      var lowest = Infinity;
      var ignoreFields = [ "OBJECTID", "x", "y", "Range" ];
      for (var att in $feature){
        var value = $feature[att];
        if( typeof(value) == 'Number' && IndexOf(ignoreFields, att) == -1){
          lowest = IIF(value < lowest, value, lowest);
        }
      }
      return lowest;
    </script>

    <script>
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/smartMapping/statistics/histogram",
        "esri/smartMapping/statistics/summaryStatistics",
        "esri/widgets/Histogram",
        "esri/widgets/Slider",
        "esri/widgets/Legend",
        "esri/widgets/Expand",
        "esri/core/watchUtils",
        "esri/Color"
      ], function (
        esriConfig,
        Map,
        MapView,
        FeatureLayer,
        histogram,
        summaryStatistics,
        Histogram,
        Slider,
        Legend,
        Expand,
        watchUtils,
        Color
      ) {

        esriConfig.apiKey = "YOUR-API-KEY";
        // Project base layer (world countries) to Equal Earth projection
        const baseLayer = new FeatureLayer({
          portalItem: {
            id: "2b93b06dc0dc4e809d3c8db5cb96ba69"
          },
          legendEnabled: false,
          popupEnabled: false,
          renderer: {
            type: "simple",
            symbol: {
              type: "simple-fill",
              color: [200, 200, 200, 0.75],
              outline: null
            }
          }
        });

        // Set initial temperature anomaly renderer on layer based
        // on data recorded for the year 1880

        const layer = new FeatureLayer({
          url: "https://services.arcgis.com/jIL9msH9OI208GCb/arcgis/rest/services/Global_Temperatures_1880_to_2018/FeatureServer/0",
          outFields: ["*"],
          title: "Temperatures by location (1880 - 2018)",

          renderer: {
            type: "simple",
            label: "Observation point",
            symbol: {
              type: "simple-marker",
              style: "diamond",
              size: "6px",
              color: [226, 226, 226, 0.75],
              outline: {
                color: [255, 255, 255, 0.25],
                width: "0.75px"
              }
            },

            visualVariables: [
              {
                type: "size",
                valueExpression: getSizeValueExpression(1880),
                valueExpressionTitle: "Absolute Value",
                legendOptions: {
                  showLegend: false
                },
                maxDataValue: 35,
                maxSize: "24px",
                minDataValue: 10,
                minSize: "4px"
              }, {
                type: "color",
                field: getColorField(1880),
                legendOptions: {
                  title: "Temperature Anomaly"
                },
                stops: [
                  {
                    value: -2.5,
                    color: [5, 112, 176, 0.75],
                    label: "Less than -2.5 deg C"
                  },
                  { value: -1, color: [208, 209, 230, 0.75] },
                  { value: -0.5, color: [236, 231, 242, 0.75] },
                  {
                    value: 0,
                    color: [226, 226, 226, 0.75],
                    label: "No difference/No Data"
                  },
                  { value: 0.5, color: [254, 232, 200, 0.75] },
                  { value: 1, color: [253, 212, 158, 0.75] },
                  {
                    value: 2.5,
                    color: [215, 48, 31, 0.75],
                    label: "More than 2.5 deg C"
                  }
                ]
              }
            ]

          },

          popupTemplate: {
            expressionInfos: [
              {
                name: "max",
                title: "Warmest anomaly",
                expression: document.getElementById("highest-temp-arcade")
                  .innerText
              },
              {
                name: "min",
                title: "Coldest anomaly",
                expression: document.getElementById("lowest-temp-arcade")
                  .innerText
              }
            ],
            content: [
              {
                type: "fields",
                fieldInfos: [
                  {
                    fieldName: "expression/max",
                    format: {
                      places: 2
                    }
                  },
                  {
                    fieldName: "expression/min",
                    format: {
                      places: 2
                    }
                  }
                ]
              }
            ]
          }
        });

        const map = new Map({
          layers: [baseLayer, layer]
        });

        const spatialReference = {
          wkid: 54035
        };

        const view = new MapView({
          container: "viewDiv",
          map: map,
          scale: 150000000,
          center: { x: 0, y: 0, spatialReference: spatialReference },
          spatialReference: spatialReference,
          popup: {
            dockOptions: {
              position: "top-left"
            }
          },
          constraints: {
            snapToZoom:false
          }
        });

        view.ui.add(
          new Expand({
            view: view,
            content: document.getElementById("containerDiv"),
            expanded: false,
            expandIconClass: "esri-icon-chart"
          }),
          "top-right"
        );

        // This slider will allow the user to update the renderer based on a
        // provided year between 1880 and 2018

        const slider = new Slider({
          min: 1880,
          max: 2018,
          values: [ 1880 ],
          visibleElements: {
            labels: true,
            rangeLabels: true
          },
          labelInputsEnabled: true,
          precision: 0,
          steps: 1,
          container: "sliderDiv"
        });

        // When the user changes the slider's value,
        // change the renderer and histogram to reflect
        // data corresponding to the year indicated on the slider



        slider.on(["thumb-change", "thumb-drag"], function (event) {
          updateRenderer(event.value);
          updateHistogram(event.value);
          updateYearDisplay(event.value);
        });


        let points = null;
        let lv = null;

        // Query all the features in the layer. These will by used
        // for client-side queries as the user slides the thumb of the slider

        view
          .whenLayerView(layer)
          .then(function (layerView) {
            lv = layerView;
            watchUtils.whenFalseOnce(layerView, "updating", function () {
              return layerView
                .queryFeatures()
                .then(function (response) {
                  points = response.features;
                  const year = slider.values[0];
                  updateRenderer(year, layerView);
                  updateHistogram(year);
                })
                .catch(function (e) {
                  console.error(e);
                });
            });
          })
          .catch(function (e) {
            console.error(e);
          });

        // Updates the underlying data value driving the expression
        // based on the given year provided by the slider


        function updateRenderer(value) {
          const renderer = layer.renderer.clone();
          const sizeVariable = renderer.visualVariables[0];
          const colorVariable = renderer.visualVariables[1];
          sizeVariable.valueExpression = getSizeValueExpression(value);
          colorVariable.field = "F" + value;
          renderer.visualVariables = [sizeVariable, colorVariable];
          layer.renderer = renderer;
        }


        // Generate color visual variable based on the given year


        function getColorField(value) {
          return "F" + value;
        }


        // Generate size visual variable based on the given year
        // This is the same expression as "size-arcade" above, but
        // modifiable for any given year

        function getSizeValueExpression(value) {
          return `
            var AbsTEMP = Abs($feature.F${value});
            var vs = $view.scale;
            var TempSize = when(
              AbsTEMP > 5, 35,
              AbsTEMP > 4, 30,
              AbsTEMP > 2.5, 25,
              AbsTEMP > 1, 20,
              AbsTEMP > 0.5, 15,
              AbsTEMP > 0.01, 12,
              AbsTEMP < 0.01, 10,
              8
            );
            when(
              vs >=37000000, TempSize,
              vs >=18500000, 2 + TempSize,
              vs >=9300000, 4 + TempSize,
              vs >=4700000, 6 + TempSize,
              vs >=2000000, 8 + TempSize,
              10 + TempSize
            );
          `
        }

        let histograms = {};
        let histogramChart = null;
        const histMin = -5;
        const histMax = 5;

        let highlight;

        function getAverage(params) {
          return summaryStatistics(params).then(function (statistics) {
            return statistics.avg;
          });
        }

        function updateHistogram(year) {
          if (histograms[year]) {
            histogramChart.bins = histograms[year];
          }

          // params for generating a histogram using the
          // points available on the client

          const params = {
            layer: layer,
            field: "F" + year,
            view: view,
            features: points,
            numBins: 100,
            minValue: histMin,
            maxValue: histMax
          };

          let average = null;

          getAverage(params)
            .then(function (avg) {
              average = avg;
              return histogram(params);
            })
            .then(function (histogramResult) {
              // cache previously used histograms to improve performance
              histograms[year] = histogramResult.bins;

              if (!histogramChart) {
                histogramChart = new Histogram({
                  container: "histogram",
                  min: histMin,
                  max: histMax,
                  bins: histogramResult.bins,
                  average: average,
                  dataLines: [
                    {
                      value: 0
                    }
                  ],
                  dataLineCreatedFunction: function (element, label, index) {
                    if (index === 0) {
                      element.setAttribute("y2", "75%");
                    }
                  },
                  labelFormatFunction: function (value, type) {
                    return type === "average" ? value.toFixed(2) + "°" : value;
                  },
                  barCreatedFunction: function (index, element) {
                    const bin = histogramChart.bins[index];
                    const midValue =
                      (bin.maxValue - bin.minValue) / 2 + bin.minValue;
                    const color = getColorFromValue(midValue);
                    element.setAttribute("fill", color.toHex());
                    element.addEventListener("focus", function () {
                      const { minValue, maxValue, count } = bin;
                      const query = lv.layer.createQuery();
                      const field = "F" + slider.values[0];
                      query.where = `${field} >= ${minValue} AND ${field} <= ${maxValue}`;
                      lv.queryObjectIds(query).then(function (ids) {
                        if (highlight) {
                          highlight.remove();
                          highlight = null;
                        }
                        highlight = lv.highlight(ids);
                      });
                    });

                    element.addEventListener("blur", function () {
                      if (highlight) {
                        highlight.remove();
                        highlight = null;
                      }
                    });
                  }