@bino-bi/bn-template-engine 1.0.0-next.64 → 1.0.0-next.66

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.
@@ -24959,7 +24959,7 @@ class TimeChart {
24959
24959
  }
24960
24960
  /** The rows of the totals dataset, one per group, with the scenario columns added up. */
24961
24961
  totalDatasetRows() {
24962
- var _a, _b, _c, _d;
24962
+ var _a, _b, _c, _d, _e;
24963
24963
  const name = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.dataset;
24964
24964
  if (!name) {
24965
24965
  return null;
@@ -24977,18 +24977,22 @@ class TimeChart {
24977
24977
  this.failQuery(e);
24978
24978
  return rows;
24979
24979
  }
24980
+ const periods = new Set(this.dataModel.map((row) => { var _a, _b, _c; return (_c = (_b = (_a = row.date) === null || _a === void 0 ? void 0 : _a.toISODate) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : ""; }));
24980
24981
  for (const row of result) {
24981
24982
  const date = TimeChart.parseDate(row.date);
24982
- const start = date ? this.totalGroupStart(date) : null;
24983
- const key = start ? ((_b = start.toISODate()) !== null && _b !== void 0 ? _b : "") : "";
24983
+ // a row with the date of a period of the chart belongs to the total of that period: a week can
24984
+ // count into another year than its first day
24985
+ const isPeriod = date != null && periods.has((_b = date.toISODate()) !== null && _b !== void 0 ? _b : "");
24986
+ const start = date ? this.totalGroupStart(date, isPeriod) : null;
24987
+ const key = start ? ((_c = start.toISODate()) !== null && _c !== void 0 ? _c : "") : "";
24984
24988
  if (this.totals.by !== "all" && key === "")
24985
24989
  continue;
24986
- const sums = (_c = rows.get(key)) !== null && _c !== void 0 ? _c : {};
24990
+ const sums = (_d = rows.get(key)) !== null && _d !== void 0 ? _d : {};
24987
24991
  for (const [column, raw] of Object.entries(row)) {
24988
24992
  // a value can come as a text, like in the dataset of the chart
24989
24993
  const value = typeof raw === "string" && raw.trim() !== "" ? Number(raw) : raw;
24990
24994
  if (column !== "date" && typeof value === "number" && Number.isFinite(value)) {
24991
- sums[column] = ((_d = sums[column]) !== null && _d !== void 0 ? _d : 0) + value;
24995
+ sums[column] = ((_e = sums[column]) !== null && _e !== void 0 ? _e : 0) + value;
24992
24996
  }
24993
24997
  }
24994
24998
  rows.set(key, sums);
@@ -25172,26 +25176,35 @@ class TimeChart {
25172
25176
  let delta;
25173
25177
  const notations = new Set();
25174
25178
  if (fromData != null) {
25175
- base = 0;
25176
25179
  const data = (_b = fromData.get(column.start ? ((_a = column.start.toISODate()) !== null && _a !== void 0 ? _a : "") : "")) !== null && _b !== void 0 ? _b : {};
25177
- // the bases of the row are the scenarios of the series, each counts once
25178
- const bases = new Set(candidates.map((entry) => entry.variance.base));
25179
- // a row for a part of the series only has no total: the reference of the dataset is the one of the whole total
25180
- const covered = column.scenarios.filter((scenario) => bases.has(scenario)).length;
25181
- if (covered > 0 && covered < column.scenarios.length) {
25180
+ // the scenarios of the series can stand on either side of a variance: that side is
25181
+ // added up, each scenario once, the other side is the one reference of the row
25182
+ const series = new Set(column.scenarios);
25183
+ const bases = [...new Set(candidates.map((entry) => entry.variance.base))];
25184
+ const deltas = [...new Set(candidates.map((entry) => entry.variance.delta))];
25185
+ // a total needs the whole series on one side and none of it on the other: a row for a part
25186
+ // of the series, or one that sets parts of the series against each other, has no total
25187
+ const inBases = bases.filter((name) => series.has(name)).length;
25188
+ const inDeltas = deltas.filter((name) => series.has(name)).length;
25189
+ if ((inBases > 0 && inDeltas > 0) || (inBases + inDeltas > 0 && inBases + inDeltas < series.size)) {
25182
25190
  return null;
25183
25191
  }
25184
- for (const name of bases) {
25185
- // a 0 is a scenario without a value in this total, as for the parts
25186
- if (Number.isFinite(data[name]) && data[name] !== 0) {
25187
- base += data[name];
25188
- notations.add(name.slice(0, 2));
25189
- }
25190
- }
25191
- if (notations.size === 0 || !Number.isFinite(data[first.delta])) {
25192
+ // a 0 is a scenario without a value in this total, as for the parts
25193
+ const has = (name) => Number.isFinite(data[name]) && data[name] !== 0;
25194
+ const side = (names) => {
25195
+ // of the side with the series only the series counts, of the other side the first name
25196
+ const ofSeries = names.filter((name) => series.has(name));
25197
+ const used = (ofSeries.length > 0 ? ofSeries : names.slice(0, 1)).filter(has);
25198
+ return used.length > 0 ? used.reduce((sum, name) => sum + data[name], 0) : null;
25199
+ };
25200
+ const baseSide = side(bases);
25201
+ const deltaSide = side(deltas);
25202
+ if (baseSide == null || deltaSide == null) {
25192
25203
  return null;
25193
25204
  }
25194
- delta = data[first.delta];
25205
+ base = baseSide;
25206
+ delta = deltaSide;
25207
+ bases.filter(has).forEach((name) => notations.add(name.slice(0, 2)));
25195
25208
  }
25196
25209
  else {
25197
25210
  // the same periods as the column, so the two tell the same: with `last` the one
@@ -993,7 +993,7 @@ export class TimeChart {
993
993
  }
994
994
  /** The rows of the totals dataset, one per group, with the scenario columns added up. */
995
995
  totalDatasetRows() {
996
- var _a, _b, _c, _d;
996
+ var _a, _b, _c, _d, _e;
997
997
  const name = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.dataset;
998
998
  if (!name) {
999
999
  return null;
@@ -1011,18 +1011,22 @@ export class TimeChart {
1011
1011
  this.failQuery(e);
1012
1012
  return rows;
1013
1013
  }
1014
+ const periods = new Set(this.dataModel.map((row) => { var _a, _b, _c; return (_c = (_b = (_a = row.date) === null || _a === void 0 ? void 0 : _a.toISODate) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : ""; }));
1014
1015
  for (const row of result) {
1015
1016
  const date = TimeChart.parseDate(row.date);
1016
- const start = date ? this.totalGroupStart(date) : null;
1017
- const key = start ? ((_b = start.toISODate()) !== null && _b !== void 0 ? _b : "") : "";
1017
+ // a row with the date of a period of the chart belongs to the total of that period: a week can
1018
+ // count into another year than its first day
1019
+ const isPeriod = date != null && periods.has((_b = date.toISODate()) !== null && _b !== void 0 ? _b : "");
1020
+ const start = date ? this.totalGroupStart(date, isPeriod) : null;
1021
+ const key = start ? ((_c = start.toISODate()) !== null && _c !== void 0 ? _c : "") : "";
1018
1022
  if (this.totals.by !== "all" && key === "")
1019
1023
  continue;
1020
- const sums = (_c = rows.get(key)) !== null && _c !== void 0 ? _c : {};
1024
+ const sums = (_d = rows.get(key)) !== null && _d !== void 0 ? _d : {};
1021
1025
  for (const [column, raw] of Object.entries(row)) {
1022
1026
  // a value can come as a text, like in the dataset of the chart
1023
1027
  const value = typeof raw === "string" && raw.trim() !== "" ? Number(raw) : raw;
1024
1028
  if (column !== "date" && typeof value === "number" && Number.isFinite(value)) {
1025
- sums[column] = ((_d = sums[column]) !== null && _d !== void 0 ? _d : 0) + value;
1029
+ sums[column] = ((_e = sums[column]) !== null && _e !== void 0 ? _e : 0) + value;
1026
1030
  }
1027
1031
  }
1028
1032
  rows.set(key, sums);
@@ -1206,26 +1210,35 @@ export class TimeChart {
1206
1210
  let delta;
1207
1211
  const notations = new Set();
1208
1212
  if (fromData != null) {
1209
- base = 0;
1210
1213
  const data = (_b = fromData.get(column.start ? ((_a = column.start.toISODate()) !== null && _a !== void 0 ? _a : "") : "")) !== null && _b !== void 0 ? _b : {};
1211
- // the bases of the row are the scenarios of the series, each counts once
1212
- const bases = new Set(candidates.map((entry) => entry.variance.base));
1213
- // a row for a part of the series only has no total: the reference of the dataset is the one of the whole total
1214
- const covered = column.scenarios.filter((scenario) => bases.has(scenario)).length;
1215
- if (covered > 0 && covered < column.scenarios.length) {
1214
+ // the scenarios of the series can stand on either side of a variance: that side is
1215
+ // added up, each scenario once, the other side is the one reference of the row
1216
+ const series = new Set(column.scenarios);
1217
+ const bases = [...new Set(candidates.map((entry) => entry.variance.base))];
1218
+ const deltas = [...new Set(candidates.map((entry) => entry.variance.delta))];
1219
+ // a total needs the whole series on one side and none of it on the other: a row for a part
1220
+ // of the series, or one that sets parts of the series against each other, has no total
1221
+ const inBases = bases.filter((name) => series.has(name)).length;
1222
+ const inDeltas = deltas.filter((name) => series.has(name)).length;
1223
+ if ((inBases > 0 && inDeltas > 0) || (inBases + inDeltas > 0 && inBases + inDeltas < series.size)) {
1216
1224
  return null;
1217
1225
  }
1218
- for (const name of bases) {
1219
- // a 0 is a scenario without a value in this total, as for the parts
1220
- if (Number.isFinite(data[name]) && data[name] !== 0) {
1221
- base += data[name];
1222
- notations.add(name.slice(0, 2));
1223
- }
1224
- }
1225
- if (notations.size === 0 || !Number.isFinite(data[first.delta])) {
1226
+ // a 0 is a scenario without a value in this total, as for the parts
1227
+ const has = (name) => Number.isFinite(data[name]) && data[name] !== 0;
1228
+ const side = (names) => {
1229
+ // of the side with the series only the series counts, of the other side the first name
1230
+ const ofSeries = names.filter((name) => series.has(name));
1231
+ const used = (ofSeries.length > 0 ? ofSeries : names.slice(0, 1)).filter(has);
1232
+ return used.length > 0 ? used.reduce((sum, name) => sum + data[name], 0) : null;
1233
+ };
1234
+ const baseSide = side(bases);
1235
+ const deltaSide = side(deltas);
1236
+ if (baseSide == null || deltaSide == null) {
1226
1237
  return null;
1227
1238
  }
1228
- delta = data[first.delta];
1239
+ base = baseSide;
1240
+ delta = deltaSide;
1241
+ bases.filter(has).forEach((name) => notations.add(name.slice(0, 2)));
1229
1242
  }
1230
1243
  else {
1231
1244
  // the same periods as the column, so the two tell the same: with `last` the one
@@ -1 +1 @@
1
- import{B as s,d as o}from"./p-B8-9TksQ.js";const p=s,r=o;export{p as BnChartTimeRenderer,r as defineCustomElement}
1
+ import{B as s,d as o}from"./p-isJcvi4q.js";const i=s,p=o;export{i as BnChartTimeRenderer,p as defineCustomElement}
@@ -1 +1 @@
1
- import{p as t,H as i,f as e,w as s,h as a,d as n,t as r}from"./p-BnmylmXF.js";import{h as o,g as l,a as h}from"./p-5LbdDgZ5.js";import{k as c,v as d,a as u,B as p,i as v,f as m,h as g,n as f,C as b,m as y}from"./p-DG0UTzyc.js";import{w as S}from"./p-ClFDt6Bk.js";import{w as x}from"./p-BrQCbmG0.js";import{i as w,w as A,a as O}from"./p-BcTq1zVT.js";import{w as M}from"./p-BPvwrhvq.js";import{w as _}from"./p-CpUADUdN.js";import{w as N}from"./p-NkLVO7n9.js";import{r as T}from"./p-D0v9GMIf.js";import{w as D}from"./p-CFW5n3j6.js";import{w as k,r as L}from"./p-D32TsLzd.js";import{g as W}from"./p-Dsvjkuy3.js";import{r as F,f as j,p as P}from"./p-Xb6Ilq8u.js";import{o as R}from"./p-B6kka9sT.js";import{V as U,F as C,v as I}from"./p-Zz3fAPcH.js";import{b as B,e as $,f as z,g as E,h as G}from"./p-DguYWLBj.js";import{D as V}from"./p-ja0FCkHB.js";import{L as H}from"./p-DY5fMUX8.js";import{o as q,m as J}from"./p-Bmb0YBzz.js";import{r as X,a as Y}from"./p-CckAR27O.js";import{a as Z}from"./p-CFY-zEXs.js";import{a as Q}from"./p-JofGXz75.js";import{s as K}from"./p-DakXa7Dp.js";import{d as tt}from"./p-B8-9TksQ.js";const it=t(class t extends i{validateFilter(t){const i="ERR_filter";o(t)?this.errors.addOrReplace({id:i,type:"error",message:"filter: double backticks are not allowed."}):this.errors.remove(i)}validateScenario(t){const i="WARN_scenarios";if(w(t)||c(t))return void this.errors.remove(i);const e=d(t);e.length>0?this.errors.addOrReplace({id:i,type:"warning",message:"scenarios: invalid value(s) '"+JSON.stringify(e)+"' are not supported."}):this.errors.remove(i)}validateVariances(t){const i="WARN_variances";if(w(t))return void this.errors.remove(i);const e=u(t);e.length>0?this.errors.addOrReplace({id:i,type:"warning",message:"variances: invalid value(s) '"+JSON.stringify(e)+"' are not supported."}):this.errors.remove(i)}validateLeftSync(t){const i="WARN_syncSpaceLeft";p(t)?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"syncSpaceLeft: invalid value(s) '"+t+"' are not supported."})}validateUnitScaling(t){const i="WARN_unitScaling";v(t)?this.errors.remove(i):"invalid"===F(t,this.pixelPerUnitGroupMap).kind?this.errors.addOrReplace({id:i,type:"warning",message:"unitScaling: invalid value(s) '"+t+"' are not supported."}):this.errors.remove(i)}validatePercentageScaling(t){const i="WARN_percentageScaling";v(t)?this.errors.remove(i):"invalid"===F(t,this.pixelPerUnitGroupMap).kind?this.errors.addOrReplace({id:i,type:"warning",message:"percentageScaling: invalid value(s) '"+t+"' are not supported."}):this.errors.remove(i)}validateDateInterval(t){const i="WARN_dateInterval";v(t)||m(t)?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"dateInterval: invalid value '"+(null==t?void 0:""+t)+"' is not supported."})}validateChartMode(t){const i="WARN_chartMode";["bar","line","auto"].includes(null==t?void 0:t.toLowerCase())?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"chartMode: invalid value '"+(null==t?void 0:""+t)+"' is not supported. Valid values are: bar, line, auto."})}validateMaxBars(t){const i="WARN_maxBars";!g(t)||t<1?this.errors.addOrReplace({id:i,type:"warning",message:"maxBars: invalid value '"+(null==t?void 0:""+t)+"' is not supported. Must be a positive integer."}):this.errors.remove(i)}validateStack(t){const i="WARN_stack",e=f(t);e.length>0?this.errors.addOrReplace({id:i,type:"warning",message:e.join("; ")}):this.errors.remove(i)}validateScaling(t){if(null==t||""===t||"none"===t||"auto"===t)return void this.errors.remove("WARN_scale");const i=Number(t);isNaN(i)||i<=0?this.errors.addOrReplace({id:"WARN_scale",type:"warning",message:`Invalid scale value: "${t}". Use "none", "auto", or a positive number.`}):this.errors.remove("WARN_scale")}validateAxisLabelsMode(t){const i="WARN_axisLabelsMode";v(t)||b(t)?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"axisLabelsMode: invalid value '"+(null==t?void 0:""+t)+"' is not supported."})}validateMeasureScale(t){const i="WARN_measureScale";y(t)?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"measureScale: invalid value '"+(null==t?void 0:""+t)+"' is not supported."})}validateDataFormatDigitsDecimal(t){this.validateDigits("dataFormatDigitsDecimal",t)}validateDataFormatDigitsPercent(t){this.validateDigits("dataFormatDigitsPercent",t)}validateDigits(t,i){const e="WARN_"+t;!g(i)||Number(i)<0||Number(i)>100?this.errors.addOrReplace({id:e,type:"warning",message:t+": invalid value '"+i+"' is not supported."}):this.errors.remove(e)}validateTotals(t){const i="WARN_totals";v(t)||null!=this.parseTotals(t)?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:'totals: needs JSON with a unitScaling greater than 0, by one of all, year, quarter, month, week, and aggregation one of sum, average, last. For example {"unitScaling":280}.'}),this.bindTotalsDataset()}parseTotals(t){var i,e;try{const s=JSON.parse(t),a=F(null==s?void 0:s.unitScaling,this.pixelPerUnitGroupMap);if("value"!==a.kind||!(a.value>0))return null;const n=null!==(i=s.by)&&void 0!==i?i:"all",r=null!==(e=s.aggregation)&&void 0!==e?e:"sum";if(!["all","year","quarter","month","week"].includes(n))return null;if(!["sum","average","last"].includes(r))return null;const o=Number(s.width);return{unitScaling:a.value,by:n,aggregation:r,label:"string"==typeof s.label||"number"==typeof s.label?s.label+"":"",width:o>0?o:1,dataset:"string"==typeof s.dataset?s.dataset.trim():""}}catch(t){return null}}bindTotalsDataset(){var t,i;let e;try{const i=v(this.totals)?"":null===(t=JSON.parse(this.totals))||void 0===t?void 0:t.dataset;e="string"==typeof i?i.trim():""}catch(t){e=""}this.element.isConnected&&e!==this.totalsDatasetName&&(null===(i=this.totalsDatasetUnsubscribe)||void 0===i||i.call(this),this.totalsDatasetUnsubscribe=null,this.totalsDatasetName=e,e&&(this.totalsDatasetUnsubscribe=l(this.element).db.subscribe(e,(()=>{this.dataVersion++}))))}prepareTotals(){const t=v(this.totals)?null:this.parseTotals(this.totals),i="WARN_totals_unitScaling";if(null==t)return this.errors.remove(i),null;if("value"!==F(this.unitScaling,this.pixelPerUnitGroupMap).kind)return this.errors.addOrReplace({id:i,type:"warning",message:"totals: needs a fixed unitScaling of the chart, the total columns are not drawn."}),null;if(this.hidesScenarios())return this.errors.addOrReplace({id:i,type:"warning",message:"totals: needs the columns of the chart, a chart with scenarios none draws no total columns."}),null;this.errors.remove(i);const{unitScaling:e}=t,s=function(t,i){var e={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&i.indexOf(s)<0&&(e[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(s=Object.getOwnPropertySymbols(t);a<s.length;a++)i.indexOf(s[a])<0&&Object.prototype.propertyIsEnumerable.call(t,s[a])&&(e[s[a]]=t[s[a]])}return e}(t,["unitScaling"]);return Object.assign(Object.assign({},s),{pixelPerUnit:this.getEffectiveFontPx()/e})}validateAxisLabelsStep(t){const i="WARN_axisLabelsStep";!g(t)||Number(t)<1?this.errors.addOrReplace({id:i,type:"warning",message:"axisLabelsStep: invalid value '"+t+"' is not supported."}):this.errors.remove(i)}validateAxisTitlePosition(t){const i="WARN_axisTitlePosition";v(t)||["left","right","none"].includes(t.trim().toLowerCase())?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"axisTitlePosition: invalid value '"+t+"' is not supported."})}constructor(i){super(),!1!==i&&this.__registerHost(),this.__attachShadow(),this.datasetName="",this.dataVersion=0,this.datasetMeta=null,this.appliedScaleFactor=1,this.layoutObserver=null,this.chartTitle="",this.filter="",this.syncSpaceLeft=-1,this.chartMode="bar",this.maxBars=28,this.stack="",this.intervalSpanLimit=28,this.lineFullWidth=!0,this.showCategories=!0,this.measureScale="greatest",this.showMeasureScale=!1,this.showOverlayAvg=!0,this.showOverlayMedian=!1,this.measureUnit="",this.dataFormatDigitsDecimal=1,this.dataFormatDigitsPercent=2,this.dataFormatPercentSign=!0,this.axisLabelsStep=1,this.totals="",this.totalsDatasetUnsubscribe=null,this.totalsDatasetName="",this.scenarioSwitch=!1,this.axisTitlePosition="left",this.pixelPerUnitGroupMap=new Map,this._autoScaleGuard=!1,this._lastObservedWidth=0,this._settleTimer=null,this._lastAppliedHeight=0,this._baseHeightBonus=0,this.autoUnitWarningActive=!1,this.autoPctWarningActive=!1,this.handleAutoScalingReport=i=>{var e,s,a,n,r,o;this.lastAutoScalingReport={unit:null!==(e=i.unit)&&void 0!==e?e:null===(s=this.lastAutoScalingReport)||void 0===s?void 0:s.unit,percentage:null!==(a=i.percentage)&&void 0!==a?a:null===(n=this.lastAutoScalingReport)||void 0===n?void 0:n.percentage};const l=(t,i)=>void 0===i||Math.abs(t-i)>.001*Math.abs(t),h=this.getEffectiveFontPx();if(void 0!==i.unit&&i.unit>0&&this.autoUnitWarningActive){const e=h/i.unit;l(e,this.lastReportedUnitsPerEm)&&(this.lastReportedUnitsPerEm=e,this.errors.addOrReplace({id:"AUTO_unitScaling",type:"warning",message:`unit-scaling: ${t.describeScalingInput(((null!==(r=this.unitScaling)&&void 0!==r?r:"")+"").trim())}, auto-fitted to 1 em ≈ ${j(e)} units.`}))}if(void 0!==i.percentage&&i.percentage>0&&this.autoPctWarningActive){const e=100*h/i.percentage;l(e,this.lastReportedPpPerEm)&&(this.lastReportedPpPerEm=e,this.errors.addOrReplace({id:"AUTO_percentageScaling",type:"warning",message:`percentage-scaling: ${t.describeScalingInput(((null!==(o=this.percentageScaling)&&void 0!==o?o:"")+"").trim())}, auto-fitted to 1 em ≈ ${j(e)} percentage points.`}))}},_(this),x(this),S(this,(t=>{this.datasetName=(null==t?void 0:t.startsWith("$"))?t.substring(1):t||"",this.dataVersion=this.dataVersion+1}),((t,i)=>{this.datasetMeta=i})),this.chartTemplate=this.chartTemplate.bind(this),this.errors=k(this),M(this),this.componentStyle=N(this),this.ruleSetConfig=D(this),this.t=A(this).t,this.resolveInherited=O(this,[{propName:"scenarios",ancestorAttr:"title-scenarios"},{propName:"variances",ancestorAttr:"title-variances"}],this.errors)}componentWillLoad(){this.validateFilter(this.filter),this.validateScenario(this.scenarios),this.validateVariances(this.variances),this.validateUnitScaling(this.unitScaling),this.validateLeftSync(this.syncSpaceLeft),this.validateDateInterval(this.dateInterval),this.validateAxisLabelsMode(this.axisLabelsMode),this.validateMeasureScale(this.measureScale),this.validateChartMode(this.chartMode),this.validateMaxBars(this.maxBars),this.validateStack(this.stack),this.validateScaling(this.scale),this.validateDataFormatDigitsDecimal(this.dataFormatDigitsDecimal),this.validateDataFormatDigitsPercent(this.dataFormatDigitsPercent),this.validateAxisLabelsStep(this.axisLabelsStep),this.validateTotals(this.totals),this.validateAxisTitlePosition(this.axisTitlePosition)}measureContentWidth(){var t;const i=null===(t=this.element.shadowRoot)||void 0===t?void 0:t.querySelectorAll("bn-chart-time-renderer");let e=0,s=!1;return null==i||i.forEach((t=>{var i,a,n;const r=parseFloat(null!==(n=null===(a=null===(i=t.shadowRoot)||void 0===i?void 0:i.querySelector("svg#drawCanvas"))||void 0===a?void 0:a.getAttribute("width"))&&void 0!==n?n:"");Number.isNaN(r)||(e=Math.max(e,r),s=!0)})),s?Math.max(Math.floor(e),this.element.scrollWidth):this.element.scrollWidth}measureContentHeight(){var t;const i=null===(t=this.element.shadowRoot)||void 0===t?void 0:t.querySelectorAll("bn-chart-time-renderer");let e=0,s=!1;return null==i||i.forEach((t=>{var i,a,n;const r=parseFloat(null!==(n=null===(a=null===(i=t.shadowRoot)||void 0===i?void 0:i.querySelector("svg#drawCanvas"))||void 0===a?void 0:a.getAttribute("height"))&&void 0!==n?n:"");Number.isNaN(r)||(e+=r,s=!0)})),s?Math.max(Math.floor(e),this.element.scrollHeight):this.element.scrollHeight}checkOverflow(){const t=W(this.element),i=this.measureContentWidth(),e=this.measureContentHeight(),s=t.width>0&&i>t.width+1,a=t.height>0&&e>t.height+1;if(!s&&!a)return void L(this.errors,null);const n=this.prepareVariances().some((t=>t.startsWith("dr"))),r="value"===F(this.unitScaling,this.pixelPerUnitGroupMap).kind,o=n&&"value"===F(this.percentageScaling,this.pixelPerUnitGroupMap).kind,{mode:l}=P(this.scale),h="auto"!==l&&"empty"!==l,c=[];a&&r&&c.push("unit-scaling"),a&&o&&c.push("percentage-scaling"),s&&h&&c.push("scale");const d=[];s&&d.push(`width (${Math.round(i)}px > ${Math.round(t.width)}px)`),a&&d.push(`height (${Math.round(e)}px > ${Math.round(t.height)}px)`),L(this.errors,`Chart exceeds available ${d.join(" and ")}. `+(c.length>0?`Adjust ${c.join(" / ")} or set to "auto".`:"Content does not fit even at minimum auto scaling; enlarge the container."),c.length>0)}componentDidRender(){K(this.element,"bn-chart-time-renderer");const t=this.updateBaseHeightBonus();t&&!this._autoScaleGuard&&e(this);const{mode:i}=P(this.scale);if("auto"!==i&&"empty"!==i)return this._autoScaleGuard=!1,void this.checkOverflow();if(this._autoScaleGuard)return this._autoScaleGuard=!1,this.checkOverflow(),void(t&&e(this));const a=this.element,{width:n}=W(a);if(n<=0)return void this.checkOverflow();this._lastObservedWidth=n;const r=this.componentStyle((t=>{var i;return(null===(i=t.global)||void 0===i?void 0:i.fontSizePx)||13.3333})),o=a.scrollWidth,l=this.appliedScaleFactor;if(o<=n+1)return this.errors.remove("AUTO_scale"),void this.checkOverflow();const h=Math.max(.3,l*(n-1)/o);Math.abs(h-l)<.01||(a.style.setProperty("--bn-font-size",r*h+"px"),"empty"===i?this.errors.addOrReplace({id:"AUTO_scale",type:"warning",message:"Auto-scaled chart by factor "+h.toFixed(3)}):this.errors.remove("AUTO_scale"),this._autoScaleGuard=!0,s((()=>{this.appliedScaleFactor=h}))),this.checkOverflow()}componentDidLoad(){this.layoutObserver=R(this.element,(()=>{if(this._autoScaleGuard)return;const{width:t}=W(this.element);t>0&&Math.abs(t-this._lastObservedWidth)>2&&(this._lastObservedWidth=t,e(this))})),requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(this._autoScaleGuard)return;const{width:t}=W(this.element);this._lastObservedWidth=t,e(this)}))})),this.settleParentHeight()}settleParentHeight(){const t=[150,400,1e3,2500],i=()=>{if(this._settleTimer=null,!this.element.isConnected)return;const{height:s}=W(this.element);s>0&&Math.abs(s-this._lastAppliedHeight)>8&&!this._autoScaleGuard&&e(this);const a=t.shift();void 0!==a&&(this._settleTimer=setTimeout(i,a))};this._settleTimer=setTimeout(i,t.shift())}connectedCallback(){this.bindTotalsDataset()}disconnectedCallback(){var t,i;null===(t=this.totalsDatasetUnsubscribe)||void 0===t||t.call(this),this.totalsDatasetUnsubscribe=null,this.totalsDatasetName="",null===(i=this.layoutObserver)||void 0===i||i.disconnect(),this.layoutObserver=null,null!=this._settleTimer&&(clearTimeout(this._settleTimer),this._settleTimer=null)}updateBaseHeightBonus(){var t,i;const e=this.prepareSegments();let s=0;if("value"===F(this.unitScaling,this.pixelPerUnitGroupMap).kind&&e.length>1&&0===e[0].length){const a=Array.from(null!==(i=null===(t=this.element.shadowRoot)||void 0===t?void 0:t.querySelectorAll("bn-chart-time-renderer"))&&void 0!==i?i:[]);s=function(t,i){let e=0;for(const s of i)s>0&&(e+=t-s);return Math.max(0,e)}(this.segmentShare(this._lastAppliedHeight,e.length),a.slice(1).map((t=>t.offsetHeight)))}const a=function(t,i){const e=i-t;return e<-1||e>8?i:t}(this._baseHeightBonus,s);return a!==this._baseHeightBonus&&(this._baseHeightBonus=a,!0)}segmentShare(t,i){const e=this.showMeasureScale?this.getEffectiveFontPx():0;return Math.max(0,t-e)/Math.max(1,i)}prepareDimension(t=!1){const i=W(this.element),e=this.prepareScenarios(),s=this.prepareSegments();this.canvasWidthSegmented=i.width/(e.length+this.prepareVariances().length||1),this._lastAppliedHeight=i.height;const a=this.segmentShare(i.height,s.length);return{width:this.canvasWidthSegmented,height:a+(t?this._baseHeightBonus:0)}}prepareScenarios(){var t,i,e,s;const a=this.resolveInherited("scenarios",this.scenarios);if(a.inherited)return this.errors.remove("AUTO_scenarios"),a.value.split(",").map((t=>t.trim()));if(c(a.value))return this.errors.remove("AUTO_scenarios"),[];const n="auto"===(null===(t=a.value)||void 0===t?void 0:t.trim().toLowerCase());return v(a.value)||n?(null===(e=null===(i=this.datasetMeta)||void 0===i?void 0:i.availableScenarios)||void 0===e?void 0:e.length)>0?(n||a.unresolved?this.errors.remove("AUTO_scenarios"):this.errors.addOrReplace({id:"AUTO_scenarios",type:"warning",message:"scenarios: not set, auto-detected: "+this.datasetMeta.availableScenarios.join(",")}),this.datasetMeta.availableScenarios):[]:(this.errors.remove("AUTO_scenarios"),null===(s=a.value)||void 0===s?void 0:s.split(",").map((t=>t.trim())))}hidesScenarios(){const t=this.resolveInherited("scenarios",this.scenarios);return!t.inherited&&c(t.value)}prepareSegments(){const t=this.hidesScenarios()?[]:[[]],i=new Map;for(const e of this.prepareVariances()){const s=new U(e),a=`${s.type}:${s.delta}`,n=this.scenarioSwitch&&s.isValid?i.get(a):void 0;if(n){n.push(e);continue}const r=[e];t.push(r),s.isValid&&i.set(a,r)}return t}prepareAxisTitlePosition(){var t;const i=null===(t=this.axisTitlePosition)||void 0===t?void 0:t.trim().toLowerCase();return"right"===i||"none"===i?i:"left"}prepareAvg(){return this.showOverlayAvg}prepareMedian(){return this.showOverlayMedian}prepareVariances(){const t=this.resolveInherited("variances",this.variances).value;return v(t)?[]:null==t?void 0:t.split(",").map((t=>t.trim()))}checkVarianceScenarios(t){const i="WARN_variances_scenario",e=this.prepareScenarios(),s=[];for(const i of t){const t=new U(i);if(t.isValid)for(const a of[t.base,t.delta])e.includes(a)||s.push(`'${i}' needs '${a}'`)}!this.hidesScenarios()&&e.length>0&&s.length>0?this.errors.addOrReplace({id:i,type:"warning",message:`variances: ${s.join(", ")}, which is not in scenarios (${e.join(", ")}). The variance has no values.`}):this.errors.remove(i)}prepareHideAxisLabels(t){return t>=1||!this.showCategories}prepareI18n(){const t=h,i=new Map(["no-data","date-format-short-year"].map((t=>[t,this.t(".".concat(t))]))),e=new Map(t.map((t=>[t,this.t("global.".concat(t))])));return new Map([...e.entries(),...i.entries(),...T(this.ruleSetConfig("user"))])}static describeScalingInput(t){return""===t?"not set":`invalid value "${t}"`}preparePixelPerUnit(){const i=F(this.unitScaling,this.pixelPerUnitGroupMap);return"value"===i.kind?(this.errors.remove("AUTO_unitScaling"),this.autoUnitWarningActive=!1,this.lastReportedUnitsPerEm=void 0,this.getEffectiveFontPx()/i.value):"auto"===i.kind?(this.errors.remove("AUTO_unitScaling"),this.autoUnitWarningActive=!1,this.lastReportedUnitsPerEm=void 0,0):(this.autoUnitWarningActive=!0,this.errors.addOrReplace({id:"AUTO_unitScaling",type:"warning",message:`unit-scaling: ${t.describeScalingInput(i.raw)}, auto-calculated to fit available space.`}),0)}preparePixelPerPercentage(){const i=F(this.percentageScaling,this.pixelPerUnitGroupMap);return"value"===i.kind?(this.errors.remove("AUTO_percentageScaling"),this.autoPctWarningActive=!1,this.lastReportedPpPerEm=void 0,100*this.getEffectiveFontPx()/i.value):"auto"===i.kind?(this.errors.remove("AUTO_percentageScaling"),this.autoPctWarningActive=!1,this.lastReportedPpPerEm=void 0,0):(this.autoPctWarningActive=!0,this.errors.addOrReplace({id:"AUTO_percentageScaling",type:"warning",message:`percentage-scaling: ${t.describeScalingInput(i.raw)}, auto-calculated to fit available space.`}),0)}prepareStyle(){const t=this.getEffectiveScaleFactor();return this.componentStyle((i=>{const e=i.global.fontSizePx*t;return{scaleFactors:{scenarioOffset:i["bn-chart-time"].scaleFactors.scenarioOffset,scenarioLabelToColumn:i["bn-chart-time"].scaleFactors.scenarioLabelToColumn,labelToColumn:i["bn-chart-time"].scaleFactors.labelToColumn,labelToAxis:i["bn-chart-time"].scaleFactors.labelToAxis,needleWidth:i["bn-chart-time"].scaleFactors.needleWidth,needleHeadWidth:i["bn-chart-time"].scaleFactors.needleHeadWidth,columnWidth:i["bn-chart-time"].scaleFactors.columnWidth,varianceAxisLineWidth:i["bn-chart-time"].scaleFactors.varianceAxisLineWidth,axisLineWidth:i["bn-chart-time"].scaleFactors.axisLineWidth,auxiliaryLineWidth:i["bn-chart-time"].scaleFactors.auxiliaryLineWidth,scenarioLineWidth:i["bn-chart-time"].scaleFactors.scenarioLineWidth,markerWidth:i["bn-chart-time"].scaleFactors.markerWidth,markerOffset:i["bn-chart-time"].scaleFactors.markerOffset,categoryWidth:i["bn-chart-time"].scaleFactors.categoryWidth,axisTickLength:i["bn-chart-time"].scaleFactors.axisTickLength},fontStyles:{font:`${e}px ${i.global.fontFamily}`,family:i.global.fontFamily,size:e,color:i.global.fontColor,background:i.global.fontBackgroundColor,leading:1.8},axisStyles:i["bn-chart-time"].axisStyles,barStyles:i["bn-chart-time"].barStyles,varianceStyles:i["bn-chart-time"].varianceStyles,stackColors:i["bn-chart-time"].stackColors,padding:i["bn-chart-time"].padding,pattern:null,locale:"de"}}))}prepareLeftSideOffset(t,i){if(this.syncSpaceLeft>-1)return this.syncSpaceLeft;const e="left"===this.prepareAxisTitlePosition()?[...this.prepareVariances(),this.chartTitle]:[];return C.getMaxWidthOfArrayItems([...e,...this.prepareScenarios()],t,i)}prepareChartTitle(t){return t>=1||this.hidesScenarios()?"":this.chartTitle}prepareDateInterval(){var t,i,e;const s="auto"===(null===(t=this.dateInterval)||void 0===t?void 0:t.trim().toLowerCase());return v(this.dateInterval)||s?(null===(i=this.datasetMeta)||void 0===i?void 0:i.suggestedDateInterval)?(s?this.errors.remove("AUTO_dateInterval"):this.errors.addOrReplace({id:"AUTO_dateInterval",type:"warning",message:"dateInterval: not set, auto-detected: "+this.datasetMeta.suggestedDateInterval}),V[this.datasetMeta.suggestedDateInterval.toUpperCase()]):s?V.AUTO:void 0:(this.errors.remove("AUTO_dateInterval"),V[null===(e=this.dateInterval)||void 0===e?void 0:e.toUpperCase()])}prepareIntervalSpanLimit(){const t=Number(this.intervalSpanLimit);return t>0?t:28}prepareAxisLabelsMode(){var t;return B[null===(t=this.axisLabelsMode)||void 0===t?void 0:t.toUpperCase().replace("-","_")]}prepareFilter(){return 0===this.filter.length?"":this.filter}getDataStructure(){return{ITimeChartDataRow:{setName:{type:"string",isOptional:!1,description:""},date:{type:"string",isOptional:!1,description:""},operation:{type:"string",isOptional:!1,description:""},rowGroup:{type:"string",isOptional:!1,description:""},rowGroupIndex:{type:"number",isOptional:!1,description:""},category:{type:"string",isOptional:!1,description:""},categoryIndex:{type:"number",isOptional:!1,description:""},subCategory:{type:"string",isOptional:!1,description:""},subCategoryIndex:{type:"number",isOptional:!1,description:""},columnGroup:{type:"string",isOptional:!1,description:""},columnGroupIndex:{type:"number",isOptional:!1,description:""},columnSubGroup:{type:"string",isOptional:!1,description:""},columnSubGroupIndex:{type:"number",isOptional:!1,description:""},ac1:{type:"number",isOptional:!1,description:""},ac2:{type:"number",isOptional:!1,description:""},ac3:{type:"number",isOptional:!1,description:""},ac4:{type:"number",isOptional:!1,description:""},pp1:{type:"number",isOptional:!1,description:""},pp2:{type:"number",isOptional:!1,description:""},pp3:{type:"number",isOptional:!1,description:""},pp4:{type:"number",isOptional:!1,description:""},fc1:{type:"number",isOptional:!1,description:""},fc2:{type:"number",isOptional:!1,description:""},fc3:{type:"number",isOptional:!1,description:""},fc4:{type:"number",isOptional:!1,description:""},pl1:{type:"number",isOptional:!1,description:""},pl2:{type:"number",isOptional:!1,description:""},pl3:{type:"number",isOptional:!1,description:""},pl4:{type:"number",isOptional:!1,description:""}}}}prepareMeasureScale(){return v(this.measureScale)?"GREATEST":["_","k","M","G","T","P","E","Z","Y","m","μ","n","p","P","f","a","z","y"].includes(this.measureScale.trim())||"LEAST"===this.measureScale.trim().toUpperCase()?this.measureScale.trim():"GREATEST"}prepareShowMeasureScale(t){return 0===t&&this.showMeasureScale}prepareMeasureUnit(){return""===this.measureUnit||null==this.measureUnit?"":this.measureUnit}prepareStackConfig(){if(v(this.stack))return this.errors.remove("WARN_stack_dimensions_scenarios"),this.errors.remove("WARN_stack_scenarios_max"),null;try{const t=JSON.parse(this.stack),i=t.by,e="WARN_stack_dimensions_scenarios",s="WARN_stack_scenarios_max",a=this.prepareScenarios();return i===$.DIMENSIONS&&a.length>1&&!this.scenarioSwitch?this.errors.addOrReplace({id:e,type:"warning",message:`stack by dimensions: only the first scenario "${a[0]}" is used, the rest (${a.slice(1).join(", ")}) are discarded.`}):this.errors.remove(e),i===$.SCENARIOS&&a.length>4?this.errors.addOrReplace({id:s,type:"warning",message:`stack by scenarios: at most four scenarios are stacked, the rest (${a.slice(4).join(", ")}) are discarded. Use stack by dimensions for more series.`}):this.errors.remove(s),{by:i,mode:t.mode||E.ABSOLUTE,order:t.order||z.DATASET,notation:"scenario"===t.notation?"scenario":"none",legend:["right","both","none"].includes(t.legend)?t.legend:"left",percentMark:!0===t.percentMark}}catch(t){return this.errors.remove("WARN_stack_dimensions_scenarios"),this.errors.remove("WARN_stack_scenarios_max"),null}}prepareLineFullWidth(){return this.lineFullWidth}prepareChartMode(){var t;const i=null===(t=this.chartMode)||void 0===t?void 0:t.toLowerCase();return"line"===i?G.LINE:"auto"===i?G.AUTO:G.BAR}prepareMaxBars(){return Math.floor(Number(this.maxBars)||28)}chartTemplate(t,i){const e=this.prepareI18n(),s=this.prepareStyle(),n=W(this.element).width,r=this.preparePixelPerUnit(),o=this.preparePixelPerPercentage(),l=this.prepareStackConfig(),h=0===t.length,c=this.hidesScenarios()?I(t):this.prepareScenarios(),d=h&&(null==l?void 0:l.by)===$.DIMENSIONS&&!this.scenarioSwitch?c.slice(0,1):c;return a("bn-chart-time-renderer",{tableName:this.datasetName,dataVersion:this.dataVersion,chartTitle:this.prepareChartTitle(i),scenarios:d,variances:t.length>0?t:[""],hideAxisLabels:this.prepareHideAxisLabels(i),pixelPerUnit:r,pixelPerPercentage:o,reportAutoScaling:this.handleAutoScalingReport,errors:this.errors,leftSideOffsetForHorizontalSync:this.prepareLeftSideOffset(e,s),styles:s,i18n:e,dateInterval:this.prepareDateInterval(),intervalSpanLimit:this.prepareIntervalSpanLimit(),axisLabelsMode:this.prepareAxisLabelsMode(),filter:this.prepareFilter(),"measure-scale":this.prepareMeasureScale(),"measure-unit":this.prepareMeasureUnit(),showOverlayAvg:this.prepareAvg(),showOverlayMedian:this.prepareMedian(),showMeasureScale:this.prepareShowMeasureScale(i),chartMode:this.prepareChartMode(),maxBars:this.prepareMaxBars(),stackConfig:l,lineFullWidth:this.prepareLineFullWidth(),dataFormatDigits:{percent:this.dataFormatDigitsPercent,decimal:this.dataFormatDigitsDecimal,percentSign:!1!==this.dataFormatPercentSign},axisLabelsStep:Math.max(1,Math.floor(Number(this.axisLabelsStep)||1)),scalingIndicator:Number(this.scalingIndicator)||0,totals:this.prepareTotals(),scenarioSwitch:this.scenarioSwitch,axisTitlePosition:this.prepareAxisTitlePosition(),containerWidth:n,parentDimensions:this.prepareDimension(h),ruleSetConfig:this.ruleSetConfig()})}async getBaseline(){return Q(this.element,"bn-chart-time-renderer")}async getLayoutState(t){var i,e,s,a;const n=null!==(i=null==t?void 0:t.detail)&&void 0!==i?i:"summary",r=q(this.element),o=this.getEffectiveScaleFactor(),l=Number.isFinite(o)&&o>0?o:1,h=this.componentStyle((t=>{var i;return(null===(i=t.global)||void 0===i?void 0:i.fontSizePx)||13.3333}))*l,c=this.prepareVariances(),d=Z(this.element,"bn-chart-time-renderer",this.prepareSegments().map((t=>t.length>0?t.join(","):"base")),r,n),u=null===(e=this.element.shadowRoot)||void 0===e?void 0:e.querySelector("bn-chart-time-renderer"),p={version:H,tag:this.element.localName,id:Y(this.element),slot:null!==(s=this.element.getAttribute("slot"))&&void 0!==s?s:void 0,rect:J(this.element,r),em:{fontSizePx:h,appliedScaleFactor:l},regions:d.regions,metadata:{title:this.chartTitle||void 0,scenarios:null!==(a=null==u?void 0:u.scenarios)&&void 0!==a?a:[],variances:c,barCount:d.barCount,chartMode:this.chartMode||void 0,hasNoData:0===d.barCount},diagnostics:X(this.element),scaling:this.resolveScalingInfo(h),baseline:d.baseline};return d.elements&&(p.elements=d.elements),p}resolveScalingInfo(t){var i,e;const s={},a=F(this.unitScaling,this.pixelPerUnitGroupMap);if("value"===a.kind)s.unitMode="fixed",s.unitsPerEm=a.value,s.unitPxPerUnit=t/a.value;else{s.unitMode="auto";const e=null===(i=this.lastAutoScalingReport)||void 0===i?void 0:i.unit;void 0!==e&&e>0&&(s.unitPxPerUnit=e,s.unitsPerEm=t/e)}const n=F(this.percentageScaling,this.pixelPerUnitGroupMap);if("value"===n.kind)s.percentageMode="fixed",s.percentagePointsPerEm=n.value,s.percentagePxPerPoint=t/n.value;else{s.percentageMode="auto";const i=null===(e=this.lastAutoScalingReport)||void 0===e?void 0:e.percentage;void 0!==i&&i>0&&(s.percentagePxPerPoint=i/100,s.percentagePointsPerEm=100*t/i)}return s}getEffectiveScaleFactor(){const{mode:t,factor:i}=P(this.scale);return"factor"===t?i:"auto"===t||"empty"===t?this.appliedScaleFactor:1}getEffectiveFontPx(){return this.componentStyle((t=>{var i;return(null===(i=t.global)||void 0===i?void 0:i.fontSizePx)||13.3333}))*this.getEffectiveScaleFactor()}getFontStyles(){const t=this.getEffectiveScaleFactor();return this.componentStyle((i=>{var e,s,a,n;const r=(null===(e=i.global)||void 0===e?void 0:e.fontSizePx)||13.3333;return{"--bn-font-family":(null===(s=i.global)||void 0===s?void 0:s.fontFamily)||"'Noto Sans', sans-serif","--bn-font-size":r*t+"px","--bn-font-color":(null===(a=i.global)||void 0===a?void 0:a.fontColor)||"#000000","--bn-font-background":(null===(n=i.global)||void 0===n?void 0:n.fontBackgroundColor)||"#ffffff"}}))}render(){this.checkVarianceScenarios(this.prepareVariances());const t=this.prepareSegments();0===t.length?this.errors.addOrReplace({id:"WARN_scenarios_none",type:"warning",message:"scenarios: none needs at least one variance, the chart is empty."}):this.errors.remove("WARN_scenarios_none");const i=this.getFontStyles();return a(n,{key:"baa11d12a8dc2e01a487b02bcd68902890ceb85a",style:i},a("div",{key:"40a33368366a59709c8a6c0354a6aca50445778f",class:"container"},t.map(this.chartTemplate)))}get element(){return this}static get watchers(){return{filter:[{validateFilter:0}],scenarios:[{validateScenario:0}],variances:[{validateVariances:0}],syncSpaceLeft:[{validateLeftSync:0}],unitScaling:[{validateUnitScaling:0}],percentageScaling:[{validatePercentageScaling:0}],dateInterval:[{validateDateInterval:0}],chartMode:[{validateChartMode:0}],maxBars:[{validateMaxBars:0}],stack:[{validateStack:0}],scale:[{validateScaling:0}],axisLabelsMode:[{validateAxisLabelsMode:0}],measureScale:[{validateMeasureScale:0}],dataFormatDigitsDecimal:[{validateDataFormatDigitsDecimal:0}],dataFormatDigitsPercent:[{validateDataFormatDigitsPercent:0}],totals:[{validateTotals:0}],axisLabelsStep:[{validateAxisLabelsStep:0}],axisTitlePosition:[{validateAxisTitlePosition:0}]}}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{display:inline-block;position:relative;overflow:hidden;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px);color:var(--bn-font-color, #000000)}.container{display:flex;flex-direction:column-reverse}.background-image{display:flex;flex-wrap:wrap;justify-content:flex-end}'}},[1,"bn-chart-time",{datasets:[513],selectedStyle:[513,"selected-style"],i18nNamespace:[513,"i18n-namespace"],ruleset:[513],chartTitle:[1,"chart-title"],filter:[1],scenarios:[1],variances:[1],syncSpaceLeft:[2,"sync-space-left"],unitScaling:[8,"unit-scaling"],percentageScaling:[8,"percentage-scaling"],dateInterval:[1,"date-interval"],chartMode:[1,"chart-mode"],maxBars:[2,"max-bars"],stack:[1],scale:[1],intervalSpanLimit:[2,"interval-span-limit"],axisLabelsMode:[1,"axis-labels-mode"],lineFullWidth:[4,"line-full-width"],showCategories:[4,"show-categories"],measureScale:[1,"measure-scale"],showMeasureScale:[4,"show-measure-scale"],showOverlayAvg:[4,"show-overlay-avg"],showOverlayMedian:[4,"show-overlay-median"],measureUnit:[1,"measure-unit"],dataFormatDigitsDecimal:[2,"data-format-digits-decimal"],dataFormatDigitsPercent:[2,"data-format-digits-percent"],dataFormatPercentSign:[4,"data-format-percent-sign"],axisLabelsStep:[2,"axis-labels-step"],scalingIndicator:[2,"scaling-indicator"],totals:[1],scenarioSwitch:[4,"scenario-switch"],axisTitlePosition:[1,"axis-title-position"],datasetName:[32],dataVersion:[32],datasetMeta:[32],appliedScaleFactor:[32],getBaseline:[64],getLayoutState:[64]},void 0,{filter:[{validateFilter:0}],scenarios:[{validateScenario:0}],variances:[{validateVariances:0}],syncSpaceLeft:[{validateLeftSync:0}],unitScaling:[{validateUnitScaling:0}],percentageScaling:[{validatePercentageScaling:0}],dateInterval:[{validateDateInterval:0}],chartMode:[{validateChartMode:0}],maxBars:[{validateMaxBars:0}],stack:[{validateStack:0}],scale:[{validateScaling:0}],axisLabelsMode:[{validateAxisLabelsMode:0}],measureScale:[{validateMeasureScale:0}],dataFormatDigitsDecimal:[{validateDataFormatDigitsDecimal:0}],dataFormatDigitsPercent:[{validateDataFormatDigitsPercent:0}],totals:[{validateTotals:0}],axisLabelsStep:[{validateAxisLabelsStep:0}],axisTitlePosition:[{validateAxisTitlePosition:0}]}]),et=it,st=function(){"undefined"!=typeof customElements&&["bn-chart-time","bn-chart-time-renderer"].forEach((t=>{switch(t){case"bn-chart-time":customElements.get(r(t))||customElements.define(r(t),it);break;case"bn-chart-time-renderer":customElements.get(r(t))||tt()}}))};export{et as BnChartTime,st as defineCustomElement}
1
+ import{p as t,H as i,f as e,w as s,h as a,d as n,t as r}from"./p-BnmylmXF.js";import{h as o,g as l,a as h}from"./p-5LbdDgZ5.js";import{k as c,v as d,a as u,B as p,i as v,f as m,h as g,n as f,C as b,m as y}from"./p-DG0UTzyc.js";import{w as S}from"./p-ClFDt6Bk.js";import{w as x}from"./p-BrQCbmG0.js";import{i as w,w as A,a as O}from"./p-BcTq1zVT.js";import{w as M}from"./p-BPvwrhvq.js";import{w as _}from"./p-CpUADUdN.js";import{w as N}from"./p-NkLVO7n9.js";import{r as T}from"./p-D0v9GMIf.js";import{w as D}from"./p-CFW5n3j6.js";import{w as k,r as L}from"./p-D32TsLzd.js";import{g as W}from"./p-Dsvjkuy3.js";import{r as F,f as j,p as P}from"./p-Xb6Ilq8u.js";import{o as R}from"./p-B6kka9sT.js";import{V as U,F as C,v as I}from"./p-Zz3fAPcH.js";import{b as $,e as B,f as z,g as E,h as G}from"./p-DguYWLBj.js";import{D as V}from"./p-ja0FCkHB.js";import{L as q}from"./p-DY5fMUX8.js";import{o as H,m as J}from"./p-Bmb0YBzz.js";import{r as X,a as Y}from"./p-CckAR27O.js";import{a as Z}from"./p-CFY-zEXs.js";import{a as Q}from"./p-JofGXz75.js";import{s as K}from"./p-DakXa7Dp.js";import{d as tt}from"./p-isJcvi4q.js";const it=t(class t extends i{validateFilter(t){const i="ERR_filter";o(t)?this.errors.addOrReplace({id:i,type:"error",message:"filter: double backticks are not allowed."}):this.errors.remove(i)}validateScenario(t){const i="WARN_scenarios";if(w(t)||c(t))return void this.errors.remove(i);const e=d(t);e.length>0?this.errors.addOrReplace({id:i,type:"warning",message:"scenarios: invalid value(s) '"+JSON.stringify(e)+"' are not supported."}):this.errors.remove(i)}validateVariances(t){const i="WARN_variances";if(w(t))return void this.errors.remove(i);const e=u(t);e.length>0?this.errors.addOrReplace({id:i,type:"warning",message:"variances: invalid value(s) '"+JSON.stringify(e)+"' are not supported."}):this.errors.remove(i)}validateLeftSync(t){const i="WARN_syncSpaceLeft";p(t)?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"syncSpaceLeft: invalid value(s) '"+t+"' are not supported."})}validateUnitScaling(t){const i="WARN_unitScaling";v(t)?this.errors.remove(i):"invalid"===F(t,this.pixelPerUnitGroupMap).kind?this.errors.addOrReplace({id:i,type:"warning",message:"unitScaling: invalid value(s) '"+t+"' are not supported."}):this.errors.remove(i)}validatePercentageScaling(t){const i="WARN_percentageScaling";v(t)?this.errors.remove(i):"invalid"===F(t,this.pixelPerUnitGroupMap).kind?this.errors.addOrReplace({id:i,type:"warning",message:"percentageScaling: invalid value(s) '"+t+"' are not supported."}):this.errors.remove(i)}validateDateInterval(t){const i="WARN_dateInterval";v(t)||m(t)?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"dateInterval: invalid value '"+(null==t?void 0:""+t)+"' is not supported."})}validateChartMode(t){const i="WARN_chartMode";["bar","line","auto"].includes(null==t?void 0:t.toLowerCase())?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"chartMode: invalid value '"+(null==t?void 0:""+t)+"' is not supported. Valid values are: bar, line, auto."})}validateMaxBars(t){const i="WARN_maxBars";!g(t)||t<1?this.errors.addOrReplace({id:i,type:"warning",message:"maxBars: invalid value '"+(null==t?void 0:""+t)+"' is not supported. Must be a positive integer."}):this.errors.remove(i)}validateStack(t){const i="WARN_stack",e=f(t);e.length>0?this.errors.addOrReplace({id:i,type:"warning",message:e.join("; ")}):this.errors.remove(i)}validateScaling(t){if(null==t||""===t||"none"===t||"auto"===t)return void this.errors.remove("WARN_scale");const i=Number(t);isNaN(i)||i<=0?this.errors.addOrReplace({id:"WARN_scale",type:"warning",message:`Invalid scale value: "${t}". Use "none", "auto", or a positive number.`}):this.errors.remove("WARN_scale")}validateAxisLabelsMode(t){const i="WARN_axisLabelsMode";v(t)||b(t)?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"axisLabelsMode: invalid value '"+(null==t?void 0:""+t)+"' is not supported."})}validateMeasureScale(t){const i="WARN_measureScale";y(t)?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"measureScale: invalid value '"+(null==t?void 0:""+t)+"' is not supported."})}validateDataFormatDigitsDecimal(t){this.validateDigits("dataFormatDigitsDecimal",t)}validateDataFormatDigitsPercent(t){this.validateDigits("dataFormatDigitsPercent",t)}validateDigits(t,i){const e="WARN_"+t;!g(i)||Number(i)<0||Number(i)>100?this.errors.addOrReplace({id:e,type:"warning",message:t+": invalid value '"+i+"' is not supported."}):this.errors.remove(e)}validateTotals(t){const i="WARN_totals";v(t)||null!=this.parseTotals(t)?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:'totals: needs JSON with a unitScaling greater than 0, by one of all, year, quarter, month, week, and aggregation one of sum, average, last. For example {"unitScaling":280}.'}),this.bindTotalsDataset()}parseTotals(t){var i,e;try{const s=JSON.parse(t),a=F(null==s?void 0:s.unitScaling,this.pixelPerUnitGroupMap);if("value"!==a.kind||!(a.value>0))return null;const n=null!==(i=s.by)&&void 0!==i?i:"all",r=null!==(e=s.aggregation)&&void 0!==e?e:"sum";if(!["all","year","quarter","month","week"].includes(n))return null;if(!["sum","average","last"].includes(r))return null;const o=Number(s.width);return{unitScaling:a.value,by:n,aggregation:r,label:"string"==typeof s.label||"number"==typeof s.label?s.label+"":"",width:o>0?o:1,dataset:"string"==typeof s.dataset?s.dataset.trim():""}}catch(t){return null}}bindTotalsDataset(){var t,i;let e;try{const i=v(this.totals)?"":null===(t=JSON.parse(this.totals))||void 0===t?void 0:t.dataset;e="string"==typeof i?i.trim():""}catch(t){e=""}this.element.isConnected&&e!==this.totalsDatasetName&&(null===(i=this.totalsDatasetUnsubscribe)||void 0===i||i.call(this),this.totalsDatasetUnsubscribe=null,this.totalsDatasetName=e,e&&(this.totalsDatasetUnsubscribe=l(this.element).db.subscribe(e,(()=>{this.dataVersion++}))))}prepareTotals(){const t=v(this.totals)?null:this.parseTotals(this.totals),i="WARN_totals_unitScaling";if(null==t)return this.errors.remove(i),null;if("value"!==F(this.unitScaling,this.pixelPerUnitGroupMap).kind)return this.errors.addOrReplace({id:i,type:"warning",message:"totals: needs a fixed unitScaling of the chart, the total columns are not drawn."}),null;if(this.hidesScenarios())return this.errors.addOrReplace({id:i,type:"warning",message:"totals: needs the columns of the chart, a chart with scenarios none draws no total columns."}),null;this.errors.remove(i);const{unitScaling:e}=t,s=function(t,i){var e={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&i.indexOf(s)<0&&(e[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(s=Object.getOwnPropertySymbols(t);a<s.length;a++)i.indexOf(s[a])<0&&Object.prototype.propertyIsEnumerable.call(t,s[a])&&(e[s[a]]=t[s[a]])}return e}(t,["unitScaling"]);return Object.assign(Object.assign({},s),{pixelPerUnit:this.getEffectiveFontPx()/e})}validateAxisLabelsStep(t){const i="WARN_axisLabelsStep";!g(t)||Number(t)<1?this.errors.addOrReplace({id:i,type:"warning",message:"axisLabelsStep: invalid value '"+t+"' is not supported."}):this.errors.remove(i)}validateAxisTitlePosition(t){const i="WARN_axisTitlePosition";v(t)||["left","right","none"].includes(t.trim().toLowerCase())?this.errors.remove(i):this.errors.addOrReplace({id:i,type:"warning",message:"axisTitlePosition: invalid value '"+t+"' is not supported."})}constructor(i){super(),!1!==i&&this.__registerHost(),this.__attachShadow(),this.datasetName="",this.dataVersion=0,this.datasetMeta=null,this.appliedScaleFactor=1,this.layoutObserver=null,this.chartTitle="",this.filter="",this.syncSpaceLeft=-1,this.chartMode="bar",this.maxBars=28,this.stack="",this.intervalSpanLimit=28,this.lineFullWidth=!0,this.showCategories=!0,this.measureScale="greatest",this.showMeasureScale=!1,this.showOverlayAvg=!0,this.showOverlayMedian=!1,this.measureUnit="",this.dataFormatDigitsDecimal=1,this.dataFormatDigitsPercent=2,this.dataFormatPercentSign=!0,this.axisLabelsStep=1,this.totals="",this.totalsDatasetUnsubscribe=null,this.totalsDatasetName="",this.scenarioSwitch=!1,this.axisTitlePosition="left",this.pixelPerUnitGroupMap=new Map,this._autoScaleGuard=!1,this._lastObservedWidth=0,this._settleTimer=null,this._lastAppliedHeight=0,this._baseHeightBonus=0,this.autoUnitWarningActive=!1,this.autoPctWarningActive=!1,this.handleAutoScalingReport=i=>{var e,s,a,n,r,o;this.lastAutoScalingReport={unit:null!==(e=i.unit)&&void 0!==e?e:null===(s=this.lastAutoScalingReport)||void 0===s?void 0:s.unit,percentage:null!==(a=i.percentage)&&void 0!==a?a:null===(n=this.lastAutoScalingReport)||void 0===n?void 0:n.percentage};const l=(t,i)=>void 0===i||Math.abs(t-i)>.001*Math.abs(t),h=this.getEffectiveFontPx();if(void 0!==i.unit&&i.unit>0&&this.autoUnitWarningActive){const e=h/i.unit;l(e,this.lastReportedUnitsPerEm)&&(this.lastReportedUnitsPerEm=e,this.errors.addOrReplace({id:"AUTO_unitScaling",type:"warning",message:`unit-scaling: ${t.describeScalingInput(((null!==(r=this.unitScaling)&&void 0!==r?r:"")+"").trim())}, auto-fitted to 1 em ≈ ${j(e)} units.`}))}if(void 0!==i.percentage&&i.percentage>0&&this.autoPctWarningActive){const e=100*h/i.percentage;l(e,this.lastReportedPpPerEm)&&(this.lastReportedPpPerEm=e,this.errors.addOrReplace({id:"AUTO_percentageScaling",type:"warning",message:`percentage-scaling: ${t.describeScalingInput(((null!==(o=this.percentageScaling)&&void 0!==o?o:"")+"").trim())}, auto-fitted to 1 em ≈ ${j(e)} percentage points.`}))}},_(this),x(this),S(this,(t=>{this.datasetName=(null==t?void 0:t.startsWith("$"))?t.substring(1):t||"",this.dataVersion=this.dataVersion+1}),((t,i)=>{this.datasetMeta=i})),this.chartTemplate=this.chartTemplate.bind(this),this.errors=k(this),M(this),this.componentStyle=N(this),this.ruleSetConfig=D(this),this.t=A(this).t,this.resolveInherited=O(this,[{propName:"scenarios",ancestorAttr:"title-scenarios"},{propName:"variances",ancestorAttr:"title-variances"}],this.errors)}componentWillLoad(){this.validateFilter(this.filter),this.validateScenario(this.scenarios),this.validateVariances(this.variances),this.validateUnitScaling(this.unitScaling),this.validateLeftSync(this.syncSpaceLeft),this.validateDateInterval(this.dateInterval),this.validateAxisLabelsMode(this.axisLabelsMode),this.validateMeasureScale(this.measureScale),this.validateChartMode(this.chartMode),this.validateMaxBars(this.maxBars),this.validateStack(this.stack),this.validateScaling(this.scale),this.validateDataFormatDigitsDecimal(this.dataFormatDigitsDecimal),this.validateDataFormatDigitsPercent(this.dataFormatDigitsPercent),this.validateAxisLabelsStep(this.axisLabelsStep),this.validateTotals(this.totals),this.validateAxisTitlePosition(this.axisTitlePosition)}measureContentWidth(){var t;const i=null===(t=this.element.shadowRoot)||void 0===t?void 0:t.querySelectorAll("bn-chart-time-renderer");let e=0,s=!1;return null==i||i.forEach((t=>{var i,a,n;const r=parseFloat(null!==(n=null===(a=null===(i=t.shadowRoot)||void 0===i?void 0:i.querySelector("svg#drawCanvas"))||void 0===a?void 0:a.getAttribute("width"))&&void 0!==n?n:"");Number.isNaN(r)||(e=Math.max(e,r),s=!0)})),s?Math.max(Math.floor(e),this.element.scrollWidth):this.element.scrollWidth}measureContentHeight(){var t;const i=null===(t=this.element.shadowRoot)||void 0===t?void 0:t.querySelectorAll("bn-chart-time-renderer");let e=0,s=!1;return null==i||i.forEach((t=>{var i,a,n;const r=parseFloat(null!==(n=null===(a=null===(i=t.shadowRoot)||void 0===i?void 0:i.querySelector("svg#drawCanvas"))||void 0===a?void 0:a.getAttribute("height"))&&void 0!==n?n:"");Number.isNaN(r)||(e+=r,s=!0)})),s?Math.max(Math.floor(e),this.element.scrollHeight):this.element.scrollHeight}checkOverflow(){const t=W(this.element),i=this.measureContentWidth(),e=this.measureContentHeight(),s=t.width>0&&i>t.width+1,a=t.height>0&&e>t.height+1;if(!s&&!a)return void L(this.errors,null);const n=this.prepareVariances().some((t=>t.startsWith("dr"))),r="value"===F(this.unitScaling,this.pixelPerUnitGroupMap).kind,o=n&&"value"===F(this.percentageScaling,this.pixelPerUnitGroupMap).kind,{mode:l}=P(this.scale),h="auto"!==l&&"empty"!==l,c=[];a&&r&&c.push("unit-scaling"),a&&o&&c.push("percentage-scaling"),s&&h&&c.push("scale");const d=[];s&&d.push(`width (${Math.round(i)}px > ${Math.round(t.width)}px)`),a&&d.push(`height (${Math.round(e)}px > ${Math.round(t.height)}px)`),L(this.errors,`Chart exceeds available ${d.join(" and ")}. `+(c.length>0?`Adjust ${c.join(" / ")} or set to "auto".`:"Content does not fit even at minimum auto scaling; enlarge the container."),c.length>0)}componentDidRender(){K(this.element,"bn-chart-time-renderer");const t=this.updateBaseHeightBonus();t&&!this._autoScaleGuard&&e(this);const{mode:i}=P(this.scale);if("auto"!==i&&"empty"!==i)return this._autoScaleGuard=!1,void this.checkOverflow();if(this._autoScaleGuard)return this._autoScaleGuard=!1,this.checkOverflow(),void(t&&e(this));const a=this.element,{width:n}=W(a);if(n<=0)return void this.checkOverflow();this._lastObservedWidth=n;const r=this.componentStyle((t=>{var i;return(null===(i=t.global)||void 0===i?void 0:i.fontSizePx)||13.3333})),o=a.scrollWidth,l=this.appliedScaleFactor;if(o<=n+1)return this.errors.remove("AUTO_scale"),void this.checkOverflow();const h=Math.max(.3,l*(n-1)/o);Math.abs(h-l)<.01||(a.style.setProperty("--bn-font-size",r*h+"px"),"empty"===i?this.errors.addOrReplace({id:"AUTO_scale",type:"warning",message:"Auto-scaled chart by factor "+h.toFixed(3)}):this.errors.remove("AUTO_scale"),this._autoScaleGuard=!0,s((()=>{this.appliedScaleFactor=h}))),this.checkOverflow()}componentDidLoad(){this.layoutObserver=R(this.element,(()=>{if(this._autoScaleGuard)return;const{width:t}=W(this.element);t>0&&Math.abs(t-this._lastObservedWidth)>2&&(this._lastObservedWidth=t,e(this))})),requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(this._autoScaleGuard)return;const{width:t}=W(this.element);this._lastObservedWidth=t,e(this)}))})),this.settleParentHeight()}settleParentHeight(){const t=[150,400,1e3,2500],i=()=>{if(this._settleTimer=null,!this.element.isConnected)return;const{height:s}=W(this.element);s>0&&Math.abs(s-this._lastAppliedHeight)>8&&!this._autoScaleGuard&&e(this);const a=t.shift();void 0!==a&&(this._settleTimer=setTimeout(i,a))};this._settleTimer=setTimeout(i,t.shift())}connectedCallback(){this.bindTotalsDataset()}disconnectedCallback(){var t,i;null===(t=this.totalsDatasetUnsubscribe)||void 0===t||t.call(this),this.totalsDatasetUnsubscribe=null,this.totalsDatasetName="",null===(i=this.layoutObserver)||void 0===i||i.disconnect(),this.layoutObserver=null,null!=this._settleTimer&&(clearTimeout(this._settleTimer),this._settleTimer=null)}updateBaseHeightBonus(){var t,i;const e=this.prepareSegments();let s=0;if("value"===F(this.unitScaling,this.pixelPerUnitGroupMap).kind&&e.length>1&&0===e[0].length){const a=Array.from(null!==(i=null===(t=this.element.shadowRoot)||void 0===t?void 0:t.querySelectorAll("bn-chart-time-renderer"))&&void 0!==i?i:[]);s=function(t,i){let e=0;for(const s of i)s>0&&(e+=t-s);return Math.max(0,e)}(this.segmentShare(this._lastAppliedHeight,e.length),a.slice(1).map((t=>t.offsetHeight)))}const a=function(t,i){const e=i-t;return e<-1||e>8?i:t}(this._baseHeightBonus,s);return a!==this._baseHeightBonus&&(this._baseHeightBonus=a,!0)}segmentShare(t,i){const e=this.showMeasureScale?this.getEffectiveFontPx():0;return Math.max(0,t-e)/Math.max(1,i)}prepareDimension(t=!1){const i=W(this.element),e=this.prepareScenarios(),s=this.prepareSegments();this.canvasWidthSegmented=i.width/(e.length+this.prepareVariances().length||1),this._lastAppliedHeight=i.height;const a=this.segmentShare(i.height,s.length);return{width:this.canvasWidthSegmented,height:a+(t?this._baseHeightBonus:0)}}prepareScenarios(){var t,i,e,s;const a=this.resolveInherited("scenarios",this.scenarios);if(a.inherited)return this.errors.remove("AUTO_scenarios"),a.value.split(",").map((t=>t.trim()));if(c(a.value))return this.errors.remove("AUTO_scenarios"),[];const n="auto"===(null===(t=a.value)||void 0===t?void 0:t.trim().toLowerCase());return v(a.value)||n?(null===(e=null===(i=this.datasetMeta)||void 0===i?void 0:i.availableScenarios)||void 0===e?void 0:e.length)>0?(n||a.unresolved?this.errors.remove("AUTO_scenarios"):this.errors.addOrReplace({id:"AUTO_scenarios",type:"warning",message:"scenarios: not set, auto-detected: "+this.datasetMeta.availableScenarios.join(",")}),this.datasetMeta.availableScenarios):[]:(this.errors.remove("AUTO_scenarios"),null===(s=a.value)||void 0===s?void 0:s.split(",").map((t=>t.trim())))}hidesScenarios(){const t=this.resolveInherited("scenarios",this.scenarios);return!t.inherited&&c(t.value)}prepareSegments(){const t=this.hidesScenarios()?[]:[[]],i=new Map;for(const e of this.prepareVariances()){const s=new U(e),a=`${s.type}:${s.delta}`,n=this.scenarioSwitch&&s.isValid?i.get(a):void 0;if(n){n.push(e);continue}const r=[e];t.push(r),s.isValid&&i.set(a,r)}return t}prepareAxisTitlePosition(){var t;const i=null===(t=this.axisTitlePosition)||void 0===t?void 0:t.trim().toLowerCase();return"right"===i||"none"===i?i:"left"}prepareAvg(){return this.showOverlayAvg}prepareMedian(){return this.showOverlayMedian}prepareVariances(){const t=this.resolveInherited("variances",this.variances).value;return v(t)?[]:null==t?void 0:t.split(",").map((t=>t.trim()))}checkVarianceScenarios(t){const i="WARN_variances_scenario",e=this.prepareScenarios(),s=[];for(const i of t){const t=new U(i);if(t.isValid)for(const a of[t.base,t.delta])e.includes(a)||s.push(`'${i}' needs '${a}'`)}!this.hidesScenarios()&&e.length>0&&s.length>0?this.errors.addOrReplace({id:i,type:"warning",message:`variances: ${s.join(", ")}, which is not in scenarios (${e.join(", ")}). The variance has no values.`}):this.errors.remove(i)}prepareHideAxisLabels(t){return t>=1||!this.showCategories}prepareI18n(){const t=h,i=new Map(["no-data","date-format-short-year"].map((t=>[t,this.t(".".concat(t))]))),e=new Map(t.map((t=>[t,this.t("global.".concat(t))])));return new Map([...e.entries(),...i.entries(),...T(this.ruleSetConfig("user"))])}static describeScalingInput(t){return""===t?"not set":`invalid value "${t}"`}preparePixelPerUnit(){const i=F(this.unitScaling,this.pixelPerUnitGroupMap);return"value"===i.kind?(this.errors.remove("AUTO_unitScaling"),this.autoUnitWarningActive=!1,this.lastReportedUnitsPerEm=void 0,this.getEffectiveFontPx()/i.value):"auto"===i.kind?(this.errors.remove("AUTO_unitScaling"),this.autoUnitWarningActive=!1,this.lastReportedUnitsPerEm=void 0,0):(this.autoUnitWarningActive=!0,this.errors.addOrReplace({id:"AUTO_unitScaling",type:"warning",message:`unit-scaling: ${t.describeScalingInput(i.raw)}, auto-calculated to fit available space.`}),0)}preparePixelPerPercentage(){const i=F(this.percentageScaling,this.pixelPerUnitGroupMap);return"value"===i.kind?(this.errors.remove("AUTO_percentageScaling"),this.autoPctWarningActive=!1,this.lastReportedPpPerEm=void 0,100*this.getEffectiveFontPx()/i.value):"auto"===i.kind?(this.errors.remove("AUTO_percentageScaling"),this.autoPctWarningActive=!1,this.lastReportedPpPerEm=void 0,0):(this.autoPctWarningActive=!0,this.errors.addOrReplace({id:"AUTO_percentageScaling",type:"warning",message:`percentage-scaling: ${t.describeScalingInput(i.raw)}, auto-calculated to fit available space.`}),0)}prepareStyle(){const t=this.getEffectiveScaleFactor();return this.componentStyle((i=>{const e=i.global.fontSizePx*t;return{scaleFactors:{scenarioOffset:i["bn-chart-time"].scaleFactors.scenarioOffset,scenarioLabelToColumn:i["bn-chart-time"].scaleFactors.scenarioLabelToColumn,labelToColumn:i["bn-chart-time"].scaleFactors.labelToColumn,labelToAxis:i["bn-chart-time"].scaleFactors.labelToAxis,needleWidth:i["bn-chart-time"].scaleFactors.needleWidth,needleHeadWidth:i["bn-chart-time"].scaleFactors.needleHeadWidth,columnWidth:i["bn-chart-time"].scaleFactors.columnWidth,varianceAxisLineWidth:i["bn-chart-time"].scaleFactors.varianceAxisLineWidth,axisLineWidth:i["bn-chart-time"].scaleFactors.axisLineWidth,auxiliaryLineWidth:i["bn-chart-time"].scaleFactors.auxiliaryLineWidth,scenarioLineWidth:i["bn-chart-time"].scaleFactors.scenarioLineWidth,markerWidth:i["bn-chart-time"].scaleFactors.markerWidth,markerOffset:i["bn-chart-time"].scaleFactors.markerOffset,categoryWidth:i["bn-chart-time"].scaleFactors.categoryWidth,axisTickLength:i["bn-chart-time"].scaleFactors.axisTickLength},fontStyles:{font:`${e}px ${i.global.fontFamily}`,family:i.global.fontFamily,size:e,color:i.global.fontColor,background:i.global.fontBackgroundColor,leading:1.8},axisStyles:i["bn-chart-time"].axisStyles,barStyles:i["bn-chart-time"].barStyles,varianceStyles:i["bn-chart-time"].varianceStyles,stackColors:i["bn-chart-time"].stackColors,padding:i["bn-chart-time"].padding,pattern:null,locale:"de"}}))}prepareLeftSideOffset(t,i){if(this.syncSpaceLeft>-1)return this.syncSpaceLeft;const e="left"===this.prepareAxisTitlePosition()?[...this.prepareVariances(),this.chartTitle]:[];return C.getMaxWidthOfArrayItems([...e,...this.prepareScenarios()],t,i)}prepareChartTitle(t){return t>=1||this.hidesScenarios()?"":this.chartTitle}prepareDateInterval(){var t,i,e;const s="auto"===(null===(t=this.dateInterval)||void 0===t?void 0:t.trim().toLowerCase());return v(this.dateInterval)||s?(null===(i=this.datasetMeta)||void 0===i?void 0:i.suggestedDateInterval)?(s?this.errors.remove("AUTO_dateInterval"):this.errors.addOrReplace({id:"AUTO_dateInterval",type:"warning",message:"dateInterval: not set, auto-detected: "+this.datasetMeta.suggestedDateInterval}),V[this.datasetMeta.suggestedDateInterval.toUpperCase()]):s?V.AUTO:void 0:(this.errors.remove("AUTO_dateInterval"),V[null===(e=this.dateInterval)||void 0===e?void 0:e.toUpperCase()])}prepareIntervalSpanLimit(){const t=Number(this.intervalSpanLimit);return t>0?t:28}prepareAxisLabelsMode(){var t;return $[null===(t=this.axisLabelsMode)||void 0===t?void 0:t.toUpperCase().replace("-","_")]}prepareFilter(){return 0===this.filter.length?"":this.filter}getDataStructure(){return{ITimeChartDataRow:{setName:{type:"string",isOptional:!1,description:""},date:{type:"string",isOptional:!1,description:""},operation:{type:"string",isOptional:!1,description:""},rowGroup:{type:"string",isOptional:!1,description:""},rowGroupIndex:{type:"number",isOptional:!1,description:""},category:{type:"string",isOptional:!1,description:""},categoryIndex:{type:"number",isOptional:!1,description:""},subCategory:{type:"string",isOptional:!1,description:""},subCategoryIndex:{type:"number",isOptional:!1,description:""},columnGroup:{type:"string",isOptional:!1,description:""},columnGroupIndex:{type:"number",isOptional:!1,description:""},columnSubGroup:{type:"string",isOptional:!1,description:""},columnSubGroupIndex:{type:"number",isOptional:!1,description:""},ac1:{type:"number",isOptional:!1,description:""},ac2:{type:"number",isOptional:!1,description:""},ac3:{type:"number",isOptional:!1,description:""},ac4:{type:"number",isOptional:!1,description:""},pp1:{type:"number",isOptional:!1,description:""},pp2:{type:"number",isOptional:!1,description:""},pp3:{type:"number",isOptional:!1,description:""},pp4:{type:"number",isOptional:!1,description:""},fc1:{type:"number",isOptional:!1,description:""},fc2:{type:"number",isOptional:!1,description:""},fc3:{type:"number",isOptional:!1,description:""},fc4:{type:"number",isOptional:!1,description:""},pl1:{type:"number",isOptional:!1,description:""},pl2:{type:"number",isOptional:!1,description:""},pl3:{type:"number",isOptional:!1,description:""},pl4:{type:"number",isOptional:!1,description:""}}}}prepareMeasureScale(){return v(this.measureScale)?"GREATEST":["_","k","M","G","T","P","E","Z","Y","m","μ","n","p","P","f","a","z","y"].includes(this.measureScale.trim())||"LEAST"===this.measureScale.trim().toUpperCase()?this.measureScale.trim():"GREATEST"}prepareShowMeasureScale(t){return 0===t&&this.showMeasureScale}prepareMeasureUnit(){return""===this.measureUnit||null==this.measureUnit?"":this.measureUnit}prepareStackConfig(){if(v(this.stack))return this.errors.remove("WARN_stack_dimensions_scenarios"),this.errors.remove("WARN_stack_scenarios_max"),null;try{const t=JSON.parse(this.stack),i=t.by,e="WARN_stack_dimensions_scenarios",s="WARN_stack_scenarios_max",a=this.prepareScenarios();return i===B.DIMENSIONS&&a.length>1&&!this.scenarioSwitch?this.errors.addOrReplace({id:e,type:"warning",message:`stack by dimensions: only the first scenario "${a[0]}" is used, the rest (${a.slice(1).join(", ")}) are discarded.`}):this.errors.remove(e),i===B.SCENARIOS&&a.length>4?this.errors.addOrReplace({id:s,type:"warning",message:`stack by scenarios: at most four scenarios are stacked, the rest (${a.slice(4).join(", ")}) are discarded. Use stack by dimensions for more series.`}):this.errors.remove(s),{by:i,mode:t.mode||E.ABSOLUTE,order:t.order||z.DATASET,notation:"scenario"===t.notation?"scenario":"none",legend:["right","both","none"].includes(t.legend)?t.legend:"left",percentMark:!0===t.percentMark}}catch(t){return this.errors.remove("WARN_stack_dimensions_scenarios"),this.errors.remove("WARN_stack_scenarios_max"),null}}prepareLineFullWidth(){return this.lineFullWidth}prepareChartMode(){var t;const i=null===(t=this.chartMode)||void 0===t?void 0:t.toLowerCase();return"line"===i?G.LINE:"auto"===i?G.AUTO:G.BAR}prepareMaxBars(){return Math.floor(Number(this.maxBars)||28)}chartTemplate(t,i){const e=this.prepareI18n(),s=this.prepareStyle(),n=W(this.element).width,r=this.preparePixelPerUnit(),o=this.preparePixelPerPercentage(),l=this.prepareStackConfig(),h=0===t.length,c=this.hidesScenarios()?I(t):this.prepareScenarios(),d=h&&(null==l?void 0:l.by)===B.DIMENSIONS&&!this.scenarioSwitch?c.slice(0,1):c;return a("bn-chart-time-renderer",{tableName:this.datasetName,dataVersion:this.dataVersion,chartTitle:this.prepareChartTitle(i),scenarios:d,variances:t.length>0?t:[""],hideAxisLabels:this.prepareHideAxisLabels(i),pixelPerUnit:r,pixelPerPercentage:o,reportAutoScaling:this.handleAutoScalingReport,errors:this.errors,leftSideOffsetForHorizontalSync:this.prepareLeftSideOffset(e,s),styles:s,i18n:e,dateInterval:this.prepareDateInterval(),intervalSpanLimit:this.prepareIntervalSpanLimit(),axisLabelsMode:this.prepareAxisLabelsMode(),filter:this.prepareFilter(),"measure-scale":this.prepareMeasureScale(),"measure-unit":this.prepareMeasureUnit(),showOverlayAvg:this.prepareAvg(),showOverlayMedian:this.prepareMedian(),showMeasureScale:this.prepareShowMeasureScale(i),chartMode:this.prepareChartMode(),maxBars:this.prepareMaxBars(),stackConfig:l,lineFullWidth:this.prepareLineFullWidth(),dataFormatDigits:{percent:this.dataFormatDigitsPercent,decimal:this.dataFormatDigitsDecimal,percentSign:!1!==this.dataFormatPercentSign},axisLabelsStep:Math.max(1,Math.floor(Number(this.axisLabelsStep)||1)),scalingIndicator:Number(this.scalingIndicator)||0,totals:this.prepareTotals(),scenarioSwitch:this.scenarioSwitch,axisTitlePosition:this.prepareAxisTitlePosition(),containerWidth:n,parentDimensions:this.prepareDimension(h),ruleSetConfig:this.ruleSetConfig()})}async getBaseline(){return Q(this.element,"bn-chart-time-renderer")}async getLayoutState(t){var i,e,s,a;const n=null!==(i=null==t?void 0:t.detail)&&void 0!==i?i:"summary",r=H(this.element),o=this.getEffectiveScaleFactor(),l=Number.isFinite(o)&&o>0?o:1,h=this.componentStyle((t=>{var i;return(null===(i=t.global)||void 0===i?void 0:i.fontSizePx)||13.3333}))*l,c=this.prepareVariances(),d=Z(this.element,"bn-chart-time-renderer",this.prepareSegments().map((t=>t.length>0?t.join(","):"base")),r,n),u=null===(e=this.element.shadowRoot)||void 0===e?void 0:e.querySelector("bn-chart-time-renderer"),p={version:q,tag:this.element.localName,id:Y(this.element),slot:null!==(s=this.element.getAttribute("slot"))&&void 0!==s?s:void 0,rect:J(this.element,r),em:{fontSizePx:h,appliedScaleFactor:l},regions:d.regions,metadata:{title:this.chartTitle||void 0,scenarios:null!==(a=null==u?void 0:u.scenarios)&&void 0!==a?a:[],variances:c,barCount:d.barCount,chartMode:this.chartMode||void 0,hasNoData:0===d.barCount},diagnostics:X(this.element),scaling:this.resolveScalingInfo(h),baseline:d.baseline};return d.elements&&(p.elements=d.elements),p}resolveScalingInfo(t){var i,e;const s={},a=F(this.unitScaling,this.pixelPerUnitGroupMap);if("value"===a.kind)s.unitMode="fixed",s.unitsPerEm=a.value,s.unitPxPerUnit=t/a.value;else{s.unitMode="auto";const e=null===(i=this.lastAutoScalingReport)||void 0===i?void 0:i.unit;void 0!==e&&e>0&&(s.unitPxPerUnit=e,s.unitsPerEm=t/e)}const n=F(this.percentageScaling,this.pixelPerUnitGroupMap);if("value"===n.kind)s.percentageMode="fixed",s.percentagePointsPerEm=n.value,s.percentagePxPerPoint=t/n.value;else{s.percentageMode="auto";const i=null===(e=this.lastAutoScalingReport)||void 0===e?void 0:e.percentage;void 0!==i&&i>0&&(s.percentagePxPerPoint=i/100,s.percentagePointsPerEm=100*t/i)}return s}getEffectiveScaleFactor(){const{mode:t,factor:i}=P(this.scale);return"factor"===t?i:"auto"===t||"empty"===t?this.appliedScaleFactor:1}getEffectiveFontPx(){return this.componentStyle((t=>{var i;return(null===(i=t.global)||void 0===i?void 0:i.fontSizePx)||13.3333}))*this.getEffectiveScaleFactor()}getFontStyles(){const t=this.getEffectiveScaleFactor();return this.componentStyle((i=>{var e,s,a,n;const r=(null===(e=i.global)||void 0===e?void 0:e.fontSizePx)||13.3333;return{"--bn-font-family":(null===(s=i.global)||void 0===s?void 0:s.fontFamily)||"'Noto Sans', sans-serif","--bn-font-size":r*t+"px","--bn-font-color":(null===(a=i.global)||void 0===a?void 0:a.fontColor)||"#000000","--bn-font-background":(null===(n=i.global)||void 0===n?void 0:n.fontBackgroundColor)||"#ffffff"}}))}render(){this.checkVarianceScenarios(this.prepareVariances());const t=this.prepareSegments();0===t.length?this.errors.addOrReplace({id:"WARN_scenarios_none",type:"warning",message:"scenarios: none needs at least one variance, the chart is empty."}):this.errors.remove("WARN_scenarios_none");const i=this.getFontStyles();return a(n,{key:"baa11d12a8dc2e01a487b02bcd68902890ceb85a",style:i},a("div",{key:"40a33368366a59709c8a6c0354a6aca50445778f",class:"container"},t.map(this.chartTemplate)))}get element(){return this}static get watchers(){return{filter:[{validateFilter:0}],scenarios:[{validateScenario:0}],variances:[{validateVariances:0}],syncSpaceLeft:[{validateLeftSync:0}],unitScaling:[{validateUnitScaling:0}],percentageScaling:[{validatePercentageScaling:0}],dateInterval:[{validateDateInterval:0}],chartMode:[{validateChartMode:0}],maxBars:[{validateMaxBars:0}],stack:[{validateStack:0}],scale:[{validateScaling:0}],axisLabelsMode:[{validateAxisLabelsMode:0}],measureScale:[{validateMeasureScale:0}],dataFormatDigitsDecimal:[{validateDataFormatDigitsDecimal:0}],dataFormatDigitsPercent:[{validateDataFormatDigitsPercent:0}],totals:[{validateTotals:0}],axisLabelsStep:[{validateAxisLabelsStep:0}],axisTitlePosition:[{validateAxisTitlePosition:0}]}}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{display:inline-block;position:relative;overflow:hidden;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px);color:var(--bn-font-color, #000000)}.container{display:flex;flex-direction:column-reverse}.background-image{display:flex;flex-wrap:wrap;justify-content:flex-end}'}},[1,"bn-chart-time",{datasets:[513],selectedStyle:[513,"selected-style"],i18nNamespace:[513,"i18n-namespace"],ruleset:[513],chartTitle:[1,"chart-title"],filter:[1],scenarios:[1],variances:[1],syncSpaceLeft:[2,"sync-space-left"],unitScaling:[8,"unit-scaling"],percentageScaling:[8,"percentage-scaling"],dateInterval:[1,"date-interval"],chartMode:[1,"chart-mode"],maxBars:[2,"max-bars"],stack:[1],scale:[1],intervalSpanLimit:[2,"interval-span-limit"],axisLabelsMode:[1,"axis-labels-mode"],lineFullWidth:[4,"line-full-width"],showCategories:[4,"show-categories"],measureScale:[1,"measure-scale"],showMeasureScale:[4,"show-measure-scale"],showOverlayAvg:[4,"show-overlay-avg"],showOverlayMedian:[4,"show-overlay-median"],measureUnit:[1,"measure-unit"],dataFormatDigitsDecimal:[2,"data-format-digits-decimal"],dataFormatDigitsPercent:[2,"data-format-digits-percent"],dataFormatPercentSign:[4,"data-format-percent-sign"],axisLabelsStep:[2,"axis-labels-step"],scalingIndicator:[2,"scaling-indicator"],totals:[1],scenarioSwitch:[4,"scenario-switch"],axisTitlePosition:[1,"axis-title-position"],datasetName:[32],dataVersion:[32],datasetMeta:[32],appliedScaleFactor:[32],getBaseline:[64],getLayoutState:[64]},void 0,{filter:[{validateFilter:0}],scenarios:[{validateScenario:0}],variances:[{validateVariances:0}],syncSpaceLeft:[{validateLeftSync:0}],unitScaling:[{validateUnitScaling:0}],percentageScaling:[{validatePercentageScaling:0}],dateInterval:[{validateDateInterval:0}],chartMode:[{validateChartMode:0}],maxBars:[{validateMaxBars:0}],stack:[{validateStack:0}],scale:[{validateScaling:0}],axisLabelsMode:[{validateAxisLabelsMode:0}],measureScale:[{validateMeasureScale:0}],dataFormatDigitsDecimal:[{validateDataFormatDigitsDecimal:0}],dataFormatDigitsPercent:[{validateDataFormatDigitsPercent:0}],totals:[{validateTotals:0}],axisLabelsStep:[{validateAxisLabelsStep:0}],axisTitlePosition:[{validateAxisTitlePosition:0}]}]),et=it,st=function(){"undefined"!=typeof customElements&&["bn-chart-time","bn-chart-time-renderer"].forEach((t=>{switch(t){case"bn-chart-time":customElements.get(r(t))||customElements.define(r(t),it);break;case"bn-chart-time-renderer":customElements.get(r(t))||tt()}}))};export{et as BnChartTime,st as defineCustomElement}