/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{clone as e}from"../../../core/lang.js";import r from"../../../symbols/CIMSymbol.js";function n(e){const{view:r,field:n,normalizationField:t,sizeStops:o,sizeByScaleEnabled:i}=e,{value:a,size:l}=o[0],{value:c,size:s}=o[1];let m,y=0;n&&(y=`$feature["${n}"]`,m=`\n      if(!HasValue($feature, "${n}")){\n        return 0;\n      }\n      $feature["${n}"];\n    `),t&&(y=`$feature["${n}"] / $feature["${t}"]`,m=`if(!HasValue($feature, "${n}") || !HasValue($feature, "${t}") || $feature["${t}"] <= 0){\n        return 0;\n      }\n      $feature["${n}"];\n      $feature["${t}"];`);return[{type:"CIMPrimitiveOverride",primitiveName:"reference-size-outer-ring",propertyName:"Size",valueExpressionInfo:{type:"CIMExpressionInfo",title:"Size in pixels of outer ring",expression:i?`\n      ${m}\n      var maxSize = ${s};\n      var referenceScale = ${r.scale};\n      return (maxSize * (referenceScale / $view.scale));\n    `:`${m}\n      return ${s}`,returnType:"Default"}},{type:"CIMPrimitiveOverride",primitiveName:"reference-size-inner-dot",propertyName:"Size",valueExpressionInfo:{type:"CIMExpressionInfo",title:"Size in pixels of inner ring",expression:`\n        ${m}\n        var value = ${y};\n\n        var referenceScale = ${r.scale};\n        var referenceScaleRatio = ${i?"(referenceScale / $view.scale)":1};\n        var maxSize = ${s} * referenceScaleRatio;\n        var minSize = ${l} * referenceScaleRatio;\n\n        var minDataValue = ${a};\n        var maxDataValue = ${c};\n\n        var ratio = Constrain(( value - minDataValue ) / ( maxDataValue - minDataValue ), 0, 1);\n\n        var innerDotSize = Constrain(maxSize * ratio, minSize, maxSize);\n        return innerDotSize;\n      `,returnType:"Default"}}]}function t(e){switch(e){case"circle":return{rings:[[[8.5,.2],[7.06,.33],[5.66,.7],[4.35,1.31],[3.16,2.14],[2.14,3.16],[1.31,4.35],[.7,5.66],[.33,7.06],[.2,8.5],[.33,9.94],[.7,11.34],[1.31,12.65],[2.14,13.84],[3.16,14.86],[4.35,15.69],[5.66,16.3],[7.06,16.67],[8.5,16.8],[9.94,16.67],[11.34,16.3],[12.65,15.69],[13.84,14.86],[14.86,13.84],[15.69,12.65],[16.3,11.34],[16.67,9.94],[16.8,8.5],[16.67,7.06],[16.3,5.66],[15.69,4.35],[14.86,3.16],[13.84,2.14],[12.65,1.31],[11.34,.7],[9.94,.33],[8.5,.2]]]};case"square":return{rings:[[[.5,.5],[.5,16.5],[16.5,16.5],[16.5,.5],[.5,.5]]]};case"diamond":return{rings:[[[8.5,.5],[.2,8.5],[8.5,16.5],[16.5,8.5],[8.5,.5]]]};case"hexagon-pointy":return{rings:[[[15.86,12.75],[15.86,4.25],[8.5,0],[1.14,4.25],[1.14,12.75],[8.5,17],[15.86,12.75]]]};case"hexagon-flat":return{rings:[[[12.75,15.86],[17,8.5],[12.75,1.14],[4.25,1.14],[0,8.5],[4.25,15.86],[12.75,15.86]]]}}}function o(e){const{type:r,color:n,colorLocked:o}=e;return{type:"CIMVectorMarker",enable:!0,colorLocked:!1,anchorPoint:{x:0,y:0},anchorPointUnits:"Relative",primitiveName:"reference-size-outer-ring",frame:{xmin:0,ymin:0,xmax:17,ymax:17},markerGraphics:[{type:"CIMMarkerGraphic",geometry:t(r),symbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidFill",enable:!0,color:n.toArray(),colorLocked:!!o,effects:[{type:"CIMGeometricEffectDonut",width:.75}]}]}}],scaleSymbolsProportionally:!1,respectFrame:!0,markerPlacement:{type:"CIMMarkerPlacementPolygonCenter",placePerPart:!1,method:"OnPolygon",offsetX:0,offsetY:0,clipAtBoundary:!1},size:20}}function i(e){const{type:r,color:n}=e;return{type:"CIMVectorMarker",enable:!0,anchorPoint:{x:0,y:0},anchorPointUnits:"Relative",primitiveName:"reference-size-inner-dot",frame:{xmin:0,ymin:0,xmax:17,ymax:17},markerGraphics:[{type:"CIMMarkerGraphic",geometry:t(r),symbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidFill",enable:!0,color:n.toArray()}]}}],scaleSymbolsProportionally:!0,respectFrame:!0,markerPlacement:{type:"CIMMarkerPlacementPolygonCenter",placePerPart:!1,method:"OnPolygon",offsetX:0,offsetY:0,clipAtBoundary:!1},size:10}}function a(e){const{primitiveOverrides:n}=e;return new r({data:{type:"CIMSymbolReference",symbol:{type:"CIMPolygonSymbol",symbolLayers:[o(e),i(e)]},primitiveOverrides:n}})}function l(e){return"CIMVectorMarker"===e?.type?e.markerGraphics?.[0]:void 0}function c(e){return"CIMPolygonSymbol"===e?.symbol?.type?e.symbol.symbolLayers?.[0]:void 0}function s(e,r){"CIMVectorMarker"===e?.type&&null!=r&&(e.size=r)}function m(e,r){const n=l(e);n&&null!=r&&(n.geometry=t(r))}function y(e,r){const n=c(l(e));n&&null!=r&&(n.color=r.toArray())}function u(e,r,n){const t=c(l(e));t&&null!=r&&n&&(t.colorLocked=r)}function f(r,n){const{outerRingSize:t,innerDotSize:o,type:i,color:a,colorLocked:l,primitiveOverrides:c}=n,f="CIMPolygonSymbol"===r.data.symbol?.type?r.data.symbol.symbolLayers:null;if(2===f?.length)for(const e of f){const r="reference-size-outer-ring"===e.primitiveName;s(e,r?t:o),m(e,i),y(e,a),u(e,l,r)}return null!=t&&null!=o&&(r.data.primitiveOverrides=null),void 0!==c&&(r.data.primitiveOverrides=e(c)),r}export{n as createPrimitiveOverrides,a as createReferenceSizeSymbol,f as updateReferenceSizeSymbol};
