UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

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