@usetheo/ui 0.29.0 → 0.30.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.
|
@@ -39,6 +39,13 @@ export interface TrendChartProps extends HTMLAttributes<HTMLElement> {
|
|
|
39
39
|
height?: number;
|
|
40
40
|
/** Formats y-axis labels and table cells (tremor vocabulary). */
|
|
41
41
|
valueFormatter?: (v: number) => string;
|
|
42
|
+
/**
|
|
43
|
+
* Pin the top of the y-axis. Pass a fixed bound (e.g. `1` for a 0–1 score) so the
|
|
44
|
+
* scale is stable and comparable across renders instead of auto-fitting to the data
|
|
45
|
+
* max via {@link niceMax} (which makes 0.68 look near the top of a [0, 0.7] axis).
|
|
46
|
+
* Ignored when ≤ 0. Default: auto (`niceMax`).
|
|
47
|
+
*/
|
|
48
|
+
yMax?: number;
|
|
42
49
|
}
|
|
43
50
|
declare const TrendChart: import("react").ForwardRefExoticComponent<TrendChartProps & import("react").RefAttributes<HTMLElement>>;
|
|
44
51
|
export { TrendChart };
|
package/dist/index.js
CHANGED
|
@@ -5087,7 +5087,7 @@ function niceMax(values) {
|
|
|
5087
5087
|
const m = Math.max(0, ...values.filter((v) => Number.isFinite(v)));
|
|
5088
5088
|
if (m <= 0) return 0;
|
|
5089
5089
|
const pow = 10 ** Math.floor(Math.log10(m));
|
|
5090
|
-
return Math.ceil(m / pow) * pow;
|
|
5090
|
+
return Number((Math.ceil(m / pow) * pow).toPrecision(12));
|
|
5091
5091
|
}
|
|
5092
5092
|
function seriesPath(points, xScale, yScale) {
|
|
5093
5093
|
const finite = points.filter((p) => Number.isFinite(p.y));
|
|
@@ -5098,7 +5098,29 @@ var VIEW_W = 600;
|
|
|
5098
5098
|
var PAD = { top: 8, right: 8, bottom: 4, left: 40 };
|
|
5099
5099
|
var SPARSE_MARKER_MAX = 5;
|
|
5100
5100
|
var TrendChart = forwardRef(
|
|
5101
|
-
({
|
|
5101
|
+
({
|
|
5102
|
+
title,
|
|
5103
|
+
series,
|
|
5104
|
+
height = 180,
|
|
5105
|
+
valueFormatter = (v) => String(v),
|
|
5106
|
+
yMax: yMaxProp,
|
|
5107
|
+
className,
|
|
5108
|
+
...props
|
|
5109
|
+
}, ref) => {
|
|
5110
|
+
const [viewW, setViewW] = useState(VIEW_W);
|
|
5111
|
+
const roRef = useRef(null);
|
|
5112
|
+
const setSvgNode = useCallback((node) => {
|
|
5113
|
+
roRef.current?.disconnect();
|
|
5114
|
+
roRef.current = null;
|
|
5115
|
+
if (!node || typeof ResizeObserver === "undefined") return;
|
|
5116
|
+
const measure = () => {
|
|
5117
|
+
const w = node.clientWidth;
|
|
5118
|
+
if (w > 0) setViewW(w);
|
|
5119
|
+
};
|
|
5120
|
+
measure();
|
|
5121
|
+
roRef.current = new ResizeObserver(measure);
|
|
5122
|
+
roRef.current.observe(node);
|
|
5123
|
+
}, []);
|
|
5102
5124
|
const allPoints = series.flatMap((s) => s.points);
|
|
5103
5125
|
const hasData = allPoints.some((p) => Number.isFinite(p.y));
|
|
5104
5126
|
if (!hasData) {
|
|
@@ -5128,17 +5150,18 @@ var TrendChart = forwardRef(
|
|
|
5128
5150
|
const xs = allPoints.map((p) => p.x);
|
|
5129
5151
|
const xMin = Math.min(...xs);
|
|
5130
5152
|
const xMax = Math.max(...xs);
|
|
5131
|
-
const yMax = niceMax(allPoints.map((p) => p.y)) || 1;
|
|
5153
|
+
const yMax = yMaxProp != null && yMaxProp > 0 ? yMaxProp : niceMax(allPoints.map((p) => p.y)) || 1;
|
|
5132
5154
|
const axisXs = Array.from(new Set(allPoints.map((p) => p.x))).sort((a, b) => a - b);
|
|
5133
5155
|
const yByX = series.map((s) => new Map(s.points.map((p) => [p.x, p.y])));
|
|
5134
|
-
const xScale = linScale([xMin, xMax], [PAD.left,
|
|
5156
|
+
const xScale = linScale([xMin, xMax], [PAD.left, viewW - PAD.right]);
|
|
5135
5157
|
const yScale = linScale([0, yMax], [height - PAD.bottom, PAD.top]);
|
|
5136
5158
|
return /* @__PURE__ */ jsxs("figure", { "data-slot": "trend-chart", ref, className: cn("space-y-1", className), ...props, children: [
|
|
5137
5159
|
/* @__PURE__ */ jsx("figcaption", { className: "font-semibold text-label-caps text-muted-foreground uppercase", children: title }),
|
|
5138
5160
|
/* @__PURE__ */ jsxs(
|
|
5139
5161
|
"svg",
|
|
5140
5162
|
{
|
|
5141
|
-
|
|
5163
|
+
ref: setSvgNode,
|
|
5164
|
+
viewBox: `0 0 ${viewW} ${height}`,
|
|
5142
5165
|
preserveAspectRatio: "none",
|
|
5143
5166
|
role: "img",
|
|
5144
5167
|
"aria-label": `${title} trend`,
|
|
@@ -5150,7 +5173,7 @@ var TrendChart = forwardRef(
|
|
|
5150
5173
|
{
|
|
5151
5174
|
x1: PAD.left,
|
|
5152
5175
|
y1: height - PAD.bottom,
|
|
5153
|
-
x2:
|
|
5176
|
+
x2: viewW - PAD.right,
|
|
5154
5177
|
y2: height - PAD.bottom,
|
|
5155
5178
|
className: "stroke-border",
|
|
5156
5179
|
strokeWidth: 1
|
|
@@ -5161,7 +5184,7 @@ var TrendChart = forwardRef(
|
|
|
5161
5184
|
{
|
|
5162
5185
|
x1: PAD.left,
|
|
5163
5186
|
y1: PAD.top,
|
|
5164
|
-
x2:
|
|
5187
|
+
x2: viewW - PAD.right,
|
|
5165
5188
|
y2: PAD.top,
|
|
5166
5189
|
className: "stroke-border/50",
|
|
5167
5190
|
strokeWidth: 1,
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usetheo/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"packageManager": "pnpm@10.32.1+sha512.a706938f0e89ac1456b6563eab4edf1d1faf3368d1191fc5c59790e96dc918e4456ab2e67d613de1043d2e8c81f87303e6b40d4ffeca9df15ef1ad567348f2be",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"description": "Violet Forge design system — generic React components + primitives (the non-AI foundation of @theokit/ui).",
|
|
8
8
|
"sideEffects": false,
|
|
9
|
-
"files": [
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
10
12
|
"exports": {
|
|
11
13
|
".": {
|
|
12
14
|
"types": "./dist/index.d.ts",
|