12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as t}from"../../chunks/tslib.es6.js";import{isSome as s}from"../../core/maybe.js";import{property as e}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as i}from"../../core/accessorSupport/decorators/subclass.js";import o from"../Slider/SliderViewModel.js";import{formatDateLabel as n,formatNumberLabel as a,getStopChanges as r}from"./support/utils.js";let h=class extends o{constructor(t){super(t),this._initialStopValues=[],this._max=null,this._min=null,this.hasTimeData=!1,this.inputFormatFunction=(t,s)=>"max"===s?this.getUnzoomedMax().toString():"min"===s?this.getUnzoomedMin().toString():t.toString(),this.inputParseFunction=null,this.labelFormatFunction=t=>{if(this.hasTimeData)return n(t);const{max:s,min:e,precision:i}=this,o=s-e>10?2:i;return a(parseFloat(t.toFixed(o)))},this.thumbsConstrained=!1,this.zoomingEnabled=!0}set breaks(t){this._set("breaks",t),this.notifyChange("max"),this.notifyChange("min")}set stops(t){if(t?.length){const{max:e,min:i}=this,o=this.getValuesFromStops(t),n={};s(i)&&o.some((t=>t<i))&&(n.min=Math.min(...o)),s(e)&&o.some((t=>t>e))&&(n.max=Math.max(...o)),this.set({...n}),this._initialStopValues=o}else this._initialStopValues=null;this._set("stops",t||null),this.notifyChange("values")}get labels(){const{values:t}=this,s=t&&t.length?t.map(((t,s)=>this.getLabelForValue(t,"value",s))):[],e=this.getUnzoomedMax(),i=this.getUnzoomedMin();return{max:this.getLabelForValue(e,"max"),min:this.getLabelForValue(i,"min"),values:s}}get max(){const{breaks:t}=this;return t?.length?t[t.length-1].max:this.max}set max(t){const{zoomOptions:e}=this;if(e&&s(e.max)){const s=this.values;let i=e.max;if(t<i&&(i=t,e.max=t),s&&s.length)for(let e=0;e<s.length;e++)t<s[e]&&this.setValue(e,t);this._storeZoomMax(i,t)}else this.updateBreakMax(t),this.setMax(t);this.notifyChange("labels")}get min(){const{breaks:t}=this;return t?.length?t[0].min:this.min}set min(t){const{zoomOptions:e}=this;if(e&&s(e.min)){const s=this.values;let i=e.min;if(t>i&&(i=t,e.min=t),s&&s.length)for(let e=0;e<s.length;e++)t>s[e]&&this.setValue(e,t);this._storeZoomMin(i,t)}else this.updateBreakMin(t),this.setMin(t);this.notifyChange("labels")}get state(){const{max:t,min:e,values:i}=this;return s(t)&&s(e)&&i.length>0?"ready":"disabled"}get values(){const{breaks:t,stops:s}=this;if(!t&&!s)return[];if(t?.length){const s=t.map((t=>t.max));return s.pop(),s}if(s?.length<2)return[];const e=this.getValuesFromStops();return[e[0],e[e.length-1]]}set zoomOptions(t){const{zoomingEnabled:e,zoomOptions:i}=this;if(e){if(i){const e=s(this._max)?this._max:this.max,i=s(this._min)?this._min:this.min;if(t){const{max:o,min:n}=t,a=s(o),r=s(n),h=r?t.min:i,l=r?i:null,m=a?t.max:e,p=a?e:null;this._storeZoomMin(h,l),this._storeZoomMax(m,p)}else this.setMax(e),this.setMin(i),this._min=null,this._max=null}else if(t){const{max:e,min:i}=t;s(i)&&this._storeZoomMin(t.min,this.min),s(e)&&this._storeZoomMax(t.max,this.max)}this._set("zoomOptions",t),this.notifyChange("max"),this.notifyChange("min")}}getStopIndexFromValueIndex(t){const{stops:s}=this,e=this.values[t];if(0===t){return e<=this.values[1]?0:s.length-1}if(1===t){return this.values[0]>=e?0:s.length-1}return null}getStopChanges(t,s){const e=this.stops,i=this.getStopIndexFromValueIndex(t),o=this.getValuesFromStops();o[i]=s;const[n,a]=[o[0],o[o.length-1]].sort(((t,s)=>t>s?1:-1)),r=a-n,h=e.length-1;return o.map(((t,s)=>({index:s,value:this.toPrecision(n+s*r/h)})))}setValue(t,s){const{max:e,min:i,values:o}=this,n=o[t];if(isNaN(s)||n===s||s>e||s<i)return;o[t]=this.toPrecision(s),this._set("values",[...o]);const a=o.slice().sort(((t,s)=>t>s?1:-1)),h=a[0],l=a[a.length-1],m=r(h,l,this._initialStopValues);this.updateStops(m),this.updateBreaks(),this.notifyChange("labels")}getValuesFromStops(t){return(t||this.stops)?.map((t=>t.hasOwnProperty("ratio")?t.ratio:t.value))}updateBreaks(){const{breaks:t,values:e}=this;t?.length&&e.slice().sort(((t,s)=>t>s?1:-1)).forEach(((e,i)=>{t[i].max=e,s(t[i+1])&&(t[i+1].min=e)}))}updateBreakMax(t){const{breaks:e,max:i,min:o}=this;!isNaN(t)&&i!==t&&s(o)&&t>o&&e?.length&&(e[e.length-1].max=t)}updateBreakMin(t){const{breaks:e,max:i,min:o}=this;!isNaN(t)&&o!==t&&s(i)&&t<i&&e?.length&&(e[0].min=t)}updateStops(t){const{stops:s}=this,e=this.getValuesFromStops();if(e?.length){for(const s of t)e[s.index]=s.value;s.forEach(((t,s)=>{t.hasOwnProperty("ratio")?t.ratio=e[s]:t.value=e[s]}))}}getUnzoomedMax(){return this.zoomOptions&&s(this._max)?this._max:this.max}getUnzoomedMin(){return this.zoomOptions&&s(this._min)?this._min:this.min}_storeZoomMax(t,s){this._max=s,this.setMax(t)}_storeZoomMin(t,s){this._min=s,this.setMin(t)}};t([e()],h.prototype,"breaks",null),t([e()],h.prototype,"stops",null),t([e()],h.prototype,"hasTimeData",void 0),t([e()],h.prototype,"inputFormatFunction",void 0),t([e()],h.prototype,"inputParseFunction",void 0),t([e()],h.prototype,"labelFormatFunction",void 0),t([e({readOnly:!0})],h.prototype,"labels",null),t([e()],h.prototype,"max",null),t([e()],h.prototype,"min",null),t([e({readOnly:!0})],h.prototype,"state",null),t([e()],h.prototype,"thumbsConstrained",void 0),t([e({readOnly:!0})],h.prototype,"values",null),t([e()],h.prototype,"zoomingEnabled",void 0),t([e()],h.prototype,"zoomOptions",null),h=t([i("esri.widgets.smartMapping.SmartMappingSliderViewModel")],h);const l=h;export{l as default};
|