p1-charts 0.3.0 → 0.4.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 +26 -0
- package/README.md +58 -2
- package/dist/CategoryBarChart-KYzsjGwg.js +715 -0
- package/dist/CategoryBarChart-KYzsjGwg.js.map +1 -0
- package/dist/{ChartFrame-B1bVFM2E.js → ChartFrame-DOEsou-R.js} +2 -2
- package/dist/{ChartFrame-B1bVFM2E.js.map → ChartFrame-DOEsou-R.js.map} +1 -1
- package/dist/ChartLegend-B8ZmIG2y.js +46 -0
- package/dist/ChartLegend-B8ZmIG2y.js.map +1 -0
- package/dist/{Heatmap-CFC753mV.js → Heatmap-Bwhf305C.js} +2 -2
- package/dist/{Heatmap-CFC753mV.js.map → Heatmap-Bwhf305C.js.map} +1 -1
- package/dist/{PieLegend-CbpjaOJH.js → PieLegend-16E6W10x.js} +3 -3
- package/dist/{PieLegend-CbpjaOJH.js.map → PieLegend-16E6W10x.js.map} +1 -1
- package/dist/PolarChart-C_vPz-3K.js +489 -0
- package/dist/PolarChart-C_vPz-3K.js.map +1 -0
- package/dist/{TimeSeriesChart-BzeHEtQl.js → TimeSeriesChart-BZMLERDZ.js} +451 -451
- package/dist/{TimeSeriesChart-BzeHEtQl.js.map → TimeSeriesChart-BZMLERDZ.js.map} +1 -1
- package/dist/category.d.ts +4 -1
- package/dist/category.d.ts.map +1 -1
- package/dist/category.js +4 -3
- package/dist/charts/CategoryBarChart/index.d.ts +3 -1
- package/dist/charts/CategoryBarChart/index.d.ts.map +1 -1
- package/dist/charts/ScatterChart/index.d.ts +1 -1
- package/dist/charts/ScatterChart/index.d.ts.map +1 -1
- package/dist/components/ChartLegend/index.d.ts +13 -0
- package/dist/components/ChartLegend/index.d.ts.map +1 -0
- package/dist/{css-BtFQ2bM4.js → css-BTZA9hea.js} +2 -2
- package/dist/{css-BtFQ2bM4.js.map → css-BTZA9hea.js.map} +1 -1
- package/dist/heatmap.js +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -63
- package/dist/index.js.map +1 -1
- package/dist/pie.js +1 -1
- package/dist/scatter.d.ts +4 -1
- package/dist/scatter.d.ts.map +1 -1
- package/dist/scatter.js +3 -2
- package/dist/series.js +1 -1
- package/dist/standalone/p1-charts.standalone.js +13 -0
- package/dist/standalone.d.ts +27 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/story.js +2 -2
- package/dist/theme.js +2 -2
- package/dist/{theme.utils-DgmWROoe.js → theme.utils-DF_e8LxQ.js} +118 -119
- package/dist/theme.utils-DF_e8LxQ.js.map +1 -0
- package/dist/types/category.d.ts +16 -0
- package/dist/types/category.d.ts.map +1 -1
- package/dist/types/scatter.d.ts +31 -0
- package/dist/types/scatter.d.ts.map +1 -1
- package/dist/{useChartTheme-KKtc1C4K.js → useChartTheme-D0bQ3LQq.js} +2 -2
- package/dist/{useChartTheme-KKtc1C4K.js.map → useChartTheme-D0bQ3LQq.js.map} +1 -1
- package/dist/utils/category.utils.d.ts +13 -1
- package/dist/utils/category.utils.d.ts.map +1 -1
- package/dist/utils/scatter.utils.d.ts +17 -1
- package/dist/utils/scatter.utils.d.ts.map +1 -1
- package/dist/utils/theme.utils.d.ts +1 -1
- package/dist/utils/theme.utils.d.ts.map +1 -1
- package/package.json +7 -3
- package/src/category.ts +4 -1
- package/src/charts/CategoryBarChart/index.tsx +108 -19
- package/src/charts/ScatterChart/index.tsx +73 -10
- package/src/components/ChartLegend/index.tsx +46 -0
- package/src/index.ts +5 -1
- package/src/scatter.ts +4 -1
- package/src/standalone.tsx +68 -0
- package/src/types/category.ts +16 -0
- package/src/types/scatter.ts +20 -0
- package/src/utils/category.utils.ts +89 -2
- package/src/utils/scatter.utils.ts +22 -5
- package/src/utils/theme.utils.ts +18 -15
- package/dist/CategoryBarChart-1Kn3Vozc.js +0 -580
- package/dist/CategoryBarChart-1Kn3Vozc.js.map +0 -1
- package/dist/PolarChart-hcNTWKfJ.js +0 -450
- package/dist/PolarChart-hcNTWKfJ.js.map +0 -1
- package/dist/theme.utils-DgmWROoe.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type CategoryBarMode = "group" | "stack" | "overlay";
|
|
1
|
+
export type CategoryBarMode = "group" | "stack" | "overlay" | "dot";
|
|
2
2
|
export type CategoryOrientation = "vertical" | "horizontal";
|
|
3
3
|
export type CategoryScale = "left" | "right";
|
|
4
4
|
export interface CategorySeriesInput {
|
|
@@ -44,6 +44,11 @@ export interface CategoryLayoutOptions {
|
|
|
44
44
|
value: number;
|
|
45
45
|
scale?: CategoryScale;
|
|
46
46
|
}[];
|
|
47
|
+
/**
|
|
48
|
+
* Round each fitted end out so the four even ticks fall on round numbers (0.239 → 0.24 in
|
|
49
|
+
* steps of 0.06). A fixed `domain` end is kept as given. Default true.
|
|
50
|
+
*/
|
|
51
|
+
nice?: boolean;
|
|
47
52
|
}
|
|
48
53
|
export interface CategoryLine {
|
|
49
54
|
x1: number;
|
|
@@ -60,6 +65,13 @@ export interface CategoryFrame {
|
|
|
60
65
|
/** A line across the plot at one value. Horizontal charts draw it upright. */
|
|
61
66
|
across: (value: number, scale?: CategoryScale) => CategoryLine;
|
|
62
67
|
}
|
|
68
|
+
/** The smallest round step at or above `raw`: 1, 1.5, 2, 2.5, 3, 4, 5, 6 or 8 times a power of ten. */
|
|
69
|
+
export declare function niceStep(raw: number): number;
|
|
70
|
+
/**
|
|
71
|
+
* Widen the fitted ends of `[min, max]` so `count` even ticks are round numbers. An end fixed in
|
|
72
|
+
* `domain` stays where it is; the step is then chosen so the other end is round.
|
|
73
|
+
*/
|
|
74
|
+
export declare function niceExtent(min: number, max: number, domain?: CategoryDomain, count?: number): CategoryExtent;
|
|
63
75
|
/** Bar rectangles, the value extents, and a helper for a reference line. */
|
|
64
76
|
export declare function categoryFrame(options: CategoryLayoutOptions): CategoryFrame;
|
|
65
77
|
/** Bar rectangles for grouped, stacked, or overlaid category columns. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"category.utils.d.ts","sourceRoot":"","sources":["../../src/utils/category.utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"category.utils.d.ts","sourceRoot":"","sources":["../../src/utils/category.utils.ts"],"names":[],"mappings":"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"}
|
|
@@ -6,6 +6,11 @@ export interface ScatterSeriesInput {
|
|
|
6
6
|
id: string;
|
|
7
7
|
data: readonly ScatterDatum[];
|
|
8
8
|
}
|
|
9
|
+
/** A fixed extent for one axis. A missing end is fitted to the data. */
|
|
10
|
+
export interface ScatterDomain {
|
|
11
|
+
min?: number;
|
|
12
|
+
max?: number;
|
|
13
|
+
}
|
|
9
14
|
export interface PlacedScatterPoint {
|
|
10
15
|
series: string;
|
|
11
16
|
index: number;
|
|
@@ -15,11 +20,22 @@ export interface PlacedScatterPoint {
|
|
|
15
20
|
py: number;
|
|
16
21
|
}
|
|
17
22
|
export interface ScatterFrame {
|
|
23
|
+
pad: ScatterPad;
|
|
18
24
|
points: PlacedScatterPoint[];
|
|
19
25
|
xTicks: number[];
|
|
20
26
|
yTicks: number[];
|
|
21
27
|
xOf: (value: number) => number;
|
|
22
28
|
yOf: (value: number) => number;
|
|
23
29
|
}
|
|
24
|
-
export
|
|
30
|
+
export interface ScatterPad {
|
|
31
|
+
top: number;
|
|
32
|
+
right: number;
|
|
33
|
+
bottom: number;
|
|
34
|
+
left: number;
|
|
35
|
+
}
|
|
36
|
+
export declare const SCATTER_PAD: ScatterPad;
|
|
37
|
+
export declare function scatterLayout(series: readonly ScatterSeriesInput[], width: number, height: number, domains?: {
|
|
38
|
+
x?: ScatterDomain;
|
|
39
|
+
y?: ScatterDomain;
|
|
40
|
+
}, PAD?: ScatterPad): ScatterFrame;
|
|
25
41
|
//# sourceMappingURL=scatter.utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scatter.utils.d.ts","sourceRoot":"","sources":["../../src/utils/scatter.utils.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,SAAS,YAAY,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC/B,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAChC;
|
|
1
|
+
{"version":3,"file":"scatter.utils.d.ts","sourceRoot":"","sources":["../../src/utils/scatter.utils.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,SAAS,YAAY,EAAE,CAAC;CAC/B;AAED,wEAAwE;AACxE,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,UAAU,CAAC;IAChB,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC/B,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,WAAW,EAAE,UAAyD,CAAC;AAwBpF,wBAAgB,aAAa,CAC3B,MAAM,EAAE,SAAS,kBAAkB,EAAE,EACrC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IAAE,CAAC,CAAC,EAAE,aAAa,CAAC;IAAC,CAAC,CAAC,EAAE,aAAa,CAAA;CAAO,EACtD,GAAG,GAAE,UAAwB,GAC5B,YAAY,CA2Cd"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Theme, ThemeLine, ThemeText, ThemeInput } from "../types/theme.js";
|
|
2
|
-
import {
|
|
2
|
+
import type { DeepPartial, ChartOptions, PriceLineOptions, LineSeriesPartialOptions, AreaSeriesPartialOptions, BaselineSeriesPartialOptions, CandlestickSeriesPartialOptions } from "lightweight-charts";
|
|
3
3
|
import type { CSSProperties } from "react";
|
|
4
4
|
import { toSrgb, withAlpha } from "./color.utils.js";
|
|
5
5
|
import type { HistogramColors, LineVariant } from "../types/series.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.utils.d.ts","sourceRoot":"","sources":["../../src/utils/theme.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,SAAS,EACT,UAAU,EACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,
|
|
1
|
+
{"version":3,"file":"theme.utils.d.ts","sourceRoot":"","sources":["../../src/utils/theme.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,SAAS,EACT,UAAU,EACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAIV,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,4BAA4B,EAC5B,+BAA+B,EAChC,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEvE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAE7B,eAAO,MAAM,YAAY,EAAE,KAiC1B,CAAC;AAEF,wBAAgB,WAAW,CACzB,GAAG,QAAQ,EAAE,aAAa,CAAC,UAAU,GAAG,SAAS,CAAC,GACjD,KAAK,CAEP;AAkCD,wBAAgB,kBAAkB,CAChC,GAAG,KAAK,EAAE,aAAa,CAAC,SAAS,GAAG,SAAS,CAAC,GAC7C,OAAO,CAAC,gBAAgB,CAAC,CAQ3B;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,aAAa,CAOpE;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,KAAK,GAAG,IAAI,GAClB,WAAW,CAAC,YAAY,CAAC,CA2B3B;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,KAAK,GAAG,IAAI,GAClB,+BAA+B,CAiBjC;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,KAAK,GAAG,IAAI,EACnB,OAAO,EAAE,WAAW,GAElB,wBAAwB,GACxB,wBAAwB,GACxB,4BAA4B,CA4B/B;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,eAAe,CAW7E;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,KAAK,GAAG,IAAI,EACnB,IAAI,EAAE,SAAS,GAAG,SAAS,EAC3B,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAO3B;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAC/B,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,GAAG,SAAS,GAClD,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAEnC;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,EACvD,OAAO,CAAC,EAAE,OAAO,GAChB,UAAU,CAkCZ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "p1-charts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Reusable chart components for React",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -41,18 +41,22 @@
|
|
|
41
41
|
"./story": {
|
|
42
42
|
"types": "./dist/story.d.ts",
|
|
43
43
|
"default": "./dist/story.js"
|
|
44
|
+
},
|
|
45
|
+
"./standalone": {
|
|
46
|
+
"default": "./dist/standalone/p1-charts.standalone.js"
|
|
44
47
|
}
|
|
45
48
|
},
|
|
46
49
|
"sideEffects": false,
|
|
47
50
|
"scripts": {
|
|
48
51
|
"test": "vitest run",
|
|
49
|
-
"build": "vite build && tsc -p tsconfig.build.json",
|
|
52
|
+
"build": "vite build && tsc -p tsconfig.build.json && vite build -c vite.standalone.mts",
|
|
50
53
|
"prepack": "npm run build",
|
|
51
54
|
"typecheck": "tsc --noEmit",
|
|
52
55
|
"dev": "vite build --watch",
|
|
53
56
|
"test:watch": "vitest",
|
|
54
57
|
"playground": "vite serve playground --config vite.config.mts",
|
|
55
|
-
"tokens:p1": "node playground/themes/build-p1.ts"
|
|
58
|
+
"tokens:p1": "node playground/themes/build-p1.ts",
|
|
59
|
+
"build:standalone": "vite build -c vite.standalone.mts"
|
|
56
60
|
},
|
|
57
61
|
"repository": {
|
|
58
62
|
"type": "git",
|
package/src/category.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { CategoryBarChart } from "./charts/CategoryBarChart/index.js";
|
|
2
|
-
export { categoryLayout } from "./utils/category.utils.js";
|
|
2
|
+
export { categoryLayout, niceExtent, niceStep } from "./utils/category.utils.js";
|
|
3
|
+
export { labelRoom } from "./charts/CategoryBarChart/index.js";
|
|
4
|
+
export { ChartLegend } from "./components/ChartLegend/index.js";
|
|
5
|
+
export type { ChartLegendItem } from "./components/ChartLegend/index.js";
|
|
3
6
|
export { bin } from "./utils/bin.utils.js";
|
|
4
7
|
|
|
5
8
|
export type {
|
|
@@ -18,6 +18,7 @@ import { useTween } from "../../hooks/useTween.js";
|
|
|
18
18
|
import { useMarkMemory } from "../../hooks/useMarkMemory.js";
|
|
19
19
|
import { sortOrder } from "../../utils/category.utils.js";
|
|
20
20
|
import { HEATMAP_SVG } from "../../styles/heatmap.js";
|
|
21
|
+
import { ChartLegend } from "../../components/ChartLegend/index.js";
|
|
21
22
|
|
|
22
23
|
const WIDTH = 640;
|
|
23
24
|
const HEIGHT = 320;
|
|
@@ -28,6 +29,13 @@ function ink(categorical: readonly string[], index: number, color?: string) {
|
|
|
28
29
|
return color ?? categorical[index % Math.max(1, categorical.length)] ?? "currentColor";
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
/** Room for 11px category labels: about 6.2 units a character, never under the old 108. */
|
|
33
|
+
export function labelRoom(labels: readonly string[]): number {
|
|
34
|
+
const longest = labels.reduce((most, label) => Math.max(most, label.length), 0);
|
|
35
|
+
|
|
36
|
+
return Math.max(108, Math.ceil(longest * 6.2) + 14);
|
|
37
|
+
}
|
|
38
|
+
|
|
31
39
|
function readDatum(datum: CategoryBarDatum | undefined): {
|
|
32
40
|
value: number | undefined;
|
|
33
41
|
color?: string;
|
|
@@ -69,6 +77,9 @@ export function CategoryBarChart({
|
|
|
69
77
|
bands = NO_BANDS,
|
|
70
78
|
activeIndex,
|
|
71
79
|
valueLabel,
|
|
80
|
+
labelWidth,
|
|
81
|
+
nice = true,
|
|
82
|
+
legend = false,
|
|
72
83
|
width = WIDTH,
|
|
73
84
|
height = HEIGHT,
|
|
74
85
|
className,
|
|
@@ -108,10 +119,11 @@ export function CategoryBarChart({
|
|
|
108
119
|
const hasRight = series.some((item) => item.scale === "right");
|
|
109
120
|
const pad =
|
|
110
121
|
orientation === "horizontal"
|
|
111
|
-
? { top: 12, right: hasRight ? 48 : 64, bottom: valueLabel ? 36 : 28, left:
|
|
112
|
-
: { top: 16, right: hasRight ? 48 : 12, bottom: valueLabel ? 40 : 28, left: 44 };
|
|
122
|
+
? { top: 12, right: hasRight ? 48 : 64, bottom: valueLabel ? 36 : 28, left: labelWidth ?? labelRoom(categories) }
|
|
123
|
+
: { top: 16, right: hasRight ? 48 : 12, bottom: valueLabel ? 40 : 28, left: labelWidth ?? 44 };
|
|
113
124
|
const lines = reference ? [reference, ...references] : references;
|
|
114
125
|
const frame = categoryFrame({
|
|
126
|
+
nice,
|
|
115
127
|
mode,
|
|
116
128
|
orientation,
|
|
117
129
|
domain,
|
|
@@ -201,7 +213,9 @@ export function CategoryBarChart({
|
|
|
201
213
|
|
|
202
214
|
return frame.across(Math.max(extent.min, Math.min(extent.max, 0)), scale);
|
|
203
215
|
};
|
|
216
|
+
const dot = mode === "dot";
|
|
204
217
|
const toBaseline = (memory: BarMemory | undefined, [x, y, w, h]: readonly number[]) => {
|
|
218
|
+
if (dot) return [x!, y!, w!, h!]; // a dot fades where it is; it does not grow from zero
|
|
205
219
|
const base = baseline(memory?.scale ?? "left");
|
|
206
220
|
|
|
207
221
|
return horizontal ? [base.x1, y!, 0, h!] : [x!, base.y1, w!, 0];
|
|
@@ -240,6 +254,8 @@ export function CategoryBarChart({
|
|
|
240
254
|
previousAcross.current = frame.across;
|
|
241
255
|
});
|
|
242
256
|
|
|
257
|
+
const centre = (x: number, y: number, w: number, h: number) =>
|
|
258
|
+
horizontal ? { cx: x, cy: y + h / 2 } : { cx: x + w / 2, cy: y };
|
|
243
259
|
const fade = (key: string) => {
|
|
244
260
|
const opacity = drawn[key]?.[1] ?? 1;
|
|
245
261
|
|
|
@@ -278,6 +294,17 @@ export function CategoryBarChart({
|
|
|
278
294
|
data-orientation={orientation}
|
|
279
295
|
style={{ position: "relative" }}
|
|
280
296
|
>
|
|
297
|
+
{legend && (
|
|
298
|
+
<ChartLegend
|
|
299
|
+
unstyled={unstyled}
|
|
300
|
+
color={text}
|
|
301
|
+
items={
|
|
302
|
+
legend === true
|
|
303
|
+
? series.map((item, index) => ({ label: item.name, color: seriesColor(item, categorical, index) }))
|
|
304
|
+
: legend
|
|
305
|
+
}
|
|
306
|
+
/>
|
|
307
|
+
)}
|
|
281
308
|
<svg
|
|
282
309
|
role="img"
|
|
283
310
|
aria-label={ariaLabel}
|
|
@@ -446,6 +473,37 @@ export function CategoryBarChart({
|
|
|
446
473
|
</g>
|
|
447
474
|
);
|
|
448
475
|
})}
|
|
476
|
+
{dot &&
|
|
477
|
+
categories.map((label, category) => {
|
|
478
|
+
const placed = frame.rects
|
|
479
|
+
.filter((rect) => rect.category === category)
|
|
480
|
+
.map((rect) => {
|
|
481
|
+
const [x, y, w, h] = drawn[`bar:${rect.series}:${label}`] ?? [];
|
|
482
|
+
|
|
483
|
+
return centre(x ?? rect.x, y ?? rect.y, w ?? rect.width, h ?? rect.height);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
if (placed.length < 2) return null;
|
|
487
|
+
|
|
488
|
+
const along = placed.map((point) => (horizontal ? point.cx : point.cy));
|
|
489
|
+
const at = horizontal ? placed[0]!.cy : placed[0]!.cx;
|
|
490
|
+
const lo = Math.min(...along);
|
|
491
|
+
const hi = Math.max(...along);
|
|
492
|
+
|
|
493
|
+
return (
|
|
494
|
+
<line
|
|
495
|
+
key={`span:${label}`}
|
|
496
|
+
data-part="dot-span"
|
|
497
|
+
data-key={label}
|
|
498
|
+
x1={horizontal ? lo : at}
|
|
499
|
+
x2={horizontal ? hi : at}
|
|
500
|
+
y1={horizontal ? at : lo}
|
|
501
|
+
y2={horizontal ? at : hi}
|
|
502
|
+
stroke={grid}
|
|
503
|
+
strokeWidth={2}
|
|
504
|
+
/>
|
|
505
|
+
);
|
|
506
|
+
})}
|
|
449
507
|
{frame.rects.map((placed) => {
|
|
450
508
|
const label = categories[placed.category];
|
|
451
509
|
const [x, y, w, h] = drawn[`bar:${placed.series}:${label}`] ?? [];
|
|
@@ -462,27 +520,42 @@ export function CategoryBarChart({
|
|
|
462
520
|
|
|
463
521
|
return (
|
|
464
522
|
<g key={`${rect.series}:${label}`}>
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
523
|
+
{dot ? (
|
|
524
|
+
<circle
|
|
525
|
+
data-part="dot"
|
|
526
|
+
data-key={label}
|
|
527
|
+
data-series={rect.series}
|
|
528
|
+
data-category={rect.category}
|
|
529
|
+
data-active={rect.category === active ? "" : undefined}
|
|
530
|
+
{...centre(rect.x, rect.y, rect.width, rect.height)}
|
|
531
|
+
r={rect.category === active ? 5 : 4}
|
|
532
|
+
fill={datum?.color ?? seriesColor(item, categorical, index)}
|
|
533
|
+
onPointerEnter={() => setFocus(rect.category)}
|
|
534
|
+
onClick={() => choose(rect.category)}
|
|
535
|
+
/>
|
|
536
|
+
) : (
|
|
537
|
+
<rect
|
|
538
|
+
data-part="bar"
|
|
539
|
+
data-key={label}
|
|
540
|
+
data-series={rect.series}
|
|
541
|
+
data-category={rect.category}
|
|
542
|
+
data-active={rect.category === active ? "" : undefined}
|
|
543
|
+
x={rect.x}
|
|
544
|
+
y={rect.y}
|
|
545
|
+
width={rect.width}
|
|
546
|
+
height={Math.max(rect.height, rect.value === 0 ? 0 : 1)}
|
|
547
|
+
fill={datum?.color ?? seriesColor(item, categorical, index)}
|
|
548
|
+
opacity={mode === "overlay" ? 0.72 : 1}
|
|
549
|
+
onPointerEnter={() => setFocus(rect.category)}
|
|
550
|
+
onClick={() => choose(rect.category)}
|
|
551
|
+
/>
|
|
552
|
+
)}
|
|
480
553
|
{datum?.label && (
|
|
481
554
|
<text
|
|
482
555
|
data-part="bar-label"
|
|
483
556
|
data-series={rect.series}
|
|
484
|
-
x={orientation === "horizontal" ? rect.x + rect.width + 4 : rect.x + rect.width / 2}
|
|
485
|
-
y={orientation === "horizontal" ? rect.y + rect.height / 2 : rect.y - 4}
|
|
557
|
+
x={orientation === "horizontal" ? rect.x + rect.width + (dot ? 8 : 4) : rect.x + rect.width / 2}
|
|
558
|
+
y={orientation === "horizontal" ? rect.y + rect.height / 2 : rect.y - (dot ? 8 : 4)}
|
|
486
559
|
textAnchor={orientation === "horizontal" ? "start" : "middle"}
|
|
487
560
|
dominantBaseline={orientation === "horizontal" ? "middle" : "auto"}
|
|
488
561
|
fill={text}
|
|
@@ -498,6 +571,22 @@ export function CategoryBarChart({
|
|
|
498
571
|
const [x, y, w, h] = drawn[key]!;
|
|
499
572
|
const gone = memory.current.get(key);
|
|
500
573
|
|
|
574
|
+
if (dot) {
|
|
575
|
+
return (
|
|
576
|
+
<circle
|
|
577
|
+
key={key}
|
|
578
|
+
data-part="dot"
|
|
579
|
+
data-leaving=""
|
|
580
|
+
data-key={gone?.label}
|
|
581
|
+
data-series={gone?.series}
|
|
582
|
+
{...centre(x!, y!, w!, h!)}
|
|
583
|
+
r={4}
|
|
584
|
+
fill={gone?.color}
|
|
585
|
+
pointerEvents="none"
|
|
586
|
+
/>
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
|
|
501
590
|
return (
|
|
502
591
|
<rect
|
|
503
592
|
key={key}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useLayoutEffect, useRef, useState, type KeyboardEvent } from "react";
|
|
2
2
|
import type { ScatterChartProps } from "../../types/scatter.js";
|
|
3
3
|
import { useChartTheme } from "../../hooks/useChartTheme.js";
|
|
4
|
-
import { scatterLayout } from "../../utils/scatter.utils.js";
|
|
4
|
+
import { SCATTER_PAD, scatterLayout } from "../../utils/scatter.utils.js";
|
|
5
|
+
import { ChartLegend } from "../../components/ChartLegend/index.js";
|
|
5
6
|
import { classes } from "../../utils/dom.utils.js";
|
|
6
7
|
import { HEATMAP_SVG } from "../../styles/heatmap.js";
|
|
7
8
|
import { useTween } from "../../hooks/useTween.js";
|
|
@@ -20,6 +21,12 @@ export function ScatterChart({
|
|
|
20
21
|
ariaLabel = "Scatter chart",
|
|
21
22
|
xLabel,
|
|
22
23
|
yLabel,
|
|
24
|
+
xDomain,
|
|
25
|
+
yDomain,
|
|
26
|
+
formatX,
|
|
27
|
+
formatY,
|
|
28
|
+
references = [],
|
|
29
|
+
legend = false,
|
|
23
30
|
animate = true,
|
|
24
31
|
onSelect,
|
|
25
32
|
renderTooltip,
|
|
@@ -30,7 +37,21 @@ export function ScatterChart({
|
|
|
30
37
|
const categorical = resolved?.palette.categorical ?? [];
|
|
31
38
|
const text = resolved?.palette.text;
|
|
32
39
|
const grid = resolved?.palette.grid;
|
|
33
|
-
|
|
40
|
+
// Axis titles get their own room: the y title runs up the left edge, the x title under the ticks.
|
|
41
|
+
const pad = {
|
|
42
|
+
...SCATTER_PAD,
|
|
43
|
+
left: SCATTER_PAD.left + (yLabel ? 16 : 0),
|
|
44
|
+
bottom: SCATTER_PAD.bottom + (xLabel ? 14 : 0),
|
|
45
|
+
};
|
|
46
|
+
const frame = scatterLayout(
|
|
47
|
+
[...series, ...references.map((line, index) => ({ id: `ref:${index}`, data: [line.from, line.to] }))],
|
|
48
|
+
width,
|
|
49
|
+
height,
|
|
50
|
+
{ x: xDomain, y: yDomain },
|
|
51
|
+
pad,
|
|
52
|
+
);
|
|
53
|
+
const plotted = new Set(series.map((item) => item.id));
|
|
54
|
+
frame.points = frame.points.filter((item) => plotted.has(item.series));
|
|
34
55
|
const target: Record<string, number[]> = {};
|
|
35
56
|
const colors = new Map<string, string | undefined>();
|
|
36
57
|
|
|
@@ -105,6 +126,25 @@ export function ScatterChart({
|
|
|
105
126
|
|
|
106
127
|
return (
|
|
107
128
|
<div className={classes(className)} style={{ position: "relative" }}>
|
|
129
|
+
{legend && (
|
|
130
|
+
<ChartLegend
|
|
131
|
+
unstyled={unstyled}
|
|
132
|
+
color={text}
|
|
133
|
+
items={
|
|
134
|
+
legend === true
|
|
135
|
+
? [
|
|
136
|
+
...series.map((item, index) => ({
|
|
137
|
+
label: item.name,
|
|
138
|
+
color: item.color ?? categorical[index % Math.max(1, categorical.length)] ?? "currentColor",
|
|
139
|
+
})),
|
|
140
|
+
...references.flatMap((line) =>
|
|
141
|
+
line.label ? [{ label: line.label, color: line.color ?? grid ?? "currentColor", dashed: true }] : [],
|
|
142
|
+
),
|
|
143
|
+
]
|
|
144
|
+
: legend
|
|
145
|
+
}
|
|
146
|
+
/>
|
|
147
|
+
)}
|
|
108
148
|
<svg
|
|
109
149
|
role="img"
|
|
110
150
|
aria-label={ariaLabel}
|
|
@@ -115,27 +155,45 @@ export function ScatterChart({
|
|
|
115
155
|
>
|
|
116
156
|
{ticks("y").map((tick) => (
|
|
117
157
|
<g key={tick.key} opacity={tick.opacity}>
|
|
118
|
-
<line data-part="grid" x1={
|
|
119
|
-
<text data-part="tick" x={
|
|
120
|
-
{tick.value}
|
|
158
|
+
<line data-part="grid" x1={pad.left} x2={width - pad.right} y1={tick.at} y2={tick.at} stroke={grid} />
|
|
159
|
+
<text data-part="tick" x={pad.left - 4} y={tick.at} textAnchor="end" dominantBaseline="middle" fill={text} fontSize={11}>
|
|
160
|
+
{formatY?.(tick.value) ?? tick.value}
|
|
121
161
|
</text>
|
|
122
162
|
</g>
|
|
123
163
|
))}
|
|
124
164
|
{ticks("x").map((tick) => (
|
|
125
|
-
<text key={tick.key} data-part="tick" x={tick.at} y={height -
|
|
126
|
-
{tick.value}
|
|
165
|
+
<text key={tick.key} data-part="tick" x={tick.at} y={height - pad.bottom + 16} opacity={tick.opacity} textAnchor="middle" fill={text} fontSize={11}>
|
|
166
|
+
{formatX?.(tick.value) ?? tick.value}
|
|
127
167
|
</text>
|
|
128
168
|
))}
|
|
129
169
|
{xLabel && (
|
|
130
|
-
<text data-part="axis-label" x={width / 2} y={height -
|
|
170
|
+
<text data-part="axis-label" x={(pad.left + width - pad.right) / 2} y={height - 4} textAnchor="middle" fill={text} fontSize={11}>
|
|
131
171
|
{xLabel}
|
|
132
172
|
</text>
|
|
133
173
|
)}
|
|
134
174
|
{yLabel && (
|
|
135
|
-
<text
|
|
175
|
+
<text
|
|
176
|
+
data-part="axis-label"
|
|
177
|
+
transform={`translate(12 ${(pad.top + height - pad.bottom) / 2}) rotate(-90)`}
|
|
178
|
+
textAnchor="middle"
|
|
179
|
+
fill={text}
|
|
180
|
+
fontSize={11}
|
|
181
|
+
>
|
|
136
182
|
{yLabel}
|
|
137
183
|
</text>
|
|
138
184
|
)}
|
|
185
|
+
{references.map((line, index) => (
|
|
186
|
+
<line
|
|
187
|
+
key={`ref-${index}`}
|
|
188
|
+
data-part="reference"
|
|
189
|
+
x1={frame.xOf(line.from.x)}
|
|
190
|
+
y1={frame.yOf(line.from.y)}
|
|
191
|
+
x2={frame.xOf(line.to.x)}
|
|
192
|
+
y2={frame.yOf(line.to.y)}
|
|
193
|
+
stroke={line.color ?? grid}
|
|
194
|
+
strokeDasharray="4 3"
|
|
195
|
+
/>
|
|
196
|
+
))}
|
|
139
197
|
{series.map((entry) => {
|
|
140
198
|
if (!entry.line) return null;
|
|
141
199
|
|
|
@@ -160,7 +218,12 @@ export function ScatterChart({
|
|
|
160
218
|
data-series={entry.id}
|
|
161
219
|
d={d}
|
|
162
220
|
fill="none"
|
|
163
|
-
stroke={
|
|
221
|
+
stroke={
|
|
222
|
+
entry.color ??
|
|
223
|
+
(entry.markers === false
|
|
224
|
+
? text
|
|
225
|
+
: categorical[series.indexOf(entry) % Math.max(1, categorical.length)] ?? text)
|
|
226
|
+
}
|
|
164
227
|
strokeDasharray={DASH[entry.lineStyle ?? "solid"]}
|
|
165
228
|
/>
|
|
166
229
|
);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
|
|
3
|
+
export interface ChartLegendItem {
|
|
4
|
+
label: string;
|
|
5
|
+
color: string;
|
|
6
|
+
/** Draw the swatch as a dashed line, for a reference such as a diagonal. */
|
|
7
|
+
dashed?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const ROW: CSSProperties = { display: "flex", flexWrap: "wrap", gap: "4px 14px", fontSize: 11, marginBottom: 6 };
|
|
11
|
+
const ITEM: CSSProperties = { display: "inline-flex", alignItems: "center", gap: 5 };
|
|
12
|
+
|
|
13
|
+
/** Swatch and name per item, above a chart. `data-part="legend"`, items `legend-item`, swatches `swatch`. */
|
|
14
|
+
export function ChartLegend({
|
|
15
|
+
items,
|
|
16
|
+
color,
|
|
17
|
+
unstyled,
|
|
18
|
+
}: {
|
|
19
|
+
items: readonly ChartLegendItem[];
|
|
20
|
+
color?: string;
|
|
21
|
+
unstyled?: boolean;
|
|
22
|
+
}) {
|
|
23
|
+
if (items.length === 0) return null;
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div data-part="legend" style={unstyled ? undefined : { ...ROW, color }}>
|
|
27
|
+
{items.map((item) => (
|
|
28
|
+
<span key={item.label} data-part="legend-item" style={unstyled ? undefined : ITEM}>
|
|
29
|
+
<span
|
|
30
|
+
data-part="swatch"
|
|
31
|
+
data-dashed={item.dashed ? "" : undefined}
|
|
32
|
+
aria-hidden="true"
|
|
33
|
+
style={
|
|
34
|
+
unstyled
|
|
35
|
+
? undefined
|
|
36
|
+
: item.dashed
|
|
37
|
+
? { width: 14, height: 0, borderTop: `2px dashed ${item.color}` }
|
|
38
|
+
: { width: 10, height: 10, borderRadius: 2, background: item.color }
|
|
39
|
+
}
|
|
40
|
+
/>
|
|
41
|
+
{item.label}
|
|
42
|
+
</span>
|
|
43
|
+
))}
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -234,7 +234,11 @@ export type {
|
|
|
234
234
|
CategoryScale,
|
|
235
235
|
} from "./utils/category.utils.js";
|
|
236
236
|
export type { Bin, BinOptions } from "./utils/bin.utils.js";
|
|
237
|
-
export type { ScatterChartProps, ScatterSeries } from "./types/scatter.js";
|
|
237
|
+
export type { ScatterChartProps, ScatterReference, ScatterSeries } from "./types/scatter.js";
|
|
238
|
+
export type { ScatterDomain } from "./utils/scatter.utils.js";
|
|
239
|
+
export { ChartLegend } from "./components/ChartLegend/index.js";
|
|
240
|
+
export type { ChartLegendItem } from "./components/ChartLegend/index.js";
|
|
241
|
+
export { niceExtent, niceStep } from "./utils/category.utils.js";
|
|
238
242
|
export type { PolarChartProps } from "./types/polar.js";
|
|
239
243
|
export type { SparklineProps } from "./types/sparkline.js";
|
|
240
244
|
export type { Mode } from "./themes/p1.js";
|
package/src/scatter.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { ScatterChart } from "./charts/ScatterChart/index.js";
|
|
2
2
|
export { PolarChart } from "./charts/PolarChart/index.js";
|
|
3
3
|
export { scatterLayout } from "./utils/scatter.utils.js";
|
|
4
|
+
export type { ScatterDomain } from "./utils/scatter.utils.js";
|
|
4
5
|
export { sectorPath } from "./utils/polar.utils.js";
|
|
5
6
|
|
|
6
|
-
export type { ScatterChartProps, ScatterSeries } from "./types/scatter.js";
|
|
7
|
+
export type { ScatterChartProps, ScatterReference, ScatterSeries } from "./types/scatter.js";
|
|
8
|
+
export { ChartLegend } from "./components/ChartLegend/index.js";
|
|
9
|
+
export type { ChartLegendItem } from "./components/ChartLegend/index.js";
|
|
7
10
|
export type { PolarChartProps } from "./types/polar.js";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* p1-charts for pages without React: one script that carries React and the SVG charts.
|
|
3
|
+
*
|
|
4
|
+
* <script src="p1-charts.standalone.js"></script>
|
|
5
|
+
* P1Charts.render(el, "CategoryBarChart", { categories, series, orientation: "horizontal" });
|
|
6
|
+
*
|
|
7
|
+
* `render` mounts once per element and re-renders on later calls; `unmount` removes it. Props are
|
|
8
|
+
* the components' own props, so functions (formatValue, renderTooltip returning a string) work.
|
|
9
|
+
* The canvas charts (TimeSeriesChart and friends) stay in the React entries.
|
|
10
|
+
*/
|
|
11
|
+
import { createElement, type ComponentType } from "react";
|
|
12
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
13
|
+
import { CategoryBarChart } from "./charts/CategoryBarChart/index.js";
|
|
14
|
+
import { ScatterChart } from "./charts/ScatterChart/index.js";
|
|
15
|
+
import { PolarChart } from "./charts/PolarChart/index.js";
|
|
16
|
+
import { PieChart } from "./charts/PieChart/index.js";
|
|
17
|
+
import { Heatmap } from "./charts/Heatmap/index.js";
|
|
18
|
+
import { Sparkline } from "./charts/Sparkline/index.js";
|
|
19
|
+
import { ChartLegend } from "./components/ChartLegend/index.js";
|
|
20
|
+
import { createTheme } from "./utils/theme.utils.js";
|
|
21
|
+
import { p1Theme } from "./themes/p1.js";
|
|
22
|
+
import { p1ThemeFromCss } from "./themes/css.js";
|
|
23
|
+
import { bin } from "./utils/bin.utils.js";
|
|
24
|
+
import { niceExtent, niceStep } from "./utils/category.utils.js";
|
|
25
|
+
|
|
26
|
+
const charts: Record<string, ComponentType<any>> = {
|
|
27
|
+
CategoryBarChart,
|
|
28
|
+
ScatterChart,
|
|
29
|
+
PolarChart,
|
|
30
|
+
PieChart,
|
|
31
|
+
Heatmap,
|
|
32
|
+
Sparkline,
|
|
33
|
+
ChartLegend,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const roots = new WeakMap<Element, Root>();
|
|
37
|
+
|
|
38
|
+
export type StandaloneChart = keyof typeof charts;
|
|
39
|
+
|
|
40
|
+
/** Draw `chart` with `props` into `el`; a later call on the same element updates it in place. */
|
|
41
|
+
export function render(el: Element, chart: StandaloneChart, props: Record<string, unknown>): void {
|
|
42
|
+
const component = charts[chart];
|
|
43
|
+
|
|
44
|
+
if (!component) throw new Error(`p1-charts standalone: no chart named "${chart}"`);
|
|
45
|
+
|
|
46
|
+
let root = roots.get(el);
|
|
47
|
+
|
|
48
|
+
if (!root) {
|
|
49
|
+
el.replaceChildren();
|
|
50
|
+
root = createRoot(el);
|
|
51
|
+
roots.set(el, root);
|
|
52
|
+
}
|
|
53
|
+
root.render(createElement(component, props));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Remove the chart drawn into `el`. */
|
|
57
|
+
export function unmount(el: Element): void {
|
|
58
|
+
roots.get(el)?.unmount();
|
|
59
|
+
roots.delete(el);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The charts `render` knows by name. */
|
|
63
|
+
export const chartNames = Object.keys(charts);
|
|
64
|
+
export { bin, createTheme, niceExtent, niceStep, p1Theme, p1ThemeFromCss };
|
|
65
|
+
export const version: string =
|
|
66
|
+
typeof __P1_CHARTS_VERSION__ === "string" ? __P1_CHARTS_VERSION__ : "dev";
|
|
67
|
+
|
|
68
|
+
declare const __P1_CHARTS_VERSION__: string;
|