@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.59 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as e}from"../../chunks/tslib.es6.js";import{property as t}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import n from"./SmartMappingSliderViewModel.js";let r=class extends n{constructor(e){super(e),this.handlesSyncedToPrimary=!0}set primaryHandleEnabled(e){this._set("primaryHandleEnabled",e)}get primaryHandleEnabled(){const{stops:e}=this;if(!e?.length)return!1;const t=e.length;return(3===t||5===t)&&this._get("primaryHandleEnabled")}get values(){const{primaryHandleEnabled:e,stops:t}=this;if(!t?.length||t.length<2)return[];const s=this.getValuesFromStops();return e?3===s.length?[s[0],s[1],s[2]]:[s[0],s[2],s[4]]:[s[0],s[s.length-1]]}setValue(e,t){const{max:s,min:n,values:r}=this,a=r[e];if(isNaN(t)||a===t||t>s||t<n)return;t=this.toPrecision(t);const i=this.primaryHandleEnabled&&this.handlesSyncedToPrimary;if(i){const s=r.slice().sort(((e,t)=>e>t?1:-1))[1];(0===e&&t>s||2===e&&t<s)&&(t=s)}const o=this.getStopChanges(e,t);this.updateStops(o),i?this.notifyChange("values"):(r[e]=t,this._set("values",[...r])),this.notifyChange("labels")}getStopIndexFromValueIndex(e){const{handlesSyncedToPrimary:t,primaryHandleEnabled:s}=this;if(s){const{values:s}=this,n=s[e];if(t)return e;const r=s.slice().sort(((e,t)=>e>t?1:-1)),a=r.indexOf(n);return s.some(((e,t)=>e===n&&t!==a))?r.lastIndexOf(n):a}return super.getStopIndexFromValueIndex(e)}getStopChanges(e,t){return this.primaryHandleEnabled?this._getStopChanges(e,t):super.getStopChanges(e,t)}_getStopChanges(e,t){const{max:s,min:n,stops:r,values:a}=this,i=this.handlesSyncedToPrimary&&1===e,o=a[e],l=a.slice();i||(l[e]=t);const d=l.sort(((e,t)=>e>t?1:-1)),p=i?t:d[1],h=t-o,c=i?this.toPrecision(Math.max(Math.min(d[0]+h,s),n)):d[0],m=i?this.toPrecision(Math.max(Math.min(d[2]+h,s),n)):d[2];return 5===r.length?[{index:0,value:c},{index:1,value:this.toPrecision((p+c)/2)},{index:2,value:p},{index:3,value:this.toPrecision((p+m)/2)},{index:4,value:m}]:[{index:0,value:c},{index:1,value:p},{index:2,value:m}]}};e([t()],r.prototype,"handlesSyncedToPrimary",void 0),e([t()],r.prototype,"primaryHandleEnabled",null),e([t({dependsOn:["handlesSyncedToPrimary"],readOnly:!0})],r.prototype,"values",null),r=e([s("esri.widgets.smartMapping.SmartMappingPrimaryHandleSliderViewModel")],r);const a=r;export{a as default};