@reactloom/charts 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.
- package/README.md +39 -2
- package/dist/LICENSE +21 -0
- package/dist/_internal/hooks/use-isomorphic-layout-effect.js +7 -0
- package/dist/_internal/hooks/use-isomorphic-layout-effect.js.map +1 -0
- package/dist/_internal/primitives/visually-hidden.js +29 -0
- package/dist/_internal/primitives/visually-hidden.js.map +1 -0
- package/dist/_internal/utils/cx.js +10 -0
- package/dist/_internal/utils/cx.js.map +1 -0
- package/dist/_internal/utils/warn.js +13 -0
- package/dist/_internal/utils/warn.js.map +1 -0
- package/dist/advanced-charts.d.ts +37 -0
- package/dist/advanced-charts.d.ts.map +1 -0
- package/dist/advanced-charts.js +587 -0
- package/dist/advanced-charts.js.map +1 -0
- package/dist/cartesian.d.ts +25 -0
- package/dist/cartesian.d.ts.map +1 -0
- package/dist/cartesian.js +461 -0
- package/dist/cartesian.js.map +1 -0
- package/dist/chart-frame.d.ts +55 -0
- package/dist/chart-frame.d.ts.map +1 -0
- package/dist/chart-frame.js +148 -0
- package/dist/chart-frame.js.map +1 -0
- package/dist/charts.d.ts +35 -0
- package/dist/charts.d.ts.map +1 -0
- package/dist/charts.js +47 -0
- package/dist/charts.js.map +1 -0
- package/dist/charts.module.js +126 -0
- package/dist/charts.module.js.map +1 -0
- package/dist/format.d.ts +42 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +101 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/item-charts.d.ts +140 -0
- package/dist/item-charts.d.ts.map +1 -0
- package/dist/item-charts.js +1476 -0
- package/dist/item-charts.js.map +1 -0
- package/dist/pie-chart.d.ts +23 -0
- package/dist/pie-chart.d.ts.map +1 -0
- package/dist/pie-chart.js +216 -0
- package/dist/pie-chart.js.map +1 -0
- package/dist/sparkline.d.ts +25 -0
- package/dist/sparkline.d.ts.map +1 -0
- package/dist/sparkline.js +88 -0
- package/dist/sparkline.js.map +1 -0
- package/dist/styles.css +3 -0
- package/dist/types.d.ts +84 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +76 -3
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { VisuallyHidden } from "./_internal/primitives/visually-hidden.js";
|
|
3
|
+
import { useIsomorphicLayoutEffect } from "./_internal/hooks/use-isomorphic-layout-effect.js";
|
|
4
|
+
import { cx } from "./_internal/utils/cx.js";
|
|
5
|
+
import charts_module_default from "./charts.module.js";
|
|
6
|
+
import { useId, useRef, useState } from "react";
|
|
7
|
+
import { Button, Collapsible, Skeleton } from "@reactloom/ui";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
/**
|
|
10
|
+
* Measures the plot container: its width (redrawn on resize) and its layout direction (charts
|
|
11
|
+
* mirror in right-to-left layouts).
|
|
12
|
+
*/
|
|
13
|
+
function usePlotLayout(ref) {
|
|
14
|
+
const [layout, setLayout] = useState({
|
|
15
|
+
width: 600,
|
|
16
|
+
rtl: false
|
|
17
|
+
});
|
|
18
|
+
useIsomorphicLayoutEffect(() => {
|
|
19
|
+
const el = ref.current;
|
|
20
|
+
if (!el) return;
|
|
21
|
+
const measure = () => {
|
|
22
|
+
const width = Math.max(120, Math.round(el.getBoundingClientRect().width));
|
|
23
|
+
const rtl = getComputedStyle(el).direction === "rtl";
|
|
24
|
+
setLayout((prev) => prev.width === width && prev.rtl === rtl ? prev : {
|
|
25
|
+
width,
|
|
26
|
+
rtl
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
measure();
|
|
30
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
31
|
+
const observer = new ResizeObserver(measure);
|
|
32
|
+
observer.observe(el);
|
|
33
|
+
return () => observer.disconnect();
|
|
34
|
+
}, [ref]);
|
|
35
|
+
return layout;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The accessible frame every chart shares: a `<figure>` named by its title and described by the
|
|
39
|
+
* summary, the legend, the plot, a polite live region and the data table alternative.
|
|
40
|
+
*/
|
|
41
|
+
function ChartFrame({ title, hideTitle, description, hideDescription, loading, messages, table, renderTable, legend, announcement, height, className, id, kind, children }) {
|
|
42
|
+
const uid = useId();
|
|
43
|
+
const titleId = `${uid}-title`;
|
|
44
|
+
const descriptionId = `${uid}-description`;
|
|
45
|
+
const [tableOpen, setTableOpen] = useState(table === "visible");
|
|
46
|
+
const titleNode = /* @__PURE__ */ jsx("span", {
|
|
47
|
+
id: titleId,
|
|
48
|
+
children: title
|
|
49
|
+
});
|
|
50
|
+
const descriptionNode = description ? /* @__PURE__ */ jsx("span", {
|
|
51
|
+
id: descriptionId,
|
|
52
|
+
className: charts_module_default.description,
|
|
53
|
+
dir: "auto",
|
|
54
|
+
children: description
|
|
55
|
+
}) : null;
|
|
56
|
+
return /* @__PURE__ */ jsxs("figure", {
|
|
57
|
+
id,
|
|
58
|
+
className: cx(charts_module_default.figure, className),
|
|
59
|
+
"data-chart": kind,
|
|
60
|
+
"aria-labelledby": titleId,
|
|
61
|
+
"aria-describedby": description ? descriptionId : void 0,
|
|
62
|
+
"aria-busy": loading || void 0,
|
|
63
|
+
children: [
|
|
64
|
+
/* @__PURE__ */ jsxs("figcaption", {
|
|
65
|
+
className: charts_module_default.caption,
|
|
66
|
+
children: [hideTitle ? /* @__PURE__ */ jsx(VisuallyHidden, { children: titleNode }) : /* @__PURE__ */ jsx("span", {
|
|
67
|
+
className: charts_module_default.title,
|
|
68
|
+
children: titleNode
|
|
69
|
+
}), descriptionNode && (hideDescription ? /* @__PURE__ */ jsx(VisuallyHidden, { children: descriptionNode }) : descriptionNode)]
|
|
70
|
+
}),
|
|
71
|
+
legend,
|
|
72
|
+
loading ? /* @__PURE__ */ jsxs("div", {
|
|
73
|
+
className: charts_module_default.loading,
|
|
74
|
+
style: { height },
|
|
75
|
+
children: [/* @__PURE__ */ jsx(Skeleton, {
|
|
76
|
+
shape: "rect",
|
|
77
|
+
width: "100%",
|
|
78
|
+
height
|
|
79
|
+
}), /* @__PURE__ */ jsx(VisuallyHidden, { children: messages.loading })]
|
|
80
|
+
}) : children,
|
|
81
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("span", {
|
|
82
|
+
role: "status",
|
|
83
|
+
"aria-live": "polite",
|
|
84
|
+
"aria-atomic": "true",
|
|
85
|
+
children: announcement
|
|
86
|
+
}) }),
|
|
87
|
+
!loading && table === "visible" && /* @__PURE__ */ jsx("div", {
|
|
88
|
+
className: charts_module_default.table,
|
|
89
|
+
children: renderTable()
|
|
90
|
+
}),
|
|
91
|
+
!loading && table === "toggle" && /* @__PURE__ */ jsxs(Collapsible.Root, {
|
|
92
|
+
open: tableOpen,
|
|
93
|
+
onOpenChange: setTableOpen,
|
|
94
|
+
children: [/* @__PURE__ */ jsx(Collapsible.Trigger, {
|
|
95
|
+
asChild: true,
|
|
96
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
97
|
+
variant: "link",
|
|
98
|
+
size: "sm",
|
|
99
|
+
className: charts_module_default.tableToggle,
|
|
100
|
+
children: tableOpen ? messages.hideTable : messages.showTable
|
|
101
|
+
})
|
|
102
|
+
}), /* @__PURE__ */ jsx(Collapsible.Content, {
|
|
103
|
+
keepMounted: false,
|
|
104
|
+
className: charts_module_default.table,
|
|
105
|
+
children: tableOpen && renderTable()
|
|
106
|
+
})]
|
|
107
|
+
})
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** A list of series with their colours (decorative swatches; the label carries the meaning). */
|
|
112
|
+
function Legend({ items, label }) {
|
|
113
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
114
|
+
className: charts_module_default.legend,
|
|
115
|
+
"aria-label": label,
|
|
116
|
+
children: items.map((item, index) => /* @__PURE__ */ jsxs("li", {
|
|
117
|
+
className: charts_module_default.legendItem,
|
|
118
|
+
children: [
|
|
119
|
+
/* @__PURE__ */ jsx("span", {
|
|
120
|
+
className: charts_module_default.swatch,
|
|
121
|
+
"data-series": index + 1,
|
|
122
|
+
style: { background: item.color },
|
|
123
|
+
"aria-hidden": "true"
|
|
124
|
+
}),
|
|
125
|
+
item.label,
|
|
126
|
+
item.detail && /* @__PURE__ */ jsx("span", {
|
|
127
|
+
className: charts_module_default.legendDetail,
|
|
128
|
+
children: item.detail
|
|
129
|
+
})
|
|
130
|
+
]
|
|
131
|
+
}, item.key))
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/** Reusable plot keyboard hint id + node. */
|
|
135
|
+
function useKeyboardHint(text) {
|
|
136
|
+
const id = `${useId()}-hint`;
|
|
137
|
+
return {
|
|
138
|
+
id,
|
|
139
|
+
node: /* @__PURE__ */ jsx(VisuallyHidden, {
|
|
140
|
+
id,
|
|
141
|
+
children: text
|
|
142
|
+
})
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
var useMeasuredRef = () => useRef(null);
|
|
146
|
+
export { ChartFrame, Legend, useKeyboardHint, useMeasuredRef, usePlotLayout };
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=chart-frame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-frame.js","names":["styles"],"sources":["../src/chart-frame.tsx"],"sourcesContent":["'use client';\n\nimport { useId, useRef, useState, type ReactNode, type RefObject } from 'react';\nimport { VisuallyHidden } from '@reactloom/primitives';\nimport { useIsomorphicLayoutEffect } from '@reactloom/hooks';\nimport { Button, Collapsible, Skeleton } from '@reactloom/ui';\nimport { cx } from '@reactloom/utils';\nimport type { ChartMessages } from './types.js';\nimport styles from './charts.module.css';\n\n/** Width the plot is drawn at before it is measured (server rendering, first client render). */\nexport const INITIAL_WIDTH = 600;\n\n/**\n * Measures the plot container: its width (redrawn on resize) and its layout direction (charts\n * mirror in right-to-left layouts).\n */\nexport function usePlotLayout(ref: RefObject<HTMLElement | null>): { width: number; rtl: boolean } {\n const [layout, setLayout] = useState({ width: INITIAL_WIDTH, rtl: false });\n useIsomorphicLayoutEffect(() => {\n const el = ref.current;\n if (!el) return;\n const measure = () => {\n const width = Math.max(120, Math.round(el.getBoundingClientRect().width));\n const rtl = getComputedStyle(el).direction === 'rtl';\n setLayout((prev) => (prev.width === width && prev.rtl === rtl ? prev : { width, rtl }));\n };\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(measure);\n observer.observe(el);\n return () => observer.disconnect();\n }, [ref]);\n return layout;\n}\n\nexport interface ChartFrameProps {\n title: string;\n hideTitle?: boolean;\n description: ReactNode;\n hideDescription?: boolean;\n loading?: boolean;\n messages: ChartMessages;\n table: 'toggle' | 'visible' | 'none';\n /** The data table (rendered only when shown). */\n renderTable: () => ReactNode;\n legend?: ReactNode;\n /** Polite live-region text (keyboard exploration readout). */\n announcement?: string;\n height: number;\n className?: string;\n id?: string;\n kind: string;\n children: ReactNode;\n}\n\n/**\n * The accessible frame every chart shares: a `<figure>` named by its title and described by the\n * summary, the legend, the plot, a polite live region and the data table alternative.\n */\nexport function ChartFrame({\n title,\n hideTitle,\n description,\n hideDescription,\n loading,\n messages,\n table,\n renderTable,\n legend,\n announcement,\n height,\n className,\n id,\n kind,\n children,\n}: ChartFrameProps) {\n const uid = useId();\n const titleId = `${uid}-title`;\n const descriptionId = `${uid}-description`;\n const [tableOpen, setTableOpen] = useState(table === 'visible');\n const titleNode = <span id={titleId}>{title}</span>;\n const descriptionNode = description ? (\n <span id={descriptionId} className={styles.description} dir=\"auto\">\n {description}\n </span>\n ) : null;\n return (\n <figure\n id={id}\n className={cx(styles.figure, className)}\n data-chart={kind}\n aria-labelledby={titleId}\n aria-describedby={description ? descriptionId : undefined}\n aria-busy={loading || undefined}\n >\n <figcaption className={styles.caption}>\n {hideTitle ? <VisuallyHidden>{titleNode}</VisuallyHidden> : <span className={styles.title}>{titleNode}</span>}\n {descriptionNode && (hideDescription ? <VisuallyHidden>{descriptionNode}</VisuallyHidden> : descriptionNode)}\n </figcaption>\n {legend}\n {loading ? (\n <div className={styles.loading} style={{ height }}>\n <Skeleton shape=\"rect\" width=\"100%\" height={height} />\n <VisuallyHidden>{messages.loading}</VisuallyHidden>\n </div>\n ) : (\n children\n )}\n <VisuallyHidden>\n <span role=\"status\" aria-live=\"polite\" aria-atomic=\"true\">\n {announcement}\n </span>\n </VisuallyHidden>\n {!loading && table === 'visible' && <div className={styles.table}>{renderTable()}</div>}\n {!loading && table === 'toggle' && (\n <Collapsible.Root open={tableOpen} onOpenChange={setTableOpen}>\n <Collapsible.Trigger asChild>\n <Button variant=\"link\" size=\"sm\" className={styles.tableToggle}>\n {tableOpen ? messages.hideTable : messages.showTable}\n </Button>\n </Collapsible.Trigger>\n <Collapsible.Content keepMounted={false} className={styles.table}>\n {tableOpen && renderTable()}\n </Collapsible.Content>\n </Collapsible.Root>\n )}\n </figure>\n );\n}\n\nexport interface LegendItem {\n key: string;\n label: string;\n color: string;\n /** Extra text after the label (e.g. a pie slice's share). */\n detail?: string;\n}\n\n/** A list of series with their colours (decorative swatches; the label carries the meaning). */\nexport function Legend({ items, label }: { items: LegendItem[]; label: string }) {\n return (\n <ul className={styles.legend} aria-label={label}>\n {items.map((item, index) => (\n <li key={item.key} className={styles.legendItem}>\n <span className={styles.swatch} data-series={index + 1} style={{ background: item.color }} aria-hidden=\"true\" />\n {item.label}\n {item.detail && <span className={styles.legendDetail}>{item.detail}</span>}\n </li>\n ))}\n </ul>\n );\n}\n\n/** Reusable plot keyboard hint id + node. */\nexport function useKeyboardHint(text: string) {\n const id = `${useId()}-hint`;\n return { id, node: <VisuallyHidden id={id}>{text}</VisuallyHidden> };\n}\n\nexport const useMeasuredRef = () => useRef<HTMLDivElement>(null);\n"],"mappings":";;;;;;;;;;;;AAiBA,SAAgB,cAAc,KAAqE;CACjG,MAAM,CAAC,QAAQ,aAAa,SAAS;EAAE,OAAA;EAAsB,KAAK;CAAM,CAAC;CACzE,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BAAC,QAAD;KAAM,WAAWA,sBAAO;KAAe,UAAA,KAAK;IAAa,CAAA;GACvE;EAJK,GAAA,KAAK,GAIV,CACL;CACC,CAAA;AAER;;AAGA,SAAgB,gBAAgB,MAAc;CAC5C,MAAM,KAAK,GAAG,MAAM,EAAE;CACtB,OAAO;EAAE;EAAI,MAAM,oBAAC,gBAAD;GAAoB;GAAK,UAAA;EAAqB,CAAA;CAAE;AACrE;AAEA,IAAa,uBAAuB,OAAuB,IAAI"}
|
package/dist/charts.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Accessor, CartesianChartProps } from './types.js';
|
|
2
|
+
export interface LineChartProps<Row> extends CartesianChartProps<Row> {
|
|
3
|
+
/** `monotone` smooths the line without overshooting the data. @default 'linear' */
|
|
4
|
+
curve?: 'linear' | 'monotone';
|
|
5
|
+
/** Mark each data point. @default true for up to 24 points */
|
|
6
|
+
points?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Trends over an ordered x axis (time, sequence). One tab stop; arrow keys move between points
|
|
10
|
+
* and announce their values. Includes a generated summary and a data table.
|
|
11
|
+
*/
|
|
12
|
+
export declare function LineChart<Row>(props: LineChartProps<Row>): import("react").JSX.Element;
|
|
13
|
+
export interface AreaChartProps<Row> extends CartesianChartProps<Row> {
|
|
14
|
+
/** Stack series to show how parts add up to a total. Values should not be negative. */
|
|
15
|
+
stacked?: boolean;
|
|
16
|
+
/** @default 'linear' */
|
|
17
|
+
curve?: 'linear' | 'monotone';
|
|
18
|
+
/** @default true for up to 24 points */
|
|
19
|
+
points?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Like LineChart with the area under each line filled; `stacked` shows parts of a total. */
|
|
22
|
+
export declare function AreaChart<Row>(props: AreaChartProps<Row>): import("react").JSX.Element;
|
|
23
|
+
export interface BarChartProps<Row> extends CartesianChartProps<Row> {
|
|
24
|
+
/** Stack series in one bar per category instead of side by side. */
|
|
25
|
+
stacked?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** Compares values across categories. Grouped by default; `stacked` for parts of a total. */
|
|
28
|
+
export declare function BarChart<Row>(props: BarChartProps<Row>): import("react").JSX.Element;
|
|
29
|
+
export interface ScatterChartProps<Row> extends Omit<CartesianChartProps<Row>, 'x' | 'xFormat'> {
|
|
30
|
+
/** Numeric x coordinate. Rows whose x coordinate is missing or non-finite are omitted. */
|
|
31
|
+
x: Accessor<Row, number>;
|
|
32
|
+
}
|
|
33
|
+
/** Plot independent observations on numeric axes and explore them in source order. */
|
|
34
|
+
export declare function ScatterChart<Row>({ data, x, ...props }: ScatterChartProps<Row>): import("react").JSX.Element;
|
|
35
|
+
//# sourceMappingURL=charts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charts.d.ts","sourceRoot":"","sources":["../src/charts.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEhE,MAAM,WAAW,cAAc,CAAC,GAAG,CAAE,SAAQ,mBAAmB,CAAC,GAAG,CAAC;IACnE,mFAAmF;IACnF,KAAK,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC9B,8DAA8D;IAC9D,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,+BAExD;AAED,MAAM,WAAW,cAAc,CAAC,GAAG,CAAE,SAAQ,mBAAmB,CAAC,GAAG,CAAC;IACnE,uFAAuF;IACvF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,wBAAwB;IACxB,KAAK,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC9B,wCAAwC;IACxC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,6FAA6F;AAC7F,wBAAgB,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,+BAExD;AAED,MAAM,WAAW,aAAa,CAAC,GAAG,CAAE,SAAQ,mBAAmB,CAAC,GAAG,CAAC;IAClE,oEAAoE;IACpE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,6FAA6F;AAC7F,wBAAgB,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,aAAa,CAAC,GAAG,CAAC,+BAItD;AAED,MAAM,WAAW,iBAAiB,CAAC,GAAG,CAAE,SAAQ,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,SAAS,CAAC;IAC7F,0FAA0F;IAC1F,CAAC,EAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;CAC1B;AAED,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,CAAC,GAAG,CAAC,+BAG9E"}
|
package/dist/charts.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { read } from "./format.js";
|
|
3
|
+
import { CartesianChart } from "./cartesian.js";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
// src/charts.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Trends over an ordered x axis (time, sequence). One tab stop; arrow keys move between points
|
|
9
|
+
* and announce their values. Includes a generated summary and a data table.
|
|
10
|
+
*/
|
|
11
|
+
function LineChart(props) {
|
|
12
|
+
return /* @__PURE__ */ jsx(CartesianChart, {
|
|
13
|
+
...props,
|
|
14
|
+
kind: "line",
|
|
15
|
+
kindLabel: "Line chart"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** Like LineChart with the area under each line filled; `stacked` shows parts of a total. */
|
|
19
|
+
function AreaChart(props) {
|
|
20
|
+
return /* @__PURE__ */ jsx(CartesianChart, {
|
|
21
|
+
...props,
|
|
22
|
+
kind: "area",
|
|
23
|
+
kindLabel: props.stacked ? "Stacked area chart" : "Area chart"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Compares values across categories. Grouped by default; `stacked` for parts of a total. */
|
|
27
|
+
function BarChart(props) {
|
|
28
|
+
return /* @__PURE__ */ jsx(CartesianChart, {
|
|
29
|
+
...props,
|
|
30
|
+
kind: "bar",
|
|
31
|
+
kindLabel: props.stacked ? "Stacked bar chart" : props.series.length > 1 ? "Grouped bar chart" : "Bar chart"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** Plot independent observations on numeric axes and explore them in source order. */
|
|
35
|
+
function ScatterChart({ data, x, ...props }) {
|
|
36
|
+
const valid = useMemo(() => data.filter((row) => Number.isFinite(read(x, row))), [data, x]);
|
|
37
|
+
return /* @__PURE__ */ jsx(CartesianChart, {
|
|
38
|
+
...props,
|
|
39
|
+
data: valid,
|
|
40
|
+
x,
|
|
41
|
+
kind: "scatter",
|
|
42
|
+
kindLabel: "Scatter chart"
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export { AreaChart, BarChart, LineChart, ScatterChart };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=charts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charts.js","names":[],"sources":["../src/charts.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo } from 'react';\nimport { read } from './format.js';\nimport { CartesianChart } from './cartesian.js';\nimport type { Accessor, CartesianChartProps } from './types.js';\n\nexport interface LineChartProps<Row> extends CartesianChartProps<Row> {\n /** `monotone` smooths the line without overshooting the data. @default 'linear' */\n curve?: 'linear' | 'monotone';\n /** Mark each data point. @default true for up to 24 points */\n points?: boolean;\n}\n\n/**\n * Trends over an ordered x axis (time, sequence). One tab stop; arrow keys move between points\n * and announce their values. Includes a generated summary and a data table.\n */\nexport function LineChart<Row>(props: LineChartProps<Row>) {\n return <CartesianChart {...props} kind=\"line\" kindLabel=\"Line chart\" />;\n}\n\nexport interface AreaChartProps<Row> extends CartesianChartProps<Row> {\n /** Stack series to show how parts add up to a total. Values should not be negative. */\n stacked?: boolean;\n /** @default 'linear' */\n curve?: 'linear' | 'monotone';\n /** @default true for up to 24 points */\n points?: boolean;\n}\n\n/** Like LineChart with the area under each line filled; `stacked` shows parts of a total. */\nexport function AreaChart<Row>(props: AreaChartProps<Row>) {\n return <CartesianChart {...props} kind=\"area\" kindLabel={props.stacked ? 'Stacked area chart' : 'Area chart'} />;\n}\n\nexport interface BarChartProps<Row> extends CartesianChartProps<Row> {\n /** Stack series in one bar per category instead of side by side. */\n stacked?: boolean;\n}\n\n/** Compares values across categories. Grouped by default; `stacked` for parts of a total. */\nexport function BarChart<Row>(props: BarChartProps<Row>) {\n return (\n <CartesianChart {...props} kind=\"bar\" kindLabel={props.stacked ? 'Stacked bar chart' : props.series.length > 1 ? 'Grouped bar chart' : 'Bar chart'} />\n );\n}\n\nexport interface ScatterChartProps<Row> extends Omit<CartesianChartProps<Row>, 'x' | 'xFormat'> {\n /** Numeric x coordinate. Rows whose x coordinate is missing or non-finite are omitted. */\n x: Accessor<Row, number>;\n}\n\n/** Plot independent observations on numeric axes and explore them in source order. */\nexport function ScatterChart<Row>({ data, x, ...props }: ScatterChartProps<Row>) {\n const valid = useMemo(() => data.filter((row) => Number.isFinite(read(x, row))), [data, x]);\n return <CartesianChart {...props} data={valid} x={x} kind=\"scatter\" kindLabel=\"Scatter chart\" />;\n}\n"],"mappings":";;;;;;;;;;AAkBA,SAAgB,UAAe,OAA4B;CACzD,OAAO,oBAAC,gBAAD;EAAgB,GAAI;EAAO,MAAK;EAAO,WAAU;CAAc,CAAA;AACxE;;AAYA,SAAgB,UAAe,OAA4B;CACzD,OAAO,oBAAC,gBAAD;EAAgB,GAAI;EAAO,MAAK;EAAO,WAAW,MAAM,UAAU,uBAAuB;CAAe,CAAA;AACjH;;AAQA,SAAgB,SAAc,OAA2B;CACvD,OACE,oBAAC,gBAAD;EAAgB,GAAI;EAAO,MAAK;EAAM,WAAW,MAAM,UAAU,sBAAsB,MAAM,OAAO,SAAS,IAAI,sBAAsB;CAAc,CAAA;AAEzJ;;AAQA,SAAgB,aAAkB,EAAE,MAAM,GAAG,GAAG,SAAiC;CAC/E,MAAM,QAAQ,cAAc,KAAK,QAAQ,QAAQ,OAAO,SAAS,KAAK,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CAC1F,OAAO,oBAAC,gBAAD;EAAgB,GAAI;EAAO,MAAM;EAAU;EAAG,MAAK;EAAU,WAAU;CAAiB,CAAA;AACjG"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// src/charts.module.css
|
|
2
|
+
var figure = "pl-charts-figure-r2OY1S";
|
|
3
|
+
var caption = "pl-charts-caption-r2OY1S";
|
|
4
|
+
var title = "pl-charts-title-r2OY1S";
|
|
5
|
+
var description = "pl-charts-description-r2OY1S";
|
|
6
|
+
var legend = "pl-charts-legend-r2OY1S";
|
|
7
|
+
var legendItem = "pl-charts-legendItem-r2OY1S";
|
|
8
|
+
var legendDetail = "pl-charts-legendDetail-r2OY1S";
|
|
9
|
+
var swatch = "pl-charts-swatch-r2OY1S";
|
|
10
|
+
var plotWrap = "pl-charts-plotWrap-r2OY1S";
|
|
11
|
+
var plot = "pl-charts-plot-r2OY1S";
|
|
12
|
+
var svg = "pl-charts-svg-r2OY1S";
|
|
13
|
+
var grid = "pl-charts-grid-r2OY1S";
|
|
14
|
+
var tickLabels = "pl-charts-tickLabels-r2OY1S";
|
|
15
|
+
var axisTitle = "pl-charts-axisTitle-r2OY1S";
|
|
16
|
+
var line = "pl-charts-line-r2OY1S";
|
|
17
|
+
var area = "pl-charts-area-r2OY1S";
|
|
18
|
+
var point = "pl-charts-point-r2OY1S";
|
|
19
|
+
var bar = "pl-charts-bar-r2OY1S";
|
|
20
|
+
var guide = "pl-charts-guide-r2OY1S";
|
|
21
|
+
var activeBand = "pl-charts-activeBand-r2OY1S";
|
|
22
|
+
var activePoint = "pl-charts-activePoint-r2OY1S";
|
|
23
|
+
var slice = "pl-charts-slice-r2OY1S";
|
|
24
|
+
var center = "pl-charts-center-r2OY1S";
|
|
25
|
+
var tooltip = "pl-charts-tooltip-r2OY1S";
|
|
26
|
+
var tooltipTitle = "pl-charts-tooltipTitle-r2OY1S";
|
|
27
|
+
var tooltipRow = "pl-charts-tooltipRow-r2OY1S";
|
|
28
|
+
var tooltipLabel = "pl-charts-tooltipLabel-r2OY1S";
|
|
29
|
+
var tooltipValue = "pl-charts-tooltipValue-r2OY1S";
|
|
30
|
+
var tooltipShare = "pl-charts-tooltipShare-r2OY1S";
|
|
31
|
+
var empty = "pl-charts-empty-r2OY1S";
|
|
32
|
+
var loading = "pl-charts-loading-r2OY1S";
|
|
33
|
+
var tableToggle = "pl-charts-tableToggle-r2OY1S";
|
|
34
|
+
var table = "pl-charts-table-r2OY1S";
|
|
35
|
+
var sparkline = "pl-charts-sparkline-r2OY1S";
|
|
36
|
+
var sparkLine = "pl-charts-sparkLine-r2OY1S";
|
|
37
|
+
var sparkArea = "pl-charts-sparkArea-r2OY1S";
|
|
38
|
+
var series = "pl-charts-series-r2OY1S";
|
|
39
|
+
var cell = "pl-charts-cell-r2OY1S";
|
|
40
|
+
var cellText = "pl-charts-cellText-r2OY1S";
|
|
41
|
+
var cellTextStrong = "pl-charts-cellTextStrong-r2OY1S";
|
|
42
|
+
var barValue = "pl-charts-barValue-r2OY1S";
|
|
43
|
+
var connector = "pl-charts-connector-r2OY1S";
|
|
44
|
+
var whisker = "pl-charts-whisker-r2OY1S";
|
|
45
|
+
var box = "pl-charts-box-r2OY1S";
|
|
46
|
+
var treemapGroup = "pl-charts-treemapGroup-r2OY1S";
|
|
47
|
+
var sankeyLink = "pl-charts-sankeyLink-r2OY1S";
|
|
48
|
+
var sankeyNode = "pl-charts-sankeyNode-r2OY1S";
|
|
49
|
+
var scale = "pl-charts-scale-r2OY1S";
|
|
50
|
+
var scaleBar = "pl-charts-scaleBar-r2OY1S";
|
|
51
|
+
var gauge = "pl-charts-gauge-r2OY1S";
|
|
52
|
+
var gaugeTrack = "pl-charts-gaugeTrack-r2OY1S";
|
|
53
|
+
var gaugeBand = "pl-charts-gaugeBand-r2OY1S";
|
|
54
|
+
var gaugeValue = "pl-charts-gaugeValue-r2OY1S";
|
|
55
|
+
var gaugeNeedle = "pl-charts-gaugeNeedle-r2OY1S";
|
|
56
|
+
var gaugeHub = "pl-charts-gaugeHub-r2OY1S";
|
|
57
|
+
var gaugeText = "pl-charts-gaugeText-r2OY1S";
|
|
58
|
+
var gaugeBandLabel = "pl-charts-gaugeBandLabel-r2OY1S";
|
|
59
|
+
var gridLine = "pl-charts-gridLine-r2OY1S";
|
|
60
|
+
var axisLine = "pl-charts-axisLine-r2OY1S";
|
|
61
|
+
var tickLabel = "pl-charts-tickLabel-r2OY1S";
|
|
62
|
+
var charts_module_default = {
|
|
63
|
+
figure,
|
|
64
|
+
caption,
|
|
65
|
+
title,
|
|
66
|
+
description,
|
|
67
|
+
legend,
|
|
68
|
+
legendItem,
|
|
69
|
+
legendDetail,
|
|
70
|
+
swatch,
|
|
71
|
+
plotWrap,
|
|
72
|
+
plot,
|
|
73
|
+
svg,
|
|
74
|
+
grid,
|
|
75
|
+
tickLabels,
|
|
76
|
+
axisTitle,
|
|
77
|
+
line,
|
|
78
|
+
area,
|
|
79
|
+
point,
|
|
80
|
+
bar,
|
|
81
|
+
guide,
|
|
82
|
+
activeBand,
|
|
83
|
+
activePoint,
|
|
84
|
+
slice,
|
|
85
|
+
center,
|
|
86
|
+
tooltip,
|
|
87
|
+
tooltipTitle,
|
|
88
|
+
tooltipRow,
|
|
89
|
+
tooltipLabel,
|
|
90
|
+
tooltipValue,
|
|
91
|
+
tooltipShare,
|
|
92
|
+
empty,
|
|
93
|
+
loading,
|
|
94
|
+
tableToggle,
|
|
95
|
+
table,
|
|
96
|
+
sparkline,
|
|
97
|
+
sparkLine,
|
|
98
|
+
sparkArea,
|
|
99
|
+
series,
|
|
100
|
+
cell,
|
|
101
|
+
cellText,
|
|
102
|
+
cellTextStrong,
|
|
103
|
+
barValue,
|
|
104
|
+
connector,
|
|
105
|
+
whisker,
|
|
106
|
+
box,
|
|
107
|
+
treemapGroup,
|
|
108
|
+
sankeyLink,
|
|
109
|
+
sankeyNode,
|
|
110
|
+
scale,
|
|
111
|
+
scaleBar,
|
|
112
|
+
gauge,
|
|
113
|
+
gaugeTrack,
|
|
114
|
+
gaugeBand,
|
|
115
|
+
gaugeValue,
|
|
116
|
+
gaugeNeedle,
|
|
117
|
+
gaugeHub,
|
|
118
|
+
gaugeText,
|
|
119
|
+
gaugeBandLabel,
|
|
120
|
+
gridLine,
|
|
121
|
+
axisLine,
|
|
122
|
+
tickLabel
|
|
123
|
+
};
|
|
124
|
+
export { activeBand, activePoint, area, axisLine, axisTitle, bar, barValue, box, caption, cell, cellText, cellTextStrong, center, connector, charts_module_default as default, description, empty, figure, gauge, gaugeBand, gaugeBandLabel, gaugeHub, gaugeNeedle, gaugeText, gaugeTrack, gaugeValue, grid, gridLine, guide, legend, legendDetail, legendItem, line, loading, plot, plotWrap, point, sankeyLink, sankeyNode, scale, scaleBar, series, slice, sparkArea, sparkLine, sparkline, svg, swatch, table, tableToggle, tickLabel, tickLabels, title, tooltip, tooltipLabel, tooltipRow, tooltipShare, tooltipTitle, tooltipValue, treemapGroup, whisker };
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=charts.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charts.module.js","names":[],"sources":[],"mappings":""}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Accessor, ChartMessages, XValue } from './types.js';
|
|
2
|
+
export declare const defaultMessages: ChartMessages;
|
|
3
|
+
export declare function read<Row, Value>(accessor: Accessor<Row, Value>, row: Row): Value;
|
|
4
|
+
export declare function seriesValue<Row>(series: {
|
|
5
|
+
key: string;
|
|
6
|
+
value?: (row: Row) => number | null | undefined;
|
|
7
|
+
}, row: Row): number | null;
|
|
8
|
+
/** The colour of the n-th series (0-based) from the theme, unless the series sets its own. */
|
|
9
|
+
export declare const seriesColor: (index: number, color?: string) => string;
|
|
10
|
+
export interface Formatters {
|
|
11
|
+
value: (value: number) => string;
|
|
12
|
+
tick: (value: number) => string;
|
|
13
|
+
x: (x: XValue) => string;
|
|
14
|
+
percent: (fraction: number) => string;
|
|
15
|
+
}
|
|
16
|
+
export interface FormatOptions {
|
|
17
|
+
valueFormat?: Intl.NumberFormatOptions;
|
|
18
|
+
formatValue?: (v: number) => string;
|
|
19
|
+
xFormat?: Intl.DateTimeFormatOptions;
|
|
20
|
+
formatX?: (x: XValue) => string;
|
|
21
|
+
}
|
|
22
|
+
/** Formatters for the locale, recreated only when the options' content changes (they are often inline objects). */
|
|
23
|
+
export declare function useFormatters(locale: string, { valueFormat, formatValue, xFormat, formatX }: FormatOptions): Formatters;
|
|
24
|
+
export declare function createFormatters(locale: string, options: FormatOptions): Formatters;
|
|
25
|
+
/**
|
|
26
|
+
* A factual description of a cartesian chart: what it covers and, per series, the range, where
|
|
27
|
+
* the extremes are and the change from first to last value. English sentences; numbers and lists
|
|
28
|
+
* use the locale. Pass `description` for other languages or to state the takeaway.
|
|
29
|
+
*/
|
|
30
|
+
export declare function summarizeCartesian<Row>(input: {
|
|
31
|
+
kind: string;
|
|
32
|
+
data: readonly Row[];
|
|
33
|
+
xs: XValue[];
|
|
34
|
+
series: ReadonlyArray<{
|
|
35
|
+
key: string;
|
|
36
|
+
label: string;
|
|
37
|
+
value?: (row: Row) => number | null | undefined;
|
|
38
|
+
}>;
|
|
39
|
+
format: Formatters;
|
|
40
|
+
locale: string;
|
|
41
|
+
}): string;
|
|
42
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,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G,UAAU,CAOvH;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,UAAU,CAYnF;AAID;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,KAAK,EAAE;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,GAAG,EAAE,CAAC;IACrB,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,MAAM,EAAE,aAAa,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;KAAE,CAAC,CAAC;IACvG,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,MAAM,CA0BT"}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
// src/format.ts
|
|
3
|
+
var defaultMessages = {
|
|
4
|
+
keyboardHint: "Use the arrow keys to move between data points, Home and End to jump to the first and last.",
|
|
5
|
+
showTable: "Show data table",
|
|
6
|
+
hideTable: "Hide data table",
|
|
7
|
+
empty: "No data to show",
|
|
8
|
+
loading: "Loading chart",
|
|
9
|
+
categoryHeader: "Category",
|
|
10
|
+
shareHeader: "Share",
|
|
11
|
+
tableCaption: (title) => `${title} (data)`
|
|
12
|
+
};
|
|
13
|
+
function read(accessor, row) {
|
|
14
|
+
return typeof accessor === "function" ? accessor(row) : row[accessor];
|
|
15
|
+
}
|
|
16
|
+
function seriesValue(series, row) {
|
|
17
|
+
const raw = series.value ? series.value(row) : row[series.key];
|
|
18
|
+
return typeof raw === "number" && Number.isFinite(raw) ? raw : null;
|
|
19
|
+
}
|
|
20
|
+
/** The colour of the n-th series (0-based) from the theme, unless the series sets its own. */
|
|
21
|
+
var seriesColor = (index, color) => color ?? `var(--pl-color-chart-${index % 6 + 1})`;
|
|
22
|
+
/** Formatters for the locale, recreated only when the options' content changes (they are often inline objects). */
|
|
23
|
+
function useFormatters(locale, { valueFormat, formatValue, xFormat, formatX }) {
|
|
24
|
+
const valueKey = JSON.stringify(valueFormat ?? null);
|
|
25
|
+
const xKey = JSON.stringify(xFormat ?? null);
|
|
26
|
+
return useMemo(() => createFormatters(locale, {
|
|
27
|
+
valueFormat: JSON.parse(valueKey) ?? void 0,
|
|
28
|
+
formatValue,
|
|
29
|
+
xFormat: JSON.parse(xKey) ?? void 0,
|
|
30
|
+
formatX
|
|
31
|
+
}), [
|
|
32
|
+
locale,
|
|
33
|
+
valueKey,
|
|
34
|
+
xKey,
|
|
35
|
+
formatValue,
|
|
36
|
+
formatX
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
function createFormatters(locale, options) {
|
|
40
|
+
const valueFormat = new Intl.NumberFormat(locale, options.valueFormat ?? { maximumFractionDigits: 2 });
|
|
41
|
+
const tickFormat = new Intl.NumberFormat(locale, {
|
|
42
|
+
...options.valueFormat,
|
|
43
|
+
notation: "compact",
|
|
44
|
+
maximumFractionDigits: 1,
|
|
45
|
+
minimumFractionDigits: 0
|
|
46
|
+
});
|
|
47
|
+
const dateFormat = new Intl.DateTimeFormat(locale, options.xFormat ?? {
|
|
48
|
+
month: "short",
|
|
49
|
+
day: "numeric"
|
|
50
|
+
});
|
|
51
|
+
const numberFormat = new Intl.NumberFormat(locale);
|
|
52
|
+
const percentFormat = new Intl.NumberFormat(locale, {
|
|
53
|
+
style: "percent",
|
|
54
|
+
maximumFractionDigits: 1
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
value: options.formatValue ?? ((v) => valueFormat.format(v)),
|
|
58
|
+
tick: options.formatValue && !options.valueFormat ? options.formatValue : (v) => tickFormat.format(v),
|
|
59
|
+
x: options.formatX ?? ((x) => x instanceof Date ? dateFormat.format(x) : typeof x === "number" ? numberFormat.format(x) : x),
|
|
60
|
+
percent: (f) => percentFormat.format(f)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
var list = (locale, items) => new Intl.ListFormat(locale, {
|
|
64
|
+
style: "long",
|
|
65
|
+
type: "conjunction"
|
|
66
|
+
}).format(items);
|
|
67
|
+
/**
|
|
68
|
+
* A factual description of a cartesian chart: what it covers and, per series, the range, where
|
|
69
|
+
* the extremes are and the change from first to last value. English sentences; numbers and lists
|
|
70
|
+
* use the locale. Pass `description` for other languages or to state the takeaway.
|
|
71
|
+
*/
|
|
72
|
+
function summarizeCartesian(input) {
|
|
73
|
+
const { kind, data, xs, series, format, locale } = input;
|
|
74
|
+
if (data.length === 0) return "";
|
|
75
|
+
const first = format.x(xs[0] ?? "");
|
|
76
|
+
const last = format.x(xs[xs.length - 1] ?? "");
|
|
77
|
+
const parts = [`${kind} of ${list(locale, series.map((s) => s.label))}, ${data.length} points from ${first} to ${last}.`];
|
|
78
|
+
for (const s of series.slice(0, 4)) {
|
|
79
|
+
const present = data.map((row) => seriesValue(s, row)).flatMap((v, i) => v === null ? [] : [{
|
|
80
|
+
v,
|
|
81
|
+
i
|
|
82
|
+
}]);
|
|
83
|
+
if (present.length === 0) continue;
|
|
84
|
+
const start = present[0];
|
|
85
|
+
const end = present[present.length - 1];
|
|
86
|
+
if (!start || !end) continue;
|
|
87
|
+
const min = present.reduce((a, b) => b.v < a.v ? b : a);
|
|
88
|
+
const max = present.reduce((a, b) => b.v > a.v ? b : a);
|
|
89
|
+
let change = "";
|
|
90
|
+
if (present.length > 1 && start.v !== 0) {
|
|
91
|
+
const delta = (end.v - start.v) / Math.abs(start.v);
|
|
92
|
+
change = delta === 0 ? " No change overall." : ` ${delta > 0 ? "Up" : "Down"} ${format.percent(Math.abs(delta))} from first to last.`;
|
|
93
|
+
}
|
|
94
|
+
parts.push(`${s.label}: lowest ${format.value(min.v)} (${format.x(xs[min.i] ?? "")}), highest ${format.value(max.v)} (${format.x(xs[max.i] ?? "")}).${change}`);
|
|
95
|
+
}
|
|
96
|
+
if (series.length > 4) parts.push(`${series.length - 4} more series are in the data table.`);
|
|
97
|
+
return parts.join(" ");
|
|
98
|
+
}
|
|
99
|
+
export { createFormatters, defaultMessages, read, seriesColor, seriesValue, summarizeCartesian, useFormatters };
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","names":[],"sources":["../src/format.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { Accessor, ChartMessages, XValue } from './types.js';\n\nexport const defaultMessages: ChartMessages = {\n keyboardHint: 'Use the arrow keys to move between data points, Home and End to jump to the first and last.',\n showTable: 'Show data table',\n hideTable: 'Hide data table',\n empty: 'No data to show',\n loading: 'Loading chart',\n categoryHeader: 'Category',\n shareHeader: 'Share',\n tableCaption: (title) => `${title} (data)`,\n};\n\nexport function read<Row, Value>(accessor: Accessor<Row, Value>, row: Row): Value {\n return typeof accessor === 'function' ? accessor(row) : (row[accessor] as Value);\n}\n\nexport function seriesValue<Row>(series: { key: string; value?: (row: Row) => number | null | undefined }, row: Row): number | null {\n const raw = series.value ? series.value(row) : (row as Record<string, unknown>)[series.key];\n return typeof raw === 'number' && Number.isFinite(raw) ? raw : null;\n}\n\n/** The colour of the n-th series (0-based) from the theme, unless the series sets its own. */\nexport const seriesColor = (index: number, color?: string) => color ?? `var(--pl-color-chart-${(index % 6) + 1})`;\n\nexport interface Formatters {\n value: (value: number) => string;\n tick: (value: number) => string;\n x: (x: XValue) => string;\n percent: (fraction: number) => string;\n}\n\nexport interface FormatOptions {\n valueFormat?: Intl.NumberFormatOptions;\n formatValue?: (v: number) => string;\n xFormat?: Intl.DateTimeFormatOptions;\n formatX?: (x: XValue) => string;\n}\n\n/** Formatters for the locale, recreated only when the options' content changes (they are often inline objects). */\nexport function useFormatters(locale: string, { valueFormat, formatValue, xFormat, formatX }: FormatOptions): Formatters {\n const valueKey = JSON.stringify(valueFormat ?? null);\n const xKey = JSON.stringify(xFormat ?? null);\n return useMemo(\n () => createFormatters(locale, { valueFormat: JSON.parse(valueKey) ?? undefined, formatValue, xFormat: JSON.parse(xKey) ?? undefined, formatX }),\n [locale, valueKey, xKey, formatValue, formatX],\n );\n}\n\nexport function createFormatters(locale: string, options: FormatOptions): Formatters {\n const valueFormat = new Intl.NumberFormat(locale, options.valueFormat ?? { maximumFractionDigits: 2 });\n const tickFormat = new Intl.NumberFormat(locale, { ...options.valueFormat, notation: 'compact', maximumFractionDigits: 1, minimumFractionDigits: 0 });\n const dateFormat = new Intl.DateTimeFormat(locale, options.xFormat ?? { month: 'short', day: 'numeric' });\n const numberFormat = new Intl.NumberFormat(locale);\n const percentFormat = new Intl.NumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 });\n return {\n value: options.formatValue ?? ((v) => valueFormat.format(v)),\n tick: options.formatValue && !options.valueFormat ? options.formatValue : (v) => tickFormat.format(v),\n x: options.formatX ?? ((x) => (x instanceof Date ? dateFormat.format(x) : typeof x === 'number' ? numberFormat.format(x) : x)),\n percent: (f) => percentFormat.format(f),\n };\n}\n\nconst list = (locale: string, items: string[]) => new Intl.ListFormat(locale, { style: 'long', type: 'conjunction' }).format(items);\n\n/**\n * A factual description of a cartesian chart: what it covers and, per series, the range, where\n * the extremes are and the change from first to last value. English sentences; numbers and lists\n * use the locale. Pass `description` for other languages or to state the takeaway.\n */\nexport function summarizeCartesian<Row>(input: {\n kind: string;\n data: readonly Row[];\n xs: XValue[];\n series: ReadonlyArray<{ key: string; label: string; value?: (row: Row) => number | null | undefined }>;\n format: Formatters;\n locale: string;\n}): string {\n const { kind, data, xs, series, format, locale } = input;\n if (data.length === 0) return '';\n const first = format.x(xs[0] ?? '');\n const last = format.x(xs[xs.length - 1] ?? '');\n const parts = [`${kind} of ${list(locale, series.map((s) => s.label))}, ${data.length} points from ${first} to ${last}.`];\n for (const s of series.slice(0, 4)) {\n const values = data.map((row) => seriesValue(s, row));\n const present = values.flatMap((v, i) => (v === null ? [] : [{ v, i }]));\n if (present.length === 0) continue;\n const start = present[0];\n const end = present[present.length - 1];\n if (!start || !end) continue;\n const min = present.reduce((a, b) => (b.v < a.v ? b : a));\n const max = present.reduce((a, b) => (b.v > a.v ? b : a));\n let change = '';\n if (present.length > 1 && start.v !== 0) {\n const delta = (end.v - start.v) / Math.abs(start.v);\n change = delta === 0 ? ' No change overall.' : ` ${delta > 0 ? 'Up' : 'Down'} ${format.percent(Math.abs(delta))} from first to last.`;\n }\n parts.push(\n `${s.label}: lowest ${format.value(min.v)} (${format.x(xs[min.i] ?? '')}), highest ${format.value(max.v)} (${format.x(xs[max.i] ?? '')}).${change}`,\n );\n }\n if (series.length > 4) parts.push(`${series.length - 4} more series are in the data table.`);\n return parts.join(' ');\n}\n"],"mappings":";;AAGA,IAAa,kBAAiC;CAC5C,cAAc;CACd,WAAW;CACX,WAAW;CACX,OAAO;CACP,SAAS;CACT,gBAAgB;CAChB,aAAa;CACb,eAAe,UAAU,GAAG,MAAM;AACpC;AAEA,SAAgB,KAAiB,UAAgC,KAAiB;CAChF,OAAO,OAAO,aAAa,aAAa,SAAS,GAAG,IAAK,IAAI;AAC/D;AAEA,SAAgB,YAAiB,QAA0E,KAAyB;CAClI,MAAM,MAAM,OAAO,QAAQ,OAAO,MAAM,GAAG,IAAK,IAAgC,OAAO;CACvF,OAAO,OAAO,QAAQ,YAAY,OAAO,SAAS,GAAG,IAAI,MAAM;AACjE;;AAGA,IAAa,eAAe,OAAe,UAAmB,SAAS,wBAAyB,QAAQ,IAAK,EAAE;;AAiB/G,SAAgB,cAAc,QAAgB,EAAE,aAAa,aAAa,SAAS,WAAsC;CACvH,MAAM,WAAW,KAAK,UAAU,eAAe,IAAI;CACnD,MAAM,OAAO,KAAK,UAAU,WAAW,IAAI;CAC3C,OAAO,cACC,iBAAiB,QAAQ;EAAE,aAAa,KAAK,MAAM,QAAQ,KAAK,KAAA;EAAW;EAAa,SAAS,KAAK,MAAM,IAAI,KAAK,KAAA;EAAW;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|
|
|
1
|
+
export { LineChart, AreaChart, BarChart, ScatterChart, type ScatterChartProps, type LineChartProps, type AreaChartProps, type BarChartProps } from './charts.js';
|
|
2
|
+
export { ComboChart, CandlestickChart, type ComboChartProps, type CandlestickChartProps } from './advanced-charts.js';
|
|
3
|
+
export { PieChart, type PieChartProps } from './pie-chart.js';
|
|
4
|
+
export { Sparkline, type SparklineProps } from './sparkline.js';
|
|
5
|
+
export type { Accessor, CartesianChartProps, ChartBaseProps, ChartMessages, ChartSeries, XValue } from './types.js';
|
|
6
|
+
export { Heatmap, Histogram, BoxPlot, boxStats, WaterfallChart, FunnelChart, Gauge, RadarChart, Treemap, Sankey, chartToSvg, downloadChart, type HeatmapProps, type HistogramProps, type BoxPlotProps, type BoxStats, type WaterfallChartProps, type FunnelChartProps, type GaugeProps, type GaugeBand, type RadarChartProps, type TreemapProps, type TreemapNode, type SankeyProps, type SankeyNode, type SankeyLink, } from './item-charts.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACjK,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACtH,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChE,YAAY,EAAE,QAAQ,EAAE,mBAAmB,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpH,OAAO,EACL,OAAO,EACP,SAAS,EACT,OAAO,EACP,QAAQ,EACR,cAAc,EACd,WAAW,EACX,KAAK,EACL,UAAU,EACV,OAAO,EACP,MAAM,EACN,UAAU,EACV,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,GAChB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AreaChart, BarChart, LineChart, ScatterChart } from "./charts.js";
|
|
2
|
+
import { CandlestickChart, ComboChart } from "./advanced-charts.js";
|
|
3
|
+
import { PieChart } from "./pie-chart.js";
|
|
4
|
+
import { Sparkline } from "./sparkline.js";
|
|
5
|
+
import { BoxPlot, FunnelChart, Gauge, Heatmap, Histogram, RadarChart, Sankey, Treemap, WaterfallChart, boxStats, chartToSvg, downloadChart } from "./item-charts.js";
|
|
6
|
+
export { AreaChart, BarChart, BoxPlot, CandlestickChart, ComboChart, FunnelChart, Gauge, Heatmap, Histogram, LineChart, PieChart, RadarChart, Sankey, ScatterChart, Sparkline, Treemap, WaterfallChart, boxStats, chartToSvg, downloadChart };
|