@oicl/openbridge-webcomponents 2.1.0 → 2.1.1

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.
@@ -33709,24 +33709,36 @@ function getChartTooltipOptions(host) {
33709
33709
  }
33710
33710
  //#endregion
33711
33711
  //#region src/charthelpers/legend.ts
33712
+ function span(className, text = "") {
33713
+ const el = document.createElement("span");
33714
+ el.className = className;
33715
+ el.textContent = text;
33716
+ return el;
33717
+ }
33712
33718
  /**
33713
- * Generate HTML markup for a chart legend given legend items.
33714
- * @param legendItems - Array of legend item objects with fillStyle, label, value, and unit
33715
- * @returns HTML string for the legend
33719
+ * Fills a chart's legend with one row per item, replacing what was there.
33720
+ *
33721
+ * Labels, values, units and colours come from the consumer's data, which an
33722
+ * application often takes from a backend or from what a user typed. They are
33723
+ * written as text and as a single style value, never as markup: a label
33724
+ * containing HTML shows up as that literal text.
33725
+ *
33726
+ * @param container - The legend element to fill
33727
+ * @param items - The rows, in display order; an empty list clears the legend
33716
33728
  */
33717
- function generateLegendHTML(legendItems) {
33718
- return legendItems.map((item) => `
33719
- <div class="legend-item">
33720
- <span class="legend-group legend-group--label">
33721
- <span class="legend-color" style="background-color: ${item.fillStyle};"></span>
33722
- <span class="legend-label">${item.label}</span>
33723
- </span>
33724
- <span class="legend-group legend-group--value-unit">
33725
- <span class="legend-value">${item.value}</span>
33726
- <span class="legend-unit">${item.unit}</span>
33727
- </span>
33728
- </div>
33729
- `).join("");
33729
+ function renderLegend(container, items) {
33730
+ container.replaceChildren(...items.map((item) => {
33731
+ const swatch = span("legend-color");
33732
+ swatch.style.backgroundColor = item.fillStyle;
33733
+ const label = span("legend-group legend-group--label");
33734
+ label.append(swatch, span("legend-label", item.label));
33735
+ const valueUnit = span("legend-group legend-group--value-unit");
33736
+ valueUnit.append(span("legend-value", item.value), span("legend-unit", item.unit));
33737
+ const row = document.createElement("div");
33738
+ row.className = "legend-item";
33739
+ row.append(label, valueUnit);
33740
+ return row;
33741
+ }));
33730
33742
  }
33731
33743
  //#endregion
33732
33744
  //#region src/charthelpers/x-value.ts
@@ -37752,7 +37764,7 @@ var ObcChartLineBase = class extends i$4 {
37752
37764
  updateLegend() {
37753
37765
  if (!this.legend || !this.legendDiv || !this.chart) return;
37754
37766
  if (!this.chart.data.datasets || this.chart.data.datasets.length === 0) {
37755
- this.legendDiv.innerHTML = "";
37767
+ renderLegend(this.legendDiv, []);
37756
37768
  return;
37757
37769
  }
37758
37770
  try {
@@ -37768,10 +37780,7 @@ var ObcChartLineBase = class extends i$4 {
37768
37780
  unit: ""
37769
37781
  };
37770
37782
  }).filter((item) => item !== null);
37771
- if (legendItems.length > 0) {
37772
- const legendHTML = generateLegendHTML(legendItems);
37773
- this.legendDiv.innerHTML = legendHTML;
37774
- }
37783
+ if (legendItems.length > 0) renderLegend(this.legendDiv, legendItems);
37775
37784
  } catch (error) {
37776
37785
  console.debug("[chart-line-base] updateLegend: error generating legend HTML", error);
37777
37786
  }
@@ -68289,13 +68298,13 @@ var ObcDonutChart = class ObcDonutChart extends i$4 {
68289
68298
  const meta = this.chart.getDatasetMeta(0);
68290
68299
  if (!meta || !meta.controller) return;
68291
68300
  if (!this.data || this.data.length === 0) {
68292
- this.legendDiv.innerHTML = "";
68301
+ renderLegend(this.legendDiv, []);
68293
68302
  return;
68294
68303
  }
68295
68304
  const denominator = this.max > 0 ? this.max : this.total > 0 ? this.total : 1;
68296
68305
  const isPercentage = this.outerLabelUnit === "%";
68297
68306
  try {
68298
- const legendHTML = generateLegendHTML(this.data.map((item, i) => {
68307
+ const legendItems = this.data.map((item, i) => {
68299
68308
  const style = meta.controller.getStyle(i, false);
68300
68309
  const numericValue = formatChartNumber(item.value, denominator, isPercentage, this.outerLabelDecimalPlaces);
68301
68310
  const showUnit = this.showUnit && this.outerLabelUnit;
@@ -68307,8 +68316,8 @@ var ObcDonutChart = class ObcDonutChart extends i$4 {
68307
68316
  value,
68308
68317
  unit
68309
68318
  };
68310
- }));
68311
- this.legendDiv.innerHTML = legendHTML;
68319
+ });
68320
+ renderLegend(this.legendDiv, legendItems);
68312
68321
  } catch (error) {
68313
68322
  console.debug("[obc-donut-chart] updateLegend: error generating legend HTML", error);
68314
68323
  }
@@ -68752,13 +68761,13 @@ var ObcPieChart = class ObcPieChart extends i$4 {
68752
68761
  const meta = this.chart.getDatasetMeta(0);
68753
68762
  if (!meta || !meta.controller) return;
68754
68763
  if (!this.data || this.data.length === 0) {
68755
- this.legendDiv.innerHTML = "";
68764
+ renderLegend(this.legendDiv, []);
68756
68765
  return;
68757
68766
  }
68758
68767
  const denominator = this.total > 0 ? this.total : 1;
68759
68768
  const isPercentage = this.outerLabelUnit === "%";
68760
68769
  try {
68761
- const legendHTML = generateLegendHTML(this.data.map((item, i) => {
68770
+ const legendItems = this.data.map((item, i) => {
68762
68771
  const style = meta.controller.getStyle(i, false);
68763
68772
  const numericValue = formatChartNumber(item.value, denominator, isPercentage, this.outerLabelDecimalPlaces);
68764
68773
  const showUnit = this.showUnit && this.outerLabelUnit;
@@ -68770,8 +68779,8 @@ var ObcPieChart = class ObcPieChart extends i$4 {
68770
68779
  value,
68771
68780
  unit
68772
68781
  };
68773
- }));
68774
- this.legendDiv.innerHTML = legendHTML;
68782
+ });
68783
+ renderLegend(this.legendDiv, legendItems);
68775
68784
  } catch (error) {
68776
68785
  console.debug("[obc-pie-chart] updateLegend: error generating legend HTML", error);
68777
68786
  }
@@ -69142,13 +69151,13 @@ var ObcPolarChart = class ObcPolarChart extends i$4 {
69142
69151
  const meta = this.chart.getDatasetMeta(0);
69143
69152
  if (!meta || !meta.controller) return;
69144
69153
  if (!this.data || this.data.length === 0) {
69145
- this.legendDiv.innerHTML = "";
69154
+ renderLegend(this.legendDiv, []);
69146
69155
  return;
69147
69156
  }
69148
69157
  const denominator = this.showSectorLabels ? 1 : 360;
69149
69158
  const isPercentage = this.outerLabelUnit === "%";
69150
69159
  try {
69151
- const legendHTML = generateLegendHTML(this.data.map((item, i) => {
69160
+ const legendItems = this.data.map((item, i) => {
69152
69161
  const style = meta.controller.getStyle(i, false);
69153
69162
  let label;
69154
69163
  let valueToFormat;
@@ -69169,8 +69178,8 @@ var ObcPolarChart = class ObcPolarChart extends i$4 {
69169
69178
  value,
69170
69179
  unit
69171
69180
  };
69172
- }));
69173
- this.legendDiv.innerHTML = legendHTML;
69181
+ });
69182
+ renderLegend(this.legendDiv, legendItems);
69174
69183
  } catch (error) {
69175
69184
  console.debug("[obc-polar-chart] updateLegend: error generating legend HTML", error);
69176
69185
  }
@@ -69465,20 +69474,20 @@ var ObcRadialBarChart = class ObcRadialBarChart extends i$4 {
69465
69474
  updateLegend() {
69466
69475
  if (!this.legend || !this.legendDiv || !this.chart) return;
69467
69476
  if (!this.data || this.data.length === 0) {
69468
- this.legendDiv.innerHTML = "";
69477
+ renderLegend(this.legendDiv, []);
69469
69478
  return;
69470
69479
  }
69471
69480
  try {
69472
69481
  const chartColors = getChartColorsOrDefault(this, this.colors, this.priority === Priority.enhanced ? CHART_SECTOR_ENHANCED_COLORS : CHART_SECTOR_DEFAULT_COLORS);
69473
- const legendHTML = generateLegendHTML(this.data.map((value, i) => {
69482
+ const legendItems = this.data.map((value, i) => {
69474
69483
  return {
69475
69484
  fillStyle: chartColors[i % chartColors.length] ?? (this.priority === Priority.enhanced ? CHART_SECTOR_ENHANCED_COLORS[0] : CHART_SECTOR_DEFAULT_COLORS[0]),
69476
69485
  label: `Ring ${i + 1}`,
69477
69486
  value: value.toString(),
69478
69487
  unit: ""
69479
69488
  };
69480
- }));
69481
- this.legendDiv.innerHTML = legendHTML;
69489
+ });
69490
+ renderLegend(this.legendDiv, legendItems);
69482
69491
  } catch (error) {
69483
69492
  console.debug("[obc-radial-bar-chart] updateLegend: error generating legend HTML", error);
69484
69493
  }