@bino-bi/bn-template-engine 1.0.0-next.37 → 1.0.0-next.39

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.
Files changed (52) hide show
  1. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  2. package/dist/bn-template-engine/{p-f74760d7.entry.js → p-8c84d57e.entry.js} +1 -1
  3. package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +271 -57
  4. package/dist/cjs/bn-template-engine.cjs.js +1 -1
  5. package/dist/cjs/loader.cjs.js +1 -1
  6. package/dist/collection/components/bn-table/bn-table-renderer/bn-table-renderer.js +56 -6
  7. package/dist/collection/components/bn-table/bn-table.js +93 -5
  8. package/dist/collection/components/bn-table/utils/Table.js +33 -2
  9. package/dist/collection/components/bn-table/utils/elements/CellBarChart.js +15 -7
  10. package/dist/collection/components/bn-table/utils/elements/WaterfallBar.js +2 -2
  11. package/dist/collection/components/bn-table/utils/factories/tableDataSetFactory.js +15 -7
  12. package/dist/collection/components/bn-table/utils/helper/DataQuery.js +24 -10
  13. package/dist/collection/components/bn-table/utils/helper/IntervalColumns.js +30 -6
  14. package/dist/collection/components/bn-table/utils/helper/WaterfallCalculator.js +9 -3
  15. package/dist/collection/components/bn-table/utils/helper/barColumnGeometry.js +31 -8
  16. package/dist/collection/components/bn-table/utils/model/TableComponentConfig.js +5 -0
  17. package/dist/collection/utils/layoutState/baseline.js +6 -5
  18. package/dist/components/bn-chart-bubble-renderer.js +1 -1
  19. package/dist/components/bn-chart-bubble.js +1 -1
  20. package/dist/components/bn-chart-bullet-renderer.js +1 -1
  21. package/dist/components/bn-chart-bullet.js +1 -1
  22. package/dist/components/bn-chart-scatter-renderer.js +1 -1
  23. package/dist/components/bn-chart-scatter.js +1 -1
  24. package/dist/components/bn-chart-structure.js +1 -1
  25. package/dist/components/bn-chart-time.js +1 -1
  26. package/dist/components/bn-table-renderer.js +1 -1
  27. package/dist/components/bn-table.js +1 -1
  28. package/dist/components/{p-CQVAHG6w.js → p-B4Cf0cVi.js} +1 -1
  29. package/dist/components/{p-C-KX1_tw.js → p-BsJOvfIg.js} +1 -1
  30. package/dist/components/p-ChaSU4fh.js +1 -0
  31. package/dist/components/{p-BhEdmPjm.js → p-Cyf5ZEXs.js} +1 -1
  32. package/dist/components/{p-t4xPltK2.js → p-XFZYX7DZ.js} +1 -1
  33. package/dist/components/{p-C_6KHDYv.js → p-chnyMHJT.js} +1 -1
  34. package/dist/components/p-dRPJiQB6.js +1 -0
  35. package/dist/esm/bn-annotation-layer_30.entry.js +271 -57
  36. package/dist/esm/bn-template-engine.js +1 -1
  37. package/dist/esm/loader.js +1 -1
  38. package/dist/types/components/bn-table/bn-table-renderer/bn-table-renderer.d.ts +2 -0
  39. package/dist/types/components/bn-table/bn-table.d.ts +26 -0
  40. package/dist/types/components/bn-table/utils/Table.d.ts +11 -1
  41. package/dist/types/components/bn-table/utils/elements/CellBarChart.d.ts +5 -2
  42. package/dist/types/components/bn-table/utils/factories/tableDataSetFactory.d.ts +7 -4
  43. package/dist/types/components/bn-table/utils/helper/DataQuery.d.ts +1 -0
  44. package/dist/types/components/bn-table/utils/helper/IntervalColumns.d.ts +7 -0
  45. package/dist/types/components/bn-table/utils/helper/WaterfallCalculator.d.ts +5 -2
  46. package/dist/types/components/bn-table/utils/helper/barColumnGeometry.d.ts +15 -6
  47. package/dist/types/components/bn-table/utils/model/TableComponentConfig.d.ts +2 -0
  48. package/dist/types/components.d.ts +19 -4
  49. package/dist/types/utils/layoutState/baseline.d.ts +4 -2
  50. package/package.json +1 -1
  51. package/dist/components/p-CHQ67u2G.js +0 -1
  52. package/dist/components/p-sar8m7th.js +0 -1
@@ -1 +1 @@
1
- import{p as t,H as i,h as s,a as e,t as h}from"./p-D6YGOYV1.js";import{g as n,d as r}from"./p-DDvWTgk1.js";import{A as a,C as o}from"./p-B5tixDPM.js";import{C as l,F as d,s as u,I as c}from"./p-CniN8ALm.js";import{w as m}from"./p-Dq9dG0Kr.js";import{S as p,F as g,a as f,P as v}from"./p-eWxolPDU.js";import{d as b,l as w,S as $}from"./p-BzjGUtYh.js";import{S as y}from"./p-NBaq67dL.js";import{e as M,r as S}from"./p-ClruFZD_.js";import{O as x}from"./p-16rjcQ0t.js";import{N as j}from"./p-BJmwHV0a.js";import{s as N}from"./p-Xb6Ilq8u.js";import{B as E}from"./p-t4xPltK2.js";class D{constructor(t,i,s,e,h,n){this.ruleSet=t,this.config=e,this.styles=h,this.availableWidth=n,this.rows=[],this.warnings=[],this.i18nMap=new Map,this.populateModel(i,s),this.normalized="target"===this.config.normalize&&this.rows.some((t=>null!==t.fraction)),null!==this.config.target&&this.rows.length>0&&!this.rows.some((t=>null!==t.target))&&this.warnings.push({code:"bullet-target-none",data:{}})}populateModel(t,i){var s,e,h;if(""===i)return;const n=this.config.level,r=this.config.order,a=this.config.actual.measure,o=null!==(e=null===(s=this.config.target)||void 0===s?void 0:s.measure)&&void 0!==e?e:null,l="transformOperator(operation)",d=[a,...null!==o?[o]:[]].map((t=>`CASE WHEN MIN(${l}) = MAX(${l}) THEN SUM(${t}) ELSE SUM(${t} * ${l}) END as ${t}, SUM(ABS(${t})) as ${t}_gross, COUNT(ISNULL(${t})) as ${t}_cnt`)).join(", ");let u;try{u=t.exec(`SELECT ${this.createSelectString(n,r)}, ${d},\n MIN(transformOperator(operation)) as opMin, MAX(transformOperator(operation)) as opMax\n FROM ${i}\n GROUP BY ${this.createGroupByStr(n,r)}\n ORDER BY ${this.createOrderStr(n,r)}`)}catch(t){return void(this.queryError=M(t))}let c=null!=u?u:[];this.config.limit>0&&(c=c.slice(0,this.config.limit));let m=0,p=0,g=0,f=0;for(const t of c){const i="number"==typeof t.opMin?t.opMin:1,s="number"==typeof t.opMax?t.opMax:1;let e=-1===i&&-1===s?"-":"+";i!==s&&(e="+",m++);const n=this.readValue(t,a),r=null!==o?this.readValue(t,o):null;null!==n&&n<0&&f++;let l=null;"target"===this.config.normalize&&(null===r?null!==o&&p++:r<=0?g++:null!==n&&n>=0&&(l=n/r)),this.rows.push({category:String(null!==(h=t.category)&&void 0!==h?h:""),actual:n,target:r,operation:e,sentiment:this.sentiment(n,r,e),fraction:l})}m>0&&this.warnings.push({code:"bullet-mixed-operation",data:{count:String(m)}}),p>0&&this.warnings.push({code:"bullet-target-missing",data:{count:String(p)}}),g>0&&this.warnings.push({code:"bullet-target-invalid",data:{count:String(g)}}),f>0&&this.warnings.push({code:"bullet-actual-negative",data:{count:String(f)}})}readValue(t,i){if(0===t[`${i}_cnt`])return null;const s=t[i],e=t[`${i}_gross`];return"number"==typeof s&&"number"==typeof e&&Math.abs(s)<=1e-9*e?0:"number"==typeof s&&isFinite(s)?s:null}sentiment(t,i,s){return null===t||null===i||t===i?"neu":t>i!=("-"===s)?"pos":"neg"}createSelectString(t,i){return t===a.CATEGORY&&i.hierarchy.includes(x.CATEGORYINDEX)?`${x.CATEGORYINDEX}, ${a.CATEGORY} as category`:t===a.ROWGROUP&&i.hierarchy.includes(x.ROWGROUPINDEX)?`${x.ROWGROUPINDEX}, ${a.ROWGROUP} as category`:t===a.SUBCATEGORY&&i.hierarchy.includes(x.SUBCATEGORYINDEX)?`${x.SUBCATEGORYINDEX}, ${a.SUBCATEGORY} as category`:`${t.toString()} as category`}createGroupByStr(t,i){return t===a.CATEGORY&&i.hierarchy.includes(x.CATEGORYINDEX)?`${x.CATEGORYINDEX}, ${a.CATEGORY}`:t===a.ROWGROUP&&i.hierarchy.includes(x.ROWGROUPINDEX)?`${x.ROWGROUPINDEX}, ${a.ROWGROUP}`:t===a.SUBCATEGORY&&i.hierarchy.includes(x.SUBCATEGORYINDEX)?`${x.SUBCATEGORYINDEX}, ${a.SUBCATEGORY}`:`${t.toString()}`}createOrderStr(t,i){let s=`${t.toLowerCase()}`;return i.hierarchy.length>=1&&(s=i.hierarchy.map((t=>`${t} ${i.direction}`)).toString()),s}get em(){return this.styles.fontStyles.size}fontFamily(){return this.styles.fontStyles.font.replace(/^[\d.]+px\s*/,"")}textWidth(t,i=!1){const s=l(t,{font:this.styles.fontStyles.font,fontSize:this.styles.fontStyles.size+"px",fontWeight:i?"bold":"normal"}).width;return Number.isFinite(s)&&s>0?s:.6*t.length*this.em}drawText(t,i,s,e,h={}){var n,r,a;return t.text(i).font({size:null!==(n=h.size)&&void 0!==n?n:this.styles.fontStyles.size,weight:h.bold?"bold":"normal",anchor:null!==(r=h.anchor)&&void 0!==r?r:"start"}).fill(null!==(a=h.color)&&void 0!==a?a:this.styles.fontStyles.color).attr({x:s,y:e,"font-family":this.fontFamily()})}setI18n(t){this.i18nMap=t}hasNoData(){return 0===this.rows.length}getWarnings(){return this.warnings}getQueryError(){return this.queryError}getAllocatedCanvasWidth(){return this.availableWidth}getAllocatedCanvasHeight(){return this.styles.padding.top+this.titleHeight()+this.headerHeight()+this.rows.length*this.rowBlockHeight()+this.styles.padding.bottom}titleHeight(){return""!==this.config.chartTitle?1.6*this.em:0}headerHeight(){return this.rows.length>0?1.2*this.em:0}rowBlockHeight(){const t=this.em,i=this.styles.scaleFactors.rowHeight*t;return this.normalized?i:i+this.styles.scaleFactors.tickStripHeight*t}valueLabel(t){return null===t||"none"===this.config.labels.show?"":d.number(t,"decimal",this.config.labels.decimals,0,1,this.styles.locale)}targetFamily(){var t,i;const s=null!==(i=null===(t=this.config.target)||void 0===t?void 0:t.measure)&&void 0!==i?i:"pl1";return u(this.ruleSet.getScenarioColorIndex(s))}actualLabel(){var t;return null!==(t=this.config.actual.label)&&void 0!==t?t:d.translateScenarioLabel(this.config.actual.measure,this.i18nMap)}targetLabel(){return null===this.config.target?"":void 0!==this.config.target.label?this.config.target.label:this.normalized?this.i18nMap.get("target")||"Target":d.translateScenarioLabel(this.config.target.measure,this.i18nMap)}toString(){const t=new p;return this.draw(t),t.id("drawCanvas"),t.width(this.getAllocatedCanvasWidth()),t.height(this.getAllocatedCanvasHeight()),t.attr("overflow","visible"),t.svg()}draw(t){var i,s;const e=this.em,h=this.styles.scaleFactors,n=this.styles.padding,r=t.group();if(""!==this.config.chartTitle&&this.drawText(r,this.config.chartTitle,n.left,n.top+e,{bold:!0}),0===this.rows.length)return void t.group().addClass("annotations");const a=h.rowHeight*e,o=this.rowBlockHeight(),l=n.top+this.titleHeight()+this.headerHeight(),d=l+(this.rows.length-1)*o+a,u=Math.max(...this.rows.map((t=>this.textWidth(t.category,!0))),e),c=this.rows.map((t=>this.valueLabel(t.actual))),m="none"===this.config.labels.show?0:Math.max(...c.map((t=>this.textWidth(t))),0),p=n.left+u+h.labelToAxis*e,g=Math.max(10,this.availableWidth-p-n.right-m-(m>0?h.labelToBar*e:0)),f=null!==(i=this.config.actual.unit)&&void 0!==i?i:null===(s=this.config.target)||void 0===s?void 0:s.unit,v=this.i18nMap.get("axis.in")||"in",b=l-.35*e;void 0!==f&&""!==f&&this.drawText(r,`${v} ${f}`,n.left,b,{}),this.drawText(r,this.actualLabel(),p+.2*e,b,{}),this.normalized?this.drawNormalized(r,p,g,l,d,a,o,c):this.drawClassic(r,p,g,l,a,o,c),this.rows.forEach(((t,i)=>{this.drawText(r,t.category,p-h.labelToAxis*e,l+i*o+a/2+.35*e,{anchor:"end",bold:!0})})),r.line(p,l-.2*e,p,d+.2*e).stroke({color:this.styles.axisStyles.ac.stroke,width:N(h.axisLineWidth,this.em)}).attr(E,"axis"),t.group().addClass("annotations")}drawNormalized(t,i,s,e,h,n,r,a){const o=this.em,l=this.styles.scaleFactors,d=1.05*Math.max(1,...this.rows.map((t=>{var i;return null!==(i=t.fraction)&&void 0!==i?i:0}))),u=t=>i+t/d*s,c=u(1),m=this.styles.barStyles.getSVGStyle(this.targetFamily()),p=t.line(c,e-.3*o,c,h+.3*o).stroke({color:m.stroke,width:N(l.targetLineWidth,this.em)});void 0!==m.dasharray&&p.attr("stroke-dasharray",m.dasharray),this.drawText(t,this.targetLabel(),c,e-.35*o,{anchor:"middle",bold:!0}),this.rows.forEach(((s,h)=>{const d=e+h*r+n/2;if(null===s.fraction)return void this.drawValueText(t,a[h],i+l.labelToBar*o,d,s);const m=l.barHeight*o,p=u(s.fraction);if(t.rect(Math.max(0,p-i),m).move(i,d-m/2).fill(this.styles.barStyles.ac.fill).stroke({color:this.styles.barStyles.ac.stroke,width:this.styles.barStyles.ac.width}).attr(b(this.rowKey(s),"element")).attr("data-bn-index",String(h)),this.config.showVariances&&"neu"!==s.sentiment){const i=l.varianceHeight*o,e=this.styles.varianceStyles.getSVGStyle(s.sentiment);t.rect(Math.abs(p-c),i).move(Math.min(p,c),d-i/2).fill(e.fill).stroke({color:e.stroke,width:e.width})}this.drawValueText(t,a[h],Math.max(p,c)+l.labelToBar*o,d,s)}))}drawClassic(t,i,s,e,h,n,r){const a=this.em,o=this.styles.scaleFactors,l=o.barHeight*a,u=this.config.ranges.length>0;this.rows.forEach(((c,m)=>{var p,g;const f=e+m*n,v=f+h/2,w=u&&null!==c.target?this.config.ranges.map((t=>t*c.target)):[],$=Math.max(null!==(p=c.actual)&&void 0!==p?p:0,null!==(g=c.target)&&void 0!==g?g:0,...w);if($<=0)return void this.drawValueText(t,r[m],i+o.labelToBar*a,v,c);const y=j.niceStep($,4),M=Math.ceil($/y-1e-9*y)*y,S=new j(0,M,i,i+s);let x=i;w.forEach(((i,s)=>{const e=.8*h;t.rect(Math.max(0,S.scale(i)-x),e).move(x,v-e/2).fill(this.styles.rangeColors[Math.min(s,this.styles.rangeColors.length-1)]).stroke("none"),x=S.scale(i)}));let E=i;if(null!==c.actual&&c.actual>0){const s=S.scale(c.actual);t.rect(s-i,l).move(i,v-l/2).fill(this.styles.barStyles.ac.fill).stroke({color:this.styles.barStyles.ac.stroke,width:this.styles.barStyles.ac.width}).attr(b(this.rowKey(c),"element")).attr("data-bn-index",String(m)),E=s}if(null!==c.target&&c.target>0){const i=S.scale(c.target),s=o.targetTickHeight*a,h=this.styles.barStyles.getSVGStyle(this.targetFamily()),n=t.line(i,v-s/2,i,v+s/2).stroke({color:h.stroke,width:N(o.targetLineWidth,this.em)});void 0!==h.dasharray&&n.attr("stroke-dasharray",h.dasharray),0===m&&this.drawText(t,this.targetLabel(),i,e-.35*a,{anchor:"middle"}),E=Math.max(E,i)}E=Math.max(E,x),this.drawValueText(t,r[m],E+o.labelToBar*a,v,c);const D=S.ticks(4),C=j.tickDecimals(D),O=f+h;for(const i of D){const s=S.scale(i);t.line(s,O,s,O+o.axisTickLength*a).stroke({color:this.styles.axisStyles.ac.stroke,width:N(o.axisLineWidth,this.em)}),this.drawText(t,d.number(i,"decimal",C,C,1,this.styles.locale),s,O+o.tickStripHeight*a-.2*a,{anchor:"middle"})}}))}drawValueText(t,i,s,e,h){""!==i&&this.drawText(t,i,s,e+.35*this.em,{}).attr(b(this.rowKey(h),"label"))}rowKey(t){return Object.assign(Object.assign({},w(this.config.level,t.category)),{scenario:this.config.actual.measure})}}class C{constructor(){this.rowHeight=1.9,this.barHeight=.66,this.varianceHeight=.4,this.targetTickHeight=1.1,this.targetLineWidth=.15,this.axisLineWidth=.075,this.labelToBar=.3,this.labelToAxis=.3,this.axisTickLength=.35,this.tickStripHeight=1.2}}class O{adapt(t){const i=new C;return o.isNumber(t.rowHeight)&&(i.rowHeight=t.rowHeight),o.isNumber(t.barHeight)&&(i.barHeight=t.barHeight),o.isNumber(t.varianceHeight)&&(i.varianceHeight=t.varianceHeight),o.isNumber(t.targetTickHeight)&&(i.targetTickHeight=t.targetTickHeight),o.isNumber(t.targetLineWidth)&&(i.targetLineWidth=t.targetLineWidth),o.isNumber(t.axisLineWidth)&&(i.axisLineWidth=t.axisLineWidth),o.isNumber(t.labelToBar)&&(i.labelToBar=t.labelToBar),o.isNumber(t.labelToAxis)&&(i.labelToAxis=t.labelToAxis),o.isNumber(t.axisTickLength)&&(i.axisTickLength=t.axisTickLength),o.isNumber(t.tickStripHeight)&&(i.tickStripHeight=t.tickStripHeight),i}default(){return new C}}class W{constructor(t,i,s,e,h,n){this.scaleFactors=t,this.fontStyles=i,this.axisStyles=s,this.barStyles=e,this.varianceStyles=h,this.padding=n,this.rangeColors=["#D9D9D9","#EFEFEF"],this.locale="de"}}class z{constructor(t,i,s,e,h){this.scaleFactorsBulletChartAdapter=t,this.fontStyleAdapter=i,this.svgStyleGroupAdapter=s,this.svgVariancesStyleGroupAdapter=e,this.paddingAdapter=h}adapt(t){const i=this.default();return o.isExisting(t)&&(o.isExisting(t.scaleFactors)&&(i.scaleFactors=this.scaleFactorsBulletChartAdapter.adapt(t.scaleFactors)),o.isExisting(t.fontStyles)&&(i.fontStyles=this.fontStyleAdapter.adapt(t.fontStyles)),o.isExisting(t.axisStyles)&&(i.axisStyles=this.svgStyleGroupAdapter.adapt(t.axisStyles)),o.isExisting(t.barStyles)&&(i.barStyles=this.svgStyleGroupAdapter.adapt(t.barStyles)),o.isExisting(t.varianceStyles)&&(i.varianceStyles=this.svgVariancesStyleGroupAdapter.adapt(t.varianceStyles)),o.isExisting(t.padding)&&(i.padding=this.paddingAdapter.adapt(t.padding)),Array.isArray(t.rangeColors)&&t.rangeColors.length>0&&(i.rangeColors=t.rangeColors)),i}default(){return new W(this.scaleFactorsBulletChartAdapter.default(),this.fontStyleAdapter.default(),this.svgStyleGroupAdapter.default(),this.svgStyleGroupAdapter.default(),this.svgVariancesStyleGroupAdapter.default(),this.paddingAdapter.default())}}const B=["bullet-target-missing","bullet-target-invalid","bullet-actual-negative","bullet-mixed-operation","bullet-target-none"],L=t(class extends i{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.tableName="",this.dataVersion=0,this.chartTitle="",this.target=null,this.ranges=[],this.normalizeMode="target",this.showVariances=!0,this.level=a.CATEGORY,this.limit=0,this.filter="",this.i18n=new Map,this.containerWidth=0,this.svgMarkup="",m(this)}getDb(){return this.stores||(this.stores=n(this.element)),this.stores.db.db}componentWillLoad(){this.rebuild()}componentWillUpdate(){this.rebuild()}rebuild(){const t=this.prepareStyle(),i=r(this.getDb(),this.tableName,this.filter);this.chart=new D(new c(this.ruleSetConfig),this.getDb(),i,{chartTitle:this.chartTitle,actual:this.actual,target:this.target,ranges:this.ranges,normalize:this.normalizeMode,showVariances:this.showVariances,level:this.level,order:this.order,limit:this.limit,labels:this.labels},t,this.containerWidth||0),this.chart.setI18n(this.i18n),this.svgMarkup=this.chart.hasNoData()?"":this.chart.toString(),this.syncWarnings(this.chart.getWarnings()),S(this.errors,this.chart.getQueryError())}syncWarnings(t){if(void 0===this.errors)return;const i=new Map(t.map((t=>[t.code,t.data])));for(const t of B){const s=`WARN_${t.replace(/-/g,"_")}`;if(i.has(t)){const e=void 0!==this.translator?this.translator(`.${t}`,i.get(t)):t;this.errors.addOrReplace({id:s,type:"warning",message:e})}else this.errors.remove(s)}}prepareStyle(){var t,i;const s=new z(new O,new g,new f(new $),new y(new $),new v).adapt(this.styles);return s.locale=(null===(i=null===(t=n(this.element).context)||void 0===t?void 0:t.state)||void 0===i?void 0:i.locale)||"de",s}render(){var t;if(void 0===this.chart||void 0!==this.chart.getQueryError())return s(e,null);if(this.chart.hasNoData()){const i=null!==(t=this.i18n.get("no-data"))&&void 0!==t?t:"No Data";return s(e,{class:"no-data"},s("div",{class:"empty-state"},i))}return s(e,null,s("div",{innerHTML:this.svgMarkup}))}get element(){return this}static get style(){return':host(.no-data){display:block;box-sizing:border-box;width:100%;height:100%}:host(.no-data)>div{float:none;width:100%;height:100%}:host(.no-data) .no-data~.no-data{display:none}.empty-state{box-sizing:border-box;display:flex;align-items:center;justify-content:center;float:none;width:100%;height:100%;min-height:3em;margin:0;padding:0.5em;overflow:hidden;border:0.1em dashed #ddd;color:#808080;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px);font-style:normal;text-align:center}:host{position:relative;display:inline-block}'}},[1,"bn-chart-bullet-renderer",{tableName:[1,"table-name"],dataVersion:[2,"data-version"],chartTitle:[1,"chart-title"],actual:[16],target:[16],ranges:[16],normalizeMode:[1,"normalize-mode"],showVariances:[4,"show-variances"],level:[1],order:[16],limit:[2],labels:[16],filter:[1],styles:[16],i18n:[16],containerWidth:[2,"container-width"],ruleSetConfig:[16],errors:[16],translator:[16]}]);function A(){"undefined"!=typeof customElements&&["bn-chart-bullet-renderer"].forEach((t=>{"bn-chart-bullet-renderer"===t&&(customElements.get(h(t))||customElements.define(h(t),L))}))}export{L as B,A as d}
1
+ import{p as t,H as i,h as s,a as e,t as h}from"./p-D6YGOYV1.js";import{g as n,d as r}from"./p-DDvWTgk1.js";import{A as a,C as o}from"./p-B5tixDPM.js";import{C as l,F as d,s as u,I as c}from"./p-CniN8ALm.js";import{w as m}from"./p-Dq9dG0Kr.js";import{S as p,F as g,a as f,P as v}from"./p-eWxolPDU.js";import{d as b,l as w,S as $}from"./p-BzjGUtYh.js";import{S as y}from"./p-NBaq67dL.js";import{e as M,r as S}from"./p-ClruFZD_.js";import{O as x}from"./p-16rjcQ0t.js";import{N as j}from"./p-BJmwHV0a.js";import{s as N}from"./p-Xb6Ilq8u.js";import{B as D}from"./p-XFZYX7DZ.js";class E{constructor(t,i,s,e,h,n){this.ruleSet=t,this.config=e,this.styles=h,this.availableWidth=n,this.rows=[],this.warnings=[],this.i18nMap=new Map,this.populateModel(i,s),this.normalized="target"===this.config.normalize&&this.rows.some((t=>null!==t.fraction)),null!==this.config.target&&this.rows.length>0&&!this.rows.some((t=>null!==t.target))&&this.warnings.push({code:"bullet-target-none",data:{}})}populateModel(t,i){var s,e,h;if(""===i)return;const n=this.config.level,r=this.config.order,a=this.config.actual.measure,o=null!==(e=null===(s=this.config.target)||void 0===s?void 0:s.measure)&&void 0!==e?e:null,l="transformOperator(operation)",d=[a,...null!==o?[o]:[]].map((t=>`CASE WHEN MIN(${l}) = MAX(${l}) THEN SUM(${t}) ELSE SUM(${t} * ${l}) END as ${t}, SUM(ABS(${t})) as ${t}_gross, COUNT(ISNULL(${t})) as ${t}_cnt`)).join(", ");let u;try{u=t.exec(`SELECT ${this.createSelectString(n,r)}, ${d},\n MIN(transformOperator(operation)) as opMin, MAX(transformOperator(operation)) as opMax\n FROM ${i}\n GROUP BY ${this.createGroupByStr(n,r)}\n ORDER BY ${this.createOrderStr(n,r)}`)}catch(t){return void(this.queryError=M(t))}let c=null!=u?u:[];this.config.limit>0&&(c=c.slice(0,this.config.limit));let m=0,p=0,g=0,f=0;for(const t of c){const i="number"==typeof t.opMin?t.opMin:1,s="number"==typeof t.opMax?t.opMax:1;let e=-1===i&&-1===s?"-":"+";i!==s&&(e="+",m++);const n=this.readValue(t,a),r=null!==o?this.readValue(t,o):null;null!==n&&n<0&&f++;let l=null;"target"===this.config.normalize&&(null===r?null!==o&&p++:r<=0?g++:null!==n&&n>=0&&(l=n/r)),this.rows.push({category:String(null!==(h=t.category)&&void 0!==h?h:""),actual:n,target:r,operation:e,sentiment:this.sentiment(n,r,e),fraction:l})}m>0&&this.warnings.push({code:"bullet-mixed-operation",data:{count:String(m)}}),p>0&&this.warnings.push({code:"bullet-target-missing",data:{count:String(p)}}),g>0&&this.warnings.push({code:"bullet-target-invalid",data:{count:String(g)}}),f>0&&this.warnings.push({code:"bullet-actual-negative",data:{count:String(f)}})}readValue(t,i){if(0===t[`${i}_cnt`])return null;const s=t[i],e=t[`${i}_gross`];return"number"==typeof s&&"number"==typeof e&&Math.abs(s)<=1e-9*e?0:"number"==typeof s&&isFinite(s)?s:null}sentiment(t,i,s){return null===t||null===i||t===i?"neu":t>i!=("-"===s)?"pos":"neg"}createSelectString(t,i){return t===a.CATEGORY&&i.hierarchy.includes(x.CATEGORYINDEX)?`${x.CATEGORYINDEX}, ${a.CATEGORY} as category`:t===a.ROWGROUP&&i.hierarchy.includes(x.ROWGROUPINDEX)?`${x.ROWGROUPINDEX}, ${a.ROWGROUP} as category`:t===a.SUBCATEGORY&&i.hierarchy.includes(x.SUBCATEGORYINDEX)?`${x.SUBCATEGORYINDEX}, ${a.SUBCATEGORY} as category`:`${t.toString()} as category`}createGroupByStr(t,i){return t===a.CATEGORY&&i.hierarchy.includes(x.CATEGORYINDEX)?`${x.CATEGORYINDEX}, ${a.CATEGORY}`:t===a.ROWGROUP&&i.hierarchy.includes(x.ROWGROUPINDEX)?`${x.ROWGROUPINDEX}, ${a.ROWGROUP}`:t===a.SUBCATEGORY&&i.hierarchy.includes(x.SUBCATEGORYINDEX)?`${x.SUBCATEGORYINDEX}, ${a.SUBCATEGORY}`:`${t.toString()}`}createOrderStr(t,i){let s=`${t.toLowerCase()}`;return i.hierarchy.length>=1&&(s=i.hierarchy.map((t=>`${t} ${i.direction}`)).toString()),s}get em(){return this.styles.fontStyles.size}fontFamily(){return this.styles.fontStyles.font.replace(/^[\d.]+px\s*/,"")}textWidth(t,i=!1){const s=l(t,{font:this.styles.fontStyles.font,fontSize:this.styles.fontStyles.size+"px",fontWeight:i?"bold":"normal"}).width;return Number.isFinite(s)&&s>0?s:.6*t.length*this.em}drawText(t,i,s,e,h={}){var n,r,a;return t.text(i).font({size:null!==(n=h.size)&&void 0!==n?n:this.styles.fontStyles.size,weight:h.bold?"bold":"normal",anchor:null!==(r=h.anchor)&&void 0!==r?r:"start"}).fill(null!==(a=h.color)&&void 0!==a?a:this.styles.fontStyles.color).attr({x:s,y:e,"font-family":this.fontFamily()})}setI18n(t){this.i18nMap=t}hasNoData(){return 0===this.rows.length}getWarnings(){return this.warnings}getQueryError(){return this.queryError}getAllocatedCanvasWidth(){return this.availableWidth}getAllocatedCanvasHeight(){return this.styles.padding.top+this.titleHeight()+this.headerHeight()+this.rows.length*this.rowBlockHeight()+this.styles.padding.bottom}titleHeight(){return""!==this.config.chartTitle?1.6*this.em:0}headerHeight(){return this.rows.length>0?1.2*this.em:0}rowBlockHeight(){const t=this.em,i=this.styles.scaleFactors.rowHeight*t;return this.normalized?i:i+this.styles.scaleFactors.tickStripHeight*t}valueLabel(t){return null===t||"none"===this.config.labels.show?"":d.number(t,"decimal",this.config.labels.decimals,0,1,this.styles.locale)}targetFamily(){var t,i;const s=null!==(i=null===(t=this.config.target)||void 0===t?void 0:t.measure)&&void 0!==i?i:"pl1";return u(this.ruleSet.getScenarioColorIndex(s))}actualLabel(){var t;return null!==(t=this.config.actual.label)&&void 0!==t?t:d.translateScenarioLabel(this.config.actual.measure,this.i18nMap)}targetLabel(){return null===this.config.target?"":void 0!==this.config.target.label?this.config.target.label:this.normalized?this.i18nMap.get("target")||"Target":d.translateScenarioLabel(this.config.target.measure,this.i18nMap)}toString(){const t=new p;return this.draw(t),t.id("drawCanvas"),t.width(this.getAllocatedCanvasWidth()),t.height(this.getAllocatedCanvasHeight()),t.attr("overflow","visible"),t.svg()}draw(t){var i,s;const e=this.em,h=this.styles.scaleFactors,n=this.styles.padding,r=t.group();if(""!==this.config.chartTitle&&this.drawText(r,this.config.chartTitle,n.left,n.top+e,{bold:!0}),0===this.rows.length)return void t.group().addClass("annotations");const a=h.rowHeight*e,o=this.rowBlockHeight(),l=n.top+this.titleHeight()+this.headerHeight(),d=l+(this.rows.length-1)*o+a,u=Math.max(...this.rows.map((t=>this.textWidth(t.category,!0))),e),c=this.rows.map((t=>this.valueLabel(t.actual))),m="none"===this.config.labels.show?0:Math.max(...c.map((t=>this.textWidth(t))),0),p=n.left+u+h.labelToAxis*e,g=Math.max(10,this.availableWidth-p-n.right-m-(m>0?h.labelToBar*e:0)),f=null!==(i=this.config.actual.unit)&&void 0!==i?i:null===(s=this.config.target)||void 0===s?void 0:s.unit,v=this.i18nMap.get("axis.in")||"in",b=l-.35*e;void 0!==f&&""!==f&&this.drawText(r,`${v} ${f}`,n.left,b,{}),this.drawText(r,this.actualLabel(),p+.2*e,b,{}),this.normalized?this.drawNormalized(r,p,g,l,d,a,o,c):this.drawClassic(r,p,g,l,a,o,c),this.rows.forEach(((t,i)=>{this.drawText(r,t.category,p-h.labelToAxis*e,l+i*o+a/2+.35*e,{anchor:"end",bold:!0})})),r.line(p,l-.2*e,p,d+.2*e).stroke({color:this.styles.axisStyles.ac.stroke,width:N(h.axisLineWidth,this.em)}).attr(D,"axis"),t.group().addClass("annotations")}drawNormalized(t,i,s,e,h,n,r,a){const o=this.em,l=this.styles.scaleFactors,d=1.05*Math.max(1,...this.rows.map((t=>{var i;return null!==(i=t.fraction)&&void 0!==i?i:0}))),u=t=>i+t/d*s,c=u(1),m=this.styles.barStyles.getSVGStyle(this.targetFamily()),p=t.line(c,e-.3*o,c,h+.3*o).stroke({color:m.stroke,width:N(l.targetLineWidth,this.em)});void 0!==m.dasharray&&p.attr("stroke-dasharray",m.dasharray),this.drawText(t,this.targetLabel(),c,e-.35*o,{anchor:"middle",bold:!0}),this.rows.forEach(((s,h)=>{const d=e+h*r+n/2;if(null===s.fraction)return void this.drawValueText(t,a[h],i+l.labelToBar*o,d,s);const m=l.barHeight*o,p=u(s.fraction);if(t.rect(Math.max(0,p-i),m).move(i,d-m/2).fill(this.styles.barStyles.ac.fill).stroke({color:this.styles.barStyles.ac.stroke,width:this.styles.barStyles.ac.width}).attr(b(this.rowKey(s),"element")).attr("data-bn-index",String(h)),this.config.showVariances&&"neu"!==s.sentiment){const i=l.varianceHeight*o,e=this.styles.varianceStyles.getSVGStyle(s.sentiment);t.rect(Math.abs(p-c),i).move(Math.min(p,c),d-i/2).fill(e.fill).stroke({color:e.stroke,width:e.width})}this.drawValueText(t,a[h],Math.max(p,c)+l.labelToBar*o,d,s)}))}drawClassic(t,i,s,e,h,n,r){const a=this.em,o=this.styles.scaleFactors,l=o.barHeight*a,u=this.config.ranges.length>0;this.rows.forEach(((c,m)=>{var p,g;const f=e+m*n,v=f+h/2,w=u&&null!==c.target?this.config.ranges.map((t=>t*c.target)):[],$=Math.max(null!==(p=c.actual)&&void 0!==p?p:0,null!==(g=c.target)&&void 0!==g?g:0,...w);if($<=0)return void this.drawValueText(t,r[m],i+o.labelToBar*a,v,c);const y=j.niceStep($,4),M=Math.ceil($/y-1e-9*y)*y,S=new j(0,M,i,i+s);let x=i;w.forEach(((i,s)=>{const e=.8*h;t.rect(Math.max(0,S.scale(i)-x),e).move(x,v-e/2).fill(this.styles.rangeColors[Math.min(s,this.styles.rangeColors.length-1)]).stroke("none"),x=S.scale(i)}));let D=i;if(null!==c.actual&&c.actual>0){const s=S.scale(c.actual);t.rect(s-i,l).move(i,v-l/2).fill(this.styles.barStyles.ac.fill).stroke({color:this.styles.barStyles.ac.stroke,width:this.styles.barStyles.ac.width}).attr(b(this.rowKey(c),"element")).attr("data-bn-index",String(m)),D=s}if(null!==c.target&&c.target>0){const i=S.scale(c.target),s=o.targetTickHeight*a,h=this.styles.barStyles.getSVGStyle(this.targetFamily()),n=t.line(i,v-s/2,i,v+s/2).stroke({color:h.stroke,width:N(o.targetLineWidth,this.em)});void 0!==h.dasharray&&n.attr("stroke-dasharray",h.dasharray),0===m&&this.drawText(t,this.targetLabel(),i,e-.35*a,{anchor:"middle"}),D=Math.max(D,i)}D=Math.max(D,x),this.drawValueText(t,r[m],D+o.labelToBar*a,v,c);const E=S.ticks(4),C=j.tickDecimals(E),O=f+h;for(const i of E){const s=S.scale(i);t.line(s,O,s,O+o.axisTickLength*a).stroke({color:this.styles.axisStyles.ac.stroke,width:N(o.axisLineWidth,this.em)}),this.drawText(t,d.number(i,"decimal",C,C,1,this.styles.locale),s,O+o.tickStripHeight*a-.2*a,{anchor:"middle"})}}))}drawValueText(t,i,s,e,h){""!==i&&this.drawText(t,i,s,e+.35*this.em,{}).attr(b(this.rowKey(h),"label"))}rowKey(t){return Object.assign(Object.assign({},w(this.config.level,t.category)),{scenario:this.config.actual.measure})}}class C{constructor(){this.rowHeight=1.9,this.barHeight=.66,this.varianceHeight=.4,this.targetTickHeight=1.1,this.targetLineWidth=.15,this.axisLineWidth=.075,this.labelToBar=.3,this.labelToAxis=.3,this.axisTickLength=.35,this.tickStripHeight=1.2}}class O{adapt(t){const i=new C;return o.isNumber(t.rowHeight)&&(i.rowHeight=t.rowHeight),o.isNumber(t.barHeight)&&(i.barHeight=t.barHeight),o.isNumber(t.varianceHeight)&&(i.varianceHeight=t.varianceHeight),o.isNumber(t.targetTickHeight)&&(i.targetTickHeight=t.targetTickHeight),o.isNumber(t.targetLineWidth)&&(i.targetLineWidth=t.targetLineWidth),o.isNumber(t.axisLineWidth)&&(i.axisLineWidth=t.axisLineWidth),o.isNumber(t.labelToBar)&&(i.labelToBar=t.labelToBar),o.isNumber(t.labelToAxis)&&(i.labelToAxis=t.labelToAxis),o.isNumber(t.axisTickLength)&&(i.axisTickLength=t.axisTickLength),o.isNumber(t.tickStripHeight)&&(i.tickStripHeight=t.tickStripHeight),i}default(){return new C}}class W{constructor(t,i,s,e,h,n){this.scaleFactors=t,this.fontStyles=i,this.axisStyles=s,this.barStyles=e,this.varianceStyles=h,this.padding=n,this.rangeColors=["#D9D9D9","#EFEFEF"],this.locale="de"}}class z{constructor(t,i,s,e,h){this.scaleFactorsBulletChartAdapter=t,this.fontStyleAdapter=i,this.svgStyleGroupAdapter=s,this.svgVariancesStyleGroupAdapter=e,this.paddingAdapter=h}adapt(t){const i=this.default();return o.isExisting(t)&&(o.isExisting(t.scaleFactors)&&(i.scaleFactors=this.scaleFactorsBulletChartAdapter.adapt(t.scaleFactors)),o.isExisting(t.fontStyles)&&(i.fontStyles=this.fontStyleAdapter.adapt(t.fontStyles)),o.isExisting(t.axisStyles)&&(i.axisStyles=this.svgStyleGroupAdapter.adapt(t.axisStyles)),o.isExisting(t.barStyles)&&(i.barStyles=this.svgStyleGroupAdapter.adapt(t.barStyles)),o.isExisting(t.varianceStyles)&&(i.varianceStyles=this.svgVariancesStyleGroupAdapter.adapt(t.varianceStyles)),o.isExisting(t.padding)&&(i.padding=this.paddingAdapter.adapt(t.padding)),Array.isArray(t.rangeColors)&&t.rangeColors.length>0&&(i.rangeColors=t.rangeColors)),i}default(){return new W(this.scaleFactorsBulletChartAdapter.default(),this.fontStyleAdapter.default(),this.svgStyleGroupAdapter.default(),this.svgStyleGroupAdapter.default(),this.svgVariancesStyleGroupAdapter.default(),this.paddingAdapter.default())}}const B=["bullet-target-missing","bullet-target-invalid","bullet-actual-negative","bullet-mixed-operation","bullet-target-none"],F=t(class extends i{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.tableName="",this.dataVersion=0,this.chartTitle="",this.target=null,this.ranges=[],this.normalizeMode="target",this.showVariances=!0,this.level=a.CATEGORY,this.limit=0,this.filter="",this.i18n=new Map,this.containerWidth=0,this.svgMarkup="",m(this)}getDb(){return this.stores||(this.stores=n(this.element)),this.stores.db.db}componentWillLoad(){this.rebuild()}componentWillUpdate(){this.rebuild()}rebuild(){const t=this.prepareStyle(),i=r(this.getDb(),this.tableName,this.filter);this.chart=new E(new c(this.ruleSetConfig),this.getDb(),i,{chartTitle:this.chartTitle,actual:this.actual,target:this.target,ranges:this.ranges,normalize:this.normalizeMode,showVariances:this.showVariances,level:this.level,order:this.order,limit:this.limit,labels:this.labels},t,this.containerWidth||0),this.chart.setI18n(this.i18n),this.svgMarkup=this.chart.hasNoData()?"":this.chart.toString(),this.syncWarnings(this.chart.getWarnings()),S(this.errors,this.chart.getQueryError())}syncWarnings(t){if(void 0===this.errors)return;const i=new Map(t.map((t=>[t.code,t.data])));for(const t of B){const s=`WARN_${t.replace(/-/g,"_")}`;if(i.has(t)){const e=void 0!==this.translator?this.translator(`.${t}`,i.get(t)):t;this.errors.addOrReplace({id:s,type:"warning",message:e})}else this.errors.remove(s)}}prepareStyle(){var t,i;const s=new z(new O,new g,new f(new $),new y(new $),new v).adapt(this.styles);return s.locale=(null===(i=null===(t=n(this.element).context)||void 0===t?void 0:t.state)||void 0===i?void 0:i.locale)||"de",s}render(){var t;if(void 0===this.chart||void 0!==this.chart.getQueryError())return s(e,null);if(this.chart.hasNoData()){const i=null!==(t=this.i18n.get("no-data"))&&void 0!==t?t:"No Data";return s(e,{class:"no-data"},s("div",{class:"empty-state"},i))}return s(e,null,s("div",{innerHTML:this.svgMarkup}))}get element(){return this}static get style(){return':host(.no-data){display:block;box-sizing:border-box;width:100%;height:100%}:host(.no-data)>div{float:none;width:100%;height:100%}:host(.no-data) .no-data~.no-data{display:none}.empty-state{box-sizing:border-box;display:flex;align-items:center;justify-content:center;float:none;width:100%;height:100%;min-height:3em;margin:0;padding:0.5em;overflow:hidden;border:0.1em dashed #ddd;color:#808080;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px);font-style:normal;text-align:center}:host{position:relative;display:inline-block}'}},[1,"bn-chart-bullet-renderer",{tableName:[1,"table-name"],dataVersion:[2,"data-version"],chartTitle:[1,"chart-title"],actual:[16],target:[16],ranges:[16],normalizeMode:[1,"normalize-mode"],showVariances:[4,"show-variances"],level:[1],order:[16],limit:[2],labels:[16],filter:[1],styles:[16],i18n:[16],containerWidth:[2,"container-width"],ruleSetConfig:[16],errors:[16],translator:[16]}]);function L(){"undefined"!=typeof customElements&&["bn-chart-bullet-renderer"].forEach((t=>{"bn-chart-bullet-renderer"===t&&(customElements.get(h(t))||customElements.define(h(t),F))}))}export{F as B,L as d}
@@ -0,0 +1 @@
1
+ import{h as t,p as e,H as i,f as n,a as o,t as s}from"./p-D6YGOYV1.js";import{m as r,a as l,b as a}from"./p-DaOm9YwQ.js";import{p as c,n as h,r as u,d}from"./p-BzjGUtYh.js";import{F as f,V as p,Q as v,s as $,a as m,I as g,b}from"./p-CniN8ALm.js";import{S as w,I as E,D as y,C as S,d as R,M}from"./p-B5tixDPM.js";import{N as O,r as N}from"./p-fCjsrD7I.js";import{D as _,w as U}from"./p-Dq9dG0Kr.js";import{D as G,b as T}from"./p-sLbQ7yZ1.js";import{F as L}from"./p-DCPLGEs_.js";import{p as x,c as C}from"./p-16rjcQ0t.js";import{d as k,g as P}from"./p-DDvWTgk1.js";import{D as A,a as D,b as W}from"./p-7ieJFBUk.js";import{A as B}from"./p-BXg3v5AO.js";import{S as F}from"./p-BPGLOHUe.js";import{S as I}from"./p-CeE4_3wQ.js";import{w as H}from"./p-DjPWZfry.js";var Y,j,z,Q,V;!function(t){t[t.ALL=-1]="ALL"}(Y||(Y={})),function(t){t[t.UP_TO_DATE=0]="UP_TO_DATE",t[t.DIRTY=1]="DIRTY"}(j||(j={})),function(t){t.LIST="list",t.SUM="sum",t.SUMNOTOTAL="sumnototal",t.OPT="opt",t.OPTNOTOTAL="optnototal"}(z||(z={})),function(t){t.ASC="asc",t.DESC="desc"}(Q||(Q={})),function(t){t.HEADER="HEADER",t.GROUPHEAD="GROUPHEAD",t.SEPERATORLINE="SEPERATORLINE",t.SUM="SUM",t.GROUPSUM="GROUP_SUM",t.DRILLELEMENT="DRILLELEMENT",t.STANDARD="STANDARD",t.PARTELEMENT="PARTELEMENT",t.ENTRY="ENTRY"}(V||(V={}));const X="none",q="setname";function K(t){return t===q?"COALESCE([setname],[setName])":`normalizeDate([date], '${t}')`}function Z(t){if("string"==typeof t?""===t.trim():"number"!=typeof t)return;const e=Number(t);return Number.isFinite(e)?e:void 0}function J(t){if(null==t)return"";if("string"==typeof t)return t.trim();const e=tt(t);return e?e.toISO():String(t)}function tt(t){if(null!=t){if("string"==typeof t){const e=_.fromISO(t,{zone:"utc"});return e.isValid?e:void 0}if("number"==typeof t){const e=_.fromMillis(t,{zone:"utc"});return e.isValid?e:void 0}if("boolean"==typeof t.isValid)return t.isValid?t:void 0}}const et=/[\s\u200e\u200f\u061c]*[%\u066a][\s\u200e\u200f\u061c]*/;class it{constructor(t,e,i,n,o,s,r,l,a){this.prefixStyle="prefix",this.isBarChart=!1,this.key=t,this.index=e,this.value=i,this.prefix=s||"",this.cssStyle=n||"",this.prefixStyle=r||"prefix",this.type=o,this.mark=void 0,this.colSpan=l||1,this.measureScale=a||1}getAsHeaderList(){if(null==this.value)return[""];const t=[];for(const e of this.value.toString().split("<br/>"))t.push(e);return t}draw(t,e){let i=this.value;if("undefined"===i||void 0===i||null==i)return"";if(Number.isNaN(Number(i)))return i;if(""===this.type||void 0===this.type||null==this.type)return i;let n=t.percent,o=t.percent;return"percentpoint"===this.type?f.number(Number(i),"percent",n,o,1,e).replace(et,""):("decimal"===this.type&&(i=+i/this.measureScale,n=t.decimal,o=t.decimal),f.number(Number(i),this.type,n,o,1,e))}drawPrefix(){return null==this.prefix?"":this.prefix}}class nt{constructor(t,e,i){this.index=t,this.groupindex=e,this.type=i,this.cssStyle=this.initCssStyle(),this.elements=[]}initCssStyle(){switch(this.type){case V.HEADER:return"groupheader";case V.SEPERATORLINE:return"";case V.DRILLELEMENT:return"ofit";case V.PARTELEMENT:return"partof";case V.STANDARD:return"";case V.SUM:return"sum";default:return""}}getCells(){return this.elements}createElement(t,e,i,n,o,s,r,l,a,c=!1,h,u=1,d){let f=s;"category"===e&&null!=l&&(f=`category-${l.toString()}`),this.type===V.HEADER?f="headerlabel":this.type===V.SEPERATORLINE&&(f=null!=s?s:e),this.type===V.PARTELEMENT&&("percent"===n&&(t="-"),"category"!==e&&"operation"!==e&&(n="percent",f="")),("-"===t||t===O&&"percent"===n)&&(f="");let p="prefix-first";r&&(p="prefix-second"),i&&(f=`${f} ${i}`);const v=new it(e,this.elements.length,t,f,n,o,p,u,a);v.isBarChart=c,v.columnStats=h,v.waterfall=d,this.elements.push(v)}}const ot=.85,st=.3,rt=.25,lt={".":.28,",":.28,"-":.34,"%":.89," ":.28," ":.28," ":.28,M:.9};function at(t,e){var i;let n=0;for(const e of t)n+=null!==(i=lt[e])&&void 0!==i?i:/[0-9+]/.test(e)?.59:.72;return n*e*1.1}let ct;function ht(t,e,i,n){const o=function(){var t,e,i;if(void 0===ct)try{ct="undefined"==typeof document?null:null!==(i=null===(e=(t=document.createElement("canvas")).getContext)||void 0===e?void 0:e.call(t,"2d"))&&void 0!==i?i:null}catch(t){ct=null}return ct}();if(o){o.font="1px __bn_font_sentinel__";const s=o.font;if(o.font=`${n?"italic ":""}${e}px ${i}`,o.font===s)return at(t,e);const r=o.measureText(t).width;if(Number.isFinite(r)&&(r>0||""===t))return r+.15*e}return at(t,e)}function ut(t,e){return Math.max(0,(t-.5)*e)}function dt(t,e,i){const n=void 0!==t.neg,o=void 0!==t.pos||!n,s=(t,n)=>t?e+i+(null!=n?n:0):0;return{sides:(n?1:0)+(o?1:0),neg:s(n,t.neg),pos:s(o,t.pos)}}function ft(t,e,i,n){const{sides:o,neg:s,pos:r}=dt(e,i,n),l=s+r>0?Math.min(1,t/(s+r)):1,a=Math.max(0,(t-(s+r)*l)/o);return{extent:a,axisX:void 0!==e.neg?s*l+a:0}}function pt(t,e,i,n){const o=ut(t,e),{sides:s,neg:r,pos:l}=dt(i,n/2,st*e);return r+l+s*function(t,e,i){return Math.min(1*e,t/(2*i))}(o,e,s)<=o+1e-6}function vt(t,e){const i=.15*t;return{maxBarWidth:t,breakGap:e,overdriveZoneWidth:i,cutWidth:Math.max(0,t-e-i)}}function $t(t,e,i,n){var o,s;const r=ut(t,e),l=st*e,{extent:a,axisX:c}=ft(r,i,rt*e/2,l),h=Math.min(.3*e,.2*a),u=void 0!==i.neg,d=void 0!==i.pos||!u;let f=u?a:0;const p=Math.max(0,null!==(o=null==n?void 0:n.neg)&&void 0!==o?o:0),v=Math.max(0,null!==(s=null==n?void 0:n.pos)&&void 0!==s?s:0);u&&d&&p+v>0&&(f=(h+(2*a*.85-2*h)*p/(p+v))/.85);const $=d?u?2*a-f:a:0;return{totalWidth:r,neg:vt(f,h),pos:vt($,h),axisX:u?c-a+f:0,labelGap:l}}function mt(t,e,i,n,o){var s,r;const l=ut(t,e),a=st*e,{extent:c,axisX:h}=ft(l,i,n/2,a),u=void 0!==i.neg,d=void 0!==i.pos||!u;let f=u?c:0,p=d?c:0;if(o&&u&&d){const t=2*c,e=Math.max(0,null!==(s=o.neg)&&void 0!==s?s:0),i=Math.max(0,null!==(r=o.pos)&&void 0!==r?r:0);e+i<=t+1e-6?(f=e+(t-e-i)/2,p=t-f):e<c?(f=e,p=t-f):i<c&&(p=i,f=t-p)}return{totalWidth:l,maxPinLength:Math.max(f,p),negPinLength:f,posPinLength:p,axisX:u?h-c+f:0,labelGap:a}}const gt={positive:{stroke:"#008f96",fill:"#008f96",fillpattern:"solid"},negative:{stroke:"#ff0000",fill:"#ff0000",fillpattern:"solid"},neutral:{stroke:"#808080",fill:"#808080",fillpattern:"outlined"},scenarios:{ac:{stroke:"#404040",fill:"#404040",fillpattern:"solid"},pp:{stroke:"#A6A6A6",fill:"#A6A6A6",fillpattern:"solid"},fc:{stroke:"#404040",fill:"#ffffff",fillpattern:"hatched"},pl:{stroke:"#404040",fill:"#ffffff",fillpattern:"outlined"}},fontColor:"#000000",fontSize:11.333305,emPx:13.3333,fontFamily:"'Noto Sans', sans-serif",unitScaling:.01,percentageScaling:.5,scaleFactor:1},bt="#666666";function wt(t,e){return`pattern-${t}-${e.replace("#","")}`}const Et=({styles:e})=>{const i=e.scaleFactor,n=6*i,o=[{id:wt("pos",e.positive.stroke),stroke:e.positive.stroke,fill:e.positive.fill},{id:wt("neg",e.negative.stroke),stroke:e.negative.stroke,fill:e.negative.fill},{id:wt("neu",e.neutral.stroke),stroke:e.neutral.stroke,fill:e.neutral.fill},...["ac","pp","fc","pl"].map((t=>({id:wt(t,e.scenarios[t].stroke),stroke:e.scenarios[t].stroke,fill:e.scenarios[t].fill})))];return t("defs",null,o.map((e=>t("pattern",{id:e.id,patternUnits:"userSpaceOnUse",width:n,height:n},t("rect",{width:n,height:n,fill:"#ffffff"}),t("line",{x1:"0",y1:n,x2:n,y2:"0",stroke:e.stroke,"stroke-width":1.5*i})))))};function yt(t,e,i=1,n,o=0,s=!0,r){const l=(e,i)=>(t>0&&e!==i?"+":"")+e;if(e){const e=(t,e)=>s?f.number(t,"percent",e,e,1,n):f.number(100*t,"decimal",e,e,1,n),i=i=>l(e(t,i),e(0,i));let r=Math.min(20,Math.max(0,Math.trunc(o)||0));for(;r>0&&i(r).length>7;)r--;return i(r)}const a=t/i;if(void 0!==r){const t=t=>f.number(t,"decimal",r,r,1,n);return l(t(a),t(0))}const c=Math.abs(a);let h=1,u="";c>=9995e5?(h=1e9,u="B"):c>=999500?(h=1e6,u="M"):c>=999.5&&(h=1e3,u="K");const d=c>=10*h?0:1;return l(f.number(a/h,"decimal",d,0,1,n),f.number(0,"decimal",d,0,1,n))+u}function St(t){const e=t.slice(0,2).toLowerCase();return["ac","pp","fc","pl"].includes(e)}function Rt(t){const e=t.slice(0,2).toLowerCase();return"pp"===e?"pp":"fc"===e?"fc":"pl"===e?"pl":"ac"}function Mt(t,e){if(St(t))return null;const i=new p(t);if(!i.isValid)return null;const n=Rt(i.base),o=Rt(i.delta);return{minuend:e.scenarios[n],minuendSlot:n,reference:e.scenarios[o],referenceSlot:o}}const Ot=({x:e,height:i,look:n,styles:o})=>{const s=o.scaleFactor,r=rt*o.emPx,{reference:l,referenceSlot:a}=n;let c;if("outlined"===l.fillpattern){const n=r/2-.5*s;c=[e-n,e+n].map((e=>t("line",{x1:e,y1:0,x2:e,y2:i,stroke:l.stroke,"stroke-width":1*s})))}else c=t("line","hatched"===l.fillpattern?{x1:e,y1:0,x2:e,y2:i,stroke:l.stroke,"stroke-width":r,"stroke-dasharray":""+2*s}:{x1:e,y1:0,x2:e,y2:i,stroke:l.fill,"stroke-width":r});return t("g",{class:`variance-axis axis-${a}`},c)};function Nt(t){return void 0!==t.pos||void 0===t.neg}function _t(t,e){return{neg:t.min<0?e:void 0,pos:t.max>0?e:void 0}}function Ut(t,e,i,n){return St(t)?function(t,e){const i=Rt(t);return e.scenarios[i]}(t,n):function(t,e,i){const n=t>=0;return e?n?i.positive:i.negative:n?i.negative:i.positive}(e,i,n)}function Gt(t,e){const i=t.fillpattern;return"hatched"===i?`url(#${wt(e,t.stroke)})`:"outlined"===i?"transparent":t.fill}function Tt(t){return"outlined"===t.fillpattern?{stroke:t.stroke,strokeWidth:1.5}:{stroke:"none",strokeWidth:0}}const Lt=e=>{const{value:i,scenario:n,columnStats:o,height:s,isPositiveGood:r,formattedValue:l,measureScale:a,locale:c,decimalDigits:h,columnWidthEm:u=10,labelWidths:d,sideMax:f,styles:p=gt}=e,v=p.scaleFactor,$=p.fontSize,m=l||yt(i,!1,a,c,0,!0,h),g=null!=d?d:_t(o,ht(m,$,p.fontFamily,!1)),b=i>0||0===i&&Nt(g),{neg:w=Math.max(0,-o.min),pos:E=Math.max(0,o.max)}=null!=f?f:{},y=$t(u,p.emPx,g,{neg:w,pos:E}),{totalWidth:S,axisX:R,labelGap:M}=y,{breakGap:O,overdriveZoneWidth:N,cutWidth:_}=b?y.pos:y.neg,U=Math.abs(i)*p.unitScaling*$,G=U-_>1e-6,T=Math.max(0,(b?E:w)*p.unitScaling*$-_),L=Math.max(0,U-_),x=T>0?L/T*N:0,C=2*v,k=s-2*C,P=C,A=Mt(n,p),D=Ut(n,i,r,p),W=null==A?void 0:A.minuend.fillpattern,B="hatched"===W||"outlined"===W?Object.assign(Object.assign({},D),{fillpattern:W}):D,F=Gt(B,St(n)?Rt(n):r?b?"pos":"neg":b?"neg":"pos"),{stroke:I,strokeWidth:H}=A&&"hatched"===B.fillpattern?{stroke:B.stroke,strokeWidth:1}:Tt(B),Y=A?rt*p.emPx/2:0,j=b?R+Y:R-Y,z=G?_:U,Q=G?_+O+x:U,V=b?j+Q+M:j-Q-M,X=b?"start":"end";return t("svg",{width:S,height:s,class:"cell-bar-chart absolute-variance",style:{overflow:"visible"}},t(Et,{styles:p}),!A&&t("line",{x1:R,y1:0,x2:R,y2:s,stroke:bt,"stroke-width":1*v}),z>0&&t("rect",{x:b?j:j-z,y:P,width:z,height:k,fill:F,stroke:I,"stroke-width":H*v}),G&&x>0&&t("rect",{x:b?j+_+O:j-_-O-x,y:P,width:x,height:k,fill:F,stroke:I,"stroke-width":H*v}),G&&function(e,i,n,o,s){const r=e+i/2,l=.35*i,a=o/3,c=.3*i;let h=`M ${r-l} ${n}`;for(let t=0;t<3;t++)h+=` L ${r-l-c} ${n+a*(t+.5)} L ${r-l} ${n+a*(t+1)}`;let u=`M ${r+l} ${n}`;for(let t=0;t<3;t++)u+=` L ${r+l+c} ${n+a*(t+.5)} L ${r+l} ${n+a*(t+1)}`;return[t("rect",{x:e,y:n-1,width:i,height:o+2,fill:"#ffffff"}),t("path",{d:h,fill:"none",stroke:"#000000","stroke-width":1*s}),t("path",{d:u,fill:"none",stroke:"#000000","stroke-width":1*s})]}(b?j+_:j-_-O,O,P,k,v),A&&t(Ot,{x:R,height:s,look:A,styles:p}),t("text",{x:V,y:s/2,dy:"0.35em","text-anchor":X,fill:p.fontColor,"font-size":$,"font-family":p.fontFamily},m))},xt=e=>{var i,n;const{value:o,scenario:s,columnStats:r,height:l,isPositiveGood:a,formattedValue:c,measureScale:h,locale:u,percentDigits:d,percentSign:f,columnWidthEm:p=10,labelWidths:v,sideMax:$,styles:m=gt}=e,g=m.scaleFactor,b=m.fontSize,w=10*g,E=100*m.percentageScaling*b,y=c||yt(o,!0,h,u,d,f),S=null!=v?v:_t(r,ht(y,b,m.fontFamily,!0)),{neg:R=Math.max(0,-r.min),pos:M=Math.max(0,r.max)}=null!=$?$:{},{totalWidth:O,negPinLength:N,posPinLength:_,axisX:U,labelGap:G}=mt(p,m.emPx,S,w,{neg:R*E,pos:M*E}),T=l/2,L=Math.abs(o)*E,x=o>0||0===o&&Nt(S),C=x?_:N,k=L-C>1e-6,P=x?1:-1,A=U+P*Math.min(L,C),D=Ut(s,o,a,m),W=Mt(s,m),B=null!==(i=null==W?void 0:W.minuend)&&void 0!==i?i:m.scenarios.ac,F=U+P*(C+w/2),I=F-P*w,H=(k?F:A+P*(w/2))+P*G;return t("svg",{width:O,height:l,class:"cell-bar-chart relative-variance",style:{overflow:"visible"}},t(Et,{styles:m}),W?t(Ot,{x:U,height:l,look:W,styles:m}):t("line",{x1:U,y1:0,x2:U,y2:l,stroke:bt,"stroke-width":1*g}),t("line",{x1:U,y1:T,x2:k?I:A,y2:T,stroke:D.fill,"stroke-width":3*g}),k?t("polygon",{points:`${F},${T} ${I},${T-w/2} ${I},${T+w/2}`,fill:D.fill}):t("rect",{x:A-w/2,y:T-w/2,width:w,height:w,fill:"outlined"===B.fillpattern?"#ffffff":Gt(B,null!==(n=null==W?void 0:W.minuendSlot)&&void 0!==n?n:"ac"),stroke:B.stroke,"stroke-width":1*g}),t("text",{x:H,y:l/2,dy:"0.35em","text-anchor":x?"start":"end",fill:m.fontColor,"font-size":b,"font-style":"italic","font-family":m.fontFamily},y))},Ct=e=>{const{value:i,columnStats:n,isRelative:o,styles:s=gt}=e;return null==i||isNaN(i)||!n||0===n.absMax?t("span",{class:"bar-chart-empty",style:{color:s.fontColor,fontStyle:"italic"}},"-"):t(o?xt:Lt,Object.assign({},e))},kt=e=>{const{value:i,scenario:n,height:o,measureScale:s,locale:r,decimalDigits:l,columnWidthEm:a=10,styles:c=gt,waterfall:h}=e,u=c.scaleFactor,d=c.fontSize,f=h.max-h.min;if(null==i||isNaN(i)||f<=0)return t("span",{class:"bar-chart-empty",style:{color:c.fontColor,fontStyle:"italic"}},"-");const{totalWidth:p,labelAreaWidth:v,barAreaWidth:$,labelGap:m}=function(t,e){const i=ut(t,e),n=Math.min(2.85*e,i/4);return{totalWidth:i,labelAreaWidth:n,barAreaWidth:i-2*n,labelGap:st*e}}(a,c.emPx),g=$/f,b=t=>v+(t-h.min)*g,w=2*u,E=o-2*w,y=w,S=b(0),R=b(h.start),M=b(h.end),O=Math.min(R,M),N=Math.abs(M-R),_=Ut(n,i,!1,c),U=Gt(_,Rt(n)),{stroke:G,strokeWidth:T}=Tt(_),L=yt(i,"partof"===h.kind,s,r,0,!0,l).replace(/^\+/,""),x=M<R,C=x?O-m:O+N+m,k=x?"end":"start";return t("svg",{width:p,height:o,class:"cell-bar-chart waterfall-bar",style:{overflow:"visible"}},t(Et,{styles:c}),t("line",{x1:S,y1:0,x2:S,y2:o,stroke:bt,"stroke-width":1*u}),void 0!==h.parentStart&&void 0!==h.parentEnd&&t("line",{x1:b(h.parentStart),y1:0,x2:b(h.parentStart),y2:o,stroke:bt,"stroke-width":1*u,"stroke-dasharray":`${2*u},${2*u}`}),void 0!==h.parentStart&&void 0!==h.parentEnd&&t("line",{x1:b(h.parentEnd),y1:0,x2:b(h.parentEnd),y2:o,stroke:bt,"stroke-width":1*u,"stroke-dasharray":`${2*u},${2*u}`}),N>0&&t("rect",{x:O,y,width:N,height:E,fill:U,stroke:G,"stroke-width":T*u}),t("text",{x:C,y:o/2,dy:"0.35em","text-anchor":k,fill:c.fontColor,"font-size":d,"font-family":c.fontFamily},L))},Pt=`IFNULL(${v.ROWGROUP}, '')`;class At{constructor(t){this.groups=[v.CATEGORY,v.CATEGORYINDEX],z.OPT!==t.type&&z.OPTNOTOTAL!==t.type||this.groups.unshift(v.OPERATION),t.grouped&&(this.groups.push(v.ROWGROUP),this.groups.push(v.ROWGROUPINDEX))}toString(){return this.groups.map((t=>t===v.ROWGROUP?Pt:t)).toString()}select(){return this.groups.map((t=>t===v.ROWGROUP?`${Pt} as ${t}`:t)).toString()}noCategory(){return this.groups.filter((t=>t!==v.CATEGORY))}toArray(){return this.groups}}class Dt{constructor(t,e){this.hasPartOf=!1,this.params=[],this.sortSelect="",this.hasBlankRowGroup=!1,this.config=t,this.i18n=e}execute(t,e){var i;this.db=t,this.fromExpr=e;for(const t of[...this.config.scenarios,...this.config.categoryThereOf.keys()])if(!L.test(t))throw new Error(`invalid identifier "${t}"`);const n=[],o=[],s=[],r=this.config.scenarios.map((t=>this.translateScenarioSQL(t,!1,this.config.type))).toString(),l=this.config.scenarios.map((t=>this.translateScenarioSQL(t,!0,this.config.type))).toString(),a=this.getRelativeScenarios(),c=this.config.attributes.map((t=>this.translateAttributeSQL(t))).toString(),h=new At(this.config),u=this.config.interval===q?this.config.sortOrder:{hierarchy:this.config.sortOrder.hierarchy.map((t=>{var e,i;return null!==(i=null===(e=x(t))||void 0===e?void 0:e.column)&&void 0!==i?i:t})),direction:this.config.sortOrder.direction};let d=["",""];u.hierarchy.length>0&&(d=this.createOrderString(u)),this.hasPartOf=this.checkConfigForPartOf();const{hierarchy:f,direction:p}=u,$=f.filter((t=>t===v.ROWGROUP||t===v.ROWGROUPINDEX||t.toUpperCase()in w)),m=$.filter((t=>t.toUpperCase()in w)).map((t=>`, SUM(${t} * transformOperator(operation)) as ${t}`)).join(""),g=$.length>0?$.map((t=>`${t} ${p}`)).toString():`${v.ROWGROUPINDEX} asc`,b=t.exec(`SELECT COUNT(DISTINCT ${v.CATEGORY}) as ${v.TOTALROWCOUNT} ${this.config.grouped?`, ${Pt} as ${v.ROWGROUP}, FIRST(${v.ROWGROUPINDEX}) as ${v.ROWGROUPINDEX}${m}`:""}\n FROM ${e} ${this.config.grouped?`GROUP BY ${Pt} ORDER BY ${g}`:""}`);return 0===b.length||1===b.length&&0===(null!==(i=b[0][v.TOTALROWCOUNT])&&void 0!==i?i:0)&&!this.config.grouped?[]:(this.hasBlankRowGroup=this.config.grouped&&b.some((t=>""===t.rowGroup)),b.forEach((t=>{const e=this.config.grouped?""===t.rowGroup?`WHERE (${v.ROWGROUP} IS NULL OR ${v.ROWGROUP} = '')`:`WHERE ${v.ROWGROUP} = ${this.bind(t.rowGroup)}`:"";let i="";this.config.limit&&(i=`LIMIT ${this.config.limit}`),this.createGroupHeaderRow(t,n),this.createDataRow(n,t,h,r,c,e,d,i),this.createRestRow(t,n,h,r,e,d),this.createGroupSumRow(n,o,t,l,e,d)})),this.createTotalSumRow(n,o,l),n.forEach((t=>s.push(this.exec(t)))),this.detectNaNCells(this.config.scenarios,s),this.createThereOfDrillRows(r,c,d,s),this.createPartOfDrillRows(r,d,o,s),this.createIntervalColumns(s),this.createThereOfDrillColumns(this.config.categoryThereOf,s),this.calculateColumnGroupRest(s,this.config.categoryThereOf),this.calculateRelativeVariances(s,a),s)}detectNaNCells(t,e){e.forEach((e=>{e.map((e=>(t.forEach((t=>{const i=new p(t);!0===i.isValid?0!==e[i.base+"_cnt"]&&0!==e[i.delta+"_cnt"]||(e[t]=Number.NaN):0===e[t+"_cnt"]&&(e[t]=Number.NaN)})),e)))}))}createPartOfDrillRows(t,e,i,n){if(null==this.config.partOf||0===this.config.partOf.length||this.config.type===z.LIST)return;const o=this.createPartOfQuery(t,e);let s=[];const r=this.db,l=this.params;o.forEach((t=>{s.push(...this.exec(t))}));const a=this.exctractScenarioNames(t),c=[];i.forEach((function(t){c.push(...r.exec(t,l))}));const h=new Map;c.forEach((t=>h.set(t[v.ROWGROUP],t))),s=this.reduceResDrillByCategoryGroups(s,a),s.forEach((function(t){a.forEach((e=>{try{t[e]=t[e]/h.get(t[v.ROWGROUP])[e]}catch(i){console.error("DataQuery: partOf drill row calculation failed",e,i),t[e]=Number.NaN}}))})),this.injectDrillRowsToResultRows(s,n)}createRestRow(t,e,i,n,o,s){var r;if(t.totalRowCnt-this.config.limit>0&&0!==this.config.limit){const l=this.exctractScenarioNames(n).map((t=>`SUM(${t}) as ${t}`)).join(", "),a=z.OPT===this.config.type||z.OPTNOTOTAL===this.config.type?", CASE WHEN MAX(transformOperator(operation)) = -1 THEN '-' ELSE '+' END as restOperation":"";e.push(`SELECT ${v.ROWNR}, 1 as ${v.ROWGROUPINDEX} , 'ENTRY' as ${v.TYPE}, 'NO_GROUP' as ${v.ROWGROUP}, ${this.bind(String(null!==(r=t.rowGroup)&&void 0!==r?r:""))} as restRowGroup, 'REST' as ${v.CATEGORY}${a} ${l.length>0?", "+l:""} FROM (SELECT ROWNUM() AS ${v.ROWNR}, ${e.length} as ${v.ROWGROUPINDEX} , 'ENTRY' as ${v.TYPE}, ${this.bind(String(t.rowGroup||"NO_GROUP"))} as ${v.ROWGROUP}, ${i.select()} ${n.length>0?",".concat(n):""}${this.sortSelect} FROM ${this.fromExpr} ${o} GROUP BY ${i} ORDER BY ${s[0]}) t WHERE t.rowNr > ${this.config.limit}`)}}createDataRow(t,e,i,n,o,s,r,l){t.push(`SELECT ROWNUM() AS ${v.ROWNR},\n ${t.length} as ${v.ROWGROUPINDEX},\n 'ENTRY' as ${v.TYPE},\n ${this.bind(String(e.rowGroup||"NO_GROUP"))} as ${v.ROWGROUP},\n '${v.CATEGORYINDEX}',\n ${i.select()} ${n.length>0?",".concat(n):""} ${o.length>0?",".concat(o):""}${this.sortSelect}\n FROM ${this.fromExpr} ${s}\n GROUP BY ${i}\n ORDER BY ${r[0]} ${l}`)}createGroupHeaderRow(t,e){if(!0===this.config.grouped&&(this.config.showGroupTitle||!this.hasGroupSum())){const i=this.bind(String(t.rowGroup)),n=""===t.rowGroup?this.bind("-"):i;e.push(`SELECT ROWNUM() AS ${v.ROWNR},\n ${e.length} as ${v.ROWGROUPINDEX},\n 'GROUPHEAD' as ${v.TYPE},\n ${i} as ${v.ROWGROUP} ${this.config.showGroupTitle?`,${n} as ${v.CATEGORY}`:""}\n FROM ${this.fromExpr}\n GROUP BY '1'`)}}hasGroupSum(){return z.SUM===this.config.type||z.SUMNOTOTAL===this.config.type||z.OPT===this.config.type||z.OPTNOTOTAL===this.config.type}createGroupSumRow(t,e,i,n,o,s){if(!0===this.config.grouped&&this.hasGroupSum()){const r=this.bind(String(i.rowGroup));t.push(`SELECT ${t.length} as ${v.ROWGROUPINDEX},\n '=' as ${v.OPERATION},\n ${r} as ${v.ROWGROUP},\n ROWNUM() AS ${v.ROWNR},\n 'GROUP_SUM' as ${v.TYPE} ${n.length>0?",".concat(n):""}\n FROM ${this.fromExpr} ${o}\n ORDER BY ${s[0]} `),e.push(`SELECT ${t.length} as ${v.ROWGROUPINDEX},\n '=' as ${v.OPERATION},\n ${r} as ${v.ROWGROUP},\n ROWNUM() AS ${v.ROWNR},\n 'GROUP_SUM' as ${v.TYPE} ${n.length>0?",".concat(n):""}\n FROM ${this.fromExpr} ${o}\n ORDER BY ${s[0]} `)}}createTotalSumRow(t,e,i){var n;if(z.SUM===this.config.type||z.OPT===this.config.type){const e=(null===(n=this.config.title)||void 0===n?void 0:n.trim())||"SUM_TOTAL",o=this.hasPartOf&&!1===this.config.grouped&&"SUM_TOTAL"!==e?`${this.i18n.get("SUM_TOTAL")||"SUM_TOTAL"} ${e}`:e;t.push(`SELECT ${t.length} as ${v.ROWGROUPINDEX},\n ${this.bind(o)} as ${v.ROWGROUP},\n '=' as ${v.OPERATION},\n 'SUM' as ${v.TYPE} ${i.length>0?",".concat(i):""}\n FROM ${this.fromExpr} `)}e.push(`SELECT ${t.length} as ${v.ROWGROUPINDEX},\n 'SUM_TOTAL' as ${v.ROWGROUP},\n '=' as ${v.OPERATION},\n 'SUM' as ${v.TYPE} ${i.length>0?",".concat(i):""}\n FROM ${this.fromExpr} `)}reduceResDrillByCategoryGroups(t,e){const i=new Map;return t.forEach((function(t){const n=t.rowNr+t.rowGroup+t.type+t.category;if(i.has(n)){const o=i.get(n);e.forEach((e=>{try{o[e]+=t[e]}catch(t){console.error("DataQuery: drill row aggregation failed",e,t)}}))}else i.set(n,t)})),[...i.values()]}injectDrillRowsToResultRows(t,e){const i=new Map;if(!0===this.config.grouped)t.forEach((function(t){e.forEach((function(e){const n=e.findIndex((e=>e.category===t.category&&e.rowGroup===t.rowGroup));if(n>=0){if(i.has(`${t.category}_${t.rowGroup}`)){const e=i.get(`${t.category}_${t.rowGroup}`)||0;i.set(`${t.category}_${t.rowGroup}`,e+1)}else i.set(`${t.category}_${t.rowGroup}`,1);t[v.ROWNR]=i.get(`${t.category}_${t.rowGroup}`),e.splice(n+t[v.ROWNR],0,t)}}))}));else{const n=this.findDuplicateSubCategories(t);t.forEach((function(t){e.forEach((function(e){const o=e.findIndex((e=>null!=e.category&&e.category===t.category));if(o>=0){if(i.has(`${t.category}`)){const e=i.get(`${t.category}`)||0;i.set(`${t.category}`,e+1)}else i.set(`${t.category}`,1);null!=t.rowGroup&&""!==t.rowGroup&&n.includes(`${t.category}##${t.subCategory}`)&&(t.rawSubCategory=t.subCategory,t.subCategory=`${t.subCategory} (${t.rowGroup})`),e.splice(o+t[v.ROWNR],0,t)}}))}))}}createThereOfDrillRows(t,e,i,n){if(void 0===this.config.thereOf||0===this.config.thereOf.length)return;const o=[],s=[];this.config.thereOf.forEach((n=>{let s=!0,r="1 <> 1 OR ( ";null!=n.category&&0!==n.category.length&&n.category.trim()&&(r+=` ${v.CATEGORY} = ${this.bind(n.category)}`,s=!1),null!=n.rowGroup&&0!==n.rowGroup.length&&n.rowGroup.trim()&&(r+=` ${s?"":"AND"} ${v.ROWGROUP} = ${this.bind(n.rowGroup)}`,s=!1),null!=n.subCategory&&0!==n.subCategory.length&&n.subCategory.trim()&&(r+=` ${s?"":"AND"} ${v.SUBCATEGORY} = ${this.bind(n.subCategory)}`),r+=")",o.push(`SELECT ROWNUM() AS ${v.ROWNR},\n null as operation,\n 'DRILLELEMENT' as ${v.TYPE},\n ${v.CATEGORY},\n ${v.SUBCATEGORY},\n ${this.drillRowGroup} as ${v.ROWGROUP},\n ${t} ${e.length>0?",".concat(e):""}${this.sortSelect}\n FROM ${this.fromExpr}\n WHERE ${r}\n GROUP BY ${this.drillRowGroup}, ${v.CATEGORY}, ${v.SUBCATEGORY}\n ORDER BY ${i[1]}`)})),o.forEach((t=>{s.push(...this.exec(t))})),this.injectDrillRowsToResultRows(s,n)}calculateRelativeVariances(t,e){t.forEach((t=>{t.forEach((t=>{"GROUPHEAD"!==t[v.TYPE]&&e.forEach(((e,i)=>{var n;t[i]=null!==(n=N(t[i],t[e]))&&void 0!==n?n:O}))}))}))}calculateColumnGroupRest(t,e){if(null==e||0===e.size)return;const i=new Map,n=new Map;e.forEach(((t,e)=>{const o=t,s=[];for(const t of o)s.push(`${e}##${t.name}`);i.set(e,s),n.set(`${e}##REST`,!1)})),t.forEach((t=>{t.forEach((t=>{"GROUPHEAD"!==t[v.TYPE]&&i.forEach(((e,i)=>{let o=0;e.forEach((e=>{void 0!==t[e]&&(o+=t[e])})),t[`${i}##REST`]=t[i]-o,0!==t[`${i}##REST`]&&n.set(`${i}##REST`,!0)}))}))}));const o=Array.from(n.entries()).filter((([t,e])=>!e)).map((([t])=>t));t.forEach((t=>{t.forEach((t=>{for(const e of o)delete t[e]}))}))}createIntervalColumns(t){var e,i,n,o,s;if(this.config.interval===X||this.config.categoryThereOf.size>0||0===this.config.scenarios.length)return;const r="##",l=`(SELECT *, ${K(this.config.interval)} as __interval FROM ${this.fromExpr}) as p`,a=this.config.scenarios.map((t=>this.translateScenarioSQL(t,!1,this.config.type))).toString(),c=this.config.scenarios.map((t=>this.translateScenarioSQL(t,!0,this.config.type))).toString(),h=[...new Set(this.exctractScenarioNames(a))],u=this.getRelativeScenarios(),d=new At(this.config),f=z.OPT===this.config.type||z.OPTNOTOTAL===this.config.type,$=this.config.grouped&&(z.SUM===this.config.type||z.SUMNOTOTAL===this.config.type||z.OPT===this.config.type||z.OPTNOTOTAL===this.config.type),m=this.checkConfigForPartOf()&&this.config.type!==z.LIST,g=t=>this.exec(t),b=t=>(this.config.scenarios.forEach((e=>{const i=new p(e);!0===i.isValid?0!==t[i.base+"_cnt"]&&0!==t[i.delta+"_cnt"]||(t[e]=Number.NaN):0===t[e+"_cnt"]&&(t[e]=Number.NaN)})),u.forEach(((e,i)=>{var n;t[i]=null!==(n=N(t[i],t[e]))&&void 0!==n?n:O})),t),w=(t,e,i)=>{for(const n of this.config.scenarios)t[n+r+i]=e[n]},E=g(`SELECT ${d.select()}, __interval ${a.length>0?",".concat(a):""}\n FROM ${l}\n GROUP BY ${d}, __interval`),y=t=>"ENTRY"===t.type&&null!=t.restRowGroup;if(this.config.limit>0)for(let n=0;n<t.length;n++){const o=t[n].find(y);if(!o)continue;let s;for(let e=n-1;e>=0&&!s;e--){const i=t[e].filter((t=>"ENTRY"===t.type&&!y(t)));i.length>0&&(s=i)}if(!s)continue;const r=new Set(s.map((t=>t.category))),l=s[0].rowGroup,a=new Map;for(const t of E){if(this.config.grouped&&t.rowGroup!==l)continue;if(r.has(t.category))continue;const n=J(t.__interval);let o=a.get(n);o||(o={},a.set(n,o));for(const n of h)o[n]=(null!==(e=o[n])&&void 0!==e?e:0)+(null!==(i=t[n])&&void 0!==i?i:0)}a.forEach(((t,e)=>{w(o,b(t),e)}))}for(const e of E){const i=J(e.__interval);b(e);for(const n of t)for(const t of n)"ENTRY"!==t.type||y(t)||t.category!==e.category||this.config.grouped&&t.rowGroup!==e.rowGroup||f&&t.operation!==e.operation||w(t,e,i)}const S=$||m&&this.config.grouped?g(`SELECT ${Pt} as ${v.ROWGROUP}, __interval ${c.length>0?",".concat(c):""}\n FROM ${l}\n GROUP BY ${Pt}, __interval`):[],R=new Map;if(S.forEach((t=>R.set(`${t.rowGroup}${r}${J(t.__interval)}`,t))),$)for(const e of S){const i=J(e.__interval),n=b(Object.assign({},e));for(const o of t)for(const t of o)"GROUP_SUM"===t.type&&t.rowGroup===e.rowGroup&&w(t,n,i)}const M=z.SUM===this.config.type||z.OPT===this.config.type,_=M||m&&!this.config.grouped?g(`SELECT __interval ${c.length>0?",".concat(c):""}\n FROM ${l}\n GROUP BY __interval`):[],U=new Map;if(_.forEach((t=>U.set(J(t.__interval),t))),M)for(const e of _){const i=J(e.__interval),n=b(Object.assign({},e));for(const e of t)for(const t of e)"SUM"===t.type&&w(t,n,i)}if(null!=this.config.thereOf&&this.config.thereOf.length>0){const e=[];this.config.thereOf.forEach((t=>{e.push(...g(`SELECT ${this.drillRowGroup} as ${v.ROWGROUP}, ${v.CATEGORY}, ${v.SUBCATEGORY}, __interval ${a.length>0?",".concat(a):""}\n FROM ${l}\n WHERE ${this.createThereOfWhereClause(t)}\n GROUP BY ${this.drillRowGroup}, ${v.CATEGORY}, ${v.SUBCATEGORY}, __interval`))}));for(const i of e){const e=J(i.__interval);b(i);for(const n of t)for(const t of n)"DRILLELEMENT"===t.type&&t.category===i.category&&t.rowGroup===i.rowGroup&&(t.subCategory!==i.subCategory&&t.subCategory!==`${i.subCategory} (${i.rowGroup})`||w(t,i,e))}}if(m){let e="1 <> 1 ";null===(n=this.config.partOf)||void 0===n||n.forEach((t=>{e+=`OR (${v.CATEGORY} = ${this.bind(t.category)}`,null!=t.rowGroup&&0!==t.rowGroup.length&&t.rowGroup.trim()&&(e+=`and ${v.ROWGROUP} = ${this.bind(t.rowGroup)}`),e+=")"}));const i=g(`SELECT ${v.CATEGORY}, ${this.config.grouped?`${v.ROWGROUP}`:`'SUM_TOTAL' as ${v.ROWGROUP}`}, __interval ${a.length>0?",".concat(a):""}\n FROM ${l}\n WHERE ${e}\n GROUP BY ${v.ROWGROUP}, ${v.CATEGORY}, __interval`),c=new Map;for(const t of i){const e=`${t.rowGroup}${r}${t.category}${r}${J(t.__interval)}`,i=c.get(e);if(i)for(const e of h)i[e]=(null!==(o=i[e])&&void 0!==o?o:0)+(null!==(s=t[e])&&void 0!==s?s:0);else c.set(e,t)}c.forEach((e=>{const i=J(e.__interval),n=this.config.grouped?R.get(`${e.rowGroup}${r}${i}`):U.get(i);for(const t of h)e[t]=e[t]/(n?n[t]:Number.NaN);b(e);for(const n of t)for(const t of n)"PARTELEMENT"===t.type&&t.category===e.category&&t.rowGroup===e.rowGroup&&w(t,e,i)}))}}createThereOfWhereClause(t){let e=!0,i="1 <> 1 OR ( ";return null!=t.category&&0!==t.category.length&&t.category.trim()&&(i+=` ${v.CATEGORY} = ${this.bind(t.category)}`,e=!1),null!=t.rowGroup&&0!==t.rowGroup.length&&t.rowGroup.trim()&&(i+=` ${e?"":"AND"} ${v.ROWGROUP} = ${this.bind(t.rowGroup)}`,e=!1),null!=t.subCategory&&0!==t.subCategory.length&&t.subCategory.trim()&&(i+=` ${e?"":"AND"} ${v.SUBCATEGORY} = ${this.bind(t.subCategory)}`),i+")"}getRelativeScenarios(){const t=new Map;return this.config.scenarios.forEach((e=>{const i=this.createRelativeScenario(e);null!=i&&t.set(i.key,i.value)})),t}translateScenarioSQL(t,e,i){const n=new p(t);if(z.OPT===i||z.OPTNOTOTAL===i){if(n.isValid){const i=e?" * transformOperator(operation)":"",o=e?`SUM((${n.base} - ${n.delta})${i}) as ${t}`:`SUM(${n.base} - ${n.delta}) as ${t}`;return"dr"===n.type?`${o}, SUM(${n.delta}${i}) as dr_${n.delta}`:o}return e?`SUM(${t} * transformOperator(operation)) as ${t}, COUNT(ISNULL(${t})) as ${t}_cnt`:`SUM(${t}) as ${t}, COUNT(ISNULL(${t})) as ${t}_cnt`}return n.isValid?"dr"===n.type?`SUM((${n.base} * transformOperator(operation)) - (${n.delta} * transformOperator(operation))) as ${t}, SUM(${n.delta} * transformOperator(operation)) as dr_${n.delta}`:`SUM((${n.base} * transformOperator(operation))- (${n.delta} * transformOperator(operation))) as ${t}`:`SUM(${t} * transformOperator(operation)) as ${t}, COUNT(ISNULL(${t})) as ${t}_cnt`}translateAttributeSQL(t){const e=`[${t.arg}]`,i=/^(ac|pp|fc|pl)[1-4]$/.test(t.arg)&&this.config.type!==z.OPT&&this.config.type!==z.OPTNOTOTAL;switch(t.fn){case"set":return`SETAGG(${e}) as ${t.alias}`;case"first":return`FIRST(${e}) as ${t.alias}`;case"last":return`LAST(${e}) as ${t.alias}`;case"min":return`MIN(${e}) as ${t.alias}`;case"max":return`MAX(${e}) as ${t.alias}`;case"avg":return i?`AVG(${e} * transformOperator(operation)) as ${t.alias}`:`AVG(${e}) as ${t.alias}`;case"sum":return i?`SUM(${e} * transformOperator(operation)) as ${t.alias}`:`SUM(${e}) as ${t.alias}`;case"lit":{const e=t.arg;return`${this.bind(""===e||Number.isNaN(Number(e))?e:Number(e))} as ${t.alias}`}}}get drillRowGroup(){return this.config.grouped?Pt:v.ROWGROUP}exec(t){const e=this.db.exec(t,this.params);return this.config.grouped&&e.forEach((t=>t.rowGroup=null==t.rowGroup?"":String(t.rowGroup))),e}bind(t){return`$${this.params.push(t)-1} `}createOrderString(t){const e=Q.ASC===t.direction?Q.DESC:Q.ASC,i=new Map;t.hierarchy.forEach(((t,e)=>{const n=x(t),o=null==n?void 0:n.bucket;("variance"===(null==n?void 0:n.kind)||"scenario"===(null==n?void 0:n.kind)&&void 0!==o)&&i.set(e,this.translateSortKeySQL(n,o,e))})),this.sortSelect=[...i.values()].map((t=>`, ${t}`)).join("");const n=t.hierarchy.some((t=>{var e;const i=null===(e=x(t))||void 0===e?void 0:e.kind;return"scenario"===i||"variance"===i}));n&&(this.sortSelect+=`, CASE WHEN ${v.CATEGORY} = 'REST' THEN 1 ELSE 0 END as __sortrest`);const o=(t,e,n)=>i.has(e)?`__sortnull${e} asc, __sort${e} ${n}`:`${t} ${n}`,s=t.hierarchy.map(((e,i)=>o(e,i,t.direction))).toString(),r=t.hierarchy.map(((t,i)=>o(t,i,e))).toString();return n?[`__sortrest asc, ${s}`,`__sortrest desc, ${r}`]:[s,r]}translateSortKeySQL(t,e,i){const n=z.OPT===this.config.type||z.OPTNOTOTAL===this.config.type?"":" * transformOperator(operation)",o=void 0===e?"":`TRIM(CAST(${K(q)} AS STRING)) = ${this.bind(e)}`,s=t=>`SUM(${o?`(CASE WHEN ${o} THEN ${t} ELSE 0 END)`:t}${n})`,r=t=>`SUM(CASE WHEN ${o?`${o} AND `:""}${t} IS NOT NULL THEN 1 ELSE 0 END) = 0`;if("scenario"===t.kind)return`${s(t.column)} as __sort${i}, CASE WHEN ${r(t.column)} THEN 1 ELSE 0 END as __sortnull${i}`;const l=`(${s(t.base)} - ${s(t.delta)})`;let a=l,c=`${r(t.base)} OR ${r(t.delta)}`;if("dr"===t.type){const e=s(t.delta),i=`ABS(${e}) <= ABS(${l}) * 0.000000001`;a=`CASE WHEN ${i} THEN 0 ELSE ${l} / ABS(${e}) END`,c+=` OR ${i}`}return`${a} as __sort${i}, CASE WHEN ${c} THEN 1 ELSE 0 END as __sortnull${i}`}createRelativeScenario(t){const e=new p(t);return e.isValid&&"dr"===e.type?{key:`${t}`,value:`dr_${e.delta}`}:null}exctractScenarioNames(t){const e=[];return t.split(",").forEach((t=>t.length>=2?e.push(t.split("as")[1].trim()):null)),e}findDuplicateSubCategories(t){const e=t.map((t=>({count:1,subCategory:`${t.category}##${t.subCategory}`}))).reduce(((t,e)=>(t[e.subCategory]=(t[e.subCategory]||0)+e.count,t)),{});return Object.keys(e).filter((t=>e[t]>1))}createPartOfQuery(t,e){var i;const n=[];let o="1 <> 1 ",s=` ${this.drillRowGroup} as ${v.ROWGROUP}`,r="ROWNUM()";return null===(i=this.config.partOf)||void 0===i||i.forEach((t=>{o+=`OR (${v.CATEGORY} = ${this.bind(t.category)}`,null!=t.rowGroup&&0!==t.rowGroup.length&&t.rowGroup.trim()&&(o+=`and ${v.ROWGROUP} = ${this.bind(t.rowGroup)}`),!1===this.config.grouped&&(s=` 'SUM_TOTAL' as ${v.ROWGROUP} `,r="1"),o+=")"})),n.push(`SELECT ${r} AS ${v.ROWNR},\n 'PARTELEMENT' as ${v.TYPE},\n ${v.CATEGORY},\n ${s},\n ${t}${this.sortSelect}\n FROM ${this.fromExpr}\n WHERE ${o}\n GROUP BY ${this.drillRowGroup}, ${v.CATEGORY}, ${v.TYPE}\n ORDER BY ${e[1]}`),n}checkConfigForPartOf(){return null!=this.config.partOf&&0!==this.config.partOf.length}createThereOfDrillColumns(t,e){if(null==t||0===t.size)return;const i=[],n=[],o=this.fromExpr;t.forEach(((t,e)=>{let n="1 <> 1 ";t.forEach((t=>{n+=` or columnGroup = ${this.bind(String(t.name))} `})),i.push(`SELECT 'ENTRY' as rowlevel,\n 'COLUMNGROUP' as columnlevel,\n rowGroup,\n category,\n columnGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${o}\n WHERE ${n}\n GROUP BY rowlevel, rowGroup, category, columnGroup, scenario`),i.push(`SELECT 'ENTRY' as rowlevel,\n 'SUBGROUP' as columnlevel,\n rowGroup,\n category,\n columnGroup,\n columnSubGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${o}\n WHERE ${n}\n GROUP BY rowlevel, rowGroup, category, columnGroup, columnSubGroup, scenario`),i.push(`SELECT 'DRILLELEMENT' as rowlevel,\n 'COLUMNGROUP' as columnlevel,\n rowGroup,\n category,\n subCategory,\n columnGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${o}\n WHERE ${n}\n GROUP BY rowlevel, rowGroup, category, subCategory, columnGroup, scenario`),i.push(`SELECT 'DRILLELEMENT' as rowlevel,\n 'SUBGROUP' as columnlevel,\n rowGroup,\n category,\n subCategory,\n columnGroup,\n columnSubGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${o}\n WHERE ${n}\n GROUP BY rowlevel, rowGroup, category, subCategory, columnGroup, columnSubGroup, scenario`),i.push(`SELECT 'GROUP_SUM' as rowlevel,\n 'COLUMNGROUP' as columnlevel,\n rowGroup,\n columnGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${o}\n WHERE ${n}\n GROUP BY rowlevel, rowGroup, columnGroup, scenario`),i.push(`SELECT 'GROUP_SUM' as rowlevel,\n 'SUBGROUP' as columnlevel,\n rowGroup,\n columnGroup,\n columnSubGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${o}\n WHERE ${n}\n GROUP BY rowlevel, rowGroup, columnGroup, columnSubGroup, scenario`),i.push(`SELECT 'SUM' as rowlevel,\n 'COLUMNGROUP' as columnlevel,\n columnGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${o}\n WHERE ${n}\n GROUP BY rowlevel, columnGroup, scenario`),i.push(`SELECT 'SUM' as rowlevel,\n 'SUBGROUP' as columnlevel,\n columnGroup,\n columnSubGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${o}\n WHERE ${n}\n GROUP BY rowlevel, columnGroup, columnSubGroup, scenario`)}));for(const t of i)n.push(...this.db.exec(t,this.params));this.injectDrillColumnsToResultRows(n,e)}injectDrillColumnsToResultRows(t,e){const i="##";for(const n of t)for(const t of e)for(const e of t)if(e.type===n.rowlevel)if("ENTRY"===n.rowlevel)"COLUMNGROUP"===n.columnlevel&&e.category===n.category?e[n.scenario+i+n.columnGroup]=n.val:"SUBGROUP"===n.columnlevel&&e.category===n.category&&(e[n.scenario+i+n.columnGroup+i+n.columnSubGroup]=n.val);else if("DRILLELEMENT"===n.rowlevel){if(!this.config.grouped&&e.rowGroup!==n.rowGroup)continue;"COLUMNGROUP"===n.columnlevel&&e.category===n.category&&e.subCategory===n.subCategory?e[n.scenario+i+n.columnGroup]=n.val:"SUBGROUP"===n.columnlevel&&e.category===n.category&&e.subCategory===n.subCategory?e[n.scenario+i+n.columnGroup+i+n.columnSubGroup]=n.val:"COLUMNGROUP"===n.columnlevel&&e.category===n.category&&e.subCategory===`${n.subCategory} (${n.rowGroup})`?e[n.scenario+i+n.columnGroup]=n.val:"SUBGROUP"===n.columnlevel&&e.category===n.category&&e.subCategory===`${n.subCategory} (${n.rowGroup})`&&(e[n.scenario+i+n.columnGroup+i+n.columnSubGroup]=n.val)}else("SUM"===n.rowlevel||"GROUP_SUM"===n.rowlevel)&&("COLUMNGROUP"===n.columnlevel&&e.category===n.category&&e.subCategory===n.subCategory&&(e[n.scenario+i+n.columnGroup]=n.val),"SUBGROUP"===n.columnlevel&&e.category===n.category&&e.subCategory===n.subCategory&&(e[n.scenario+i+n.columnGroup+i+n.columnSubGroup]=n.val))}}class Wt{constructor(){this.geometry=new Map}set(t,e,i){let n=this.geometry.get(t);n||(n=new Map,this.geometry.set(t,n)),n.set(e,i)}get(t,e){var i;return null===(i=this.geometry.get(t))||void 0===i?void 0:i.get(e)}}function Bt(t,e,i){const n=t[e];if(null==n)return null;const o=Number(n);return isNaN(o)?null:i!==z.OPT&&i!==z.OPTNOTOTAL||t[v.TYPE]!==V.ENTRY||"-"!==t[v.OPERATION]?o:-o}class Ft{constructor(t){this.ruleSet=t,this.normalizedHeader=[],this.attributesByAlias=new Map,this.hasBlankRowGroup=!1,this.dateBuckets=!1,this.unsignedEntries=!1}underlineClass(t){return this.ruleSet&&/^(ac|pp|fc|pl)[1-4]$/.test(t)?$(this.ruleSet.getScenarioColorIndex(t))+t.slice(2):null}getNormalizedHeader(){return this.normalizedHeader}createHeader(t,e,i,n,o,s,r=[],l=0){const a=[];this.attributesByAlias=new Map(r.map((t=>[t.alias,t]))),this.normalizedHeader=this.normalizeHeader(t,e,r,l);const c=this.normalizedHeader.some((t=>void 0!==t.bucket));c&&a.push(this.createIntervalBandRow());const h=new nt(c?1:0,0,V.HEADER),u=new nt(c?2:1,0,V.SEPERATORLINE);for(const t of this.normalizedHeader){const e=this.attributesByAlias.get(t.name);h.createElement(e?i.get(e.label)||e.label:f.translateScenarioLabel(t.name,i),t.type,this.createColumnType(t),null,this.setHeaderPrefix(t,i,n,o,s),null,null,null,null),u.createElement(null,t.type,this.createColumnType(t),null,null,this.underlineClass(t.type),null,null,null)}return a.push(h),a.push(u),a}createIntervalBandRow(){const t=new nt(0,0,V.HEADER);let e=0;for(;e<this.normalizedHeader.length;){const i=this.normalizedHeader[e];if(void 0===i.bucket){t.createElement(null,i.type,"filler",null,null,null,null,null,null),e+=1;continue}let n=1;for(;e+n<this.normalizedHeader.length&&this.normalizedHeader[e+n].bucket===i.bucket;)n+=1;t.createElement(i.bucketLabel,i.type,"intervalGroup",null,null,null,null,null,null,!1,void 0,n),e+=n}return t}setHeaderPrefix(t,e,i,n,o){let s="";return"category"===t.name&&o&&(0===i.prefix.length&&0===n.length||(s=f.translateScenarioLabel("in",e)+" "+i.prefix+n)),t.order&&(s+=f.translateScenarioLabel("ORDER_"+t.order,e)),s}normalizeHeader(t,e,i,n=0){let o=[{name:v.CATEGORY,group:v.CATEGORY,type:v.CATEGORY,order:void 0}];z.OPT!==t&&z.OPTNOTOTAL!==t||(o=[{name:v.OPERATION,group:v.OPERATION,type:v.OPERATION,order:void 0},{name:v.CATEGORY,group:v.CATEGORY,type:v.CATEGORY,order:void 0}]);const s=i.map((t=>({name:t.alias,group:t.alias,type:t.alias,order:void 0})));return[...e.slice(0,n),...o,...s,...e.slice(n)]}createBodyRows(t,e,i,n){var o;const s=[];let r=-1;const l=new Dt(t,e);var a;this.dateBuckets=(a=t.interval)!==X&&a!==q,this.unsignedEntries=z.OPT===t.type||z.OPTNOTOTAL===t.type;const c=l.execute(i,n);this.hasBlankRowGroup=l.hasBlankRowGroup;const h=this.calculateColumnStatistics(c,t.barColumns,t.interval!==X),u=(null!==(o=t.barColumns)&&void 0!==o?o:[]).filter((t=>t.toUpperCase().trim()in w)),d=u.length>0&&t.interval===X&&0===t.categoryThereOf.size&&function(t){for(const e of t)for(const t of e){const e=t[v.TYPE];if(e===V.SUM||e===V.GROUPSUM||e===V.DRILLELEMENT||e===V.PARTELEMENT)return!0}return!1}(c)?function(t,e,i){const n=new Wt;for(const o of e){let e,s=0,r=0;const l=[],a=(t,e)=>{l.push(e),n.set(t,o,e)};for(const n of t)for(const t of n){const n=t[v.TYPE];if(n===V.GROUPHEAD){s=0,e=void 0;continue}const l=Bt(t,o,i);if(n===V.ENTRY){if(null===l){e=void 0;continue}a(t,{start:s,end:s+l,min:0,max:0,kind:"cascade"}),e={start:s,end:s+l},r=e.start,s+=l}else if(n===V.SUM||n===V.GROUPSUM){if(null===l){e=void 0;continue}a(t,{start:0,end:l,min:0,max:0,kind:"anchor"}),e={start:0,end:l},r=0,s=n===V.GROUPSUM?0:l}else if(n===V.DRILLELEMENT){if(null===l||void 0===e)continue;const i=r+(Math.sign(e.end-e.start)||1)*Math.abs(l);a(t,{start:r,end:i,min:0,max:0,kind:"thereof",parentStart:e.start,parentEnd:e.end}),r=i}else if(n===V.PARTELEMENT){if(null===l||void 0===e)continue;const i=r+l*(e.end-e.start);a(t,{start:r,end:i,min:0,max:0,kind:"partof",parentStart:e.start,parentEnd:e.end}),r=i}}let c=0,h=0;for(const t of l)c=Math.min(c,t.start,t.end),h=Math.max(h,t.start,t.end);for(const t of l)t.min=c,t.max=h}return n}(c,u,t.type):void 0;for(const i of c)r+=1,s.push(...this.createRow(t.i18n,e,t.scenariosUnitType,i,r,-1,t.categoryWidth,t.measureScale,t.barColumns,h,d));return s}calculateColumnStatistics(t,e,i=!1){const n=new Map;if(!e||0===e.length)return n;const o=new Map;for(const t of e)n.set(t,{min:1/0,max:-1/0,absMax:0,median:0}),o.set(t,[]);for(const s of t)for(const t of s){const s=t[v.TYPE];if(s!==V.SUM&&s!==V.GROUPSUM)for(const s of e){const e=i?this.extractIntervalColumnValues(t,s):[this.extractColumnValue(t,s)];for(const t of e)if(null!==t&&!isNaN(t)){const e=n.get(s);e.min=Math.min(e.min,t),e.max=Math.max(e.max,t),o.get(s).push(Math.abs(t))}}}for(const[t,e]of n){e.min!==1/0&&e.max!==-1/0||(e.min=0,e.max=0),e.absMax=Math.max(Math.abs(e.min),Math.abs(e.max));const i=o.get(t);if(i.length>0){i.sort(((t,e)=>t-e));const t=Math.floor(i.length/2);e.median=i.length%2==0?(i[t-1]+i[t])/2:i[t]}n.set(t,e)}return n}extractIntervalColumnValues(t,e){const i=e+"##",n=[];for(const e of Object.keys(t))if(e.startsWith(i)){const i=Number(t[e]);n.push(isNaN(i)?null:i)}return n}extractColumnValue(t,e){if(void 0!==t[e]){const i=Number(t[e]);return isNaN(i)?null:i}for(const i of Object.keys(t))if(i===e||i.endsWith("##"+e)||i===e+"##"+e){const e=Number(t[i]);if(!isNaN(e))return e}return null}createRow(t,e,i,n,o,s,r,l,a,h,u){var d,f,$;const m=[];let g;for(const b of n){const w=b[v.ROWGROUP],E=""===w?"-":w,y=b[v.SUBCATEGORY],S=b[v.TYPE],R=b[v.ROWNR]>=2;g=null!==(f=null!==(d=b.operation)&&void 0!==d?d:b.restOperation)&&void 0!==f?f:g;const M=this.createDetailRow(S,s+=1,o,n.length);M.key=this.rowKey(b);for(const n of this.normalizedHeader){const o=this.getRawDataRowElement(b,n),s=null!==($=null==a?void 0:a.includes(n.type))&&void 0!==$&&$,d=s?null==h?void 0:h.get(n.type):void 0,f=s&&void 0===n.bucket&&n.name===n.group&&n.name===n.type?null==u?void 0:u.get(b,n.type):void 0;M.createElement(this.translateSumCellLabel(t,e,o,E,y,S,n.type),n.type,this.createColumnType(n),this.setCellType(n.type,i),this.translateCellPrefix(e,S,n.type),this.translateScenarioCSS(n.type,o,g),R,r,null==l?void 0:l.value,s,d,1,f);const v=M.elements[M.elements.length-1];this.dateBuckets&&void 0!==n.bucket&&(v.date=c(n.bucket));const m=new p(n.type);m.isValid&&(v.direction=this.resolveDirection(m,g))}m.push(M)}return m}rowKey(t){var e;const i=null!=t.restRowGroup?t.restRowGroup:"NO_GROUP"===t.rowGroup?void 0:t.rowGroup;switch(t.type){case V.ENTRY:return{rowGroup:i,category:t.category,subCategory:t.subCategory};case V.DRILLELEMENT:return{rowGroup:i,category:t.category,subCategory:null!==(e=t.rawSubCategory)&&void 0!==e?e:t.subCategory};case V.GROUPSUM:return{rowGroup:i,row:"subtotal"};case V.SUM:return{row:"total"};default:return}}getRawDataRowElement(t,e){return void 0!==e.bucket?t[e.type+"##"+e.bucket]:e.name===e.group&&e.name===e.type?t[e.name]:e.name===e.group&&e.name!==e.type?t[e.type+"##"+e.name]:t[e.type+"##"+e.group+"##"+e.name]}createDetailRow(t,e,i,n){switch(t){case V.GROUPHEAD:return new nt(e,i,V.HEADER);case V.SUM:case V.GROUPSUM:return new nt(n+2,i,V.SUM);case V.DRILLELEMENT:return new nt(n+2,i,V.DRILLELEMENT);case V.PARTELEMENT:return new nt(n+2,i,V.PARTELEMENT);default:return new nt(e,i,V.STANDARD)}}translateSumCellLabel(t,e,i,n,o,s,r){return this.attributesByAlias.has(r)||!1===Number.isNaN(Number(i))||this.isOperationColumn(r)?i:this.isGroupHeadCategory(s,r)?t===E.ALL?`${e.get(i)||i}`:i:this.isEntryCategory(s,r)?t===E.ALL||"REST"===i?`${e.get(i)||i}`:i:this.isDrillElementCategory(s,r)?t===E.ALL?`${e.get(o)||o}`:`${o}`:this.isPartElementCategory(s,r)?t===E.ALL||"SUM_TOTAL"===n?`${e.get(n)||n}`:`${n}`:this.isSumElementCategory(s,r)?t===E.ALL||"SUM_TOTAL"===n?`${e.get(n)||n}`:n:"GROUPHEAD"===s&&null==i||i===O?i:Number.isNaN(Number(i))?"-":Number(i)}isOperationColumn(t){return"operation"===t}translateScenarioCSS(t,e,i){if(this.attributesByAlias.has(t))return"attribute";const n=new p(t);let o="pos";return e<0&&(o="neg"),n.isValid?o+"_"+this.resolveDirection(n,i)+("dr"===n.type?" relative_variance":""):t}resolveDirection(t,e){return m(t.direction,e,!this.unsignedEntries)}setCellType(t,e){if("category"===t)return"";const i=this.attributesByAlias.get(t);if(i)return i.isNumeric?"decimal":"";let n;const o=new p(t);return e===y.PERCENT?(n="percent",o.isValid&&"d"===o.type&&(n="percentpoint")):(n="decimal",o.isValid&&"dr"===o.type&&(n="percent")),n}isDrillElementCategory(t,e){return"DRILLELEMENT"===t&&"category"===e}isPartElementCategory(t,e){return"PARTELEMENT"===t&&"category"===e}isSumElementCategory(t,e){return("GROUP_SUM"===t||"SUM"===t)&&"category"===e}isEntryCategory(t,e){return"ENTRY"===t&&"category"===e}isGroupHeadCategory(t,e){return"GROUPHEAD"===t&&"category"===e}translateCellPrefix(t,e,i){return this.isOperationColumn(i)||this.isGroupHeadCategory(e,i)||this.isEntryCategory(e,i)?null:this.isDrillElementCategory(e,i)?`${t.get("thereof")} `:this.isPartElementCategory(e,i)?`${t.get("part_of")} `:null}createColumnType(t){return t.name===t.group&&t.name===t.type?"base":t.name===t.group?"columnGroup":"columnSubGroup"}}class It{constructor(t,e,i,n){this.fromExpr="",this.rowCount=0,this.headerRows=[],this.bodyRows=[],this.intervalBuckets=[],this.ruleSet=t||new g,this.db=e,this.dataSetFactory=new Ft(this.ruleSet),this.config=this.initConfig(n),this.i18n=this.initI18n(new Map),this.setSource(i,n.filter)}setI18n(t){this.i18n=this.initI18n(t)}initI18n(t){const e=new Map([["",""],["SEPARATOR_WS",", "],["in","in"],["ORDER_asc","↑"],["ORDER_desc","↓"],["ac1","AC"],["pp1","PY"],["fc1","FC"],["pl1","PL"],["ac2","AC2"],["pp2","PY2"],["fc2","FC2"],["pl2","PL2"],["ac3","AC3"],["pp3","PY3"],["fc3","FC3"],["pl3","PL3"],["ac4","AC4"],["pp4","PY4"],["fc4","FC4"],["pl4","PL4"],["category"," "],["operation"," "],["thereof","davon"],["part_of","in % von"],["ibcssymbol_delta_ac","Δ{%}"],["ibcssymbol_delta_generic","Δ({%})"],["ibcssymbol_delta_ac_relative","Δ{%}%"],["ibcssymbol_delta_generic_relative","Δ({%})%"],["SUM_TOTAL","❖"]]);return this.state=j.DIRTY,new Map([...e,...t||new Map])}initConfig(t){this.state=j.DIRTY;const e=t,i=this;return t.scenarios.sort(((t,e)=>i.ruleSet.getScenarioSorIndex(t)-i.ruleSet.getScenarioSorIndex(e))),e}setConfig(t){this.config=this.initConfig(t)}setSource(t,e){var i,n;if(this.state=j.DIRTY,this.fromExpr=k(this.db,t,e),!this.fromExpr)return void(this.rowCount=0);const o=this.db.exec(`SELECT COUNT(*) AS cnt FROM ${this.fromExpr}`);this.rowCount=null!==(n=null===(i=o[0])||void 0===i?void 0:i.cnt)&&void 0!==n?n:0}update(){this.prepareIntervalBuckets();const t=this.normalizeScenarios(this.config.scenarios,this.config.categoryThereOf,this.config.sortOrder,this.intervalBuckets);this.headerRows=this.dataSetFactory.createHeader(this.config.type,t,this.i18n,this.config.measureScale,this.config.measureUnit,this.config.showMeasureScale,this.config.attributes,Math.min(this.categoryIntervalPosition(),this.intervalBuckets.length)*this.config.scenarios.length),this.bodyRows=0!==this.rowCount&&this.fromExpr?this.dataSetFactory.createBodyRows(this.config,this.i18n,this.db,this.fromExpr):[],this.state=j.UP_TO_DATE}getHeader(){return this.state===j.DIRTY&&this.update(),this.headerRows}getBody(){return this.state===j.DIRTY&&this.update(),this.bodyRows}getColumns(){return this.state===j.DIRTY&&this.update(),this.dataSetFactory.getNormalizedHeader()}prepareIntervalBuckets(){this.intervalBuckets=[],this.config.interval===X||!this.fromExpr||this.config.categoryThereOf.size>0?this.config.interval=X:(this.config.interval=function(t,e,i){var n;if(i!==G.AUTO)return i;const o=t.exec(`SELECT [date] as d FROM ${e}`);let s,r;for(const t of o){const e=null===(n=tt(t.d))||void 0===n?void 0:n.toMillis();void 0!==e&&(s=void 0===s?e:Math.min(s,e),r=void 0===r?e:Math.max(r,e))}return void 0===s||void 0===r?G.DAY:(new T).calculateDistanceType(_.fromMillis(s),_.fromMillis(r))}(this.db,this.fromExpr,this.config.interval),this.intervalBuckets=function(t,e,i,n){if(i===q){const n=t.exec(`SELECT ${K(i)} as __interval, COALESCE([setnameIndex],[setNameIndex]) as __index FROM ${e}`),o=new Set,s=new Map,r=[];for(const t of n){const e=J(t.__interval);o.has(e)||(o.add(e),r.push({key:e,label:0===e.length?"-":e}));const i=Z(t.__index),n=s.get(e);void 0!==i&&(void 0===n||i<n)&&s.set(e,i)}if(s.size>0){const t=t=>{var e;return null!==(e=s.get(t.key))&&void 0!==e?e:Number.POSITIVE_INFINITY};r.sort(((e,i)=>t(e)===t(i)?0:t(e)<t(i)?-1:1))}return r}const o=t.exec(`SELECT ${K(i)} as __interval FROM ${e}`),s=new Set,r=[];for(const t of o){const e=tt(t.__interval);if(!e)continue;const i=e.toISO();s.has(i)||(s.add(i),r.push(e))}r.sort(((t,e)=>t.toMillis()-e.toMillis()));const l=new T;return l.setLocale(n),r.map((t=>({key:t.toISO(),label:l.getDateString(t,i)})))}(this.db,this.fromExpr,this.config.interval,this.config.locale),0===this.intervalBuckets.length&&(this.config.interval=X))}normalizeScenarios(t,e,i,n=[]){var o;const s=[],r=null===(o=null==i?void 0:i.hierarchy)||void 0===o?void 0:o.map((t=>x(t))).find((t=>"dim"!==(null==t?void 0:t.kind))),l=this.config.interval===q?null==r?void 0:r.bucket:void 0,a=(t,e)=>{var n;return null==r||(null===(n=x(t))||void 0===n?void 0:n.column)!==r.column||void 0!==l&&l!==e?void 0:i.direction};if(n.length>0){for(const e of n)for(const i of t)s.push({name:i,group:i,type:i,order:a(i,e.key),bucket:e.key,bucketLabel:e.label});return s}for(const i of t){if(null==e?void 0:e.has(i)){const t=e.get(i);for(const e of t){s.push({name:e.name,group:e.name,type:i,order:void 0});for(const t of e.subGroups)s.push({name:t,group:e.name,type:i,order:void 0})}s.push({name:"REST",group:"REST",type:i,order:void 0})}s.push({name:i,group:i,type:i,order:a(i)})}return s}hasNoData(){return 0===this.rowCount}orderBucketWarning(){var t,e;if(this.hasNoData()||this.state!==j.UP_TO_DATE)return;const i=(null!==(e=null===(t=this.config.sortOrder)||void 0===t?void 0:t.hierarchy)&&void 0!==e?e:[]).map((t=>{var e;return null===(e=x(t))||void 0===e?void 0:e.bucket})).filter((t=>void 0!==t));if(0===i.length)return;if(this.config.interval!==q)return`order: '@${i[0]}' needs interval setname, the bucket is ignored.`;const n=i.find((t=>!this.intervalBuckets.some((e=>e.key===t))));return void 0===n?void 0:`order: setname '${n}' not found, the rows are not sorted by it.`}categoryIntervalPosition(){const t=this.config.categoryIntervalPosition;return Number.isInteger(t)&&t>0?t:0}categoryIntervalPositionWarning(){const t=this.categoryIntervalPosition();if(t<=0||this.hasNoData()||this.state!==j.UP_TO_DATE)return;const e=this.intervalBuckets.length;return 0===e?{id:"WARN_categoryIntervalPositionNoInterval",message:"categoryIntervalPosition: needs an active interval, the value is ignored."}:t>e?{id:"WARN_categoryIntervalPositionRange",message:`categoryIntervalPosition: '${t}' is greater than the number of interval groups, ${e} is used.`}:void 0}hasBlankRowGroup(){return this.dataSetFactory.hasBlankRowGroup}}class Ht{constructor(){this.title="",this.scenarios=[],this.scenariosUnitType=y.DECIMAL,this.grouped=!1,this.showGroupTitle=!0,this.thereOf=[],this.categoryThereOf=new Map,this.partOf=[],this.attributes=[],this.sortOrder=new C(new F).default(),this.type=z.LIST,this.limit=0,this.i18n=E.ALL,this.categoryWidth=R.W25,this.measureScale=new I,this.measureUnit="",this.measureType=M.VOLUME,this.showMeasureScale=!0,this.filter="",this.barColumns=[],this.interval="none",this.categoryIntervalPosition=0,this.locale="de"}}class Yt{constructor(t,e,i,n,o,s){this.tableDrillGroupAdapter=t,this.stringAdapter=e,this.orderAdapter=i,this.db=n,this.fromExpr=o,this.onQueryError=s}adapt(t){const e=new Ht;return S.isString(t.title)&&(e.title=t.title),S.isArray(t.scenarios)&&(e.scenarios=B.adaptArray(t.scenarios,this.stringAdapter)),S.isExisting(t.scenariosUnitType)&&(e.scenariosUnitType=t.scenariosUnitType),S.isBoolean(t.grouped)&&(e.grouped=t.grouped),S.isBoolean(t.showGroupTitle)&&(e.showGroupTitle=t.showGroupTitle),S.isBoolean(t.showMeasureScale)&&(e.showMeasureScale=t.showMeasureScale),S.isArray(t.thereOf)&&(e.thereOf=B.adaptArray(t.thereOf,this.tableDrillGroupAdapter)),S.isExisting(t.categoryThereOf)&&(e.categoryThereOf=t.categoryThereOf),S.isArray(t.partOf)&&(e.partOf=B.adaptArray(t.partOf,this.tableDrillGroupAdapter)),S.isArray(t.attributes)&&(e.attributes=t.attributes),S.isExisting(t.order)&&(e.sortOrder=this.orderAdapter.adapt(t.order)),S.isExisting(t.type)&&(e.type=t.type),S.isNumber(t.limit)&&(e.limit=t.limit),S.isExisting(t.i18n)&&(e.i18n=t.i18n),S.isExisting(t.categoryWidth)&&(e.categoryWidth=t.categoryWidth),S.isExisting(t.measureScale)&&(e.measureScale=A.calculateMeasureScale(this.db,this.fromExpr,e.scenarios,t.measureScale,this.onQueryError)),S.isExisting(t.measureType)&&(e.measureType=t.measureType),S.isString(t.measureUnit)&&(e.measureUnit=t.measureUnit),S.isString(t.filter)&&(e.filter=t.filter.trim()),S.isArray(t.barColumns)&&(e.barColumns=t.barColumns),S.isString(t.interval)&&(e.interval=t.interval),S.isNumber(t.categoryIntervalPosition)&&(e.categoryIntervalPosition=t.categoryIntervalPosition),S.isString(t.locale)&&(e.locale=t.locale),e}default(){return new Ht}}class jt{constructor(){this.rowGroup="",this.category="",this.subCategory="",this.partOf=""}}class zt{constructor(){}adapt(t){const e=new jt;return S.isString(t.rowGroup)&&(e.rowGroup=t.rowGroup),S.isString(t.category)&&(e.category=t.category),S.isString(t.subCategory)&&(e.subCategory=t.subCategory),S.isString(t.partOf)&&(e.partOf=t.partOf),e}default(){return new jt}}const Qt=e(class extends i{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.tableName="",this.dataVersion=0,this.sumTitle="SUM_TOTAL",this.scenarios=[],this.scenariosDataFormat=y.DECIMAL,this.grouped=!1,this.limit=0,this.showGroupTitle=!0,this.thereof=[],this.partof=[],this.order={hierarchy:[],direction:Q.ASC},this.categorythereof=new Map,this.attributeColumns=[],this.type=z.LIST,this.categoryWidth=R.INF,this.dataFormatDigits={percent:2,decimal:1},this.i18n=new Map,this.i18nMode=E.ALL,this.measureScale="_",this.measureUnit="",this.showMeasureScale=!0,this.measureType=M.VOLUME,this.filter="",this.barColumns=[],this.interval="none",this.categoryIntervalPosition=0,this.barColumnMaxWidth=30,this.unitScaling=.01,this.percentageScaling=.5,this.scaleFactor=1,this.componentDataFormatDigits=new D,this.barColumnLayouts=new Map,this.relayout=()=>{this.barColumnLayouts.size>0&&n(this)},U(this),this.componentStyle=H(this)}connectedCallback(){var t;null===(t=document.fonts)||void 0===t||t.addEventListener("loadingdone",this.relayout)}disconnectedCallback(){var t;null===(t=document.fonts)||void 0===t||t.removeEventListener("loadingdone",this.relayout)}async getLayoutDetail(t,e){var i,n,o;const s={regions:[],metadata:{},diagnostics:[]},c=null===(i=this.element.shadowRoot)||void 0===i?void 0:i.querySelector("table");if(s.metadata.hasNoData=null===(o=null===(n=this.table)||void 0===n?void 0:n.hasNoData())||void 0===o||o,!this.table||!c)return s;const h=c.querySelector("thead"),d=c.querySelector("tbody");h&&s.regions.push({id:"header",rect:r(h,t)}),d&&s.regions.push({id:"body",rect:r(d,t)});const f=this.table.getHeader(),p=this.table.getBody(),v=this.table.getColumns();if(s.metadata.headerRowCount=f.length,s.metadata.rowCount=p.length,s.metadata.columnCount=v.length,s.metadata.cellCount=p.reduce(((t,e)=>t+e.getCells().length),0),"full"!==e)return s;const $=[],m=[],g=(e,i,n)=>{const o=n?Array.from(n.children).filter((t=>"tr"===t.localName)):[];i.forEach(((i,n)=>{const c=o[n];if(!c)return;$.push({section:e,index:n,type:i.type,rect:r(c,t),point:u(c)});const h=i.getCells(),d=Array.from(c.children);h.length===d.length?h.forEach(((i,o)=>{var s,c;const h=d[o],f={kind:"header"===e?"headerCell":"cell",row:n,column:i.index,key:i.key||void 0,colSpan:i.colSpan,value:null!==(s=i.value)&&void 0!==s?s:void 0,text:(null===(c=h.textContent)||void 0===c?void 0:c.trim())||void 0,type:i.type||void 0,rect:r(h,t),point:u(h)};f.point&&(f.content=l(h,t),f.contentSign=a(h)||void 0);const p=h.querySelector("svg.cell-bar-chart");p&&(f.bar={variant:p.classList.contains("waterfall-bar")?"waterfall":p.classList.contains("relative-variance")?"relative":"absolute",rect:r(p,t)}),m.push(f)})):s.diagnostics.push({id:`WARN_layout_cell_pairing_${e}_${n}`,type:"warning",message:`layout-state: model/DOM cell count mismatch in ${e} row ${n} (${h.length} vs ${d.length}); cell details skipped for this row.`})}))};return g("header",f,h),g("body",p,d),s.elements=m,s.table={rows:$,columns:v.map(((t,e)=>({index:e,key:t.name,group:t.group,type:t.type,bucket:t.bucket})))},s}render(){var e;return t(o,{class:{"no-data":!0===(null===(e=this.table)||void 0===e?void 0:e.hasNoData())}},(()=>{var e,i,n,o;if(void 0===this.table)return;if(this.table.hasNoData()){const i=null!==(e=this.i18n.get("no-data"))&&void 0!==e?e:"No Data";return t("div",{class:"empty-state"},i)}const s=null===(o=null===(n=null===(i=this.stores)||void 0===i?void 0:i.context)||void 0===n?void 0:n.state)||void 0===o?void 0:o.locale;return t("table",null,t("thead",null,this.table.getHeader().map((e=>t("tr",{class:e.cssStyle},e.getCells().map((e=>t("th",{colSpan:e.colSpan,class:e.cssStyle},e.getAsHeaderList().map(((i,n,o)=>t("span",null,n===o.length-1?t("span",{class:" "===i?"table-footer":""},i,e.drawPrefix()," "):t("span",null,i,e.drawPrefix(),t("br",null)))))))))))),t("tbody",null,this.table.getBody().map((e=>t("tr",Object.assign({class:e.cssStyle},d(e.key,"element")),null==e?void 0:e.getCells().map((i=>{var n,o,r,l,a;return t("td",Object.assign({colSpan:i.colSpan,class:i.type?`${i.cssStyle} ${i.type}`:i.cssStyle},e.key&&null!=i.value&&""!==i.value&&"-"!==i.value?d(Object.assign(Object.assign({},e.key),{date:i.date,scenario:i.key}),"element"):{}),null!=i.prefix?t("span",{class:i.cssStyle+" "+i.prefixStyle},i.drawPrefix()):"",!i.isBarChart||!i.columnStats||i.value===O||!this.showGroupTitle&&e.type===V.HEADER||void 0===i.waterfall&&e.type===V.SUM?i.draw(this.componentDataFormatDigits,s):void 0!==i.waterfall?t(kt,{value:i.value,scenario:i.key,columnStats:i.columnStats,height:18*this.scaleFactor,isRelative:!1,isPositiveGood:"pos"===i.direction,measureScale:i.measureScale,locale:s,decimalDigits:Xt(i,this.componentDataFormatDigits),columnWidthEm:this.barColumnMaxWidth,styles:this.barChartStyles,waterfall:i.waterfall}):t(Ct,{value:i.value,scenario:i.key,columnStats:i.columnStats,height:18*this.scaleFactor,isRelative:i.key.startsWith("dr"),isPositiveGood:"pos"===i.direction,measureScale:Vt(i),locale:s,decimalDigits:Xt(i,this.componentDataFormatDigits),percentDigits:null!==(o=null===(n=this.barColumnLayouts.get(i.key))||void 0===n?void 0:n.percentDigits)&&void 0!==o?o:this.componentDataFormatDigits.percent,percentSign:null===(r=this.barColumnLayouts.get(i.key))||void 0===r?void 0:r.percentSign,columnWidthEm:this.barColumnMaxWidth,labelWidths:null===(l=this.barColumnLayouts.get(i.key))||void 0===l?void 0:l.labels,sideMax:null===(a=this.barColumnLayouts.get(i.key))||void 0===a?void 0:a.sideMax,styles:this.barChartStyles}))})))))))})())}componentWillRender(){var t,e,i,n,o,s,r,l,a,c,h;this.stores||(this.stores=P(this.element));const u=this.stores.db.db;this.componentDataFormatDigits=(new W).adapt(this.dataFormatDigits);try{const e=this.prepareConfig(u);this.table=new It(new g(this.ruleSetConfig),u,this.tableName,e),this.table.setI18n(this.i18n),this.table.hasNoData()||this.table.getBody(),null===(t=this.errors)||void 0===t||t.remove("ERR_sql")}catch(t){console.error("bn-table-renderer: query failed",t),this.table=void 0,null===(e=this.errors)||void 0===e||e.addOrReplace({id:"ERR_sql",type:"error",message:`Query failed: ${t instanceof Error?t.message:t}`})}(null===(i=this.table)||void 0===i?void 0:i.hasBlankRowGroup())?null===(n=this.errors)||void 0===n||n.addOrReplace({id:"WARN_blankRowGroup",type:"warning",message:"grouped: rows with blank rowGroup found, they are grouped under '-'."}):null===(o=this.errors)||void 0===o||o.remove("WARN_blankRowGroup");const d=null===(s=this.table)||void 0===s?void 0:s.orderBucketWarning();d?null===(r=this.errors)||void 0===r||r.addOrReplace({id:"WARN_orderBucket",type:"warning",message:d}):null===(l=this.errors)||void 0===l||l.remove("WARN_orderBucket");const f=null===(a=this.table)||void 0===a?void 0:a.categoryIntervalPositionWarning();for(const t of["WARN_categoryIntervalPositionNoInterval","WARN_categoryIntervalPositionRange"])(null==f?void 0:f.id)===t?null===(c=this.errors)||void 0===c||c.addOrReplace({id:t,type:"warning",message:f.message}):null===(h=this.errors)||void 0===h||h.remove(t);this.barColumnLayouts=this.collectBarColumnLayouts(),this.barChartStyles=this.prepareBarChartStyles()}prepareConfig(t){var e,i,n;const o=k(t,this.tableName,this.filter);return new Yt(new zt,new F,new C(new F,!0),t,o,(t=>{throw t})).adapt({title:this.sumTitle,scenarios:this.scenarios,scenariosUnitType:this.scenariosDataFormat,grouped:this.grouped,showGroupTitle:this.showGroupTitle,thereOf:this.thereof,partOf:this.partof,categoryThereOf:this.categorythereof,attributes:this.attributeColumns,order:this.order,type:this.type,limit:this.limit,i18n:this.i18nMode,categoryWidth:this.categoryWidth,measureScale:this.measureScale,measureUnit:this.measureUnit,measureType:this.measureType,showMeasureScale:this.showMeasureScale,filter:this.filter,barColumns:this.barColumns,interval:this.interval,categoryIntervalPosition:this.categoryIntervalPosition,locale:(null===(n=null===(i=null===(e=this.stores)||void 0===e?void 0:e.context)||void 0===i?void 0:i.state)||void 0===n?void 0:n.locale)||"de"})}prepareBarChartStyles(){var t;const e=!(this.unitScaling>0),i=!(this.percentageScaling>0),n=e?this.autoUnitScaling():this.unitScaling,o=i?this.autoPercentageScaling():this.percentageScaling;return(e||i)&&(null===(t=this.reportAutoScaling)||void 0===t||t.call(this,{unit:e?n:void 0,percentage:i?o:void 0})),this.componentStyle((t=>{var e,i,s,r,l,a,c,u,d,f,p,v,$,m,w,E,y,S,R,M,O,N,_,U,G,T;const L=null===(e=t["bn-chart-time"])||void 0===e?void 0:e.varianceStyles,x=null===(i=t["bn-chart-time"])||void 0===i?void 0:i.barStyles;return{positive:{stroke:(null===(s=null==L?void 0:L.pos)||void 0===s?void 0:s.stroke)||"#008f96",fill:(null===(r=null==L?void 0:L.pos)||void 0===r?void 0:r.fill)||"#008f96",fillpattern:h(null===(l=null==L?void 0:L.pos)||void 0===l?void 0:l.fillpattern)||"solid"},negative:{stroke:(null===(a=null==L?void 0:L.neg)||void 0===a?void 0:a.stroke)||"#ff0000",fill:(null===(c=null==L?void 0:L.neg)||void 0===c?void 0:c.fill)||"#ff0000",fillpattern:h(null===(u=null==L?void 0:L.neg)||void 0===u?void 0:u.fillpattern)||"solid"},neutral:{stroke:(null===(d=null==L?void 0:L.neu)||void 0===d?void 0:d.stroke)||"#808080",fill:(null===(f=null==L?void 0:L.neu)||void 0===f?void 0:f.fill)||"#808080",fillpattern:h(null===(p=null==L?void 0:L.neu)||void 0===p?void 0:p.fillpattern)||"outlined"},scenarios:b({ac:{stroke:(null===(v=null==x?void 0:x.ac)||void 0===v?void 0:v.stroke)||"#404040",fill:(null===($=null==x?void 0:x.ac)||void 0===$?void 0:$.fill)||"#404040",fillpattern:h(null===(m=null==x?void 0:x.ac)||void 0===m?void 0:m.fillpattern)||"solid"},pp:{stroke:(null===(w=null==x?void 0:x.pp)||void 0===w?void 0:w.stroke)||"#A6A6A6",fill:(null===(E=null==x?void 0:x.pp)||void 0===E?void 0:E.fill)||"#A6A6A6",fillpattern:h(null===(y=null==x?void 0:x.pp)||void 0===y?void 0:y.fillpattern)||"solid"},fc:{stroke:(null===(S=null==x?void 0:x.fc)||void 0===S?void 0:S.stroke)||"#404040",fill:(null===(R=null==x?void 0:x.fc)||void 0===R?void 0:R.fill)||"#ffffff",fillpattern:h(null===(M=null==x?void 0:x.fc)||void 0===M?void 0:M.fillpattern)||"hatched"},pl:{stroke:(null===(O=null==x?void 0:x.pl)||void 0===O?void 0:O.stroke)||"#404040",fill:(null===(N=null==x?void 0:x.pl)||void 0===N?void 0:N.fill)||"#ffffff",fillpattern:h(null===(_=null==x?void 0:x.pl)||void 0===_?void 0:_.fillpattern)||"outlined"}},new g(this.ruleSetConfig)),fontColor:(null===(U=t.global)||void 0===U?void 0:U.fontColor)||"#000000",fontSize:((null===(G=t.global)||void 0===G?void 0:G.fontSizePx)||13.3333)*ot*this.scaleFactor,emPx:((null===(T=t.global)||void 0===T?void 0:T.fontSizePx)||13.3333)*this.scaleFactor,fontFamily:this.labelFontFamily(),unitScaling:n,percentageScaling:o,scaleFactor:this.scaleFactor}}))}labelFontFamily(){return this.componentStyle((t=>{var e;return(null===(e=t.global)||void 0===e?void 0:e.fontFamily)||"'Noto Sans', sans-serif"}))}emPx(){return this.componentStyle((t=>{var e;return(null===(e=t.global)||void 0===e?void 0:e.fontSizePx)||13.3333}))*this.scaleFactor}autoUnitScaling(){var t;const e=this.emPx(),i=e*ot;let n=1/0;for(const{isRelative:o,absMax:s,labels:r,sideMax:l}of this.barColumnLayouts.values()){if(o||s<=0)continue;const a=$t(this.barColumnMaxWidth,e,r,l);for(const e of["neg","pos"]){const o=null!==(t=l[e])&&void 0!==t?t:0;if(o<=0)continue;const{maxBarWidth:s,cutWidth:r}=a[e];n=Math.min(n,Math.min(.8*s,r)/(o*i))}}return Number.isFinite(n)&&i>0?n:.01}autoPercentageScaling(){var t,e;const i=this.emPx(),n=i*ot;let o=1/0;for(const{isRelative:s,absMax:r,labels:l,sideMax:a}of this.barColumnLayouts.values()){if(!s||r<=0)continue;const c=10*this.scaleFactor,{negPinLength:h,posPinLength:u}=mt(this.barColumnMaxWidth,i,l,c),d=100*((null!==(t=a.neg)&&void 0!==t?t:0)+(null!==(e=a.pos)&&void 0!==e?e:0));o=Math.min(o,(h+u)/(d*n))}return Number.isFinite(o)&&n>0?o:.5}collectBarColumnLayouts(){var t,e,i,n;const o=new Map;if(!this.table||this.table.hasNoData())return o;const s=new Map;for(const e of this.table.getBody())if(e.type!==V.SUM)for(const i of e.getCells())i.isBarChart&&i.columnStats&&void 0===i.waterfall&&("number"!=typeof i.value||isNaN(i.value)||s.set(i.key,[...null!==(t=s.get(i.key))&&void 0!==t?t:[],i]));const r=this.emPx(),l=r*ot,a=10*this.scaleFactor,c=null===(n=null===(i=null===(e=this.stores)||void 0===e?void 0:e.context)||void 0===i?void 0:i.state)||void 0===n?void 0:n.locale,h=this.labelFontFamily();for(const[t,e]of s){const i=t.startsWith("dr"),n=e.map((t=>t.value)),s=(t,o)=>{var s;const r={neg:n.some((t=>t<0))?0:void 0,pos:n.some((t=>t>0))?0:void 0},a=Nt(r);for(const n of e){const e=n.value,u=e>0||0===e&&a?"pos":"neg",d=yt(e,i,Vt(n),c,t,o,Xt(n,this.componentDataFormatDigits));r[u]=Math.max(null!==(s=r[u])&&void 0!==s?s:0,ht(d,l,h,i))}return r};let u=Math.min(20,Math.max(0,Math.trunc(this.componentDataFormatDigits.percent)||0)),d=!0,f=s(u,d);for(;i&&(u>0||d)&&!pt(this.barColumnMaxWidth,r,f,a);)u>0?u--:d=!1,f=s(u,d);const p=Math.max(...n.map(Math.abs))*(i?100:1),v={neg:void 0===f.neg?void 0:Math.max(0,...n.map((t=>-t))),pos:void 0===f.pos?void 0:Math.max(0,...n)};o.set(t,{isRelative:i,absMax:p,labels:f,sideMax:v,percentDigits:u,percentSign:d})}return o}get element(){return this}static get style(){return':host(.no-data){display:block;box-sizing:border-box;width:100%;height:100%}:host(.no-data)>div{float:none;width:100%;height:100%}:host(.no-data) .no-data~.no-data{display:none}.empty-state{box-sizing:border-box;display:flex;align-items:center;justify-content:center;float:none;width:100%;height:100%;min-height:3em;margin:0;padding:0.5em;overflow:hidden;border:0.1em dashed #ddd;color:#808080;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px);font-style:normal;text-align:center}:host{position:relative;display:inline-block}table{background-color:var(--bn-font-background, white);font-size:var(--bn-font-size, 1em);color:var(--bn-font-color, black);font-family:var(--bn-font-family, "Noto Sans", "Helvetica Neue", Helvetica, sans-serif);border-spacing:0.3em 0}thead{border-style:none}tr:first-child td{border-top:none;padding-top:0.5em}td.ac1,td.ac2,td.ac3,td.ac4,td.pp1,td.pp2,td.pp3,td.pp4,td.pl1,td.pl2,td.pl3,td.pl4,td.fc1,td.fc2,td.fc3,td.fc4,td.share,td.variance,td.pos_pos,td.pos_neg,td.neg_pos,td.neg_neg,td.pos_neutral,td.neg_neutral{text-align:right}.category-w100{min-width:100em;max-width:100em}.category-w50{min-width:50em;max-width:50em}.category-w25{min-width:25em;max-width:25em}.category-w20{min-width:20em;max-width:20em}.category-w15{min-width:15em;max-width:15em}.category-w10{min-width:10em;max-width:10em}.category-w5{min-width:5em;max-width:5em}.prefix-second{color:transparent;font-style:normal}.prefix-first{font-style:normal}th{border-bottom:0.1em solid black;text-align:right;font-weight:normal;vertical-align:text-top}td.columnGroup,th.columnGroup{font-size:0.6em}td.columnSubGroup,th.columnSubGroup{font-size:0.6em;border-spacing:0em 0;font-style:italic}td.base,th.base{font-style:normal}th.ofit,td.ofit,tr.ofit,th.partof,td.partof,tr.partof{font-size:0.6em;font-style:italic}td.ofit,td.partof{font-size:0.6em;font-style:italic}th.ofit td,tr.ofit td,th.partof td,tr.partof td{border-top:0em solid black;padding-left:1em}th.ofit share,th.partof share,tr.share td{border-top:0em solid black}th.share,tr.share,td.share{font-size:0.6em;font-style:italic}th.filler{border-bottom:0em solid black;text-align:right}td.filler{border-top:0em none !important;border-bottom:0em none;text-align:right}th.group{text-align:center;border-spacing:1em 0}th.headerlabel{border-bottom:0em none black;padding-bottom:0em}th.intervalGroup{border-bottom:0.1em solid black;text-align:center;font-weight:bold}td.variance:after{content:"%"}td.relative_variance{font-style:italic}td.percent{font-style:italic;text-align:right}td.decimal,td.percentpoint{text-align:right}td.pos_pos{color:#008f96}td.neg_pos{color:#ff0000}td.pos_neg{color:#ff0000}td.neg_neg{color:#008f96}td.pos_pos:before{content:"+"}td.pos_neg:before{content:"+"}td.pos_neu:before{content:"+"}th.ac1,th.ac2,th.ac3,th.ac4{padding-top:0em;border-bottom:0.3em solid black}th.pp1,th.pp2,th.pp3,th.pp4{padding-top:0em;border-bottom:0.3em solid grey}th.pl1,th.pl2,th.pl3,th.pl4{padding-top:0em;border-bottom:0.3em double black}th.fc1,th.fc2,th.fc3,th.fc4{border-bottom:0.3em solid;border-image:repeating-linear-gradient(-45deg, white, white, black, white, white 0.3em) 2}td.colsum{font-weight:bold}th.colsum{padding-top:0em;font-weight:bold}tr.sum td{border-top:0.1em solid black;font-weight:bold;padding-bottom:0.5em}tr.groupheader td{border-top:0em dotted #ddd;padding-top:0.5em;font-weight:bold;font-style:italic}tr.begingroup td{border-top:0em dotted #ddd;padding-top:0.5em}th.begin-group{padding-left:0.75em}th.end-group{padding-left:0.75em}td{box-sizing:border-box;-webkit-box-sizing:border-box;border-top:0.1em dashed #ddd;padding-left:0.5em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.table-footer{font-size:0.6em}.cell-bar-chart{display:inline-block;vertical-align:middle}.bar-chart-empty{color:#999}td:has(.cell-bar-chart){padding:0 0.25em;vertical-align:middle}td:has(.cell-bar-chart).pos_pos:before,td:has(.cell-bar-chart).pos_neg:before,td:has(.cell-bar-chart).pos_neu:before{content:none}td:has(.cell-bar-chart).variance:after{content:none}'}},[1,"bn-table-renderer",{tableName:[1,"table-name"],dataVersion:[2,"data-version"],selectedStyle:[513,"selected-style"],sumTitle:[1,"sum-title"],scenarios:[16],scenariosDataFormat:[1,"scenarios-data-format"],grouped:[4],limit:[2],showGroupTitle:[4,"show-group-title"],thereof:[16],partof:[16],order:[16],categorythereof:[16],attributeColumns:[16],type:[1],categoryWidth:[1,"category-width"],dataFormatDigits:[16],ruleSetConfig:[16],i18n:[1040],i18nMode:[1,"i18n-mode"],measureScale:[1,"measure-scale"],measureUnit:[1,"measure-unit"],showMeasureScale:[4,"show-measure-scale"],measureType:[1,"measure-type"],filter:[1],barColumns:[16],interval:[1],categoryIntervalPosition:[2,"category-interval-position"],barColumnMaxWidth:[2,"bar-column-max-width"],unitScaling:[2,"unit-scaling"],percentageScaling:[2,"percentage-scaling"],reportAutoScaling:[16],errors:[16],scaleFactor:[2,"scale-factor"],getLayoutDetail:[64]}]);function Vt(t){return"percentpoint"===t.type?.01:t.measureScale}function Xt(t,e){return"percentpoint"===t.type?e.percent:"decimal"===t.type?e.decimal:void 0}function qt(){"undefined"!=typeof customElements&&["bn-table-renderer"].forEach((t=>{"bn-table-renderer"===t&&(customElements.get(s(t))||customElements.define(s(t),Qt))}))}export{Qt as B,X as I,z as T,q as a,Z as c,qt as d}