HistogramRangeSliderViewModel

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

Provides the logic for the HistogramRangeSlider widget.

See also

Constructors

HistogramRangeSliderViewModel

Constructor
new HistogramRangeSliderViewModel(properties)
Parameter
properties Object
optional

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

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.

HistogramRangeSliderViewModel

An array of objects representing each bin in the histogram.

HistogramRangeSliderViewModel

The name of the class.

Accessor

When set, the user is restricted from moving slider thumbs to positions higher than this value.

SliderViewModel

When set, the user is restricted from moving slider thumbs to positions less than this value.

SliderViewModel

A function used to format user inputs.

SliderViewModel

Function used to parse slider inputs formatted by the inputFormatFunction.

SliderViewModel

A modified version of SliderViewModel.labelFormatFunction, which is a custom function used to format labels.

HistogramRangeSliderViewModel

An array of strings associated with values generated using an internal label formatter or the values returned from labelFormatFunction.

SliderViewModel

The maximum possible data/thumb value of the slider.

SliderViewModel

The minimum possible data/thumb value of the slider.

SliderViewModel

Defines how slider values should be rounded.

SliderViewModel

Determines the SQL where clause generated in generateWhereClause() for filtering purposes.

HistogramRangeSliderViewModel

Indicates the standard deviation of the dataset above and below the average.

HistogramRangeSliderViewModel

The state of the view model.

SliderViewModel

When false, the user can freely move any slider thumb to any position along the track.

SliderViewModel

An array of numbers representing absolute thumb positions on the slider.

SliderViewModel

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.

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

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
histogramVM.bins = histogramResult.bins;
// Creates a histogram with 7 bins.
histogramVM.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 }
];

declaredClass

Inherited
Property
declaredClass Stringreadonly
Inherited from Accessor

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

effectiveMax

Inherited
Property
effectiveMax Number
Inherited from SliderViewModel
Since: ArcGIS Maps SDK for JavaScript 4.23 SliderViewModel since 4.12, effectiveMax added at 4.23.

When set, the user is restricted from moving slider thumbs to positions higher than this value. This value should be less than the slider max. The effectiveMax and effectiveMin allow you to represent ranges of values in a dataset that cannot be filtered or selected with the slider. This can be useful when using the slider to represent datasets with outliers, or scale ranges not suitable for a layer.

Example
// slider.viewModel.max = 100
slider.viewModel.effectiveMax = 60;
// now the user cannot slide thumbs above
// 60 even though the slider track displays
// values up to 100.

effectiveMin

Inherited
Property
effectiveMin Number
Inherited from SliderViewModel
Since: ArcGIS Maps SDK for JavaScript 4.23 SliderViewModel since 4.12, effectiveMin added at 4.23.

When set, the user is restricted from moving slider thumbs to positions less than this value. This value should be greater than the slider min. The effectiveMin and effectiveMax allow you to represent ranges of values in a dataset that cannot be filtered or selected with the slider. This can be useful when using the slider to represent datasets with outliers, or scale ranges not suitable for a layer.

Example
// slider.viewModel.min = 0
slider.viewModel.effectiveMin = 4;
// now the user cannot slide thumbs below
// 4 even though the slider track displays
// values down to 0.

inputFormatFunction

Inherited
Property
inputFormatFunction LabelFormatter
Inherited from SliderViewModel

A function used to format user inputs. As opposed to labelFormatFunction, which formats thumb labels, the inputFormatFunction formats thumb values in the input element when the user begins to edit them.

The image below demonstrates how slider input values resemble corresponding slider values by default and won't match the formatting set in labelFormatFunction.

Slider without input formatter

If you want to format slider input values so they match thumb labels, you can pass the same function set in labelFormatFunction to inputFormatFunction for consistent formatting.

Slider with input formatter

However, if an inputFormatFunction is specified, you must also write a corresponding inputParseFunction to parse user inputs to understandable slider values. In most cases, if you specify an inputFormatFunction, you should set the labelFormatFunction to the same value for consistency between labels and inputs.

This property overrides the default input formatter, which formats by calling toString() on the input value.

Example
// Formats the slider input to abbreviated numbers with units
// e.g. a thumb at position 1500 will render with an input label of 1.5k
slider.inputFormatFunction = function(value, type){
  if(value >= 1000000){
    return (value / 1000000).toPrecision(3) + "m"
  }
  if(value >= 100000){
    return (value / 1000).toPrecision(3) + "k"
  }
  if(value >= 1000){
    return (value / 1000).toPrecision(2) + "k"
  }
  return value.toFixed(0);
}

inputParseFunction

Inherited
Property
inputParseFunction InputParser
Inherited from SliderViewModel

Function used to parse slider inputs formatted by the inputFormatFunction. This property must be set if an inputFormatFunction is set. Otherwise the slider values will likely not update to their expected positions.

Overrides the default input parses, which is a parsed floating point number.

Example
// Parses the slider input (a string value) to a number value understandable to the slider
// This assumes the slider was already configured with an inputFormatFunction
// For example, if the input is 1.5k this function will parse
// it to a value of 1500
slider.inputParseFunction = function(value, type, index){
  let charLength = value.length;
  let valuePrefix = parseFloat(value.substring(0,charLength-1));
  let finalChar = value.substring(charLength-1);

  if(parseFloat(finalChar) >= 0){
    return parseFloat(value);
  }
  if(finalChar === "k"){
    return valuePrefix * 1000;
  }
  if(finalChar === "m"){
    return valuePrefix * 1000000;
  }
  return value;
}

labelFormatFunction

Property
labelFormatFunction LabelFormatter

A modified version of SliderViewModel.labelFormatFunction, which is a custom function used to format labels. Overrides the default label formatter.

labels

Inherited
Property
labels String[]readonly
Inherited from SliderViewModel

An array of strings associated with values generated using an internal label formatter or the values returned from labelFormatFunction.

max

Inherited
Property
max Number
Inherited from SliderViewModel

The maximum possible data/thumb value of the slider. In the constructor, if one of the values specified in values is greater than the max value specified in this property, then the max will update to the highest value in values.

Example
sliderViewModel.max = 100;

min

Inherited
Property
min Number
Inherited from SliderViewModel

The minimum possible data/thumb value of the slider. In the constructor, if one of the values specified in values is less than the min value specified in this property, then the min will update to the lowest value in values.

Example
sliderViewModel.min = 0;

precision

Inherited
Property
precision Number
Inherited from SliderViewModel

Defines how slider values should be rounded. This number indicates the number of decimal places slider 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 SliderVM({
  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.

If thumb labels aren't visible, they must be enabled with labelInputsEnabled.

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
sliderViewModel.precision = 7;

rangeType

Property
rangeType String

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"

Default Value:"equal"
See also
Example
// renders the histogram so that all bins between
// the two handles are shaded with a blue color
slider.viewModel.rangeType = "between";

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

// if slider min is 1,000 and max is 10,000, the following is generated
// layerView.filter.where = 'POPULATION >= 1000 AND POPULATION <= 10000'

standardDeviation

Property
standardDeviation Number

Indicates the standard deviation of the dataset above and below the average.

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

state

Inherited
Property
state Stringreadonly
Inherited from SliderViewModel

The state of the view model.

Possible Values:"ready" |"disabled"

thumbsConstrained

Inherited
Property
thumbsConstrained Boolean
Inherited from SliderViewModel

When false, the user can freely move any slider thumb to any position along the track. By default, a thumb's position is constrained to the positions of neighboring thumbs so you cannot move one thumb past another. Set this property to false to disable this constraining behavior.

Default Value:true
Example
// allows the user to freely move slider
// thumbs to any position along the track
slider.viewModel.thumbsConstrained = false;

values

Inherited
Property
values Number[]
Inherited from SliderViewModel

An array of numbers representing absolute thumb positions on the slider.

See also
Example
const slider = new SliderVM({
  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
});

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

The default input format function available for use as a fallback in custom formatting implementations.

SliderViewModel

The default input parsing function available for use as a fallback in custom parsing implementations.

SliderViewModel

The default label format function, available for use as a fallback in custom formatting implementations.

SliderViewModel

Emits an event on the instance.

SliderViewModel

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

HistogramRangeSliderViewModel

Returns the effective bounds of the slider.

SliderViewModel

Returns the min and max bounds for a 'value' at the provided index.

SliderViewModel

Returns the formatted label for a provided value.

SliderViewModel

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

SliderViewModel

Returns true if a named group of handles exist.

Accessor

Registers an event handler on the instance.

SliderViewModel

Removes a group of handles owned by the object.

Accessor

Updates a thumb value based on the provided index.

SliderViewModel

Rounds the given value to the number of decimal places specified in the precision property set on the view model.

SliderViewModel

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.

defaultInputFormatFunction

Inherited
Method
defaultInputFormatFunction(value){String}
Inherited from SliderViewModel

The default input format function available for use as a fallback in custom formatting implementations.

Parameter
value Number

The input value to format.

Returns
Type Description
String The formatted input value.

defaultInputParseFunction

Inherited
Method
defaultInputParseFunction(value){Number}
Inherited from SliderViewModel

The default input parsing function available for use as a fallback in custom parsing implementations.

Parameter
value String

The thumb value to parse.

Returns
Type Description
Number The parsed thumb value.

defaultLabelFormatFunction

Inherited
Method
defaultLabelFormatFunction(value){String}
Inherited from SliderViewModel

The default label format function, available for use as a fallback in custom formatting implementations.

Parameter
value Number

The thumb value to format.

Returns
Type Description
String The formatted thumb value.

emit

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

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.viewModel.rangeType = "between";

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

getBounds

Inherited
Method
getBounds(){Bounds}
Inherited from SliderViewModel
Since: ArcGIS Maps SDK for JavaScript 4.23 SliderViewModel since 4.12, getBounds added at 4.23.

Returns the effective bounds of the slider. If effectiveMin and effectiveMax are set on the slider, then those values will be returned. If not, then the min and max are returned.

Returns
Type Description
Bounds The effective bounds of the slider.

getBoundsForValueAtIndex

Inherited
Method
getBoundsForValueAtIndex(index){Object}
Inherited from SliderViewModel

Returns the min and max bounds for a 'value' at the provided index. Also used internally to provide accessibility information via HTMLElement properties

Parameter
index Number

The index of the associated value.

Returns
Type Description
Object Returns a simple object with bound information.

getLabelForValue

Inherited
Method
getLabelForValue(value, type, index){String}
Inherited from SliderViewModel

Returns the formatted label for a provided value.

Parameters
value Number

The value from which to retrieve a formatted label.

type String
optional

The label type.

Possible Values:"min"|"max"|"tick"|"values"

index Number
optional

The index of the label.

Returns
Type Description
String Returns the formatted label.

hasEventListener

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

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

on

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

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

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

setValue

Inherited
Method
setValue(index, value)
Inherited from SliderViewModel

Updates a thumb value based on the provided index. The provided value must differ from the previous value. The provided value must also be between the min and max.

Parameters
index Number

The index of the thumb value in the associated values array.

value Number

The new value to replace with the old value.

toPrecision

Inherited
Method
toPrecision(value){String}
Inherited from SliderViewModel
Since: ArcGIS Maps SDK for JavaScript 4.14 SliderViewModel since 4.12, toPrecision added at 4.14.

Rounds the given value to the number of decimal places specified in the precision property set on the view model.

Parameter
value Number

The thumb value to format.

Returns
Type Description
String The input value rounded to the number of places specified in precision.
See also

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