@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.
@@ -5,8 +5,8 @@ import { ObcPalette, PaletteController, currentPalette, observeThemeChanges } fr
5
5
  import { calculateSumTotal, createArcOuterLabelPlugin } from "./outer-labels.js";
6
6
  import { calculateRectangularChartLayout } from "./rectangular-chart-layout.js";
7
7
  import { getChartTooltipOptions } from "./tooltip.js";
8
- import { generateLegendHTML } from "./legend.js";
8
+ import { generateLegendHTML, renderLegend } from "./legend.js";
9
9
  import { XValueMode, formatXValue, normalizeXValue } from "./x-value.js";
10
10
  import { observeLabelThreshold } from "./label-threshold.js";
11
11
  import { formatRangeValue, measureRangeLabelGutters, rangeLabelFontString, rangeLabelLineHeight, yRangeLabelValues } from "./range-labels.js";
12
- export { CENTER_READOUT_CONFIG, CHART_AREA_BACKGROUND_COLOR_VAR, CHART_DIMENSIONS, CHART_SECTOR_DEFAULT_COLORS, CHART_SECTOR_ENHANCED_COLORS, LINE_GRAPH_GRID_CONFIG, LINE_GRAPH_LABEL_CONFIG, OUTER_LABEL_CONFIG, ObcPalette, PaletteController, RECTANGULAR_CHART_DIMENSIONS, TOOLTIP_CONFIG, XValueMode, applyAlphaToColor, calculateChartPaddingAndLabels, calculateFixedHeightChartLayout, calculateRectangularChartLayout, calculateSumTotal, createArcOuterLabelPlugin, currentPalette, formatChartNumber, formatRangeValue, formatSingleLabel, formatXValue, generateLegendHTML, getChartColorsOrDefault, getChartTooltipOptions, getCssVariableValue, measureRangeLabelGutters, normalizeXValue, observeLabelThreshold, observeThemeChanges, rangeLabelFontString, rangeLabelLineHeight, yRangeLabelValues };
12
+ export { CENTER_READOUT_CONFIG, CHART_AREA_BACKGROUND_COLOR_VAR, CHART_DIMENSIONS, CHART_SECTOR_DEFAULT_COLORS, CHART_SECTOR_ENHANCED_COLORS, LINE_GRAPH_GRID_CONFIG, LINE_GRAPH_LABEL_CONFIG, OUTER_LABEL_CONFIG, ObcPalette, PaletteController, RECTANGULAR_CHART_DIMENSIONS, TOOLTIP_CONFIG, XValueMode, applyAlphaToColor, calculateChartPaddingAndLabels, calculateFixedHeightChartLayout, calculateRectangularChartLayout, calculateSumTotal, createArcOuterLabelPlugin, currentPalette, formatChartNumber, formatRangeValue, formatSingleLabel, formatXValue, generateLegendHTML, getChartColorsOrDefault, getChartTooltipOptions, getCssVariableValue, measureRangeLabelGutters, normalizeXValue, observeLabelThreshold, observeThemeChanges, rangeLabelFontString, rangeLabelLineHeight, renderLegend, yRangeLabelValues };
@@ -1,12 +1,29 @@
1
- /**
2
- * Generate HTML markup for a chart legend given legend items.
3
- * @param legendItems - Array of legend item objects with fillStyle, label, value, and unit
4
- * @returns HTML string for the legend
5
- */
6
- export declare function generateLegendHTML(legendItems: Array<{
1
+ /** One row of a chart legend. */
2
+ export interface LegendItem {
3
+ /** Swatch colour. A value that is not a CSS colour leaves the swatch unpainted. */
7
4
  fillStyle: string;
8
5
  label: string;
9
6
  value: string;
10
7
  unit: string;
11
- }>): string;
8
+ }
9
+ /**
10
+ * Fills a chart's legend with one row per item, replacing what was there.
11
+ *
12
+ * Labels, values, units and colours come from the consumer's data, which an
13
+ * application often takes from a backend or from what a user typed. They are
14
+ * written as text and as a single style value, never as markup: a label
15
+ * containing HTML shows up as that literal text.
16
+ *
17
+ * @param container - The legend element to fill
18
+ * @param items - The rows, in display order; an empty list clears the legend
19
+ */
20
+ export declare function renderLegend(container: HTMLElement, items: readonly LegendItem[]): void;
21
+ /**
22
+ * The legend rows as an HTML string, with every value escaped.
23
+ *
24
+ * @deprecated Use `renderLegend()`, which fills the legend element itself.
25
+ * @param legendItems - The rows, in display order
26
+ * @returns The rows' markup
27
+ */
28
+ export declare function generateLegendHTML(legendItems: readonly LegendItem[]): string;
12
29
  //# sourceMappingURL=legend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/charthelpers/legend.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,KAAK,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,GACD,MAAM,CAiBR"}
1
+ {"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/charthelpers/legend.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,MAAM,WAAW,UAAU;IACzB,mFAAmF;IACnF,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AASD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,SAAS,UAAU,EAAE,GAC3B,IAAI,CAqBN;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,GAAG,MAAM,CAK7E"}
@@ -1,24 +1,48 @@
1
1
  //#region src/charthelpers/legend.ts
2
+ function span(className, text = "") {
3
+ const el = document.createElement("span");
4
+ el.className = className;
5
+ el.textContent = text;
6
+ return el;
7
+ }
8
+ /**
9
+ * Fills a chart's legend with one row per item, replacing what was there.
10
+ *
11
+ * Labels, values, units and colours come from the consumer's data, which an
12
+ * application often takes from a backend or from what a user typed. They are
13
+ * written as text and as a single style value, never as markup: a label
14
+ * containing HTML shows up as that literal text.
15
+ *
16
+ * @param container - The legend element to fill
17
+ * @param items - The rows, in display order; an empty list clears the legend
18
+ */
19
+ function renderLegend(container, items) {
20
+ container.replaceChildren(...items.map((item) => {
21
+ const swatch = span("legend-color");
22
+ swatch.style.backgroundColor = item.fillStyle;
23
+ const label = span("legend-group legend-group--label");
24
+ label.append(swatch, span("legend-label", item.label));
25
+ const valueUnit = span("legend-group legend-group--value-unit");
26
+ valueUnit.append(span("legend-value", item.value), span("legend-unit", item.unit));
27
+ const row = document.createElement("div");
28
+ row.className = "legend-item";
29
+ row.append(label, valueUnit);
30
+ return row;
31
+ }));
32
+ }
2
33
  /**
3
- * Generate HTML markup for a chart legend given legend items.
4
- * @param legendItems - Array of legend item objects with fillStyle, label, value, and unit
5
- * @returns HTML string for the legend
34
+ * The legend rows as an HTML string, with every value escaped.
35
+ *
36
+ * @deprecated Use `renderLegend()`, which fills the legend element itself.
37
+ * @param legendItems - The rows, in display order
38
+ * @returns The rows' markup
6
39
  */
7
40
  function generateLegendHTML(legendItems) {
8
- return legendItems.map((item) => `
9
- <div class="legend-item">
10
- <span class="legend-group legend-group--label">
11
- <span class="legend-color" style="background-color: ${item.fillStyle};"></span>
12
- <span class="legend-label">${item.label}</span>
13
- </span>
14
- <span class="legend-group legend-group--value-unit">
15
- <span class="legend-value">${item.value}</span>
16
- <span class="legend-unit">${item.unit}</span>
17
- </span>
18
- </div>
19
- `).join("");
41
+ const holder = document.createElement("div");
42
+ renderLegend(holder, legendItems);
43
+ return holder.innerHTML;
20
44
  }
21
45
  //#endregion
22
- export { generateLegendHTML };
46
+ export { generateLegendHTML, renderLegend };
23
47
 
24
48
  //# sourceMappingURL=legend.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"legend.js","names":[],"sources":["../../src/charthelpers/legend.ts"],"sourcesContent":["/**\n * Generate HTML markup for a chart legend given legend items.\n * @param legendItems - Array of legend item objects with fillStyle, label, value, and unit\n * @returns HTML string for the legend\n */\nexport function generateLegendHTML(\n legendItems: Array<{\n fillStyle: string;\n label: string;\n value: string;\n unit: string;\n }>\n): string {\n return legendItems\n .map(\n (item) => `\n <div class=\"legend-item\">\n <span class=\"legend-group legend-group--label\">\n <span class=\"legend-color\" style=\"background-color: ${item.fillStyle};\"></span>\n <span class=\"legend-label\">${item.label}</span>\n </span>\n <span class=\"legend-group legend-group--value-unit\">\n <span class=\"legend-value\">${item.value}</span>\n <span class=\"legend-unit\">${item.unit}</span>\n </span>\n </div>\n `\n )\n .join('');\n}\n"],"mappings":";;;;;;AAKA,SAAgB,mBACd,aAMQ;CACR,OAAO,YACJ,KACE,SAAS;;;kEAGkD,KAAK,UAAU;yCACxC,KAAK,MAAM;;;yCAGX,KAAK,MAAM;wCACZ,KAAK,KAAK;;;OAI9C,CAAC,CACA,KAAK,EAAE;AACZ"}
1
+ {"version":3,"file":"legend.js","names":[],"sources":["../../src/charthelpers/legend.ts"],"sourcesContent":["/** One row of a chart legend. */\nexport interface LegendItem {\n /** Swatch colour. A value that is not a CSS colour leaves the swatch unpainted. */\n fillStyle: string;\n label: string;\n value: string;\n unit: string;\n}\n\nfunction span(className: string, text = ''): HTMLSpanElement {\n const el = document.createElement('span');\n el.className = className;\n el.textContent = text;\n return el;\n}\n\n/**\n * Fills a chart's legend with one row per item, replacing what was there.\n *\n * Labels, values, units and colours come from the consumer's data, which an\n * application often takes from a backend or from what a user typed. They are\n * written as text and as a single style value, never as markup: a label\n * containing HTML shows up as that literal text.\n *\n * @param container - The legend element to fill\n * @param items - The rows, in display order; an empty list clears the legend\n */\nexport function renderLegend(\n container: HTMLElement,\n items: readonly LegendItem[]\n): void {\n container.replaceChildren(\n ...items.map((item) => {\n const swatch = span('legend-color');\n swatch.style.backgroundColor = item.fillStyle;\n\n const label = span('legend-group legend-group--label');\n label.append(swatch, span('legend-label', item.label));\n\n const valueUnit = span('legend-group legend-group--value-unit');\n valueUnit.append(\n span('legend-value', item.value),\n span('legend-unit', item.unit)\n );\n\n const row = document.createElement('div');\n row.className = 'legend-item';\n row.append(label, valueUnit);\n return row;\n })\n );\n}\n\n/**\n * The legend rows as an HTML string, with every value escaped.\n *\n * @deprecated Use `renderLegend()`, which fills the legend element itself.\n * @param legendItems - The rows, in display order\n * @returns The rows' markup\n */\nexport function generateLegendHTML(legendItems: readonly LegendItem[]): string {\n const holder = document.createElement('div');\n renderLegend(holder, legendItems);\n // A read, not a write: serialising the nodes escapes the text they hold.\n return holder.innerHTML;\n}\n"],"mappings":";AASA,SAAS,KAAK,WAAmB,OAAO,IAAqB;CAC3D,MAAM,KAAK,SAAS,cAAc,MAAM;CACxC,GAAG,YAAY;CACf,GAAG,cAAc;CACjB,OAAO;AACT;;;;;;;;;;;;AAaA,SAAgB,aACd,WACA,OACM;CACN,UAAU,gBACR,GAAG,MAAM,KAAK,SAAS;EACrB,MAAM,SAAS,KAAK,cAAc;EAClC,OAAO,MAAM,kBAAkB,KAAK;EAEpC,MAAM,QAAQ,KAAK,kCAAkC;EACrD,MAAM,OAAO,QAAQ,KAAK,gBAAgB,KAAK,KAAK,CAAC;EAErD,MAAM,YAAY,KAAK,uCAAuC;EAC9D,UAAU,OACR,KAAK,gBAAgB,KAAK,KAAK,GAC/B,KAAK,eAAe,KAAK,IAAI,CAC/B;EAEA,MAAM,MAAM,SAAS,cAAc,KAAK;EACxC,IAAI,YAAY;EAChB,IAAI,OAAO,OAAO,SAAS;EAC3B,OAAO;CACT,CAAC,CACH;AACF;;;;;;;;AASA,SAAgB,mBAAmB,aAA4C;CAC7E,MAAM,SAAS,SAAS,cAAc,KAAK;CAC3C,aAAa,QAAQ,WAAW;CAEhC,OAAO,OAAO;AAChB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oicl/openbridge-webcomponents",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",