@vielzeug/prism 2.2.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -40
- package/dist/_dev.cjs +1 -1
- package/dist/_dev.cjs.map +1 -1
- package/dist/_dev.js +1 -2
- package/dist/_dev.js.map +1 -1
- package/dist/axes/axis.cjs +1 -1
- package/dist/axes/axis.cjs.map +1 -1
- package/dist/axes/axis.d.ts +1 -0
- package/dist/axes/axis.d.ts.map +1 -1
- package/dist/axes/axis.js +15 -11
- package/dist/axes/axis.js.map +1 -1
- package/dist/charts/area/area-chart.cjs +1 -1
- package/dist/charts/area/area-chart.cjs.map +1 -1
- package/dist/charts/area/area-chart.d.ts +2 -2
- package/dist/charts/area/area-chart.d.ts.map +1 -1
- package/dist/charts/area/area-chart.js +31 -31
- package/dist/charts/area/area-chart.js.map +1 -1
- package/dist/charts/area/area-renderer.cjs +1 -1
- package/dist/charts/area/area-renderer.cjs.map +1 -1
- package/dist/charts/area/area-renderer.d.ts +2 -2
- package/dist/charts/area/area-renderer.d.ts.map +1 -1
- package/dist/charts/area/area-renderer.js +14 -14
- package/dist/charts/area/area-renderer.js.map +1 -1
- package/dist/charts/bar/bar-chart.cjs +1 -1
- package/dist/charts/bar/bar-chart.cjs.map +1 -1
- package/dist/charts/bar/bar-chart.d.ts +2 -2
- package/dist/charts/bar/bar-chart.d.ts.map +1 -1
- package/dist/charts/bar/bar-chart.js +58 -56
- package/dist/charts/bar/bar-chart.js.map +1 -1
- package/dist/charts/bar/bar-hit-test.cjs +1 -1
- package/dist/charts/bar/bar-hit-test.cjs.map +1 -1
- package/dist/charts/bar/bar-hit-test.js +5 -4
- package/dist/charts/bar/bar-hit-test.js.map +1 -1
- package/dist/charts/bar/bar-renderer.cjs +1 -1
- package/dist/charts/bar/bar-renderer.js +24 -24
- package/dist/charts/line/line-chart.cjs +1 -1
- package/dist/charts/line/line-chart.cjs.map +1 -1
- package/dist/charts/line/line-chart.d.ts +2 -2
- package/dist/charts/line/line-chart.d.ts.map +1 -1
- package/dist/charts/line/line-chart.js +31 -31
- package/dist/charts/line/line-chart.js.map +1 -1
- package/dist/charts/line/line-renderer.cjs +1 -1
- package/dist/charts/line/line-renderer.cjs.map +1 -1
- package/dist/charts/line/line-renderer.d.ts +2 -2
- package/dist/charts/line/line-renderer.d.ts.map +1 -1
- package/dist/charts/line/line-renderer.js +34 -34
- package/dist/charts/line/line-renderer.js.map +1 -1
- package/dist/charts/pie/pie-chart.cjs +1 -1
- package/dist/charts/pie/pie-chart.cjs.map +1 -1
- package/dist/charts/pie/pie-chart.d.ts +2 -2
- package/dist/charts/pie/pie-chart.d.ts.map +1 -1
- package/dist/charts/pie/pie-chart.js +118 -109
- package/dist/charts/pie/pie-chart.js.map +1 -1
- package/dist/charts/sparkline/sparkline.cjs +1 -1
- package/dist/charts/sparkline/sparkline.cjs.map +1 -1
- package/dist/charts/sparkline/sparkline.d.ts +2 -2
- package/dist/charts/sparkline/sparkline.d.ts.map +1 -1
- package/dist/charts/sparkline/sparkline.js +119 -117
- package/dist/charts/sparkline/sparkline.js.map +1 -1
- package/dist/core/chart-base.cjs +1 -1
- package/dist/core/chart-base.cjs.map +1 -1
- package/dist/core/chart-base.d.ts +2 -4
- package/dist/core/chart-base.d.ts.map +1 -1
- package/dist/core/chart-base.js +21 -30
- package/dist/core/chart-base.js.map +1 -1
- package/dist/core/chart-scaffold.cjs +1 -1
- package/dist/core/chart-scaffold.cjs.map +1 -1
- package/dist/core/chart-scaffold.d.ts +9 -10
- package/dist/core/chart-scaffold.d.ts.map +1 -1
- package/dist/core/chart-scaffold.js +31 -43
- package/dist/core/chart-scaffold.js.map +1 -1
- package/dist/core/layout.cjs +1 -1
- package/dist/core/layout.cjs.map +1 -1
- package/dist/core/layout.js +1 -1
- package/dist/core/layout.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -12
- package/dist/interaction/legend.cjs +1 -1
- package/dist/interaction/legend.cjs.map +1 -1
- package/dist/interaction/legend.js +1 -1
- package/dist/interaction/legend.js.map +1 -1
- package/dist/interaction/tooltip.cjs +1 -1
- package/dist/interaction/tooltip.cjs.map +1 -1
- package/dist/interaction/tooltip.d.ts.map +1 -1
- package/dist/interaction/tooltip.js +29 -29
- package/dist/interaction/tooltip.js.map +1 -1
- package/dist/prism.cjs +1 -1
- package/dist/prism.cjs.map +1 -1
- package/dist/prism.iife.js +1 -1
- package/dist/prism.iife.js.map +1 -1
- package/dist/prism.js +1 -1
- package/dist/prism.js.map +1 -1
- package/dist/types.d.ts +24 -48
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -9
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createSvgElement as e, setAttributes as t } from "../../svg/element.js";
|
|
2
|
+
import { animate as n } from "../../animation/transition.js";
|
|
3
3
|
//#region src/charts/bar/bar-renderer.ts
|
|
4
4
|
var r = /* @__PURE__ */ new WeakMap();
|
|
5
5
|
function i(i, a, o, s, c, l) {
|
|
@@ -8,17 +8,17 @@ function i(i, a, o, s, c, l) {
|
|
|
8
8
|
e && i.removeChild(e);
|
|
9
9
|
}
|
|
10
10
|
let u = o.bandwidth(), d = l.stacked ? u : u / l.seriesCount, f = l.stacked ? 0 : d * l.seriesIndex, p = l.horizontal ?? !1, m = [], h = [];
|
|
11
|
-
for (let
|
|
12
|
-
let r = a[
|
|
13
|
-
if (v || (v =
|
|
14
|
-
let e = Math.max(0, Math.abs(g - _)),
|
|
15
|
-
|
|
11
|
+
for (let n = 0; n < a.length; n++) {
|
|
12
|
+
let r = a[n], u = o.map(r.key) + f, g = l.baselineYs ? l.baselineYs[n] : c, _ = s.map(r.y), v = i.children[n], y = !v;
|
|
13
|
+
if (v || (v = e("rect", { class: "prism-bar" }), i.appendChild(v)), v.style.display = r.present ? "" : "none", p) {
|
|
14
|
+
let e = Math.max(0, Math.abs(g - _)), n = Math.min(_, g);
|
|
15
|
+
t(v, {
|
|
16
16
|
fill: l.color,
|
|
17
17
|
height: Math.max(0, d - 1),
|
|
18
18
|
rx: l.borderRadius,
|
|
19
19
|
ry: l.borderRadius,
|
|
20
20
|
y: u
|
|
21
|
-
}), l.transition ? y ? (
|
|
21
|
+
}), l.transition ? y ? (t(v, {
|
|
22
22
|
width: 0,
|
|
23
23
|
x: g
|
|
24
24
|
}), m.push({
|
|
@@ -29,7 +29,7 @@ function i(i, a, o, s, c, l) {
|
|
|
29
29
|
},
|
|
30
30
|
x: {
|
|
31
31
|
from: g,
|
|
32
|
-
to:
|
|
32
|
+
to: n
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
el: v
|
|
@@ -40,24 +40,24 @@ function i(i, a, o, s, c, l) {
|
|
|
40
40
|
to: e
|
|
41
41
|
},
|
|
42
42
|
x: {
|
|
43
|
-
from: Number(v.getAttribute("x") ??
|
|
44
|
-
to:
|
|
43
|
+
from: Number(v.getAttribute("x") ?? n),
|
|
44
|
+
to: n
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
el: v
|
|
48
|
-
}) :
|
|
48
|
+
}) : t(v, {
|
|
49
49
|
width: e,
|
|
50
|
-
x:
|
|
50
|
+
x: n
|
|
51
51
|
});
|
|
52
52
|
} else {
|
|
53
|
-
let e = Math.max(0, Math.abs(g - _)),
|
|
54
|
-
|
|
53
|
+
let e = Math.max(0, Math.abs(g - _)), n = Math.min(_, g);
|
|
54
|
+
t(v, {
|
|
55
55
|
fill: l.color,
|
|
56
56
|
rx: l.borderRadius,
|
|
57
57
|
ry: l.borderRadius,
|
|
58
58
|
width: Math.max(0, d - 1),
|
|
59
59
|
x: u
|
|
60
|
-
}), l.transition ? y ? (
|
|
60
|
+
}), l.transition ? y ? (t(v, {
|
|
61
61
|
height: 0,
|
|
62
62
|
y: g
|
|
63
63
|
}), m.push({
|
|
@@ -68,7 +68,7 @@ function i(i, a, o, s, c, l) {
|
|
|
68
68
|
},
|
|
69
69
|
y: {
|
|
70
70
|
from: g,
|
|
71
|
-
to:
|
|
71
|
+
to: n
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
el: v
|
|
@@ -79,25 +79,25 @@ function i(i, a, o, s, c, l) {
|
|
|
79
79
|
to: e
|
|
80
80
|
},
|
|
81
81
|
y: {
|
|
82
|
-
from: Number(v.getAttribute("y") ??
|
|
83
|
-
to:
|
|
82
|
+
from: Number(v.getAttribute("y") ?? n),
|
|
83
|
+
to: n
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
el: v
|
|
87
|
-
}) :
|
|
87
|
+
}) : t(v, {
|
|
88
88
|
height: e,
|
|
89
|
-
y:
|
|
89
|
+
y: n
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
if (l.transition) {
|
|
94
94
|
r.get(i)?.();
|
|
95
|
-
let
|
|
96
|
-
m.length > 0 &&
|
|
95
|
+
let e = [];
|
|
96
|
+
m.length > 0 && e.push(n(m, l.transition, void 0, l.disposalSignal)), h.length > 0 && e.push(n(h, {
|
|
97
97
|
...l.transition,
|
|
98
98
|
stagger: 0
|
|
99
99
|
}, void 0, l.disposalSignal)), r.set(i, () => {
|
|
100
|
-
for (let
|
|
100
|
+
for (let t of e) t();
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require("../../svg/element.cjs"),t=require("../../axes/axis.cjs"),n=require("../../axes/grid.cjs"),r=require("../../core/cartesian-scales.cjs"),i=require("../../core/layout.cjs"),a=require("../../core/chart-scaffold.cjs"),o=require("../../interaction/crosshair.cjs"),s=require("../../interaction/series-interaction.cjs"),c=require("../../theme/index.cjs"),l=require("./line-renderer.cjs");function u(u,d){let f=null,p=d.series;return a.createChartScaffold(u,d,u=>{let{groups:m,legend:h,tooltip:g}=u,_=u.dimensions,v=i.chartArea(_.width,_.height,_.margin),y=p.map(e=>e.data),b=y.flat().map(e=>e.key),x=y.flat().map(e=>e.value);if(b.length===0){a.clearCartesianDom(m,h,g,f);return}d.crosshair&&!f&&(f=o.createCrosshair(u.chartArea,d.crosshair));let S=r.buildXScale(b,v.width),C=r.buildYScale(x,v.height);for(d.yAxis?.grid&&n.renderGrid(m.grid,C,d.yAxis.grid,v.width,`horizontal`,t.resolveTickCount(d.yAxis,v.height,`left`)),d.xAxis?.grid&&n.renderGrid(m.grid,S,d.xAxis.grid,v.height,`vertical`,t.resolveTickCount(d.xAxis,v.width,`bottom`)),d.xAxis&&(t.positionAxis(m.xAxis,d.xAxis.position??`bottom`,v.width,v.height),t.renderAxis(m.xAxis,S,d.xAxis,v.width,`bottom`)),d.yAxis&&(t.positionAxis(m.yAxis,d.yAxis.position??`left`,v.width,v.height),t.renderAxis(m.yAxis,C,d.yAxis,v.height,`left`));m.series.children.length>p.length;)m.series.removeChild(m.series.lastChild);let w=[];for(let t=0;t<p.length;t++){let n=p[t],r=m.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-line-series`}),m.series.appendChild(r));let i=l.computePoints(y[t],S,C);w.push(i),l.renderLine(r,i,{color:c.seriesColor(t,n.color),curve:n.curve??`linear`,disposalSignal:u.disposalSignal,pointRadius:n.pointRadius??3,showPoints:n.showPoints??!1,strokeWidth:n.strokeWidth??2,transition:d.transition})}return h?.update(p.map((e,t)=>({color:c.seriesColor(t,e.color),name:e.name}))),g?.hide(),s.createSeriesInteraction({crosshair:f,dims:()=>u.dimensions,getData:()=>y,getPoints:()=>w,getSeriesList:()=>p,onClick:d.onClick,onHover:d.onHover,svg:u.svg,tooltip:g})},e=>{p=e})}exports.createLineChart=u;
|
|
2
2
|
//# sourceMappingURL=line-chart.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-chart.cjs","names":[],"sources":["../../../src/charts/line/line-chart.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"line-chart.cjs","names":[],"sources":["../../../src/charts/line/line-chart.ts"],"sourcesContent":["import { positionAxis, renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { buildXScale, buildYScale } from '../../core/cartesian-scales';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction } from '../../interaction/series-interaction';\nimport { createSvgElement } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { seriesColor } from '../../theme';\nimport type { ChartHandle, LineChartConfig, LineSeriesConfig } from '../../types';\nimport { computePoints, renderLine } from './line-renderer';\n\nexport function createLineChart(container: HTMLElement, config: LineChartConfig): ChartHandle<LineSeriesConfig[]> {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const allData = seriesList.map((series) => series.data);\n const allX = allData.flat().map((datum) => datum.key);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\n clearCartesianDom(groups, legend, tooltip, crosshair);\n\n return;\n }\n\n if (config.crosshair && !crosshair) {\n crosshair = createCrosshair(ctx.chartArea, config.crosshair);\n }\n\n const xScale = buildXScale(allX, area.width);\n const yScale = buildYScale(allY, area.height);\n\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n yScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n xScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n if (config.xAxis) {\n positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n }\n\n while (groups.series.children.length > seriesList.length) {\n groups.series.removeChild(groups.series.lastChild!);\n }\n\n const allPoints: Point[][] = [];\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-line-series' });\n groups.series.appendChild(group);\n }\n\n const points = computePoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderLine(group, points, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n pointRadius: series.pointRadius ?? 3,\n showPoints: series.showPoints ?? false,\n strokeWidth: series.strokeWidth ?? 2,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n return createSeriesInteraction({\n crosshair,\n dims: () => ctx.dimensions,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"6YAaA,SAAgB,EAAgB,EAAwB,EAA0D,CAChH,IAAI,EAAuD,KACvD,EAAa,EAAO,OAExB,OAAO,EAAA,oBACL,EACA,EACC,GAAQ,CACP,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAAU,EAAW,IAAK,GAAW,EAAO,IAAI,EAChD,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAU,EAAM,GAAG,EAC9C,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAM,EAAE,KAAK,EAE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AAU,KAAK,CAAM,EAErB,EAAA,WAAW,EAAO,EAAQ,CACxB,MAAO,EAAA,YAAY,EAAG,EAAO,KAAK,EAClC,MAAO,EAAO,OAAS,SACvB,eAAgB,EAAI,eACpB,YAAa,EAAO,aAAe,EACnC,WAAY,EAAO,YAAc,GACjC,YAAa,EAAO,aAAe,EACnC,WAAY,EAAO,UACrB,CAAC,CACH,CAKA,OAHA,GAAQ,OAAO,EAAW,KAAK,EAAG,KAAO,CAAE,MAAO,EAAA,YAAY,EAAG,EAAE,KAAK,EAAG,KAAM,EAAE,IAAK,EAAE,CAAC,EAC3F,GAAS,KAAK,EAEP,EAAA,wBAAwB,CAC7B,YACA,SAAY,EAAI,WAChB,YAAe,EACf,cAAiB,EACjB,kBAAqB,EACrB,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,IAAK,EAAI,IACT,SACF,CAAC,CACH,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ChartHandle, LineChartConfig } from '../../types';
|
|
2
|
-
export declare function createLineChart(container: HTMLElement, config: LineChartConfig): ChartHandle
|
|
1
|
+
import type { ChartHandle, LineChartConfig, LineSeriesConfig } from '../../types';
|
|
2
|
+
export declare function createLineChart(container: HTMLElement, config: LineChartConfig): ChartHandle<LineSeriesConfig[]>;
|
|
3
3
|
//# sourceMappingURL=line-chart.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-chart.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"line-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-chart.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGlF,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,GAAG,WAAW,CAAC,gBAAgB,EAAE,CAAC,CA6GhH"}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import "../../_dev.js";
|
|
2
1
|
import { createSvgElement as e } from "../../svg/element.js";
|
|
3
|
-
import {
|
|
4
|
-
import { renderGrid as
|
|
5
|
-
import { buildXScale as
|
|
6
|
-
import { chartArea as
|
|
7
|
-
import { clearCartesianDom as
|
|
8
|
-
import { createCrosshair as
|
|
9
|
-
import { createSeriesInteraction as
|
|
10
|
-
import { seriesColor as
|
|
11
|
-
import { computePoints as
|
|
12
|
-
import { isReactive as m } from "@vielzeug/ripple";
|
|
2
|
+
import { positionAxis as t, renderAxis as n, resolveTickCount as r } from "../../axes/axis.js";
|
|
3
|
+
import { renderGrid as i } from "../../axes/grid.js";
|
|
4
|
+
import { buildXScale as a, buildYScale as o } from "../../core/cartesian-scales.js";
|
|
5
|
+
import { chartArea as s } from "../../core/layout.js";
|
|
6
|
+
import { clearCartesianDom as c, createChartScaffold as l } from "../../core/chart-scaffold.js";
|
|
7
|
+
import { createCrosshair as u } from "../../interaction/crosshair.js";
|
|
8
|
+
import { createSeriesInteraction as d } from "../../interaction/series-interaction.js";
|
|
9
|
+
import { seriesColor as f } from "../../theme/index.js";
|
|
10
|
+
import { computePoints as p, renderLine as m } from "./line-renderer.js";
|
|
13
11
|
//#region src/charts/line/line-chart.ts
|
|
14
12
|
function h(h, g) {
|
|
15
|
-
let _ = null;
|
|
16
|
-
return
|
|
17
|
-
let { groups: h, legend:
|
|
13
|
+
let _ = null, v = g.series;
|
|
14
|
+
return l(h, g, (l) => {
|
|
15
|
+
let { groups: h, legend: y, tooltip: b } = l, x = l.dimensions, S = s(x.width, x.height, x.margin), C = v.map((e) => e.data), w = C.flat().map((e) => e.key), T = C.flat().map((e) => e.value);
|
|
18
16
|
if (w.length === 0) {
|
|
19
|
-
|
|
17
|
+
c(h, y, b, _);
|
|
20
18
|
return;
|
|
21
19
|
}
|
|
22
|
-
g.crosshair && !_ && (_ = l
|
|
23
|
-
let E =
|
|
24
|
-
for (g.yAxis?.grid &&
|
|
20
|
+
g.crosshair && !_ && (_ = u(l.chartArea, g.crosshair));
|
|
21
|
+
let E = a(w, S.width), D = o(T, S.height);
|
|
22
|
+
for (g.yAxis?.grid && i(h.grid, D, g.yAxis.grid, S.width, "horizontal", r(g.yAxis, S.height, "left")), g.xAxis?.grid && i(h.grid, E, g.xAxis.grid, S.height, "vertical", r(g.xAxis, S.width, "bottom")), g.xAxis && (t(h.xAxis, g.xAxis.position ?? "bottom", S.width, S.height), n(h.xAxis, E, g.xAxis, S.width, "bottom")), g.yAxis && (t(h.yAxis, g.yAxis.position ?? "left", S.width, S.height), n(h.yAxis, D, g.yAxis, S.height, "left")); h.series.children.length > v.length;) h.series.removeChild(h.series.lastChild);
|
|
25
23
|
let O = [];
|
|
26
|
-
for (let t = 0; t <
|
|
27
|
-
let n =
|
|
24
|
+
for (let t = 0; t < v.length; t++) {
|
|
25
|
+
let n = v[t], r = h.series.children[t];
|
|
28
26
|
r || (r = e("g", { class: "prism-line-series" }), h.series.appendChild(r));
|
|
29
|
-
let i =
|
|
30
|
-
O.push(i),
|
|
31
|
-
color:
|
|
27
|
+
let i = p(C[t], E, D);
|
|
28
|
+
O.push(i), m(r, i, {
|
|
29
|
+
color: f(t, n.color),
|
|
32
30
|
curve: n.curve ?? "linear",
|
|
33
|
-
disposalSignal:
|
|
31
|
+
disposalSignal: l.disposalSignal,
|
|
34
32
|
pointRadius: n.pointRadius ?? 3,
|
|
35
33
|
showPoints: n.showPoints ?? !1,
|
|
36
34
|
strokeWidth: n.strokeWidth ?? 2,
|
|
37
35
|
transition: g.transition
|
|
38
36
|
});
|
|
39
37
|
}
|
|
40
|
-
return
|
|
41
|
-
color:
|
|
38
|
+
return y?.update(v.map((e, t) => ({
|
|
39
|
+
color: f(t, e.color),
|
|
42
40
|
name: e.name
|
|
43
|
-
}))),
|
|
41
|
+
}))), b?.hide(), d({
|
|
44
42
|
crosshair: _,
|
|
45
|
-
dims: () =>
|
|
43
|
+
dims: () => l.dimensions,
|
|
46
44
|
getData: () => C,
|
|
47
45
|
getPoints: () => O,
|
|
48
|
-
getSeriesList: () =>
|
|
46
|
+
getSeriesList: () => v,
|
|
49
47
|
onClick: g.onClick,
|
|
50
48
|
onHover: g.onHover,
|
|
51
|
-
svg:
|
|
52
|
-
tooltip:
|
|
49
|
+
svg: l.svg,
|
|
50
|
+
tooltip: b
|
|
53
51
|
});
|
|
52
|
+
}, (e) => {
|
|
53
|
+
v = e;
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-chart.js","names":[],"sources":["../../../src/charts/line/line-chart.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"line-chart.js","names":[],"sources":["../../../src/charts/line/line-chart.ts"],"sourcesContent":["import { positionAxis, renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { buildXScale, buildYScale } from '../../core/cartesian-scales';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction } from '../../interaction/series-interaction';\nimport { createSvgElement } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { seriesColor } from '../../theme';\nimport type { ChartHandle, LineChartConfig, LineSeriesConfig } from '../../types';\nimport { computePoints, renderLine } from './line-renderer';\n\nexport function createLineChart(container: HTMLElement, config: LineChartConfig): ChartHandle<LineSeriesConfig[]> {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const allData = seriesList.map((series) => series.data);\n const allX = allData.flat().map((datum) => datum.key);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\n clearCartesianDom(groups, legend, tooltip, crosshair);\n\n return;\n }\n\n if (config.crosshair && !crosshair) {\n crosshair = createCrosshair(ctx.chartArea, config.crosshair);\n }\n\n const xScale = buildXScale(allX, area.width);\n const yScale = buildYScale(allY, area.height);\n\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n yScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n xScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n if (config.xAxis) {\n positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n }\n\n while (groups.series.children.length > seriesList.length) {\n groups.series.removeChild(groups.series.lastChild!);\n }\n\n const allPoints: Point[][] = [];\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-line-series' });\n groups.series.appendChild(group);\n }\n\n const points = computePoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderLine(group, points, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n pointRadius: series.pointRadius ?? 3,\n showPoints: series.showPoints ?? false,\n strokeWidth: series.strokeWidth ?? 2,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n return createSeriesInteraction({\n crosshair,\n dims: () => ctx.dimensions,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n on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AO,GAAQ,EAAO,OAAO,EAAK,QAAQ,MAAM,IAG7D,EAAO,OAAO,SAAS,SAAS,EAAW,SAChD,EAAO,OAAO,YAAY,EAAO,OAAO,SAAU;EAGpD,IAAM,IAAuB,CAAC;EAE9B,KAAK,IAAI,IAAI,GAAG,IAAI,EAAW,QAAQ,KAAK;GAC1C,IAAM,IAAS,EAAW,IACtB,IAAQ,EAAO,OAAO,SAAS;GAEnC,AAAK,MACH,IAAQ,EAAiB,KAAK,EAAE,OAAO,oBAAoB,CAAC,GAC5D,EAAO,OAAO,YAAY,CAAK;GAGjC,IAAM,IAAS,EAAc,EAAQ,IAAI,GAAQ,CAAM;GAIvD,AAFA,EAAU,KAAK,CAAM,GAErB,EAAW,GAAO,GAAQ;IACxB,OAAO,EAAY,GAAG,EAAO,KAAK;IAClC,OAAO,EAAO,SAAS;IACvB,gBAAgB,EAAI;IACpB,aAAa,EAAO,eAAe;IACnC,YAAY,EAAO,cAAc;IACjC,aAAa,EAAO,eAAe;IACnC,YAAY,EAAO;GACrB,CAAC;EACH;EAKA,OAHA,GAAQ,OAAO,EAAW,KAAK,GAAG,OAAO;GAAE,OAAO,EAAY,GAAG,EAAE,KAAK;GAAG,MAAM,EAAE;EAAK,EAAE,CAAC,GAC3F,GAAS,KAAK,GAEP,EAAwB;GAC7B;GACA,YAAY,EAAI;GAChB,eAAe;GACf,iBAAiB;GACjB,qBAAqB;GACrB,SAAS,EAAO;GAChB,SAAS,EAAO;GAChB,KAAK,EAAI;GACT;EACF,CAAC;CACH,IACC,MAAS;EACR,IAAa;CACf,CACF;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../../
|
|
1
|
+
require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../animation/easing.cjs"),n=require("../../animation/motion.cjs"),r=require("../../animation/tween.cjs"),i=require("../../svg/path.cjs");var a=new WeakMap;function o(e,t){return t===`monotone`?i.monotonePath(e):t===`step`?i.stepPath(e):i.linePath(e)}function s(i,s,c){let l=n.resolveMotion(c.transition,0),u=l.duration,d=t.resolveEasing(l.easing),f=i.querySelector(`.prism-line-path`);f||(f=e.createSvgElement(`path`,{class:`prism-line-path`,fill:`none`}),i.appendChild(f)),e.setAttributes(f,{stroke:c.color,"stroke-width":c.strokeWidth});let p=i.querySelector(`.prism-line-dots`);if(c.showPoints?p||(p=e.createSvgElement(`g`,{class:`prism-line-dots`}),i.appendChild(p)):p&&=(p.remove(),null),u===0){if(e.setAttributes(f,{d:o(s,c.curve)}),p){for(;p.children.length>s.length;)p.removeChild(p.lastChild);for(let t=0;t<s.length;t++){let n=p.children[t];n||(n=e.createSvgElement(`circle`,{class:`prism-line-dot`}),p.appendChild(n)),e.setAttributes(n,{cx:s[t].x,cy:s[t].y,fill:c.color,r:c.pointRadius})}}return}a.get(i)?.();let m=!!f.getAttribute(`d`),h=[],g=null;if(p){let t=p.children.length;for(let e=0;e<t;e++){let t=p.children[e],n={x:Number(t.getAttribute(`cx`)),y:Number(t.getAttribute(`cy`))};h.push(n),g=n}for(;p.children.length>s.length;)p.removeChild(p.lastChild);for(let t=p.children.length;t<s.length;t++){let n=e.createSvgElement(`circle`,{class:`prism-line-dot`});e.setAttributes(n,{cx:s[t].x,cy:s[t].y,fill:c.color,r:c.pointRadius}),p.appendChild(n)}}for(let e=h.length;e<s.length;e++)h.push(g??s[e]);let _=null;function v(t){if(c.disposalSignal?.aborted){a.delete(i);return}_===null&&(_=t);let n=Math.min(1,(t-_)/u),l=d(n),m=s.map((e,t)=>{let n=h[t]??e;return{x:r.tweenNumber(n.x,e.x,l),y:r.tweenNumber(n.y,e.y,l)}});if(e.setAttributes(f,{d:o(m,c.curve)}),p)for(let t=0;t<s.length;t++){let n=p.children[t];n&&e.setAttributes(n,{cx:m[t].x,cy:m[t].y})}if(n<1){let e=requestAnimationFrame(v);a.set(i,()=>cancelAnimationFrame(e))}else a.delete(i)}if(!m)e.setAttributes(f,{d:o(s,c.curve)});else{let e=requestAnimationFrame(v);a.set(i,()=>cancelAnimationFrame(e))}}function c(e,t,n){return e.some(e=>e.key==null)||e.some(e=>typeof e.key==`string`),e.map(e=>({x:t.map(e.key),y:n.map(e.value)}))}exports.computePoints=c,exports.renderLine=s;
|
|
2
2
|
//# sourceMappingURL=line-renderer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-renderer.cjs","names":[],"sources":["../../../src/charts/line/line-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { linePath, monotonePath, stepPath } from '../../svg/path';\nimport type {
|
|
1
|
+
{"version":3,"file":"line-renderer.cjs","names":[],"sources":["../../../src/charts/line/line-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionConfig } from '../../types';\n\nexport interface LineRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed — stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n pointRadius: number;\n showPoints: boolean;\n strokeWidth: number;\n transition?: TransitionConfig;\n}\n\nconst activeAnimations = new WeakMap<SVGGElement, () => void>();\n\nfunction buildPath(pts: Point[], curve: LineRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let path = parent.querySelector<SVGPathElement>('.prism-line-path');\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n parent.appendChild(path);\n }\n\n setAttributes(path, { stroke: options.color, 'stroke-width': options.strokeWidth });\n\n let dotsGroup = parent.querySelector<SVGGElement>('.prism-line-dots');\n\n if (options.showPoints) {\n if (!dotsGroup) {\n dotsGroup = createSvgElement('g', { class: 'prism-line-dots' });\n parent.appendChild(dotsGroup);\n }\n } else if (dotsGroup) {\n dotsGroup.remove();\n dotsGroup = null;\n }\n\n if (dur === 0) {\n setAttributes(path, { d: buildPath(points, options.curve) });\n\n if (dotsGroup) {\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = 0; i < points.length; i++) {\n let c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (!c) {\n c = createSvgElement('circle', { class: 'prism-line-dot' });\n dotsGroup.appendChild(c);\n }\n\n setAttributes(c, { cx: points[i].x, cy: points[i].y, fill: options.color, r: options.pointRadius });\n }\n }\n\n return;\n }\n\n activeAnimations.get(parent)?.();\n\n const hasExisting = !!path.getAttribute('d');\n\n const fromPts: Point[] = [];\n let lastKnown: Point | null = null;\n\n if (dotsGroup) {\n const existingCount = dotsGroup.children.length;\n\n for (let i = 0; i < existingCount; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement;\n const pt = { x: Number(c.getAttribute('cx')), y: Number(c.getAttribute('cy')) };\n\n fromPts.push(pt);\n lastKnown = pt;\n }\n\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = dotsGroup.children.length; i < points.length; i++) {\n const c = createSvgElement('circle', { class: 'prism-line-dot' });\n\n setAttributes(c, { cx: points[i].x, cy: points[i].y, fill: options.color, r: options.pointRadius });\n dotsGroup.appendChild(c);\n }\n }\n\n for (let i = fromPts.length; i < points.length; i++) {\n fromPts.push(lastKnown ?? points[i]);\n }\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAnimations.delete(parent);\n\n return;\n }\n\n if (startTime === null) startTime = ts;\n\n const t = Math.min(1, (ts - startTime) / dur);\n const e = easing(t);\n const interpolated: Point[] = points.map((to, i) => {\n const from = fromPts[i] ?? to;\n\n return { x: tweenNumber(from.x, to.x, e), y: tweenNumber(from.y, to.y, e) };\n });\n\n setAttributes(path!, { d: buildPath(interpolated, options.curve) });\n\n if (dotsGroup) {\n for (let i = 0; i < points.length; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (c) setAttributes(c, { cx: interpolated[i].x, cy: interpolated[i].y });\n }\n }\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAnimations.delete(parent);\n }\n }\n\n if (!hasExisting) {\n setAttributes(path, { d: buildPath(points, options.curve) });\n } else {\n const id = requestAnimationFrame(frame);\n\n activeAnimations.set(parent, () => cancelAnimationFrame(id));\n }\n}\n\nexport function computePoints(data: ContinuousDatum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computePoints: datum.key is null or undefined — data must use the Datum shape { key, value }. Did you pass { x, y } instead?',\n );\n } else if (data.some((d) => typeof d.key === 'string')) {\n warn('computePoints: string keys are not supported for line/area charts — use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":"0NAoBA,IAAM,EAAmB,IAAI,QAE7B,SAAS,EAAU,EAAc,EAA2C,CAC1E,OAAO,IAAU,WAAa,EAAA,aAAa,CAAG,EAAI,IAAU,OAAS,EAAA,SAAS,CAAG,EAAI,EAAA,SAAS,CAAG,CACnG,CAEA,SAAgB,EAAW,EAAqB,EAAiB,EAAkC,CACjG,IAAM,EAAS,EAAA,cAAc,EAAQ,WAAY,CAAC,EAC5C,EAAM,EAAO,SACb,EAAS,EA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GAAI,EAAa,EAAE,CAAC,CAAE,CAAC,CAC1E,CAGF,GAAI,EAAI,EAAG,CACT,IAAM,EAAK,sBAAsB,CAAK,EAEtC,EAAiB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CAC7D,MACE,EAAiB,OAAO,CAAM,CAElC,CAEA,GAAI,CAAC,EACH,EAAA,cAAc,EAAM,CAAE,EAAG,EAAU,EAAQ,EAAQ,KAAK,CAAE,CAAC,MACtD,CACL,IAAM,EAAK,sBAAsB,CAAK,EAEtC,EAAiB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CAC7D,CACF,CAEA,SAAgB,EAAc,EAAyB,EAA8B,EAAgC,CASnH,OARI,EAAK,KAAM,GAAM,EAAE,KAAO,IAAI,GAIvB,EAAK,KAAM,GAAM,OAAO,EAAE,KAAQ,QAAQ,EAI9C,EAAK,IAAK,IAAO,CACtB,EAAG,EAAO,IAAI,EAAE,GAAoB,EACpC,EAAG,EAAO,IAAI,EAAE,KAAK,CACvB,EAAE,CACJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Point } from '../../svg/path';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ContinuousDatum, Scale, TransitionConfig } from '../../types';
|
|
3
3
|
export interface LineRenderOptions {
|
|
4
4
|
color: string;
|
|
5
5
|
curve: 'linear' | 'monotone' | 'step';
|
|
@@ -11,5 +11,5 @@ export interface LineRenderOptions {
|
|
|
11
11
|
transition?: TransitionConfig;
|
|
12
12
|
}
|
|
13
13
|
export declare function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void;
|
|
14
|
-
export declare function computePoints(data:
|
|
14
|
+
export declare function computePoints(data: ContinuousDatum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[];
|
|
15
15
|
//# sourceMappingURL=line-renderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-renderer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"line-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-renderer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IACtC,yHAAyH;IACzH,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAQD,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CA4HjG;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAanH"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { resolveEasing as e } from "../../animation/easing.js";
|
|
2
|
-
import { resolveMotion as t } from "../../animation/motion.js";
|
|
3
|
-
import { tweenNumber as n } from "../../animation/tween.js";
|
|
4
1
|
import "../../_dev.js";
|
|
5
|
-
import { createSvgElement as
|
|
2
|
+
import { createSvgElement as e, setAttributes as t } from "../../svg/element.js";
|
|
3
|
+
import { resolveEasing as n } from "../../animation/easing.js";
|
|
4
|
+
import { resolveMotion as r } from "../../animation/motion.js";
|
|
5
|
+
import { tweenNumber as i } from "../../animation/tween.js";
|
|
6
6
|
import { linePath as a, monotonePath as o, stepPath as s } from "../../svg/path.js";
|
|
7
7
|
//#region src/charts/line/line-renderer.ts
|
|
8
8
|
var c = /* @__PURE__ */ new WeakMap();
|
|
@@ -10,23 +10,23 @@ function l(e, t) {
|
|
|
10
10
|
return t === "monotone" ? o(e) : t === "step" ? s(e) : a(e);
|
|
11
11
|
}
|
|
12
12
|
function u(a, o, s) {
|
|
13
|
-
let u =
|
|
14
|
-
p || (p =
|
|
13
|
+
let u = r(s.transition, 0), d = u.duration, f = n(u.easing), p = a.querySelector(".prism-line-path");
|
|
14
|
+
p || (p = e("path", {
|
|
15
15
|
class: "prism-line-path",
|
|
16
16
|
fill: "none"
|
|
17
|
-
}), a.appendChild(p)),
|
|
17
|
+
}), a.appendChild(p)), t(p, {
|
|
18
18
|
stroke: s.color,
|
|
19
19
|
"stroke-width": s.strokeWidth
|
|
20
20
|
});
|
|
21
21
|
let m = a.querySelector(".prism-line-dots");
|
|
22
|
-
if (s.showPoints ? m || (m =
|
|
23
|
-
if (
|
|
22
|
+
if (s.showPoints ? m || (m = e("g", { class: "prism-line-dots" }), a.appendChild(m)) : m &&= (m.remove(), null), d === 0) {
|
|
23
|
+
if (t(p, { d: l(o, s.curve) }), m) {
|
|
24
24
|
for (; m.children.length > o.length;) m.removeChild(m.lastChild);
|
|
25
|
-
for (let
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
cx: o[
|
|
29
|
-
cy: o[
|
|
25
|
+
for (let n = 0; n < o.length; n++) {
|
|
26
|
+
let r = m.children[n];
|
|
27
|
+
r || (r = e("circle", { class: "prism-line-dot" }), m.appendChild(r)), t(r, {
|
|
28
|
+
cx: o[n].x,
|
|
29
|
+
cy: o[n].y,
|
|
30
30
|
fill: s.color,
|
|
31
31
|
r: s.pointRadius
|
|
32
32
|
});
|
|
@@ -37,23 +37,23 @@ function u(a, o, s) {
|
|
|
37
37
|
c.get(a)?.();
|
|
38
38
|
let h = !!p.getAttribute("d"), g = [], _ = null;
|
|
39
39
|
if (m) {
|
|
40
|
-
let
|
|
41
|
-
for (let
|
|
42
|
-
let
|
|
43
|
-
x: Number(
|
|
44
|
-
y: Number(
|
|
40
|
+
let n = m.children.length;
|
|
41
|
+
for (let e = 0; e < n; e++) {
|
|
42
|
+
let t = m.children[e], n = {
|
|
43
|
+
x: Number(t.getAttribute("cx")),
|
|
44
|
+
y: Number(t.getAttribute("cy"))
|
|
45
45
|
};
|
|
46
46
|
g.push(n), _ = n;
|
|
47
47
|
}
|
|
48
48
|
for (; m.children.length > o.length;) m.removeChild(m.lastChild);
|
|
49
|
-
for (let
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
cx: o[
|
|
53
|
-
cy: o[
|
|
49
|
+
for (let n = m.children.length; n < o.length; n++) {
|
|
50
|
+
let r = e("circle", { class: "prism-line-dot" });
|
|
51
|
+
t(r, {
|
|
52
|
+
cx: o[n].x,
|
|
53
|
+
cy: o[n].y,
|
|
54
54
|
fill: s.color,
|
|
55
55
|
r: s.pointRadius
|
|
56
|
-
}), m.appendChild(
|
|
56
|
+
}), m.appendChild(r);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
for (let e = g.length; e < o.length; e++) g.push(_ ?? o[e]);
|
|
@@ -64,26 +64,26 @@ function u(a, o, s) {
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
v === null && (v = e);
|
|
67
|
-
let
|
|
68
|
-
let
|
|
67
|
+
let n = Math.min(1, (e - v) / d), r = f(n), u = o.map((e, t) => {
|
|
68
|
+
let n = g[t] ?? e;
|
|
69
69
|
return {
|
|
70
|
-
x: n
|
|
71
|
-
y: n
|
|
70
|
+
x: i(n.x, e.x, r),
|
|
71
|
+
y: i(n.y, e.y, r)
|
|
72
72
|
};
|
|
73
73
|
});
|
|
74
|
-
if (
|
|
75
|
-
let
|
|
76
|
-
|
|
74
|
+
if (t(p, { d: l(u, s.curve) }), m) for (let e = 0; e < o.length; e++) {
|
|
75
|
+
let n = m.children[e];
|
|
76
|
+
n && t(n, {
|
|
77
77
|
cx: u[e].x,
|
|
78
78
|
cy: u[e].y
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
-
if (
|
|
81
|
+
if (n < 1) {
|
|
82
82
|
let e = requestAnimationFrame(y);
|
|
83
83
|
c.set(a, () => cancelAnimationFrame(e));
|
|
84
84
|
} else c.delete(a);
|
|
85
85
|
}
|
|
86
|
-
if (!h)
|
|
86
|
+
if (!h) t(p, { d: l(o, s.curve) });
|
|
87
87
|
else {
|
|
88
88
|
let e = requestAnimationFrame(y);
|
|
89
89
|
c.set(a, () => cancelAnimationFrame(e));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-renderer.js","names":[],"sources":["../../../src/charts/line/line-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { linePath, monotonePath, stepPath } from '../../svg/path';\nimport type {
|
|
1
|
+
{"version":3,"file":"line-renderer.js","names":[],"sources":["../../../src/charts/line/line-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionConfig } from '../../types';\n\nexport interface LineRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed — stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n pointRadius: number;\n showPoints: boolean;\n strokeWidth: number;\n transition?: TransitionConfig;\n}\n\nconst activeAnimations = new WeakMap<SVGGElement, () => void>();\n\nfunction buildPath(pts: Point[], curve: LineRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let path = parent.querySelector<SVGPathElement>('.prism-line-path');\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n parent.appendChild(path);\n }\n\n setAttributes(path, { stroke: options.color, 'stroke-width': options.strokeWidth });\n\n let dotsGroup = parent.querySelector<SVGGElement>('.prism-line-dots');\n\n if (options.showPoints) {\n if (!dotsGroup) {\n dotsGroup = createSvgElement('g', { class: 'prism-line-dots' });\n parent.appendChild(dotsGroup);\n }\n } else if (dotsGroup) {\n dotsGroup.remove();\n dotsGroup = null;\n }\n\n if (dur === 0) {\n setAttributes(path, { d: buildPath(points, options.curve) });\n\n if (dotsGroup) {\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = 0; i < points.length; i++) {\n let c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (!c) {\n c = createSvgElement('circle', { class: 'prism-line-dot' });\n dotsGroup.appendChild(c);\n }\n\n setAttributes(c, { cx: points[i].x, cy: points[i].y, fill: options.color, r: options.pointRadius });\n }\n }\n\n return;\n }\n\n activeAnimations.get(parent)?.();\n\n const hasExisting = !!path.getAttribute('d');\n\n const fromPts: Point[] = [];\n let lastKnown: Point | null = null;\n\n if (dotsGroup) {\n const existingCount = dotsGroup.children.length;\n\n for (let i = 0; i < existingCount; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement;\n const pt = { x: Number(c.getAttribute('cx')), y: Number(c.getAttribute('cy')) };\n\n fromPts.push(pt);\n lastKnown = pt;\n }\n\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = dotsGroup.children.length; i < points.length; i++) {\n const c = createSvgElement('circle', { class: 'prism-line-dot' });\n\n setAttributes(c, { cx: points[i].x, cy: points[i].y, fill: options.color, r: options.pointRadius });\n dotsGroup.appendChild(c);\n }\n }\n\n for (let i = fromPts.length; i < points.length; i++) {\n fromPts.push(lastKnown ?? points[i]);\n }\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAnimations.delete(parent);\n\n return;\n }\n\n if (startTime === null) startTime = ts;\n\n const t = Math.min(1, (ts - startTime) / dur);\n const e = easing(t);\n const interpolated: Point[] = points.map((to, i) => {\n const from = fromPts[i] ?? to;\n\n return { x: tweenNumber(from.x, to.x, e), y: tweenNumber(from.y, to.y, e) };\n });\n\n setAttributes(path!, { d: buildPath(interpolated, options.curve) });\n\n if (dotsGroup) {\n for (let i = 0; i < points.length; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (c) setAttributes(c, { cx: interpolated[i].x, cy: interpolated[i].y });\n }\n }\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAnimations.delete(parent);\n }\n }\n\n if (!hasExisting) {\n setAttributes(path, { d: buildPath(points, options.curve) });\n } else {\n const id = requestAnimationFrame(frame);\n\n activeAnimations.set(parent, () => cancelAnimationFrame(id));\n }\n}\n\nexport function computePoints(data: ContinuousDatum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computePoints: datum.key is null or undefined — data must use the Datum shape { key, value }. Did you pass { x, y } instead?',\n );\n } else if (data.some((d) => typeof d.key === 'string')) {\n warn('computePoints: string keys are not supported for line/area charts — use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":";;;;;;;AAoBA,IAAM,oBAAmB,IAAI,QAA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U,GAAc,EAAQ,KAAK,EAAE,CAAC,GAE9D,GACF,KAAK,IAAI,IAAI,GAAG,IAAI,EAAO,QAAQ,KAAK;GACtC,IAAM,IAAI,EAAU,SAAS;GAE7B,AAAI,KAAG,EAAc,GAAG;IAAE,IAAI,EAAa,EAAE,CAAC;IAAG,IAAI,EAAa,EAAE,CAAC;GAAE,CAAC;EAC1E;EAGF,IAAI,IAAI,GAAG;GACT,IAAM,IAAK,sBAAsB,CAAK;GAEtC,EAAiB,IAAI,SAAc,qBAAqB,CAAE,CAAC;EAC7D,OACE,EAAiB,OAAO,CAAM;CAElC;CAEA,IAAI,CAAC,GACH,EAAc,GAAM,EAAE,GAAG,EAAU,GAAQ,EAAQ,KAAK,EAAE,CAAC;MACtD;EACL,IAAM,IAAK,sBAAsB,CAAK;EAEtC,EAAiB,IAAI,SAAc,qBAAqB,CAAE,CAAC;CAC7D;AACF;AAEA,SAAgB,EAAc,GAAyB,GAA8B,GAAgC;CASnH,OARI,EAAK,MAAM,MAAM,EAAE,OAAO,IAAI,KAIvB,EAAK,MAAM,MAAM,OAAO,EAAE,OAAQ,QAAQ,GAI9C,EAAK,KAAK,OAAO;EACtB,GAAG,EAAO,IAAI,EAAE,GAAoB;EACpC,GAAG,EAAO,IAAI,EAAE,KAAK;CACvB,EAAE;AACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../../
|
|
1
|
+
const e=require("../../svg/element.cjs"),t=require("../../core/chart-scaffold.cjs"),n=require("../../theme/index.cjs"),r=require("../../animation/easing.cjs"),i=require("../../animation/motion.cjs"),a=require("../../animation/tween.cjs"),o=require("./pie-renderer.cjs");var s=2*Math.PI,c=-Math.PI/2,l=Math.PI/2;function u(e){return e===`semi`?{end:l,start:c}:{end:s,start:0}}function d(s,c){let l=c.variant??`pie`,d=c.padPixels??(l===`pie`?0:8),p=c.cornerRadius??(l===`pie`?0:8),m=c.data,h=e.createSvgElement(`circle`,{class:`prism-pie-bg`,"pointer-events":`none`}),g=e.createSvgElement(`g`,{class:`prism-pie-slices`,"shape-rendering":`geometricPrecision`}),_=e.createSvgElement(`g`,{class:`prism-pie-labels`,"pointer-events":`none`}),v=[],y=null;function b(t){_.replaceChildren();for(let n=0;n<v.length;n++){let r=v[n],i=t[n];if(!i?.label)continue;let{x:a,y:s}=o.arcCentroid(r),c=e.createSvgElement(`text`,{class:`prism-pie-label`});e.setAttributes(c,{"dominant-baseline":`middle`,fill:`var(--prism-pie-label-color, #fff)`,"font-family":`var(--prism-font-family, system-ui)`,"font-size":`var(--prism-pie-label-size, 12px)`,"text-anchor":`middle`,x:a,y:s}),c.textContent=i.label,_.appendChild(c)}}let x;try{return x=t.createRadialScaffold(s,{a11y:c.a11y,legend:c.legend,tooltip:c.tooltip},t=>{let{legend:x,svg:S,tooltip:C}=t;S.contains(h)||(S.appendChild(h),S.appendChild(g),S.appendChild(_));let{height:w,width:T}=t.dimensions,E=l===`semi`,D=T/2,O=E?w*.85:w/2,k=E?Math.min(D,O)-8:Math.min(T,w)/2-8,A=l===`pie`?0:Math.round(k*.55),j=c.innerRadius===void 0?A:c.innerRadius,M=Math.max(j+1,k),N=m,{end:P,start:F}=u(l);for(v=o.computeArcs(N,D,O,M,j,F,P,d,p,e=>n.seriesColor(e),!1),e.setAttributes(h,{cx:D,cy:O,r:j>0?j:0}),h.setAttribute(`style`,`fill:var(--prism-bg,#fff)`);g.children.length>v.length;)g.removeChild(g.lastChild);_.replaceChildren();let I=i.resolveMotion(c.transition,0),L=I.duration,R=r.resolveEasing(I.easing);for(let t=0;t<v.length;t++){let n=v[t],r=g.children[t];r||(r=e.createSvgElement(`path`,{class:`prism-pie-slice`}),g.appendChild(r)),r.setAttribute(`fill`,n.color),r.setAttribute(`stroke`,`none`),r.style.cursor=c.onClick||c.onHover?`pointer`:``}if(y!==null&&(cancelAnimationFrame(y),y=null),L>0){let t=null,n=r=>{t===null&&(t=r);let i=R(Math.min(1,(r-t)/L)),s=a.tweenNumber(F,P,i);for(let t=0;t<v.length;t++){let n=v[t],r=g.children[t];if(r){if(s<=n.startAngle)e.setAttributes(r,{d:``});else{let t=Math.min(n.endAngle,s);e.setAttributes(r,{d:o.arcPath({...n,endAngle:t})})}}}i<1?y=requestAnimationFrame(n):(y=null,b(N))};y=requestAnimationFrame(n)}else{for(let t=0;t<v.length;t++){let n=v[t],r=g.children[t];r&&e.setAttributes(r,{d:o.arcPath(n)})}b(N)}return x?.update(v.map(e=>({color:e.color,name:e.slice.label??``}))),C?.hide(),{onClick:e=>{if(!c.onClick)return;let t=S.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top,i=f(v,n,r,l);i>=0&&c.onClick(v[i].slice,i)},onMouseLeave:()=>{c.onHover?.(null,null),C?.hide()},onMouseMove:e=>{let t=S.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top,i=f(v,n,r,l);if(i>=0){let e=v[i];c.onHover?.(e.slice,i);let{x:n,y:r}=o.arcCentroid(e),a=s.getBoundingClientRect();C?.show(n+(t.left-a.left),r+(t.top-a.top),{key:i,value:e.slice.value},{color:e.color,data:[],name:e.slice.label??``})}else c.onHover?.(null,null),C?.hide()}}},e=>{m=e}),{get disposalSignal(){return x.disposalSignal},dispose(){y!==null&&(cancelAnimationFrame(y),y=null),x.dispose()},get disposed(){return x.disposed},el:x.el,update(e){x.update(e)},[Symbol.dispose](){this.dispose()}}}catch(e){throw x?.dispose(),e}}function f(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i],o=t-a.centerX,c=n-a.centerY,l=Math.sqrt(o*o+c*c);if(l<a.outerRadius&&l>=a.innerRadius){let e=Math.atan2(o,-c);if(r===`semi`){if(e>=a.startAngle-1e-9&&e<=a.endAngle+1e-9)return i}else{let t=e<0?e+s:e;if(t>=a.startAngle-1e-9&&t<=a.endAngle+1e-9)return i}}}return-1}exports.createPieChart=d;
|
|
2
2
|
//# sourceMappingURL=pie-chart.cjs.map
|