Skip to content
import HistogramRangeSlider from "@arcgis/core/widgets/HistogramRangeSlider.js";
Inheritance:
HistogramRangeSliderWidgetAccessor
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.

See also

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table 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 ]
});

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

average

Property
Type
number | null | undefined

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
Type
BarCreatedFunction | null | undefined

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
Type
HistogramBin[] | null | undefined

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

autocast inherited Property
Type
HTMLElement | null | undefined
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
Type
DataLineCreatedFunction | null | undefined

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
Type
DataLineInfos[] | null | undefined

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

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

readonlyinherited Property
Type
string
Inherited from: Accessor

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

destroyed

readonlyinherited Property
Type
boolean
Inherited from: Widget

When true, this property indicates whether the widget has been destroyed.

excludedBarColor

autocast Property
Type
Color

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.

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

icon

autocast Property
Type
Icon["icon"]
Since
ArcGIS Maps SDK for JavaScript 4.27

Icon displayed in the widget's button.

See also
Default value
"arrow-double-horizontal"

id

inherited Property
Type
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

autocast Property
Type
Color

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.

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

label

autocast Property
Type
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
Type
LabelFormatFunction

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, HistogramRangeSliderViewModel.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
Type
number | null | undefined

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
Type
number | null | undefined

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
Type
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 HistogramRangeSliderViewModel.labels when the data range (max - min) is less than 10.

When the data range is larger than 10, HistogramRangeSliderViewModel.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
Type
RangeType

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 ValueNumber of valuesWhere clause
equal1${field} = ${value1}
not-equal1${field} <> ${value1}
less-than1${field} < ${value1}
greater-than1${field} > ${value1}
at-most1${field} <= ${value1}
at-least1${field} >= ${value1}
between2${field} BETWEEN ${value1} AND ${value2}
not-between2${field} NOT BETWEEN ${value1} AND ${value2}
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

Property
Type
number | null | undefined

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
Type
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
Type
number[] | null | undefined

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

autocast Property
Type
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 HistogramRangeSliderViewModel class to access all properties and methods on the Slider widget.

visible

inherited Property
Type
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 DefaultUI, 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;

Methods

MethodSignatureClass
classes
inherited
classes(...classNames: ((string | null | undefined) | ((string[] | Record<string, boolean>) | null | undefined) | false | null | undefined)[]): string
destroy
inherited
destroy(): void
emit
inherited
emit<Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
generateWhereClause(field: string): string | null | undefined
hasEventListener
inherited
hasEventListener<Type extends EventNames<this>>(type: Type): boolean
isFulfilled
inherited
isFulfilled(): boolean
isRejected
inherited
isRejected(): boolean
isResolved
inherited
isResolved(): boolean
on
inherited
on<Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
postInitialize
inherited
postInitialize(): void
render
inherited
render(): any | null
renderNow
inherited
renderNow(): void
scheduleRender
inherited
scheduleRender(): void
when
inherited
when<TResult1 = this, TResult2 = never>(onFulfilled?: OnFulfilledCallback<this, TResult1> | null | undefined, onRejected?: OnRejectedCallback<TResult2> | null | undefined): Promise<TResult1 | TResult2>

classes

inherited Method
Signature
classes (...classNames: ((string | null | undefined) | ((string[] | Record<string, boolean>) | null | undefined) | false | null | undefined)[]): 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.

Parameters
ParameterTypeDescriptionRequired
classNames
((string | null | undefined) | ((string[] | Record<string, boolean>) | null | undefined) | false | null | undefined)[]

The class names.

Returns
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
Signature
destroy (): void
Inherited from: Widget

Destroys the widget instance.

Returns
void

emit

inherited Method
Signature
emit <Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

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

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

event
this["@eventTypes"][Type]

The event payload.

Returns
boolean

true if a listener was notified

generateWhereClause

Method
Signature
generateWhereClause (field: string): string | null | undefined

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.

See also
Parameters
ParameterTypeDescriptionRequired
field

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
string | null | undefined

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
Signature
hasEventListener <Type extends EventNames<this>>(type: Type): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

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

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

Returns
boolean

Returns true if the class supports the input event.

isFulfilled

inherited Method
Signature
isFulfilled (): boolean
Inherited from: EsriPromiseMixin

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
boolean

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

isRejected

inherited Method
Signature
isRejected (): boolean
Inherited from: EsriPromiseMixin

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

Returns
boolean

Indicates whether creating an instance of the class has been rejected.

isResolved

inherited Method
Signature
isResolved (): boolean
Inherited from: EsriPromiseMixin

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

Returns
boolean

Indicates whether creating an instance of the class has been resolved.

on

inherited Method
Signature
on <Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

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

Parameters
ParameterTypeDescriptionRequired
type
Type

An event or an array of events to listen for.

listener
EventedCallback<this["@eventTypes"][Type]>

The function to call when the event fires.

Returns
ResourceHandle

Returns an event handler with a remove() method that should be called to stop listening for the event(s).

PropertyTypeDescription
removeFunctionWhen 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);
});

postInitialize

inherited Method
Signature
postInitialize (): void
Inherited from: Widget

Executes after widget is ready for rendering.

Returns
void

render

inherited Method
Signature
render (): any | null
Inherited from: Widget

This method is implemented by subclasses for rendering.

Returns
any | null

The rendered virtual node.

renderNow

inherited Method
Signature
renderNow (): void
Inherited from: Widget

Renders widget to the DOM immediately.

Returns
void

scheduleRender

inherited Method
Signature
scheduleRender (): void
Inherited from: Widget

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

Returns
void

when

inherited Method
Signature
when <TResult1 = this, TResult2 = never>(onFulfilled?: OnFulfilledCallback<this, TResult1> | null | undefined, onRejected?: OnRejectedCallback<TResult2> | null | undefined): Promise<TResult1 | TResult2>
Type parameters
<TResult1 = this, TResult2 = never>
Inherited from: EsriPromiseMixin

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

Parameters
ParameterTypeDescriptionRequired
onFulfilled

The function to call when the promise resolves.

onRejected

The function to execute when the promise fails.

Returns
Promise<TResult1 | TResult2>

Returns a new promise for the result of onFulfilled that may be used to chain additional functions.

Example
// Although this example uses MapView, any class instance that is a promise may use when() in the same way
let view = new MapView();
view.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
});

Events

max-change

inherited Event
Inherited from: CommonSliderEvents

Fires when a user changes the max of the slider.

bubbles composed cancelable
Example
slider.on("max-change", function() {
const renderer = layer.renderer.clone();
const visualVariable = renderer.visualVariables[0].clone();
colorVariable.stops = slider.stops;
renderer.visualVariables = [ visualVariable ];
layer.renderer = renderer;
});

min-change

inherited Event
Inherited from: CommonSliderEvents

Fires when a user changes the min of the slider.

bubbles composed cancelable
Example
slider.on("min-change", function() {
const renderer = layer.renderer.clone();
const visualVariable = renderer.visualVariables[0].clone();
colorVariable.stops = slider.stops;
renderer.visualVariables = [ visualVariable ];
layer.renderer = renderer;
});

segment-drag

inherited Event
segment-drag: CustomEvent<SegmentDragEvent>
Inherited from: CommonSliderEvents
Since
ArcGIS Maps SDK for JavaScript 4.20

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 only applies when two or more thumbs are set on the slider.

See also
bubbles composed cancelable
Example
slider.on("segment-drag", () => {
const renderer = layer.renderer.clone();
const visualVariable = renderer.visualVariables[0].clone();
colorVariable.stops = slider.stops;
renderer.visualVariables = [ visualVariable ];
layer.renderer = renderer;
});

thumb-change

inherited Event
thumb-change: CustomEvent<ThumbChangeEvent>
Inherited from: CommonSliderEvents

Fires when a user changes the value of a thumb via the arrow keys or by keyboard editing of the label on the slider.

bubbles composed cancelable
Examples
slider.on("thumb-change", function() {
const renderer = layer.renderer.clone();
const visualVariable = renderer.visualVariables[0].clone();
colorVariable.stops = slider.stops;
renderer.visualVariables = [ visualVariable ];
layer.renderer = renderer;
});
slider.on("thumb-change", function() {
const renderer = layer.renderer.clone();
renderer.colorStops = slider.stops;
layer.renderer = renderer;
});

thumb-drag

inherited Event
Inherited from: CommonSliderEvents

Fires when a user drags a thumb on the widget.

bubbles composed cancelable
Examples
slider.on("thumb-drag", function() {
const renderer = layer.renderer.clone();
const visualVariable = renderer.visualVariables[0].clone();
colorVariable.stops = slider.stops;
renderer.visualVariables = [ visualVariable ];
layer.renderer = renderer;
});
slider.on("thumb-drag", function() {
const renderer = layer.renderer.clone();
renderer.colorStops = slider.stops;
layer.renderer = renderer;
});

Type definitions