@gridui/chart 0.0.0-stage → 1.0.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.
Files changed (40) hide show
  1. package/README.md +65 -2
  2. package/dist/bar-chart/bar-chart.d.ts +12 -0
  3. package/dist/bar-series/bar-series.d.ts +17 -0
  4. package/dist/chart-cursor/chart-cursor.d.ts +13 -0
  5. package/dist/chart-grid/chart-grid.d.ts +18 -0
  6. package/dist/chart-plot/chart-plot.d.ts +13 -0
  7. package/dist/chart-tooltip/chart-tooltip.d.ts +14 -0
  8. package/dist/chart-tooltip/layout.d.ts +31 -0
  9. package/dist/chart-value-labels/chart-value-labels.d.ts +17 -0
  10. package/dist/chart-value-labels/layout.d.ts +28 -0
  11. package/dist/chart-x-axis/chart-x-axis.d.ts +12 -0
  12. package/dist/chart-y-axis/chart-y-axis.d.ts +12 -0
  13. package/dist/index.d.ts +29 -0
  14. package/dist/index.js +1276 -0
  15. package/dist/index.js.map +7 -0
  16. package/dist/line-chart/line-chart.d.ts +12 -0
  17. package/dist/line-series/line-series.d.ts +16 -0
  18. package/dist/shared/axis.d.ts +13 -0
  19. package/dist/shared/chart-root.d.ts +14 -0
  20. package/dist/shared/context.d.ts +38 -0
  21. package/dist/shared/datum-mark.d.ts +13 -0
  22. package/dist/shared/model.d.ts +13 -0
  23. package/dist/shared/ticks.d.ts +14 -0
  24. package/dist/shared/types.d.ts +46 -0
  25. package/dist/shared/use-measured-layout.d.ts +12 -0
  26. package/dist/styles.css +37 -0
  27. package/docs/catalog.json +168 -0
  28. package/docs/reference/README.md +14 -0
  29. package/docs/reference/bar-chart.md +97 -0
  30. package/docs/reference/bar-series.md +61 -0
  31. package/docs/reference/chart-cursor.md +39 -0
  32. package/docs/reference/chart-grid.md +61 -0
  33. package/docs/reference/chart-plot.md +37 -0
  34. package/docs/reference/chart-tooltip.md +37 -0
  35. package/docs/reference/chart-value-labels.md +57 -0
  36. package/docs/reference/chart-xaxis.md +71 -0
  37. package/docs/reference/chart-yaxis.md +71 -0
  38. package/docs/reference/line-chart.md +97 -0
  39. package/docs/reference/line-series.md +47 -0
  40. package/package.json +50 -3
package/README.md CHANGED
@@ -1,3 +1,66 @@
1
- # Temporary Holding Version
1
+ # @gridui/chart
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Composable line and bar charts in the Data family. Import components from
4
+ `@gridui/chart` and load `@gridui/chart/styles.css` after Theme.
5
+
6
+ LineChart and BarChart own data and selection. ChartPlot, ChartGrid, ChartXAxis,
7
+ ChartYAxis, LineSeries, BarSeries, ChartValueLabels, ChartCursor and ChartTooltip
8
+ compose the actual chart. There are no whole-chart visual variants.
9
+
10
+ ```tsx
11
+ <LineChart label="Requests per day" data={observations}>
12
+ <ChartPlot>
13
+ <ChartGrid />
14
+ <ChartXAxis />
15
+ <ChartYAxis />
16
+ <LineSeries points={{ shape: "square", size: 5 }} />
17
+ <ChartValueLabels visibility="all" />
18
+ </ChartPlot>
19
+ </LineChart>
20
+ ```
21
+
22
+ Bar gaps are preferred pixel spacing: they shrink when necessary to keep positive
23
+ values visible within their category bands.
24
+
25
+ Each observation has a stable nonempty `id`, `x` (string, number or Date), and `y`
26
+ (finite number or null). Category coordinates preserve order. LineChart's
27
+ `xScale="time"` and `"linear"` sort observations and preserve proportional gaps.
28
+ Null breaks a line; zero remains data. Value domains include zero and all values.
29
+ Explicit domains must be finite and increasing, and cannot clip data or zero.
30
+
31
+ Charts fill their container. `height` defaults to 300px and must be at least
32
+ 160px. Plot padding reserves space for axes and labels; callers provide more
33
+ padding for long formatted labels or relocated axes. If padding leaves no plotting
34
+ space, the chart retains its accessible data description and resumes drawing
35
+ when space becomes available. Use modest SVG datasets.
36
+ Applications own aggregation, localized formatters and loading/empty content.
37
+
38
+ Axes accept `tickCount` (an integer of at least two) or `tickValues` (exact values,
39
+ with precedence over the count). Continuous counts divide the domain evenly;
40
+ category counts sample existing observations and preserve endpoints. Explicit
41
+ values outside the domain or missing categories are ignored; repeated continuous
42
+ values are deduplicated. `tickValues={[]}` hides ticks. Time tick formatters receive
43
+ Date values. Share the same options with `ChartGrid.xTicks` / `yTicks` to align
44
+ reference lines with axes; these always use screen directions.
45
+
46
+ Tick lines remain visible when their labels collide. Axis and value labels use
47
+ actual SVG text bounds; tooltips wrap using measured text widths. Layout updates
48
+ on resize and font changes. Visual labels need browser measurement; SSR retains
49
+ the complete accessible data description. Plot padding remains caller-controlled.
50
+
51
+ `defaultSelectedId` enables local selection. `selectedId` and
52
+ `onSelectionChange` support controlled selection. Hover/focus is transient and
53
+ independent from selection. Pointer inspection temporarily overrides keyboard
54
+ inspection; leaving a mark restores the focused observation. Enter/Space toggles
55
+ once per press, Escape clears. Missing or
56
+ removed selected IDs show no selection without emitting a callback.
57
+ `formatDatum` controls accessible names and default tooltip text.
58
+
59
+ Local CSS variables map to Theme: `--gridui-chart-background`, `-grid`, `-axis`,
60
+ `-label`, `-value`, `-series`, `-selected`, and `-point-background` (all share the
61
+ `--gridui-chart` prefix). Part props override their respective default tokens.
62
+ Keep cards, summaries and tables outside Chart; Grid owns surrounding seams.
63
+
64
+ See [component ownership](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/docs/component-ownership.md),
65
+ [component reference](docs/reference/README.md), and
66
+ [release history](https://github.com/sudo-ui/GridUI-React-Monorepo/tree/main/packages-data/chart/.changeset/history).
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace BarChart
5
+ * @description Bar Chart
6
+ */
7
+ import type { ChartOptions } from "../shared/types";
8
+ import type { FC } from "react";
9
+ export type BarChartProps = ChartOptions & {
10
+ readonly orientation?: "vertical" | "horizontal";
11
+ };
12
+ export declare const BarChart: FC<BarChartProps>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace BarSeries
5
+ * @description Bar Series
6
+ */
7
+ import type { CSSProperties, FC } from "react";
8
+ export type BarSeriesProps = {
9
+ readonly color?: CSSProperties["color"];
10
+ readonly selectedColor?: CSSProperties["color"];
11
+ readonly width?: number;
12
+ readonly widthRatio?: number;
13
+ readonly gap?: number;
14
+ readonly opacity?: number;
15
+ readonly inactiveOpacity?: number;
16
+ };
17
+ export declare const BarSeries: FC<BarSeriesProps>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace ChartCursor
5
+ * @description Chart Cursor
6
+ */
7
+ import type { CSSProperties, FC } from "react";
8
+ export type ChartCursorProps = {
9
+ readonly color?: CSSProperties["color"];
10
+ readonly strokeWidth?: number;
11
+ readonly dashArray?: string;
12
+ };
13
+ export declare const ChartCursor: FC<ChartCursorProps>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace ChartGrid
5
+ * @description Chart Grid
6
+ */
7
+ import type { ChartTickOptions } from "../shared/types";
8
+ import type { CSSProperties, FC } from "react";
9
+ export type ChartGridProps = {
10
+ readonly xTicks?: ChartTickOptions;
11
+ readonly yTicks?: ChartTickOptions;
12
+ readonly horizontal?: boolean;
13
+ readonly vertical?: boolean;
14
+ readonly color?: CSSProperties["color"];
15
+ readonly strokeWidth?: number;
16
+ readonly dashArray?: string;
17
+ };
18
+ export declare const ChartGrid: FC<ChartGridProps>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace ChartPlot
5
+ * @description Chart Plot
6
+ */
7
+ import type { CSSProperties, FC, ReactNode } from "react";
8
+ export type ChartPlotProps = {
9
+ readonly children: ReactNode;
10
+ readonly background?: CSSProperties["fill"];
11
+ readonly padding?: Partial<Record<"top" | "right" | "bottom" | "left", number>>;
12
+ };
13
+ export declare const ChartPlot: FC<ChartPlotProps>;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace ChartTooltip
5
+ * @description Chart Tooltip
6
+ */
7
+ import type { ChartDatum } from "../shared/types";
8
+ import type { CSSProperties, FC } from "react";
9
+ export type ChartTooltipProps = {
10
+ readonly format?: (datum: ChartDatum) => string;
11
+ readonly background?: CSSProperties["color"];
12
+ readonly color?: CSSProperties["color"];
13
+ };
14
+ export declare const ChartTooltip: FC<ChartTooltipProps>;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace ChartTooltip
5
+ * @description Layout
6
+ */
7
+ import type { PlotState } from "../shared/context";
8
+ import type { ChartDatum } from "../shared/types";
9
+ import type { MeasureText } from "../shared/use-measured-layout";
10
+ type TooltipLayout = {
11
+ readonly lines: readonly {
12
+ readonly text: string;
13
+ readonly x: number;
14
+ readonly y: number;
15
+ }[];
16
+ readonly width: number;
17
+ readonly height: number;
18
+ };
19
+ export declare const calculateTooltipLayout: (text: string | null, plotWidth: number, measure: MeasureText) => TooltipLayout | null;
20
+ type TooltipPositionOptions = {
21
+ readonly datum: ChartDatum | undefined;
22
+ readonly horizontal: boolean;
23
+ readonly plot: Pick<PlotState, "width" | "height" | "category" | "value">;
24
+ readonly width: number;
25
+ readonly height: number;
26
+ };
27
+ export declare const calculateTooltipPosition: (options: TooltipPositionOptions) => {
28
+ readonly x: number;
29
+ readonly y: number;
30
+ };
31
+ export {};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace ChartValueLabels
5
+ * @description Chart Value Labels
6
+ */
7
+ import type { ChartDatum } from "../shared/types";
8
+ import type { CSSProperties, FC } from "react";
9
+ export type ChartValueLabelsProps = {
10
+ readonly visibility?: "all" | "selected" | "none";
11
+ readonly position?: "end" | "center";
12
+ readonly format?: (value: number, datum: ChartDatum) => string;
13
+ readonly color?: CSSProperties["color"];
14
+ readonly fontSize?: number;
15
+ readonly offset?: number;
16
+ };
17
+ export declare const ChartValueLabels: FC<ChartValueLabelsProps>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace ChartValueLabels
5
+ * @description Layout
6
+ */
7
+ import type { PlotState } from "../shared/context";
8
+ import type { ChartDatum } from "../shared/types";
9
+ import type { MeasureText } from "../shared/use-measured-layout";
10
+ type ValueLabelLayoutOptions = {
11
+ readonly data: readonly ChartDatum[];
12
+ readonly selectedId: string | null;
13
+ readonly horizontal: boolean;
14
+ readonly plot: Pick<PlotState, "width" | "height" | "category" | "value">;
15
+ readonly visibility: "all" | "selected" | "none";
16
+ readonly position: "end" | "center";
17
+ readonly format: (value: number, datum: ChartDatum) => string;
18
+ readonly offset: number;
19
+ readonly measure: MeasureText;
20
+ };
21
+ type ValueLabel = {
22
+ readonly id: string;
23
+ readonly text: string;
24
+ readonly x: number;
25
+ readonly y: number;
26
+ };
27
+ export declare const calculateValueLabelLayout: (options: ValueLabelLayoutOptions) => ValueLabel[];
28
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace ChartXAxis
5
+ * @description Chart X Axis
6
+ */
7
+ import type { ChartAxisOptions } from "../shared/types";
8
+ import type { FC } from "react";
9
+ export type ChartXAxisProps = ChartAxisOptions & {
10
+ readonly position?: "top" | "bottom";
11
+ };
12
+ export declare const ChartXAxis: FC<ChartXAxisProps>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace ChartYAxis
5
+ * @description Chart Y Axis
6
+ */
7
+ import type { ChartAxisOptions } from "../shared/types";
8
+ import type { FC } from "react";
9
+ export type ChartYAxisProps = ChartAxisOptions & {
10
+ readonly position?: "left" | "right";
11
+ };
12
+ export declare const ChartYAxis: FC<ChartYAxisProps>;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package GridUI
4
+ * @namespace Root
5
+ * @description Index
6
+ */
7
+ export type { BarChartProps } from "./bar-chart/bar-chart";
8
+ export { BarChart } from "./bar-chart/bar-chart";
9
+ export type { BarSeriesProps } from "./bar-series/bar-series";
10
+ export { BarSeries } from "./bar-series/bar-series";
11
+ export type { ChartCursorProps } from "./chart-cursor/chart-cursor";
12
+ export { ChartCursor } from "./chart-cursor/chart-cursor";
13
+ export type { ChartGridProps } from "./chart-grid/chart-grid";
14
+ export { ChartGrid } from "./chart-grid/chart-grid";
15
+ export type { ChartPlotProps } from "./chart-plot/chart-plot";
16
+ export { ChartPlot } from "./chart-plot/chart-plot";
17
+ export type { ChartTooltipProps } from "./chart-tooltip/chart-tooltip";
18
+ export { ChartTooltip } from "./chart-tooltip/chart-tooltip";
19
+ export type { ChartValueLabelsProps } from "./chart-value-labels/chart-value-labels";
20
+ export { ChartValueLabels } from "./chart-value-labels/chart-value-labels";
21
+ export type { ChartXAxisProps } from "./chart-x-axis/chart-x-axis";
22
+ export { ChartXAxis } from "./chart-x-axis/chart-x-axis";
23
+ export type { ChartYAxisProps } from "./chart-y-axis/chart-y-axis";
24
+ export { ChartYAxis } from "./chart-y-axis/chart-y-axis";
25
+ export type { LineChartProps } from "./line-chart/line-chart";
26
+ export { LineChart } from "./line-chart/line-chart";
27
+ export type { LineSeriesProps } from "./line-series/line-series";
28
+ export { LineSeries } from "./line-series/line-series";
29
+ export type { ChartDatum, ChartPointOptions, ChartScale, ChartTickOptions } from "./shared/types";