SmartMappingPrimaryHandleSliderViewModel.js 2.5 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../../chunks/tslib.es6.js";import{property as t}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import r from"./SmartMappingSliderViewModel.js";let n=class extends r{constructor(e){super(e),this.handlesSyncedToPrimary=!0}set primaryHandleEnabled(e){this._set("primaryHandleEnabled",e)}get primaryHandleEnabled(){const{stops:e}=this;if(!e||!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||!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:r,values:n}=this,a=n[e];if(isNaN(t)||a===t||t>s||t<r)return;t=this.toPrecision(t);const i=this.primaryHandleEnabled&&this.handlesSyncedToPrimary;if(i){const s=n.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"):(n[e]=t,this._set("values",[...n])),this.notifyChange("labels")}getStopIndexFromValueIndex(e){const{handlesSyncedToPrimary:t,primaryHandleEnabled:s}=this;if(s){const{values:s}=this,r=s[e];if(t)return e;const n=s.slice().sort(((e,t)=>e>t?1:-1)),a=n.indexOf(r);return s.some(((e,t)=>e===r&&t!==a))?n.lastIndexOf(r):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:r,stops:n,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),r)):d[0],u=i?this.toPrecision(Math.max(Math.min(d[2]+h,s),r)):d[2];return 5===n.length?[{index:0,value:c},{index:1,value:this.toPrecision((p+c)/2)},{index:2,value:p},{index:3,value:this.toPrecision((p+u)/2)},{index:4,value:u}]:[{index:0,value:c},{index:1,value:p},{index:2,value:u}]}};e([t()],n.prototype,"handlesSyncedToPrimary",void 0),e([t()],n.prototype,"primaryHandleEnabled",null),e([t({dependsOn:["handlesSyncedToPrimary"],readOnly:!0})],n.prototype,"values",null),n=e([s("esri.widgets.smartMapping.SmartMappingPrimaryHandleSliderViewModel")],n);const a=n;export{a as default};