UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 5.2 kB
import e from"../../../Color.js";import{isSymbol3D as l}from"../../../symbols.js";import{round as t,numDigits as o,percentChange as s}from"../../../renderers/support/numberUtils.js";import{applyCIMSymbolColor as n}from"../../../symbols/support/cimSymbolUtils.js";import{isVolumetricSymbol as i,getSymbolOutlineSize as r}from"../../../symbols/support/utils.js";import{getSymbolForFlowRenderer as a,createStopLabel as u}from"./utils.js";import"../../support/widgetUtils.js";import{isDarkTheme as c}from"../../../support/themeUtils.js";import m from"../../../symbols/SimpleMarkerSymbol.js";import f from"../../../symbols/SimpleLineSymbol.js";const p=30,y=12,b=[255,255,255],h=[200,200,200],d=[128,128,128],w=20,g=5;function S(e){return"esri.symbols.SimpleMarkerSymbol"===e.declaredClass}function v(e){return"esri.symbols.PictureMarkerSymbol"===e.declaredClass}function z(e){return"esri.symbols.SimpleLineSymbol"===e.declaredClass}function j(e){return"esri.symbols.TextSymbol"===e.declaredClass}function V(e,l){const t=e.length-1;return e.map(((e,o)=>u(e,o,t,l)))}async function k(e,l,o,s,n,a,u){const c=l.legendOptions,m=c&&c.customValues,f=u||await U(e,o),p=!!f,y=!!m,b=null!=l.minSize&&null!=l.maxSize,h=l.stops&&l.stops.length>1,d=!!l.target;if(!p||!y&&!(b||h&&!d))return;const w=i(f);let g=null,S=null,v=null;S=w&&!h?t([l.minDataValue,l.maxDataValue]):m||await D(l,f,s,n);const z=e?.authoringInfo,j="univariate-color-size"===z?.type,k=j&&"above-and-below"===z?.univariateTheme;if(!S&&h&&(S=l.stops.map((e=>e.value)),g=l.stops.some((e=>!!e.label)),"flow"===e.type&&(S=t(S)),g&&(v=l.stops.map((e=>e.label)))),w&&S?.length>2&&!k&&(S=[S[0],S[S.length-1]]),!S)return null;j&&5!==S?.length&&(S=E({minSize:S[0],maxSize:S[S.length-1]}));const C=w?x(e,S):null,I=r(f),M=g?null:V(S,a);return(await Promise.all(S.map((async(t,o)=>{const i=w?C[o]:await B(l,f,t,s,n);return{value:t,symbol:P(k&&"class-breaks"===e.type?L(e,o):f,i),label:g?v[o]:M[o],size:i,outlineSize:I}})))).reverse()}function x(e,l){const t=e?.authoringInfo,o="univariate-color-size"===t?.type;let s=[y,p];if(o){const e=l[0],t=l[l.length-1],o=y,n=p;s=l.map((l=>o+(l-e)/(t-e)*(n-o)))}return o&&"below"===t?.univariateTheme&&s.reverse(),s}function L(e,l){const t=e.classBreakInfos,o=t.length,s=o<2||!(l>=2)?t[0].symbol.clone():t[o-1].symbol.clone();return e.visualVariables.some((e=>"color"===e.type))&&(s.type.includes("3d")?I(s):M(s)),s}async function U(e,l){if("flow"===e.type)return a(e,l);if("pie-chart"===e.type)return new m({color:null,outline:e.outline?.width?e.outline:new f});let t=null,o=null;if("simple"===e.type)t=e.symbol;else if("class-breaks"===e.type){const l=e.classBreakInfos;t=l&&l[0]&&l[0].symbol,o=l.length>1}else if("unique-value"===e.type){const l=e.uniqueValueInfos;t=l&&l[0]&&l[0].symbol,o=l.length>1}return!t||C(t)?null:(t=t.clone(),(l||o)&&(t.type.includes("3d")?I(t):M(t)),t)}function C(e){if(e){if(l(e)){return!!e.symbolLayers&&e.symbolLayers.some((e=>e&&"fill"===e.type))}return e.type.includes("fill")}return!1}function I(e){"line-3d"===e.type?e.symbolLayers.forEach((e=>{e.material={color:d}})):e.symbolLayers.forEach((e=>{"icon"!==e.type||e.resource&&e.resource.href?e.material={color:h}:(e.material={color:b},e.outline={color:d,size:1.5})}))}function M(l){const t=c();if("cim"===l.type)n(l,new e(h));else if(l.type.includes("line"))l.color=d;else if(l.color=t?d:b,"simple-marker"===l.type)if(l.outline){const e=l.outline?.color?.toHex();"#ffffff"===e&&(l.outline.color=d)}else l.outline={color:d,width:1.5}}async function D(e,l,o,s){const n=(await import("../../../renderers/visualVariables/support/visualVariableUtils.js")).getSizeRangeAtScale(e,o,s),i=n&&E(n);if(!n&&!i)return;let r=i.map((l=>T(l,e,n)));r=t(r);for(let t=1;t<r.length-1;t++){const n=await q(e,l,r[t],r[t-1],o,s);n&&(r[t]=n[0],i[t]=n[1])}return r}function E(e){const l=e.minSize,t=e.maxSize,o=g,s=(t-l)/(o-1),n=[];for(let i=0;i<o;i++)n.push(l+s*i);return n}function T(e,l,t){const o=t.minSize,s=t.maxSize,n=l.minDataValue,i=l.maxDataValue;let r=null;if(e<=o)r=n;else if(e>=s)r=i;else{r=(e-o)/(s-o)*(i-n)+n}return r}async function q(e,l,n,i,r,a){const u=await B(e,l,n,r,a),c=await B(e,l,i,r,a),m=o(n),f=m.fractional,p=w;let y=m.integer,b=null,h=null;n>0&&n<1&&(b=10**f,y=o(n*=b).integer);for(let o=y-1;o>=0;o--){const i=10**o;let m=Math.floor(n/i)*i,f=Math.ceil(n/i)*i;null!=b&&(m/=b,f/=b);let y=(m+f)/2;[,y]=t([m,y,f],{indexes:[1]});const d=await B(e,l,m,r,a),w=await B(e,l,f,r,a),g=await B(e,l,y,r,a),S=s(u,d,c,null),v=s(u,w,c,null),z=s(u,g,c,null);let j=S.previous<=p,V=v.previous<=p;if(j&&V&&(S.previous<=v.previous?(j=!0,V=!1):(V=!0,j=!1)),j?h=[m,d]:V?h=[f,w]:z.previous<=p&&(h=[y,g]),h)break}return h}async function B(e,l,t,o,s){const{getSize:n}=await import("../../../renderers/visualVariables/support/visualVariableUtils.js");return n(e,t,{scale:o,view:s,shape:"simple-marker"===l.type?l.style:null})}function P(e,t){const o=e.clone();if(l(o))i(o)||o.symbolLayers.forEach((e=>{"fill"!==e.type&&(e.size=t)}));else if(S(o))o.size=t;else if(v(o)){const e=o.width,l=o.height;o.height=t,o.width=t*(e/l)}else z(o)?o.width=t:j(o)&&o.font&&(o.font.size=t);return o}export{p as REAL_WORLD_MAX_SIZE,y as REAL_WORLD_MIN_SIZE,k as getRampStops};