minerva-design 1.1.0 → 1.2.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 +8 -0
- package/dist/charts/canvas.d.cts +7 -0
- package/dist/charts/canvas.d.ts +7 -0
- package/dist/charts/core.cjs +1 -1
- package/dist/charts/core.d.cts +5 -1
- package/dist/charts/core.d.ts +5 -1
- package/dist/charts/core.js +4 -1
- package/dist/charts/engine/canvas.cjs +2 -0
- package/dist/charts/engine/canvas.cjs.map +1 -0
- package/dist/charts/engine/canvas.d.cts +85 -0
- package/dist/charts/engine/canvas.d.ts +85 -0
- package/dist/charts/engine/canvas.js +165 -0
- package/dist/charts/engine/canvas.js.map +1 -0
- package/dist/charts/engine/chart.cjs +2 -2
- package/dist/charts/engine/chart.cjs.map +1 -1
- package/dist/charts/engine/chart.js +382 -440
- package/dist/charts/engine/chart.js.map +1 -1
- package/dist/charts/engine/color.cjs +1 -1
- package/dist/charts/engine/color.cjs.map +1 -1
- package/dist/charts/engine/color.d.cts +10 -0
- package/dist/charts/engine/color.d.ts +10 -0
- package/dist/charts/engine/color.js +75 -3
- package/dist/charts/engine/color.js.map +1 -1
- package/dist/charts/engine/controller.cjs +3 -0
- package/dist/charts/engine/controller.cjs.map +1 -0
- package/dist/charts/engine/controller.d.cts +182 -0
- package/dist/charts/engine/controller.d.ts +182 -0
- package/dist/charts/engine/controller.js +528 -0
- package/dist/charts/engine/controller.js.map +1 -0
- package/dist/charts/engine/model.cjs +1 -1
- package/dist/charts/engine/model.cjs.map +1 -1
- package/dist/charts/engine/model.d.cts +2 -2
- package/dist/charts/engine/model.d.ts +2 -2
- package/dist/charts/engine/model.js +72 -72
- package/dist/charts/engine/model.js.map +1 -1
- package/dist/charts/engine/overlay.cjs +1 -1
- package/dist/charts/engine/overlay.cjs.map +1 -1
- package/dist/charts/engine/overlay.d.cts +17 -1
- package/dist/charts/engine/overlay.d.ts +17 -1
- package/dist/charts/engine/overlay.js +63 -49
- package/dist/charts/engine/overlay.js.map +1 -1
- package/dist/charts/engine/presets.cjs +3 -0
- package/dist/charts/engine/presets.cjs.map +1 -0
- package/dist/charts/engine/presets.d.cts +103 -0
- package/dist/charts/engine/presets.d.ts +103 -0
- package/dist/charts/engine/presets.js +153 -0
- package/dist/charts/engine/presets.js.map +1 -0
- package/dist/charts/engine/renderers/canvas2d.cjs +1 -1
- package/dist/charts/engine/renderers/canvas2d.cjs.map +1 -1
- package/dist/charts/engine/renderers/canvas2d.d.cts +17 -1
- package/dist/charts/engine/renderers/canvas2d.d.ts +17 -1
- package/dist/charts/engine/renderers/canvas2d.js +88 -51
- package/dist/charts/engine/renderers/canvas2d.js.map +1 -1
- package/dist/charts/engine/scene.cjs +2 -0
- package/dist/charts/engine/scene.cjs.map +1 -0
- package/dist/charts/engine/scene.d.cts +89 -0
- package/dist/charts/engine/scene.d.ts +89 -0
- package/dist/charts/engine/scene.js +241 -0
- package/dist/charts/engine/scene.js.map +1 -0
- package/dist/charts/engine/theme.cjs +1 -1
- package/dist/charts/engine/theme.cjs.map +1 -1
- package/dist/charts/engine/theme.d.cts +25 -1
- package/dist/charts/engine/theme.d.ts +25 -1
- package/dist/charts/engine/theme.js +42 -26
- package/dist/charts/engine/theme.js.map +1 -1
- package/dist/charts/engine/types.d.cts +69 -2
- package/dist/charts/engine/types.d.ts +69 -2
- package/dist/charts/index.cjs +1 -1
- package/dist/charts/index.d.cts +1 -1
- package/dist/charts/index.d.ts +1 -1
- package/dist/charts/index.js +5 -2
- package/dist/charts/react/Chart.cjs +1 -1
- package/dist/charts/react/Chart.cjs.map +1 -1
- package/dist/charts/react/Chart.d.cts +11 -4
- package/dist/charts/react/Chart.d.ts +11 -4
- package/dist/charts/react/Chart.js +81 -39
- package/dist/charts/react/Chart.js.map +1 -1
- package/dist/charts/react/charts.cjs +1 -1
- package/dist/charts/react/charts.cjs.map +1 -1
- package/dist/charts/react/charts.d.cts +1 -1
- package/dist/charts/react/charts.d.ts +1 -1
- package/dist/charts/react/charts.js +99 -145
- package/dist/charts/react/charts.js.map +1 -1
- package/dist/charts/react/types.d.cts +29 -61
- package/dist/charts/react/types.d.ts +29 -61
- package/dist/native/charts/src/canvas.cjs +1 -0
- package/dist/native/charts/src/canvas.js +6 -0
- package/dist/native/charts/src/engine/axis.cjs +2 -0
- package/dist/native/charts/src/engine/axis.cjs.map +1 -0
- package/dist/native/charts/src/engine/axis.js +38 -0
- package/dist/native/charts/src/engine/axis.js.map +1 -0
- package/dist/native/charts/src/engine/canvas.cjs +1 -0
- package/dist/native/charts/src/engine/canvas.js +1 -0
- package/dist/native/charts/src/engine/color.cjs +2 -0
- package/dist/native/charts/src/engine/color.cjs.map +1 -0
- package/dist/native/charts/src/engine/color.js +130 -0
- package/dist/native/charts/src/engine/color.js.map +1 -0
- package/dist/native/charts/src/engine/controller.cjs +3 -0
- package/dist/native/charts/src/engine/controller.cjs.map +1 -0
- package/dist/native/charts/src/engine/controller.js +528 -0
- package/dist/native/charts/src/engine/controller.js.map +1 -0
- package/dist/native/charts/src/engine/data.cjs +2 -0
- package/dist/native/charts/src/engine/data.cjs.map +1 -0
- package/dist/native/charts/src/engine/data.js +104 -0
- package/dist/native/charts/src/engine/data.js.map +1 -0
- package/dist/native/charts/src/engine/decimate.cjs +2 -0
- package/dist/native/charts/src/engine/decimate.cjs.map +1 -0
- package/dist/native/charts/src/engine/decimate.js +28 -0
- package/dist/native/charts/src/engine/decimate.js.map +1 -0
- package/dist/native/charts/src/engine/format.cjs +2 -0
- package/dist/native/charts/src/engine/format.cjs.map +1 -0
- package/dist/native/charts/src/engine/format.js +34 -0
- package/dist/native/charts/src/engine/format.js.map +1 -0
- package/dist/native/charts/src/engine/layout.cjs +2 -0
- package/dist/native/charts/src/engine/layout.cjs.map +1 -0
- package/dist/native/charts/src/engine/layout.js +26 -0
- package/dist/native/charts/src/engine/layout.js.map +1 -0
- package/dist/native/charts/src/engine/model.cjs +2 -0
- package/dist/native/charts/src/engine/model.cjs.map +1 -0
- package/dist/native/charts/src/engine/model.js +175 -0
- package/dist/native/charts/src/engine/model.js.map +1 -0
- package/dist/native/charts/src/engine/overlay.cjs +2 -0
- package/dist/native/charts/src/engine/overlay.cjs.map +1 -0
- package/dist/native/charts/src/engine/overlay.js +49 -0
- package/dist/native/charts/src/engine/overlay.js.map +1 -0
- package/dist/native/charts/src/engine/presets.cjs +3 -0
- package/dist/native/charts/src/engine/presets.cjs.map +1 -0
- package/dist/native/charts/src/engine/presets.js +147 -0
- package/dist/native/charts/src/engine/presets.js.map +1 -0
- package/dist/native/charts/src/engine/scale.cjs +2 -0
- package/dist/native/charts/src/engine/scale.cjs.map +1 -0
- package/dist/native/charts/src/engine/scale.js +37 -0
- package/dist/native/charts/src/engine/scale.js.map +1 -0
- package/dist/native/charts/src/engine/scene.cjs +2 -0
- package/dist/native/charts/src/engine/scene.cjs.map +1 -0
- package/dist/native/charts/src/engine/scene.js +241 -0
- package/dist/native/charts/src/engine/scene.js.map +1 -0
- package/dist/native/charts/src/engine/spatial.cjs +2 -0
- package/dist/native/charts/src/engine/spatial.cjs.map +1 -0
- package/dist/native/charts/src/engine/spatial.js +53 -0
- package/dist/native/charts/src/engine/spatial.js.map +1 -0
- package/dist/native/charts/src/engine/theme.cjs +2 -0
- package/dist/native/charts/src/engine/theme.cjs.map +1 -0
- package/dist/native/charts/src/engine/theme.js +62 -0
- package/dist/native/charts/src/engine/theme.js.map +1 -0
- package/dist/native/charts/src/engine/time.cjs +2 -0
- package/dist/native/charts/src/engine/time.cjs.map +1 -0
- package/dist/native/charts/src/engine/time.js +189 -0
- package/dist/native/charts/src/engine/time.js.map +1 -0
- package/dist/native/charts/src/engine/viewport.cjs +2 -0
- package/dist/native/charts/src/engine/viewport.cjs.map +1 -0
- package/dist/native/charts/src/engine/viewport.js +12 -0
- package/dist/native/charts/src/engine/viewport.js.map +1 -0
- package/dist/native/components/Chart/ChartBase.cjs +2 -0
- package/dist/native/components/Chart/ChartBase.cjs.map +1 -0
- package/dist/native/components/Chart/ChartBase.d.cts +29 -0
- package/dist/native/components/Chart/ChartBase.d.ts +29 -0
- package/dist/native/components/Chart/ChartBase.js +287 -0
- package/dist/native/components/Chart/ChartBase.js.map +1 -0
- package/dist/native/components/Chart/charts.cjs +2 -0
- package/dist/native/components/Chart/charts.cjs.map +1 -0
- package/dist/native/components/Chart/charts.d.cts +19 -0
- package/dist/native/components/Chart/charts.d.ts +19 -0
- package/dist/native/components/Chart/charts.js +173 -0
- package/dist/native/components/Chart/charts.js.map +1 -0
- package/dist/native/components/Chart/index.cjs +1 -0
- package/dist/native/components/Chart/index.d.cts +2 -0
- package/dist/native/components/Chart/index.d.ts +2 -0
- package/dist/native/components/Chart/index.js +2 -0
- package/dist/native/components/Chart/measure.cjs +2 -0
- package/dist/native/components/Chart/measure.cjs.map +1 -0
- package/dist/native/components/Chart/measure.d.cts +5 -0
- package/dist/native/components/Chart/measure.d.ts +5 -0
- package/dist/native/components/Chart/measure.js +11 -0
- package/dist/native/components/Chart/measure.js.map +1 -0
- package/dist/native/components/Chart/scene.cjs +2 -0
- package/dist/native/components/Chart/scene.cjs.map +1 -0
- package/dist/native/components/Chart/scene.d.cts +41 -0
- package/dist/native/components/Chart/scene.d.ts +41 -0
- package/dist/native/components/Chart/scene.js +419 -0
- package/dist/native/components/Chart/scene.js.map +1 -0
- package/dist/native/components/Chart/theme.cjs +2 -0
- package/dist/native/components/Chart/theme.cjs.map +1 -0
- package/dist/native/components/Chart/theme.d.cts +10 -0
- package/dist/native/components/Chart/theme.d.ts +10 -0
- package/dist/native/components/Chart/theme.js +10 -0
- package/dist/native/components/Chart/theme.js.map +1 -0
- package/dist/native/components/Chart/types.d.cts +129 -0
- package/dist/native/components/Chart/types.d.ts +129 -0
- package/dist/native/index.cjs +1 -1
- package/dist/native/index.d.cts +1 -0
- package/dist/native/index.d.ts +1 -0
- package/dist/native/index.js +6 -4
- package/dist/native/manifest.d.cts +7 -0
- package/dist/native/manifest.d.ts +7 -0
- package/dist/native/source/components/Chart/ChartBase.tsx +545 -0
- package/dist/native/source/components/Chart/charts.tsx +291 -0
- package/dist/native/source/components/Chart/index.ts +8 -0
- package/dist/native/source/components/Chart/measure.ts +50 -0
- package/dist/native/source/components/Chart/scene.tsx +987 -0
- package/dist/native/source/components/Chart/theme.ts +16 -0
- package/dist/native/source/components/Chart/types.ts +194 -0
- package/dist/native/source/index.ts +1 -0
- package/dist/native/source/manifest.ts +14 -0
- package/dist/taro/charts.d.ts +144 -0
- package/dist/taro/index.d.ts +1 -0
- package/dist/taro/index.js +3064 -618
- package/dist/uni/BarChart.vue +75 -0
- package/dist/uni/BarChart.vue.d.ts +111 -0
- package/dist/uni/Chart.vue +68 -0
- package/dist/uni/Chart.vue.d.ts +100 -0
- package/dist/uni/LineChart.vue +75 -0
- package/dist/uni/LineChart.vue.d.ts +111 -0
- package/dist/uni/ProgressIndicator.vue.d.ts +1 -1
- package/dist/uni/QuadrantChart.vue +184 -0
- package/dist/uni/QuadrantChart.vue.d.ts +173 -0
- package/dist/uni/ScatterChart.vue +69 -0
- package/dist/uni/ScatterChart.vue.d.ts +100 -0
- package/dist/uni/chart-canvas.d.ts +68 -0
- package/dist/uni/chart-canvas.js +363 -0
- package/dist/uni/chart-types.d.ts +135 -0
- package/dist/uni/chart-types.js +84 -0
- package/dist/uni/charts-canvas.d.ts +1 -0
- package/dist/uni/charts-canvas.js +8 -0
- package/dist/uni/index.d.ts +6 -0
- package/dist/uni/index.js +6 -0
- package/dist/weapp/bar-chart/index.js +1 -0
- package/dist/weapp/bar-chart/index.json +1 -0
- package/dist/weapp/bar-chart/index.wxml +1 -0
- package/dist/weapp/bar-chart/index.wxss +1 -0
- package/dist/weapp/chart/index.js +1 -0
- package/dist/weapp/chart/index.json +1 -0
- package/dist/weapp/chart/index.wxml +1 -0
- package/dist/weapp/chart/index.wxss +1 -0
- package/dist/weapp/controls.js +4019 -266
- package/dist/weapp/line-chart/index.js +1 -0
- package/dist/weapp/line-chart/index.json +1 -0
- package/dist/weapp/line-chart/index.wxml +1 -0
- package/dist/weapp/line-chart/index.wxss +1 -0
- package/dist/weapp/quadrant-chart/index.js +1 -0
- package/dist/weapp/quadrant-chart/index.json +1 -0
- package/dist/weapp/quadrant-chart/index.wxml +1 -0
- package/dist/weapp/quadrant-chart/index.wxss +1 -0
- package/dist/weapp/scatter-chart/index.js +1 -0
- package/dist/weapp/scatter-chart/index.json +1 -0
- package/dist/weapp/scatter-chart/index.wxml +1 -0
- package/dist/weapp/scatter-chart/index.wxss +1 -0
- package/dist/weapp/types.d.ts +295 -0
- package/package.json +21 -1
|
@@ -25,7 +25,16 @@ export interface ResolvedLine {
|
|
|
25
25
|
dash: number[];
|
|
26
26
|
label?: string;
|
|
27
27
|
}
|
|
28
|
-
export
|
|
28
|
+
export interface ResolvedText {
|
|
29
|
+
type: "text";
|
|
30
|
+
x?: number;
|
|
31
|
+
y?: number;
|
|
32
|
+
text: string;
|
|
33
|
+
anchor: "center" | "top" | "bottom" | "left" | "right";
|
|
34
|
+
color: Rgba;
|
|
35
|
+
weight: number;
|
|
36
|
+
}
|
|
37
|
+
export type ResolvedAnnotation = ResolvedRect | ResolvedLine | ResolvedText;
|
|
29
38
|
export interface PointLabel {
|
|
30
39
|
x: number;
|
|
31
40
|
y: number;
|
|
@@ -34,6 +43,8 @@ export interface PointLabel {
|
|
|
34
43
|
text: string;
|
|
35
44
|
}
|
|
36
45
|
export declare const font: (theme: ChartTheme, size?: number, weight?: number) => string;
|
|
46
|
+
/** Box of a text annotation, kept inside the plot */
|
|
47
|
+
export declare const textBox: (a: ResolvedText, s: Scales, width: number, height: number) => Rect;
|
|
37
48
|
export interface BackgroundInput {
|
|
38
49
|
width: number;
|
|
39
50
|
height: number;
|
|
@@ -58,5 +69,10 @@ export interface ForegroundInput {
|
|
|
58
69
|
theme: ChartTheme;
|
|
59
70
|
annotations: readonly ResolvedAnnotation[];
|
|
60
71
|
pointLabels: readonly PointLabel[];
|
|
72
|
+
/**
|
|
73
|
+
* Clears the canvas first (off when the layers share one canvas)
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
76
|
+
clear?: boolean;
|
|
61
77
|
}
|
|
62
78
|
export declare const drawForeground: (ctx: CanvasRenderingContext2D, input: ForegroundInput) => void;
|
|
@@ -25,7 +25,16 @@ export interface ResolvedLine {
|
|
|
25
25
|
dash: number[];
|
|
26
26
|
label?: string;
|
|
27
27
|
}
|
|
28
|
-
export
|
|
28
|
+
export interface ResolvedText {
|
|
29
|
+
type: "text";
|
|
30
|
+
x?: number;
|
|
31
|
+
y?: number;
|
|
32
|
+
text: string;
|
|
33
|
+
anchor: "center" | "top" | "bottom" | "left" | "right";
|
|
34
|
+
color: Rgba;
|
|
35
|
+
weight: number;
|
|
36
|
+
}
|
|
37
|
+
export type ResolvedAnnotation = ResolvedRect | ResolvedLine | ResolvedText;
|
|
29
38
|
export interface PointLabel {
|
|
30
39
|
x: number;
|
|
31
40
|
y: number;
|
|
@@ -34,6 +43,8 @@ export interface PointLabel {
|
|
|
34
43
|
text: string;
|
|
35
44
|
}
|
|
36
45
|
export declare const font: (theme: ChartTheme, size?: number, weight?: number) => string;
|
|
46
|
+
/** Box of a text annotation, kept inside the plot */
|
|
47
|
+
export declare const textBox: (a: ResolvedText, s: Scales, width: number, height: number) => Rect;
|
|
37
48
|
export interface BackgroundInput {
|
|
38
49
|
width: number;
|
|
39
50
|
height: number;
|
|
@@ -58,5 +69,10 @@ export interface ForegroundInput {
|
|
|
58
69
|
theme: ChartTheme;
|
|
59
70
|
annotations: readonly ResolvedAnnotation[];
|
|
60
71
|
pointLabels: readonly PointLabel[];
|
|
72
|
+
/**
|
|
73
|
+
* Clears the canvas first (off when the layers share one canvas)
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
76
|
+
clear?: boolean;
|
|
61
77
|
}
|
|
62
78
|
export declare const drawForeground: (ctx: CanvasRenderingContext2D, input: ForegroundInput) => void;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { toCss as e } from "./color.js";
|
|
2
2
|
//#region src/engine/overlay.ts
|
|
3
|
-
var t = (e, t = e.fontSize, n = 400) => `${n} ${t}px ${e.fontFamily}`, n = (e) => Math.round(e) + .5, r = (e, t) => {
|
|
3
|
+
var t = (e, t = e.fontSize, n = 400) => `${n} ${t}px ${e.fontFamily}`, n = (e) => Math.round(e) + .5, r = (e, t, n, r) => {
|
|
4
|
+
let { plot: i } = t, a = e.x === void 0 ? i.x + i.width / 2 : t.xToPx(e.x), o = e.y === void 0 ? i.y + i.height / 2 : t.yToPx(e.y), s = a - n / 2, c = o - r / 2;
|
|
5
|
+
return e.anchor === "top" ? c = o + 6 : e.anchor === "bottom" ? c = o - 6 - r : e.anchor === "left" ? s = a + 6 : e.anchor === "right" && (s = a - 6 - n), s = Math.max(i.x + 6, Math.min(s, i.x + i.width - 6 - n)), c = Math.max(i.y + 2, Math.min(c, i.y + i.height - 2 - r)), {
|
|
6
|
+
x: s,
|
|
7
|
+
y: c,
|
|
8
|
+
width: n,
|
|
9
|
+
height: r
|
|
10
|
+
};
|
|
11
|
+
}, i = (e, t) => {
|
|
4
12
|
let { plot: n } = t, r = e.x0 === void 0 ? -Infinity : t.xToPx(e.x0), i = e.x1 === void 0 ? Infinity : t.xToPx(e.x1), a = e.y0 === void 0 ? Infinity : t.yToPx(e.y0), o = e.y1 === void 0 ? -Infinity : t.yToPx(e.y1), s = Math.max(n.x, Math.min(r, i)), c = Math.min(n.x + n.width, Math.max(r, i)), l = Math.max(n.y, Math.min(a, o)), u = Math.min(n.y + n.height, Math.max(a, o));
|
|
5
13
|
return {
|
|
6
14
|
x: s,
|
|
@@ -8,47 +16,47 @@ var t = (e, t = e.fontSize, n = 400) => `${n} ${t}px ${e.fontFamily}`, n = (e) =
|
|
|
8
16
|
width: c - s,
|
|
9
17
|
height: u - l
|
|
10
18
|
};
|
|
11
|
-
},
|
|
19
|
+
}, a = (r, a) => {
|
|
12
20
|
let { scales: o, theme: s, x: c, y: l, xTicks: u, yTicks: d } = a, { plot: f } = o;
|
|
13
|
-
|
|
21
|
+
r.clearRect(0, 0, a.width, a.height), r.save(), r.beginPath(), r.rect(f.x, f.y, f.width, f.height), r.clip();
|
|
14
22
|
for (let t of a.annotations) {
|
|
15
23
|
if (t.type !== "rect") continue;
|
|
16
|
-
let n =
|
|
17
|
-
n.width <= 0 || n.height <= 0 || (
|
|
24
|
+
let n = i(t, o);
|
|
25
|
+
n.width <= 0 || n.height <= 0 || (r.fillStyle = e(t.color, t.opacity), r.fillRect(n.x, n.y, n.width, n.height));
|
|
18
26
|
}
|
|
19
|
-
if (
|
|
27
|
+
if (r.restore(), r.lineWidth = 1, r.strokeStyle = e(s.grid), r.beginPath(), l.grid) for (let e of d.values) {
|
|
20
28
|
let t = n(o.yToPx(e));
|
|
21
|
-
t < f.y - 1 || t > f.y + f.height + 1 || (
|
|
29
|
+
t < f.y - 1 || t > f.y + f.height + 1 || (r.moveTo(f.x, t), r.lineTo(f.x + f.width, t));
|
|
22
30
|
}
|
|
23
31
|
if (c.grid) for (let e of u.values) {
|
|
24
32
|
let t = n(o.xToPx(e));
|
|
25
|
-
t < f.x - 1 || t > f.x + f.width + 1 || (
|
|
33
|
+
t < f.x - 1 || t > f.x + f.width + 1 || (r.moveTo(t, f.y), r.lineTo(t, f.y + f.height));
|
|
26
34
|
}
|
|
27
|
-
|
|
35
|
+
r.stroke();
|
|
28
36
|
let p = Math.ceil(s.fontSize * 1.4);
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
let
|
|
32
|
-
|
|
37
|
+
if (r.font = t(s), r.fillStyle = e(s.textMuted), c.visible) {
|
|
38
|
+
r.strokeStyle = e(s.axis), r.beginPath();
|
|
39
|
+
let i = n(f.y + f.height);
|
|
40
|
+
r.moveTo(f.x, i), r.lineTo(f.x + f.width, i), r.stroke(), r.textBaseline = "top", r.textAlign = "center";
|
|
33
41
|
let l = -Infinity, d = u.values.map((e, t) => ({
|
|
34
42
|
px: o.xToPx(e),
|
|
35
43
|
text: u.labels[t]
|
|
36
44
|
})).sort((e, t) => e.px - t.px);
|
|
37
45
|
for (let { px: e, text: t } of d) {
|
|
38
46
|
if (e < f.x - .5 || e > f.x + f.width + .5) continue;
|
|
39
|
-
let n =
|
|
40
|
-
|
|
47
|
+
let n = r.measureText(t).width, i = Math.max(0, Math.min(a.width - n, e - n / 2));
|
|
48
|
+
i < l + 6 || (l = i + n, r.fillText(t, i + n / 2, f.y + f.height + 7));
|
|
41
49
|
}
|
|
42
|
-
c.title && (
|
|
50
|
+
c.title && (r.font = t(s, s.fontSize + 1, 500), r.fillStyle = e(s.text, .8), r.fillText(c.title, f.x + f.width / 2, f.y + f.height + p + 10));
|
|
43
51
|
}
|
|
44
|
-
l.visible && (
|
|
52
|
+
l.visible && (r.font = t(s), r.fillStyle = e(s.textMuted), r.textAlign = "right", r.textBaseline = "middle", d.values.forEach((e, t) => {
|
|
45
53
|
let n = o.yToPx(e);
|
|
46
|
-
n < f.y - .5 || n > f.y + f.height + .5 ||
|
|
47
|
-
}), l.title && (
|
|
48
|
-
},
|
|
54
|
+
n < f.y - .5 || n > f.y + f.height + .5 || r.fillText(d.labels[t], f.x - 8, n);
|
|
55
|
+
}), l.title && (r.save(), r.font = t(s, s.fontSize + 1, 500), r.fillStyle = e(s.text, .8), r.translate(p / 2 + 4, f.y + f.height / 2), r.rotate(-Math.PI / 2), r.textAlign = "center", r.fillText(l.title, 0, 0), r.restore()));
|
|
56
|
+
}, o = (e, t) => e.x < t.x + t.width && t.x < e.x + e.width && e.y < t.y + t.height && t.y < e.y + e.height, s = (e, t) => e.x >= t.x && e.y >= t.y && e.x + e.width <= t.x + t.width && e.y + e.height <= t.y + t.height, c = (e, t, n, r, i, a) => {
|
|
49
57
|
e.lineWidth = 3, e.lineJoin = "round", e.strokeStyle = a, e.strokeText(t, n, r), e.fillStyle = i, e.fillText(t, n, r);
|
|
50
|
-
},
|
|
51
|
-
let
|
|
58
|
+
}, l = (e, t, n, r, i = []) => {
|
|
59
|
+
let a = [];
|
|
52
60
|
for (let c of e) {
|
|
53
61
|
let e = n(c.text), l = c.r + 4, u = [
|
|
54
62
|
{
|
|
@@ -75,49 +83,55 @@ var t = (e, t = e.fontSize, n = 400) => `${n} ${t}px ${e.fontFamily}`, n = (e) =
|
|
|
75
83
|
width: e,
|
|
76
84
|
height: r
|
|
77
85
|
}
|
|
78
|
-
].find((e) =>
|
|
79
|
-
u && (i.push(u),
|
|
86
|
+
].find((e) => s(e, t) && !i.some((t) => o(t, e)));
|
|
87
|
+
u && (i.push(u), a.push({
|
|
80
88
|
label: c,
|
|
81
89
|
box: u
|
|
82
90
|
}));
|
|
83
91
|
}
|
|
84
|
-
return
|
|
85
|
-
},
|
|
86
|
-
let { scales:
|
|
87
|
-
|
|
88
|
-
let
|
|
89
|
-
for (let r of
|
|
92
|
+
return a;
|
|
93
|
+
}, u = (a, o) => {
|
|
94
|
+
let { scales: s, theme: u } = o, { plot: d } = s;
|
|
95
|
+
o.clear !== !1 && a.clearRect(0, 0, o.width, o.height), a.save(), a.beginPath(), a.rect(d.x, d.y, d.width, d.height), a.clip();
|
|
96
|
+
let f = e(u.background, .9), p = [], m = u.fontSize + 4;
|
|
97
|
+
for (let r of o.annotations) {
|
|
90
98
|
if (r.type !== "line") continue;
|
|
91
|
-
let
|
|
92
|
-
if (
|
|
93
|
-
let e = n(
|
|
94
|
-
|
|
99
|
+
let i = e(r.color);
|
|
100
|
+
if (a.strokeStyle = i, a.lineWidth = r.width, a.setLineDash(r.dash), a.beginPath(), r.axis === "y") {
|
|
101
|
+
let e = n(s.yToPx(r.value));
|
|
102
|
+
a.moveTo(d.x, e), a.lineTo(d.x + d.width, e), a.stroke(), r.label && (a.setLineDash([]), a.font = t(u, u.fontSize, 500), a.textAlign = "right", a.textBaseline = "bottom", c(a, r.label, d.x + d.width - 6, e - 3, i, f));
|
|
95
103
|
} else {
|
|
96
|
-
let e = n(
|
|
97
|
-
|
|
104
|
+
let e = n(s.xToPx(r.value));
|
|
105
|
+
a.moveTo(e, d.y), a.lineTo(e, d.y + d.height), a.stroke(), r.label && (a.setLineDash([]), a.font = t(u, u.fontSize, 500), a.textAlign = "left", a.textBaseline = "top", c(a, r.label, e + 5, d.y + 5, i, f));
|
|
98
106
|
}
|
|
99
107
|
}
|
|
100
|
-
|
|
101
|
-
for (let t of
|
|
108
|
+
a.setLineDash([]), a.font = t(u, u.fontSize + 1, 600);
|
|
109
|
+
for (let t of o.annotations) {
|
|
102
110
|
if (t.type !== "rect" || !t.label) continue;
|
|
103
|
-
let n =
|
|
111
|
+
let n = i(t, s);
|
|
104
112
|
if (n.width <= 0 || n.height <= 0) continue;
|
|
105
|
-
let
|
|
106
|
-
|
|
113
|
+
let r = a.measureText(t.label).width, o = t.labelPosition, c = o.endsWith("left") ? n.x + 10 : o.endsWith("right") ? n.x + n.width - 10 - r : n.x + (n.width - r) / 2, l = o.startsWith("top") ? n.y + 10 : o.startsWith("bottom") ? n.y + n.height - 10 - m : n.y + (n.height - m) / 2;
|
|
114
|
+
a.textAlign = "left", a.textBaseline = "top", a.fillStyle = e(t.labelColor), a.fillText(t.label, c, l), p.push({
|
|
107
115
|
x: c,
|
|
108
116
|
y: l,
|
|
109
|
-
width:
|
|
110
|
-
height:
|
|
117
|
+
width: r,
|
|
118
|
+
height: m
|
|
111
119
|
});
|
|
112
120
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
121
|
+
for (let n of o.annotations) {
|
|
122
|
+
if (n.type !== "text" || !n.text) continue;
|
|
123
|
+
a.font = t(u, u.fontSize, n.weight);
|
|
124
|
+
let i = r(n, s, a.measureText(n.text).width, m);
|
|
125
|
+
a.textAlign = "left", a.textBaseline = "middle", c(a, n.text, i.x, i.y + i.height / 2, e(n.color), f), p.push(i);
|
|
126
|
+
}
|
|
127
|
+
if (o.pointLabels.length) {
|
|
128
|
+
a.font = t(u), a.textAlign = "left", a.textBaseline = "middle";
|
|
129
|
+
let n = e(u.text, .85), r = l(o.pointLabels, d, (e) => a.measureText(e).width, m - 2, p);
|
|
130
|
+
for (let { label: e, box: t } of r) c(a, e.text, t.x, t.y + t.height / 2, n, f);
|
|
117
131
|
}
|
|
118
|
-
|
|
132
|
+
a.restore();
|
|
119
133
|
};
|
|
120
134
|
//#endregion
|
|
121
|
-
export {
|
|
135
|
+
export { a as drawBackground, u as drawForeground, t as font, l as placeLabels, r as textBox };
|
|
122
136
|
|
|
123
137
|
//# sourceMappingURL=overlay.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.js","names":["font","theme","weight","size","crisp","v","rectOf","s","xa","a","xb","ya","yb","left","plot","right","top","bottom","drawBackground","input","scales","ctx","r","toCss","y","yTicks","py","x","xTicks","px","line","base","lastRight","order","i","b","w","text","overlaps","inside","haloText","halo","color","placeLabels","placed","label","labels","measure","gap","box","height","c","occupied","o","drawForeground","labelHeight","pos","tx","ty","textColor","t"],"sources":["../../../../charts/src/engine/overlay.ts"],"sourcesContent":["// Canvas2D layers around the data: background (areas, grid, axes, tick\n// labels) and foreground (reference lines, annotation and point labels).\n\nimport { toCss, type Rgba } from \"./color\";\nimport type { AxisTicks } from \"./axis\";\nimport type { Rect, Scales } from \"./layout\";\nimport type { AxisModel } from \"./model\";\nimport type { ChartTheme } from \"./theme\";\nimport type { ChartLabelPosition } from \"./types\";\n\nexport interface ResolvedRect {\n type: \"rect\";\n x0?: number;\n x1?: number;\n y0?: number;\n y1?: number;\n color: Rgba;\n opacity: number;\n label?: string;\n labelPosition: ChartLabelPosition;\n labelColor: Rgba;\n}\n\nexport interface ResolvedLine {\n type: \"line\";\n axis: \"x\" | \"y\";\n value: number;\n color: Rgba;\n width: number;\n dash: number[];\n label?: string;\n}\n\nexport type ResolvedAnnotation = ResolvedRect | ResolvedLine;\n\nexport interface PointLabel {\n x: number;\n y: number;\n /** Radius of the dot */\n r: number;\n text: string;\n}\n\nexport const font = (theme: ChartTheme, size = theme.fontSize, weight = 400) =>\n `${weight} ${size}px ${theme.fontFamily}`;\n\nconst crisp = (v: number) => Math.round(v) + 0.5;\n\nconst rectOf = (a: ResolvedRect, s: Scales): Rect => {\n const { plot } = s;\n const xa = a.x0 === undefined ? -Infinity : s.xToPx(a.x0);\n const xb = a.x1 === undefined ? Infinity : s.xToPx(a.x1);\n const ya = a.y0 === undefined ? Infinity : s.yToPx(a.y0);\n const yb = a.y1 === undefined ? -Infinity : s.yToPx(a.y1);\n const left = Math.max(plot.x, Math.min(xa, xb));\n const right = Math.min(plot.x + plot.width, Math.max(xa, xb));\n const top = Math.max(plot.y, Math.min(ya, yb));\n const bottom = Math.min(plot.y + plot.height, Math.max(ya, yb));\n return { x: left, y: top, width: right - left, height: bottom - top };\n};\n\nexport interface BackgroundInput {\n width: number;\n height: number;\n scales: Scales;\n x: AxisModel;\n y: AxisModel;\n xTicks: AxisTicks;\n yTicks: AxisTicks;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n}\n\nexport const drawBackground = (\n ctx: CanvasRenderingContext2D,\n input: BackgroundInput,\n) => {\n const { scales, theme, x, y, xTicks, yTicks } = input;\n const { plot } = scales;\n ctx.clearRect(0, 0, input.width, input.height);\n\n // areas\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n for (const a of input.annotations) {\n if (a.type !== \"rect\") continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n ctx.fillStyle = toCss(a.color, a.opacity);\n ctx.fillRect(r.x, r.y, r.width, r.height);\n }\n ctx.restore();\n\n // grid\n ctx.lineWidth = 1;\n ctx.strokeStyle = toCss(theme.grid);\n ctx.beginPath();\n if (y.grid) {\n for (const v of yTicks.values) {\n const py = crisp(scales.yToPx(v));\n if (py < plot.y - 1 || py > plot.y + plot.height + 1) continue;\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n }\n }\n if (x.grid) {\n for (const v of xTicks.values) {\n const px = crisp(scales.xToPx(v));\n if (px < plot.x - 1 || px > plot.x + plot.width + 1) continue;\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n }\n }\n ctx.stroke();\n\n const line = Math.ceil(theme.fontSize * 1.4);\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n\n // x axis\n if (x.visible) {\n ctx.strokeStyle = toCss(theme.axis);\n ctx.beginPath();\n const base = crisp(plot.y + plot.height);\n ctx.moveTo(plot.x, base);\n ctx.lineTo(plot.x + plot.width, base);\n ctx.stroke();\n ctx.textBaseline = \"top\";\n ctx.textAlign = \"center\";\n let lastRight = -Infinity;\n // left to right (reversed axes list their ticks right to left)\n const order = xTicks.values\n .map((v, i) => ({ px: scales.xToPx(v), text: xTicks.labels[i] }))\n .sort((a, b) => a.px - b.px);\n for (const { px, text } of order) {\n if (px < plot.x - 0.5 || px > plot.x + plot.width + 0.5) continue;\n const w = ctx.measureText(text).width;\n const left = Math.max(0, Math.min(input.width - w, px - w / 2));\n if (left < lastRight + 6) continue;\n lastRight = left + w;\n ctx.fillText(text, left + w / 2, plot.y + plot.height + 7);\n }\n if (x.title) {\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.fillText(\n x.title,\n plot.x + plot.width / 2,\n plot.y + plot.height + line + 10,\n );\n }\n }\n\n // y axis\n if (y.visible) {\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"middle\";\n yTicks.values.forEach((v, i) => {\n const py = scales.yToPx(v);\n if (py < plot.y - 0.5 || py > plot.y + plot.height + 0.5) return;\n ctx.fillText(yTicks.labels[i], plot.x - 8, py);\n });\n if (y.title) {\n ctx.save();\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.translate(line / 2 + 4, plot.y + plot.height / 2);\n ctx.rotate(-Math.PI / 2);\n ctx.textAlign = \"center\";\n ctx.fillText(y.title, 0, 0);\n ctx.restore();\n }\n }\n};\n\nconst overlaps = (a: Rect, b: Rect) =>\n a.x < b.x + b.width &&\n b.x < a.x + a.width &&\n a.y < b.y + b.height &&\n b.y < a.y + a.height;\n\nconst inside = (r: Rect, plot: Rect) =>\n r.x >= plot.x &&\n r.y >= plot.y &&\n r.x + r.width <= plot.x + plot.width &&\n r.y + r.height <= plot.y + plot.height;\n\n/** Text with a halo in the background color (readable over data) */\nconst haloText = (\n ctx: CanvasRenderingContext2D,\n text: string,\n x: number,\n y: number,\n color: string,\n halo: string,\n) => {\n ctx.lineWidth = 3;\n ctx.lineJoin = \"round\";\n ctx.strokeStyle = halo;\n ctx.strokeText(text, x, y);\n ctx.fillStyle = color;\n ctx.fillText(text, x, y);\n};\n\n/** Greedy placement: right, left, above, below the dot; skipped when no slot is free */\nexport const placeLabels = (\n labels: readonly PointLabel[],\n plot: Rect,\n measure: (text: string) => number,\n height: number,\n occupied: Rect[] = [],\n): { label: PointLabel; box: Rect }[] => {\n const placed: { label: PointLabel; box: Rect }[] = [];\n for (const label of labels) {\n const w = measure(label.text);\n const gap = label.r + 4;\n const candidates: Rect[] = [\n { x: label.x + gap, y: label.y - height / 2, width: w, height },\n { x: label.x - gap - w, y: label.y - height / 2, width: w, height },\n { x: label.x - w / 2, y: label.y - gap - height, width: w, height },\n { x: label.x - w / 2, y: label.y + gap, width: w, height },\n ];\n const box = candidates.find(\n (c) => inside(c, plot) && !occupied.some((o) => overlaps(o, c)),\n );\n if (!box) continue;\n occupied.push(box);\n placed.push({ label, box });\n }\n return placed;\n};\n\nexport interface ForegroundInput {\n width: number;\n height: number;\n scales: Scales;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n pointLabels: readonly PointLabel[];\n}\n\nexport const drawForeground = (\n ctx: CanvasRenderingContext2D,\n input: ForegroundInput,\n) => {\n const { scales, theme } = input;\n const { plot } = scales;\n ctx.clearRect(0, 0, input.width, input.height);\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n\n const halo = toCss(theme.background, 0.9);\n const occupied: Rect[] = [];\n const labelHeight = theme.fontSize + 4;\n\n for (const a of input.annotations) {\n if (a.type !== \"line\") continue;\n const color = toCss(a.color);\n ctx.strokeStyle = color;\n ctx.lineWidth = a.width;\n ctx.setLineDash(a.dash);\n ctx.beginPath();\n if (a.axis === \"y\") {\n const py = crisp(scales.yToPx(a.value));\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"bottom\";\n haloText(ctx, a.label, plot.x + plot.width - 6, py - 3, color, halo);\n }\n } else {\n const px = crisp(scales.xToPx(a.value));\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n haloText(ctx, a.label, px + 5, plot.y + 5, color, halo);\n }\n }\n }\n ctx.setLineDash([]);\n\n // labels of areas\n ctx.font = font(theme, theme.fontSize + 1, 600);\n for (const a of input.annotations) {\n if (a.type !== \"rect\" || !a.label) continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n const pad = 10;\n const w = ctx.measureText(a.label).width;\n const pos = a.labelPosition;\n const tx = pos.endsWith(\"left\")\n ? r.x + pad\n : pos.endsWith(\"right\")\n ? r.x + r.width - pad - w\n : r.x + (r.width - w) / 2;\n const ty = pos.startsWith(\"top\")\n ? r.y + pad\n : pos.startsWith(\"bottom\")\n ? r.y + r.height - pad - labelHeight\n : r.y + (r.height - labelHeight) / 2;\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n ctx.fillStyle = toCss(a.labelColor);\n ctx.fillText(a.label, tx, ty);\n occupied.push({ x: tx, y: ty, width: w, height: labelHeight });\n }\n\n // point labels\n if (input.pointLabels.length) {\n ctx.font = font(theme);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n const textColor = toCss(theme.text, 0.85);\n const placed = placeLabels(\n input.pointLabels,\n plot,\n (t) => ctx.measureText(t).width,\n labelHeight - 2,\n occupied,\n );\n for (const { label, box } of placed) {\n haloText(ctx, label.text, box.x, box.y + box.height / 2, textColor, halo);\n }\n }\n ctx.restore();\n};\n"],"mappings":";;AA2CA,IAAaA,KAAQ,GAAmB,IAAOC,EAAM,UAAU,IAAS,QACtE,GAAGC,EAAO,GAAGC,EAAK,KAAKF,EAAM,cAEzBG,KAAS,MAAc,KAAK,MAAMC,CAAC,IAAI,IAEvCC,KAAU,GAAiB,MAAoB;CACnD,IAAM,EAAE,YAASC,GACXC,IAAKC,EAAE,OAAO,KAAA,IAAY,YAAYF,EAAE,MAAME,EAAE,EAAE,GAClDC,IAAKD,EAAE,OAAO,KAAA,IAAY,WAAWF,EAAE,MAAME,EAAE,EAAE,GACjDE,IAAKF,EAAE,OAAO,KAAA,IAAY,WAAWF,EAAE,MAAME,EAAE,EAAE,GACjDG,IAAKH,EAAE,OAAO,KAAA,IAAY,YAAYF,EAAE,MAAME,EAAE,EAAE,GAClDI,IAAO,KAAK,IAAIC,EAAK,GAAG,KAAK,IAAIN,GAAIE,CAAE,CAAC,GACxCK,IAAQ,KAAK,IAAID,EAAK,IAAIA,EAAK,OAAO,KAAK,IAAIN,GAAIE,CAAE,CAAC,GACtDM,IAAM,KAAK,IAAIF,EAAK,GAAG,KAAK,IAAIH,GAAIC,CAAE,CAAC,GACvCK,IAAS,KAAK,IAAIH,EAAK,IAAIA,EAAK,QAAQ,KAAK,IAAIH,GAAIC,CAAE,CAAC;CAC9D,OAAO;EAAE,GAAGC;EAAM,GAAGG;EAAK,OAAOD,IAAQF;EAAM,QAAQI,IAASD;CAAI;AACtE,GAcaE,KACX,GACA,MACG;CACH,I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ACd"}
|
|
1
|
+
{"version":3,"file":"overlay.js","names":["font","theme","weight","size","crisp","v","textBox","s","px","a","plot","py","x","width","y","height","rectOf","xa","xb","ya","yb","left","right","top","bottom","drawBackground","input","scales","ctx","r","toCss","yTicks","xTicks","line","base","lastRight","order","i","b","w","text","overlaps","inside","haloText","halo","color","placeLabels","placed","label","labels","measure","gap","box","c","occupied","o","drawForeground","labelHeight","pos","tx","ty","textColor","t"],"sources":["../../../../charts/src/engine/overlay.ts"],"sourcesContent":["// Canvas2D layers around the data: background (areas, grid, axes, tick\n// labels) and foreground (reference lines, annotation and point labels).\n\nimport { toCss, type Rgba } from \"./color\";\nimport type { AxisTicks } from \"./axis\";\nimport type { Rect, Scales } from \"./layout\";\nimport type { AxisModel } from \"./model\";\nimport type { ChartTheme } from \"./theme\";\nimport type { ChartLabelPosition } from \"./types\";\n\nexport interface ResolvedRect {\n type: \"rect\";\n x0?: number;\n x1?: number;\n y0?: number;\n y1?: number;\n color: Rgba;\n opacity: number;\n label?: string;\n labelPosition: ChartLabelPosition;\n labelColor: Rgba;\n}\n\nexport interface ResolvedLine {\n type: \"line\";\n axis: \"x\" | \"y\";\n value: number;\n color: Rgba;\n width: number;\n dash: number[];\n label?: string;\n}\n\nexport interface ResolvedText {\n type: \"text\";\n x?: number;\n y?: number;\n text: string;\n anchor: \"center\" | \"top\" | \"bottom\" | \"left\" | \"right\";\n color: Rgba;\n weight: number;\n}\n\nexport type ResolvedAnnotation = ResolvedRect | ResolvedLine | ResolvedText;\n\nexport interface PointLabel {\n x: number;\n y: number;\n /** Radius of the dot */\n r: number;\n text: string;\n}\n\nexport const font = (theme: ChartTheme, size = theme.fontSize, weight = 400) =>\n `${weight} ${size}px ${theme.fontFamily}`;\n\nconst crisp = (v: number) => Math.round(v) + 0.5;\n\n/** Box of a text annotation, kept inside the plot */\nexport const textBox = (\n a: ResolvedText,\n s: Scales,\n width: number,\n height: number,\n): Rect => {\n const { plot } = s;\n const px = a.x === undefined ? plot.x + plot.width / 2 : s.xToPx(a.x);\n const py = a.y === undefined ? plot.y + plot.height / 2 : s.yToPx(a.y);\n const gap = 6;\n let x = px - width / 2;\n let y = py - height / 2;\n if (a.anchor === \"top\") y = py + gap;\n else if (a.anchor === \"bottom\") y = py - gap - height;\n else if (a.anchor === \"left\") x = px + gap;\n else if (a.anchor === \"right\") x = px - gap - width;\n x = Math.max(plot.x + gap, Math.min(x, plot.x + plot.width - gap - width));\n y = Math.max(plot.y + 2, Math.min(y, plot.y + plot.height - 2 - height));\n return { x, y, width, height };\n};\n\nconst rectOf = (a: ResolvedRect, s: Scales): Rect => {\n const { plot } = s;\n const xa = a.x0 === undefined ? -Infinity : s.xToPx(a.x0);\n const xb = a.x1 === undefined ? Infinity : s.xToPx(a.x1);\n const ya = a.y0 === undefined ? Infinity : s.yToPx(a.y0);\n const yb = a.y1 === undefined ? -Infinity : s.yToPx(a.y1);\n const left = Math.max(plot.x, Math.min(xa, xb));\n const right = Math.min(plot.x + plot.width, Math.max(xa, xb));\n const top = Math.max(plot.y, Math.min(ya, yb));\n const bottom = Math.min(plot.y + plot.height, Math.max(ya, yb));\n return { x: left, y: top, width: right - left, height: bottom - top };\n};\n\nexport interface BackgroundInput {\n width: number;\n height: number;\n scales: Scales;\n x: AxisModel;\n y: AxisModel;\n xTicks: AxisTicks;\n yTicks: AxisTicks;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n}\n\nexport const drawBackground = (\n ctx: CanvasRenderingContext2D,\n input: BackgroundInput,\n) => {\n const { scales, theme, x, y, xTicks, yTicks } = input;\n const { plot } = scales;\n ctx.clearRect(0, 0, input.width, input.height);\n\n // areas\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n for (const a of input.annotations) {\n if (a.type !== \"rect\") continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n ctx.fillStyle = toCss(a.color, a.opacity);\n ctx.fillRect(r.x, r.y, r.width, r.height);\n }\n ctx.restore();\n\n // grid\n ctx.lineWidth = 1;\n ctx.strokeStyle = toCss(theme.grid);\n ctx.beginPath();\n if (y.grid) {\n for (const v of yTicks.values) {\n const py = crisp(scales.yToPx(v));\n if (py < plot.y - 1 || py > plot.y + plot.height + 1) continue;\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n }\n }\n if (x.grid) {\n for (const v of xTicks.values) {\n const px = crisp(scales.xToPx(v));\n if (px < plot.x - 1 || px > plot.x + plot.width + 1) continue;\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n }\n }\n ctx.stroke();\n\n const line = Math.ceil(theme.fontSize * 1.4);\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n\n // x axis\n if (x.visible) {\n ctx.strokeStyle = toCss(theme.axis);\n ctx.beginPath();\n const base = crisp(plot.y + plot.height);\n ctx.moveTo(plot.x, base);\n ctx.lineTo(plot.x + plot.width, base);\n ctx.stroke();\n ctx.textBaseline = \"top\";\n ctx.textAlign = \"center\";\n let lastRight = -Infinity;\n // left to right (reversed axes list their ticks right to left)\n const order = xTicks.values\n .map((v, i) => ({ px: scales.xToPx(v), text: xTicks.labels[i] }))\n .sort((a, b) => a.px - b.px);\n for (const { px, text } of order) {\n if (px < plot.x - 0.5 || px > plot.x + plot.width + 0.5) continue;\n const w = ctx.measureText(text).width;\n const left = Math.max(0, Math.min(input.width - w, px - w / 2));\n if (left < lastRight + 6) continue;\n lastRight = left + w;\n ctx.fillText(text, left + w / 2, plot.y + plot.height + 7);\n }\n if (x.title) {\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.fillText(\n x.title,\n plot.x + plot.width / 2,\n plot.y + plot.height + line + 10,\n );\n }\n }\n\n // y axis\n if (y.visible) {\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"middle\";\n yTicks.values.forEach((v, i) => {\n const py = scales.yToPx(v);\n if (py < plot.y - 0.5 || py > plot.y + plot.height + 0.5) return;\n ctx.fillText(yTicks.labels[i], plot.x - 8, py);\n });\n if (y.title) {\n ctx.save();\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.translate(line / 2 + 4, plot.y + plot.height / 2);\n ctx.rotate(-Math.PI / 2);\n ctx.textAlign = \"center\";\n ctx.fillText(y.title, 0, 0);\n ctx.restore();\n }\n }\n};\n\nconst overlaps = (a: Rect, b: Rect) =>\n a.x < b.x + b.width &&\n b.x < a.x + a.width &&\n a.y < b.y + b.height &&\n b.y < a.y + a.height;\n\nconst inside = (r: Rect, plot: Rect) =>\n r.x >= plot.x &&\n r.y >= plot.y &&\n r.x + r.width <= plot.x + plot.width &&\n r.y + r.height <= plot.y + plot.height;\n\n/** Text with a halo in the background color (readable over data) */\nconst haloText = (\n ctx: CanvasRenderingContext2D,\n text: string,\n x: number,\n y: number,\n color: string,\n halo: string,\n) => {\n ctx.lineWidth = 3;\n ctx.lineJoin = \"round\";\n ctx.strokeStyle = halo;\n ctx.strokeText(text, x, y);\n ctx.fillStyle = color;\n ctx.fillText(text, x, y);\n};\n\n/** Greedy placement: right, left, above, below the dot; skipped when no slot is free */\nexport const placeLabels = (\n labels: readonly PointLabel[],\n plot: Rect,\n measure: (text: string) => number,\n height: number,\n occupied: Rect[] = [],\n): { label: PointLabel; box: Rect }[] => {\n const placed: { label: PointLabel; box: Rect }[] = [];\n for (const label of labels) {\n const w = measure(label.text);\n const gap = label.r + 4;\n const candidates: Rect[] = [\n { x: label.x + gap, y: label.y - height / 2, width: w, height },\n { x: label.x - gap - w, y: label.y - height / 2, width: w, height },\n { x: label.x - w / 2, y: label.y - gap - height, width: w, height },\n { x: label.x - w / 2, y: label.y + gap, width: w, height },\n ];\n const box = candidates.find(\n (c) => inside(c, plot) && !occupied.some((o) => overlaps(o, c)),\n );\n if (!box) continue;\n occupied.push(box);\n placed.push({ label, box });\n }\n return placed;\n};\n\nexport interface ForegroundInput {\n width: number;\n height: number;\n scales: Scales;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n pointLabels: readonly PointLabel[];\n /**\n * Clears the canvas first (off when the layers share one canvas)\n * @default true\n */\n clear?: boolean;\n}\n\nexport const drawForeground = (\n ctx: CanvasRenderingContext2D,\n input: ForegroundInput,\n) => {\n const { scales, theme } = input;\n const { plot } = scales;\n if (input.clear !== false) ctx.clearRect(0, 0, input.width, input.height);\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n\n const halo = toCss(theme.background, 0.9);\n const occupied: Rect[] = [];\n const labelHeight = theme.fontSize + 4;\n\n for (const a of input.annotations) {\n if (a.type !== \"line\") continue;\n const color = toCss(a.color);\n ctx.strokeStyle = color;\n ctx.lineWidth = a.width;\n ctx.setLineDash(a.dash);\n ctx.beginPath();\n if (a.axis === \"y\") {\n const py = crisp(scales.yToPx(a.value));\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"bottom\";\n haloText(ctx, a.label, plot.x + plot.width - 6, py - 3, color, halo);\n }\n } else {\n const px = crisp(scales.xToPx(a.value));\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n haloText(ctx, a.label, px + 5, plot.y + 5, color, halo);\n }\n }\n }\n ctx.setLineDash([]);\n\n // labels of areas\n ctx.font = font(theme, theme.fontSize + 1, 600);\n for (const a of input.annotations) {\n if (a.type !== \"rect\" || !a.label) continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n const pad = 10;\n const w = ctx.measureText(a.label).width;\n const pos = a.labelPosition;\n const tx = pos.endsWith(\"left\")\n ? r.x + pad\n : pos.endsWith(\"right\")\n ? r.x + r.width - pad - w\n : r.x + (r.width - w) / 2;\n const ty = pos.startsWith(\"top\")\n ? r.y + pad\n : pos.startsWith(\"bottom\")\n ? r.y + r.height - pad - labelHeight\n : r.y + (r.height - labelHeight) / 2;\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n ctx.fillStyle = toCss(a.labelColor);\n ctx.fillText(a.label, tx, ty);\n occupied.push({ x: tx, y: ty, width: w, height: labelHeight });\n }\n\n // free texts\n for (const a of input.annotations) {\n if (a.type !== \"text\" || !a.text) continue;\n ctx.font = font(theme, theme.fontSize, a.weight);\n const box = textBox(a, scales, ctx.measureText(a.text).width, labelHeight);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n haloText(ctx, a.text, box.x, box.y + box.height / 2, toCss(a.color), halo);\n occupied.push(box);\n }\n\n // point labels\n if (input.pointLabels.length) {\n ctx.font = font(theme);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n const textColor = toCss(theme.text, 0.85);\n const placed = placeLabels(\n input.pointLabels,\n plot,\n (t) => ctx.measureText(t).width,\n labelHeight - 2,\n occupied,\n );\n for (const { label, box } of placed) {\n haloText(ctx, label.text, box.x, box.y + box.height / 2, textColor, halo);\n }\n }\n ctx.restore();\n};\n"],"mappings":";;AAqDA,IAAaA,KAAQ,GAAmB,IAAOC,EAAM,UAAU,IAAS,QACtE,GAAGC,EAAO,GAAGC,EAAK,KAAKF,EAAM,cAEzBG,KAAS,MAAc,KAAK,MAAMC,CAAC,IAAI,IAGhCC,KACX,GACA,GACA,GACA,MACS;CACT,IAAM,EAAE,YAASC,GACXC,IAAKC,EAAE,MAAM,KAAA,IAAYC,EAAK,IAAIA,EAAK,QAAQ,IAAIH,EAAE,MAAME,EAAE,CAAC,GAC9DE,IAAKF,EAAE,MAA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IzE,AAHA,EAAI,YAAY,QAChB,EAAI,eAAe,UACnBd,EAASf,GAAKnB,EAAE,MAAM2C,EAAI,GAAGA,EAAI,IAAIA,EAAI,SAAS,GAAGtB,EAAMrB,EAAE,KAAK,GAAGmC,CAAI,GACzEU,EAAS,KAAKF,CAAG;CACnB;CAGA,IAAI1B,EAAM,YAAY,QAAQ;EAG5B,AAFA,EAAI,OAAO1B,EAAKC,CAAK,GACrB,EAAI,YAAY,QAChB,EAAI,eAAe;EACnB,IAAM4D,IAAY/B,EAAM7B,EAAM,MAAM,GAAI,GAClC8C,IAASD,EACbpB,EAAM,aACNhB,IACC,MAAMkB,EAAI,YAAYkC,CAAC,CAAC,CAAC,OAC1BL,IAAc,GACdH,CACF;EACA,KAAK,IAAM,EAAE,UAAO,YAASP,GAC3B,EAASnB,GAAKoB,EAAM,MAAMI,EAAI,GAAGA,EAAI,IAAIA,EAAI,SAAS,GAAGS,GAAWjB,CAAI;CAE5E;CACA,EAAI,QAAQ;AACd"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var e=(e,t,n)=>e.map(e=>({...e,type:e.type??t,...n!==void 0&&(e.type??t)===`bar`?{stack:e.stack??n}:{}})),t=(t,n=!1)=>e(t,n?`area`:`line`),n=(t,n=!1)=>e(t,`bar`,n?`stack`:void 0),r=t=>e(t,`scatter`),i={topLeft:`var(--danger-color, #ef4444)`,topRight:`var(--primary-color, #4f46e5)`,bottomLeft:`var(--warning-color, #f59e0b)`,bottomRight:`var(--text-secondary-color, #64748b)`},a=`var(--border-strong-color, var(--border-color, #cbd5e1))`,o=e=>{let[t,n]=e.xDomain??[0,10],[r,i]=e.yDomain??[0,10];return{x0:t,x1:n,y0:r,y1:i,xs:e.xSplit??(t+n)/2,ys:e.ySplit??(r+i)/2}},s=(e,t,n)=>{let{xs:r,ys:i}=o(e),a=e.reverseX?t<r:t>=r;return n>=i?a?`topRight`:`topLeft`:a?`bottomRight`:`bottomLeft`},c=(e,t)=>{let{x0:n,x1:r,y0:i,y1:a,xs:s,ys:c}=o(e),l=t.endsWith(`Right`);return{x:(e.reverseX?!l:l)?(s+r)/2:(n+s)/2,y:t.startsWith(`top`)?(c+a)/2:(i+c)/2}},l=(e,t={})=>{let{x0:n,x1:r,y0:c,y1:l,xs:u,ys:d}=o(e),f=!!e.reverseX,p=t=>e.quadrants?.[t]?.color??i[t],m=[{type:`scatter`,name:e.name??``,pointSize:e.pointSize??12,showLabels:e.showLabels??!0,opacity:.9,data:e.points.map(t=>({x:t.x,y:t.y,label:t.label,size:t.size,color:t.color??p(s(e,t.x,t.y))}))}],h=f?[u,r]:[n,u],g=f?[n,u]:[u,r],_=(t,[n,r],[i,a],o)=>({type:`rect`,x0:n,x1:r,y0:i,y1:a,color:p(t),opacity:.07,label:e.quadrants?.[t]?.label,labelPosition:o}),v=e.axisLabels??{},y=f?r:n,b=f?n:r,x=[...v.top?[{type:`text`,x:u,y:l,text:v.top,anchor:`top`}]:[],...v.bottom?[{type:`text`,x:u,y:c,text:v.bottom,anchor:`bottom`}]:[],...v.left?[{type:`text`,x:y,y:d,text:v.left,anchor:`left`}]:[],...v.right?[{type:`text`,x:b,y:d,text:v.right,anchor:`right`}]:[]],S=[_(`topLeft`,h,[d,l],`top-left`),_(`topRight`,g,[d,l],`top-right`),_(`bottomLeft`,h,[c,d],`bottom-left`),_(`bottomRight`,g,[c,d],`bottom-right`),{type:`line`,axis:`x`,value:u,dash:[],color:a},{type:`line`,axis:`y`,value:d,dash:[],color:a},...x,...t.annotations??[]],C=e.showTicks??!0,w=t.interaction!==!1&&{zoom:!1,...typeof t.interaction==`object`?t.interaction:{},...e.draggable?{dragPoints:!0}:{}};return{...t,series:m,annotations:S,tooltip:t.tooltip??(C?void 0:{render:t=>{let n=t.items[0];if(!n)return null;let r=e.quadrants?.[s(e,n.x,n.y)]?.label;return[n.label??e.name??``,r??``].filter(Boolean).join(`
|
|
2
|
+
`)}}),xAxis:{min:n,max:r,title:e.xLabel,reverse:f,nice:!1,grid:!1,tickCount:4,visible:C||!!e.xLabel,...C?{}:{format:()=>``}},yAxis:{min:c,max:l,title:e.yLabel,nice:!1,grid:!1,tickCount:4,visible:C||!!e.yLabel,...C?{}:{format:()=>``}},legend:t.legend??!1,padding:t.padding??(C?void 0:{top:4,right:4,bottom:4,left:4}),interaction:w}};exports.DEFAULT_QUADRANT_COLORS=i,exports.barSeries=n,exports.lineSeries=t,exports.quadrantCenter=c,exports.quadrantChartOptions=l,exports.quadrantOf=s,exports.scatterSeries=r,exports.withSeriesType=e;
|
|
3
|
+
//# sourceMappingURL=presets.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.cjs","names":["withSeriesType","series","s","type","stack","lineSeries","area","barSeries","stacked","scatterSeries","DEFAULT_QUADRANT_COLORS","DIVIDER","splits","x0","x1","config","y0","y1","quadrantOf","right","x","xs","y","ys","quadrantCenter","visualRight","corner","quadrantChartOptions","reverseX","color","p","left","rect","xa","xb","ya","yb","position","ends","visualLeft","texts","annotations","base","showTicks","interaction","item","event","region"],"sources":["../../../../charts/src/engine/presets.ts"],"sourcesContent":["// Option presets of the chart components, shared by every platform (React,\n// mini-programs, React Native): they turn component props into engine\n// options.\n\nimport type {\n ChartAnnotation,\n ChartInteractionOptions,\n ChartOptions,\n ChartSeries,\n ChartSeriesType,\n} from \"./types\";\n\n/** Gives the series without a `type` the type of the component */\nexport const withSeriesType = (\n series: readonly ChartSeries[],\n type: ChartSeriesType,\n stack?: string,\n): ChartSeries[] =>\n series.map((s) => ({\n ...s,\n type: s.type ?? type,\n ...(stack !== undefined && (s.type ?? type) === \"bar\"\n ? { stack: s.stack ?? stack }\n : {}),\n }));\n\n/** Series of a LineChart (`area` fills them) */\nexport const lineSeries = (series: readonly ChartSeries[], area = false) =>\n withSeriesType(series, area ? \"area\" : \"line\");\n\n/** Series of a BarChart (`stacked` stacks them) */\nexport const barSeries = (series: readonly ChartSeries[], stacked = false) =>\n withSeriesType(series, \"bar\", stacked ? \"stack\" : undefined);\n\n/** Series of a ScatterChart */\nexport const scatterSeries = (series: readonly ChartSeries[]) =>\n withSeriesType(series, \"scatter\");\n\n/** A point of a QuadrantChart */\nexport interface QuadrantPoint {\n /** Position on the horizontal axis */\n x: number;\n /** Position on the vertical axis */\n y: number;\n /** Text drawn next to the dot and shown in the tooltip */\n label?: string;\n /** Dot color (any CSS color); the color of its quadrant by default */\n color?: string;\n /** Dot diameter in pixels */\n size?: number;\n}\n\n/** Title and color of a quadrant */\nexport interface QuadrantRegion {\n /** Title drawn in the outer corner of the quadrant */\n label?: string;\n /** Background tint and default dot color (any CSS color) */\n color?: string;\n}\n\n/** The four quadrants of a QuadrantChart */\nexport interface QuadrantRegions {\n topLeft?: QuadrantRegion;\n topRight?: QuadrantRegion;\n bottomLeft?: QuadrantRegion;\n bottomRight?: QuadrantRegion;\n}\n\n/** A quadrant, as seen on screen */\nexport type QuadrantCorner = keyof QuadrantRegions;\n\n/** Texts at the four ends of the dividers, inside the plot */\nexport interface QuadrantAxisLabels {\n top?: string;\n bottom?: string;\n left?: string;\n right?: string;\n}\n\n/** Settings of a quadrant matrix (the props of QuadrantChart) */\nexport interface QuadrantConfig {\n /** Points to place */\n points: readonly QuadrantPoint[];\n /**\n * Range of the horizontal axis\n * @default [0, 10]\n */\n xDomain?: [number, number];\n /**\n * Range of the vertical axis\n * @default [0, 10]\n */\n yDomain?: [number, number];\n /** X value of the vertical divider (the middle of `xDomain` by default) */\n xSplit?: number;\n /** Y value of the horizontal divider (the middle of `yDomain` by default) */\n ySplit?: number;\n /** Titles and colors of the quadrants */\n quadrants?: QuadrantRegions;\n /** Title of the horizontal axis */\n xLabel?: string;\n /** Title of the vertical axis */\n yLabel?: string;\n /** Texts at the ends of the dividers, drawn inside the plot (e.g. \"Important\" at the top) */\n axisLabels?: QuadrantAxisLabels;\n /**\n * Shows the numeric ticks of the axes; `false` keeps only the matrix\n * @default true\n */\n showTicks?: boolean;\n /** Reverses the horizontal axis (e.g. \"urgent\" on the left) */\n reverseX?: boolean;\n /**\n * Draws the labels next to the dots (overlapping labels are skipped)\n * @default true\n */\n showLabels?: boolean;\n /**\n * Dot diameter in pixels\n * @default 12\n */\n pointSize?: number;\n /** Name of the points in the tooltip */\n name?: string;\n /** Lets the user drag the dots (`drag` / `drop` events) */\n draggable?: boolean;\n}\n\nexport const DEFAULT_QUADRANT_COLORS: Required<Record<QuadrantCorner, string>> =\n {\n topLeft: \"var(--danger-color, #ef4444)\",\n topRight: \"var(--primary-color, #4f46e5)\",\n bottomLeft: \"var(--warning-color, #f59e0b)\",\n bottomRight: \"var(--text-secondary-color, #64748b)\",\n };\n\nconst DIVIDER = \"var(--border-strong-color, var(--border-color, #cbd5e1))\";\n\nconst splits = (config: QuadrantConfig) => {\n const [x0, x1] = config.xDomain ?? [0, 10];\n const [y0, y1] = config.yDomain ?? [0, 10];\n return {\n x0,\n x1,\n y0,\n y1,\n xs: config.xSplit ?? (x0 + x1) / 2,\n ys: config.ySplit ?? (y0 + y1) / 2,\n };\n};\n\n/** Quadrant of a data position, as seen on screen */\nexport const quadrantOf = (\n config: Pick<\n QuadrantConfig,\n \"xDomain\" | \"yDomain\" | \"xSplit\" | \"ySplit\" | \"reverseX\"\n >,\n x: number,\n y: number,\n): QuadrantCorner => {\n const { xs, ys } = splits(config as QuadrantConfig);\n const right = config.reverseX ? x < xs : x >= xs;\n const top = y >= ys;\n return top\n ? right\n ? \"topRight\"\n : \"topLeft\"\n : right\n ? \"bottomRight\"\n : \"bottomLeft\";\n};\n\n/** Center of a quadrant in data coordinates */\nexport const quadrantCenter = (\n config: Pick<\n QuadrantConfig,\n \"xDomain\" | \"yDomain\" | \"xSplit\" | \"ySplit\" | \"reverseX\"\n >,\n corner: QuadrantCorner,\n): { x: number; y: number } => {\n const { x0, x1, y0, y1, xs, ys } = splits(config as QuadrantConfig);\n const visualRight = corner.endsWith(\"Right\");\n const dataHigh = config.reverseX ? !visualRight : visualRight;\n return {\n x: dataHigh ? (xs + x1) / 2 : (x0 + xs) / 2,\n y: corner.startsWith(\"top\") ? (ys + y1) / 2 : (y0 + ys) / 2,\n };\n};\n\n/** Engine options of a quadrant matrix */\nexport const quadrantChartOptions = (\n config: QuadrantConfig,\n base: Omit<ChartOptions, \"series\"> = {},\n): ChartOptions => {\n const { x0, x1, y0, y1, xs, ys } = splits(config);\n const reverseX = !!config.reverseX;\n const color = (corner: QuadrantCorner) =>\n config.quadrants?.[corner]?.color ?? DEFAULT_QUADRANT_COLORS[corner];\n\n const series: ChartSeries[] = [\n {\n type: \"scatter\",\n name: config.name ?? \"\",\n pointSize: config.pointSize ?? 12,\n showLabels: config.showLabels ?? true,\n opacity: 0.9,\n data: config.points.map((p) => ({\n x: p.x,\n y: p.y,\n label: p.label,\n size: p.size,\n color: p.color ?? color(quadrantOf(config, p.x, p.y)),\n })),\n },\n ];\n\n // visual left / right -> data ranges\n const left: [number, number] = reverseX ? [xs, x1] : [x0, xs];\n const right: [number, number] = reverseX ? [x0, xs] : [xs, x1];\n const rect = (\n corner: QuadrantCorner,\n [xa, xb]: [number, number],\n [ya, yb]: [number, number],\n position: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\",\n ): ChartAnnotation => ({\n type: \"rect\",\n x0: xa,\n x1: xb,\n y0: ya,\n y1: yb,\n color: color(corner),\n opacity: 0.07,\n label: config.quadrants?.[corner]?.label,\n labelPosition: position,\n });\n const ends = config.axisLabels ?? {};\n const visualLeft = reverseX ? x1 : x0;\n const visualRight = reverseX ? x0 : x1;\n const texts: ChartAnnotation[] = [\n ...(ends.top\n ? [{ type: \"text\", x: xs, y: y1, text: ends.top, anchor: \"top\" } as const]\n : []),\n ...(ends.bottom\n ? [\n {\n type: \"text\",\n x: xs,\n y: y0,\n text: ends.bottom,\n anchor: \"bottom\",\n } as const,\n ]\n : []),\n ...(ends.left\n ? [\n {\n type: \"text\",\n x: visualLeft,\n y: ys,\n text: ends.left,\n anchor: \"left\",\n } as const,\n ]\n : []),\n ...(ends.right\n ? [\n {\n type: \"text\",\n x: visualRight,\n y: ys,\n text: ends.right,\n anchor: \"right\",\n } as const,\n ]\n : []),\n ];\n\n const annotations: ChartAnnotation[] = [\n rect(\"topLeft\", left, [ys, y1], \"top-left\"),\n rect(\"topRight\", right, [ys, y1], \"top-right\"),\n rect(\"bottomLeft\", left, [y0, ys], \"bottom-left\"),\n rect(\"bottomRight\", right, [y0, ys], \"bottom-right\"),\n { type: \"line\", axis: \"x\", value: xs, dash: [], color: DIVIDER },\n { type: \"line\", axis: \"y\", value: ys, dash: [], color: DIVIDER },\n ...texts,\n ...(base.annotations ?? []),\n ];\n\n const showTicks = config.showTicks ?? true;\n const interaction: boolean | ChartInteractionOptions =\n base.interaction === false\n ? false\n : {\n zoom: false,\n ...(typeof base.interaction === \"object\" ? base.interaction : {}),\n ...(config.draggable ? { dragPoints: true } : {}),\n };\n\n return {\n ...base,\n series,\n annotations,\n tooltip:\n base.tooltip ??\n (showTicks\n ? undefined\n : {\n render: (event) => {\n const item = event.items[0];\n if (!item) return null;\n const region =\n config.quadrants?.[quadrantOf(config, item.x, item.y)]?.label;\n return [item.label ?? config.name ?? \"\", region ?? \"\"]\n .filter(Boolean)\n .join(\"\\n\");\n },\n }),\n xAxis: {\n min: x0,\n max: x1,\n title: config.xLabel,\n reverse: reverseX,\n nice: false,\n grid: false,\n tickCount: 4,\n visible: showTicks || !!config.xLabel,\n ...(showTicks ? {} : { format: () => \"\" }),\n },\n yAxis: {\n min: y0,\n max: y1,\n title: config.yLabel,\n nice: false,\n grid: false,\n tickCount: 4,\n visible: showTicks || !!config.yLabel,\n ...(showTicks ? {} : { format: () => \"\" }),\n },\n legend: base.legend ?? false,\n padding:\n base.padding ??\n (showTicks ? undefined : { top: 4, right: 4, bottom: 4, left: 4 }),\n interaction,\n };\n};\n"],"mappings":"AAaA,IAAaA,GACX,EACA,EACA,IAEAC,EAAO,IAAK,IAAO,CACjB,GAAGC,EACH,KAAMA,EAAE,MAAQC,EAChB,GAAIC,IAAU,IA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T,KAAM,GACN,KAAM,GACN,UAAW,EACX,QAASe,GAAa,CAAC,CAAC5B,EAAO,OAC/B,GAAI4B,EAAY,CAAC,EAAI,CAAE,WAAc,EAAG,CAC1C,EACA,MAAO,CACL,IAAK3B,EACL,IAAKC,EACL,MAAOF,EAAO,OACd,KAAM,GACN,KAAM,GACN,UAAW,EACX,QAAS4B,GAAa,CAAC,CAAC5B,EAAO,OAC/B,GAAI4B,EAAY,CAAC,EAAI,CAAE,WAAc,EAAG,CAC1C,EACA,OAAQD,EAAK,QAAU,GACvB,QACEA,EAAK,UACJC,EAAY,IAAA,GAAY,CAAE,IAAK,EAAG,MAAO,EAAG,OAAQ,EAAG,KAAM,CAAE,GAClE,aACF,CACF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ChartOptions, ChartSeries, ChartSeriesType } from './types.cjs';
|
|
2
|
+
/** Gives the series without a `type` the type of the component */
|
|
3
|
+
export declare const withSeriesType: (series: readonly ChartSeries[], type: ChartSeriesType, stack?: string) => ChartSeries[];
|
|
4
|
+
/** Series of a LineChart (`area` fills them) */
|
|
5
|
+
export declare const lineSeries: (series: readonly ChartSeries[], area?: boolean) => ChartSeries[];
|
|
6
|
+
/** Series of a BarChart (`stacked` stacks them) */
|
|
7
|
+
export declare const barSeries: (series: readonly ChartSeries[], stacked?: boolean) => ChartSeries[];
|
|
8
|
+
/** Series of a ScatterChart */
|
|
9
|
+
export declare const scatterSeries: (series: readonly ChartSeries[]) => ChartSeries[];
|
|
10
|
+
/** A point of a QuadrantChart */
|
|
11
|
+
export interface QuadrantPoint {
|
|
12
|
+
/** Position on the horizontal axis */
|
|
13
|
+
x: number;
|
|
14
|
+
/** Position on the vertical axis */
|
|
15
|
+
y: number;
|
|
16
|
+
/** Text drawn next to the dot and shown in the tooltip */
|
|
17
|
+
label?: string;
|
|
18
|
+
/** Dot color (any CSS color); the color of its quadrant by default */
|
|
19
|
+
color?: string;
|
|
20
|
+
/** Dot diameter in pixels */
|
|
21
|
+
size?: number;
|
|
22
|
+
}
|
|
23
|
+
/** Title and color of a quadrant */
|
|
24
|
+
export interface QuadrantRegion {
|
|
25
|
+
/** Title drawn in the outer corner of the quadrant */
|
|
26
|
+
label?: string;
|
|
27
|
+
/** Background tint and default dot color (any CSS color) */
|
|
28
|
+
color?: string;
|
|
29
|
+
}
|
|
30
|
+
/** The four quadrants of a QuadrantChart */
|
|
31
|
+
export interface QuadrantRegions {
|
|
32
|
+
topLeft?: QuadrantRegion;
|
|
33
|
+
topRight?: QuadrantRegion;
|
|
34
|
+
bottomLeft?: QuadrantRegion;
|
|
35
|
+
bottomRight?: QuadrantRegion;
|
|
36
|
+
}
|
|
37
|
+
/** A quadrant, as seen on screen */
|
|
38
|
+
export type QuadrantCorner = keyof QuadrantRegions;
|
|
39
|
+
/** Texts at the four ends of the dividers, inside the plot */
|
|
40
|
+
export interface QuadrantAxisLabels {
|
|
41
|
+
top?: string;
|
|
42
|
+
bottom?: string;
|
|
43
|
+
left?: string;
|
|
44
|
+
right?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Settings of a quadrant matrix (the props of QuadrantChart) */
|
|
47
|
+
export interface QuadrantConfig {
|
|
48
|
+
/** Points to place */
|
|
49
|
+
points: readonly QuadrantPoint[];
|
|
50
|
+
/**
|
|
51
|
+
* Range of the horizontal axis
|
|
52
|
+
* @default [0, 10]
|
|
53
|
+
*/
|
|
54
|
+
xDomain?: [number, number];
|
|
55
|
+
/**
|
|
56
|
+
* Range of the vertical axis
|
|
57
|
+
* @default [0, 10]
|
|
58
|
+
*/
|
|
59
|
+
yDomain?: [number, number];
|
|
60
|
+
/** X value of the vertical divider (the middle of `xDomain` by default) */
|
|
61
|
+
xSplit?: number;
|
|
62
|
+
/** Y value of the horizontal divider (the middle of `yDomain` by default) */
|
|
63
|
+
ySplit?: number;
|
|
64
|
+
/** Titles and colors of the quadrants */
|
|
65
|
+
quadrants?: QuadrantRegions;
|
|
66
|
+
/** Title of the horizontal axis */
|
|
67
|
+
xLabel?: string;
|
|
68
|
+
/** Title of the vertical axis */
|
|
69
|
+
yLabel?: string;
|
|
70
|
+
/** Texts at the ends of the dividers, drawn inside the plot (e.g. "Important" at the top) */
|
|
71
|
+
axisLabels?: QuadrantAxisLabels;
|
|
72
|
+
/**
|
|
73
|
+
* Shows the numeric ticks of the axes; `false` keeps only the matrix
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
76
|
+
showTicks?: boolean;
|
|
77
|
+
/** Reverses the horizontal axis (e.g. "urgent" on the left) */
|
|
78
|
+
reverseX?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Draws the labels next to the dots (overlapping labels are skipped)
|
|
81
|
+
* @default true
|
|
82
|
+
*/
|
|
83
|
+
showLabels?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Dot diameter in pixels
|
|
86
|
+
* @default 12
|
|
87
|
+
*/
|
|
88
|
+
pointSize?: number;
|
|
89
|
+
/** Name of the points in the tooltip */
|
|
90
|
+
name?: string;
|
|
91
|
+
/** Lets the user drag the dots (`drag` / `drop` events) */
|
|
92
|
+
draggable?: boolean;
|
|
93
|
+
}
|
|
94
|
+
export declare const DEFAULT_QUADRANT_COLORS: Required<Record<QuadrantCorner, string>>;
|
|
95
|
+
/** Quadrant of a data position, as seen on screen */
|
|
96
|
+
export declare const quadrantOf: (config: Pick<QuadrantConfig, "xDomain" | "yDomain" | "xSplit" | "ySplit" | "reverseX">, x: number, y: number) => QuadrantCorner;
|
|
97
|
+
/** Center of a quadrant in data coordinates */
|
|
98
|
+
export declare const quadrantCenter: (config: Pick<QuadrantConfig, "xDomain" | "yDomain" | "xSplit" | "ySplit" | "reverseX">, corner: QuadrantCorner) => {
|
|
99
|
+
x: number;
|
|
100
|
+
y: number;
|
|
101
|
+
};
|
|
102
|
+
/** Engine options of a quadrant matrix */
|
|
103
|
+
export declare const quadrantChartOptions: (config: QuadrantConfig, base?: Omit<ChartOptions, "series">) => ChartOptions;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ChartOptions, ChartSeries, ChartSeriesType } from './types.js';
|
|
2
|
+
/** Gives the series without a `type` the type of the component */
|
|
3
|
+
export declare const withSeriesType: (series: readonly ChartSeries[], type: ChartSeriesType, stack?: string) => ChartSeries[];
|
|
4
|
+
/** Series of a LineChart (`area` fills them) */
|
|
5
|
+
export declare const lineSeries: (series: readonly ChartSeries[], area?: boolean) => ChartSeries[];
|
|
6
|
+
/** Series of a BarChart (`stacked` stacks them) */
|
|
7
|
+
export declare const barSeries: (series: readonly ChartSeries[], stacked?: boolean) => ChartSeries[];
|
|
8
|
+
/** Series of a ScatterChart */
|
|
9
|
+
export declare const scatterSeries: (series: readonly ChartSeries[]) => ChartSeries[];
|
|
10
|
+
/** A point of a QuadrantChart */
|
|
11
|
+
export interface QuadrantPoint {
|
|
12
|
+
/** Position on the horizontal axis */
|
|
13
|
+
x: number;
|
|
14
|
+
/** Position on the vertical axis */
|
|
15
|
+
y: number;
|
|
16
|
+
/** Text drawn next to the dot and shown in the tooltip */
|
|
17
|
+
label?: string;
|
|
18
|
+
/** Dot color (any CSS color); the color of its quadrant by default */
|
|
19
|
+
color?: string;
|
|
20
|
+
/** Dot diameter in pixels */
|
|
21
|
+
size?: number;
|
|
22
|
+
}
|
|
23
|
+
/** Title and color of a quadrant */
|
|
24
|
+
export interface QuadrantRegion {
|
|
25
|
+
/** Title drawn in the outer corner of the quadrant */
|
|
26
|
+
label?: string;
|
|
27
|
+
/** Background tint and default dot color (any CSS color) */
|
|
28
|
+
color?: string;
|
|
29
|
+
}
|
|
30
|
+
/** The four quadrants of a QuadrantChart */
|
|
31
|
+
export interface QuadrantRegions {
|
|
32
|
+
topLeft?: QuadrantRegion;
|
|
33
|
+
topRight?: QuadrantRegion;
|
|
34
|
+
bottomLeft?: QuadrantRegion;
|
|
35
|
+
bottomRight?: QuadrantRegion;
|
|
36
|
+
}
|
|
37
|
+
/** A quadrant, as seen on screen */
|
|
38
|
+
export type QuadrantCorner = keyof QuadrantRegions;
|
|
39
|
+
/** Texts at the four ends of the dividers, inside the plot */
|
|
40
|
+
export interface QuadrantAxisLabels {
|
|
41
|
+
top?: string;
|
|
42
|
+
bottom?: string;
|
|
43
|
+
left?: string;
|
|
44
|
+
right?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Settings of a quadrant matrix (the props of QuadrantChart) */
|
|
47
|
+
export interface QuadrantConfig {
|
|
48
|
+
/** Points to place */
|
|
49
|
+
points: readonly QuadrantPoint[];
|
|
50
|
+
/**
|
|
51
|
+
* Range of the horizontal axis
|
|
52
|
+
* @default [0, 10]
|
|
53
|
+
*/
|
|
54
|
+
xDomain?: [number, number];
|
|
55
|
+
/**
|
|
56
|
+
* Range of the vertical axis
|
|
57
|
+
* @default [0, 10]
|
|
58
|
+
*/
|
|
59
|
+
yDomain?: [number, number];
|
|
60
|
+
/** X value of the vertical divider (the middle of `xDomain` by default) */
|
|
61
|
+
xSplit?: number;
|
|
62
|
+
/** Y value of the horizontal divider (the middle of `yDomain` by default) */
|
|
63
|
+
ySplit?: number;
|
|
64
|
+
/** Titles and colors of the quadrants */
|
|
65
|
+
quadrants?: QuadrantRegions;
|
|
66
|
+
/** Title of the horizontal axis */
|
|
67
|
+
xLabel?: string;
|
|
68
|
+
/** Title of the vertical axis */
|
|
69
|
+
yLabel?: string;
|
|
70
|
+
/** Texts at the ends of the dividers, drawn inside the plot (e.g. "Important" at the top) */
|
|
71
|
+
axisLabels?: QuadrantAxisLabels;
|
|
72
|
+
/**
|
|
73
|
+
* Shows the numeric ticks of the axes; `false` keeps only the matrix
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
76
|
+
showTicks?: boolean;
|
|
77
|
+
/** Reverses the horizontal axis (e.g. "urgent" on the left) */
|
|
78
|
+
reverseX?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Draws the labels next to the dots (overlapping labels are skipped)
|
|
81
|
+
* @default true
|
|
82
|
+
*/
|
|
83
|
+
showLabels?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Dot diameter in pixels
|
|
86
|
+
* @default 12
|
|
87
|
+
*/
|
|
88
|
+
pointSize?: number;
|
|
89
|
+
/** Name of the points in the tooltip */
|
|
90
|
+
name?: string;
|
|
91
|
+
/** Lets the user drag the dots (`drag` / `drop` events) */
|
|
92
|
+
draggable?: boolean;
|
|
93
|
+
}
|
|
94
|
+
export declare const DEFAULT_QUADRANT_COLORS: Required<Record<QuadrantCorner, string>>;
|
|
95
|
+
/** Quadrant of a data position, as seen on screen */
|
|
96
|
+
export declare const quadrantOf: (config: Pick<QuadrantConfig, "xDomain" | "yDomain" | "xSplit" | "ySplit" | "reverseX">, x: number, y: number) => QuadrantCorner;
|
|
97
|
+
/** Center of a quadrant in data coordinates */
|
|
98
|
+
export declare const quadrantCenter: (config: Pick<QuadrantConfig, "xDomain" | "yDomain" | "xSplit" | "ySplit" | "reverseX">, corner: QuadrantCorner) => {
|
|
99
|
+
x: number;
|
|
100
|
+
y: number;
|
|
101
|
+
};
|
|
102
|
+
/** Engine options of a quadrant matrix */
|
|
103
|
+
export declare const quadrantChartOptions: (config: QuadrantConfig, base?: Omit<ChartOptions, "series">) => ChartOptions;
|