UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 4.61 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as t}from"tslib";import e from"../../core/Accessor.js";import i from"../../core/Error.js";import s from"../../core/Logger.js";import{property as l,subclass as n}from"../../core/accessorSupport/decorators.js";let r=class extends e{constructor(t){super(t),this.precision=4,this.thumbsConstrained=!0}set effectiveMax(t){this.setEffectiveMax(t)}set effectiveMin(t){this.setEffectiveMin(t)}set labelFormatFunction(t){this._set("labelFormatFunction",t)}set inputFormatFunction(t){this._set("inputFormatFunction",t)}set inputParseFunction(t){this._set("inputParseFunction",t)}get labels(){const{max:t,min:e,values:i}=this,s=i?.length?i.map((t,e)=>this.getLabelForValue(t,"value",e)):[];return{max:this.getLabelForValue(t,"max"),min:this.getLabelForValue(e,"min"),values:s}}set max(t){this.setMax(t)}set min(t){this.setMin(t)}get state(){const{max:t,min:e}=this;return null!=t&&null!=e&&t>e?"ready":"disabled"}set values(t){const{max:e,min:i}=this,s=this.values;s&&s.length===t?.length&&s.every((e,i)=>e===t[i])||(this._set("values",null),t?.length&&(null!=i&&t.some(t=>t<i)&&(this.min=Math.min(...t)),null!=e&&t.some(t=>t>e)&&(this.max=Math.max(...t))),this._set("values",t))}toPrecision(t){return parseFloat(t.toFixed(this.precision))}defaultLabelFormatFunction(t){const{max:e,min:i,precision:s}=this,l=null!=e&&null!=i&&e-i>10?2:s;return parseFloat(t.toFixed(l)).toString()}defaultInputFormatFunction(t){return t.toString()}defaultInputParseFunction(t){return parseFloat(t)}getBounds(){const{effectiveMax:t,effectiveMin:e,max:i,min:s}=this;return{min:null!=e&&null!=s?Math.max(s,e):s,max:null!=t&&null!=i?Math.min(i,t):i}}getBoundsForValueAtIndex(t){const{thumbsConstrained:e,values:i}=this,{min:s,max:l}=this.getBounds();if(e&&i){const e=t-1,n=t+1;return{min:null!=i[e]?i[e]:s,max:null!=i[n]?i[n]:l}}return{min:s,max:l}}getLabelForValue(t,e,i){return null==t?null:this.labelFormatFunction?this.labelFormatFunction(t,e,i):this.defaultLabelFormatFunction(t)}setMax(t){const{max:e,values:i}=this;if(null==t)return void this._set("max",null);if(isNaN(t))return void this._logError("slider:invalid-value","Supplied value for property 'max' is NaN.");const s=this.toPrecision(t);if(e!==s)if(null!=this.min&&s<this.min)this._logError("slider:invalid-value","Supplied value for property 'max' is less than 'min'.");else if(this._set("max",s),i?.length)for(let l=0;l<i.length;l++)s<i[l]&&this.setValue(l,s)}setMin(t){const{min:e,values:i}=this;if(null==t)return void this._set("min",null);if(isNaN(t))return void this._logError("slider:invalid-value","Supplied value for property 'min' is NaN.");const s=this.toPrecision(t);if(e!==s)if(null!=this.max&&s>this.max)this._logError("slider:invalid-value","Supplied value for property 'min' is greater than 'max'.");else if(this._set("min",s),i?.length)for(let l=0;l<i.length;l++)s>i[l]&&this.setValue(l,s)}setEffectiveMax(t){if(null==t)return void this._set("effectiveMax",null);if(isNaN(t))return void this._logError("slider:invalid-value","Supplied value for property 'effectiveMax' is NaN.");const e=this.toPrecision(t);this.effectiveMax!==e&&this._set("effectiveMax",this._applyBoundsToValue(e))}setEffectiveMin(t){if(null==t)return void this._set("effectiveMin",null);if(isNaN(t))return void this._logError("slider:invalid-value","Supplied value for property 'effectiveMin' is NaN.");const e=this.toPrecision(t);this.effectiveMin!==e&&this._set("effectiveMin",this._applyBoundsToValue(e))}setValue(t,e){if(isNaN(e))return void this._logError("slider:invalid-value","Supplied value for member of property 'values' is NaN.");const{values:i}=this;if(null==i)return void this._logError("slider:invalid-value","Supplied value for member of property 'values' is null.");const s=i[t],l=this.toPrecision(e);if(s===l)return;const n=[...i];n[t]=l,this._set("values",n)}_applyBoundsToValue(t){const{max:e,min:i}=this;return null!=i&&t<i?i:null!=e&&t>e?e:t}_logError(t,e,l){s.getLogger(this).error(new i(t,e,l))}};t([l()],r.prototype,"effectiveMax",null),t([l()],r.prototype,"effectiveMin",null),t([l()],r.prototype,"labelFormatFunction",null),t([l()],r.prototype,"inputFormatFunction",null),t([l()],r.prototype,"inputParseFunction",null),t([l({readOnly:!0})],r.prototype,"labels",null),t([l()],r.prototype,"max",null),t([l()],r.prototype,"min",null),t([l()],r.prototype,"precision",void 0),t([l({readOnly:!0})],r.prototype,"state",null),t([l()],r.prototype,"thumbsConstrained",void 0),t([l()],r.prototype,"values",null),r=t([n("esri.widgets.Slider.SliderViewModel")],r);const o=r;export{o as default};