@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 7.22 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 t from"../../core/Error.js";import{JSONMap as i}from"../../core/jsonMap.js";import s from"../../core/Logger.js";import{property as r}from"../../core/accessorSupport/decorators/property.js";import{cast as a}from"../../core/accessorSupport/decorators/cast.js";import{reader as n}from"../../core/accessorSupport/decorators/reader.js";import{subclass as o}from"../../core/accessorSupport/decorators/subclass.js";import{writer as l}from"../../core/accessorSupport/decorators/writer.js";import p from"./VisualVariable.js";import{castSizeFromStringOrNumber as u}from"./support/castSizeVariable.js";import m from"./support/SizeStop.js";import h from"./support/SizeVariableLegendOptions.js";import{isSizeVariable as c,getInputValueType as d,getTransformationType as y,TransformationType as S}from"./support/sizeVariableUtils.js";import{viewScaleRE as x}from"./support/visualVariableUtils.js";var z;const v=new i({width:"width",depth:"depth",height:"height",widthAndDepth:"width-and-depth",all:"all"}),w=new i({unknown:"unknown",inch:"inches",foot:"feet",yard:"yards",mile:"miles","nautical-mile":"nautical-miles",millimeter:"millimeters",centimeter:"centimeters",decimeter:"decimeters",meter:"meters",kilometer:"kilometers"});function g(e){if(null!=e)return"string"==typeof e||"number"==typeof e?u(e):"size"===e.type?c(e)?e:(delete(e={...e}).type,new f(e)):void 0}function V(e,t,i){if("object"!=typeof e)return e;const s=new f;return s.read(e,i),s}let f=z=class extends p{constructor(e){super(e),this.axis=null,this.legendOptions=null,this.normalizationField=null,this.scaleBy=null,this.target=null,this.type="size",this.useSymbolValue=null,this.valueExpression=null,this.valueRepresentation=null,this.valueUnit=null}get cache(){return{ipData:this._interpolateData(),hasExpression:!!this.valueExpression,compiledFunc:null,isScaleDriven:null!=this.valueExpression&&x.test(this.valueExpression)}}set index(e){c(this.maxSize)&&(this.maxSize.index=`visualVariables[${e}].maxSize`),c(this.minSize)&&(this.minSize.index=`visualVariables[${e}].minSize`),this._set("index",e)}get inputValueType(){return d(this)}set maxDataValue(e){e&&this.stops&&(s.getLogger(this).warn("cannot set maxDataValue when stops is not null."),e=null),this._set("maxDataValue",e)}set maxSize(e){e&&this.stops&&(s.getLogger(this).warn("cannot set maxSize when stops is not null."),e=null),this._set("maxSize",e)}castMaxSize(e){return g(e)}readMaxSize(e,t,i){return V(e,t,i)}set minDataValue(e){e&&this.stops&&(s.getLogger(this).warn("cannot set minDataValue when stops is not null."),e=null),this._set("minDataValue",e)}set minSize(e){e&&this.stops&&(s.getLogger(this).warn("cannot set minSize when stops is not null."),e=null),this._set("minSize",e)}castMinSize(e){return g(e)}readMinSize(e,t,i){return V(e,t,i)}get arcadeRequired(){return!!this.valueExpression||(null!=this.minSize&&"object"==typeof this.minSize&&this.minSize.arcadeRequired||null!=this.maxSize&&"object"==typeof this.maxSize&&this.maxSize.arcadeRequired)}set stops(e){null==this.minDataValue&&null==this.maxDataValue&&null==this.minSize&&null==this.maxSize?e&&Array.isArray(e)&&(e=e.filter((e=>!!e))).sort(((e,t)=>e.value-t.value)):e&&(s.getLogger(this).warn("cannot set stops when one of minDataValue, maxDataValue, minSize or maxSize is not null."),e=null),this._set("stops",e)}get transformationType(){return y(this,this.inputValueType)}readValueExpression(e,t){return e||t.expression&&"$view.scale"}writeValueExpressionWebScene(e,i,s,r){if("$view.scale"===e){if(r?.messages){const e=this.index,i="string"==typeof e?e:`visualVariables[${e}]`;r.messages.push(new t("property:unsupported",this.type+"VisualVariable.valueExpression = '$view.scale' is not supported in Web Scene. Please remove this property to save the Web Scene.",{instance:this,propertyName:i+".valueExpression",context:r}))}}else i[s]=e}readValueUnit(e){return e?w.read(e):null}clone(){return new z({axis:this.axis,field:this.field,valueExpression:this.valueExpression,valueExpressionTitle:this.valueExpressionTitle,maxDataValue:this.maxDataValue,maxSize:c(this.maxSize)?this.maxSize.clone():this.maxSize,minDataValue:this.minDataValue,minSize:c(this.minSize)?this.minSize.clone():this.minSize,normalizationField:this.normalizationField,stops:this.stops?.map((e=>e.clone())),target:this.target,useSymbolValue:this.useSymbolValue,valueRepresentation:this.valueRepresentation,valueUnit:this.valueUnit,legendOptions:this.legendOptions?.clone()})}flipSizes(){if(this.transformationType===S.ClampedLinear){const{minSize:e,maxSize:t}=this;return this.minSize=t,this.maxSize=e,this}if(this.transformationType===S.Stops){const e=this.stops;if(!e)return this;const t=e.map((e=>e.size)).reverse(),i=e.length;for(let s=0;s<i;s++)e[s].size=t[s];return this}return this}getAttributeHash(){return`${super.getAttributeHash()}-${this.target}-${this.normalizationField}`}_interpolateData(){return this.stops?.map((e=>e.value||0))}};e([r({readOnly:!0})],f.prototype,"cache",null),e([r({type:v.apiValues,json:{type:v.jsonValues,origins:{"web-map":{read:!1}},read:v.read,write:v.write}})],f.prototype,"axis",void 0),e([r()],f.prototype,"index",null),e([r({type:String,readOnly:!0})],f.prototype,"inputValueType",null),e([r({type:h,json:{write:!0}})],f.prototype,"legendOptions",void 0),e([r({type:Number,value:null,json:{write:!0}})],f.prototype,"maxDataValue",null),e([r({type:Number,value:null,json:{write:!0}})],f.prototype,"maxSize",null),e([a("maxSize")],f.prototype,"castMaxSize",null),e([n("maxSize")],f.prototype,"readMaxSize",null),e([r({type:Number,value:null,json:{write:!0}})],f.prototype,"minDataValue",null),e([r({type:Number,value:null,json:{write:!0}})],f.prototype,"minSize",null),e([a("minSize")],f.prototype,"castMinSize",null),e([n("minSize")],f.prototype,"readMinSize",null),e([r({type:String,json:{write:!0}})],f.prototype,"normalizationField",void 0),e([r({readOnly:!0})],f.prototype,"arcadeRequired",null),e([r({type:String})],f.prototype,"scaleBy",void 0),e([r({type:[m],value:null,json:{write:!0}})],f.prototype,"stops",null),e([r({type:["outline"],json:{write:!0}})],f.prototype,"target",void 0),e([r({type:String,readOnly:!0})],f.prototype,"transformationType",null),e([r({type:["size"],json:{type:["sizeInfo"]}})],f.prototype,"type",void 0),e([r({type:Boolean,json:{write:!0,origins:{"web-map":{read:!1}}}})],f.prototype,"useSymbolValue",void 0),e([r({type:String,json:{write:!0}})],f.prototype,"valueExpression",void 0),e([n("valueExpression",["valueExpression","expression"])],f.prototype,"readValueExpression",null),e([l("web-scene","valueExpression")],f.prototype,"writeValueExpressionWebScene",null),e([r({type:["radius","diameter","area","width","distance"],json:{write:!0}})],f.prototype,"valueRepresentation",void 0),e([r({type:w.apiValues,json:{write:w.write,origins:{"web-map":{read:!1},"web-scene":{write:!0},"portal-item":{write:!0}}}})],f.prototype,"valueUnit",void 0),e([n("valueUnit")],f.prototype,"readValueUnit",null),f=z=e([o("esri.renderers.visualVariables.SizeVariable")],f);export{f as default};