@zsherman/charts 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +7 -0
- package/LICENSE +373 -0
- package/README.md +13 -2
- package/THIRD_PARTY_NOTICES.md +33 -0
- package/dist/dom/bar-list/bar-list.js +386 -0
- package/dist/dom/bar-list/bar-list.styles.js +171 -0
- package/dist/dom/bar-list/index.js +1 -0
- package/dist/dom/chart/chart.js +716 -0
- package/dist/dom/chart/chart.styles.js +165 -0
- package/dist/dom/chart/index.js +1 -0
- package/dist/dom/chart-grid/chart-grid.js +67 -0
- package/dist/dom/chart-grid/index.js +1 -0
- package/dist/dom/donut/donut.js +565 -0
- package/dist/dom/donut/donut.styles.js +111 -0
- package/dist/dom/donut/index.js +1 -0
- package/dist/dom/heat-graph/calendar.js +118 -0
- package/dist/dom/heat-graph/heat-graph.js +423 -0
- package/dist/dom/heat-graph/heat-graph.styles.js +168 -0
- package/dist/dom/heat-graph/index.js +1 -0
- package/dist/dom/heat-matrix/heat-matrix.js +346 -0
- package/dist/dom/heat-matrix/heat-matrix.styles.js +155 -0
- package/dist/dom/heat-matrix/index.js +1 -0
- package/dist/dom/heat-matrix/model.js +41 -0
- package/dist/dom/index.js +13 -0
- package/dist/dom/internal/colors.js +44 -0
- package/dist/dom/internal/floating-tip.js +83 -0
- package/dist/dom/internal/format.js +43 -0
- package/dist/dom/internal/grid-context.js +5 -0
- package/dist/dom/internal/hidden.styles.js +16 -0
- package/dist/dom/internal/legend.js +112 -0
- package/dist/dom/internal/legend.styles.js +108 -0
- package/dist/dom/internal/markers.js +101 -0
- package/dist/dom/internal/options.js +300 -0
- package/dist/dom/internal/place.js +27 -0
- package/dist/dom/internal/scheme-watch.js +73 -0
- package/dist/dom/internal/share.js +28 -0
- package/dist/dom/internal/types.js +0 -0
- package/dist/dom/row-chart/index.js +1 -0
- package/dist/dom/row-chart/model.js +59 -0
- package/dist/dom/row-chart/row-chart.js +691 -0
- package/dist/dom/row-chart/row-chart.styles.js +242 -0
- package/dist/dom/segmented-bar/index.js +1 -0
- package/dist/dom/segmented-bar/segmented-bar.js +280 -0
- package/dist/dom/segmented-bar/segmented-bar.styles.js +88 -0
- package/dist/dom/sparkline/index.js +1 -0
- package/dist/dom/sparkline/sparkline.js +145 -0
- package/dist/dom/stacked-histogram/histogram.js +137 -0
- package/dist/dom/stacked-histogram/index.js +1 -0
- package/dist/dom/stacked-histogram/stacked-histogram.js +761 -0
- package/dist/dom/stacked-histogram/stacked-histogram.styles.js +211 -0
- package/dist/dom/state-timeline/index.js +1 -0
- package/dist/dom/state-timeline/model.js +166 -0
- package/dist/dom/state-timeline/state-timeline.js +729 -0
- package/dist/dom/state-timeline/state-timeline.styles.js +171 -0
- package/dist/dom/status-history/index.js +1 -0
- package/dist/dom/status-history/status-history.js +542 -0
- package/dist/dom/status-history/status-history.styles.js +171 -0
- package/dist/solid/bar-list/bar-list.jsx +139 -0
- package/dist/solid/bar-list/bar-list.styles.jsx +171 -0
- package/dist/solid/bar-list/index.jsx +1 -0
- package/dist/solid/chart/chart.jsx +454 -0
- package/dist/solid/chart/chart.styles.jsx +165 -0
- package/dist/solid/chart/index.jsx +1 -0
- package/dist/solid/chart-grid/chart-grid.jsx +46 -0
- package/dist/solid/chart-grid/index.jsx +1 -0
- package/dist/solid/donut/donut.jsx +291 -0
- package/dist/solid/donut/donut.styles.jsx +111 -0
- package/dist/solid/donut/index.jsx +1 -0
- package/dist/solid/heat-graph/calendar.jsx +118 -0
- package/dist/solid/heat-graph/heat-graph.jsx +228 -0
- package/dist/solid/heat-graph/heat-graph.styles.jsx +168 -0
- package/dist/solid/heat-graph/index.jsx +1 -0
- package/dist/solid/heat-matrix/heat-matrix.jsx +165 -0
- package/dist/solid/heat-matrix/heat-matrix.styles.jsx +155 -0
- package/dist/solid/heat-matrix/index.jsx +1 -0
- package/dist/solid/heat-matrix/model.jsx +41 -0
- package/dist/solid/index.jsx +13 -0
- package/dist/solid/internal/colors.jsx +44 -0
- package/dist/solid/internal/floating-tip.jsx +68 -0
- package/dist/solid/internal/format.jsx +43 -0
- package/dist/solid/internal/grid-context.jsx +5 -0
- package/dist/solid/internal/hidden.styles.jsx +16 -0
- package/dist/solid/internal/legend.jsx +35 -0
- package/dist/solid/internal/legend.styles.jsx +108 -0
- package/dist/solid/internal/markers.jsx +101 -0
- package/dist/solid/internal/options.jsx +300 -0
- package/dist/solid/internal/place.jsx +27 -0
- package/dist/solid/internal/scheme-watch.jsx +73 -0
- package/dist/solid/internal/share.jsx +28 -0
- package/dist/solid/internal/types.jsx +0 -0
- package/dist/solid/row-chart/index.jsx +1 -0
- package/dist/solid/row-chart/model.jsx +59 -0
- package/dist/solid/row-chart/row-chart.jsx +312 -0
- package/dist/solid/row-chart/row-chart.styles.jsx +242 -0
- package/dist/solid/segmented-bar/index.jsx +1 -0
- package/dist/solid/segmented-bar/segmented-bar.jsx +125 -0
- package/dist/solid/segmented-bar/segmented-bar.styles.jsx +88 -0
- package/dist/solid/sparkline/index.jsx +1 -0
- package/dist/solid/sparkline/sparkline.jsx +88 -0
- package/dist/solid/stacked-histogram/histogram.jsx +137 -0
- package/dist/solid/stacked-histogram/index.jsx +1 -0
- package/dist/solid/stacked-histogram/stacked-histogram.jsx +381 -0
- package/dist/solid/stacked-histogram/stacked-histogram.styles.jsx +211 -0
- package/dist/solid/state-timeline/index.jsx +1 -0
- package/dist/solid/state-timeline/model.jsx +166 -0
- package/dist/solid/state-timeline/state-timeline.jsx +387 -0
- package/dist/solid/state-timeline/state-timeline.styles.jsx +171 -0
- package/dist/solid/status-history/index.jsx +1 -0
- package/dist/solid/status-history/status-history.jsx +279 -0
- package/dist/solid/status-history/status-history.styles.jsx +171 -0
- package/dist/styles.css +1 -0
- package/dist/types/bar-list/bar-list.d.ts +91 -0
- package/dist/types/bar-list/bar-list.styles.d.ts +148 -0
- package/dist/types/bar-list/index.d.ts +3 -0
- package/dist/types/chart/chart.d.ts +98 -0
- package/dist/types/chart/chart.styles.d.ts +145 -0
- package/dist/types/chart/index.d.ts +3 -0
- package/dist/types/chart-grid/chart-grid.d.ts +35 -0
- package/dist/types/chart-grid/index.d.ts +2 -0
- package/dist/types/donut/donut.d.ts +124 -0
- package/dist/types/donut/donut.styles.d.ts +96 -0
- package/dist/types/donut/index.d.ts +3 -0
- package/dist/types/heat-graph/calendar.d.ts +61 -0
- package/dist/types/heat-graph/heat-graph.d.ts +82 -0
- package/dist/types/heat-graph/heat-graph.styles.d.ts +141 -0
- package/dist/types/heat-graph/index.d.ts +4 -0
- package/dist/types/heat-matrix/heat-matrix.d.ts +65 -0
- package/dist/types/heat-matrix/heat-matrix.styles.d.ts +135 -0
- package/dist/types/heat-matrix/index.d.ts +3 -0
- package/dist/types/heat-matrix/model.d.ts +15 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/internal/colors.d.ts +22 -0
- package/dist/types/internal/floating-tip.d.ts +15 -0
- package/dist/types/internal/format.d.ts +7 -0
- package/dist/types/internal/grid-context.d.ts +9 -0
- package/dist/types/internal/hidden.styles.d.ts +15 -0
- package/dist/types/internal/legend.d.ts +18 -0
- package/dist/types/internal/legend.styles.d.ts +96 -0
- package/dist/types/internal/markers.d.ts +16 -0
- package/dist/types/internal/options.d.ts +59 -0
- package/dist/types/internal/place.d.ts +20 -0
- package/dist/types/internal/scheme-watch.d.ts +12 -0
- package/dist/types/internal/share.d.ts +19 -0
- package/dist/types/internal/types.d.ts +163 -0
- package/dist/types/row-chart/index.d.ts +4 -0
- package/dist/types/row-chart/model.d.ts +50 -0
- package/dist/types/row-chart/row-chart.d.ts +148 -0
- package/dist/types/row-chart/row-chart.styles.d.ts +216 -0
- package/dist/types/segmented-bar/index.d.ts +3 -0
- package/dist/types/segmented-bar/segmented-bar.d.ts +65 -0
- package/dist/types/segmented-bar/segmented-bar.styles.d.ts +75 -0
- package/dist/types/sparkline/index.d.ts +3 -0
- package/dist/types/sparkline/sparkline.d.ts +38 -0
- package/dist/types/stacked-histogram/histogram.d.ts +48 -0
- package/dist/types/stacked-histogram/index.d.ts +4 -0
- package/dist/types/stacked-histogram/stacked-histogram.d.ts +73 -0
- package/dist/types/stacked-histogram/stacked-histogram.styles.d.ts +187 -0
- package/dist/types/state-timeline/index.d.ts +3 -0
- package/dist/types/state-timeline/model.d.ts +63 -0
- package/dist/types/state-timeline/state-timeline.d.ts +108 -0
- package/dist/types/state-timeline/state-timeline.styles.d.ts +151 -0
- package/dist/types/status-history/index.d.ts +3 -0
- package/dist/types/status-history/status-history.d.ts +72 -0
- package/dist/types/status-history/status-history.styles.d.ts +150 -0
- package/docs/api.json +1346 -0
- package/docs/bar-list.md +190 -0
- package/docs/chart-grid.md +77 -0
- package/docs/chart.md +355 -0
- package/docs/donut.md +182 -0
- package/docs/heat-graph.md +121 -0
- package/docs/heat-matrix.md +108 -0
- package/docs/llms.txt +68 -0
- package/docs/row-chart.md +193 -0
- package/docs/search-index.json +291 -0
- package/docs/segmented-bar.md +128 -0
- package/docs/sparkline.md +82 -0
- package/docs/stacked-histogram.md +123 -0
- package/docs/state-timeline.md +141 -0
- package/docs/status-history.md +121 -0
- package/package.json +104 -4
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { cssColor, toneColor } from "../internal/colors.jsx";
|
|
2
|
+
import { FloatingTip } from "../internal/floating-tip.jsx";
|
|
3
|
+
import { numberFormat } from "../internal/format.jsx";
|
|
4
|
+
import { hidden } from "../internal/hidden.styles.jsx";
|
|
5
|
+
import { Swatch } from "../internal/legend.jsx";
|
|
6
|
+
import { shareFormat } from "../internal/share.jsx";
|
|
7
|
+
import { barWidth, buildModel, deltaFormat } from "./model.jsx";
|
|
8
|
+
import { styles } from "./row-chart.styles.jsx";
|
|
9
|
+
import * as stylex from "@stylexjs/stylex";
|
|
10
|
+
import { useLocale, useMessages } from "@zsherman/kit/locale-provider";
|
|
11
|
+
import { For, Show, createMemo, createSignal, createUniqueId, omit } from "solid-js";
|
|
12
|
+
// src/row-chart/row-chart.tsx
|
|
13
|
+
const DEFAULT_LABELS = {
|
|
14
|
+
total: "Total",
|
|
15
|
+
keyboardHint: "Use the up and down arrow keys to read the rows.",
|
|
16
|
+
legend: (label) => `${label}: series`,
|
|
17
|
+
empty: "No data"
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Horizontal bars, one row per category: grouped to compare series row by row (a baseline and a
|
|
21
|
+
* candidate, with the change), or stacked to split each row into parts (user and kernel time). Labels
|
|
22
|
+
* with a note on the left, values after the bars, rows in groups, muted rows, a tooltip on hover and on
|
|
23
|
+
* the arrow keys. Plain DOM, so it renders on the server; each row is named in words.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* <RowChart
|
|
27
|
+
* label="Participants per vCPU"
|
|
28
|
+
* series={[{ label: "Baseline", tone: "neutral" }, { label: "Candidate" }]}
|
|
29
|
+
* rows={[{ label: "eu-central", values: [13.3, 20.6] }, { label: "us-east", values: [17.3, 22.3] }]}
|
|
30
|
+
* delta
|
|
31
|
+
* />
|
|
32
|
+
*/
|
|
33
|
+
function RowChart(props) {
|
|
34
|
+
const rest = omit(props, "label", "series", "rows", "layout", "max", "format", "delta", "valueText", "legend", "tooltip", "labels", "class");
|
|
35
|
+
const id = createUniqueId();
|
|
36
|
+
const locale = useLocale();
|
|
37
|
+
const messages = useMessages("rowChart");
|
|
38
|
+
const text = (k) => props.labels?.[k] ?? messages()?.[k] ?? DEFAULT_LABELS[k];
|
|
39
|
+
let plot;
|
|
40
|
+
let list;
|
|
41
|
+
const [active, setActive] = createSignal(null);
|
|
42
|
+
const [readout, setReadout] = createSignal("");
|
|
43
|
+
const stacked = () => props.layout === "stacked";
|
|
44
|
+
const tooltipOn = () => props.tooltip !== false;
|
|
45
|
+
const legendOn = () => props.legend ?? props.series.length > 1;
|
|
46
|
+
/** Each series' color: its own, its tone, or the next chart token among the untoned ones. */
|
|
47
|
+
const seriesColors = createMemo(() => {
|
|
48
|
+
let next = 0;
|
|
49
|
+
return props.series.map((s) => s.color ? cssColor(s.color, 0) : s.tone ? toneColor(s.tone) : cssColor(void 0, next++));
|
|
50
|
+
});
|
|
51
|
+
const view = createMemo(() => {
|
|
52
|
+
const lay = stacked() ? "stacked" : "grouped";
|
|
53
|
+
const rows = props.rows;
|
|
54
|
+
const values = rows.map((r) => r.values);
|
|
55
|
+
const max = Math.max(0, ...values.flat().map((v) => v == null ? 0 : Math.abs(v)));
|
|
56
|
+
const format = props.format ?? numberFormat(locale(), max);
|
|
57
|
+
const delta = deltaFormat(locale());
|
|
58
|
+
const share = shareFormat(locale());
|
|
59
|
+
const model = buildModel({
|
|
60
|
+
rows,
|
|
61
|
+
seriesCount: props.series.length,
|
|
62
|
+
layout: lay,
|
|
63
|
+
max: props.max,
|
|
64
|
+
delta: props.delta === true,
|
|
65
|
+
format
|
|
66
|
+
});
|
|
67
|
+
const colors = seriesColors();
|
|
68
|
+
const out = rows.map((row, index) => {
|
|
69
|
+
const m = model.rows[index];
|
|
70
|
+
const bars = m.bars.map((b) => {
|
|
71
|
+
const own = b.delta === void 0 ? b.text : `${b.text} (${delta(b.delta)})`;
|
|
72
|
+
return {
|
|
73
|
+
...b,
|
|
74
|
+
color: row.colors?.[b.series] ? cssColor(row.colors[b.series], 0) : colors[b.series],
|
|
75
|
+
width: barWidth(b.fraction),
|
|
76
|
+
end: props.valueText?.({
|
|
77
|
+
row,
|
|
78
|
+
series: b.series,
|
|
79
|
+
value: b.value,
|
|
80
|
+
text: own,
|
|
81
|
+
delta: b.delta
|
|
82
|
+
}) ?? own,
|
|
83
|
+
own,
|
|
84
|
+
shareText: share(b.share),
|
|
85
|
+
strong: b.delta !== void 0
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
const totalText = format(m.total);
|
|
89
|
+
const end = props.valueText?.({
|
|
90
|
+
row,
|
|
91
|
+
series: null,
|
|
92
|
+
value: m.total,
|
|
93
|
+
text: totalText
|
|
94
|
+
}) ?? totalText;
|
|
95
|
+
const head = row.note ? `${row.label}, ${row.note}` : row.label;
|
|
96
|
+
const parts = props.series.map((s, i) => lay === "stacked" ? `${s.label} ${bars[i].own} (${bars[i].shareText})` : `${s.label} ${bars[i].end}`);
|
|
97
|
+
return {
|
|
98
|
+
row,
|
|
99
|
+
index,
|
|
100
|
+
bars,
|
|
101
|
+
total: m.total,
|
|
102
|
+
totalText,
|
|
103
|
+
end,
|
|
104
|
+
width: barWidth(m.fraction),
|
|
105
|
+
groupStart: m.groupStart,
|
|
106
|
+
name: lay === "stacked" ? `${head}: ${text("total")} ${end}; ${parts.join(", ")}` : `${head}: ${parts.join(", ")}`
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
rows: out,
|
|
111
|
+
reserve: `${Math.max(0, ...out.flatMap((r) => lay === "stacked" ? [r.end.length] : r.bars.map((b) => b.end.length))) + 1}ch`
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
const point = createMemo(() => {
|
|
115
|
+
const a = active();
|
|
116
|
+
const r = a ? view().rows[a.index] : void 0;
|
|
117
|
+
if (!r) return null;
|
|
118
|
+
return {
|
|
119
|
+
row: r.row,
|
|
120
|
+
index: r.index,
|
|
121
|
+
total: r.total,
|
|
122
|
+
totalText: r.totalText,
|
|
123
|
+
series: props.series.map((s, i) => ({
|
|
124
|
+
label: s.label,
|
|
125
|
+
value: r.row.values[i] ?? null,
|
|
126
|
+
text: r.bars[i].own,
|
|
127
|
+
share: stacked() ? r.bars[i].shareText : void 0,
|
|
128
|
+
color: r.bars[i].color
|
|
129
|
+
}))
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
/** The plot's pixels of an element's box. */
|
|
133
|
+
const within = (el) => {
|
|
134
|
+
const box = el.getBoundingClientRect();
|
|
135
|
+
const origin = plot.getBoundingClientRect();
|
|
136
|
+
return {
|
|
137
|
+
left: box.left - origin.left,
|
|
138
|
+
right: box.right - origin.left,
|
|
139
|
+
mid: box.top - origin.top + box.height / 2
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
function hover(index, event) {
|
|
143
|
+
if (!tooltipOn() || event.pointerType === "touch") return;
|
|
144
|
+
const row = event.currentTarget;
|
|
145
|
+
const left = event.clientX - plot.getBoundingClientRect().left;
|
|
146
|
+
setActive({
|
|
147
|
+
index,
|
|
148
|
+
left,
|
|
149
|
+
top: within(row).mid,
|
|
150
|
+
before: left > plot.clientWidth / 2
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/** Point the tooltip at the end of the row's longest bar: where the keyboard put it. */
|
|
154
|
+
function activate(index) {
|
|
155
|
+
const row = list.children[index];
|
|
156
|
+
if (!row) return;
|
|
157
|
+
const ends = [...row.querySelectorAll("[data-slot=\"row-chart-bar\"]")].map((b) => within(b).right);
|
|
158
|
+
const left = Math.max(within(row.querySelector("[data-slot=\"row-chart-bars\"]") ?? row).left, ...ends);
|
|
159
|
+
setActive({
|
|
160
|
+
index,
|
|
161
|
+
left,
|
|
162
|
+
top: within(row).mid,
|
|
163
|
+
before: left > plot.clientWidth / 2
|
|
164
|
+
});
|
|
165
|
+
setReadout(view().rows[index]?.name ?? "");
|
|
166
|
+
}
|
|
167
|
+
function onKeyDown(event) {
|
|
168
|
+
const count = view().rows.length;
|
|
169
|
+
if (!tooltipOn() || count === 0) return;
|
|
170
|
+
const current = active()?.index;
|
|
171
|
+
let next;
|
|
172
|
+
switch (event.key) {
|
|
173
|
+
case "ArrowDown":
|
|
174
|
+
next = current == null ? 0 : Math.min(count - 1, current + 1);
|
|
175
|
+
break;
|
|
176
|
+
case "ArrowUp":
|
|
177
|
+
next = current == null ? count - 1 : Math.max(0, current - 1);
|
|
178
|
+
break;
|
|
179
|
+
case "Home":
|
|
180
|
+
next = 0;
|
|
181
|
+
break;
|
|
182
|
+
case "End":
|
|
183
|
+
next = count - 1;
|
|
184
|
+
break;
|
|
185
|
+
case "Escape":
|
|
186
|
+
if (current == null) return;
|
|
187
|
+
setActive(null);
|
|
188
|
+
setReadout("");
|
|
189
|
+
event.preventDefault();
|
|
190
|
+
return;
|
|
191
|
+
default: return;
|
|
192
|
+
}
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
activate(next);
|
|
195
|
+
}
|
|
196
|
+
const focusable = () => tooltipOn() && view().rows.length > 0;
|
|
197
|
+
return <div {...rest} data-slot="row-chart" class={[stylex.props(styles.root).className, props.class]} style={{ "--rc-text": view().reserve }}>
|
|
198
|
+
<Show when={legendOn()}>
|
|
199
|
+
<ul data-slot="row-chart-legend" aria-label={text("legend")(props.label)} {...stylex.attrs(styles.legend)}>
|
|
200
|
+
<For each={props.series}>
|
|
201
|
+
{(s, i) => <li data-slot="row-chart-legend-item" {...stylex.attrs(styles.legendItem)}>
|
|
202
|
+
<span {...stylex.attrs(styles.legendSwatch)}>
|
|
203
|
+
<Swatch color={seriesColors()[i()]} />
|
|
204
|
+
</span>
|
|
205
|
+
{s.label}
|
|
206
|
+
<Show when={s.note}>
|
|
207
|
+
<span data-slot="row-chart-legend-note" {...stylex.attrs(styles.legendNote)}>
|
|
208
|
+
{s.note}
|
|
209
|
+
</span>
|
|
210
|
+
</Show>
|
|
211
|
+
</li>}
|
|
212
|
+
</For>
|
|
213
|
+
</ul>
|
|
214
|
+
</Show>
|
|
215
|
+
<div ref={(el) => plot = el} role="group" aria-label={props.label} aria-describedby={focusable() ? `${id}-keys` : void 0} tabindex={focusable() ? 0 : void 0} data-slot="row-chart-plot" onKeyDown={onKeyDown} onBlur={() => {
|
|
216
|
+
setActive(null);
|
|
217
|
+
setReadout("");
|
|
218
|
+
}} {...stylex.attrs(styles.plot)}>
|
|
219
|
+
<ul ref={(el) => list = el} data-slot="row-chart-rows" onPointerLeave={() => {
|
|
220
|
+
if (document.activeElement !== plot) setActive(null);
|
|
221
|
+
}} {...stylex.attrs(styles.rows)}>
|
|
222
|
+
<For each={view().rows} keyed={false}>
|
|
223
|
+
{(r, index) => <li data-slot="row-chart-row" data-active={active()?.index === index ? "" : void 0} data-muted={r().row.muted ? "" : void 0} data-group-start={r().groupStart ? "" : void 0} onPointerMove={(event) => hover(index, event)} {...stylex.attrs(styles.row, r().groupStart && styles.groupStart)}>
|
|
224
|
+
<span {...stylex.attrs(hidden.visually)}>{r().name}</span>
|
|
225
|
+
<div aria-hidden="true" {...stylex.attrs(styles.labelCell)}>
|
|
226
|
+
<span data-slot="row-chart-label" title={r().row.label} {...stylex.attrs(styles.label, r().row.muted && styles.labelMuted)}>
|
|
227
|
+
{r().row.label}
|
|
228
|
+
</span>
|
|
229
|
+
<Show when={r().row.note}>
|
|
230
|
+
<span data-slot="row-chart-note" title={r().row.note} {...stylex.attrs(styles.note)}>
|
|
231
|
+
{r().row.note}
|
|
232
|
+
</span>
|
|
233
|
+
</Show>
|
|
234
|
+
</div>
|
|
235
|
+
<div aria-hidden="true" data-slot="row-chart-bars" {...stylex.attrs(styles.bars)}>
|
|
236
|
+
<Show when={stacked()} fallback={<For each={r().bars} keyed={false}>
|
|
237
|
+
{(b) => <div {...stylex.attrs(styles.line)}>
|
|
238
|
+
<span data-slot="row-chart-bar" {...stylex.attrs(styles.bar, r().row.muted && styles.barMuted)} style={{
|
|
239
|
+
width: b().width,
|
|
240
|
+
"--bar": b().color
|
|
241
|
+
}} />
|
|
242
|
+
<span data-slot="row-chart-value" {...stylex.attrs(styles.value, b().strong && !r().row.muted && styles.valueStrong)}>
|
|
243
|
+
{b().end}
|
|
244
|
+
</span>
|
|
245
|
+
</div>}
|
|
246
|
+
</For>}>
|
|
247
|
+
<div {...stylex.attrs(styles.line)}>
|
|
248
|
+
<span data-slot="row-chart-bar" {...stylex.attrs(styles.stack)} style={{ width: r().width }}>
|
|
249
|
+
<For each={r().bars} keyed={false}>
|
|
250
|
+
{(b) => <Show when={b().value > 0}>
|
|
251
|
+
<span data-slot="row-chart-segment" {...stylex.attrs(styles.segment, r().row.muted && styles.barMuted)} style={{
|
|
252
|
+
"flex-grow": String(b().share * 100),
|
|
253
|
+
"--bar": b().color
|
|
254
|
+
}} />
|
|
255
|
+
</Show>}
|
|
256
|
+
</For>
|
|
257
|
+
</span>
|
|
258
|
+
<span data-slot="row-chart-value" {...stylex.attrs(styles.value, !r().row.muted && styles.valueStrong)}>
|
|
259
|
+
{r().end}
|
|
260
|
+
</span>
|
|
261
|
+
</div>
|
|
262
|
+
</Show>
|
|
263
|
+
</div>
|
|
264
|
+
</li>}
|
|
265
|
+
</For>
|
|
266
|
+
</ul>
|
|
267
|
+
<Show when={tooltipOn() ? point() : null}>
|
|
268
|
+
{(p) => <FloatingTip data-slot="row-chart-tooltip" aria-hidden="true" origin={() => plot} left={active()?.left ?? 0} top={active()?.top ?? 0} before={active()?.before} xstyle={styles.tooltip}>
|
|
269
|
+
<Show keyed when={typeof props.tooltip === "object" ? props.tooltip.render : void 0} fallback={<>
|
|
270
|
+
<div data-slot="row-chart-tooltip-heading" {...stylex.attrs(styles.tooltipHeading)}>
|
|
271
|
+
{p().row.label}
|
|
272
|
+
<Show when={p().row.note}>
|
|
273
|
+
<span {...stylex.attrs(styles.tooltipNote)}>{p().row.note}</span>
|
|
274
|
+
</Show>
|
|
275
|
+
</div>
|
|
276
|
+
<Show when={stacked()}>
|
|
277
|
+
<div data-slot="row-chart-tooltip-row" {...stylex.attrs(styles.tooltipRow)}>
|
|
278
|
+
<span {...stylex.attrs(styles.tooltipLabel)}>{text("total")}</span>
|
|
279
|
+
<span {...stylex.attrs(styles.tooltipValue)}>{p().totalText}</span>
|
|
280
|
+
<span {...stylex.attrs(styles.tooltipShare)} />
|
|
281
|
+
</div>
|
|
282
|
+
</Show>
|
|
283
|
+
<For each={p().series} keyed={false}>
|
|
284
|
+
{(s) => <div data-slot="row-chart-tooltip-row" {...stylex.attrs(styles.tooltipRow)}>
|
|
285
|
+
<Swatch color={s().color} />
|
|
286
|
+
<span {...stylex.attrs(styles.tooltipLabel)}>{s().label}</span>
|
|
287
|
+
<span {...stylex.attrs(styles.tooltipValue)}>{s().text}</span>
|
|
288
|
+
<Show when={s().share}>
|
|
289
|
+
<span {...stylex.attrs(styles.tooltipShare)}>{s().share}</span>
|
|
290
|
+
</Show>
|
|
291
|
+
</div>}
|
|
292
|
+
</For>
|
|
293
|
+
</>}>
|
|
294
|
+
{(render) => render(p)}
|
|
295
|
+
</Show>
|
|
296
|
+
</FloatingTip>}
|
|
297
|
+
</Show>
|
|
298
|
+
</div>
|
|
299
|
+
<Show when={!view().rows.length}>
|
|
300
|
+
<p data-slot="row-chart-empty" {...stylex.attrs(styles.empty)}>
|
|
301
|
+
{text("empty")}
|
|
302
|
+
</p>
|
|
303
|
+
</Show>
|
|
304
|
+
<span id={`${id}-keys`} {...stylex.attrs(hidden.visually)}>
|
|
305
|
+
{text("keyboardHint")}
|
|
306
|
+
</span>
|
|
307
|
+
<span data-slot="row-chart-readout" aria-live="polite" {...stylex.attrs(hidden.visually)}>
|
|
308
|
+
{readout()}
|
|
309
|
+
</span>
|
|
310
|
+
</div>;
|
|
311
|
+
}
|
|
312
|
+
export { RowChart };
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import "@stylexjs/stylex";
|
|
2
|
+
// src/row-chart/row-chart.styles.ts
|
|
3
|
+
const styles = {
|
|
4
|
+
root: {
|
|
5
|
+
kB7OPa: "x9f619",
|
|
6
|
+
k1xSpc: "xrvj5dj",
|
|
7
|
+
kOIVth: "xgtrjx6",
|
|
8
|
+
k7Eaqz: "xeuugli",
|
|
9
|
+
kMv6JI: "x13rcfk",
|
|
10
|
+
kGuDYH: "x409pna",
|
|
11
|
+
kLWn49: "xau0z5x",
|
|
12
|
+
kMwMTN: "x1yjpjgc",
|
|
13
|
+
$$css: true
|
|
14
|
+
},
|
|
15
|
+
legend: {
|
|
16
|
+
k1xSpc: "x78zum5",
|
|
17
|
+
kwnvtZ: "x1a02dak",
|
|
18
|
+
k1C7PZ: "x1lcxfya",
|
|
19
|
+
khm7nJ: "x1xpjfrv",
|
|
20
|
+
kogj98: "x1ghz6dp",
|
|
21
|
+
kmVPX3: "x1717udv",
|
|
22
|
+
kB88ic: "xe8uvvx",
|
|
23
|
+
kGuDYH: "xb5fjo1",
|
|
24
|
+
kMwMTN: "xe2mk2a",
|
|
25
|
+
$$css: true
|
|
26
|
+
},
|
|
27
|
+
legendItem: {
|
|
28
|
+
k1xSpc: "x3nfvp2",
|
|
29
|
+
kGNEyG: "x6s0dn4",
|
|
30
|
+
kOIVth: "x1xuqxfr",
|
|
31
|
+
k7Eaqz: "xeuugli",
|
|
32
|
+
$$css: true
|
|
33
|
+
},
|
|
34
|
+
legendSwatch: {
|
|
35
|
+
k1xSpc: "x3nfvp2",
|
|
36
|
+
$$css: true
|
|
37
|
+
},
|
|
38
|
+
legendNote: {
|
|
39
|
+
kg3NbH: "xloswcj",
|
|
40
|
+
kaIpWk: "x1b6xorz",
|
|
41
|
+
kWkggS: "x1t2kxjd",
|
|
42
|
+
kMv6JI: "xhrs3nv",
|
|
43
|
+
kMwMTN: "xe2mk2a",
|
|
44
|
+
$$css: true
|
|
45
|
+
},
|
|
46
|
+
plot: {
|
|
47
|
+
kVAEAm: "x1n2onr6",
|
|
48
|
+
k7Eaqz: "xeuugli",
|
|
49
|
+
kaIpWk: "x1b6xorz",
|
|
50
|
+
k3XXqK: "x1t137rt x9v5kkp",
|
|
51
|
+
kMeerF: "x1de99jn",
|
|
52
|
+
kInvED: "x2wh2y9",
|
|
53
|
+
kjBf7l: "xi1ptex x1x84bn5",
|
|
54
|
+
$$css: true
|
|
55
|
+
},
|
|
56
|
+
rows: {
|
|
57
|
+
k1xSpc: "xrvj5dj",
|
|
58
|
+
kumcoG: "x9v58at",
|
|
59
|
+
k1C7PZ: "x1lcxfya",
|
|
60
|
+
khm7nJ: "x1xpjfrv",
|
|
61
|
+
kogj98: "x1ghz6dp",
|
|
62
|
+
kmVPX3: "x1717udv",
|
|
63
|
+
kB88ic: "xe8uvvx",
|
|
64
|
+
$$css: true
|
|
65
|
+
},
|
|
66
|
+
row: {
|
|
67
|
+
kVAEAm: "x1n2onr6",
|
|
68
|
+
kB7OPa: "x9f619",
|
|
69
|
+
k1xSpc: "xrvj5dj",
|
|
70
|
+
kBCFzs: "x1osaytk",
|
|
71
|
+
kumcoG: "x4w6khx",
|
|
72
|
+
kGNEyG: "x6s0dn4",
|
|
73
|
+
k7Eaqz: "xeuugli",
|
|
74
|
+
k8WAf4: "x1ucdaca",
|
|
75
|
+
kg3NbH: "x1d6xsf",
|
|
76
|
+
kUOVxO: "xgjtpfo",
|
|
77
|
+
kaIpWk: "x1b6xorz",
|
|
78
|
+
kWkggS: "xjbqb8w x1duwuep",
|
|
79
|
+
k1ekBW: "x15406qy",
|
|
80
|
+
kIyJzY: "xctwqe3 x12w9bfk",
|
|
81
|
+
$$css: true
|
|
82
|
+
},
|
|
83
|
+
groupStart: {
|
|
84
|
+
keoZOQ: "xg9uls3",
|
|
85
|
+
kgeoSG: "x10tli2e",
|
|
86
|
+
kEoFBp: "x1hmns74",
|
|
87
|
+
kpsdNU: "x5avmn6",
|
|
88
|
+
k96MEf: "xa67ly5",
|
|
89
|
+
kgzTxl: "xy80zi5",
|
|
90
|
+
kLkRvE: "xviiqbq x15j5p1n",
|
|
91
|
+
$$css: true
|
|
92
|
+
},
|
|
93
|
+
labelCell: {
|
|
94
|
+
k1xSpc: "xrvj5dj",
|
|
95
|
+
kOIVth: "xpowot6",
|
|
96
|
+
k7Eaqz: "xeuugli",
|
|
97
|
+
$$css: true
|
|
98
|
+
},
|
|
99
|
+
label: {
|
|
100
|
+
k7Eaqz: "xeuugli",
|
|
101
|
+
kVQacm: "xb3r6kr",
|
|
102
|
+
kg5iWk: "xlyipyv",
|
|
103
|
+
khDVqt: "xuxw1ft",
|
|
104
|
+
k63SB2: "x1vmg6u2",
|
|
105
|
+
$$css: true
|
|
106
|
+
},
|
|
107
|
+
labelMuted: {
|
|
108
|
+
k63SB2: "x1lyc3gu",
|
|
109
|
+
kMwMTN: "xe2mk2a",
|
|
110
|
+
$$css: true
|
|
111
|
+
},
|
|
112
|
+
note: {
|
|
113
|
+
k7Eaqz: "xeuugli",
|
|
114
|
+
kVQacm: "xb3r6kr",
|
|
115
|
+
kg5iWk: "xlyipyv",
|
|
116
|
+
khDVqt: "xuxw1ft",
|
|
117
|
+
kGuDYH: "xb5fjo1",
|
|
118
|
+
kMwMTN: "xe2mk2a",
|
|
119
|
+
$$css: true
|
|
120
|
+
},
|
|
121
|
+
bars: {
|
|
122
|
+
k1xSpc: "xrvj5dj",
|
|
123
|
+
kOIVth: "x195vfkc",
|
|
124
|
+
k7Eaqz: "xeuugli",
|
|
125
|
+
$$css: true
|
|
126
|
+
},
|
|
127
|
+
line: {
|
|
128
|
+
k1xSpc: "x78zum5",
|
|
129
|
+
kGNEyG: "x6s0dn4",
|
|
130
|
+
kOIVth: "x1xuqxfr",
|
|
131
|
+
k7Eaqz: "xeuugli",
|
|
132
|
+
$$css: true
|
|
133
|
+
},
|
|
134
|
+
bar: {
|
|
135
|
+
kmuXW: "x2lah0s",
|
|
136
|
+
kZKoxP: "x1qa65zt",
|
|
137
|
+
kaIpWk: "x1cum3z5",
|
|
138
|
+
kWkggS: "xqa76ta",
|
|
139
|
+
kAXs8y: "x1kzknox",
|
|
140
|
+
$$css: true
|
|
141
|
+
},
|
|
142
|
+
stack: {
|
|
143
|
+
k1xSpc: "x78zum5",
|
|
144
|
+
kmuXW: "x2lah0s",
|
|
145
|
+
kOIVth: "x195vfkc",
|
|
146
|
+
kZKoxP: "xf08kfj",
|
|
147
|
+
kVQacm: "xb3r6kr",
|
|
148
|
+
kaIpWk: "x1cum3z5",
|
|
149
|
+
$$css: true
|
|
150
|
+
},
|
|
151
|
+
segment: {
|
|
152
|
+
kCS8Yb: "x1r8uery",
|
|
153
|
+
kmuXW: "xs83m0k",
|
|
154
|
+
k7Eaqz: "x9041oi",
|
|
155
|
+
kWkggS: "xqa76ta",
|
|
156
|
+
kAXs8y: "x1kzknox",
|
|
157
|
+
$$css: true
|
|
158
|
+
},
|
|
159
|
+
barMuted: {
|
|
160
|
+
kWkggS: "x19xktzh",
|
|
161
|
+
$$css: true
|
|
162
|
+
},
|
|
163
|
+
value: {
|
|
164
|
+
kmuXW: "x2lah0s",
|
|
165
|
+
kGuDYH: "xb5fjo1",
|
|
166
|
+
kcqcaj: "xss6m8b",
|
|
167
|
+
kMwMTN: "xe2mk2a",
|
|
168
|
+
khDVqt: "xuxw1ft",
|
|
169
|
+
kQ0QjF: "xa7awgv",
|
|
170
|
+
$$css: true
|
|
171
|
+
},
|
|
172
|
+
valueStrong: {
|
|
173
|
+
k63SB2: "x1vmg6u2",
|
|
174
|
+
kMwMTN: "x1yjpjgc",
|
|
175
|
+
$$css: true
|
|
176
|
+
},
|
|
177
|
+
tooltip: {
|
|
178
|
+
kB7OPa: "x9f619",
|
|
179
|
+
k1xSpc: "xrvj5dj",
|
|
180
|
+
kOIVth: "xz09phk",
|
|
181
|
+
k7Eaqz: "xuu4ctt",
|
|
182
|
+
ks0D6T: "xsbr6jr",
|
|
183
|
+
k8WAf4: "xqy2vlu",
|
|
184
|
+
kg3NbH: "xxobuei",
|
|
185
|
+
kWkggS: "xm9f0jk",
|
|
186
|
+
kMwMTN: "x1yjpjgc",
|
|
187
|
+
kMzoRj: "xmkeg23",
|
|
188
|
+
ksu8eU: "x1y0btm7",
|
|
189
|
+
kVAM5u: "x1wpxzwl x1w1tqly",
|
|
190
|
+
kaIpWk: "x1ttroej",
|
|
191
|
+
kGVxlE: "xfw8du2",
|
|
192
|
+
kGuDYH: "xb5fjo1",
|
|
193
|
+
kLWn49: "xau0z5x",
|
|
194
|
+
$$css: true
|
|
195
|
+
},
|
|
196
|
+
tooltipHeading: {
|
|
197
|
+
k1xSpc: "xrvj5dj",
|
|
198
|
+
kOIVth: "xpowot6",
|
|
199
|
+
kGO01o: "x9ystxo",
|
|
200
|
+
k63SB2: "x1vmg6u2",
|
|
201
|
+
$$css: true
|
|
202
|
+
},
|
|
203
|
+
tooltipNote: {
|
|
204
|
+
k63SB2: "x1lyc3gu",
|
|
205
|
+
kMwMTN: "xe2mk2a",
|
|
206
|
+
$$css: true
|
|
207
|
+
},
|
|
208
|
+
tooltipRow: {
|
|
209
|
+
k1xSpc: "x78zum5",
|
|
210
|
+
kGNEyG: "x6s0dn4",
|
|
211
|
+
kOIVth: "x8rwxmg",
|
|
212
|
+
$$css: true
|
|
213
|
+
},
|
|
214
|
+
tooltipLabel: {
|
|
215
|
+
kzQI83: "x1iyjqo2",
|
|
216
|
+
kMwMTN: "xe2mk2a",
|
|
217
|
+
$$css: true
|
|
218
|
+
},
|
|
219
|
+
tooltipValue: {
|
|
220
|
+
kcqcaj: "xss6m8b",
|
|
221
|
+
k63SB2: "x1vmg6u2",
|
|
222
|
+
khDVqt: "xuxw1ft",
|
|
223
|
+
kQ0QjF: "xa7awgv",
|
|
224
|
+
$$css: true
|
|
225
|
+
},
|
|
226
|
+
tooltipShare: {
|
|
227
|
+
k7Eaqz: "x1k8l6nd",
|
|
228
|
+
k9WMMc: "xp4054r",
|
|
229
|
+
kcqcaj: "xss6m8b",
|
|
230
|
+
kMwMTN: "xe2mk2a",
|
|
231
|
+
khDVqt: "xuxw1ft",
|
|
232
|
+
kQ0QjF: "xa7awgv",
|
|
233
|
+
$$css: true
|
|
234
|
+
},
|
|
235
|
+
empty: {
|
|
236
|
+
kogj98: "x1ghz6dp",
|
|
237
|
+
k8WAf4: "x5eapc7",
|
|
238
|
+
kMwMTN: "xe2mk2a",
|
|
239
|
+
$$css: true
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
export { styles };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SegmentedBar } from "./segmented-bar.jsx";
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { cssColor, toneColor } from "../internal/colors.jsx";
|
|
2
|
+
import { numberFormat } from "../internal/format.jsx";
|
|
3
|
+
import { LegendEntry } from "../internal/legend.jsx";
|
|
4
|
+
import { legend } from "../internal/legend.styles.jsx";
|
|
5
|
+
import { amount, describe, shareFormat, shareOf } from "../internal/share.jsx";
|
|
6
|
+
import { styles } from "./segmented-bar.styles.jsx";
|
|
7
|
+
import * as stylex from "@stylexjs/stylex";
|
|
8
|
+
import { useLocale, useMessages } from "@zsherman/kit/locale-provider";
|
|
9
|
+
import { For, Show, createMemo, omit } from "solid-js";
|
|
10
|
+
// src/segmented-bar/segmented-bar.tsx
|
|
11
|
+
const DEFAULT_LABELS = {
|
|
12
|
+
remaining: "Remaining",
|
|
13
|
+
empty: "No data"
|
|
14
|
+
};
|
|
15
|
+
const REST = "var(--sui-border)";
|
|
16
|
+
/**
|
|
17
|
+
* One bar split into parts: a breakdown by category or status that fills the bar (100%), or parts "used of"
|
|
18
|
+
* a `max`, with an optional marker and a legend. The bar is an image named from the data ("Storage: Photos
|
|
19
|
+
* 42%, Video 30%, Remaining 28%"); the legend carries the values. Plain DOM, so it renders on the server.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* <SegmentedBar label="Test results" segments={[{ label: "Passed", value: 182, tone: "success" }, { label: "Failed", value: 6, tone: "danger" }]} legend />
|
|
23
|
+
*/
|
|
24
|
+
function SegmentedBar(props) {
|
|
25
|
+
const rest = omit(props, "label", "segments", "max", "marker", "legend", "format", "height", "labels", "class");
|
|
26
|
+
const locale = useLocale();
|
|
27
|
+
const messages = useMessages("segmentedBar");
|
|
28
|
+
const text = (k) => props.labels?.[k] ?? messages()?.[k] ?? DEFAULT_LABELS[k];
|
|
29
|
+
const model = createMemo(() => {
|
|
30
|
+
let total = 0;
|
|
31
|
+
let chart = 0;
|
|
32
|
+
const parts = props.segments.map((s) => {
|
|
33
|
+
const value = amount(s.value);
|
|
34
|
+
total += value;
|
|
35
|
+
return {
|
|
36
|
+
label: s.label,
|
|
37
|
+
value,
|
|
38
|
+
color: s.color ? cssColor(s.color, 0) : s.tone ? toneColor(s.tone) : cssColor(void 0, chart++)
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
const max = amount(props.max);
|
|
42
|
+
const whole = Math.max(max, total);
|
|
43
|
+
const left = max > total ? max - total : 0;
|
|
44
|
+
const value = props.format ?? numberFormat(locale(), whole);
|
|
45
|
+
const share = shareFormat(locale());
|
|
46
|
+
const rows = parts.map((p) => ({
|
|
47
|
+
...p,
|
|
48
|
+
valueText: value(p.value),
|
|
49
|
+
shareText: share(shareOf(p.value, whole))
|
|
50
|
+
}));
|
|
51
|
+
if (left > 0) rows.push({
|
|
52
|
+
label: text("remaining"),
|
|
53
|
+
value: left,
|
|
54
|
+
color: REST,
|
|
55
|
+
valueText: value(left),
|
|
56
|
+
shareText: share(shareOf(left, whole))
|
|
57
|
+
});
|
|
58
|
+
const mark = props.marker?.value;
|
|
59
|
+
const at = mark != null && Number.isFinite(mark) && whole > 0 ? Math.min(1, Math.max(0, mark / whole)) : void 0;
|
|
60
|
+
return {
|
|
61
|
+
rows,
|
|
62
|
+
parts: rows.slice(0, parts.length),
|
|
63
|
+
left,
|
|
64
|
+
whole,
|
|
65
|
+
at
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
const grow = (value) => String(model().whole > 0 ? value / model().whole * 100 : 0);
|
|
69
|
+
const name = () => {
|
|
70
|
+
const m = model();
|
|
71
|
+
const base = m.whole > 0 ? describe(props.label, m.rows.map((r) => ({
|
|
72
|
+
label: r.label,
|
|
73
|
+
share: r.shareText
|
|
74
|
+
}))) : `${props.label}: ${text("empty")}`;
|
|
75
|
+
return props.marker && model().at !== void 0 ? `${base}. ${props.marker.label}` : base;
|
|
76
|
+
};
|
|
77
|
+
return <div {...rest} data-slot="segmented-bar" class={[stylex.props(styles.root).className, props.class]} style={{ "--sb-height": `${props.height ?? 8}px` }}>
|
|
78
|
+
<div {...stylex.attrs(styles.figure)}>
|
|
79
|
+
<Show when={props.marker && model().at !== void 0}>
|
|
80
|
+
<div aria-hidden="true" data-slot="segmented-bar-marker-label" {...stylex.attrs(styles.markerLabel)}>
|
|
81
|
+
<span {...stylex.attrs(styles.markerText)} style={(() => {
|
|
82
|
+
const at = model().at;
|
|
83
|
+
const pct = `${at * 100}%`;
|
|
84
|
+
return at > .85 ? { "inset-inline-end": `${(1 - at) * 100}%` } : at < .15 ? { "inset-inline-start": pct } : {
|
|
85
|
+
"inset-inline-start": pct,
|
|
86
|
+
translate: "calc(-50% * var(--sui-dir-flip, 1)) 0"
|
|
87
|
+
};
|
|
88
|
+
})()}>
|
|
89
|
+
{props.marker?.label}
|
|
90
|
+
</span>
|
|
91
|
+
</div>
|
|
92
|
+
</Show>
|
|
93
|
+
<div role="img" aria-label={name()} data-slot="segmented-bar-bar" {...stylex.attrs(styles.bar)}>
|
|
94
|
+
<For each={model().parts} keyed={false}>
|
|
95
|
+
{(p) => <Show when={p().value > 0}>
|
|
96
|
+
<span data-slot="segmented-bar-segment" {...stylex.attrs(styles.segment)} style={{
|
|
97
|
+
"flex-grow": grow(p().value),
|
|
98
|
+
"--swatch": p().color
|
|
99
|
+
}} />
|
|
100
|
+
</Show>}
|
|
101
|
+
</For>
|
|
102
|
+
<Show when={model().left > 0}>
|
|
103
|
+
<span {...stylex.attrs(styles.rest)} style={{ "flex-grow": grow(model().left) }} />
|
|
104
|
+
</Show>
|
|
105
|
+
</div>
|
|
106
|
+
<Show when={model().at !== void 0}>
|
|
107
|
+
<span aria-hidden="true" data-slot="segmented-bar-marker" {...stylex.attrs(styles.tick)} style={{ "inset-inline-start": `${model().at * 100}%` }} />
|
|
108
|
+
</Show>
|
|
109
|
+
</div>
|
|
110
|
+
<Show when={props.legend}>
|
|
111
|
+
<Show when={props.segments.length} fallback={<p data-slot="segmented-bar-empty" {...stylex.attrs(styles.empty)}>
|
|
112
|
+
{text("empty")}
|
|
113
|
+
</p>}>
|
|
114
|
+
<ul data-slot="segmented-bar-legend" {...stylex.attrs(legend.list, styles.legendGrid)}>
|
|
115
|
+
<For each={model().rows} keyed={false}>
|
|
116
|
+
{(r) => <li {...stylex.attrs(legend.row, styles.legendRow)}>
|
|
117
|
+
<LegendEntry color={r().color} label={r().label} value={r().valueText} share={r().shareText} />
|
|
118
|
+
</li>}
|
|
119
|
+
</For>
|
|
120
|
+
</ul>
|
|
121
|
+
</Show>
|
|
122
|
+
</Show>
|
|
123
|
+
</div>;
|
|
124
|
+
}
|
|
125
|
+
export { SegmentedBar };
|