@bino-bi/bn-template-engine 1.0.0-alpha.17 → 1.0.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
- package/dist/bn-template-engine/p-0107f0cc.entry.js +1 -0
- package/dist/bn-template-engine/p-209351c9.entry.js +1 -0
- package/dist/bn-template-engine/p-22d0fb7a.entry.js +1 -0
- package/dist/bn-template-engine/p-2e6dc267.entry.js +1 -0
- package/dist/bn-template-engine/p-485d23d7.entry.js +1 -0
- package/dist/bn-template-engine/p-5651417d.entry.js +1 -0
- package/dist/bn-template-engine/p-5bfdc1e5.entry.js +1 -0
- package/dist/bn-template-engine/p-6b75762d.entry.js +1 -0
- package/dist/bn-template-engine/{p-1a1fd8eb.entry.js → p-7bdc0e28.entry.js} +1 -1
- package/dist/bn-template-engine/p-9879c9b2.entry.js +1 -0
- package/dist/bn-template-engine/p-BWKdb9ym.js +1 -0
- package/dist/bn-template-engine/{p-CIXlJoMr.js → p-BZV1b5VH.js} +1 -1
- package/dist/bn-template-engine/p-Bdfxd_Ke.js +1 -0
- package/dist/bn-template-engine/p-BqhIhYr1.js +1 -0
- package/dist/bn-template-engine/p-C0Pwqx-O.js +1 -0
- package/dist/bn-template-engine/{p-44L8rZSd.js → p-CBqUr7I8.js} +1 -1
- package/dist/bn-template-engine/{p-COXiPUfj.js → p-CPzF3Q2m.js} +1 -1
- package/dist/bn-template-engine/{p-DHibUOw5.js → p-CiudZRQr.js} +1 -1
- package/dist/bn-template-engine/{p-B2KOyHRY.js → p-Dg9OcXAO.js} +1 -1
- package/dist/bn-template-engine/p-DsTzlzxQ.js +1 -0
- package/dist/bn-template-engine/p-X6CxL6W-.js +1 -0
- package/dist/bn-template-engine/p-a130cb43.entry.js +1 -0
- package/dist/bn-template-engine/p-aakBGfzL.js +1 -0
- package/dist/bn-template-engine/p-dc745c32.entry.js +1 -0
- package/dist/bn-template-engine/p-e96da91f.entry.js +1 -0
- package/dist/bn-template-engine/{p-d3fc17ee.entry.js → p-f3d1fa06.entry.js} +1 -1
- package/dist/bn-template-engine/p-fcb43f2c.entry.js +1 -0
- package/dist/bn-template-engine/p-rdqTC0_5.js +1 -0
- package/dist/cjs/{AxisConfig-B_GMRfX_.js → AxisConfig-VnVelfSV.js} +1 -1
- package/dist/cjs/LabelCollisionManager-nfD5P__k.js +412 -0
- package/dist/cjs/NumericScale-BAyYXpKL.js +107 -0
- package/dist/cjs/Order-DobBozQC.js +87 -0
- package/dist/cjs/{LabelCollisionManager-8HGn9W0V.js → SVGStyle-BQOmGWLX.js} +2 -409
- package/dist/cjs/SVGVariancesStyleGroup-DCGfHrqh.js +50 -0
- package/dist/cjs/{VarianceMeasure-DEOzP-XZ.js → VarianceMeasure-NY9yhiNV.js} +1 -1
- package/dist/cjs/{XYChartDataRow-CDl1Ofnv.js → XYChartDataRow-B7OKrAcC.js} +7 -111
- package/dist/cjs/bn-asset_21.cjs.entry.js +221 -263
- package/dist/cjs/bn-chart-bubble.cjs.entry.js +8 -7
- package/dist/cjs/bn-chart-bullet.cjs.entry.js +785 -0
- package/dist/cjs/bn-chart-scatter.cjs.entry.js +8 -7
- package/dist/cjs/bn-grid.cjs.entry.js +5 -4
- package/dist/cjs/bn-image.cjs.entry.js +5 -4
- package/dist/cjs/bn-internationalization.cjs.entry.js +2 -2
- package/dist/cjs/bn-ruleset.cjs.entry.js +2 -2
- package/dist/cjs/bn-template-engine.cjs.js +1 -1
- package/dist/cjs/bn-template.cjs.entry.js +1 -1
- package/dist/cjs/bn-text.cjs.entry.js +6 -5
- package/dist/cjs/bn-tree.cjs.entry.js +4 -3
- package/dist/cjs/{context-protocol-CIuyJKkK.js → context-protocol-BDrMkhc4.js} +66 -0
- package/dist/cjs/editor-companion.cjs.entry.js +2 -2
- package/dist/cjs/ibcs-chart-bubble.cjs.entry.js +20 -18
- package/dist/cjs/ibcs-chart-bullet.cjs.entry.js +673 -0
- package/dist/cjs/ibcs-chart-scatter.cjs.entry.js +19 -17
- package/dist/cjs/{layoutObserver-CJWRV_y6.js → layoutObserver-p0wXIWFg.js} +2 -2
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{scaling-B4UPXivZ.js → scaling-BmqxcNOf.js} +1 -1
- package/dist/cjs/{withScalingGroup-D832DQKp.js → withScalingGroup-BmcRlWBs.js} +1 -1
- package/dist/cjs/{withStyled-COxuhL-N.js → withStyled-CRiC9fzc.js} +5 -86
- package/dist/collection/collection-manifest.json +2 -0
- package/dist/collection/components/bn-chart-bullet/bn-chart-bullet.css +10 -0
- package/dist/collection/components/bn-chart-bullet/bn-chart-bullet.js +1014 -0
- package/dist/collection/components/bn-chart-bullet/ibcs-chart-bullet.css +9 -0
- package/dist/collection/components/bn-chart-bullet/ibcs-chart-bullet.js +538 -0
- package/dist/collection/components/bn-chart-bullet/utils/BulletChart.js +440 -0
- package/dist/collection/components/bn-chart-bullet/utils/model/BulletChartStyle.js +132 -0
- package/dist/collection/components/bn-chart-bullet/utils/model/BulletConfig.js +89 -0
- package/dist/collection/components/bn-chart-bullet/utils/model/index.js +2 -0
- package/dist/collection/components/bn-chart-scatter/bn-chart-scatter.js +1 -1
- package/dist/collection/components/bn-chart-structure/bn-chart-structure.js +1 -1
- package/dist/collection/components/bn-chart-time/bn-chart-time.js +1 -1
- package/dist/collection/components/bn-component-style/bn-component-style.js +1 -1
- package/dist/collection/components/bn-context/bn-context.js +1 -1
- package/dist/collection/components/bn-dataset/bn-dataset.js +1 -1
- package/dist/collection/components/bn-datasource/bn-datasource.js +1 -1
- package/dist/collection/components/bn-footer/bn-footer.js +1 -1
- package/dist/collection/components/bn-grid/bn-grid.js +1 -1
- package/dist/collection/components/bn-image/bn-image.js +1 -1
- package/dist/collection/components/bn-internationalization/bn-internationalization.js +1 -1
- package/dist/collection/components/bn-layout-card/bn-layout-card.js +1 -1
- package/dist/collection/components/bn-layout-page/bn-layout-page.js +1 -1
- package/dist/collection/components/bn-message/bn-message.js +1 -1
- package/dist/collection/components/bn-page/bn-page.js +1 -1
- package/dist/collection/components/bn-ruleset/bn-ruleset.js +1 -1
- package/dist/collection/components/bn-scaling-group/bn-scaling-group.js +1 -1
- package/dist/collection/components/bn-table/bn-table.js +1 -1
- package/dist/collection/components/bn-template/bn-template.js +1 -1
- package/dist/collection/components/bn-text/bn-text.js +1 -1
- package/dist/collection/components/bn-title/bn-title.js +1 -1
- package/dist/collection/components/bn-title/ibcs-title/ibcs-title.js +1 -1
- package/dist/collection/components/editor-companion/editor-companion.js +1 -1
- package/dist/collection/stores/componentStyles.js +38 -0
- package/dist/collection/stores/internationalization.js +28 -0
- package/dist/components/NumericScale.js +1 -0
- package/dist/components/Order.js +1 -1
- package/dist/components/XYChartDataRow.js +1 -1
- package/dist/components/bn-chart-bullet.d.ts +11 -0
- package/dist/components/bn-chart-bullet.js +1 -0
- package/dist/components/bn-chart-scatter.js +1 -1
- package/dist/components/bn-chart-structure.js +1 -1
- package/dist/components/bn-chart-time.js +1 -1
- package/dist/components/bn-component-style.js +1 -1
- package/dist/components/bn-context.js +1 -1
- package/dist/components/bn-dataset.js +1 -1
- package/dist/components/bn-datasource.js +1 -1
- package/dist/components/bn-footer2.js +1 -1
- package/dist/components/bn-grid.js +1 -1
- package/dist/components/bn-image.js +1 -1
- package/dist/components/bn-internationalization.js +1 -1
- package/dist/components/bn-layout-card.js +1 -1
- package/dist/components/bn-layout-page.js +1 -1
- package/dist/components/bn-message2.js +1 -1
- package/dist/components/bn-page2.js +1 -1
- package/dist/components/bn-ruleset.js +1 -1
- package/dist/components/bn-scaling-group.js +1 -1
- package/dist/components/bn-table.js +1 -1
- package/dist/components/bn-template.js +1 -1
- package/dist/components/bn-text.js +1 -1
- package/dist/components/bn-title2.js +1 -1
- package/dist/components/context-protocol.js +1 -1
- package/dist/components/editor-companion.js +1 -1
- package/dist/components/ibcs-chart-bubble2.js +1 -1
- package/dist/components/ibcs-chart-bullet.d.ts +11 -0
- package/dist/components/ibcs-chart-bullet.js +1 -0
- package/dist/components/ibcs-chart-bullet2.js +1 -0
- package/dist/components/ibcs-chart-scatter2.js +1 -1
- package/dist/components/ibcs-chart-structure2.js +1 -1
- package/dist/components/ibcs-chart-time2.js +1 -1
- package/dist/components/ibcs-table2.js +1 -1
- package/dist/components/ibcs-title2.js +1 -1
- package/dist/components/main.js +1 -0
- package/dist/components/stackColors.js +1 -1
- package/dist/esm/{AxisConfig-BwUQrme0.js → AxisConfig-C_zWCKlL.js} +1 -1
- package/dist/esm/LabelCollisionManager-8swVQHKA.js +404 -0
- package/dist/esm/NumericScale-DsTzlzxQ.js +105 -0
- package/dist/esm/Order-BPeWfygb.js +83 -0
- package/dist/esm/{LabelCollisionManager-DZP5Vl8T.js → SVGStyle-BxEDw9zh.js} +3 -403
- package/dist/esm/SVGVariancesStyleGroup-DRQYvSDD.js +48 -0
- package/dist/esm/{VarianceMeasure-Cxshx01h.js → VarianceMeasure-DnwNKspZ.js} +1 -1
- package/dist/esm/{XYChartDataRow-FF_VxRnF.js → XYChartDataRow-DeV4r-Wm.js} +5 -108
- package/dist/esm/bn-asset_21.entry.js +25 -67
- package/dist/esm/bn-chart-bubble.entry.js +8 -7
- package/dist/esm/bn-chart-bullet.entry.js +783 -0
- package/dist/esm/bn-chart-scatter.entry.js +8 -7
- package/dist/esm/bn-grid.entry.js +5 -4
- package/dist/esm/bn-image.entry.js +5 -4
- package/dist/esm/bn-internationalization.entry.js +2 -2
- package/dist/esm/bn-ruleset.entry.js +2 -2
- package/dist/esm/bn-template-engine.js +1 -1
- package/dist/esm/bn-template.entry.js +1 -1
- package/dist/esm/bn-text.entry.js +6 -5
- package/dist/esm/bn-tree.entry.js +4 -3
- package/dist/esm/{context-protocol-BNHTlllP.js → context-protocol-1Yj1uKvh.js} +66 -0
- package/dist/esm/editor-companion.entry.js +2 -2
- package/dist/esm/ibcs-chart-bubble.entry.js +6 -4
- package/dist/esm/ibcs-chart-bullet.entry.js +671 -0
- package/dist/esm/ibcs-chart-scatter.entry.js +6 -4
- package/dist/esm/{layoutObserver-D5FY_lQa.js → layoutObserver-DCbmpGrz.js} +2 -2
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{scaling-B7Pa0d_s.js → scaling-B_k50v9z.js} +1 -1
- package/dist/esm/{withScalingGroup-DBheBsP4.js → withScalingGroup-Br70pAv9.js} +1 -1
- package/dist/esm/{withStyled-DTvj2nar.js → withStyled-Br2DGTPs.js} +4 -83
- package/dist/types/components/bn-chart-bullet/bn-chart-bullet.d.ts +172 -0
- package/dist/types/components/bn-chart-bullet/ibcs-chart-bullet.d.ts +52 -0
- package/dist/types/components/bn-chart-bullet/utils/BulletChart.d.ts +91 -0
- package/dist/types/components/bn-chart-bullet/utils/model/BulletChartStyle.d.ts +70 -0
- package/dist/types/components/bn-chart-bullet/utils/model/BulletConfig.d.ts +43 -0
- package/dist/types/components/bn-chart-bullet/utils/model/index.d.ts +2 -0
- package/dist/types/components.d.ts +399 -4
- package/dist/types/stores/componentStyles.d.ts +20 -0
- package/package.json +1 -1
- package/dist/bn-template-engine/p-172499ac.entry.js +0 -1
- package/dist/bn-template-engine/p-19e65c04.entry.js +0 -1
- package/dist/bn-template-engine/p-2849c367.entry.js +0 -1
- package/dist/bn-template-engine/p-5dd11fcc.entry.js +0 -1
- package/dist/bn-template-engine/p-63f891d9.entry.js +0 -1
- package/dist/bn-template-engine/p-72f63181.entry.js +0 -1
- package/dist/bn-template-engine/p-836ad6f3.entry.js +0 -1
- package/dist/bn-template-engine/p-BnOTt2YD.js +0 -1
- package/dist/bn-template-engine/p-CDPTCKVx.js +0 -1
- package/dist/bn-template-engine/p-CPZIJpxn.js +0 -1
- package/dist/bn-template-engine/p-a50da0f0.entry.js +0 -1
- package/dist/bn-template-engine/p-a9a34fb2.entry.js +0 -1
- package/dist/bn-template-engine/p-b0369558.entry.js +0 -1
- package/dist/bn-template-engine/p-f8c46905.entry.js +0 -1
- package/dist/bn-template-engine/p-lIy3SJs2.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as t}from"./p-BZV1b5VH.js";class s{constructor(t,s,i){this.pos=t,this.neg=s,this.neu=i,this.needleHeadColour="#000000"}getSVGStyle(t){return"pos"===t?this.pos:"neg"===t?this.neg:this.neu}}class i{constructor(t){this.svgStyleAdapter=t}adapt(i){const h=new s(this.svgStyleAdapter.defaultPos(),this.svgStyleAdapter.defaultNeg(),this.svgStyleAdapter.defaultNeu());return t.isExisting(i.pos)&&(h.pos=this.svgStyleAdapter.adapt(i.pos)),t.isExisting(i.neg)&&(h.neg=this.svgStyleAdapter.adapt(i.neg)),t.isExisting(i.pp)&&(h.neu=this.svgStyleAdapter.adapt(i.neu)),t.isString(i.needleHeadColour)&&(h.needleHeadColour=i.needleHeadColour),h}default(){return new s(this.svgStyleAdapter.defaultPos(),this.svgStyleAdapter.defaultNeg(),this.svgStyleAdapter.defaultNeu())}}export{i as S}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as t,h as s,H as i,g as r}from"./p-B_d-jp99.js";import{w as a}from"./p-BjBz5cSL.js";import{g as e,f as n}from"./p-BqhIhYr1.js";import{w as o,a as h}from"./p-B4JfKvVT.js";const c=class{constructor(s){t(this,s),o(this),this.errors=h(this),a(this,(t=>{this.stores||(this.stores=e(this.element));try{const s=n(JSON.parse(t)),i=Object.assign({},this.stores.internationalization.get(this.namespace));i[this.code]=s,this.stores.internationalization.set(this.namespace,i)}catch(t){console.error(t)}}))}render(){return s(i,{key:"be9f6b1dc6c60ef5559ad47228e612ee74b0c80c"})}get element(){return r(this)}};c.style="bn-internationalization{display:none}";export{c as bn_internationalization}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as t,h as s,H as i,g as o}from"./p-B_d-jp99.js";import{w as r,b as e}from"./p-C0Pwqx-O.js";import{w as n,a}from"./p-B4JfKvVT.js";import{g as l}from"./p-BqhIhYr1.js";import"./p-BZV1b5VH.js";import"./p-Bdfxd_Ke.js";const f=class{constructor(s){t(this,s),r(this),n(this),this.errors=a(this),this.componentStyle=e(this)}connectedCallback(){this.stores=l(this.element)}getFontStyles(){return this.componentStyle((t=>{var s,i,o,r;return{"--bn-font-family":(null===(s=t.global)||void 0===s?void 0:s.fontFamily)||"'Noto Sans', sans-serif","--bn-font-size":`${(null===(i=t.global)||void 0===i?void 0:i.fontSizePx)||13.3333}px`,"--bn-font-color":(null===(o=t.global)||void 0===o?void 0:o.fontColor)||"#000000","--bn-font-background":(null===(r=t.global)||void 0===r?void 0:r.fontBackgroundColor)||"#ffffff"}}))}prepareAssetUrl(t){if(null==t||""===t)return"";const s=this.stores.assets.state;return t.startsWith("asset:")?s[t.substring(6)]:s[t]||t}render(){return s(i,{key:"cfa7e1b2978773f449f6596174edf51e4a61d4d7",style:this.getFontStyles()},null!=this.source&&""!==this.source?s("img",{src:this.prepareAssetUrl(this.source)}):"")}get element(){return o(this)}};f.style=":host{display:inline-block;position:relative;overflow:hidden}img{max-width:100%;height:auto}";export{f as bn_image}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as s,h as t,H as e,g as r}from"./p-B_d-jp99.js";import{w as
|
|
1
|
+
import{r as s,h as t,H as e,g as r}from"./p-B_d-jp99.js";import{w as i}from"./p-BjBz5cSL.js";import{g as a}from"./p-BqhIhYr1.js";import{w as o,a as h}from"./p-B4JfKvVT.js";const n=class{constructor(t){s(this,t),this.name="_default",o(this),this.errors=h(this),i(this,(s=>{this.stores||(this.stores=a(this.element));try{const t=JSON.parse(s);this.stores.ruleSets.set(this.name,t),this.errors.remove("JSON_PARSE")}catch(s){this.errors.addOrReplace({id:"JSON_PARSE",type:"error",message:`bn-ruleset: Failed to parse JSON body — ${s.message}`}),console.error(s)}}))}render(){return t(e,{key:"9049a4abd1e2b4ae4d28f56c4fe51919a89c0773"})}get element(){return r(this)}};n.style="bn-ruleset{display:none}";export{n as bn_ruleset}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as t,d as i,f as e,h as s,H as a,g as r}from"./p-B_d-jp99.js";import{a as n}from"./p-BqhIhYr1.js";import{w as l,a as o,g as h,p as u}from"./p-CPzF3Q2m.js";import{w as c,o as d}from"./p-CBqUr7I8.js";import{i as p,a as v,w as m,b as f,c as g}from"./p-C0Pwqx-O.js";import{w as y,a as b}from"./p-B4JfKvVT.js";import{w as x}from"./p-CiudZRQr.js";import{r as _,s as w}from"./p-BZV1b5VH.js";import{t as $,a as R,b as S,c as E,d as L,e as C,p as j}from"./p-Dg9OcXAO.js";import"./p-Bdfxd_Ke.js";const A={rowGroup:0,category:1,subCategory:2},O=["ac","pp","fc","pl"],z=class{validateX(t){this.validateMeasureSpec("x",t,!0,(t=>$(t)))}validateY(t){this.validateMeasureSpec("y",t,!0,(t=>$(t)))}validateSize(t){this.validateMeasureSpec("size",t,!0,(t=>R(t))),this.validateSizeScaling()}validateShare(t){this.validateMeasureSpec("share",t,!1,(t=>S(t)))}validateCompareWith(t){const i="ERR_compareWith";p(t)||O.includes(t.trim().toLowerCase())?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:`compare-with: invalid value '${t}' — expected ${O.join("/")}; ignored.`})}validateLevel(t){const i="ERR_level",e=["auto","category","subcategory"];p(t)||e.includes(t.trim().toLowerCase())?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:`level: invalid value '${t}' — expected ${e.join("/")}; using 'auto'.`})}validateSeriesLevel(t){const i="ERR_seriesLevel",e=["auto","rowgroup","category","none"];p(t)||e.includes(t.trim().toLowerCase())?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:`series-level: invalid value '${t}' — expected ${e.join("/")}; using 'auto'.`})}validateFacet(t){this.validateObjectSpec("facet",t,(t=>E(t)))}validateLabels(t){this.validateObjectSpec("labels",t,(t=>L(t,this.labelDefaults())))}validateLegend(t){this.validateObjectSpec("legend",t,(t=>C(t)))}validateAspect(t){const i="ERR_aspect";p(t)||null!==this.parseAspect(t)?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:`aspect: invalid value '${t}' — expected "w:h" (e.g. "16:9"); using the default.`})}validateLimit(t){const i="ERR_limit";v(t)&&Number(t)>=0?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:`limit: invalid value '${t}' — expected a non-negative integer; using 0.`})}validateScale(t){const i="ERR_scale";if(p(t))return void this.errors.remove(i);const{mode:e,factor:s}=u(t);"factor"===e&&(void 0===s||s<=0)?this.errors.addOrReplace({id:i,type:"warning",message:`scale: invalid value '${t}' — expected none/auto or a positive number.`}):this.errors.remove(i)}constructor(i){t(this,i),this.datasetName="",this.dataVersion=0,this.datasetMeta=null,this.appliedScaleFactor=1,this.layoutObserver=null,this.activeErrors=new Set,this.pixelPerUnitGroupMap=new Map,this.chartTitle="",this.filter="",this.share="",this.compareWith="",this.level="auto",this.seriesLevel="auto",this.facet="",this.labels="",this.legend="",this.aspect="16:9",this.limit=0,this._autoScaleGuard=!1,this._lastObservedWidth=0,this.translateForInner=(t,i)=>this.t(t,i),m(this),y(this),l(this,(t=>{this.datasetName=(null==t?void 0:t.startsWith("$"))?t.substring(1):t||"",this.dataVersion=this.dataVersion+1}),((t,i)=>{this.datasetMeta=i})),this.errors=b(this),x(this),this.componentStyle=f(this),this.ruleSetConfig=c(this),this.t=o(this).t}componentWillLoad(){this.validateX(this.x),this.validateY(this.y),this.validateSize(this.size),this.validateShare(this.share),this.validateCompareWith(this.compareWith),this.validateLevel(this.level),this.validateSeriesLevel(this.seriesLevel),this.validateFacet(this.facet),this.validateLabels(this.labels),this.validateLegend(this.legend),this.validateAspect(this.aspect),this.validateLimit(this.limit),this.validateScale(this.scale)}componentDidRender(){const{mode:t}=u(this.scale);if("auto"!==t&&"empty"!==t){this._autoScaleGuard=!1;const t=h(this.element),i="WARN_overflow";return void(t.width>0&&this.element.scrollWidth>t.width+1?this.errors.addOrReplace({id:i,type:"warning",message:"Chart exceeds available space and will be cut off. Check the scale value."}):this.errors.remove(i))}if(this._autoScaleGuard)return void(this._autoScaleGuard=!1);const e=this.element,{width:s}=h(e);if(s<=0)return;this._lastObservedWidth=s;const a=this.componentStyle((t=>{var i;return(null===(i=t.global)||void 0===i?void 0:i.fontSizePx)||13.3333})),r=e.scrollWidth,n=this.appliedScaleFactor;if(!Number.isFinite(r)||r<=s+1)return void this.errors.remove("AUTO_scale");const l=Math.max(.3,n*(s-1)/r);Math.abs(l-n)<.01||(e.style.setProperty("--bn-font-size",a*l+"px"),"empty"===t?this.errors.addOrReplace({id:"AUTO_scale",type:"warning",message:`Auto-scaled chart by factor ${l.toFixed(3)}`}):this.errors.remove("AUTO_scale"),this._autoScaleGuard=!0,i((()=>{this.appliedScaleFactor=l})))}componentDidLoad(){this.layoutObserver=d(this.element,(()=>{if(this._autoScaleGuard)return;const{width:t}=h(this.element);t>0&&Math.abs(t-this._lastObservedWidth)>2&&(this._lastObservedWidth=t,e(this))})),requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(this._autoScaleGuard)return;const{width:t}=h(this.element);this._lastObservedWidth=t,e(this)}))}))}disconnectedCallback(){var t;null===(t=this.layoutObserver)||void 0===t||t.disconnect(),this.layoutObserver=null}labelDefaults(){return{points:"all",values:!0,max:12}}setBlockingError(t,i){null===i?(this.errors.remove(t),this.activeErrors.delete(t)):(this.errors.addOrReplace({id:t,type:"error",message:i}),this.activeErrors.add(t))}hasBlockingErrors(){return this.activeErrors.size>0}validateSizeScaling(){var t;const i=null===(t=this.prepareSize())||void 0===t?void 0:t.group;this.setBlockingError("ERR_xy_scale_group",void 0===i||this.pixelPerUnitGroupMap.has(i)?null:this.t(".bubble-scale-group-unknown",{group:i}))}validateMeasureSpec(t,i,e,s){var a;const r=`ERR_xy_json_${t}`,n=`ERR_xy_measure_${t}`,l=`WARN_xy_fields_${t}`,{data:o,parseError:h}=j(i,"measure");if(h)return this.setBlockingError(r,this.t(".xy-prop-json",{prop:t})),this.setBlockingError(n,null),void this.errors.remove(l);if(this.setBlockingError(r,null),null===o)return this.setBlockingError(n,e?this.t(".xy-measure-invalid",{prop:t,measure:""}):null),void this.errors.remove(l);const u=null!==(a=o.measure)&&void 0!==a?a:"";g(u)?this.setBlockingError(n,null):this.setBlockingError(n,this.t(".xy-measure-invalid",{prop:t,measure:u})),this.reportSpecIssues(l,t,s(o))}validateObjectSpec(t,i,e){const s=`ERR_xy_json_${t}`,a=`WARN_xy_fields_${t}`,{data:r,parseError:n}=j(i,null);if(n)return this.setBlockingError(s,this.t(".xy-prop-json",{prop:t})),void this.errors.remove(a);this.setBlockingError(s,null),null!==r?this.reportSpecIssues(a,t,e(r)):this.errors.remove(a)}reportSpecIssues(t,i,e){const s=[];null!==e&&e.invalidFields.length>0&&s.push(`invalid: ${e.invalidFields.join(", ")}`),null!==e&&e.unknownKeys.length>0&&s.push(`unknown: ${e.unknownKeys.join(", ")}`),s.length>0?this.errors.addOrReplace({id:t,type:"warning",message:`${i}: ignored sub-fields (${s.join("; ")}).`}):this.errors.remove(t)}prepareAxis(t,i){const{data:e,parseError:s}=j(i,"measure");if(s||null===e)return null;const{config:a}=$(e);return null!==a&&g(a.measure)?(void 0!==a.min&&void 0!==a.max&&a.min>=a.max?(this.errors.addOrReplace({id:`WARN_xy_domain_${t}`,type:"warning",message:`${t}: min must be smaller than max; the override is ignored.`}),a.min=void 0,a.max=void 0):this.errors.remove(`WARN_xy_domain_${t}`),a):null}prepareSize(){const{data:t,parseError:i}=j(this.size,"measure");if(i||null===t)return null;const{config:e}=R(t);return null!==e&&g(e.measure)?e:null}prepareShare(){const{data:t,parseError:i}=j(this.share,"measure");if(i||null===t)return null;const{config:e}=S(t);return null!==e&&g(e.measure)?e:null}prepareCompareFamily(){var t;const i=null===(t=this.compareWith)||void 0===t?void 0:t.trim().toLowerCase();return O.includes(i)?i:null}prepareLabels(){const t=this.labelDefaults(),{data:i,parseError:e}=j(this.labels,null);return e||null===i?{points:t.points,values:t.values,max:t.max}:L(i,t).config}prepareLegend(){const{data:t,parseError:i}=j(this.legend,null);return i||null===t?{show:!0,position:"right"}:C(t).config}prepareFacet(){const{data:t,parseError:i}=j(this.facet,null);return i||null===t?null:E(t).config}preparePointLevel(){var t,i;const e=null===(t=this.level)||void 0===t?void 0:t.trim().toLowerCase();if("category"===e)return"category";if("subcategory"===e)return"subCategory";const s=null===(i=this.datasetMeta)||void 0===i?void 0:i.suggestedLevel;return"rowGroup"===s||"category"===s||"subCategory"===s?s:"category"}prepareSeriesLevel(t){var i;const e=null===(i=this.seriesLevel)||void 0===i?void 0:i.trim().toLowerCase();return"none"===e?null:"rowgroup"===e?"rowGroup":"category"===e||"subCategory"===t?"category":"category"===t?"rowGroup":null}validateCrossProp(t,i){const e=new Set;let s=!1;for(const i of t){if(void 0===i)continue;const t=_(i);null!==t&&("scenario"===t.kind?e.add(w(t.slot)):s=!0)}this.setBlockingError("ERR_xy_family",e.size>1?this.t(".xy-family-mixed",{families:[...e].join(", ")}):null);const a=this.prepareCompareFamily();this.setBlockingError("ERR_xy_compare_variance",null!==a&&s?this.t(".xy-compare-variance"):null),this.setBlockingError("ERR_xy_compare_family",null!==a&&1===e.size&&e.has(a)?`compare-with: '${a}' is already the primary scenario family.`:null);const r=this.preparePointLevel(),n=this.prepareSeriesLevel(r),l=null!==i?"rowgroup"===i.level?"rowGroup":"category":null;let o=null;if(null!==n&&A[n]>=A[r]&&(o=`series '${n}' vs point '${r}'`),null!==l){const t=null!=n?n:r;A[l]>=A[t]&&(o=`facet '${l}' vs '${t}'`)}this.setBlockingError("ERR_xy_level_order",null!==o?this.t(".xy-level-order",{detail:o}):null)}parseAspect(t){const i=/^\s*(\d+(?:\.\d+)?)\s*:\s*(\d+(?:\.\d+)?)\s*$/.exec(null!=t?t:"");if(null===i)return null;const e=Number(i[1]),s=Number(i[2]);return e<=0||s<=0?null:e/s}prepareAspect(){var t;return null!==(t=this.parseAspect(this.aspect))&&void 0!==t?t:16/9}prepareLimit(){const t=Math.floor(Number(this.limit)||0);return t>0?t:0}prepareSizeAreaPerUnit(){var t;const i=null===(t=this.prepareSize())||void 0===t?void 0:t.group;if(void 0===i||!this.pixelPerUnitGroupMap.has(i))return 0;const e=this.getEffectiveScaleFactor();return this.pixelPerUnitGroupMap.get(i)*e*e}i18nLocalKeys(){return["no-data","axis.in","legend.title","legend.size","legend.compare"]}prepareI18n(){const t=new Map(this.i18nLocalKeys().map((t=>[t,this.t(".".concat(t))]))),i=new Map(n.map((t=>[t,this.t("global.".concat(t))])));return new Map([...i.entries(),...t.entries()])}prepareStyle(){const t=this.getEffectiveScaleFactor();return this.componentStyle((i=>{const e=i.global.fontSizePx*t;return{scaleFactors:i["bn-chart-bubble"].scaleFactors,fontStyles:{font:`${e}px ${i.global.fontFamily}`,size:e,color:i.global.fontColor,background:i.global.fontBackgroundColor,leading:1.8},axisStyles:i["bn-chart-bubble"].axisStyles,seriesColors:i["bn-chart-bubble"].seriesColors,padding:i["bn-chart-bubble"].padding}}))}getEffectiveScaleFactor(){const{mode:t,factor:i}=u(this.scale);return"factor"===t?i:"auto"===t||"empty"===t?this.appliedScaleFactor:1}getFontStyles(){const t=this.getEffectiveScaleFactor();return this.componentStyle((i=>{var e,s,a,r;const n=(null===(e=i.global)||void 0===e?void 0:e.fontSizePx)||13.3333;return{"--bn-font-family":(null===(s=i.global)||void 0===s?void 0:s.fontFamily)||"'Noto Sans', sans-serif","--bn-font-size":n*t+"px","--bn-font-color":(null===(a=i.global)||void 0===a?void 0:a.fontColor)||"#000000","--bn-font-background":(null===(r=i.global)||void 0===r?void 0:r.fontBackgroundColor)||"#ffffff"}}))}getDataStructure(){const t={};for(const i of["ac","pp","fc","pl"])for(const e of[1,2,3,4])t[`${i}${e}`]={type:"number",isOptional:!0,description:""};const i={x:this.prepareAxis("x",this.x),y:this.prepareAxis("y",this.y),size:this.prepareSize(),share:this.prepareShare()};for(const[e,s]of Object.entries(i)){if(null===s)continue;const i=_(s.measure);null!==i&&("scenario"===i.kind?t[i.slot].description=`${e}: ${void 0!==s.label?s.label:s.measure}`:(t[i.measure.base].description=`${e}: ${s.measure} (base)`,t[i.measure.delta].description=`${e}: ${s.measure} (delta)`))}const e=this.prepareCompareFamily();if(null!==e)for(const[s,a]of Object.entries(i)){if(null===a||"share"===s)continue;const i=_(a.measure);if(null!==i&&"scenario"===i.kind){const a=e+i.slot.replace(/^[a-z]+/,"");""===t[a].description&&(t[a].description=`${s}: compareWith`)}}return{IBubbleChartDataRow:Object.assign({operation:{type:"string",isOptional:!1,description:""},rowGroup:{type:"string",isOptional:!0,description:""},rowGroupIndex:{type:"number",isOptional:!0,description:""},category:{type:"string",isOptional:!1,description:""},categoryIndex:{type:"number",isOptional:!1,description:""},subCategory:{type:"string",isOptional:!0,description:""},subCategoryIndex:{type:"number",isOptional:!0,description:""}},t)}}chartTemplate(){const t=this.prepareAxis("x",this.x),i=this.prepareAxis("y",this.y),e=this.prepareSize(),a=this.prepareShare(),r=this.prepareFacet();if(this.validateCrossProp([null==t?void 0:t.measure,null==i?void 0:i.measure,null==e?void 0:e.measure,null==a?void 0:a.measure],r),this.validateSizeScaling(),this.hasBlockingErrors()||null===t||null===i||null===e)return null;const n=this.preparePointLevel(),l=this.prepareI18n(),o=this.prepareStyle(),u=h(this.element).width;return s("ibcs-chart-bubble",{tableName:this.datasetName,dataVersion:this.dataVersion,chartTitle:this.chartTitle,x:t,y:i,size:e,share:a,compareFamily:this.prepareCompareFamily(),labels:this.prepareLabels(),legend:this.prepareLegend(),facet:r,pointLevel:n,seriesLevel:this.prepareSeriesLevel(n),aspect:this.prepareAspect(),limit:this.prepareLimit(),filter:this.filter,sizeAreaPerUnit:this.prepareSizeAreaPerUnit(),styles:o,i18n:l,containerWidth:u,ruleSetConfig:this.ruleSetConfig(),errors:this.errors,translate:this.translateForInner})}render(){return s(a,{key:"4191801f8d17e3241a9b681d9a7f0ab8a453bf64",style:this.getFontStyles()},s("div",{key:"a5284956b892a3647331532daae8d3251dbb6fad",class:"container"},this.chartTemplate()))}get element(){return r(this)}static get watchers(){return{x:[{validateX:0}],y:[{validateY:0}],size:[{validateSize:0}],share:[{validateShare:0}],compareWith:[{validateCompareWith:0}],level:[{validateLevel:0}],seriesLevel:[{validateSeriesLevel:0}],facet:[{validateFacet:0}],labels:[{validateLabels:0}],legend:[{validateLegend:0}],aspect:[{validateAspect:0}],limit:[{validateLimit:0}],scale:[{validateScale:0}]}}};z.style=":host{display:inline-block;position:relative;overflow:hidden}.container{display:flex;flex-direction:column}";export{z as bn_chart_bubble}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as t,a as s}from"./p-BZV1b5VH.js";import{X as i,D as n}from"./p-BqhIhYr1.js";import{L as o,H as e}from"./p-BWKdb9ym.js";import{F as r,C as h}from"./p-X6CxL6W-.js";class l{constructor(t,s,n,o){this.scaleFactors=t,this.fontStyles=s,this.axisStyles=n,this.padding=o,this.seriesColors=[...i]}}class a{constructor(t,s,i,n){this.scaleFactorsXYChartAdapter=t,this.fontStyleAdapter=s,this.svgStyleGroupAdapter=i,this.paddingAdapter=n}adapt(s){const i=this.default();return t.isExisting(s)&&(t.isExisting(s.scaleFactors)&&(i.scaleFactors=this.scaleFactorsXYChartAdapter.adapt(s.scaleFactors)),t.isExisting(s.fontStyles)&&(i.fontStyles=this.fontStyleAdapter.adapt(s.fontStyles)),t.isExisting(s.axisStyles)&&(i.axisStyles=this.svgStyleGroupAdapter.adapt(s.axisStyles)),t.isExisting(s.padding)&&(i.padding=this.paddingAdapter.adapt(s.padding)),Array.isArray(s.seriesColors)&&s.seriesColors.length>0&&(i.seriesColors=s.seriesColors)),i}default(){return new l(this.scaleFactorsXYChartAdapter.default(),this.fontStyleAdapter.default(),this.svgStyleGroupAdapter.default(),this.paddingAdapter.default())}}class c{constructor(){this.pointRadius=.4,this.bubbleMaxRadius=3.2,this.bubbleMinRadius=.35,this.axisTickLength=.35,this.labelToMark=.3,this.legendSwatch=.9,this.panelGap=1.6,this.refLineWidth=1,this.gridLineWidth=1}}class u{adapt(s){const i=new c;return t.isNumber(s.pointRadius)&&(i.pointRadius=s.pointRadius),t.isNumber(s.bubbleMaxRadius)&&(i.bubbleMaxRadius=s.bubbleMaxRadius),t.isNumber(s.bubbleMinRadius)&&(i.bubbleMinRadius=s.bubbleMinRadius),t.isNumber(s.axisTickLength)&&(i.axisTickLength=s.axisTickLength),t.isNumber(s.labelToMark)&&(i.labelToMark=s.labelToMark),t.isNumber(s.legendSwatch)&&(i.legendSwatch=s.legendSwatch),t.isNumber(s.panelGap)&&(i.panelGap=s.panelGap),t.isNumber(s.refLineWidth)&&(i.refLineWidth=s.refLineWidth),t.isNumber(s.gridLineWidth)&&(i.gridLineWidth=s.gridLineWidth),i}default(){return new c}}class f{constructor(t,s,i,n){this.count=t,this.drawingRect=i,this.panelGapPx=n,this.columns=Math.max(1,Math.min(null!=s?s:t,t)),this.rows=Math.max(1,Math.ceil(t/this.columns))}panelRect(t){const s=t%this.columns,i=Math.floor(t/this.columns),n=(this.drawingRect.width-(this.columns-1)*this.panelGapPx)/this.columns,o=(this.drawingRect.height-(this.rows-1)*this.panelGapPx)/this.rows;return{x:this.drawingRect.x+s*(n+this.panelGapPx),y:this.drawingRect.y+i*(o+this.panelGapPx),width:n,height:o}}isOuterLeft(t){return t%this.columns==0}isOuterBottom(t){return t+this.columns>=this.count}}const d=["n","ne","e","se","s","sw","w","nw"],v=Math.SQRT1_2;class w{constructor(t,s,i=new o){this.frame=t,this.gapPx=s,this.manager=i}registerMark(t,s,i){this.manager.register(this.bounds(t-i,s-i,2*i,2*i))}selectCandidates(t,s,i,n){if("none"===s)return{selected:[],unknownNames:[]};if("all"===s)return{selected:[...t],unknownNames:[]};if("auto"===s)return{selected:t.slice(0,i),unknownNames:[]};const o=new Set(s),e=t.filter((t=>o.has(n(t)))),r=new Set(e.map((t=>n(t))));return{selected:e,unknownNames:s.filter((t=>!r.has(t)))}}place(t){const s=[];for(const i of t)for(const t of d){const n=this.anchorBox(i,t);if(!this.insideFrame(n.x,n.y,i.width,i.height))continue;const o=this.bounds(n.x,n.y,i.width,i.height);if(!this.manager.hasCollision(o)){this.manager.register(o),s.push({candidate:i,x:n.x,y:n.y,anchor:t});break}}return s}anchorBox(t,s){const i=t.r+this.gapPx,n=t.r*v+.5*this.gapPx;switch(s){case"n":return{x:t.cx-t.width/2,y:t.cy-i-t.height};case"ne":return{x:t.cx+n,y:t.cy-n-t.height};case"e":return{x:t.cx+i,y:t.cy-t.height/2};case"se":return{x:t.cx+n,y:t.cy+n};case"s":return{x:t.cx-t.width/2,y:t.cy+i};case"sw":return{x:t.cx-n-t.width,y:t.cy+n};case"w":return{x:t.cx-i-t.width,y:t.cy-t.height/2};case"nw":return{x:t.cx-n-t.width,y:t.cy-n-t.height}}}insideFrame(t,s,i,n){return t>=this.frame.x&&s>=this.frame.y&&t+i<=this.frame.x+this.frame.width&&s+n<=this.frame.y+this.frame.height}bounds(t,s,i,n){return{x:t,y:s,width:i,height:n,pointIndex:0,preferredHook:e.Center}}}class m{constructor(t,s,i,n){this.xScale=t,this.yScale=s,this.rect=i,this.styles=n}get em(){return this.styles.fontStyles.size}fontFamily(){return this.styles.fontStyles.font.replace(/^[\d.]+px\s*/,"")}drawBands(t,s,i){var n,o,e,r;const h=this.styles.axisStyles.pl.fill;if(void 0!==s&&(void 0!==s.from||void 0!==s.to)){const i=this.xScale.scale(null!==(n=s.from)&&void 0!==n?n:this.xScale.domainMin),e=this.xScale.scale(null!==(o=s.to)&&void 0!==o?o:this.xScale.domainMax);t.rect(Math.abs(e-i),this.rect.height).move(Math.min(i,e),this.rect.y).fill(h)}if(void 0!==i&&(void 0!==i.from||void 0!==i.to)){const s=this.yScale.scale(null!==(e=i.from)&&void 0!==e?e:this.yScale.domainMin),n=this.yScale.scale(null!==(r=i.to)&&void 0!==r?r:this.yScale.domainMax);t.rect(this.rect.width,Math.abs(s-n)).move(this.rect.x,Math.min(s,n)).fill(h)}}drawGrid(t,s,i){const n={color:this.styles.axisStyles.pp.stroke,width:this.styles.scaleFactors.gridLineWidth};for(const i of s){const s=this.yScale.scale(i);t.line(this.rect.x,s,this.rect.x+this.rect.width,s).stroke(n)}if(void 0!==i)for(const s of i){const i=this.xScale.scale(s);t.line(i,this.rect.y,i,this.rect.y+this.rect.height).stroke(n)}}drawRefLines(t,s,i){const n={color:this.styles.axisStyles.fc.stroke,width:this.styles.scaleFactors.refLineWidth};if(void 0!==s){const i=this.xScale.scale(s);t.line(i,this.rect.y,i,this.rect.y+this.rect.height).stroke(n)}if(void 0!==i){const s=this.yScale.scale(i);t.line(this.rect.x,s,this.rect.x+this.rect.width,s).stroke(n)}}drawFrame(t){t.rect(this.rect.width,this.rect.height).move(this.rect.x,this.rect.y).fill("none").stroke({color:this.styles.axisStyles.ac.stroke,width:this.styles.scaleFactors.gridLineWidth})}drawTickLabels(t,s){const i=this.styles.scaleFactors.axisTickLength*this.em,n={size:this.styles.fontStyles.size,anchor:"start"},o=this.fontFamily(),e=this.styles.fontStyles.color;if(s.showXLabels)for(const h of s.ticksX){const l=this.xScale.scale(h);t.text(r.number(h,"decimal",s.xDecimals,s.xDecimals)).font(Object.assign(Object.assign({},n),{anchor:"middle"})).fill(e).attr({x:l,y:this.rect.y+this.rect.height+i+.8*this.em,"font-family":o})}if(s.showYLabels)for(const h of s.ticksY){const l=this.yScale.scale(h);t.text(r.number(h,"decimal",s.yDecimals,s.yDecimals)).font(Object.assign(Object.assign({},n),{anchor:"end"})).fill(e).attr({x:this.rect.x-i,y:l+.35*this.em,"font-family":o})}}drawPanelTitle(t,s){""!==s&&t.text(s).font({size:this.styles.fontStyles.size,weight:"bold",anchor:"start"}).fill(this.styles.fontStyles.color).attr({x:this.rect.x+.5*this.em,y:this.rect.y+1.2*this.em,"font-family":this.fontFamily()})}}class p{constructor(t){this.styles=t}get em(){return this.styles.fontStyles.size}get rowHeight(){return 1.5*this.em}get swatchSize(){return this.styles.scaleFactors.legendSwatch*this.em}textWidth(t,s=!1){const i=h(t,{font:this.styles.fontStyles.font,fontSize:this.styles.fontStyles.size+"px",fontWeight:s?"bold":"normal"}).width;return Number.isFinite(i)&&i>0?i:.6*t.length*this.em}rows(t){const s=[];t.sizeCaption.forEach(((t,i)=>{s.push({text:t,bold:0===i,treatment:null})})),null!==t.title&&""!==t.title&&s.push({text:t.title,bold:!0,treatment:null});for(const i of t.compareEntries)s.push({text:i.label,bold:!1,treatment:i.treatment});for(const i of t.entries)s.push({text:i.label,bold:!1,treatment:i.treatment});return s}measure(t,s){const i=this.rows(t);if(0===i.length)return{width:0,height:0};const n=this.swatchSize+.4*this.em;if("bottom"===s){let t=0;for(const s of i)t+=(null!==s.treatment?n:0)+this.textWidth(s.text,s.bold)+1.5*this.em;return{width:t,height:this.rowHeight}}let o=0;for(const t of i)o=Math.max(o,(null!==t.treatment?n:0)+this.textWidth(t.text,t.bold));return{width:o,height:i.length*this.rowHeight}}draw(t,s,i,n,o){const e=this.rows(s),r=this.swatchSize+.4*this.em;let h=i,l=n;for(const s of e){let i=h;if(null!==s.treatment){const n=t.circle(this.swatchSize).move(h,l+(this.rowHeight-this.swatchSize)/2).fill(s.treatment.hatch?"#ffffff":s.treatment.fill).stroke({color:"#ffffff"===s.treatment.stroke?s.treatment.fill:s.treatment.stroke,width:s.treatment.strokeWidth});void 0!==s.treatment.dasharray&&n.attr("stroke-dasharray",s.treatment.dasharray),i+=r}t.text(s.text).font({size:this.styles.fontStyles.size,weight:s.bold?"bold":"normal",anchor:"start"}).fill(this.styles.fontStyles.color).attr({x:i,y:l+this.rowHeight/2+.35*this.em,"font-family":this.fontFamily()}),"bottom"===o?h=i+this.textWidth(s.text,s.bold)+1.5*this.em:l+=this.rowHeight}}fontFamily(){return this.styles.fontStyles.font.replace(/^[\d.]+px\s*/,"")}}class x{constructor(){this.operation="+",this.custom={},this.counts={}}slotValue(s){const i=this[s];return t.isNumber(i)?i:null}slotHasNoData(t){return 0===this.counts[t]}}const y=["ac1","ac2","ac3","ac4","pp1","pp2","pp3","pp4","fc1","fc2","fc3","fc4","pl1","pl2","pl3","pl4"];class b{adapt(s){const i=new x;if(t.isOperator(s.operation)&&(i.operation=s.operation),t.isString(s.date)){const t=n.fromISO(s.date);i.date=t.isValid?t:void 0}t.isString(s.rowGroup)&&t.isNumber(s.rowGroupIndex)&&(i.rowGroup=s.rowGroup,i.rowGroupIndex=s.rowGroupIndex),t.isString(s.category)&&t.isNumber(s.categoryIndex)&&(i.category=s.category,i.categoryIndex=s.categoryIndex),t.isString(s.subCategory)&&t.isNumber(s.subCategoryIndex)&&(i.subCategory=s.subCategory,i.subCategoryIndex=s.subCategoryIndex),t.isString(s.columnGroup)&&t.isNumber(s.columnGroupIndex)&&(i.columnGroup=s.columnGroup,i.columnGroupIndex=s.columnGroupIndex),t.isString(s.columnSubGroup)&&t.isNumber(s.columnSubGroupIndex)&&(i.columnSubGroup=s.columnSubGroup,i.columnSubGroupIndex=s.columnSubGroupIndex);for(const n of y){t.isNumber(s[n])&&(i[n]=s[n]);const o=s[`${n}_cnt`];t.isNumber(o)&&(i.counts[n]=o)}for(const t of Object.keys(s))t.startsWith("_")&&(i.custom[t]=s[t]);return i}default(){return new x}}const g={rowGroup:"rowGroupIndex",category:"categoryIndex",subCategory:"subCategoryIndex"};function M(t,s){if("scenario"===s.kind)return{value:t.slotValue(s.slot),varianceNoData:!1};if(t.slotHasNoData(s.measure.base)||t.slotHasNoData(s.measure.delta))return{value:null,varianceNoData:!0};const i=s.measure.compute(t.slotValue(s.measure.base),t.slotValue(s.measure.delta));return{value:i,varianceNoData:null===i}}function N(t,s){return void 0!==s&&(void 0!==s.min&&t<s.min||void 0!==s.max&&t>s.max)}function S(t,i){return"scenario"!==t.kind?null:i+s(t.slot)}function k(t,s){var i,n,o,e,r,h,l,a,c;const u=[],f=new Set,d=[];let v=0,w=0,m=0,p=0,x=0;const y=new Map,b=new Map,k=new Map,j=null!==(i=s.compareFamily)&&void 0!==i?i:null,z=null!==j?S(s.measures.x,j):null,O=null!==j?S(s.measures.y,j):null,B=null!==j&&void 0!==s.measures.size?S(s.measures.size,j):null;for(const i of t){const t=i[s.pointLevel];if(null==t||""===t)continue;const u=null!==(n=null!==s.facetLevel?i[s.facetLevel]:"")&&void 0!==n?n:"",S=null!==(o=null!==s.seriesLevel?i[s.seriesLevel]:"")&&void 0!==o?o:"",j=`${u}\0${t}`;if(f.has(j)){v++,d.length<5&&!d.includes(t)&&d.push(t);continue}const C=M(i,s.measures.x),F=M(i,s.measures.y);if(null===C.value||null===F.value){(C.varianceNoData||F.varianceNoData)&&w++;continue}if(N(C.value,null===(e=s.domains)||void 0===e?void 0:e.x)||N(F.value,null===(r=s.domains)||void 0===r?void 0:r.y)){m++;continue}const D={name:t,seriesKey:S,facetKey:u,x:C.value,y:F.value,row:i};if(void 0!==s.measures.size){const t=M(i,s.measures.size).value;if(null===t)continue;if(t<0){p++;continue}D.size=t}if(void 0!==s.measures.share){const t=M(i,s.measures.share).value;null!==t&&(t<0||t>1?(x++,D.share=Math.min(1,Math.max(0,t))):D.share=t)}if(null!==z&&null!==O){const t=i.slotValue(z),n=i.slotValue(O),o=null!==B?i.slotValue(B):null;null===t||null===n||null!==B&&null===o?D.compare=null:N(t,null===(h=s.domains)||void 0===h?void 0:h.x)||N(n,null===(l=s.domains)||void 0===l?void 0:l.y)?(m++,D.compare=null):(D.compare={x:t,y:n},null!==o&&(D.compare.size=o))}if(f.add(j),k.has(u)||k.set(u,[]),k.get(u).push(D),null!==s.facetLevel){const t=i[g[s.facetLevel]];null!=t&&t<(null!==(a=y.get(u))&&void 0!==a?a:Number.POSITIVE_INFINITY)&&y.set(u,t)}if(null!==s.seriesLevel){const t=i[g[s.seriesLevel]];null!=t&&t<(null!==(c=b.get(S))&&void 0!==c?c:Number.POSITIVE_INFINITY)&&b.set(S,t)}}const C=[...k.keys()].sort(((t,s)=>{var i,n;return(null!==(i=y.get(t))&&void 0!==i?i:Number.MAX_SAFE_INTEGER)-(null!==(n=y.get(s))&&void 0!==n?n:Number.MAX_SAFE_INTEGER)})),F=C.map((t=>{let i=k.get(t);return s.limit>0&&i.length>s.limit&&(i="size"===s.limitBy?[...i].sort(((t,s)=>{var i,n;return(null!==(i=s.size)&&void 0!==i?i:0)-(null!==(n=t.size)&&void 0!==n?n:0)})).slice(0,s.limit):i.slice(0,s.limit)),{key:t,points:i}})),D=new Set;for(const t of F)for(const s of t.points)D.add(s.seriesKey);const H=[...D].sort(((t,s)=>{var i,n;return(null!==(i=b.get(t))&&void 0!==i?i:Number.MAX_SAFE_INTEGER)-(null!==(n=b.get(s))&&void 0!==n?n:Number.MAX_SAFE_INTEGER)})).map(((t,s)=>({key:t,index:s})));let I=null,L=0;for(const t of F)for(const s of t.points){L++;const t=[s.x],i=[s.y],n=void 0!==s.size?[s.size]:[];null!=s.compare&&(t.push(s.compare.x),i.push(s.compare.y),void 0!==s.compare.size&&n.push(s.compare.size)),null===I&&(I={xMin:t[0],xMax:t[0],yMin:i[0],yMax:i[0],sizeMax:0});for(const s of t)I.xMin=Math.min(I.xMin,s),I.xMax=Math.max(I.xMax,s);for(const t of i)I.yMin=Math.min(I.yMin,t),I.yMax=Math.max(I.yMax,t);for(const t of n)I.sizeMax=Math.max(I.sizeMax,t)}return v>0&&u.push({code:"xy-duplicate-point",data:{count:String(v),names:d.join(", ")}}),w>0&&u.push({code:"xy-variance-nodata",data:{count:String(w)}}),m>0&&u.push({code:"xy-point-clipped",data:{count:String(m)}}),p>0&&u.push({code:"bubble-size-negative",data:{count:String(p)}}),x>0&&u.push({code:"bubble-share-range",data:{count:String(x)}}),L>5e3&&u.push({code:"xy-point-budget",data:{count:String(L)}}),{facets:F,series:H,extents:I,warnings:u,totalPoints:L}}export{f as F,w as P,u as S,b as X,p as a,m as b,a as c,k as r}
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var SVGStyle = require('./SVGStyle-BQOmGWLX.js');
|
|
4
|
+
require('./VarianceMeasure-NY9yhiNV.js');
|
|
5
|
+
|
|
6
|
+
/** SI metric prefix for number scaling (e.g. prefix="M", value=1000000 divides displayed values by one million). */
|
|
7
|
+
class SiPrefix {
|
|
8
|
+
constructor(prefix = "", value = 1) {
|
|
9
|
+
this.prefix = prefix;
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Default fill colors cycled through for stacked chart segments. */
|
|
15
|
+
/**
|
|
16
|
+
* IBCS rendering order: back-to-front (PL behind FC behind PP behind AC).
|
|
17
|
+
* Used to ensure correct visual layering when scenarios overlap.
|
|
18
|
+
*/
|
|
19
|
+
const IBCS_LAYER_ORDER = ["pl", "fc", "pp", "ac"];
|
|
20
|
+
/** Strips the trailing numeric suffix from a scenario key (e.g. "ac1" -> "ac"). */
|
|
21
|
+
function getScenarioPrefix(scenario) {
|
|
22
|
+
return scenario.replace(/\d+$/, "");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns black or white text color for readable contrast against the given
|
|
26
|
+
* hex background, using the W3C relative luminance formula.
|
|
27
|
+
*/
|
|
28
|
+
function getContrastTextColor(hexFill) {
|
|
29
|
+
const r = parseInt(hexFill.slice(1, 3), 16);
|
|
30
|
+
const g = parseInt(hexFill.slice(3, 5), 16);
|
|
31
|
+
const b = parseInt(hexFill.slice(5, 7), 16);
|
|
32
|
+
return 0.299 * r + 0.587 * g + 0.114 * b > 128 ? "#000000" : "#ffffff";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// import { DataFormatDigits } from "../../../../utils/model/DataFormatDigits";
|
|
36
|
+
// import { SiPrefix } from "../../../../utils/model/SiPrefix";
|
|
37
|
+
/**
|
|
38
|
+
* Anchor point for label positioning relative to its coordinates.
|
|
39
|
+
* Vertical hooks control how the label is offset from its Y coordinate;
|
|
40
|
+
* horizontal hooks control text-anchor alignment (start/middle/end).
|
|
41
|
+
*/
|
|
42
|
+
exports.HookLocation = void 0;
|
|
43
|
+
(function (HookLocation) {
|
|
44
|
+
HookLocation[HookLocation["Left"] = 0] = "Left";
|
|
45
|
+
HookLocation[HookLocation["Center"] = 1] = "Center";
|
|
46
|
+
HookLocation[HookLocation["Right"] = 2] = "Right";
|
|
47
|
+
HookLocation[HookLocation["Top"] = 3] = "Top";
|
|
48
|
+
HookLocation[HookLocation["Bottom"] = 4] = "Bottom";
|
|
49
|
+
})(exports.HookLocation || (exports.HookLocation = {}));
|
|
50
|
+
/**
|
|
51
|
+
* SVG text label used across all chart elements (columns, needles, markers, axes).
|
|
52
|
+
*
|
|
53
|
+
* Handles numeric formatting via Formatter.number() with configurable type (decimal/percent),
|
|
54
|
+
* digit precision, and SI prefix scaling. Variance labels prepend a "+" sign for positive values.
|
|
55
|
+
*
|
|
56
|
+
* The label is drawn with a semi-transparent white background rectangle to ensure
|
|
57
|
+
* readability over chart geometry. For stacked segments, the background is omitted
|
|
58
|
+
* and text color is derived from the segment fill for contrast.
|
|
59
|
+
*
|
|
60
|
+
* Positioning uses a two-axis hook system: verticalHookLocation shifts the label
|
|
61
|
+
* above/below/centered on the Y coordinate, horizontalHookLocation sets the SVG
|
|
62
|
+
* text-anchor (start/middle/end) relative to X.
|
|
63
|
+
*/
|
|
64
|
+
class Label {
|
|
65
|
+
constructor(parent, xPosition, yPosition, groupPrefix, value, styles, verticalHookLocation, horizontalHookLocation) {
|
|
66
|
+
this.ID_SCENARIOLABEL = "Label";
|
|
67
|
+
this.CSS_CATEGORIES = "categories";
|
|
68
|
+
this.isRelativeLabel = false;
|
|
69
|
+
this.segmentFillColor = null;
|
|
70
|
+
this.x = xPosition;
|
|
71
|
+
this.y = yPosition;
|
|
72
|
+
this.value = value;
|
|
73
|
+
this.group = parent.group().id(this.createElementID(parent.toString(), groupPrefix));
|
|
74
|
+
this.styles = styles;
|
|
75
|
+
this.isVarianceLabel = false;
|
|
76
|
+
this.verticalHookLocation = verticalHookLocation || exports.HookLocation.Top;
|
|
77
|
+
this.horizontalHookLocation = horizontalHookLocation || exports.HookLocation.Left;
|
|
78
|
+
}
|
|
79
|
+
setToVarianceLabel() {
|
|
80
|
+
this.isVarianceLabel = true;
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
setToRelativeVarianceLabel() {
|
|
84
|
+
this.isVarianceLabel = true;
|
|
85
|
+
this.isRelativeLabel = true;
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
setSegmentFill(color) {
|
|
89
|
+
this.segmentFillColor = color;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
updateGroup(newGroup) {
|
|
93
|
+
this.group = newGroup;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
draw(displayLabel = true, dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
|
|
97
|
+
if (this.isEmpty()) {
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
const label = this.group;
|
|
101
|
+
let valueStr;
|
|
102
|
+
let prefix = "";
|
|
103
|
+
if (Number.isNaN(Number(this.value)) === false) {
|
|
104
|
+
const value = this.value;
|
|
105
|
+
let type = "percent";
|
|
106
|
+
let digits = dataFormatDigits.percent;
|
|
107
|
+
let digitsMin = dataFormatDigits.percent;
|
|
108
|
+
let scale = 1;
|
|
109
|
+
if (this.isRelativeLabel === false) {
|
|
110
|
+
digits = dataFormatDigits.decimal;
|
|
111
|
+
digitsMin = dataFormatDigits.decimal;
|
|
112
|
+
scale = measureScale.value;
|
|
113
|
+
type = "decimal";
|
|
114
|
+
}
|
|
115
|
+
valueStr = SVGStyle.Formatter.number(Number(value), type, digits, digitsMin, scale);
|
|
116
|
+
if (this.isVarianceLabel && Number(this.value) >= 0) {
|
|
117
|
+
prefix = "+";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
valueStr = "" + this.value;
|
|
122
|
+
// displayLabel = false;
|
|
123
|
+
}
|
|
124
|
+
const labelStr = prefix + valueStr;
|
|
125
|
+
const text = this.drawLabel(label, labelStr);
|
|
126
|
+
if (displayLabel === false) {
|
|
127
|
+
text.addClass("hide");
|
|
128
|
+
label.addClass("hide");
|
|
129
|
+
}
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
isEmpty() {
|
|
133
|
+
return this.value == null || "" === this.value;
|
|
134
|
+
}
|
|
135
|
+
setPos(xPosition, yPosition) {
|
|
136
|
+
this.x = xPosition;
|
|
137
|
+
this.y = yPosition;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
forceStringTypeDraw() {
|
|
141
|
+
const label = this.group;
|
|
142
|
+
const labelStr = "" + this.value;
|
|
143
|
+
this.drawLabel(label, labelStr);
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
drawLabel(label, labelStr) {
|
|
147
|
+
const background = this.styles.fontStyles.background || "#ffffff";
|
|
148
|
+
//let text = label.text(labelStr)
|
|
149
|
+
// .leading(1)
|
|
150
|
+
// .addClass(this.CSS_CATEGORIES)
|
|
151
|
+
// .font({anchor: 'middle'})
|
|
152
|
+
// .move(this.x, this.y);
|
|
153
|
+
let labelAnchor = "start";
|
|
154
|
+
const text = label.text(labelStr);
|
|
155
|
+
text.move(this.x, this.y);
|
|
156
|
+
const boxWidth = text.bbox().w;
|
|
157
|
+
const boxHeight = text.bbox().h;
|
|
158
|
+
let rectX = 0;
|
|
159
|
+
let rectY = 0;
|
|
160
|
+
const textX = text.x();
|
|
161
|
+
let textY = text.y();
|
|
162
|
+
if (this.horizontalHookLocation === exports.HookLocation.Left) {
|
|
163
|
+
labelAnchor = "left";
|
|
164
|
+
rectX = text.x();
|
|
165
|
+
}
|
|
166
|
+
else if (this.horizontalHookLocation === exports.HookLocation.Center) {
|
|
167
|
+
labelAnchor = "middle";
|
|
168
|
+
rectX = text.x() - (boxWidth + 2) / 2;
|
|
169
|
+
}
|
|
170
|
+
else if (this.horizontalHookLocation === exports.HookLocation.Right) {
|
|
171
|
+
labelAnchor = "end";
|
|
172
|
+
rectX = text.x() - boxWidth;
|
|
173
|
+
}
|
|
174
|
+
if (this.verticalHookLocation === exports.HookLocation.Center) {
|
|
175
|
+
textY = text.y() - (boxHeight * 1.2) / 2;
|
|
176
|
+
rectY = textY + boxHeight * 0.2;
|
|
177
|
+
}
|
|
178
|
+
else if (this.verticalHookLocation === exports.HookLocation.Top) {
|
|
179
|
+
textY -= boxHeight / 4;
|
|
180
|
+
rectY = textY + boxHeight * 0.2;
|
|
181
|
+
}
|
|
182
|
+
else if (this.verticalHookLocation === exports.HookLocation.Bottom) {
|
|
183
|
+
textY -= boxHeight;
|
|
184
|
+
rectY = textY + boxHeight * 0.2; // + (boxHeight / 2);
|
|
185
|
+
}
|
|
186
|
+
text.move(textX, textY);
|
|
187
|
+
text.font({ anchor: labelAnchor });
|
|
188
|
+
if (this.segmentFillColor != null) {
|
|
189
|
+
text.fill(getContrastTextColor(this.segmentFillColor));
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
label
|
|
193
|
+
.rect(boxWidth + 2, boxHeight * 0.8)
|
|
194
|
+
.stroke(background)
|
|
195
|
+
.fill(background)
|
|
196
|
+
.opacity(0.9)
|
|
197
|
+
.move(rectX - 1, rectY)
|
|
198
|
+
.insertBefore(text);
|
|
199
|
+
}
|
|
200
|
+
return text;
|
|
201
|
+
}
|
|
202
|
+
createElementID(prefix, groupPrefix) {
|
|
203
|
+
return prefix + "_" + groupPrefix + "_" + this.ID_SCENARIOLABEL;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Scenario priority for label collision resolution.
|
|
209
|
+
* Lower number = higher priority. AC always wins.
|
|
210
|
+
*/
|
|
211
|
+
const SCENARIO_PRIORITY = {
|
|
212
|
+
ac: 1,
|
|
213
|
+
pp: 2,
|
|
214
|
+
fc: 3,
|
|
215
|
+
pl: 4,
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Direction a label can be placed relative to its marker.
|
|
219
|
+
*/
|
|
220
|
+
exports.LabelDirection = void 0;
|
|
221
|
+
(function (LabelDirection) {
|
|
222
|
+
LabelDirection[LabelDirection["Above"] = 0] = "Above";
|
|
223
|
+
LabelDirection[LabelDirection["Below"] = 1] = "Below";
|
|
224
|
+
LabelDirection[LabelDirection["Left"] = 2] = "Left";
|
|
225
|
+
LabelDirection[LabelDirection["Right"] = 3] = "Right";
|
|
226
|
+
})(exports.LabelDirection || (exports.LabelDirection = {}));
|
|
227
|
+
/**
|
|
228
|
+
* Manages label collision detection across multiple line series in line charts.
|
|
229
|
+
* Tracks the bounding boxes of all registered labels and detects overlaps.
|
|
230
|
+
* Supports scenario-based priority: when labels collide and cannot be repositioned,
|
|
231
|
+
* lower-priority scenario labels are hidden (AC > PP > FC > PL).
|
|
232
|
+
*
|
|
233
|
+
* Uses 4-direction placement: Above, Below, Left, Right.
|
|
234
|
+
*/
|
|
235
|
+
class LabelCollisionManager {
|
|
236
|
+
constructor() {
|
|
237
|
+
this.labels = [];
|
|
238
|
+
this.scenarioLabels = [];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Clears all registered labels. Call this before drawing a new chart.
|
|
242
|
+
*/
|
|
243
|
+
clear() {
|
|
244
|
+
this.labels = [];
|
|
245
|
+
this.scenarioLabels = [];
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Registers a label's bounding box for collision detection.
|
|
249
|
+
*/
|
|
250
|
+
register(bounds) {
|
|
251
|
+
this.labels.push(bounds);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Checks if a label at the given bounds would collide with any existing labels.
|
|
255
|
+
*/
|
|
256
|
+
hasCollision(bounds) {
|
|
257
|
+
return this.labels.some((existing) => this.intersects(bounds, existing));
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Tries each direction in priorityOrder to find a non-colliding placement.
|
|
261
|
+
* Returns the first non-colliding LabelPlacement, or null if all 4 collide
|
|
262
|
+
* with higher-priority scenario labels (meaning this label should be hidden).
|
|
263
|
+
*
|
|
264
|
+
* @param centerX Center X position of the marker
|
|
265
|
+
* @param markerY Y position of the marker center
|
|
266
|
+
* @param width Estimated label width
|
|
267
|
+
* @param height Estimated label height
|
|
268
|
+
* @param pointIndex The data point index
|
|
269
|
+
* @param markerSize The marker size
|
|
270
|
+
* @param scenarioType e.g. "ac", "pp", "fc", "pl"
|
|
271
|
+
* @param priorityOrder Directions to try, in priority order
|
|
272
|
+
*/
|
|
273
|
+
getOptimalPlacement(centerX, markerY, width, height, pointIndex, markerSize, scenarioType, priorityOrder) {
|
|
274
|
+
const priority = SCENARIO_PRIORITY[scenarioType] || 99;
|
|
275
|
+
const gap = 8;
|
|
276
|
+
const halfMarker = markerSize / 2;
|
|
277
|
+
// Try each direction in the caller's preferred order
|
|
278
|
+
for (const direction of priorityOrder) {
|
|
279
|
+
const placement = this.calculatePlacementForDirection(centerX, markerY, width, height, pointIndex, halfMarker, gap, direction);
|
|
280
|
+
if (!this.hasCollision(placement.bounds)) {
|
|
281
|
+
return placement;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
// All 4 positions collide. Check if any collide ONLY with lower-priority
|
|
285
|
+
// labels (meaning we could still place here — the other label would lose).
|
|
286
|
+
// But to keep it simple: hide only if all positions collide with higher-priority labels.
|
|
287
|
+
for (const direction of priorityOrder) {
|
|
288
|
+
const placement = this.calculatePlacementForDirection(centerX, markerY, width, height, pointIndex, halfMarker, gap, direction);
|
|
289
|
+
if (!this.collidesWithHigherPriority(placement.bounds, priority)) {
|
|
290
|
+
// This position only collides with equal or lower priority — claim it
|
|
291
|
+
return placement;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// All positions collide with higher-priority labels — hide
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Computes the LabelPlacement for a given direction.
|
|
299
|
+
*/
|
|
300
|
+
calculatePlacementForDirection(centerX, markerY, width, height, pointIndex, halfMarker, gap, direction) {
|
|
301
|
+
let labelX;
|
|
302
|
+
let labelY;
|
|
303
|
+
let verticalHook;
|
|
304
|
+
let horizontalHook;
|
|
305
|
+
let boundsX;
|
|
306
|
+
let boundsY;
|
|
307
|
+
switch (direction) {
|
|
308
|
+
case exports.LabelDirection.Above:
|
|
309
|
+
labelX = centerX;
|
|
310
|
+
labelY = markerY - halfMarker - gap;
|
|
311
|
+
verticalHook = exports.HookLocation.Bottom;
|
|
312
|
+
horizontalHook = exports.HookLocation.Center;
|
|
313
|
+
boundsX = centerX - width / 2;
|
|
314
|
+
boundsY = markerY - halfMarker - gap - height;
|
|
315
|
+
break;
|
|
316
|
+
case exports.LabelDirection.Below:
|
|
317
|
+
labelX = centerX;
|
|
318
|
+
labelY = markerY + halfMarker + gap;
|
|
319
|
+
verticalHook = exports.HookLocation.Top;
|
|
320
|
+
horizontalHook = exports.HookLocation.Center;
|
|
321
|
+
boundsX = centerX - width / 2;
|
|
322
|
+
// Top hook shifts text up by height/4, so bounds start earlier
|
|
323
|
+
boundsY = markerY + halfMarker + gap - height / 4;
|
|
324
|
+
break;
|
|
325
|
+
case exports.LabelDirection.Left:
|
|
326
|
+
labelX = centerX - halfMarker - gap;
|
|
327
|
+
labelY = markerY;
|
|
328
|
+
verticalHook = exports.HookLocation.Center;
|
|
329
|
+
horizontalHook = exports.HookLocation.Right;
|
|
330
|
+
boundsX = centerX - halfMarker - gap - width;
|
|
331
|
+
// Center hook shifts text up by height*0.6
|
|
332
|
+
boundsY = markerY - height * 0.6;
|
|
333
|
+
break;
|
|
334
|
+
case exports.LabelDirection.Right:
|
|
335
|
+
labelX = centerX + halfMarker + gap;
|
|
336
|
+
labelY = markerY;
|
|
337
|
+
verticalHook = exports.HookLocation.Center;
|
|
338
|
+
horizontalHook = exports.HookLocation.Left;
|
|
339
|
+
boundsX = centerX + halfMarker + gap;
|
|
340
|
+
// Center hook shifts text up by height*0.6
|
|
341
|
+
boundsY = markerY - height * 0.6;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
const bounds = {
|
|
345
|
+
x: boundsX,
|
|
346
|
+
y: boundsY,
|
|
347
|
+
width,
|
|
348
|
+
height,
|
|
349
|
+
pointIndex,
|
|
350
|
+
preferredHook: verticalHook,
|
|
351
|
+
};
|
|
352
|
+
return { labelX, labelY, verticalHook, horizontalHook, bounds };
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Checks if bounds collide with any registered label that has higher priority.
|
|
356
|
+
*/
|
|
357
|
+
collidesWithHigherPriority(bounds, priority) {
|
|
358
|
+
return this.labels.some((existing) => {
|
|
359
|
+
if (!existing.scenarioType)
|
|
360
|
+
return false;
|
|
361
|
+
const existingPriority = SCENARIO_PRIORITY[existing.scenarioType] || 99;
|
|
362
|
+
return existingPriority < priority && this.intersects(bounds, existing);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Checks whether a scenario label at the end of a line should be hidden
|
|
367
|
+
* because it's too close to a higher-priority scenario label.
|
|
368
|
+
*/
|
|
369
|
+
shouldHideScenarioLabel(x, y, scenarioType, proximityThreshold = 20) {
|
|
370
|
+
const priority = SCENARIO_PRIORITY[scenarioType] || 99;
|
|
371
|
+
if (priority <= 1)
|
|
372
|
+
return false; // AC is never hidden
|
|
373
|
+
return this.scenarioLabels.some((existing) => {
|
|
374
|
+
const existingPriority = SCENARIO_PRIORITY[existing.scenarioType] || 99;
|
|
375
|
+
if (existingPriority >= priority)
|
|
376
|
+
return false;
|
|
377
|
+
const dy = Math.abs(y - existing.y);
|
|
378
|
+
const dx = Math.abs(x - existing.x);
|
|
379
|
+
return dy < proximityThreshold && dx < proximityThreshold;
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Registers a scenario label position for proximity checking.
|
|
384
|
+
*/
|
|
385
|
+
registerScenarioLabel(x, y, scenarioType) {
|
|
386
|
+
this.scenarioLabels.push({ x, y, scenarioType });
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Checks if two bounding boxes intersect (overlap).
|
|
390
|
+
*/
|
|
391
|
+
intersects(a, b) {
|
|
392
|
+
return !(a.x + a.width < b.x || // a is completely to the left of b
|
|
393
|
+
b.x + b.width < a.x || // b is completely to the left of a
|
|
394
|
+
a.y + a.height < b.y || // a is completely above b
|
|
395
|
+
b.y + b.height < a.y // b is completely above a
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Gets the number of registered labels.
|
|
400
|
+
*/
|
|
401
|
+
getLabelCount() {
|
|
402
|
+
return this.labels.length;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
exports.IBCS_LAYER_ORDER = IBCS_LAYER_ORDER;
|
|
407
|
+
exports.Label = Label;
|
|
408
|
+
exports.LabelCollisionManager = LabelCollisionManager;
|
|
409
|
+
exports.SCENARIO_PRIORITY = SCENARIO_PRIORITY;
|
|
410
|
+
exports.SiPrefix = SiPrefix;
|
|
411
|
+
exports.getContrastTextColor = getContrastTextColor;
|
|
412
|
+
exports.getScenarioPrefix = getScenarioPrefix;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Linear numeric scale with nice-tick generation for the XY charts.
|
|
5
|
+
*
|
|
6
|
+
* Domains default to the data extent padded 4% on each side; zero-inclusion
|
|
7
|
+
* is NOT forced — points encode by position, not length, so IBCS's
|
|
8
|
+
* zero-baseline rule for bars does not apply. Explicit `min`/`max`
|
|
9
|
+
* overrides disable the padding on that side.
|
|
10
|
+
*/
|
|
11
|
+
class NumericScale {
|
|
12
|
+
constructor(domainMin, domainMax, rangeMin, rangeMax) {
|
|
13
|
+
this.domainMin = domainMin;
|
|
14
|
+
this.domainMax = domainMax;
|
|
15
|
+
this.rangeMin = rangeMin;
|
|
16
|
+
this.rangeMax = rangeMax;
|
|
17
|
+
}
|
|
18
|
+
/** Maps a domain value to range (pixel) coordinates. */
|
|
19
|
+
scale(value) {
|
|
20
|
+
const span = this.domainMax - this.domainMin;
|
|
21
|
+
if (span === 0) {
|
|
22
|
+
return (this.rangeMin + this.rangeMax) / 2;
|
|
23
|
+
}
|
|
24
|
+
return this.rangeMin + ((value - this.domainMin) / span) * (this.rangeMax - this.rangeMin);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Computes the domain from a data extent: 4% padding on each side,
|
|
28
|
+
* overridden per side by explicit `min`/`max`. Degenerate extents
|
|
29
|
+
* (single value) are widened symmetrically.
|
|
30
|
+
*/
|
|
31
|
+
static domain(dataMin, dataMax, override, pad = 0.04) {
|
|
32
|
+
let span = dataMax - dataMin;
|
|
33
|
+
if (span === 0) {
|
|
34
|
+
const widen = dataMin === 0 ? 1 : Math.abs(dataMin) * 0.1;
|
|
35
|
+
dataMin -= widen;
|
|
36
|
+
dataMax += widen;
|
|
37
|
+
span = dataMax - dataMin;
|
|
38
|
+
}
|
|
39
|
+
const min = (override === null || override === void 0 ? void 0 : override.min) !== undefined ? override.min : dataMin - span * pad;
|
|
40
|
+
const max = (override === null || override === void 0 ? void 0 : override.max) !== undefined ? override.max : dataMax + span * pad;
|
|
41
|
+
return [min, max];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Picks a nice step size from the 1-2-2.5-5 ladder so that the span
|
|
45
|
+
* yields close to `targetCount` ticks.
|
|
46
|
+
*/
|
|
47
|
+
static niceStep(span, targetCount) {
|
|
48
|
+
if (span <= 0 || targetCount <= 0) {
|
|
49
|
+
return 1;
|
|
50
|
+
}
|
|
51
|
+
const rawStep = span / targetCount;
|
|
52
|
+
const magnitude = Math.pow(10, Math.floor(Math.log10(rawStep)));
|
|
53
|
+
const normalized = rawStep / magnitude;
|
|
54
|
+
let mantissa;
|
|
55
|
+
if (normalized <= 1) {
|
|
56
|
+
mantissa = 1;
|
|
57
|
+
}
|
|
58
|
+
else if (normalized <= 2) {
|
|
59
|
+
mantissa = 2;
|
|
60
|
+
}
|
|
61
|
+
else if (normalized <= 2.5) {
|
|
62
|
+
mantissa = 2.5;
|
|
63
|
+
}
|
|
64
|
+
else if (normalized <= 5) {
|
|
65
|
+
mantissa = 5;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
mantissa = 10;
|
|
69
|
+
}
|
|
70
|
+
return mantissa * magnitude;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Nice tick values inside the domain, aiming for `targetCount` ticks
|
|
74
|
+
* (the renderer picks 4–8 depending on panel size).
|
|
75
|
+
*/
|
|
76
|
+
ticks(targetCount) {
|
|
77
|
+
const span = this.domainMax - this.domainMin;
|
|
78
|
+
if (span <= 0) {
|
|
79
|
+
return [this.domainMin];
|
|
80
|
+
}
|
|
81
|
+
const step = NumericScale.niceStep(span, targetCount);
|
|
82
|
+
const first = Math.ceil(this.domainMin / step) * step;
|
|
83
|
+
const ticks = [];
|
|
84
|
+
// Guard against floating-point drift at the domain edge.
|
|
85
|
+
for (let tick = first; tick <= this.domainMax + step * 1e-9; tick += step) {
|
|
86
|
+
ticks.push(Math.abs(tick) < step * 1e-9 ? 0 : tick);
|
|
87
|
+
}
|
|
88
|
+
return ticks;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Decimal places (0–2) needed to render the given ticks without
|
|
92
|
+
* ambiguity between adjacent values.
|
|
93
|
+
*/
|
|
94
|
+
static tickDecimals(ticks) {
|
|
95
|
+
let decimals = 0;
|
|
96
|
+
for (const tick of ticks) {
|
|
97
|
+
const text = String(tick);
|
|
98
|
+
const dot = text.indexOf(".");
|
|
99
|
+
if (dot >= 0) {
|
|
100
|
+
decimals = Math.max(decimals, Math.min(2, text.length - dot - 1));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return decimals;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
exports.NumericScale = NumericScale;
|