basalt-ui 2.26.0 → 2.27.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 +24 -0
- package/MIGRATING.md +87 -12
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +37 -1
- package/dist/charts/ChartCard.d.ts +8 -2
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +2 -0
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +48 -10
- package/dist/charts/chart-box.module.css +76 -1
- package/dist/charts/chart-box.module.css.d.ts +1 -0
- package/dist/charts/chart-legend.module.css +0 -14
- package/dist/charts/compile.d.ts +20 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +82 -12
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +37 -87
- package/dist/charts/state.d.ts +7 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +14 -3
- package/dist/cli/shot/capture.d.ts +32 -3
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +17 -7
- package/dist/dashboard/meter-model.d.ts +17 -3
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +69 -19
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +28 -12
- package/dist/dashboard/meter.module.css +12 -1
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +89 -21
- package/dist/dashboard/stat-strip.module.css +13 -3
- package/dist/dashboard/stat-strip.module.css.d.ts +1 -0
- package/llms.txt +3 -2
- package/package.json +1 -1
- package/src/charts/Bars.tsx +50 -2
- package/src/charts/ChartCard.tsx +9 -1
- package/src/charts/Sparkline.tsx +67 -9
- package/src/charts/chart-box.module.css +76 -1
- package/src/charts/chart-box.module.css.d.ts +1 -0
- package/src/charts/chart-legend.module.css +0 -14
- package/src/charts/compile.ts +129 -18
- package/src/charts/legend.tsx +10 -74
- package/src/charts/state.tsx +30 -5
- package/src/cli/shot/capture.ts +25 -9
- package/src/dashboard/meter-model.ts +122 -31
- package/src/dashboard/meter-parts.tsx +53 -19
- package/src/dashboard/meter.module.css +12 -1
- package/src/dashboard/stat-strip.module.css +13 -3
- package/src/dashboard/stat-strip.module.css.d.ts +1 -0
- package/src/dashboard/stat-strip.tsx +113 -25
|
@@ -89,8 +89,51 @@ function findHoldingZone(zones, value) {
|
|
|
89
89
|
}
|
|
90
90
|
const LABEL_SUBPIXEL = 0.5;
|
|
91
91
|
function placeRowLabels(labels, rowWidth, gap = 0) {
|
|
92
|
+
const full = layOut(
|
|
93
|
+
labels.map(({ short: _short, ...l }) => l),
|
|
94
|
+
rowWidth,
|
|
95
|
+
gap
|
|
96
|
+
);
|
|
97
|
+
if (full.shown.every(Boolean) || labels.every((l) => l.short === void 0)) return full;
|
|
98
|
+
const withShort = layOut(labels, rowWidth, gap);
|
|
99
|
+
return withShort.shown.filter(Boolean).length > full.shown.filter(Boolean).length ? withShort : full;
|
|
100
|
+
}
|
|
101
|
+
function layOut(labels, rowWidth, gap) {
|
|
92
102
|
const first = placeOnce(labels, rowWidth, gap, false);
|
|
93
|
-
|
|
103
|
+
const registerShort = first.short.some(Boolean);
|
|
104
|
+
const one = registerShort ? placeOnce(labels, rowWidth, gap, true) : first;
|
|
105
|
+
return stagger(labels, one, rowWidth, gap, registerShort);
|
|
106
|
+
}
|
|
107
|
+
function stagger(labels, one, rowWidth, gap, registerShort) {
|
|
108
|
+
const row = labels.map(() => 0);
|
|
109
|
+
const { shown, short, shift } = one;
|
|
110
|
+
const kept = [];
|
|
111
|
+
const rank = (l) => l.end ? 0 : l.span ? 2 : 1;
|
|
112
|
+
const pending = labels.map((_, i) => i).filter((i) => !shown[i] && labels[i]?.figure !== true).toSorted((a, b) => rank(labels[a]) - rank(labels[b]));
|
|
113
|
+
const clamped = (b) => {
|
|
114
|
+
const width = b.right - b.left;
|
|
115
|
+
const left = Math.max(0, Math.min(b.left, rowWidth - width));
|
|
116
|
+
return { left, right: left + width };
|
|
117
|
+
};
|
|
118
|
+
const clears = (b) => !kept.some(
|
|
119
|
+
(k) => b.left < k.right + gap - LABEL_SUBPIXEL && k.left < b.right + gap - LABEL_SUBPIXEL
|
|
120
|
+
);
|
|
121
|
+
for (const i of pending) {
|
|
122
|
+
const label = labels[i];
|
|
123
|
+
const useShort = registerShort && label.short !== void 0;
|
|
124
|
+
const candidates = useShort ? [label.short] : label.short !== void 0 ? [label.box, label.short] : [label.box];
|
|
125
|
+
for (const base of candidates) {
|
|
126
|
+
const box = clamped(base);
|
|
127
|
+
if (box.right - box.left > rowWidth + LABEL_SUBPIXEL || !clears(box)) continue;
|
|
128
|
+
kept.push(box);
|
|
129
|
+
shown[i] = true;
|
|
130
|
+
short[i] = base !== label.box;
|
|
131
|
+
shift[i] = box.left - base.left;
|
|
132
|
+
row[i] = 1;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return { shown, short, shift, row };
|
|
94
137
|
}
|
|
95
138
|
function placeOnce(labels, rowWidth, gap, registerShort) {
|
|
96
139
|
const shown = labels.map(() => false);
|
|
@@ -99,31 +142,38 @@ function placeOnce(labels, rowWidth, gap, registerShort) {
|
|
|
99
142
|
const kept = [];
|
|
100
143
|
const rank = (l) => l.holding ? 0 : l.span ? 3 : l.end ? 2 : 1;
|
|
101
144
|
const order = labels.map((_, i) => i).toSorted((a, b) => rank(labels[a]) - rank(labels[b]));
|
|
102
|
-
const clears = (b
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return b.left < k.right + pad - LABEL_SUBPIXEL && k.left < b.right + pad - LABEL_SUBPIXEL;
|
|
106
|
-
});
|
|
145
|
+
const clears = (b) => !kept.some(
|
|
146
|
+
({ box: k }) => b.left < k.right + gap - LABEL_SUBPIXEL && k.left < b.right + gap - LABEL_SUBPIXEL
|
|
147
|
+
);
|
|
107
148
|
for (const i of order) {
|
|
108
149
|
const label = labels[i];
|
|
109
150
|
const { span } = label;
|
|
110
151
|
const tick = span === void 0 && !label.holding;
|
|
111
152
|
let box = label.box;
|
|
153
|
+
if (tick) {
|
|
154
|
+
const width = box.right - box.left;
|
|
155
|
+
const left = Math.max(0, Math.min(box.left, rowWidth - width));
|
|
156
|
+
shift[i] = left - box.left;
|
|
157
|
+
box = { left, right: left + width };
|
|
158
|
+
}
|
|
112
159
|
if (label.holding) {
|
|
113
160
|
const width = box.right - box.left;
|
|
114
161
|
const left = Math.max(0, Math.min(box.left, rowWidth - width));
|
|
115
162
|
shift[i] = left - box.left;
|
|
116
163
|
box = { left, right: left + width };
|
|
117
|
-
if (!clears(box
|
|
164
|
+
if (!clears(box)) continue;
|
|
118
165
|
shown[i] = true;
|
|
119
166
|
kept.push({ box, tick: false, i });
|
|
120
167
|
continue;
|
|
121
168
|
}
|
|
122
|
-
const fits = (b) => b.left >= -LABEL_SUBPIXEL && b.right <= rowWidth + LABEL_SUBPIXEL && (span === void 0 || b.left >= span.left - LABEL_SUBPIXEL && b.right <= span.right + LABEL_SUBPIXEL) && clears(b
|
|
169
|
+
const fits = (b) => b.left >= -LABEL_SUBPIXEL && b.right <= rowWidth + LABEL_SUBPIXEL && (span === void 0 || b.left >= span.left - LABEL_SUBPIXEL && b.right <= span.right + LABEL_SUBPIXEL) && clears(b);
|
|
123
170
|
const useShort = label.short !== void 0 && (registerShort ? true : !fits(box)) && fits(label.short);
|
|
124
171
|
if (registerShort && label.short !== void 0 && !useShort) continue;
|
|
125
172
|
if (useShort) box = label.short;
|
|
126
|
-
else if (!fits(box))
|
|
173
|
+
else if (!fits(box)) {
|
|
174
|
+
shift[i] = 0;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
127
177
|
shown[i] = true;
|
|
128
178
|
short[i] = useShort;
|
|
129
179
|
kept.push({ box, tick, i });
|
|
@@ -133,7 +183,7 @@ function placeOnce(labels, rowWidth, gap, registerShort) {
|
|
|
133
183
|
const { span } = label;
|
|
134
184
|
const centre = (b) => (b.left + b.right) / 2;
|
|
135
185
|
const others = kept.filter((k) => k.i !== i);
|
|
136
|
-
const movable = (k) => !k.tick
|
|
186
|
+
const movable = (k) => !k.tick;
|
|
137
187
|
const fixed = others.filter((k) => !movable(k));
|
|
138
188
|
const slidable = others.filter(movable);
|
|
139
189
|
const base = registerShort && label.short ? label.short : label.box;
|
|
@@ -141,7 +191,7 @@ function placeOnce(labels, rowWidth, gap, registerShort) {
|
|
|
141
191
|
const touches = (a, b) => a.left < b.right + gap - LABEL_SUBPIXEL && b.left < a.right + gap - LABEL_SUBPIXEL;
|
|
142
192
|
if (base.left < -LABEL_SUBPIXEL || base.right > rowWidth + LABEL_SUBPIXEL || others.some((k) => k.tick && touches(base, k.box)) || fixed.some((f) => f.box.left < mid && f.box.right > mid))
|
|
143
193
|
continue;
|
|
144
|
-
const rightOf = slidable.filter((k) => centre(k.box)
|
|
194
|
+
const rightOf = slidable.filter((k) => centre(k.box) >= mid).toSorted((a, b) => b.box.left - a.box.left);
|
|
145
195
|
const leftOf = slidable.filter((k) => centre(k.box) < mid).toSorted((a, b) => a.box.left - b.box.left);
|
|
146
196
|
const place = (b, lo, hi) => {
|
|
147
197
|
const left = Math.max(lo, Math.min(b.left, hi - (b.right - b.left)));
|
|
@@ -153,34 +203,34 @@ function placeOnce(labels, rowWidth, gap, registerShort) {
|
|
|
153
203
|
for (const k of rightOf) {
|
|
154
204
|
const w = k.box.right - k.box.left;
|
|
155
205
|
const stop = right ? Math.min(
|
|
156
|
-
(labels[k.i]?.span?.right ?? rowWidth) + LABEL_SUBPIXEL,
|
|
206
|
+
(labels[k.i]?.span?.right ?? rowWidth) + w / 2 + LABEL_SUBPIXEL,
|
|
157
207
|
hi,
|
|
158
|
-
...fixed.filter((f) => f.box.left >= k.box.left).map((f) => f.box.left -
|
|
208
|
+
...fixed.filter((f) => f.box.left >= k.box.left).map((f) => f.box.left - gap)
|
|
159
209
|
) : k.box.left + w;
|
|
160
210
|
const at = Math.max(k.box.left, stop - w);
|
|
161
211
|
slides.set(k.i, at - k.box.left);
|
|
162
|
-
hi = at;
|
|
212
|
+
hi = at - gap;
|
|
163
213
|
}
|
|
164
214
|
let lo = 0;
|
|
165
215
|
for (const k of leftOf) {
|
|
166
216
|
const w = k.box.right - k.box.left;
|
|
167
217
|
const stop = left ? Math.max(
|
|
168
|
-
(labels[k.i]?.span?.left ?? 0) - LABEL_SUBPIXEL,
|
|
218
|
+
(labels[k.i]?.span?.left ?? 0) - w / 2 - LABEL_SUBPIXEL,
|
|
169
219
|
lo,
|
|
170
|
-
...fixed.filter((f) => f.box.right <= k.box.right).map((f) => f.box.right +
|
|
220
|
+
...fixed.filter((f) => f.box.right <= k.box.right).map((f) => f.box.right + gap)
|
|
171
221
|
) : k.box.left;
|
|
172
222
|
const at = Math.min(k.box.left, stop);
|
|
173
223
|
slides.set(k.i, at - k.box.left);
|
|
174
|
-
lo = at + w;
|
|
224
|
+
lo = at + w + gap;
|
|
175
225
|
}
|
|
176
226
|
const gapLo = Math.max(
|
|
177
227
|
lo,
|
|
178
|
-
...fixed.filter((f) => f.box.right <= mid).map((f) => f.box.right +
|
|
228
|
+
...fixed.filter((f) => f.box.right <= mid).map((f) => f.box.right + gap),
|
|
179
229
|
0
|
|
180
230
|
);
|
|
181
231
|
const gapHi = Math.min(
|
|
182
232
|
hi,
|
|
183
|
-
...fixed.filter((f) => f.box.left >= mid).map((f) => f.box.left -
|
|
233
|
+
...fixed.filter((f) => f.box.left >= mid).map((f) => f.box.left - gap),
|
|
184
234
|
rowWidth
|
|
185
235
|
);
|
|
186
236
|
return { slides, gapLo, gapHi };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meter-parts.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter-parts.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAa,MAAM,OAAO,CAAA;AAgBhE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"meter-parts.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter-parts.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAa,MAAM,OAAO,CAAA;AAgBhE,OAAO,KAAK,EAGV,YAAY,EACZ,SAAS,EACT,SAAS,EAMV,MAAM,eAAe,CAAA;AAKtB,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,KAAK,EAAE,aAAa,GAAG,SAAS,CAAA;IAChC,yDAAyD;IACzD,GAAG,EAAE,OAAO,CAAA;CACb,CAAA;AAsGD,sGAAsG;AACtG,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,+BAOjF;AAID,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;IACxB,IAAI,EAAE,OAAO,CAAA;IACb,KAAK,EAAE,OAAO,CAAA;IACd,KAAK,EAAE,KAAK,CAAA;CACb,+BAgCA;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAAA;IACvC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IACjC,KAAK,EAAE,KAAK,CAAA;CACb,+BAsBA;AA4dD,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IACjC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,CAAA;IAC7C,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAAA;IACvC,KAAK,EAAE,SAAS;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,SAAS,CAAA;IAC3D,KAAK,EAAE,OAAO,GAAG,SAAS,CAAA;IAC1B,aAAa,EAAE,OAAO,GAAG,SAAS,CAAA;IAClC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAAA;IACvC,IAAI,EAAE,OAAO,GAAG,SAAS,CAAA;IACzB,eAAe,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC,YAAY,EAAE,SAAS,CAAA;IACvB,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAA;IACvC,+FAA+F;IAC/F,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,KAAK,CAAA;CACb,+BA6NA"}
|
|
@@ -145,10 +145,10 @@ function zoneStyle(zone, index, count, min, span) {
|
|
|
145
145
|
}
|
|
146
146
|
const columnGapOf = (el) => Number.parseFloat(getComputedStyle(el).columnGap) || 0;
|
|
147
147
|
const sameLayout = (a, b) => a.shown.length === b.shown.length && a.shown.every(
|
|
148
|
-
(v, i) => v === b.shown[i] && a.short[i] === b.short[i] && a.shift[i] === b.shift[i]
|
|
148
|
+
(v, i) => v === b.shown[i] && a.short[i] === b.short[i] && a.shift[i] === b.shift[i] && a.row[i] === b.row[i]
|
|
149
149
|
);
|
|
150
150
|
function useRowLabelLayout(rowRef, slots, shortOf, key) {
|
|
151
|
-
const [layout, setLayout] = useState({ shown: [], short: [], shift: [] });
|
|
151
|
+
const [layout, setLayout] = useState({ shown: [], short: [], shift: [], row: [] });
|
|
152
152
|
const slotsRef = useRef(slots);
|
|
153
153
|
const shortOfRef = useRef(shortOf);
|
|
154
154
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -163,28 +163,34 @@ function useRowLabelLayout(rowRef, slots, shortOf, key) {
|
|
|
163
163
|
const rtl = getComputedStyle(row).direction === "rtl";
|
|
164
164
|
const edge = (pct) => origin.width * (rtl ? 100 - pct : pct) / 100;
|
|
165
165
|
const children = [...row.children];
|
|
166
|
-
const
|
|
166
|
+
const naturalBox = (c) => {
|
|
167
167
|
const r = c.getBoundingClientRect();
|
|
168
|
+
const by = Number.parseFloat(c.style.getPropertyValue("--basalt-nudge")) || 0;
|
|
169
|
+
return { left: r.left - origin.left - by, right: r.right - origin.left - by };
|
|
170
|
+
};
|
|
171
|
+
const labels = children.slice(0, slotsRef.current.length).map((c, i) => {
|
|
168
172
|
const slot = slotsRef.current[i];
|
|
169
173
|
const pct = slot?.spanPct;
|
|
170
174
|
const [a, b] = pct ? [edge(pct[0]), edge(pct[1])] : [];
|
|
171
175
|
return {
|
|
172
|
-
box:
|
|
176
|
+
box: naturalBox(c),
|
|
173
177
|
...a !== void 0 && b !== void 0 && { span: { left: Math.min(a, b), right: Math.max(a, b) } },
|
|
174
178
|
...slot?.holding && { holding: true },
|
|
175
|
-
...slot?.end && { end: true }
|
|
179
|
+
...slot?.end && { end: true },
|
|
180
|
+
...slot?.figure && { figure: true }
|
|
176
181
|
};
|
|
177
182
|
});
|
|
178
183
|
shortOfRef.current.forEach((labelIndex, n) => {
|
|
179
|
-
const
|
|
184
|
+
const twin = children[slotsRef.current.length + n];
|
|
180
185
|
const label = labels[labelIndex];
|
|
181
|
-
if (
|
|
186
|
+
if (twin && label) label.short = naturalBox(twin);
|
|
182
187
|
});
|
|
183
188
|
const placed = placeRowLabels(labels, origin.width, columnGapOf(row));
|
|
184
189
|
const next = {
|
|
185
190
|
shown: placed.shown,
|
|
186
191
|
short: placed.short,
|
|
187
|
-
shift: placed.shift
|
|
192
|
+
shift: placed.shift,
|
|
193
|
+
row: placed.row
|
|
188
194
|
};
|
|
189
195
|
setLayout((prev) => sameLayout(prev, next) ? prev : next);
|
|
190
196
|
};
|
|
@@ -239,7 +245,11 @@ const TICK_LABEL_FLIP_PCT = 50;
|
|
|
239
245
|
function LabelRow({ zones, ticks }) {
|
|
240
246
|
const rowRef = useRef(null);
|
|
241
247
|
const slots = [
|
|
242
|
-
|
|
248
|
+
// The scale's own start figure (key `start`) drops before it wraps: it never takes the second row.
|
|
249
|
+
...ticks.map((t) => ({
|
|
250
|
+
...t.pct <= 0 || t.pct >= 100 ? { end: true } : {},
|
|
251
|
+
...t.key === "start" && { figure: true }
|
|
252
|
+
})),
|
|
243
253
|
...zones.map((z) => ({
|
|
244
254
|
spanPct: [z.centrePct - z.widthPct / 2, z.centrePct + z.widthPct / 2],
|
|
245
255
|
holding: z.holding
|
|
@@ -250,19 +260,22 @@ function LabelRow({ zones, ticks }) {
|
|
|
250
260
|
...zones.map((z) => `${z.label}${z.holding ? "*" : ""}@${z.centrePct}`)
|
|
251
261
|
].join("\0");
|
|
252
262
|
const twins = zones.flatMap((z, i) => z.short !== void 0 && !z.holding ? [i] : []);
|
|
253
|
-
const { shown, short, shift } = useRowLabelLayout(
|
|
263
|
+
const { shown, short, shift, row } = useRowLabelLayout(
|
|
254
264
|
rowRef,
|
|
255
265
|
slots,
|
|
256
266
|
twins.map((i) => ticks.length + i),
|
|
257
267
|
`${key}${twins.map((i) => zones[i]?.short).join("\0")}`
|
|
258
268
|
);
|
|
259
269
|
const hidden = (i) => shown[i] === false || short[i] === true ? "" : void 0;
|
|
260
|
-
const
|
|
270
|
+
const second = (i) => shown[i] === true && row[i] === 1 ? "" : void 0;
|
|
271
|
+
const rows = row.some((r, i) => r === 1 && shown[i] === true) ? 2 : 1;
|
|
272
|
+
const nudge = (i) => shift[i] ? { "--basalt-nudge": `${shift[i]}px` } : {};
|
|
261
273
|
return /* @__PURE__ */ jsxs(
|
|
262
274
|
"div",
|
|
263
275
|
{
|
|
264
276
|
ref: rowRef,
|
|
265
277
|
className: classes.labelRow,
|
|
278
|
+
"data-meter-rows": rows,
|
|
266
279
|
...zones.length > 0 ? { "data-meter-zone-band": "" } : { "data-meter-tick-band": "" },
|
|
267
280
|
"aria-hidden": true,
|
|
268
281
|
children: [
|
|
@@ -272,7 +285,8 @@ function LabelRow({ zones, ticks }) {
|
|
|
272
285
|
className: classes.rowLabel,
|
|
273
286
|
"data-meter-tick-label": "",
|
|
274
287
|
"data-hidden": hidden(i),
|
|
275
|
-
|
|
288
|
+
"data-row2": second(i),
|
|
289
|
+
style: t.pct > TICK_LABEL_FLIP_PCT ? { insetInlineEnd: `${100 - t.pct}%`, ...nudge(i) } : { insetInlineStart: `${t.pct}%`, ...nudge(i) },
|
|
276
290
|
children: t.label
|
|
277
291
|
},
|
|
278
292
|
`t${t.key}`
|
|
@@ -284,6 +298,7 @@ function LabelRow({ zones, ticks }) {
|
|
|
284
298
|
"data-meter-zone-label": z.label,
|
|
285
299
|
"data-holding": z.holding || void 0,
|
|
286
300
|
"data-hidden": hidden(ticks.length + i),
|
|
301
|
+
"data-row2": second(ticks.length + i),
|
|
287
302
|
style: { insetInlineStart: `${z.centrePct}%`, ...nudge(ticks.length + i) },
|
|
288
303
|
children: z.label
|
|
289
304
|
},
|
|
@@ -298,6 +313,7 @@ function LabelRow({ zones, ticks }) {
|
|
|
298
313
|
className: cx(classes.rowLabel, classes.zoneLabel),
|
|
299
314
|
"data-meter-zone-short": z.label,
|
|
300
315
|
"data-hidden": short[i] === true ? void 0 : "",
|
|
316
|
+
"data-row2": second(i),
|
|
301
317
|
style: { insetInlineStart: `${z.centrePct}%`, ...nudge(i) },
|
|
302
318
|
children: z.short
|
|
303
319
|
},
|
|
@@ -101,10 +101,21 @@
|
|
|
101
101
|
--basalt-reading-dir: -1;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/* A label that cannot hold its place on the first row stands on a second, directly under it. */
|
|
105
|
+
.labelRow[data-meter-rows='2'] {
|
|
106
|
+
height: 2.5em;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.rowLabel[data-row2] {
|
|
110
|
+
top: 1.25em;
|
|
111
|
+
}
|
|
112
|
+
|
|
104
113
|
.rowLabel {
|
|
105
114
|
position: absolute;
|
|
106
115
|
top: 0;
|
|
107
116
|
white-space: nowrap;
|
|
117
|
+
/* The placement's physical offset (a label kept inside the row): both anchors, either direction. */
|
|
118
|
+
translate: var(--basalt-nudge, 0px) 0;
|
|
108
119
|
}
|
|
109
120
|
|
|
110
121
|
.rowLabel[data-hidden] {
|
|
@@ -113,7 +124,7 @@
|
|
|
113
124
|
|
|
114
125
|
/* A zone name is centred on its span: the physical `translate` flips sign in RTL. */
|
|
115
126
|
.zoneLabel {
|
|
116
|
-
translate: calc(-50% * var(--basalt-reading-dir)) 0;
|
|
127
|
+
translate: calc(-50% * var(--basalt-reading-dir) + var(--basalt-nudge, 0px)) 0;
|
|
117
128
|
}
|
|
118
129
|
|
|
119
130
|
.zoneLabelHolding {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stat-strip.d.ts","sourceRoot":"","sources":["../../src/dashboard/stat-strip.tsx"],"names":[],"mappings":"AA4CA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"stat-strip.d.ts","sourceRoot":"","sources":["../../src/dashboard/stat-strip.tsx"],"names":[],"mappings":"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"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Card, Skeleton } from "@mantine/core";
|
|
3
|
-
import { useId } from "react";
|
|
3
|
+
import { useId, useRef } from "react";
|
|
4
4
|
import { toErrorMessage } from "../common/errors.js";
|
|
5
|
+
import { useIsomorphicLayoutEffect } from "../common/isomorphic-layout-effect.js";
|
|
5
6
|
import { cx } from "../common/props.js";
|
|
6
7
|
import { RetryButton } from "../common/retry-button.js";
|
|
7
8
|
import { StatusDot } from "../theme/status-dot.js";
|
|
@@ -100,27 +101,29 @@ function StripCell({
|
|
|
100
101
|
...state === void 0 && rows !== void 0 && { "data-strip-has-rows": "" },
|
|
101
102
|
...cell.stale && { "data-stale": "true" },
|
|
102
103
|
children: [
|
|
103
|
-
/* @__PURE__ */ jsxs("div", { className: classes.
|
|
104
|
-
/* @__PURE__ */ jsxs("div", { className: classes.
|
|
105
|
-
/* @__PURE__ */ jsxs("
|
|
106
|
-
/* @__PURE__ */
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
104
|
+
/* @__PURE__ */ jsxs("div", { className: classes.head, "data-strip-head": true, children: [
|
|
105
|
+
/* @__PURE__ */ jsxs("div", { className: classes.captionLine, children: [
|
|
106
|
+
/* @__PURE__ */ jsxs("div", { className: classes.captionMain, children: [
|
|
107
|
+
/* @__PURE__ */ jsxs("span", { className: classes.lead, children: [
|
|
108
|
+
/* @__PURE__ */ jsx(
|
|
109
|
+
"span",
|
|
110
|
+
{
|
|
111
|
+
className: classes.caption,
|
|
112
|
+
id: captionId,
|
|
113
|
+
title: cell.caption,
|
|
114
|
+
"data-strip-caption": true,
|
|
115
|
+
children: cell.caption
|
|
116
|
+
}
|
|
117
|
+
),
|
|
118
|
+
cell.info !== void 0 && /* @__PURE__ */ jsx(InfoGlyph, { text: cell.info })
|
|
119
|
+
] }),
|
|
120
|
+
cell.qualifier !== void 0 && /* @__PURE__ */ jsx("span", { className: classes.qualifier, children: cell.qualifier })
|
|
117
121
|
] }),
|
|
118
|
-
cell.
|
|
122
|
+
cell.action !== void 0 && /* @__PURE__ */ jsx("span", { className: classes.action, "data-strip-action": true, children: cell.action })
|
|
119
123
|
] }),
|
|
120
|
-
|
|
124
|
+
state !== void 0 && /* @__PURE__ */ jsx(CellState, { state }),
|
|
125
|
+
state === void 0 && hasHero && heroEl
|
|
121
126
|
] }),
|
|
122
|
-
state !== void 0 && /* @__PURE__ */ jsx(CellState, { state }),
|
|
123
|
-
state === void 0 && hasHero && heroEl,
|
|
124
127
|
state === void 0 && cell.visual !== void 0 && /* @__PURE__ */ jsxs(
|
|
125
128
|
"div",
|
|
126
129
|
{
|
|
@@ -135,7 +138,7 @@ function StripCell({
|
|
|
135
138
|
),
|
|
136
139
|
state === void 0 && rows !== void 0 && (loading ? /* @__PURE__ */ jsx("div", { className: classes.rows, "aria-hidden": "true", children: rows.map((row) => /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonRow, radius: "sm" }, row.key)) }) : /* @__PURE__ */ jsx("ul", { className: classes.rows, "data-strip-rows": true, children: rows.map((row) => /* @__PURE__ */ jsxs("li", { className: classes.row, "data-strip-row": row.key, children: [
|
|
137
140
|
/* @__PURE__ */ jsx("span", { className: classes.rowLabel, children: row.label }),
|
|
138
|
-
/* @__PURE__ */ jsx("span", { className: classes.visual, children: row.visual }),
|
|
141
|
+
/* @__PURE__ */ jsx("span", { className: classes.visual, children: /* @__PURE__ */ jsx(VisualSlotContext.Provider, { value: HOSTED, children: row.visual }) }),
|
|
139
142
|
/* @__PURE__ */ jsx("span", { className: classes.rowValue, children: row.hideValue ? null : row.value ?? EMPTY }),
|
|
140
143
|
/* @__PURE__ */ jsx("span", { children: row.delta })
|
|
141
144
|
] }, row.key)) })),
|
|
@@ -147,6 +150,34 @@ function StripCell({
|
|
|
147
150
|
] })
|
|
148
151
|
);
|
|
149
152
|
}
|
|
153
|
+
const DRAWN_MARK = "[data-meter-track], [data-basalt-sparkline], [data-basalt-chart]";
|
|
154
|
+
function alignVisuals(root) {
|
|
155
|
+
const rows = /* @__PURE__ */ new Map();
|
|
156
|
+
for (const head of root.querySelectorAll("[data-strip-head]")) {
|
|
157
|
+
const article = head.parentElement;
|
|
158
|
+
const visual = article?.querySelector("[data-strip-visual]");
|
|
159
|
+
const plot = visual?.querySelector(DRAWN_MARK) ?? visual?.firstElementChild;
|
|
160
|
+
const last = head.lastElementChild;
|
|
161
|
+
if (!article || !plot || !last) continue;
|
|
162
|
+
const { top, bottom } = head.getBoundingClientRect();
|
|
163
|
+
const articleTop = article.getBoundingClientRect().top;
|
|
164
|
+
const natural = last.getBoundingClientRect().bottom - top;
|
|
165
|
+
const grown = bottom - top - natural;
|
|
166
|
+
const key = Math.round(articleTop);
|
|
167
|
+
rows.set(key, [
|
|
168
|
+
...rows.get(key) ?? [],
|
|
169
|
+
{ head, natural, offset: plot.getBoundingClientRect().top - articleTop - Math.max(grown, 0) }
|
|
170
|
+
]);
|
|
171
|
+
}
|
|
172
|
+
for (const cells of rows.values()) {
|
|
173
|
+
const target = cells.length < 2 ? 0 : Math.max(...cells.map((c) => c.offset));
|
|
174
|
+
for (const { head, natural, offset } of cells) {
|
|
175
|
+
const grow = target - offset;
|
|
176
|
+
const next = grow > 0.5 ? `${natural + grow}px` : "";
|
|
177
|
+
if (head.style.minHeight !== next) head.style.minHeight = next;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
150
181
|
function StatStrip({
|
|
151
182
|
label,
|
|
152
183
|
cells,
|
|
@@ -163,6 +194,43 @@ function StatStrip({
|
|
|
163
194
|
const rest = footer?.filter((entry) => entry.under === void 0 || !keys.has(entry.under)) ?? [];
|
|
164
195
|
const hasQualifier = cells.some((cell) => cell.qualifier !== void 0);
|
|
165
196
|
const hasAction = cells.some((cell) => cell.action !== void 0);
|
|
197
|
+
const gridRef = useRef(null);
|
|
198
|
+
const observerRef = useRef(null);
|
|
199
|
+
const watched = useRef("");
|
|
200
|
+
useIsomorphicLayoutEffect(() => {
|
|
201
|
+
const grid = gridRef.current;
|
|
202
|
+
if (!grid || typeof ResizeObserver === "undefined") return;
|
|
203
|
+
let frame = 0;
|
|
204
|
+
let live = true;
|
|
205
|
+
const schedule = () => {
|
|
206
|
+
cancelAnimationFrame(frame);
|
|
207
|
+
frame = requestAnimationFrame(() => alignVisuals(grid));
|
|
208
|
+
};
|
|
209
|
+
const observer = new ResizeObserver(schedule);
|
|
210
|
+
observerRef.current = observer;
|
|
211
|
+
void document.fonts?.ready?.then(() => {
|
|
212
|
+
if (live) schedule();
|
|
213
|
+
});
|
|
214
|
+
return () => {
|
|
215
|
+
live = false;
|
|
216
|
+
cancelAnimationFrame(frame);
|
|
217
|
+
observer.disconnect();
|
|
218
|
+
observerRef.current = null;
|
|
219
|
+
watched.current = "";
|
|
220
|
+
};
|
|
221
|
+
}, []);
|
|
222
|
+
useIsomorphicLayoutEffect(() => {
|
|
223
|
+
const grid = gridRef.current;
|
|
224
|
+
if (!grid) return;
|
|
225
|
+
alignVisuals(grid);
|
|
226
|
+
const observer = observerRef.current;
|
|
227
|
+
const key = cells.map((cell) => cell.key).join("|");
|
|
228
|
+
if (!observer || watched.current === key) return;
|
|
229
|
+
watched.current = key;
|
|
230
|
+
observer.disconnect();
|
|
231
|
+
observer.observe(grid);
|
|
232
|
+
for (const head of grid.querySelectorAll("[data-strip-head]")) observer.observe(head);
|
|
233
|
+
}, [cells, footer]);
|
|
166
234
|
return /* @__PURE__ */ jsx("div", { className: cx(classes.container, className), style, children: /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(
|
|
167
235
|
Card.Section,
|
|
168
236
|
{
|
|
@@ -176,7 +244,7 @@ function StatStrip({
|
|
|
176
244
|
"--basalt-strip-cols-sm": mid
|
|
177
245
|
},
|
|
178
246
|
children: [
|
|
179
|
-
/* @__PURE__ */ jsx("div", { className: classes.cells, children: cells.map((cell) => /* @__PURE__ */ jsx(
|
|
247
|
+
/* @__PURE__ */ jsx("div", { ref: gridRef, className: classes.cells, children: cells.map((cell) => /* @__PURE__ */ jsx(
|
|
180
248
|
StripCell,
|
|
181
249
|
{
|
|
182
250
|
cell,
|
|
@@ -66,11 +66,22 @@
|
|
|
66
66
|
* every cell of a row (one caption line; a reserved qualifier line in a narrow cell when any cell has
|
|
67
67
|
* a qualifier), so a row shares one caption top and one value baseline. Below the value each cell
|
|
68
68
|
* stacks its own parts and ends at its last one. */
|
|
69
|
-
|
|
69
|
+
/* The HEAD (caption line, qualifier, value row) is one block with its own height: a longer qualifier
|
|
70
|
+
* pushes only its own value down. A visual cell whose head is shorter than a sibling's visual offset
|
|
71
|
+
* grows its head's min-height (`alignVisuals`), so the drawn visuals of a row share one top. */
|
|
72
|
+
.head {
|
|
73
|
+
display: flex;
|
|
74
|
+
flex-direction: column;
|
|
75
|
+
min-width: 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.content > *,
|
|
79
|
+
.head > * {
|
|
70
80
|
min-width: 0;
|
|
71
81
|
}
|
|
72
82
|
|
|
73
|
-
.content > :not(.
|
|
83
|
+
.content > :not(.head),
|
|
84
|
+
.head > :not(.captionLine) {
|
|
74
85
|
margin-block-start: var(--vx-space-stack-sm);
|
|
75
86
|
}
|
|
76
87
|
|
|
@@ -272,7 +283,6 @@
|
|
|
272
283
|
.visual:has([data-basalt-sparkline], [data-basalt-chart]) {
|
|
273
284
|
padding-top: max(0px, calc(var(--basalt-spark-readout-h) - var(--vx-space-stack-sm)));
|
|
274
285
|
}
|
|
275
|
-
|
|
276
286
|
/* The state copy keeps the cell's inset on every side: the article ends at its own last track, so the
|
|
277
287
|
* foot inset (carried by the row-high slot, further down) cannot reach it. */
|
|
278
288
|
.content[data-strip-has-state] {
|
package/llms.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# basalt-ui v2.
|
|
1
|
+
# basalt-ui v2.27.0
|
|
2
2
|
# Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets
|
|
3
3
|
#
|
|
4
4
|
# Entry points: use the exact import specifier below; do not guess.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# A subpath's `Install:` line is its required peers; `OptionalPeers:` are import()-only, install on use.
|
|
14
14
|
|
|
15
15
|
Package: basalt-ui
|
|
16
|
-
Version: 2.
|
|
16
|
+
Version: 2.27.0
|
|
17
17
|
|
|
18
18
|
## basalt-ui
|
|
19
19
|
Import: import { ... } from 'basalt-ui'
|
|
@@ -385,6 +385,7 @@ Signature: ChartCard(props: ChartCardProps): ReactElement<unknown, string | JSXE
|
|
|
385
385
|
actions?: ReactNode
|
|
386
386
|
state?: ChartState
|
|
387
387
|
placeholderHeight?: number | ResponsiveChartHeight | "content"
|
|
388
|
+
ghost?: number | "line" | "bars"
|
|
388
389
|
stale?: boolean
|
|
389
390
|
stateNoun?: string
|
|
390
391
|
onRetry?: (() => void)
|
package/package.json
CHANGED
package/src/charts/Bars.tsx
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
* stack diverges around the baseline (the 1.x `negativeBars`, now just a signed value). Zones,
|
|
5
5
|
* reference lines, legend, cursor and tooltip are the rung's. In a visual slot (a `StatCard`
|
|
6
6
|
* `sparkline`, a strip cell's `visual`) it drops both axes, the grid, the margin and the legend and
|
|
7
|
-
* fills the slot like a `Sparkline`: a small histogram
|
|
7
|
+
* fills the slot like a `Sparkline`: a small histogram whose tooltip is the one-line chip
|
|
8
|
+
* (`<value> · <x label>`) in the line the host reserves above the plot.
|
|
8
9
|
*/
|
|
9
10
|
import { barY } from '@tanstack/charts/bar'
|
|
11
|
+
import { dot } from '@tanstack/charts/dot'
|
|
10
12
|
import { group } from '@tanstack/charts/group'
|
|
11
13
|
import { stack } from '@tanstack/charts/stack'
|
|
12
14
|
import { useCallback, useContext, useMemo } from 'react'
|
|
@@ -66,6 +68,8 @@ export type BarsProps<T, X extends ChartX = ChartX> = Omit<
|
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
const DEFAULT_BAR_OPACITY = 0.85
|
|
71
|
+
/** The empty-bin marker's radius, px: the plot's floor clips it to a 2px-high tick. */
|
|
72
|
+
const EMPTY_BIN_R = 2
|
|
69
73
|
/** The faintest shade told-apart-by-shade series step down to. */
|
|
70
74
|
const SHADE_FLOOR = 0.4
|
|
71
75
|
|
|
@@ -104,12 +108,55 @@ function guardLogStack(layout: string, onLog: boolean): void {
|
|
|
104
108
|
warnedLogStack = true
|
|
105
109
|
}
|
|
106
110
|
|
|
111
|
+
/**
|
|
112
|
+
* A slotted chart has no axes to name the hovered bin, and an empty bin has no bar to light: the
|
|
113
|
+
* readout says `0 runs · 16 Oct 02:00` and nothing in the plot would mark where. Each bin whose
|
|
114
|
+
* stack sums to zero gets a baseline mark (a half-dot on the plot's floor), hidden until that x is hovered (the same `focus: 'x'`
|
|
115
|
+
* state that takes a drawn bar to full strength).
|
|
116
|
+
*/
|
|
117
|
+
function emptyBinTicks<T, X extends ChartX>(rows: readonly PlotRow<T, X>[]): ChartMarks {
|
|
118
|
+
// A gap (`y: null` on every series) is an absence, not a zero: only a bin with a value counts.
|
|
119
|
+
const sums = new Map<string, { row: PlotRow<T, X>; sum: number; values: number }>()
|
|
120
|
+
for (const row of rows) {
|
|
121
|
+
const key = String(row.x instanceof Date ? row.x.getTime() : row.x)
|
|
122
|
+
const entry = sums.get(key) ?? { row, sum: 0, values: 0 }
|
|
123
|
+
if (row.y !== null && Number.isFinite(row.y)) {
|
|
124
|
+
entry.sum += Math.abs(row.y)
|
|
125
|
+
entry.values += 1
|
|
126
|
+
}
|
|
127
|
+
sums.set(key, entry)
|
|
128
|
+
}
|
|
129
|
+
const empty = [...sums.values()].filter((e) => e.values > 0 && e.sum === 0).map((e) => e.row)
|
|
130
|
+
if (empty.length === 0) return []
|
|
131
|
+
return [
|
|
132
|
+
dot(empty, {
|
|
133
|
+
id: 'empty-bins',
|
|
134
|
+
x: rowX,
|
|
135
|
+
y: () => 0,
|
|
136
|
+
r: EMPTY_BIN_R,
|
|
137
|
+
fill: VX.muted,
|
|
138
|
+
fillOpacity: 0,
|
|
139
|
+
states: [{ when: { focus: 'x' }, style: { fillOpacity: 1 } }],
|
|
140
|
+
}),
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Whether the baseline (y = 0) is on the plot: not on a log axis, not in a domain that starts above it. */
|
|
145
|
+
function floorIsZero<T>(y: BarsProps<T>['y']): boolean {
|
|
146
|
+
if (y?.scale === 'log') return false
|
|
147
|
+
const domain = y?.domain
|
|
148
|
+
if (Array.isArray(domain)) return domain[0] <= 0 && domain[1] >= 0
|
|
149
|
+
if (typeof domain === 'function') return false
|
|
150
|
+
return (y?.autoMinCeil ?? 0) <= 0
|
|
151
|
+
}
|
|
152
|
+
|
|
107
153
|
export function Bars<T, X extends ChartX = ChartX>(props: BarsProps<T, X>): ReactElement {
|
|
108
154
|
const { bars: given, lines, layout = 'stacked', barOpacity, ...rest } = props
|
|
109
155
|
const bars = useMemo(() => shadeSharedColors(given, barOpacity), [given, barOpacity])
|
|
110
156
|
const sharedColor = bars.some((b, i) => bars.findIndex((o) => o.color === b.color) !== i)
|
|
111
157
|
guardLogStack(layout, bars.length > 0 && rest.y?.scale === 'log')
|
|
112
158
|
const sample = rest.data[0]
|
|
159
|
+
const zeroFloor = floorIsZero(rest.y)
|
|
113
160
|
const bare = useContext(VisualSlotContext) !== null
|
|
114
161
|
const series = useMemo<ChartSeries<T>[]>(
|
|
115
162
|
() => [
|
|
@@ -165,13 +212,14 @@ export function Bars<T, X extends ChartX = ChartX>(props: BarsProps<T, X>): Reac
|
|
|
165
212
|
: stack({ order, ...(layout === 'normalized' && { offset: 'normalize' }) }),
|
|
166
213
|
}),
|
|
167
214
|
)
|
|
215
|
+
if (bare && zeroFloor) out.push(...emptyBinTicks(rows))
|
|
168
216
|
for (const s of plot.visible) {
|
|
169
217
|
if (barKeys.has(s.key)) continue
|
|
170
218
|
out.push(lineMark(plot, s))
|
|
171
219
|
}
|
|
172
220
|
return out
|
|
173
221
|
},
|
|
174
|
-
[bars, layout, barOpacity, sharedColor],
|
|
222
|
+
[bars, layout, barOpacity, sharedColor, bare, zeroFloor],
|
|
175
223
|
)
|
|
176
224
|
|
|
177
225
|
return (
|