UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 6.6 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"../../PopupTemplate.js";import n from"../../core/Error.js";import{fetchMessageBundle as o}from"../../intl/messages.js";import{substitute as i}from"../../intl/substitute.js";import t from"../../popup/ExpressionInfo.js";import r from"../../popup/FieldInfo.js";import s from"../../popup/support/FieldInfoFormat.js";import{getFieldInfo as f}from"./support/utils.js";import{getArcadeForPredominantCategoryAlias as a,fieldNamesFromFieldInfos as p,getArcadeForPredominantCategoryValue as l,getArcadeForPredominanceMargin as d,getArcadeForStrengthOfPredominance as m,getArcadeForOrderedFields as I,getArcadeForSumOfFields as u}from"../statistics/support/predominanceUtils.js";function c(e,n){return e.legendOptions?.title??n.competingFields}function x(e,n){return{fieldInfo:new r({fieldName:"expression/predominant-category"}),expressionInfo:new t({name:"predominant-category",title:n.predominantCategory,expression:a(e)})}}function g(e,n){const o=p(e);return{fieldInfo:new r({fieldName:"expression/predominant-value",format:new s({digitSeparator:!0,places:1})}),expressionInfo:new t({name:"predominant-value",title:n.predominantCategoryValue,expression:l(o),returnType:"number"})}}function y(e,n){const o=p(e);return{fieldInfo:new r({fieldName:"expression/predominant-margin",format:new s({digitSeparator:!0,places:0})}),expressionInfo:new t({name:"predominant-margin",title:n.marginOfVictory,expression:d(o),returnType:"number"})}}function b(e,n){const o=p(e);return{fieldInfo:new r({fieldName:"expression/predominant-strength",format:new s({digitSeparator:!0,places:0})}),expressionInfo:new t({name:"predominant-strength",title:n.strengthOfPredominance,expression:m(o),returnType:"number"})}}function w(e,n){return{fieldInfo:new r({fieldName:"expression/predominant-categories-list"}),expressionInfo:new t({name:"predominant-categories-list",title:n.listOfCategories,expression:I(e)})}}function N(e,n){const o=p(e);return{fieldInfo:new r({fieldName:"expression/predominant-total",format:new s({digitSeparator:!0,places:0})}),expressionInfo:new t({name:"predominant-total",title:n.sumOfCategories,expression:u(o),returnType:"number"})}}function C(n,o){const t=x(n.fieldInfos,o),r=new e({expressionInfos:[t.expressionInfo],fieldInfos:[t.fieldInfo],content:i(o.predominantCategoryContent,{expression:`<b>{${t.fieldInfo.fieldName}}</b>`})});return{name:"predominant-category",title:o.predominantCategory,value:r}}function h(n,o){const{fieldInfos:t}=n,r=x(t,o),s=g(t,o),f=new e({expressionInfos:[s.expressionInfo,r.expressionInfo],fieldInfos:[s.fieldInfo,r.fieldInfo],content:i(o.predominantCategoryValueContent,{expression1:`<b>{${r.fieldInfo.fieldName}}</b>`,expression2:`<b>{${s.fieldInfo.fieldName}}</b>`})});return{name:"predominant-category-value",title:o.predominantCategoryValue,value:f}}function $(n,o){const{fieldInfos:t}=n,r=x(t,o),s=g(t,o),f=y(t,o),a=new e({expressionInfos:[s.expressionInfo,r.expressionInfo,f.expressionInfo],fieldInfos:[s.fieldInfo,r.fieldInfo,f.fieldInfo],title:i(o.mostCommon,{expression:"{expression/predominant-category}"}),content:i(o.predominantCategoryValueMarginContent,{expression1:`<b>{${r.fieldInfo.fieldName}}</b>`,expression2:`<b>{${s.fieldInfo.fieldName}}</b>`,expression3:`<b>{${f.fieldInfo.fieldName}}</b>`})});return{name:"predominant-category-value-margin",title:o.marginOfVictory,value:a}}function v(n,o){const{fieldInfos:t}=n,r=x(t,o),s=g(t,o),f=b(t,o),a=new e({expressionInfos:[s.expressionInfo,r.expressionInfo,f.expressionInfo],fieldInfos:[s.fieldInfo,r.fieldInfo,f.fieldInfo],content:i(o.predominantCategoryStrengthContent,{expression1:`{${s.fieldInfo.fieldName}}`,expression2:`<b>{${r.fieldInfo.fieldName}}</b>`,expression3:`<b>{${f.fieldInfo.fieldName}}%</b>`})});return{name:"predominant-category-strength",title:o.strengthOfPredominance,value:a}}function j(n,o){const{renderer:t,fieldInfos:r}=n,s=x(r,o),f=g(r,o),a=b(r,o),p=w(r,o),l=new e({expressionInfos:[s.expressionInfo,f.expressionInfo,a.expressionInfo,p.expressionInfo],fieldInfos:[s.fieldInfo,f.fieldInfo,a.fieldInfo,p.fieldInfo],title:c(t,o),content:[{type:"text",text:i(o.predominantCategoryStrengthContent,{expression1:`{${f.fieldInfo.fieldName}}`,expression2:`<b>{${s.fieldInfo.fieldName}}</b>`,expression3:`<b>{${a.fieldInfo.fieldName}}%</b>`})},{type:"text",text:`{${p.fieldInfo.fieldName}}`}]});return{name:"predominant-categories-list",title:o.orderedListOfValues,value:l}}function S(n,o){const{fieldInfos:t}=n,r=x(t,o),s=g(t,o),f=b(t,o),a=N(t,o),p=new e({expressionInfos:[s.expressionInfo,r.expressionInfo,a.expressionInfo,f.expressionInfo],fieldInfos:[s.fieldInfo,r.fieldInfo,a.fieldInfo,f.fieldInfo],content:i(o.predominantCategoryTotalStrengthContent,{expression1:`{${s.fieldInfo.fieldName}}`,expression2:`<b>{${r.fieldInfo.fieldName}}</b>`,expression3:`<b>{${f.fieldInfo.fieldName}}%</b>`,expression4:`{${a.fieldInfo.fieldName}}`})});return{name:"predominant-category-total-strength",title:o.predominantCategoryWithTotalAndStrength,value:p}}function T(n,o){const{renderer:t,fieldInfos:r}=n,s=x(r,o),f=g(r,o),a=b(r,o),p=new e({expressionInfos:[f.expressionInfo,s.expressionInfo,a.expressionInfo],fieldInfos:[f.fieldInfo,s.fieldInfo,a.fieldInfo],title:c(t,o),content:[{type:"text",text:i(o.predominantCategoryStrengthContent,{expression1:`{${f.fieldInfo.fieldName}}`,expression2:`<b>{${s.fieldInfo.fieldName}}</b>`,expression3:`<b>{${a.fieldInfo.fieldName}}%</b>`})},{type:"media",mediaInfos:{type:"pie-chart",value:{fields:r.map((e=>e.fieldName))}}}]});return{name:"predominant-category-chart",title:o.predominantCategoryWithChart,value:p}}function O(e,o){const i=e.authoringInfo,t="predominance"===i?.type?i.fields:[];if(!t?.length)throw new n("predominance-popup:insufficient-info","unable to find input fields in authoringInfo");return t.map((e=>f(o,e)))}async function V(e){const{layer:o,renderer:i}=e;await o.load();const t=i??("renderer"in o?o.renderer:void 0);if("unique-value"!==t?.type)throw new n("predominance-popup:invalid-parameters","renderer.type must be 'unique-value'");return{renderer:t,fieldInfos:O(t,o)}}async function M(e){const[n,i]=await Promise.all([V(e),o("esri/smartMapping/t9n/smartMapping")]);return[C(n,i),h(n,i),$(n,i),S(n,i),j(n,i),v(n,i),T(n,i)]}async function P(e){const[n,i]=await Promise.all([V(e),o("esri/smartMapping/t9n/smartMapping")]),t=j(n,i),r=await M(e);return{primaryTemplate:t,secondaryTemplates:r.filter((e=>e.name!==t.name))}}export{M as getAllTemplates,P as getTemplates};