HistogramRangeSlider

AMD: require(["esri/widgets/HistogramRangeSlider"], (HistogramRangeSlider) => { /* code goes here */ });
ESM: import HistogramRangeSlider from "@arcgis/core/widgets/HistogramRangeSlider.js";
Class: esri/widgets/HistogramRangeSlider
Inheritance: HistogramRangeSlider→Widget→Accessor
Since: ArcGIS Maps SDK for JavaScript 4.12

A slider widget that can be used for filtering data or gathering numeric input from a user for a range of data. When bins are provided, a histogram will render on the slider showing where data is distributed along the range. Use the rangeType property to indicate how the histogram should be styled as the user interacts with slider handles.

See the image below for a summary of the configurable options available on this slider.

HistogramRangeSlider with annotations

At a minimum, the slider's container or parent container must have a width set in css for it to render.

For information about gaining full control of widget styles, see the Styling topic.
See also

Constructors

HistogramRangeSlider

Constructor
new HistogramRangeSlider(properties)
Parameter
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Example
// Typical usage
const slider = new HistogramRangeSlider({
  container: "sliderDiv",
  min: 0,
  max: 100,
  values: [ 50, 150 ]
});

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
Show inherited properties Hide inherited properties
Name Type Summary Class

The statistical average of the data in the histogram.

HistogramRangeSlider

Function for styling bars representing histogram bins.

HistogramRangeSlider

An array of objects representing each bin in the histogram.

HistogramRangeSlider

The ID or node representing the DOM element containing the widget.

Widget

Function that fires each time a data line is created.

HistogramRangeSlider

When set, renders lines on the histogram that indicate important or meaningful values to the end user.

HistogramRangeSlider

The name of the class.

Accessor

Sets the color of the histogram bars that are excluded based on the specified rangeType.

HistogramRangeSlider

Icon displayed in the widget's button.

HistogramRangeSlider

The unique ID assigned to the widget when the widget is created.

Widget

Sets the color of the histogram bars that are included in the specified rangeType.

HistogramRangeSlider

The widget's default label.

HistogramRangeSlider

A function used to format labels.

HistogramRangeSlider

The maximum value or upper bound of the slider.

HistogramRangeSlider

The minimum value or lower bound of the slider.

HistogramRangeSlider

Defines how slider thumb values should be rounded.

HistogramRangeSlider

Indicates how the histogram bins should be rendered as the user slides the thumbs.

HistogramRangeSlider

Indicates the standard deviation of the dataset.

HistogramRangeSlider

Indicates the number of standard deviation lines to render on the histogram from the [average].

HistogramRangeSlider

An array of either one or two numbers representing thumb positions on the slider.

HistogramRangeSlider

The view model for the widget.

HistogramRangeSlider

Indicates whether the widget is visible.

Widget

Property Details

average

Property
average Number

The statistical average of the data in the histogram. You would typically get this value from the avg property of SummaryStatisticsResult, which is the result of the summaryStatistics function.

When set, this value will render on the histogram with a line and an average symbol.

Examples
// sets result returned from a smart mapping method
// to the histogram
slider.average = response.statistics.avg;
slider.average = 34.5;

barCreatedFunction

Property
barCreatedFunction BarCreatedFunction

Function for styling bars representing histogram bins. This can be used to color bins with the same color of features in the view that fall into bins representing the same range of data.

Example
slider.barCreatedFunction = function(index, element){
  const bin = slider.bins[index];
  element.addEventListener("focus", function(){
    layerView.filter = {
      where: `POPULATION >= ${bin.minValue} AND POPULATION < ${bin.maxValue}`
    };
  });
  element.addEventListener("blur", function(){
    layerView.filter = null;
  });
};

bins

Property
bins Bin[]

An array of objects representing each bin in the histogram. This information is typically returned from the histogram function.

Examples
// sets the bins of the histogram from the bins in the histogram() result
histogram.bins = histogramResult.bins;
// Creates a histogram with 7 bins.
histogram.bins = [
  { minValue: 0, maxValue: 10, count: 4 },
  { minValue: 10.1, maxValue: 20, count: 14 },
  { minValue: 20.1, maxValue: 30, count: 9 },
  { minValue: 30.1, maxValue: 40, count: 34 },
  { minValue: 40.1, maxValue: 50, count: 351 },
  { minValue: 50.1, maxValue: 60, count: 100 },
  { minValue: 60.1, maxValue: 70, count: 1 }
];

container

Inherited
Property
container String |HTMLElement
Inherited from Widget

The ID or node representing the DOM element containing the widget. This property can only be set once. The following examples are all valid use case when working with widgets.

Examples
// Create the HTML div element programmatically at runtime and set to the widget's container
const basemapGallery = new BasemapGallery({
  view: view,
  container: document.createElement("div")
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});
// Specify an already-defined HTML div element in the widget's container

const basemapGallery = new BasemapGallery({
  view: view,
  container: basemapGalleryDiv
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});

// HTML markup
<body>
  <div id="viewDiv"></div>
  <div id="basemapGalleryDiv"></div>
</body>
// Specify the widget while adding to the view's UI
const basemapGallery = new BasemapGallery({
  view: view
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});

dataLineCreatedFunction

Property
dataLineCreatedFunction DataLineCreatedFunction

Function that fires each time a data line is created. You can use this to style individual dataLines on the data axis.

Example
histogram.dataLineCreatedFunction = function (lineElement, labelElement) {
  lineElement.setAttribute("y2", "25%");
  lineElement.classList.add("line-style");
};

dataLines

Property
dataLines Object[]

When set, renders lines on the histogram that indicate important or meaningful values to the end user.

Properties
value Number

The value on the data axis of the histogram where a line will be rendered.

label String|Number
optional

The label associated with the line.

Examples
// will render lines at the 25th, 50th, 75th, and 99th percentiles
histogram.dataLines = [{
  value: 30,
  label: "25 pctl"
}, {
  value: 45,
  label: "50 pctl"
}, {
  value: 65,
  label: "75 pctl"
}, {
  value: 89,
  label: "99 pctl"
}];
// calculate standard deviations from mean using stats
// returned from smart mapping statistic methods
const stddevs = smartMappingUtils.getDeviationValues(stats.stddev, stats.avg, 2);
histogram.dataLines = stddevs.map(function(stddev){
  return {
    value: stddev
  };
});

declaredClass

Inherited
Property
declaredClass Stringreadonly
Inherited from Accessor

The name of the class. The declared class name is formatted as esri.folder.className.

excludedBarColor

Property
excludedBarColor Colorautocast
Autocasts from Number[]|String|Object

Sets the color of the histogram bars that are excluded based on the specified rangeType. For example, when a rangeType of between is used, all bars not between the slider thumbs will be rendered with the color set here.

To change the style of histogram bars representing included data based on the rangeType, use the includedBarColor property.

Default Value:"#d7e5f0"
See also
Example
slider.excludedBarColor = "black";

icon

Property
icon String
Since: ArcGIS Maps SDK for JavaScript 4.27 HistogramRangeSlider since 4.12, icon added at 4.27.

Icon displayed in the widget's button.

Default Value:"arrow-double-horizontal"
See also

id

Inherited
Property
id String
Inherited from Widget

The unique ID assigned to the widget when the widget is created. If not set by the developer, it will default to the container ID, or if that is not present then it will be automatically generated.

includedBarColor

Property
includedBarColor Colorautocast
Autocasts from Number[]|String|Object

Sets the color of the histogram bars that are included in the specified rangeType. For example, when a rangeType of between is used, all bars between the slider thumbs will be rendered with the color set here.

To change the style of histogram bars representing excluded data based on the rangeType, use the excludedBarColor property.

Default Value:"#599dd4"
See also
Example
slider.includedBarColor = "green";

label

Property
label String

The widget's default label. This label displays when it is used within another widget, such as the Expand or LayerList widgets.

labelFormatFunction

Property
labelFormatFunction LabelFormatter

A function used to format labels. Overrides the default label formatter.

By default labels are formatted in the following way:

  • When the data range is less than 10 ((max - min) < 10), labels are rounded based on the value set in the precision property.
  • When the data range is larger than 10, labels display with a precision of no more than two decimal places, though actual slider thumb values will maintain the precision specified in precision.

Use this property to override the behavior defined above.

Examples
// For thumb values, rounds each label to whole numbers.
// Note the actual value of the thumb continues to be stored
// based on the indicated data `precision` despite this formatting
slider.labelFormatFunction = function(value, type) {
  return (type === "value") ? value.toFixed(0) : value;
}
// Format thumb values as dates
slider.labelFormatFunction = function(value, type) {
  return new Date(value).toLocaleDateString();
}

max

Property
max Number

The maximum value or upper bound of the slider. If the largest slider value in the constructor is greater than the maxValue set in this property, then the maxValue will update to match the largest slider value.

Example
slider.max = 150;

min

Property
min Number

The minimum value or lower bound of the slider. If the smallest slider value in the constructor is greater than the minValue set in this property, then the minValue will update to match the smallest slider value.

Example
slider.min = -150;

precision

Property
precision Number

Defines how slider thumb values should be rounded. This number indicates the number of decimal places slider thumb values should round to when they have been moved.

This value also indicates the precision of thumb labels when the data range (max - min) is less than 10.

When the data range is larger than 10, labels display with a precision of no more than two decimal places, though actual slider thumb values will maintain the precision specified in this property.

For example, given the default precision of 4, and the following slider configuration, The label of the thumb will display two decimal places, but the precision of the actual thumb value will not be lost even when the user slides or moves the thumb.

const slider = new HistogramRangeSliderViewModel({
  min: 20,
  max: 100,  // data range of 80
  values: [50.4331],
  // thumb label will display 50.43
  // thumb value will maintain precision, so
  // value will remain at 50.4331
});

If the user manually enters a value that has a higher precision than what's indicated by this property, the precision of that thumb value will be maintained until the thumb is moved by the user. At that point, the value will be rounded according to the indicated precision.

Keep in mind this property rounds thumb values and shouldn't be used exclusively for formatting purposes. To format thumb labels, use the labelFormatFunction property.

Default Value:4
Example
histogramRangeSlider.precision = 7;

rangeType

Property
rangeType String

Indicates how the histogram bins should be rendered as the user slides the thumbs. By default, blue bars indicate data bins included in the range. Gray bars indicate data bins excluded from the range. These colors can be customized with the includedBarColor and excludedBarColor properties.

This property also determines the SQL where clause generated in generateWhereClause() for filtering purposes. The value set here determines the number of values allowed on the slider.

See the table below for a description and requirements of all possible values. value1 refers to the value of the first thumb position. value2 refers to the value of the final thumb position, if applicable.

Possible Value Number of Values Where clause
equal 1 ${field} = ${value1}
not-equal 1 ${field} <> ${value1}
less-than 1 ${field} < ${value1}
greater-than 1 ${field} > ${value1}
at-most 1 ${field} <= ${value1}
at-least 1 ${field} >= ${value1}
between 2 ${field} BETWEEN ${value1} AND ${value2}
not-between 2 ${field} NOT BETWEEN ${value1} AND ${value2}

Possible Values:"equal" |"not-equal" |"less-than" |"greater-than" |"at-most" |"at-least" |"between" |"not-between"

Example
// renders the histogram so that all bins between
// the two handles are shaded with a blue color
slider.rangeType = "between";

// filters the layer view based on the configuration
// of the slider
layerView.filter = {
  where: slider.generateWhereClause("POPULATION")
}

standardDeviation

Property
standardDeviation Number

Indicates the standard deviation of the dataset. When set, computed dataLines will render on the histogram at the location of the given standard deviation above and below the average.

Example
// stddev returned from summaryStatistics
slider.standardDeviation = stats.stddev;

standardDeviationCount

Property
standardDeviationCount Number

Indicates the number of standard deviation lines to render on the histogram from the [average].

Default Value:1
Example
slider.standardDeviationCount = 2;

values

Property
values Number[]

An array of either one or two numbers representing thumb positions on the slider. The number of values that should be indicated here depends on the associated rangeType.

See also
Example
const slider = new HistogramRangeSlider({
  min: 20,
  max: 100,  // data range of 80
  values: [50.4331],
  rangeType: "at-least"
  container: "sliderDiv"
});

viewModel

Property
viewModel HistogramRangeSliderViewModel

The view model for the widget. This is a class that contains all the logic (properties and methods) that controls this widget's behavior. See the esri/widgets/HistogramRangeSlider/HistogramRangeSliderViewModel class to access all properties and methods on the Slider widget.

visible

Inherited
Property
visible Boolean
Inherited from Widget

Indicates whether the widget is visible.

If false, the widget will no longer be rendered in the web document. This may affect the layout of other elements or widgets in the document. For example, if this widget is the first of three widgets associated to the upper right hand corner of the view UI, then the other widgets will reposition when this widget is made invisible. For more information, refer to the css display value of "none".

Default Value:true
Example
// Hides the widget in the view
widget.visible = false;

Method Overview

Show inherited methods Hide inherited methods
Name Return Type Summary Class

Adds one or more handles which are to be tied to the lifecycle of the object.

Accessor

A utility method used for building the value for a widget's class property.

Widget

Destroys the widget instance.

Widget

Emits an event on the instance.

Widget

Generates a SQL where clause based on a given field and the slider's rangeType.

HistogramRangeSlider

Indicates whether there is an event listener on the instance that matches the provided event name.

Widget

Returns true if a named group of handles exist.

Accessor

isFulfilled() may be used to verify if creating an instance of the class is fulfilled (either resolved or rejected).

Widget

isRejected() may be used to verify if creating an instance of the class is rejected.

Widget

isResolved() may be used to verify if creating an instance of the class is resolved.

Widget

Registers an event handler on the instance.

Widget

Adds one or more handles which are to be tied to the lifecycle of the widget.

Widget

Executes after widget is ready for rendering.

Widget

Removes a group of handles owned by the object.

Accessor

This method is implemented by subclasses for rendering.

Widget

Renders widget to the DOM immediately.

Widget

Schedules widget rendering.

Widget
Promise

when() may be leveraged once an instance of the class is created.

Widget

Method Details

addHandles

Inherited
Method
addHandles(handleOrHandles, groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, addHandles added at 4.25.

Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.

// Manually manage handles
const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true }
);

this.addHandles(handle);

// Destroy the object
this.destroy();
Parameters
handleOrHandles WatchHandle|WatchHandle[]

Handles marked for removal once the object is destroyed.

groupKey *
optional

Key identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.

classes

Inherited
Method
classes(classNames){String}
Inherited from Widget

A utility method used for building the value for a widget's class property. This aids in simplifying css class setup.

Parameter
classNames String|String[]|Object
repeatable

The class names.

Returns
Type Description
String The computed class name.
Example
// .tsx syntax showing how to set css classes while rendering the widget

render() {
  const dynamicClasses = {
    [css.flip]: this.flip,
    [css.primary]: this.primary
  };

  return (
    <div class={classes(css.root, css.mixin, dynamicClasses)} />
  );
}

destroy

Inherited
Method
destroy()
Inherited from Widget

Destroys the widget instance.

emit

Inherited
Method
emit(type, event){Boolean}
Inherited from Widget

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters
type String

The name of the event.

event Object
optional

The event payload.

Returns
Type Description
Boolean true if a listener was notified

generateWhereClause

Method
generateWhereClause(field){String}

Generates a SQL where clause based on a given field and the slider's rangeType. This is a convenience function for data filtering or data queries.

Parameter
field String

Name of the field used in the where clause. This field should correspond to the data used to generate the histogram associated with the slider.

Returns
Type Description
String The SQL where clause to apply to a filter or query.
Example
// renders the histogram so that all bins between
// the two handles are shaded with a blue color by default
slider.rangeType = "between";

// filters the layerview based on the configuration
// of the slider
layerView.filter = {
  where: slider.generateWhereClause("POPULATION")
}

hasEventListener

Inherited
Method
hasEventListener(type){Boolean}
Inherited from Widget

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameter
type String

The name of the event.

Returns
Type Description
Boolean Returns true if the class supports the input event.

hasHandles

Inherited
Method
hasHandles(groupKey){Boolean}
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, hasHandles added at 4.25.

Returns true if a named group of handles exist.

Parameter
groupKey *
optional

A group key.

Returns
Type Description
Boolean Returns true if a named group of handles exist.
Example
// Remove a named group of handles if they exist.
if (obj.hasHandles("watch-view-updates")) {
  obj.removeHandles("watch-view-updates");
}

isFulfilled

Inherited
Method
isFulfilled(){Boolean}
Inherited from Widget
Since: ArcGIS Maps SDK for JavaScript 4.19 Widget since 4.2, isFulfilled added at 4.19.

isFulfilled() may be used to verify if creating an instance of the class is fulfilled (either resolved or rejected). If it is fulfilled, true will be returned.

Returns
Type Description
Boolean Indicates whether creating an instance of the class has been fulfilled (either resolved or rejected).

isRejected

Inherited
Method
isRejected(){Boolean}
Inherited from Widget
Since: ArcGIS Maps SDK for JavaScript 4.19 Widget since 4.2, isRejected added at 4.19.

isRejected() may be used to verify if creating an instance of the class is rejected. If it is rejected, true will be returned.

Returns
Type Description
Boolean Indicates whether creating an instance of the class has been rejected.

isResolved

Inherited
Method
isResolved(){Boolean}
Inherited from Widget
Since: ArcGIS Maps SDK for JavaScript 4.19 Widget since 4.2, isResolved added at 4.19.

isResolved() may be used to verify if creating an instance of the class is resolved. If it is resolved, true will be returned.

Returns
Type Description
Boolean Indicates whether creating an instance of the class has been resolved.

on

Inherited
Method
on(type, listener){Object}
Inherited from Widget

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters

An event or an array of events to listen for.

listener Function

The function to call when the event fires.

Returns
Type Description
Object Returns an event handler with a remove() method that should be called to stop listening for the event(s).
Property Type Description
remove Function When called, removes the listener from the event.
Example
view.on("click", function(event){
  // event is the event handle returned after the event fires.
  console.log(event.mapPoint);
});

own

Inherited
Method
own(handleOrHandles)
Inherited from Widget
Since: ArcGIS Maps SDK for JavaScript 4.24 Widget since 4.2, own added at 4.24.
Deprecated since 4.28 Use addHandles() instead.

Adds one or more handles which are to be tied to the lifecycle of the widget. The handles will be removed when the widget is destroyed.

const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true}
);

this.own(handle); // Handle gets removed when the widget is destroyed.
Parameter
handleOrHandles WatchHandle|WatchHandle[]

Handles marked for removal once the widget is destroyed.

postInitialize

Inherited
Method
postInitialize()
Inherited from Widget

Executes after widget is ready for rendering.

removeHandles

Inherited
Method
removeHandles(groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, removeHandles added at 4.25.

Removes a group of handles owned by the object.

Parameter
groupKey *
optional

A group key or an array or collection of group keys to remove.

Example
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");

render

Inherited
Method
render(){Object}
Inherited from Widget

This method is implemented by subclasses for rendering.

Returns
Type Description
Object The rendered virtual node.

renderNow

Inherited
Method
renderNow()
Inherited from Widget

Renders widget to the DOM immediately.

scheduleRender

Inherited
Method
scheduleRender()
Inherited from Widget

Schedules widget rendering. This method is useful for changes affecting the UI.

when

Inherited
Method
when(callback, errback){Promise}
Inherited from Widget
Since: ArcGIS Maps SDK for JavaScript 4.19 Widget since 4.2, when added at 4.19.

when() may be leveraged once an instance of the class is created. This method takes two input parameters: a callback function and an errback function. The callback executes when the instance of the class loads. The errback executes if the instance of the class fails to load.

Parameters
callback Function
optional

The function to call when the promise resolves.

errback Function
optional

The function to execute when the promise fails.

Returns
Type Description
Promise Returns a new Promise for the result of callback.
Example
// Although this example uses the BasemapGallery widget, any class instance that is a promise may use when() in the same way
let bmGallery = new BasemapGallery();
bmGallery.when(function(){
  // This function will execute once the promise is resolved
}, function(error){
  // This function will execute if the promise is rejected due to an error
});

Event Overview

Name Type Summary Class
{oldValue: Number,type: "max-change",value: Number}

Fires when a user changes the max value of the slider.

HistogramRangeSlider
{oldValue: Number,type: "min-change",value: Number}

Fires when a user changes the min value of the slider.

HistogramRangeSlider
{index: Number,state: "start"|"drag",type: "segment-drag",thumbIndices: Number[]}

Fires when a user drags a segment of the slider.

HistogramRangeSlider
{index: Number,oldValue: Number,type: "thumb-change",value: Number}

Fires when a user changes the value of a thumb via the keyboard arrow keys.

HistogramRangeSlider
{index: Number,state: "start"|"drag",type: "thumb-drag",value: Number}

Fires when a user drags a thumb on the widget.

HistogramRangeSlider

Event Details

max-change

Event
max-change

Fires when a user changes the max value of the slider.

Properties
oldValue Number

The former max value (or bound) of the slider.

type String

The type of the event.

The value is always "max-change".

value Number

The value of the max value (or bound) of the slider when the event is emitted.

min-change

Event
min-change

Fires when a user changes the min value of the slider.

Properties
oldValue Number

The former min value (or bound) of the slider.

type String

The type of the event.

The value is always "min-change".

value Number

The value of the min value (or bound) of the slider when the event is emitted.

segment-drag

Event
segment-drag

Fires when a user drags a segment of the slider. A segment is the portion of the track that lies between two thumbs. Therefore, this is only applicable when two or more thumbs are set on the slider.

Properties
index Number

The 1-based index of the segment in the slider.

state String

The state of the drag.

Possible Values:"start"|"drag"

type String

The type of the event.

The value is always "segment-drag".

thumbIndices Number[]

The indices of the thumbs on each end of the segment.

thumb-change

Event
thumb-change

Fires when a user changes the value of a thumb via the keyboard arrow keys.

Properties
index Number

The 0-based index of the updated thumb position.

oldValue Number

The former value of the thumb before the change was made.

type String

The type of the event.

The value is always "thumb-change".

value Number

The value of the thumb when the event is emitted.

thumb-drag

Event
thumb-drag

Fires when a user drags a thumb on the widget.

Properties
index Number

The 0-based index of the updated thumb position.

state String

The state of the drag.

Possible Values:"start"|"drag"

type String

The type of the event.

The value is always "thumb-drag".

value Number

The value of the thumb when the event is emitted.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.