p1-charts 0.2.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 +54 -0
- package/README.md +158 -4
- package/dist/CategoryBarChart-KYzsjGwg.js +715 -0
- package/dist/CategoryBarChart-KYzsjGwg.js.map +1 -0
- package/dist/ChartFrame-DOEsou-R.js +403 -0
- package/dist/ChartFrame-DOEsou-R.js.map +1 -0
- package/dist/ChartLegend-B8ZmIG2y.js +46 -0
- package/dist/ChartLegend-B8ZmIG2y.js.map +1 -0
- package/dist/{Heatmap-C1XcTUg1.js → Heatmap-Bwhf305C.js} +278 -272
- package/dist/Heatmap-Bwhf305C.js.map +1 -0
- package/dist/{PieLegend-BZsv9IbF.js → PieLegend-16E6W10x.js} +94 -111
- package/dist/PieLegend-16E6W10x.js.map +1 -0
- package/dist/PolarChart-C_vPz-3K.js +489 -0
- package/dist/PolarChart-C_vPz-3K.js.map +1 -0
- package/dist/Sparkline-BApLVWfg.js +110 -0
- package/dist/Sparkline-BApLVWfg.js.map +1 -0
- package/dist/{TimeSeriesChart-BIwJxgnD.js → TimeSeriesChart-BZMLERDZ.js} +530 -529
- package/dist/{TimeSeriesChart-BIwJxgnD.js.map → TimeSeriesChart-BZMLERDZ.js.map} +1 -1
- package/dist/category.d.ts +5 -2
- 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/Heatmap/index.d.ts.map +1 -1
- package/dist/charts/PolarChart/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/charts/Sparkline/index.d.ts +5 -2
- package/dist/charts/Sparkline/index.d.ts.map +1 -1
- package/dist/components/ChartFrame/index.d.ts +7 -0
- package/dist/components/ChartFrame/index.d.ts.map +1 -0
- package/dist/components/ChartLegend/index.d.ts +13 -0
- package/dist/components/ChartLegend/index.d.ts.map +1 -0
- package/dist/components/ChartStory/index.d.ts +7 -0
- package/dist/components/ChartStory/index.d.ts.map +1 -0
- package/dist/components/HeatmapCells/index.d.ts +1 -1
- package/dist/components/HeatmapCells/index.d.ts.map +1 -1
- package/dist/{css-C-rsk7-l.js → css-BTZA9hea.js} +2 -2
- package/dist/{css-C-rsk7-l.js.map → css-BTZA9hea.js.map} +1 -1
- package/dist/heatmap.js +1 -1
- package/dist/hooks/useMarkMemory.d.ts +9 -0
- package/dist/hooks/useMarkMemory.d.ts.map +1 -0
- package/dist/hooks/usePieTween.d.ts.map +1 -1
- package/dist/hooks/useSteps.d.ts +4 -0
- package/dist/hooks/useSteps.d.ts.map +1 -0
- package/dist/hooks/useTween.d.ts +12 -0
- package/dist/hooks/useTween.d.ts.map +1 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +122 -117
- package/dist/index.js.map +1 -1
- package/dist/motion.utils-DFoqptDi.js +55 -0
- package/dist/motion.utils-DFoqptDi.js.map +1 -0
- 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/{tooltip.utils-D7xaBSUK.js → shared-C1pGJV4T.js} +3 -7
- package/dist/shared-C1pGJV4T.js.map +1 -0
- package/dist/sparkline.d.ts +1 -1
- package/dist/sparkline.d.ts.map +1 -1
- package/dist/sparkline.js +2 -2
- 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.d.ts +11 -0
- package/dist/story.d.ts.map +1 -0
- package/dist/story.js +7 -0
- package/dist/theme.js +3 -3
- package/dist/{theme.utils-CP1XtGIe.js → theme.utils-DF_e8LxQ.js} +132 -113
- package/dist/theme.utils-DF_e8LxQ.js.map +1 -0
- package/dist/tooltip.utils-CXD_NapA.js +9 -0
- package/dist/tooltip.utils-CXD_NapA.js.map +1 -0
- package/dist/types/category.d.ts +26 -0
- package/dist/types/category.d.ts.map +1 -1
- package/dist/types/heatmap.d.ts +3 -0
- package/dist/types/heatmap.d.ts.map +1 -1
- package/dist/types/heatmapParts.d.ts +2 -0
- package/dist/types/heatmapParts.d.ts.map +1 -1
- package/dist/types/motion.d.ts +31 -0
- package/dist/types/motion.d.ts.map +1 -0
- package/dist/types/pie.d.ts +3 -4
- package/dist/types/pie.d.ts.map +1 -1
- package/dist/types/polar.d.ts +3 -0
- package/dist/types/polar.d.ts.map +1 -1
- package/dist/types/scatter.d.ts +34 -0
- package/dist/types/scatter.d.ts.map +1 -1
- package/dist/types/sparkline.d.ts +3 -0
- package/dist/types/sparkline.d.ts.map +1 -1
- package/dist/types/story.d.ts +73 -0
- package/dist/types/story.d.ts.map +1 -0
- package/dist/{useChartTheme-B06p_jvu.js → useChartTheme-D0bQ3LQq.js} +2 -2
- package/dist/{useChartTheme-B06p_jvu.js.map → useChartTheme-D0bQ3LQq.js.map} +1 -1
- package/dist/useControllable-Crsr0byh.js +11 -0
- package/dist/useControllable-Crsr0byh.js.map +1 -0
- package/dist/useMarkMemory-CLNY6TtT.js +15 -0
- package/dist/useMarkMemory-CLNY6TtT.js.map +1 -0
- package/dist/useTween-B0G0CcvM.js +46 -0
- package/dist/useTween-B0G0CcvM.js.map +1 -0
- package/dist/utils/category.utils.d.ts +15 -1
- package/dist/utils/category.utils.d.ts.map +1 -1
- package/dist/utils/color.utils.d.ts +9 -0
- package/dist/utils/color.utils.d.ts.map +1 -1
- package/dist/utils/csv.utils.d.ts +6 -0
- package/dist/utils/csv.utils.d.ts.map +1 -0
- package/dist/utils/motion.utils.d.ts +25 -0
- package/dist/utils/motion.utils.d.ts.map +1 -1
- package/dist/utils/pieTween.utils.d.ts +1 -1
- package/dist/utils/pieTween.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/sparkline.utils.d.ts +15 -0
- package/dist/utils/sparkline.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/dist/{visibility.utils-nMI5a_Et.js → visibility.utils-wuc3ZS8D.js} +18 -25
- package/dist/visibility.utils-wuc3ZS8D.js.map +1 -0
- package/package.json +16 -5
- package/src/category.ts +5 -1
- package/src/charts/CategoryBarChart/index.tsx +310 -62
- package/src/charts/Heatmap/index.tsx +4 -0
- package/src/charts/PolarChart/index.tsx +98 -5
- package/src/charts/ScatterChart/index.tsx +164 -18
- package/src/charts/Sparkline/index.tsx +54 -7
- package/src/components/ChartFrame/index.tsx +180 -0
- package/src/components/ChartLegend/index.tsx +46 -0
- package/src/components/ChartStory/index.tsx +184 -0
- package/src/components/HeatmapCells/index.tsx +5 -2
- package/src/hooks/useMarkMemory.ts +29 -0
- package/src/hooks/usePieTween.ts +9 -44
- package/src/hooks/useSteps.ts +77 -0
- package/src/hooks/useTween.ts +112 -0
- package/src/index.ts +24 -1
- package/src/scatter.ts +4 -1
- package/src/sparkline.ts +1 -1
- package/src/standalone.tsx +68 -0
- package/src/story.ts +19 -0
- package/src/types/category.ts +27 -0
- package/src/types/heatmap.ts +3 -0
- package/src/types/heatmapParts.ts +2 -0
- package/src/types/motion.ts +35 -0
- package/src/types/pie.ts +3 -3
- package/src/types/polar.ts +3 -0
- package/src/types/scatter.ts +23 -0
- package/src/types/sparkline.ts +3 -0
- package/src/types/story.ts +103 -0
- package/src/utils/category.utils.ts +111 -2
- package/src/utils/color.utils.ts +48 -0
- package/src/utils/csv.utils.ts +28 -0
- package/src/utils/motion.utils.ts +124 -0
- package/src/utils/pieTween.utils.ts +1 -2
- package/src/utils/scatter.utils.ts +22 -5
- package/src/utils/sparkline.utils.ts +69 -0
- package/src/utils/theme.utils.ts +18 -15
- package/dist/CategoryBarChart-YEJ9VB8h.js +0 -453
- package/dist/CategoryBarChart-YEJ9VB8h.js.map +0 -1
- package/dist/Heatmap-C1XcTUg1.js.map +0 -1
- package/dist/PieLegend-BZsv9IbF.js.map +0 -1
- package/dist/PolarChart-BUEhn3CI.js +0 -334
- package/dist/PolarChart-BUEhn3CI.js.map +0 -1
- package/dist/Sparkline-DtNhxGVo.js +0 -67
- package/dist/Sparkline-DtNhxGVo.js.map +0 -1
- package/dist/motion.utils-C1eaZJdQ.js +0 -9
- package/dist/motion.utils-C1eaZJdQ.js.map +0 -1
- package/dist/theme.utils-CP1XtGIe.js.map +0 -1
- package/dist/tooltip.utils-D7xaBSUK.js.map +0 -1
- package/dist/visibility.utils-nMI5a_Et.js.map +0 -1
|
@@ -8,6 +8,12 @@ export interface ScatterSeriesInput {
|
|
|
8
8
|
data: readonly ScatterDatum[];
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/** A fixed extent for one axis. A missing end is fitted to the data. */
|
|
12
|
+
export interface ScatterDomain {
|
|
13
|
+
min?: number;
|
|
14
|
+
max?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
export interface PlacedScatterPoint {
|
|
12
18
|
series: string;
|
|
13
19
|
index: number;
|
|
@@ -18,6 +24,7 @@ export interface PlacedScatterPoint {
|
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
export interface ScatterFrame {
|
|
27
|
+
pad: ScatterPad;
|
|
21
28
|
points: PlacedScatterPoint[];
|
|
22
29
|
xTicks: number[];
|
|
23
30
|
yTicks: number[];
|
|
@@ -25,7 +32,14 @@ export interface ScatterFrame {
|
|
|
25
32
|
yOf: (value: number) => number;
|
|
26
33
|
}
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
export interface ScatterPad {
|
|
36
|
+
top: number;
|
|
37
|
+
right: number;
|
|
38
|
+
bottom: number;
|
|
39
|
+
left: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const SCATTER_PAD: ScatterPad = { top: 16, right: 16, bottom: 32, left: 40 };
|
|
29
43
|
|
|
30
44
|
function niceStep(span: number, count: number): number {
|
|
31
45
|
if (!(span > 0)) return 1;
|
|
@@ -53,6 +67,8 @@ export function scatterLayout(
|
|
|
53
67
|
series: readonly ScatterSeriesInput[],
|
|
54
68
|
width: number,
|
|
55
69
|
height: number,
|
|
70
|
+
domains: { x?: ScatterDomain; y?: ScatterDomain } = {},
|
|
71
|
+
PAD: ScatterPad = SCATTER_PAD,
|
|
56
72
|
): ScatterFrame {
|
|
57
73
|
const finite = series.flatMap((item) =>
|
|
58
74
|
item.data.filter(
|
|
@@ -61,10 +77,10 @@ export function scatterLayout(
|
|
|
61
77
|
);
|
|
62
78
|
const xs = finite.map((point) => point.x);
|
|
63
79
|
const ys = finite.map((point) => point.y);
|
|
64
|
-
const xMin = xs.length ? Math.min(...xs) : 0;
|
|
65
|
-
const xMax = xs.length ? Math.max(...xs) : 1;
|
|
66
|
-
const yMin = ys.length ? Math.min(...ys) : 0;
|
|
67
|
-
const yMax = ys.length ? Math.max(...ys) : 1;
|
|
80
|
+
const xMin = domains.x?.min ?? (xs.length ? Math.min(...xs) : 0);
|
|
81
|
+
const xMax = domains.x?.max ?? (xs.length ? Math.max(...xs) : 1);
|
|
82
|
+
const yMin = domains.y?.min ?? (ys.length ? Math.min(...ys) : 0);
|
|
83
|
+
const yMax = domains.y?.max ?? (ys.length ? Math.max(...ys) : 1);
|
|
68
84
|
const xSpan = xMax - xMin || 1;
|
|
69
85
|
const ySpan = yMax - yMin || 1;
|
|
70
86
|
const plotW = Math.max(0, width - PAD.left - PAD.right);
|
|
@@ -89,6 +105,7 @@ export function scatterLayout(
|
|
|
89
105
|
);
|
|
90
106
|
|
|
91
107
|
return {
|
|
108
|
+
pad: PAD,
|
|
92
109
|
points,
|
|
93
110
|
xTicks: ticks(xMin, xMax, 4),
|
|
94
111
|
yTicks: ticks(yMin, yMax, 4),
|
|
@@ -85,3 +85,72 @@ export function sparklineArea(
|
|
|
85
85
|
|
|
86
86
|
return `${line} L ${x(last).toFixed(2)} ${baseline.toFixed(2)} L ${x(first).toFixed(2)} ${baseline.toFixed(2)} Z`;
|
|
87
87
|
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* How far `next` scrolled from `previous`: the smallest k with
|
|
91
|
+
* `previous[k + i] === next[i]` over an overlap of at least two values.
|
|
92
|
+
* 0 when the values did not slide, so a sliding window can scroll instead of morph.
|
|
93
|
+
*/
|
|
94
|
+
export function shiftOffset(
|
|
95
|
+
previous: readonly (number | null)[],
|
|
96
|
+
next: readonly (number | null)[],
|
|
97
|
+
): number {
|
|
98
|
+
const limit = Math.min(previous.length, next.length) - 2;
|
|
99
|
+
|
|
100
|
+
for (let k = 1; k <= limit; k += 1) {
|
|
101
|
+
let same = true;
|
|
102
|
+
|
|
103
|
+
for (let i = 0; i + k < previous.length && i < next.length; i += 1) {
|
|
104
|
+
if (previous[i + k] !== next[i]) {
|
|
105
|
+
same = false;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (same) return k;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Line and area paths through `[position, value]` points sorted by position,
|
|
118
|
+
* where `count` positions span the width. A gap of more than one position
|
|
119
|
+
* (a null) breaks the line. Positions may be fractional while scrolling.
|
|
120
|
+
*/
|
|
121
|
+
export function sparklineShapes(
|
|
122
|
+
points: readonly (readonly [position: number, value: number, slot: number])[],
|
|
123
|
+
count: number,
|
|
124
|
+
width: number,
|
|
125
|
+
height: number,
|
|
126
|
+
pad = 1,
|
|
127
|
+
): { lines: string[]; area: string | null } {
|
|
128
|
+
if (points.length === 0) return { lines: [], area: null };
|
|
129
|
+
|
|
130
|
+
const values = points.map((point) => point[1]);
|
|
131
|
+
const min = Math.min(...values);
|
|
132
|
+
const max = Math.max(...values);
|
|
133
|
+
const span = max - min || 1;
|
|
134
|
+
const steps = Math.max(count - 1, 1);
|
|
135
|
+
const x = (position: number) => pad + (position / steps) * (width - pad * 2);
|
|
136
|
+
const y = (value: number) => pad + (1 - (value - min) / span) * (height - pad * 2);
|
|
137
|
+
const runs: Array<Array<readonly [number, number, number]>> = [];
|
|
138
|
+
|
|
139
|
+
points.forEach((point, index) => {
|
|
140
|
+
const before = points[index - 1];
|
|
141
|
+
|
|
142
|
+
if (!before || point[2] - before[2] !== 1) runs.push([]);
|
|
143
|
+
runs[runs.length - 1]!.push(point);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const lines = runs.map((run) =>
|
|
147
|
+
run
|
|
148
|
+
.map(([position, value], index) => `${index === 0 ? "M" : "L"} ${x(position).toFixed(2)} ${y(value).toFixed(2)}`)
|
|
149
|
+
.join(" "),
|
|
150
|
+
);
|
|
151
|
+
// Same outline as sparklineArea: the first run, closed under the last point.
|
|
152
|
+
const base = y(min).toFixed(2);
|
|
153
|
+
const area = `${lines[0]} L ${x(points[points.length - 1]![0]).toFixed(2)} ${base} L ${x(points[0]![0]).toFixed(2)} ${base} Z`;
|
|
154
|
+
|
|
155
|
+
return { lines, area };
|
|
156
|
+
}
|
package/src/utils/theme.utils.ts
CHANGED
|
@@ -5,17 +5,17 @@ import type {
|
|
|
5
5
|
ThemeInput,
|
|
6
6
|
} from "../types/theme.js";
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import type {
|
|
9
9
|
ColorType,
|
|
10
10
|
LineStyle,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
LineWidth,
|
|
12
|
+
DeepPartial,
|
|
13
|
+
ChartOptions,
|
|
14
|
+
PriceLineOptions,
|
|
15
|
+
LineSeriesPartialOptions,
|
|
16
|
+
AreaSeriesPartialOptions,
|
|
17
|
+
BaselineSeriesPartialOptions,
|
|
18
|
+
CandlestickSeriesPartialOptions,
|
|
19
19
|
} from "lightweight-charts";
|
|
20
20
|
|
|
21
21
|
import type { CSSProperties } from "react";
|
|
@@ -66,11 +66,14 @@ export function createTheme(
|
|
|
66
66
|
return deepMerge<Theme>(defaultTheme, ...partials);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
// lightweight-charts' LineStyle and ColorType values, written out so this module imports only
|
|
70
|
+
// types from it: the SVG charts (and the standalone script) then do not bundle the canvas engine.
|
|
71
|
+
const LINE_STYLES: Record<"solid" | "dotted" | "dashed", LineStyle> = {
|
|
72
|
+
solid: 0 as LineStyle.Solid,
|
|
73
|
+
dotted: 1 as LineStyle.Dotted,
|
|
74
|
+
dashed: 2 as LineStyle.Dashed,
|
|
75
|
+
};
|
|
76
|
+
const SOLID_BACKGROUND = "solid" as ColorType.Solid;
|
|
74
77
|
|
|
75
78
|
function substituteVars(
|
|
76
79
|
raw: string,
|
|
@@ -130,7 +133,7 @@ export function chartOptionsFromTheme(
|
|
|
130
133
|
|
|
131
134
|
return deepMerge({
|
|
132
135
|
layout: {
|
|
133
|
-
background: { type:
|
|
136
|
+
background: { type: SOLID_BACKGROUND, color: palette.background },
|
|
134
137
|
textColor: palette.text,
|
|
135
138
|
fontFamily: typography.axis.family,
|
|
136
139
|
fontSize: typography.axis.size,
|
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { n as e } from "./heatmap-CIBukkjS.js";
|
|
3
|
-
import { t } from "./dom.utils-CKMWLto-.js";
|
|
4
|
-
import { t as n } from "./useChartTheme-B06p_jvu.js";
|
|
5
|
-
import { useState as r } from "react";
|
|
6
|
-
import { jsx as i, jsxs as a } from "react/jsx-runtime";
|
|
7
|
-
//#region src/utils/category.utils.ts
|
|
8
|
-
var o = {
|
|
9
|
-
top: 16,
|
|
10
|
-
right: 12,
|
|
11
|
-
bottom: 28,
|
|
12
|
-
left: 36
|
|
13
|
-
}, s = {
|
|
14
|
-
top: 12,
|
|
15
|
-
right: 56,
|
|
16
|
-
bottom: 28,
|
|
17
|
-
left: 96
|
|
18
|
-
};
|
|
19
|
-
function c(e) {
|
|
20
|
-
return e.scale ?? "left";
|
|
21
|
-
}
|
|
22
|
-
function l(e, t, n, r, i, a) {
|
|
23
|
-
let o = t.filter((e) => c(e) === r);
|
|
24
|
-
if (o.length === 0) return null;
|
|
25
|
-
let s = 0, l = 0;
|
|
26
|
-
for (let t = 0; t < n; t += 1) {
|
|
27
|
-
let n = 0, r = 0;
|
|
28
|
-
for (let i of o) {
|
|
29
|
-
let a = i.data[t];
|
|
30
|
-
typeof a == "number" && Number.isFinite(a) && (e === "stack" ? a >= 0 ? n += a : r += a : (s = Math.min(s, a), l = Math.max(l, a)));
|
|
31
|
-
}
|
|
32
|
-
e === "stack" && (s = Math.min(s, r), l = Math.max(l, n));
|
|
33
|
-
}
|
|
34
|
-
for (let e of a ?? []) Number.isFinite(e) && (s = Math.min(s, e), l = Math.max(l, e));
|
|
35
|
-
let u = {
|
|
36
|
-
min: i?.min ?? s,
|
|
37
|
-
max: i?.max ?? l
|
|
38
|
-
};
|
|
39
|
-
return {
|
|
40
|
-
min: u.min,
|
|
41
|
-
max: u.max === u.min ? u.max + 1 : u.max
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function u(e, t) {
|
|
45
|
-
return e.flatMap((e) => {
|
|
46
|
-
let n = e.data[t];
|
|
47
|
-
return typeof n == "number" && Number.isFinite(n) ? [{
|
|
48
|
-
id: e.id,
|
|
49
|
-
value: n,
|
|
50
|
-
scale: c(e)
|
|
51
|
-
}] : [];
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function d(e, t, n, r) {
|
|
55
|
-
let { mode: i, series: a, categories: o, width: s, height: c } = e, l = Math.max(0, c - t.top - t.bottom), d = Math.max(0, s - t.left - t.right), f = (e) => {
|
|
56
|
-
let i = e === "right" && r ? r : n, a = i.max - i.min || 1;
|
|
57
|
-
return (e) => t.top + (i.max - e) / a * l;
|
|
58
|
-
}, p = d / o, m = [];
|
|
59
|
-
for (let e = 0; e < o; e += 1) {
|
|
60
|
-
let n = u(a, e);
|
|
61
|
-
if (n.length === 0) continue;
|
|
62
|
-
let r = p * .72, o = t.left + e * p + (p - r) / 2;
|
|
63
|
-
if (i === "group") {
|
|
64
|
-
let t = n.length > 1 ? 2 : 0, i = (r - t * (n.length - 1)) / n.length;
|
|
65
|
-
n.forEach((n, r) => {
|
|
66
|
-
let a = f(n.scale), s = Math.min(a(n.value), a(0));
|
|
67
|
-
m.push({
|
|
68
|
-
series: n.id,
|
|
69
|
-
category: e,
|
|
70
|
-
x: o + r * (i + t),
|
|
71
|
-
y: s,
|
|
72
|
-
width: i,
|
|
73
|
-
height: Math.abs(a(n.value) - a(0)),
|
|
74
|
-
value: n.value
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
if (i === "overlay") {
|
|
80
|
-
n.forEach((t) => {
|
|
81
|
-
let n = f(t.scale), i = Math.min(n(t.value), n(0));
|
|
82
|
-
m.push({
|
|
83
|
-
series: t.id,
|
|
84
|
-
category: e,
|
|
85
|
-
x: o,
|
|
86
|
-
y: i,
|
|
87
|
-
width: r,
|
|
88
|
-
height: Math.abs(n(t.value) - n(0)),
|
|
89
|
-
value: t.value
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
for (let t of ["left", "right"]) {
|
|
95
|
-
let i = 0, a = 0, s = f(t);
|
|
96
|
-
for (let c of n) {
|
|
97
|
-
if (c.scale !== t) continue;
|
|
98
|
-
let n = c.value >= 0 ? i : a, l = n + c.value;
|
|
99
|
-
c.value >= 0 ? i = l : a = l;
|
|
100
|
-
let u = Math.min(s(n), s(l));
|
|
101
|
-
m.push({
|
|
102
|
-
series: c.id,
|
|
103
|
-
category: e,
|
|
104
|
-
x: o,
|
|
105
|
-
y: u,
|
|
106
|
-
width: r,
|
|
107
|
-
height: Math.abs(s(l) - s(n)),
|
|
108
|
-
value: c.value
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return m;
|
|
114
|
-
}
|
|
115
|
-
function f(e, t, n, r) {
|
|
116
|
-
let { mode: i, series: a, categories: o, width: s, height: c } = e, l = Math.max(0, s - t.left - t.right), d = Math.max(0, c - t.top - t.bottom), f = (e) => {
|
|
117
|
-
let i = e === "right" && r ? r : n, a = i.max - i.min || 1;
|
|
118
|
-
return (e) => t.left + (e - i.min) / a * l;
|
|
119
|
-
}, p = d / o, m = [];
|
|
120
|
-
for (let e = 0; e < o; e += 1) {
|
|
121
|
-
let n = u(a, e);
|
|
122
|
-
if (n.length === 0) continue;
|
|
123
|
-
let r = p * .72, o = t.top + e * p + (p - r) / 2;
|
|
124
|
-
if (i === "group") {
|
|
125
|
-
let t = n.length > 1 ? 2 : 0, i = (r - t * (n.length - 1)) / n.length;
|
|
126
|
-
n.forEach((n, r) => {
|
|
127
|
-
let a = f(n.scale), s = Math.min(a(n.value), a(0));
|
|
128
|
-
m.push({
|
|
129
|
-
series: n.id,
|
|
130
|
-
category: e,
|
|
131
|
-
x: s,
|
|
132
|
-
y: o + r * (i + t),
|
|
133
|
-
width: Math.abs(a(n.value) - a(0)),
|
|
134
|
-
height: i,
|
|
135
|
-
value: n.value
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
if (i === "overlay") {
|
|
141
|
-
n.forEach((t) => {
|
|
142
|
-
let n = f(t.scale), i = Math.min(n(t.value), n(0));
|
|
143
|
-
m.push({
|
|
144
|
-
series: t.id,
|
|
145
|
-
category: e,
|
|
146
|
-
x: i,
|
|
147
|
-
y: o,
|
|
148
|
-
width: Math.abs(n(t.value) - n(0)),
|
|
149
|
-
height: r,
|
|
150
|
-
value: t.value
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
for (let t of ["left", "right"]) {
|
|
156
|
-
let i = 0, a = 0, s = f(t);
|
|
157
|
-
for (let c of n) {
|
|
158
|
-
if (c.scale !== t) continue;
|
|
159
|
-
let n = c.value >= 0 ? i : a, l = n + c.value;
|
|
160
|
-
c.value >= 0 ? i = l : a = l;
|
|
161
|
-
let u = Math.min(s(n), s(l));
|
|
162
|
-
m.push({
|
|
163
|
-
series: c.id,
|
|
164
|
-
category: e,
|
|
165
|
-
x: u,
|
|
166
|
-
y: o,
|
|
167
|
-
width: Math.abs(s(l) - s(n)),
|
|
168
|
-
height: r,
|
|
169
|
-
value: c.value
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return m;
|
|
175
|
-
}
|
|
176
|
-
function p(e, t, n, r, i, a, o, s) {
|
|
177
|
-
let c = s === "right" && a ? a : i, l = c.max - c.min || 1;
|
|
178
|
-
if (e === "horizontal") {
|
|
179
|
-
let e = Math.max(0, n - t.left - t.right), i = t.left + (o - c.min) / l * e;
|
|
180
|
-
return {
|
|
181
|
-
x1: i,
|
|
182
|
-
y1: t.top,
|
|
183
|
-
x2: i,
|
|
184
|
-
y2: r - t.bottom
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
let u = Math.max(0, r - t.top - t.bottom), d = t.top + (c.max - o) / l * u;
|
|
188
|
-
return {
|
|
189
|
-
x1: t.left,
|
|
190
|
-
y1: d,
|
|
191
|
-
x2: n - t.right,
|
|
192
|
-
y2: d
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
function m(e) {
|
|
196
|
-
let t = e.orientation ?? "vertical", n = e.pad ?? (t === "horizontal" ? s : o), r = (t) => (e.pins ?? []).flatMap((e) => (e.scale ?? "left") === t && Number.isFinite(e.value) ? [e.value] : []), i = l(e.mode, e.series, e.categories, "left", e.domain, r("left")) ?? {
|
|
197
|
-
min: 0,
|
|
198
|
-
max: 1
|
|
199
|
-
}, a = l(e.mode, e.series, e.categories, "right", e.rightDomain, r("right"));
|
|
200
|
-
return {
|
|
201
|
-
rects: e.categories <= 0 || e.series.length === 0 ? [] : t === "horizontal" ? f(e, n, i, a) : d(e, n, i, a),
|
|
202
|
-
orientation: t,
|
|
203
|
-
pad: n,
|
|
204
|
-
left: i,
|
|
205
|
-
right: a,
|
|
206
|
-
across: (r, o = "left") => p(t, n, e.width, e.height, i, a, r, o)
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
function h(e) {
|
|
210
|
-
return m(e).rects;
|
|
211
|
-
}
|
|
212
|
-
function g(e, t, n = 4) {
|
|
213
|
-
if (!(t > e) || n < 1) return [e];
|
|
214
|
-
let r = (t - e) / n;
|
|
215
|
-
return Array.from({ length: n + 1 }, (t, n) => Number((e + r * n).toPrecision(6)));
|
|
216
|
-
}
|
|
217
|
-
//#endregion
|
|
218
|
-
//#region src/charts/CategoryBarChart/index.tsx
|
|
219
|
-
var _ = 640, v = 320, y = [], b = [];
|
|
220
|
-
function x(e, t, n) {
|
|
221
|
-
return n ?? e[t % Math.max(1, e.length)] ?? "currentColor";
|
|
222
|
-
}
|
|
223
|
-
function S(e) {
|
|
224
|
-
return typeof e == "number" ? { value: Number.isFinite(e) ? e : void 0 } : e && typeof e.value == "number" && Number.isFinite(e.value) ? {
|
|
225
|
-
value: e.value,
|
|
226
|
-
color: e.color,
|
|
227
|
-
label: e.label
|
|
228
|
-
} : { value: void 0 };
|
|
229
|
-
}
|
|
230
|
-
function C(e, t, n) {
|
|
231
|
-
return x(t, n, e?.color);
|
|
232
|
-
}
|
|
233
|
-
function w({ categories: o, series: s, mode: c = "group", orientation: l = "vertical", domain: u, rightDomain: d, reference: f, references: p = y, bands: h = b, activeIndex: x, valueLabel: w, width: T = _, height: E = v, className: D, ariaLabel: O = "Bar chart", formatValue: k, formatTick: A, renderTooltip: j, onSelect: M, theme: N, unstyled: P }) {
|
|
234
|
-
let F = n({
|
|
235
|
-
theme: N,
|
|
236
|
-
unstyled: P
|
|
237
|
-
}), I = F?.palette.categorical ?? [], L = F?.palette.text, R = F?.palette.grid, z = s.some((e) => e.scale === "right"), B = l === "horizontal" ? {
|
|
238
|
-
top: 12,
|
|
239
|
-
right: z ? 48 : 64,
|
|
240
|
-
bottom: w ? 36 : 28,
|
|
241
|
-
left: 108
|
|
242
|
-
} : {
|
|
243
|
-
top: 16,
|
|
244
|
-
right: z ? 48 : 12,
|
|
245
|
-
bottom: w ? 40 : 28,
|
|
246
|
-
left: 44
|
|
247
|
-
}, V = f ? [f, ...p] : p, H = m({
|
|
248
|
-
mode: c,
|
|
249
|
-
orientation: l,
|
|
250
|
-
domain: u,
|
|
251
|
-
rightDomain: d,
|
|
252
|
-
pad: B,
|
|
253
|
-
width: T,
|
|
254
|
-
height: E,
|
|
255
|
-
categories: o.length,
|
|
256
|
-
pins: [...V.map((e) => ({
|
|
257
|
-
value: e.value,
|
|
258
|
-
scale: e.scale
|
|
259
|
-
})), ...h.flatMap((e) => [{
|
|
260
|
-
value: e.from,
|
|
261
|
-
scale: e.scale
|
|
262
|
-
}, {
|
|
263
|
-
value: e.to,
|
|
264
|
-
scale: e.scale
|
|
265
|
-
}])],
|
|
266
|
-
series: s.map((e) => ({
|
|
267
|
-
id: e.id,
|
|
268
|
-
scale: e.scale,
|
|
269
|
-
data: e.data.map((e) => S(e).value ?? NaN)
|
|
270
|
-
}))
|
|
271
|
-
}), [U, W] = r(null), G = U ?? x ?? 0, K = o[G] ?? o[0], q = s.flatMap((e, t) => {
|
|
272
|
-
let n = K === void 0 ? void 0 : S(e.data[G]);
|
|
273
|
-
return n?.value === void 0 ? [] : [{
|
|
274
|
-
label: e.name,
|
|
275
|
-
value: k?.(e.id, n.value) ?? String(n.value),
|
|
276
|
-
color: n.color ?? C(e, I, t)
|
|
277
|
-
}];
|
|
278
|
-
}), J = (e) => A?.(e) ?? String(e), Y = (e) => {
|
|
279
|
-
W(e);
|
|
280
|
-
let t = o[e];
|
|
281
|
-
t !== void 0 && M?.(t, e);
|
|
282
|
-
}, X = (e) => {
|
|
283
|
-
let t = l === "horizontal" ? "ArrowDown" : "ArrowRight", n = l === "horizontal" ? "ArrowUp" : "ArrowLeft";
|
|
284
|
-
if (e.key !== t && e.key !== n) return;
|
|
285
|
-
e.preventDefault();
|
|
286
|
-
let r = e.key === t ? G + 1 : G - 1;
|
|
287
|
-
Y(Math.max(0, Math.min(o.length - 1, r)));
|
|
288
|
-
}, Z = (e, t) => g(e.min, e.max).map((e) => ({
|
|
289
|
-
value: e,
|
|
290
|
-
at: H.across(e, t)
|
|
291
|
-
}));
|
|
292
|
-
return /* @__PURE__ */ a("div", {
|
|
293
|
-
className: t(D),
|
|
294
|
-
"data-mode": c,
|
|
295
|
-
"data-orientation": l,
|
|
296
|
-
style: { position: "relative" },
|
|
297
|
-
children: [/* @__PURE__ */ a("svg", {
|
|
298
|
-
role: "img",
|
|
299
|
-
"aria-label": O,
|
|
300
|
-
tabIndex: 0,
|
|
301
|
-
viewBox: `0 0 ${T} ${E}`,
|
|
302
|
-
style: e,
|
|
303
|
-
onKeyDown: X,
|
|
304
|
-
onPointerLeave: () => W(null),
|
|
305
|
-
children: [
|
|
306
|
-
l === "horizontal" ? /* @__PURE__ */ i("line", {
|
|
307
|
-
"data-part": "axis",
|
|
308
|
-
x1: B.left,
|
|
309
|
-
y1: B.top,
|
|
310
|
-
x2: B.left,
|
|
311
|
-
y2: E - B.bottom,
|
|
312
|
-
stroke: R
|
|
313
|
-
}) : /* @__PURE__ */ i("line", {
|
|
314
|
-
"data-part": "axis",
|
|
315
|
-
x1: B.left,
|
|
316
|
-
y1: E - B.bottom,
|
|
317
|
-
x2: T - B.right,
|
|
318
|
-
y2: E - B.bottom,
|
|
319
|
-
stroke: R
|
|
320
|
-
}),
|
|
321
|
-
o.map((e, t) => {
|
|
322
|
-
let n = l === "horizontal" ? (E - B.top - B.bottom) / o.length : (T - B.left - B.right) / o.length, r = l === "horizontal" ? B.top + (t + .5) * n : B.left + (t + .5) * n;
|
|
323
|
-
return l === "horizontal" ? /* @__PURE__ */ i("text", {
|
|
324
|
-
"data-part": "tick",
|
|
325
|
-
x: B.left - 8,
|
|
326
|
-
y: r,
|
|
327
|
-
textAnchor: "end",
|
|
328
|
-
dominantBaseline: "middle",
|
|
329
|
-
fill: L,
|
|
330
|
-
fontSize: 11,
|
|
331
|
-
children: e
|
|
332
|
-
}, e) : /* @__PURE__ */ i("text", {
|
|
333
|
-
"data-part": "tick",
|
|
334
|
-
x: r,
|
|
335
|
-
y: E - B.bottom + 14,
|
|
336
|
-
textAnchor: "middle",
|
|
337
|
-
fill: L,
|
|
338
|
-
fontSize: 11,
|
|
339
|
-
children: e
|
|
340
|
-
}, e);
|
|
341
|
-
}),
|
|
342
|
-
Z(H.left, "left").map((e) => l === "horizontal" ? /* @__PURE__ */ i("text", {
|
|
343
|
-
"data-part": "value-tick",
|
|
344
|
-
x: e.at.x1,
|
|
345
|
-
y: E - B.bottom + 14,
|
|
346
|
-
textAnchor: "middle",
|
|
347
|
-
fill: L,
|
|
348
|
-
fontSize: 11,
|
|
349
|
-
children: J(e.value)
|
|
350
|
-
}, `l-${e.value}`) : /* @__PURE__ */ i("text", {
|
|
351
|
-
"data-part": "value-tick",
|
|
352
|
-
x: B.left - 6,
|
|
353
|
-
y: e.at.y1,
|
|
354
|
-
textAnchor: "end",
|
|
355
|
-
dominantBaseline: "middle",
|
|
356
|
-
fill: L,
|
|
357
|
-
fontSize: 11,
|
|
358
|
-
children: J(e.value)
|
|
359
|
-
}, `l-${e.value}`)),
|
|
360
|
-
H.right && Z(H.right, "right").map((e) => /* @__PURE__ */ i("text", {
|
|
361
|
-
"data-part": "value-tick",
|
|
362
|
-
"data-scale": "right",
|
|
363
|
-
x: T - B.right + 6,
|
|
364
|
-
y: e.at.y1,
|
|
365
|
-
dominantBaseline: "middle",
|
|
366
|
-
fill: L,
|
|
367
|
-
fontSize: 11,
|
|
368
|
-
children: J(e.value)
|
|
369
|
-
}, `r-${e.value}`)),
|
|
370
|
-
w && /* @__PURE__ */ i("text", {
|
|
371
|
-
"data-part": "axis-label",
|
|
372
|
-
x: l === "horizontal" ? (B.left + T - B.right) / 2 : B.left,
|
|
373
|
-
y: E - 4,
|
|
374
|
-
textAnchor: l === "horizontal" ? "middle" : "start",
|
|
375
|
-
fill: L,
|
|
376
|
-
fontSize: 11,
|
|
377
|
-
children: w
|
|
378
|
-
}),
|
|
379
|
-
h.map((e, t) => {
|
|
380
|
-
let n = H.across(e.from, e.scale), r = H.across(e.to, e.scale), a = l === "horizontal", o = a ? Math.min(n.x1, r.x1) : B.left, s = a ? B.top : Math.min(n.y1, r.y1), c = a ? Math.abs(n.x1 - r.x1) : T - B.left - B.right, u = a ? E - B.top - B.bottom : Math.abs(n.y1 - r.y1);
|
|
381
|
-
return /* @__PURE__ */ i("rect", {
|
|
382
|
-
"data-part": "band",
|
|
383
|
-
x: o,
|
|
384
|
-
y: s,
|
|
385
|
-
width: c,
|
|
386
|
-
height: u,
|
|
387
|
-
fill: e.color ?? R
|
|
388
|
-
}, `band-${t}`);
|
|
389
|
-
}),
|
|
390
|
-
V.map((e, t) => {
|
|
391
|
-
let n = H.across(e.value, e.scale);
|
|
392
|
-
return /* @__PURE__ */ a("g", { children: [/* @__PURE__ */ i("line", {
|
|
393
|
-
"data-part": "reference",
|
|
394
|
-
...n,
|
|
395
|
-
stroke: e.color ?? R,
|
|
396
|
-
strokeDasharray: "4 3"
|
|
397
|
-
}), e.label && /* @__PURE__ */ i("text", {
|
|
398
|
-
"data-part": "reference-label",
|
|
399
|
-
x: n.x1 + 4,
|
|
400
|
-
y: B.top + 10 + t * 12,
|
|
401
|
-
fill: e.color ?? L,
|
|
402
|
-
fontSize: 10,
|
|
403
|
-
children: e.label
|
|
404
|
-
})] }, `ref-${e.label ?? e.value}-${t}`);
|
|
405
|
-
}),
|
|
406
|
-
H.rects.map((e) => {
|
|
407
|
-
let t = s.find((t) => t.id === e.series), n = s.findIndex((t) => t.id === e.series), r = S(t?.data[e.category]);
|
|
408
|
-
return /* @__PURE__ */ a("g", { children: [/* @__PURE__ */ i("rect", {
|
|
409
|
-
"data-part": "bar",
|
|
410
|
-
"data-series": e.series,
|
|
411
|
-
"data-category": e.category,
|
|
412
|
-
"data-active": e.category === G ? "" : void 0,
|
|
413
|
-
x: e.x,
|
|
414
|
-
y: e.y,
|
|
415
|
-
width: e.width,
|
|
416
|
-
height: Math.max(e.height, e.value === 0 ? 0 : 1),
|
|
417
|
-
fill: r?.color ?? C(t, I, n),
|
|
418
|
-
opacity: c === "overlay" ? .72 : 1,
|
|
419
|
-
onPointerEnter: () => W(e.category),
|
|
420
|
-
onClick: () => Y(e.category)
|
|
421
|
-
}), r?.label && /* @__PURE__ */ i("text", {
|
|
422
|
-
"data-part": "bar-label",
|
|
423
|
-
"data-series": e.series,
|
|
424
|
-
x: l === "horizontal" ? e.x + e.width + 4 : e.x + e.width / 2,
|
|
425
|
-
y: l === "horizontal" ? e.y + e.height / 2 : e.y - 4,
|
|
426
|
-
textAnchor: l === "horizontal" ? "start" : "middle",
|
|
427
|
-
dominantBaseline: l === "horizontal" ? "middle" : "auto",
|
|
428
|
-
fill: L,
|
|
429
|
-
fontSize: 10,
|
|
430
|
-
children: r.label
|
|
431
|
-
})] }, `${e.series}:${e.category}`);
|
|
432
|
-
})
|
|
433
|
-
]
|
|
434
|
-
}), K !== void 0 && (j?.(K, q) ?? /* @__PURE__ */ a("div", {
|
|
435
|
-
"data-part": "tooltip",
|
|
436
|
-
children: [/* @__PURE__ */ i("div", {
|
|
437
|
-
"data-part": "tooltip-time",
|
|
438
|
-
children: K
|
|
439
|
-
}), q.map((e) => /* @__PURE__ */ a("div", {
|
|
440
|
-
"data-part": "tooltip-row",
|
|
441
|
-
children: [
|
|
442
|
-
e.label,
|
|
443
|
-
" ",
|
|
444
|
-
e.value
|
|
445
|
-
]
|
|
446
|
-
}, e.label))]
|
|
447
|
-
}))]
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
//#endregion
|
|
451
|
-
export { h as n, w as t };
|
|
452
|
-
|
|
453
|
-
//# sourceMappingURL=CategoryBarChart-YEJ9VB8h.js.map
|