HistogramRangeSlider

AMD: require(["esri/widgets/HistogramRangeSlider"], (HistogramRangeSlider) => { /* code goes here */ });
ESM: import HistogramRangeSlider from "@arcgis/core/widgets/HistogramRangeSlider";
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

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
Number

The statistical average of the data in the histogram.

more details
HistogramRangeSlider
BarCreatedFunction

Function for styling bars representing histogram bins.

more details
HistogramRangeSlider
Bin[]

An array of objects representing each bin in the histogram.

more details
HistogramRangeSlider
String|HTMLElement

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

more details
Widget
DataLineCreatedFunction

Function that fires each time a data line is created.

more details
HistogramRangeSlider
Object[]

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

more details
HistogramRangeSlider
String

The name of the class.

more details
Accessor
Color

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

more details
HistogramRangeSlider
String

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

more details
Widget
Color

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

more details
HistogramRangeSlider
String

The widget's default label.

more details
HistogramRangeSlider
LabelFormatter

A function used to format labels.

more details
HistogramRangeSlider
Number

The maximum value or upper bound of the slider.

more details
HistogramRangeSlider
Number

The minimum value or lower bound of the slider.

more details
HistogramRangeSlider
Number

Defines how slider thumb values should be rounded.

more details
HistogramRangeSlider
String

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

more details
HistogramRangeSlider
Number

Indicates the standard deviation of the dataset.

more details
HistogramRangeSlider
Number

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

more details
HistogramRangeSlider
Number[]

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

more details
HistogramRangeSlider
HistogramRangeSliderViewModel

The view model for the widget.

more details
HistogramRangeSlider
Boolean

Indicates whether the widget is visible.

more details
Widget

Property Details

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 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 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 }
];

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 cases 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 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 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 Stringreadonly inherited

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

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";

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 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 String

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

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 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 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 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 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"

See also
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 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 Number

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

Default Value:1
Example
slider.standardDeviationCount = 2;
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"
});

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 Boolean inherited

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.

more details
Accessor
String

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

more details
Widget

Destroys the widget instance.

more details
Widget
Boolean

Emits an event on the instance.

more details
Widget
String

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

more details
HistogramRangeSlider
Boolean

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

more details
Widget
Boolean

Returns true if a named group of handles exist.

more details
Accessor
Boolean

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

more details
Widget
Boolean

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

more details
Widget
Boolean

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

more details
Widget
Object

Registers an event handler on the instance.

more details
Widget

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

more details
Widget

This method is primarily used by developers when implementing custom widgets.

more details
Widget

Removes a group of handles owned by the object.

more details
Accessor
Object

This method is primarily used by developers when implementing custom widgets.

more details
Widget

Renders widget to the DOM immediately.

more details
Widget

This method is primarily used by developers when implementing custom widgets.

more details
Widget
Promise

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

more details
Widget

Method Details

addHandles(handleOrHandles, groupKey)inherited
Since: ArcGIS Maps SDK for JavaScript 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 }
);

// Handle gets removed when the object is destroyed.
this.addHandles(handle);
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(classNames){String}inherited

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.
See also
Example
// .tsx syntax showing how to set CSS classes while rendering the widget

render() {
  const dynamicIconClasses = {
    [CSS.myIcon]: this.showIcon,
    [CSS.greyIcon]: !this.showIcon
  };

  return (
    <div class={classes(CSS.root, CSS.mixin, dynamicIconClasses)} />
  );
}
destroy()inherited

Destroys the widget instance.

emit(type, event){Boolean}inherited

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(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.
See also
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(type){Boolean}inherited

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(groupKey){Boolean}inherited
Since: ArcGIS Maps SDK for JavaScript 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(){Boolean}inherited
Since: ArcGIS Maps SDK for JavaScript 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(){Boolean}inherited
Since: ArcGIS Maps SDK for JavaScript 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(){Boolean}inherited
Since: ArcGIS Maps SDK for JavaScript 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(type, listener){Object}inherited

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(handleOrHandles)inherited
Since: ArcGIS Maps SDK for JavaScript 4.24

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

This method is primarily used by developers when implementing custom widgets. Executes after widget is ready for rendering.

removeHandles(groupKey)inherited
Since: ArcGIS Maps SDK for JavaScript 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(){Object}inherited

This method is primarily used by developers when implementing custom widgets. It must be implemented by subclasses for rendering.

Returns
Type Description
Object The rendered virtual node.
renderNow()inherited

Renders widget to the DOM immediately.

scheduleRender()inherited

This method is primarily used by developers when implementing custom widgets. Schedules widget rendering. This method is useful for changes affecting the UI.

when(callback, errback){Promise}inherited
Since: ArcGIS Maps SDK for JavaScript 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.

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

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

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

Fires when a user drags a segment of the slider.

more details
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.

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

Fires when a user drags a thumb on the widget.

more details
HistogramRangeSlider

Event Details

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

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

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

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

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.