@fusion.dev/helix-headless 0.181.1 → 0.182.0

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.
@@ -6947,7 +6947,7 @@
6947
6947
  "declarations": [
6948
6948
  {
6949
6949
  "kind": "class",
6950
- "description": "Every bar is measured from zero, and no property changes the baseline,\nbecause a bar's length is its value. To show the differences between values,\nuse a line chart.\n\nThe labels are HTML beside the drawing. An `<svg>` that fills its box scales\nthe text inside it: the same `font-size` renders at 10px in a narrow chart\nand 43px in a wide one, and SVG has no setting that keeps text at one size\nthe way `vector-effect` does for strokes.\n\nThe table is the accessible representation, and the drawing is hidden from\nscreen readers, so they get the numbers themselves. The `summary` part names\nthe chart, from `label` or the table's caption, and gives each series' highest\nreading.\n\n**The plot is read by key.** It takes focus, named by `label` or the caption.\nThe arrows along the categories move from one to the next, which is left and\nright for columns and up and down for `orientation=\"horizontal\"`. Home and\nEnd go to the first and the last, and the other pair of arrows moves among\nthe series of a category. The tooltip follows, the `live` part says the\nreading in words, and Escape puts the tooltip away.\n\nThe component writes the custom properties below with numbers it computes,\nand the stylesheet that draws the chart reads them. Do not set them yourself.\n\n**A tap shows the reading under it**, and keeps it until a tap lands\nelsewhere. `helix-reading-change` says each move of the reading, by pointer,\ntap or key, and `helix-reading-press` says a reading was clicked, tapped, or\npressed with Enter or Space, for a page that opens what a reading stands for.\n\n**`data` takes the readings as data** where the page has no table to point\n`for` at, in a table's shape: the column headings, then one row per reading\nwith its label first. A table is still the better source where the page can\nshow one, since it reads before any script runs.\n\n**A chart with nothing to draw says so.** A table with no readings shows\n`empty-text`, \"No readings\", in the plot, and `loading` shows `loading-text`\nthere until readings arrive. The `empty` and `loading` slots take markup in\ntheir place, such as a link to add the first reading.\n\n**Keyboard.** The plot is one tab stop.\n\n| Key | What it does |\n|---|---|\n| Tab | Moves focus to the plot and shows the first reading. |\n| Right, Left | Moves to the next or the previous reading. On a right-to-left page, Left moves to the next. |\n| Down, Up | Moves among the series of the reading. With one series, moves to the next or the previous reading. |\n| Down, Up under `orientation=\"horizontal\"` | Moves to the next or the previous reading, and Right and Left move among the series. |\n| Home, End | Moves to the first or the last reading. |\n| Page Down, Page Up | Moves a tenth of the readings on or back. |\n| Enter, Space | Presses the reading shown, which sends `helix-reading-press`. |\n| Escape | Puts the reading and its tooltip away. |",
6950
+ "description": "Every bar is measured from zero, and no property changes the baseline,\nbecause a bar's length is its value. To show the differences between values,\nuse a line chart.\n\nThe labels are HTML beside the drawing. An `<svg>` that fills its box scales\nthe text inside it: the same `font-size` renders at 10px in a narrow chart\nand 43px in a wide one, and SVG has no setting that keeps text at one size\nthe way `vector-effect` does for strokes.\n\nThe table is the accessible representation, and the drawing is hidden from\nscreen readers, so they get the numbers themselves. The `summary` part names\nthe chart, from `label` or the table's caption, and gives each series' highest\nreading.\n\n**The plot is read by key.** It takes focus, named by `label` or the caption.\nThe arrows along the categories move from one to the next, which is left and\nright for columns and up and down for `orientation=\"horizontal\"`. Home and\nEnd go to the first and the last, and the other pair of arrows moves among\nthe series of a category. The tooltip follows, the `live` part says the\nreading in words, and Escape puts the tooltip away.\n\nThe component writes the custom properties below with numbers it computes,\nand the stylesheet that draws the chart reads them. Do not set them yourself.\n\n**A tap shows the reading under it**, and keeps it until a tap lands\nelsewhere. `helix-reading-change` says each move of the reading, by pointer,\ntap or key, and `helix-reading-press` says a reading was clicked, tapped, or\npressed with Enter or Space, for a page that opens what a reading stands for.\n\n**A cell's `data-tone` colors its own bar**, such as `data-tone=\"primary\"`\non the one reading a chart is about, so one column of numbers can single\na bar out without a second column to color it. Without one, a bar takes\nits series' color.\n\n**`data` takes the readings as data** where the page has no table to point\n`for` at, in a table's shape: the column headings, then one row per reading\nwith its label first. A table is still the better source where the page can\nshow one, since it reads before any script runs.\n\n**A chart with nothing to draw says so.** A table with no readings shows\n`empty-text`, \"No readings\", in the plot, and `loading` shows `loading-text`\nthere until readings arrive. The `empty` and `loading` slots take markup in\ntheir place, such as a link to add the first reading.\n\n**Keyboard.** The plot is one tab stop.\n\n| Key | What it does |\n|---|---|\n| Tab | Moves focus to the plot and shows the first reading. |\n| Right, Left | Moves to the next or the previous reading. On a right-to-left page, Left moves to the next. |\n| Down, Up | Moves among the series of the reading. With one series, moves to the next or the previous reading. |\n| Down, Up under `orientation=\"horizontal\"` | Moves to the next or the previous reading, and Right and Left move among the series. |\n| Home, End | Moves to the first or the last reading. |\n| Page Down, Page Up | Moves a tenth of the readings on or back. |\n| Enter, Space | Presses the reading shown, which sends `helix-reading-press`. |\n| Escape | Puts the reading and its tooltip away. |",
6951
6951
  "name": "HelixHeadlessBarChart",
6952
6952
  "cssProperties": [
6953
6953
  {
@@ -6958,6 +6958,34 @@
6958
6958
  "description": "The color of the secondary axis, when one series is on it. The chart sets it from that series' `--chart-series-*` property, so the axis is drawn in whatever color that property resolves to.",
6959
6959
  "name": "--bar-chart-secondary"
6960
6960
  },
6961
+ {
6962
+ "description": "The color of a bar whose cell says `data-tone=\"accent\"`.",
6963
+ "name": "--bar-chart-tone-accent"
6964
+ },
6965
+ {
6966
+ "description": "The color of a bar whose cell says `data-tone=\"danger\"`.",
6967
+ "name": "--bar-chart-tone-danger"
6968
+ },
6969
+ {
6970
+ "description": "The color of a bar whose cell says `data-tone=\"info\"`.",
6971
+ "name": "--bar-chart-tone-info"
6972
+ },
6973
+ {
6974
+ "description": "The color of a bar whose cell says `data-tone=\"muted\"`.",
6975
+ "name": "--bar-chart-tone-muted"
6976
+ },
6977
+ {
6978
+ "description": "The color of a bar whose cell says `data-tone=\"primary\"`. A tone with no property of its own falls back to the bar's series color, and the same holds for a name you define.",
6979
+ "name": "--bar-chart-tone-primary"
6980
+ },
6981
+ {
6982
+ "description": "The color of a bar whose cell says `data-tone=\"success\"`.",
6983
+ "name": "--bar-chart-tone-success"
6984
+ },
6985
+ {
6986
+ "description": "The color of a bar whose cell says `data-tone=\"warning\"`.",
6987
+ "name": "--bar-chart-tone-warning"
6988
+ },
6961
6989
  {
6962
6990
  "description": "The gradient for a bar, named per bar so the styled tier can use it as the `fill`. It is always drawn, and used only when `wash=\"gradient\"` is set.",
6963
6991
  "name": "--chart-bar-wash"
@@ -7368,7 +7396,7 @@
7368
7396
  {
7369
7397
  "name": "bar",
7370
7398
  "type": {
7371
- "text": "(\n value: number,\n index: number,\n depth: number,\n tone: number,\n scale: (value: number) => number,\n from?: number,\n end?: StackEnd,\n ) => TemplateResult"
7399
+ "text": "(\n value: number,\n index: number,\n depth: number,\n tone: number,\n scale: (value: number) => number,\n from?: number,\n end?: StackEnd,\n named?: string,\n ) => TemplateResult"
7372
7400
  }
7373
7401
  }
7374
7402
  ],
@@ -200075,6 +200103,6 @@
200075
200103
  ],
200076
200104
  "helix": {
200077
200105
  "package": "@fusion.dev/helix-headless",
200078
- "version": "0.181.1"
200106
+ "version": "0.182.0"
200079
200107
  }
200080
200108
  }
@@ -35,6 +35,11 @@ declare const HelixHeadlessBarChart_base: typeof HelixElement & (new (...args: a
35
35
  * tap or key, and `helix-reading-press` says a reading was clicked, tapped, or
36
36
  * pressed with Enter or Space, for a page that opens what a reading stands for.
37
37
  *
38
+ * **A cell's `data-tone` colors its own bar**, such as `data-tone="primary"`
39
+ * on the one reading a chart is about, so one column of numbers can single
40
+ * a bar out without a second column to color it. Without one, a bar takes
41
+ * its series' color.
42
+ *
38
43
  * **`data` takes the readings as data** where the page has no table to point
39
44
  * `for` at, in a table's shape: the column headings, then one row per reading
40
45
  * with its label first. A table is still the better source where the page can
@@ -111,6 +116,13 @@ declare const HelixHeadlessBarChart_base: typeof HelixElement & (new (...args: a
111
116
  *
112
117
  * @cssproperty --bar-chart-axis - The width of an axis, in `ch`, set from the widest number on it. The chart sets it on the axis itself, and only when the categories run along the bottom. In a horizontal chart the axis is a row, one line high.
113
118
  * @cssproperty --bar-chart-secondary - The color of the secondary axis, when one series is on it. The chart sets it from that series' `--chart-series-*` property, so the axis is drawn in whatever color that property resolves to.
119
+ * @cssproperty --bar-chart-tone-accent - The color of a bar whose cell says `data-tone="accent"`.
120
+ * @cssproperty --bar-chart-tone-danger - The color of a bar whose cell says `data-tone="danger"`.
121
+ * @cssproperty --bar-chart-tone-info - The color of a bar whose cell says `data-tone="info"`.
122
+ * @cssproperty --bar-chart-tone-muted - The color of a bar whose cell says `data-tone="muted"`.
123
+ * @cssproperty --bar-chart-tone-primary - The color of a bar whose cell says `data-tone="primary"`. A tone with no property of its own falls back to the bar's series color, and the same holds for a name you define.
124
+ * @cssproperty --bar-chart-tone-success - The color of a bar whose cell says `data-tone="success"`.
125
+ * @cssproperty --bar-chart-tone-warning - The color of a bar whose cell says `data-tone="warning"`.
114
126
  * @cssproperty --chart-bar-wash - The gradient for a bar, named per bar so the styled
115
127
  * tier can use it as the `fill`. It is always drawn, and used only when
116
128
  * `wash="gradient"` is set.
@@ -9,6 +9,7 @@ import { html, nothing, svg } from 'lit';
9
9
  import { property } from 'lit/decorators.js';
10
10
  import { stackEnds, stackedReadings, stackFarEnds, stackSpans } from '../stack.js';
11
11
  import '../../tooltip/index.js';
12
+ const toned = (tone) => tone && /^[a-z][a-z0-9-]*$/.test(tone) ? tone : undefined;
12
13
  let HelixHeadlessBarChart = class HelixHeadlessBarChart extends MixinChartStatus(MixinChartSource(HelixElement)) {
13
14
  constructor() {
14
15
  super(...arguments);
@@ -112,18 +113,23 @@ let HelixHeadlessBarChart = class HelixHeadlessBarChart extends MixinChartStatus
112
113
  const stride = (slot * 0.72) / Math.max(abreast, 1);
113
114
  const gap = abreast > 1 ? stride * 0.08 : 0;
114
115
  const thickness = stride - gap;
115
- const bar = (value, index, depth, tone, scale, from, end) => {
116
+ const bar = (value, index, depth, tone, scale, from, end, named) => {
116
117
  const at = scale(value);
117
118
  const base = from === undefined ? floor : scale(from);
118
119
  const along = Math.min(base, at);
119
120
  const size = Math.abs(base - at);
120
121
  const across = index * slot + slot * 0.14 + depth * stride + gap / 2;
122
+ const ink = toned(named);
123
+ const paint = ink
124
+ ? `--chart-series: var(--bar-chart-tone-${ink}, var(--chart-series-${seriesIndex(tone)})); --chart-bar-wash: url(#helix-bar-wash-tone-${ink})`
125
+ : `--chart-series: var(--chart-series-${seriesIndex(tone)}); --chart-bar-wash: url(#helix-bar-wash-${seriesIndex(tone)})`;
121
126
  return sideways
122
127
  ? svg `<rect
123
128
  data-end=${end ?? nothing}
124
129
  data-series=${seriesIndex(tone)}
130
+ data-tone=${ink ?? nothing}
125
131
  height=${thickness}
126
- style="--chart-series: var(--chart-series-${seriesIndex(tone)}); --chart-bar-wash: url(#helix-bar-wash-${seriesIndex(tone)})"
132
+ style=${paint}
127
133
  part="bar${end ? ' bar-end' : ''}"
128
134
  width=${size}
129
135
  x=${along}
@@ -132,8 +138,9 @@ let HelixHeadlessBarChart = class HelixHeadlessBarChart extends MixinChartStatus
132
138
  : svg `<rect
133
139
  data-end=${end ?? nothing}
134
140
  data-series=${seriesIndex(tone)}
141
+ data-tone=${ink ?? nothing}
135
142
  height=${size}
136
- style="--chart-series: var(--chart-series-${seriesIndex(tone)}); --chart-bar-wash: url(#helix-bar-wash-${seriesIndex(tone)})"
143
+ style=${paint}
137
144
  part="bar${end ? ' bar-end' : ''}"
138
145
  width=${thickness}
139
146
  x=${across}
@@ -168,6 +175,19 @@ let HelixHeadlessBarChart = class HelixHeadlessBarChart extends MixinChartStatus
168
175
  <stop offset="0" part="bar-wash-start" />
169
176
  <stop offset="1" part="bar-wash-end" />
170
177
  </linearGradient>`)}
178
+ ${[...new Set(series.flatMap((one) => one.points.map((point) => toned(point.tone))))]
179
+ .filter((ink) => ink !== undefined)
180
+ .map((ink) => svg `<linearGradient
181
+ id="helix-bar-wash-tone-${ink}"
182
+ style="--chart-series: var(--bar-chart-tone-${ink}, var(--chart-series-1))"
183
+ x1="0"
184
+ x2=${sideways ? '1' : '0'}
185
+ y1="0"
186
+ y2=${sideways ? '0' : '1'}
187
+ >
188
+ <stop offset="0" part="bar-wash-start" />
189
+ <stop offset="1" part="bar-wash-end" />
190
+ </linearGradient>`)}
171
191
  </defs>`}
172
192
  ${this.renderGridlines(y, domain, sideways, categories.length)}
173
193
  ${sideways
@@ -184,7 +204,7 @@ let HelixHeadlessBarChart = class HelixHeadlessBarChart extends MixinChartStatus
184
204
  const point = slots[index];
185
205
  return point === undefined
186
206
  ? nothing
187
- : bar(point.value, index, depth, tone, against(one));
207
+ : bar(point.value, index, depth, tone, against(one), undefined, undefined, point.tone);
188
208
  })}
189
209
  </g>`)}
190
210
  ${series.map((one) => lined.has(seriesKey(one.name)) && this.showsSeries(one.name)
@@ -201,9 +221,11 @@ let HelixHeadlessBarChart = class HelixHeadlessBarChart extends MixinChartStatus
201
221
  const values = mine.map(({ slots }) => slots[index]?.value);
202
222
  const spans = stackSpans(values);
203
223
  const ends = stackFarEnds(values);
204
- return mine.flatMap(({ tone }, place) => {
224
+ return mine.flatMap(({ slots, tone }, place) => {
205
225
  const span = spans[place];
206
- return span === undefined ? [] : [bar(span[1], index, 0, tone, scale, span[0], ends[place])];
226
+ return span === undefined
227
+ ? []
228
+ : [bar(span[1], index, 0, tone, scale, span[0], ends[place], slots[index]?.tone)];
207
229
  });
208
230
  });
209
231
  }