@amad3v/solid-chart 1.0.3 → 1.0.4
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 +54 -22
- package/dist/solid-chart.js +60 -56
- package/dist/solid-chart.js.map +1 -1
- package/package.json +4 -3
- package/src/chart.tsx +17 -6
- package/src/index.ts +1 -1
- package/src/registry.ts +2 -1
- package/src/typedCharts.tsx +2 -2
package/README.md
CHANGED
|
@@ -4,27 +4,34 @@
|
|
|
4
4
|
|
|
5
5
|
A lightweight, reactive [SolidJS](https://www.solidjs.com/) wrapper for [Chart.js 4.5+](https://www.chartjs.org/).
|
|
6
6
|
|
|
7
|
-
This library provides a thin, high-performance layer over **Chart.js**, ensuring
|
|
7
|
+
This library provides a thin, high-performance layer over **Chart.js**, ensuring
|
|
8
|
+
that chart instances stay in sync with Solid's fine-grained reactivity without
|
|
9
|
+
the "Wrapper Tax" of older implementations.
|
|
8
10
|
|
|
9
11
|
---
|
|
10
12
|
|
|
11
|
-
> 💡 **Important**
|
|
13
|
+
> 💡 **Important**: This project is based on the original work by [s0ftik3/solid-chartjs](https://github.com/s0ftik3/solid-chartjs). It has been modernised to fix race conditions related to DOM rendering and updated for compatibility with the latest **Chart.js**.
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
> ⚠️ **Warning**
|
|
15
|
+
---
|
|
16
16
|
|
|
17
|
-
> This library is **not thoroughly tested** in production environments. Please use it with caution and report any issues.
|
|
17
|
+
> ⚠️ **Warning**: This library is **not thoroughly tested** in production environments. Please use it with caution and report any issues.
|
|
18
18
|
|
|
19
19
|
---
|
|
20
|
+
|
|
20
21
|
## Features
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
|
|
23
|
+
- **Zero-Signal Architecture**: Uses synchronous `onMount` ref handling to
|
|
24
|
+
prevent `getComputedStyle` errors.
|
|
25
|
+
- **Prop Protection**: Automatically unwraps Solid Stores before passing them to
|
|
26
|
+
Chart.js to prevent Proxy-related crashes.
|
|
27
|
+
- **Typed Components**: Includes pre-defined components for `Line`, `Bar`,
|
|
28
|
+
`Doughnut`,...
|
|
29
|
+
- **Registration Utilities**: Built-in helpers to register only what you need,
|
|
30
|
+
keeping your bundle small.
|
|
31
|
+
- **ESM-First**: Optimised for modern bundlers like Vite and Rspack.
|
|
26
32
|
|
|
27
33
|
## Installation
|
|
34
|
+
|
|
28
35
|
```bash
|
|
29
36
|
pnpm add @amad3v/solid-chart chart.js
|
|
30
37
|
# or
|
|
@@ -32,7 +39,11 @@ npm install @amad3v/solid-chart chart.js
|
|
|
32
39
|
```
|
|
33
40
|
|
|
34
41
|
## Setup (Registration)
|
|
35
|
-
|
|
42
|
+
|
|
43
|
+
To keep the bundle lean, `solid-chart` does not register Chart.js components
|
|
44
|
+
globally by default. We provide utilities to register exactly what you need in
|
|
45
|
+
your entry point (e.g., `index.tsx`):
|
|
46
|
+
|
|
36
47
|
```tsx
|
|
37
48
|
import { registerCoreExtra, registerLine, registerBar } from 'solid-chart';
|
|
38
49
|
|
|
@@ -43,7 +54,10 @@ registerCoreExtra();
|
|
|
43
54
|
registerLine();
|
|
44
55
|
registerBar();
|
|
45
56
|
```
|
|
46
|
-
|
|
57
|
+
|
|
58
|
+
If you have custom requirements or 3rd party plugins, use the exposed
|
|
59
|
+
`registerComponent` helper:
|
|
60
|
+
|
|
47
61
|
```tsx
|
|
48
62
|
import { registerComponent } from 'solid-chart';
|
|
49
63
|
import MyPlugin from 'chartjs-my-plugin';
|
|
@@ -52,7 +66,9 @@ registerComponent(MyPlugin);
|
|
|
52
66
|
```
|
|
53
67
|
|
|
54
68
|
## Usage
|
|
55
|
-
|
|
69
|
+
|
|
70
|
+
Using the library is straightforward. You can use the generic `DefaultChart` or
|
|
71
|
+
any of the typed exports.
|
|
56
72
|
|
|
57
73
|
```tsx
|
|
58
74
|
import { Line } from 'solid-chart';
|
|
@@ -88,18 +104,21 @@ const App = () => {
|
|
|
88
104
|
```
|
|
89
105
|
|
|
90
106
|
## API
|
|
107
|
+
|
|
91
108
|
### Components
|
|
109
|
+
|
|
92
110
|
All components accept standard Chart.js configuration objects as props.
|
|
93
111
|
|
|
94
112
|
`DefaultChart`: The base component (requires a `type` prop).
|
|
95
113
|
|
|
96
|
-
`Line`, `Bar`, `Radar`, `Doughnut`, `PolarArea`, `Bubble`, `Pie`, `Scatter`:
|
|
114
|
+
`Line`, `Bar`, `Radar`, `Doughnut`, `PolarArea`, `Bubble`, `Pie`, `Scatter`:
|
|
115
|
+
Type-safe shortcuts.
|
|
97
116
|
|
|
98
117
|
## Registration Utilities
|
|
99
118
|
|
|
100
119
|
| Function | Description |
|
|
101
120
|
| --------------------------------- | ------------------------------------------------------- |
|
|
102
|
-
| registerComponent
|
|
121
|
+
| registerComponent | Raw access to Chart.register(...args). |
|
|
103
122
|
| registerCore | Registers Tooltip and Legend. |
|
|
104
123
|
| registerCoreExtra | Registers Title, Tooltip, Legend, Colors, and SubTitle. |
|
|
105
124
|
| registerLine | Registers requirements for Line charts. |
|
|
@@ -107,8 +126,8 @@ All components accept standard Chart.js configuration objects as props.
|
|
|
107
126
|
| registerPie / registerDoughnut | Registers requirements for Arc-based charts. |
|
|
108
127
|
| registerRadar / registerPolarArea | Registers requirements for Radial charts. |
|
|
109
128
|
|
|
110
|
-
|
|
111
129
|
### Props
|
|
130
|
+
|
|
112
131
|
| Prop | Type | Description |
|
|
113
132
|
| ------- | ------------ | ------------------------------------------------- |
|
|
114
133
|
| data | ChartData | The reactive data object (Solid Store supported). |
|
|
@@ -119,20 +138,33 @@ All components accept standard Chart.js configuration objects as props.
|
|
|
119
138
|
|
|
120
139
|
## Contributing
|
|
121
140
|
|
|
122
|
-
Contributions are welcome! Please fork the repository and submit a pull request
|
|
141
|
+
Contributions are welcome! Please fork the repository and submit a pull request
|
|
142
|
+
for any improvements, bug fixes, or new features. Be sure to follow best
|
|
143
|
+
practices and ensure all tests pass before submitting.
|
|
123
144
|
|
|
124
145
|
## License
|
|
125
146
|
|
|
126
|
-
This project is licensed under the MIT License - see the [LICENSE](./LICENSE)
|
|
147
|
+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE)
|
|
148
|
+
file for details.
|
|
127
149
|
|
|
128
150
|
## Acknowledgements
|
|
129
151
|
|
|
130
|
-
This library is a modernised and refactored version of
|
|
152
|
+
This library is a modernised and refactored version of
|
|
153
|
+
[solid-chartjs](https://github.com/s0ftik3/solid-chartjs), tailored to support
|
|
154
|
+
modern SolidJS and Chart.js 4.5+ architectures. All credit for the original
|
|
155
|
+
[solid-chartjs](https://github.com/s0ftik3/solid-chartjs) library and its
|
|
156
|
+
initial implementation goes to the original
|
|
157
|
+
[authors](https://github.com/s0ftik3).
|
|
131
158
|
|
|
132
159
|
## Disclaimer
|
|
133
160
|
|
|
134
|
-
Please note: This library is by no means a professional or production-ready
|
|
161
|
+
Please note: This library is by no means a professional or production-ready
|
|
162
|
+
solution. It was developed out of necessity for personal projects, and it may
|
|
163
|
+
not meet the quality or stability standards required for a fully-fledged
|
|
164
|
+
production environment. It is intended for personal use and experimentation, and
|
|
165
|
+
contributions are highly encouraged to improve its functionality and stability.
|
|
135
166
|
|
|
136
167
|
## Changelog
|
|
137
168
|
|
|
138
|
-
Detailed changes for each release are documented in the
|
|
169
|
+
Detailed changes for each release are documented in the
|
|
170
|
+
[CHANGELOG.md](./CHANGELOG.md).
|
package/dist/solid-chart.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { template as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
var
|
|
7
|
-
const l = (e) => {
|
|
8
|
-
let
|
|
9
|
-
const t =
|
|
1
|
+
import { template as D, use as x, insert as O, effect as T, setAttribute as S, createComponent as i, mergeProps as s } from "solid-js/web";
|
|
2
|
+
import { mergeProps as M, onMount as _, createEffect as d, on as g, onCleanup as I } from "solid-js";
|
|
3
|
+
import { unwrap as f } from "solid-js/store";
|
|
4
|
+
import { mergeRefs as w } from "@solid-primitives/refs";
|
|
5
|
+
import { Chart as P, PointElement as h, LinearScale as m, BubbleController as $, Legend as A, Tooltip as E, SubTitle as k, Colors as q, Title as z, ArcElement as b, DoughnutController as F, LineElement as R, CategoryScale as B, LineController as X, PieController as j, RadialLinearScale as L, PolarAreaController as G, RadarController as H, ScatterController as J, BarElement as K, BarController as N } from "chart.js";
|
|
6
|
+
var Q = /* @__PURE__ */ D("<canvas>");
|
|
7
|
+
const U = 300, l = (e) => {
|
|
8
|
+
let c = 0, u, o;
|
|
9
|
+
const t = M({
|
|
10
10
|
width: 512,
|
|
11
11
|
height: 512,
|
|
12
12
|
type: "line",
|
|
@@ -16,93 +16,97 @@ const l = (e) => {
|
|
|
16
16
|
},
|
|
17
17
|
plugins: []
|
|
18
18
|
}, e), C = () => {
|
|
19
|
-
if (!
|
|
20
|
-
if (!
|
|
21
|
-
|
|
19
|
+
if (!u) return;
|
|
20
|
+
if (!u.isConnected) {
|
|
21
|
+
if (c++, c % 120 === 0 && console.warn("Solid-Chart: Canvas layout is delayed. Still retrying..."), c >= U) {
|
|
22
|
+
console.error("Solid-Chart: Initialisation failed. Canvas never connected to DOM.");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
requestAnimationFrame(C);
|
|
22
26
|
return;
|
|
23
27
|
}
|
|
24
|
-
|
|
25
|
-
const n =
|
|
26
|
-
...
|
|
28
|
+
c = 0;
|
|
29
|
+
const n = u.getContext("2d"), r = {
|
|
30
|
+
...f(t.options)
|
|
27
31
|
};
|
|
28
32
|
if (t.type !== "radar" && r.scales?.r) {
|
|
29
33
|
const {
|
|
30
|
-
r:
|
|
31
|
-
...
|
|
34
|
+
r: v,
|
|
35
|
+
...p
|
|
32
36
|
} = r.scales;
|
|
33
|
-
r.scales =
|
|
37
|
+
r.scales = p;
|
|
34
38
|
}
|
|
35
|
-
o = new
|
|
39
|
+
o = new P(n, {
|
|
36
40
|
type: t.type,
|
|
37
|
-
data:
|
|
41
|
+
data: f(t.data),
|
|
38
42
|
// unwrap stores before passing to external libs
|
|
39
43
|
options: r,
|
|
40
44
|
plugins: t.plugins
|
|
41
45
|
});
|
|
42
46
|
};
|
|
43
|
-
return
|
|
44
|
-
o && (o.data =
|
|
47
|
+
return _(() => C()), d(g(() => t.data, (n) => {
|
|
48
|
+
o && (o.data = f(n), o.update("none"));
|
|
45
49
|
}, {
|
|
46
50
|
defer: !0
|
|
47
|
-
})),
|
|
48
|
-
o && (o.options =
|
|
51
|
+
})), d(g(() => t.options, (n) => {
|
|
52
|
+
o && (o.options = f(n), o.update());
|
|
49
53
|
}, {
|
|
50
54
|
defer: !0
|
|
51
|
-
})),
|
|
55
|
+
})), d(g([() => t.width, () => t.height], () => o?.resize(t.width, t.height), {
|
|
52
56
|
defer: !0
|
|
53
|
-
})),
|
|
57
|
+
})), d(g(() => t.type, () => {
|
|
54
58
|
o && (o.destroy(), C());
|
|
55
59
|
}, {
|
|
56
60
|
defer: !0
|
|
57
|
-
})),
|
|
58
|
-
o?.destroy(),
|
|
61
|
+
})), I(() => {
|
|
62
|
+
o?.destroy(), w(e.ref, null);
|
|
59
63
|
}), (() => {
|
|
60
|
-
var n =
|
|
61
|
-
return typeof y == "function" &&
|
|
62
|
-
var
|
|
63
|
-
return
|
|
64
|
+
var n = Q(), y = w(e.ref, (r) => u = r);
|
|
65
|
+
return typeof y == "function" && x(y, n), O(n, () => t.fallback), T((r) => {
|
|
66
|
+
var v = t.height, p = t.width;
|
|
67
|
+
return v !== r.e && S(n, "height", r.e = v), p !== r.t && S(n, "width", r.t = p), r;
|
|
64
68
|
}, {
|
|
65
69
|
e: void 0,
|
|
66
70
|
t: void 0
|
|
67
71
|
}), n;
|
|
68
72
|
})();
|
|
69
|
-
}, a = (...e) =>
|
|
73
|
+
}, a = (...e) => P.register(...e), te = () => a(E, A), re = () => a(z, E, A, q, k), oe = () => a(X, B, m, h, R), ne = () => a(N, B, m, K), ae = () => a(H, L, h, R), ie = () => a(F, b), se = () => a(j, b), le = () => a(G, L, b), ce = () => a($, m, h), ue = () => a(J, m, h), pe = (e) => i(l, s(e, {
|
|
70
74
|
type: "line"
|
|
71
|
-
})), pe = (e) => i(l, s(e, {
|
|
72
|
-
type: "bar"
|
|
73
75
|
})), de = (e) => i(l, s(e, {
|
|
74
|
-
type: "
|
|
76
|
+
type: "bar"
|
|
75
77
|
})), ge = (e) => i(l, s(e, {
|
|
76
|
-
type: "
|
|
78
|
+
type: "radar"
|
|
77
79
|
})), fe = (e) => i(l, s(e, {
|
|
80
|
+
type: "doughnut"
|
|
81
|
+
})), he = (e) => i(l, s(e, {
|
|
78
82
|
type: "polarArea"
|
|
79
83
|
})), me = (e) => i(l, s(e, {
|
|
80
84
|
type: "bubble"
|
|
81
|
-
})), he = (e) => i(l, s(e, {
|
|
82
|
-
type: "pie"
|
|
83
85
|
})), Ce = (e) => i(l, s(e, {
|
|
86
|
+
type: "pie"
|
|
87
|
+
})), ye = (e) => i(l, s(e, {
|
|
84
88
|
type: "scatter"
|
|
85
89
|
}));
|
|
86
90
|
export {
|
|
87
|
-
|
|
91
|
+
de as Bar,
|
|
88
92
|
me as Bubble,
|
|
89
93
|
l as DefaultChart,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
fe as Doughnut,
|
|
95
|
+
pe as Line,
|
|
96
|
+
Ce as Pie,
|
|
97
|
+
he as PolarArea,
|
|
98
|
+
ge as Radar,
|
|
99
|
+
ye as Scatter,
|
|
100
|
+
ne as registerBar,
|
|
101
|
+
ce as registerBubble,
|
|
98
102
|
a as registerComponent,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
te as registerCore,
|
|
104
|
+
re as registerCoreExtra,
|
|
105
|
+
ie as registerDoughnut,
|
|
106
|
+
oe as registerLine,
|
|
107
|
+
se as registerPie,
|
|
108
|
+
le as registerPolarArea,
|
|
109
|
+
ae as registerRadar,
|
|
110
|
+
ue as registerScatter
|
|
107
111
|
};
|
|
108
112
|
//# sourceMappingURL=solid-chart.js.map
|
package/dist/solid-chart.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solid-chart.js","sources":["../src/chart.tsx","../src/registry.ts","../src/typedCharts.tsx"],"sourcesContent":["import { mergeRefs } from '@solid-primitives/refs';\nimport { Chart, ChartData, ChartItem, ChartOptions, Plugin } from 'chart.js';\nimport { Component, createEffect, mergeProps, on, onCleanup, onMount } from 'solid-js';\nimport { unwrap } from 'solid-js/store';\n\nimport { ChartProps } from './types';\n\nexport const DefaultChart: Component<ChartProps> = (props) => {\n let retryCount = 0;\n let canvasRef: HTMLCanvasElement | null;\n let chart: Chart | undefined;\n\n const merged = mergeProps(\n {\n width: 512,\n height: 512,\n type: 'line' as const,\n data: {} as ChartData,\n options: { responsive: true } as ChartOptions,\n plugins: [] as Plugin[],\n },\n props,\n );\n\n const init = () => {\n if (!canvasRef) return;\n\n // Is the canvas actually in the document?\n if (!canvasRef.isConnected) {\n retryCount++;\n\n // Warn if it takes an abnormally long time (> 1 second)\n // Assuming ~60fps, 60 retries is roughly 1 second.\n if (retryCount === 60) {\n // eslint-disable-next-line no-console\n console.warn('Solid-Chart: Canvas layout is delayed. Still retrying...');\n }\n\n requestAnimationFrame(init);\n return;\n }\n\n // Success! Reset counter and proceed\n retryCount = 0;\n\n const ctx = canvasRef.getContext('2d') as ChartItem;\n\n // Clean unwrap and a safe copy of options\n const rawOptions = unwrap(merged.options);\n const configOptions = { ...rawOptions };\n\n // Handle the radar scale issue without mutating props\n if (merged.type !== 'radar' && configOptions.scales?.r) {\n const { r: _, ...otherScales } = configOptions.scales;\n configOptions.scales = otherScales;\n }\n\n chart = new Chart(ctx, {\n type: merged.type,\n data: unwrap(merged.data), // unwrap stores before passing to external libs\n options: configOptions,\n plugins: merged.plugins,\n });\n };\n\n onMount(() => init());\n\n createEffect(\n on(\n () => merged.data,\n (newData) => {\n if (chart) {\n chart.data = unwrap(newData);\n chart.update('none'); // Use 'none' for better performance on data updates\n }\n },\n { defer: true },\n ),\n );\n\n createEffect(\n on(\n () => merged.options,\n (newOptions) => {\n if (chart) {\n chart.options = unwrap(newOptions);\n chart.update();\n }\n },\n { defer: true },\n ),\n );\n\n createEffect(\n on(\n [() => merged.width, () => merged.height],\n () => chart?.resize(merged.width, merged.height),\n { defer: true },\n ),\n );\n\n createEffect(\n on(\n () => merged.type,\n () => {\n if (chart) {\n chart.destroy();\n init();\n }\n },\n { defer: true },\n ),\n );\n\n onCleanup(() => {\n chart?.destroy();\n // Standard cleanup for the ref\n mergeRefs(props.ref, null);\n });\n\n return (\n <canvas\n ref={mergeRefs(props.ref, (el) => (canvasRef = el))}\n height={merged.height}\n width={merged.width}\n >\n {merged.fallback}\n </canvas>\n );\n};\n","import {\n ArcElement,\n BarController,\n BarElement,\n BubbleController,\n CategoryScale,\n Chart,\n ChartComponent,\n Colors,\n DoughnutController,\n Legend,\n LinearScale,\n LineController,\n LineElement,\n PieController,\n PointElement,\n PolarAreaController,\n RadarController,\n RadialLinearScale,\n ScatterController,\n SubTitle,\n Title,\n Tooltip,\n} from 'chart.js';\n\n/**\n * Global registration helper for custom components and plugins.\n * Use this to register 3rd party plugins or custom scales.\n */\nexport const registerComponent = (...args: ChartComponent[]) => Chart.register(...args);\n\n/**\n * Essential plugins most charts need.\n */\nexport const registerCore = () => registerComponent(Tooltip, Legend);\n\n/**\n * Extra standard plugins for titles and automatic color palettes.\n */\nexport const registerCoreExtra = () => registerComponent(Title, Tooltip, Legend, Colors, SubTitle);\n\n/**\n * Essential for Line chart.\n */\nexport const registerLine = () =>\n registerComponent(LineController, CategoryScale, LinearScale, PointElement, LineElement);\n\n/**\n * Essential for Bar chart.\n */\nexport const registerBar = () =>\n registerComponent(BarController, CategoryScale, LinearScale, BarElement);\n\n/**\n * Essential for Radar chart.\n */\nexport const registerRadar = () =>\n registerComponent(RadarController, RadialLinearScale, PointElement, LineElement);\n\n/**\n * Essential for Doughnut chart.\n */\nexport const registerDoughnut = () => registerComponent(DoughnutController, ArcElement);\n\n/**\n * Essential for Pie chart.\n */\nexport const registerPie = () => registerComponent(PieController, ArcElement);\n\n/**\n * Essential for PolarArea chart.\n */\nexport const registerPolarArea = () =>\n registerComponent(PolarAreaController, RadialLinearScale, ArcElement);\n\n/**\n * Essential for Bubble chart.\n */\nexport const registerBubble = () => registerComponent(BubbleController, LinearScale, PointElement);\n\n/**\n * Essential for Scatter chart.\n */\nexport const registerScatter = () =>\n registerComponent(ScatterController, LinearScale, PointElement);\n","import { Component } from 'solid-js';\n\nimport { DefaultChart } from './chart';\nimport type { ChartProps } from './types';\n\n// Omit 'type' from props since these components define the type themselves\nexport type TypedChartProps = Omit<ChartProps, 'type'>;\ntype TypedChart = Component<TypedChartProps>;\n\nexport const Line: TypedChart = (props) => <DefaultChart {...props} type=\"line\" />;\nexport const Bar: TypedChart = (props) => <DefaultChart {...props} type=\"bar\" />;\nexport const Radar: TypedChart = (props) => <DefaultChart {...props} type=\"radar\" />;\nexport const Doughnut: TypedChart = (props) => <DefaultChart {...props} type=\"doughnut\" />;\nexport const PolarArea: TypedChart = (props) => <DefaultChart {...props} type=\"polarArea\" />;\nexport const Bubble: TypedChart = (props) => <DefaultChart {...props} type=\"bubble\" />;\nexport const Pie: TypedChart = (props) => <DefaultChart {...props} type=\"pie\" />;\nexport const Scatter: TypedChart = (props) => <DefaultChart {...props} type=\"scatter\" />;\n"],"names":["DefaultChart","props","retryCount","canvasRef","chart","merged","mergeProps","width","height","type","data","options","responsive","plugins","init","isConnected","console","warn","requestAnimationFrame","ctx","getContext","configOptions","unwrap","rawOptions","scales","r","_","otherScales","Chart","onMount","createEffect","on","newData","update","defer","newOptions","resize","destroy","onCleanup","mergeRefs","ref","_el$","_tmpl$","_ref$","el","_$use","_$insert","fallback","_$effect","_p$","_v$","_v$2","e","_$setAttribute","t","undefined","registerComponent","args","registerCore","Tooltip","Legend","registerCoreExtra","Title","Colors","SubTitle","registerLine","LineController","CategoryScale","LinearScale","PointElement","LineElement","registerBar","BarController","BarElement","registerRadar","RadarController","RadialLinearScale","registerDoughnut","DoughnutController","ArcElement","registerPie","PieController","registerPolarArea","PolarAreaController","registerBubble","BubbleController","registerScatter","ScatterController","Line","_$createComponent","_$mergeProps","Bar","Radar","Doughnut","PolarArea","Bubble","Pie","Scatter"],"mappings":";;;;;;AAOO,MAAMA,IAAuCC,CAAAA,MAAU;AAC5D,MAAIC,IAAa,GACbC,GACAC;AAEJ,QAAMC,IAASC,EACb;AAAA,IACEC,OAAO;AAAA,IACPC,QAAQ;AAAA,IACRC,MAAM;AAAA,IACNC,MAAM,CAAA;AAAA,IACNC,SAAS;AAAA,MAAEC,YAAY;AAAA,IAAA;AAAA,IACvBC,SAAS,CAAA;AAAA,EAAA,GAEXZ,CACF,GAEMa,IAAOA,MAAM;AACjB,QAAI,CAACX,EAAW;AAGhB,QAAI,CAACA,EAAUY,aAAa;AAC1Bb,MAAAA,KAIIA,MAAe,MAEjBc,QAAQC,KAAK,0DAA0D,GAGzEC,sBAAsBJ,CAAI;AAC1B;AAAA,IACF;AAGAZ,IAAAA,IAAa;AAEb,UAAMiB,IAAMhB,EAAUiB,WAAW,IAAI,GAI/BC,IAAgB;AAAA,MAAE,GADLC,EAAOjB,EAAOM,OAAO;AAAA,IACbY;AAG3B,QAAIlB,EAAOI,SAAS,WAAWY,EAAcG,QAAQC,GAAG;AACtD,YAAM;AAAA,QAAEA,GAAGC;AAAAA,QAAG,GAAGC;AAAAA,MAAAA,IAAgBN,EAAcG;AAC/CH,MAAAA,EAAcG,SAASG;AAAAA,IACzB;AAEAvB,IAAAA,IAAQ,IAAIwB,EAAMT,GAAK;AAAA,MACrBV,MAAMJ,EAAOI;AAAAA,MACbC,MAAMY,EAAOjB,EAAOK,IAAI;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AAMzF,GAAY0F,EAAKzF,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA,GAC/DqF,KAAyB7F,CAAAA,MAAKwF,EAAMzF,GAAY0F,EAAKzF,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA,GAChEsF,KAAsB9F,CAAAA,MAAKwF,EAAMzF,GAAY0F,EAAKzF,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA,GAC7DuF,KAAmB/F,CAAAA,MAAKwF,EAAMzF,GAAY0F,EAAKzF,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA,GAC1DwF,KAAuBhG,CAAAA,MAAKwF,EAAMzF,GAAY0F,EAAKzF,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA;"}
|
|
1
|
+
{"version":3,"file":"solid-chart.js","sources":["../src/chart.tsx","../src/registry.ts","../src/typedCharts.tsx"],"sourcesContent":["import type { ChartData, ChartItem, ChartOptions, Plugin } from 'chart.js';\nimport type { Component } from 'solid-js';\nimport type { ChartProps } from './types';\n\nimport { createEffect, mergeProps, on, onCleanup, onMount } from 'solid-js';\nimport { unwrap } from 'solid-js/store';\n\nimport { mergeRefs } from '@solid-primitives/refs';\nimport { Chart } from 'chart.js';\n\nconst MAX_RETRIES = 300; // ~5 seconds of trying\n\nexport const DefaultChart: Component<ChartProps> = (props) => {\n let retryCount = 0;\n let canvasRef: HTMLCanvasElement | null;\n let chart: Chart | undefined;\n\n const merged = mergeProps(\n {\n width: 512,\n height: 512,\n type: 'line' as const,\n data: {} as ChartData,\n options: { responsive: true } as ChartOptions,\n plugins: [] as Plugin[],\n },\n props,\n );\n\n const init = () => {\n if (!canvasRef) return;\n\n // Is the canvas actually in the document?\n if (!canvasRef.isConnected) {\n retryCount++;\n\n // Warns every ~2 second if it's still failing\n // Assuming ~60fps, 60 retries is roughly 1 second.\n if (retryCount % 120 === 0) {\n // eslint-disable-next-line no-console\n console.warn('Solid-Chart: Canvas layout is delayed. Still retrying...');\n }\n\n if (retryCount >= MAX_RETRIES) {\n // eslint-disable-next-line no-console\n console.error('Solid-Chart: Initialisation failed. Canvas never connected to DOM.');\n return; // Stop retrying\n }\n\n requestAnimationFrame(init);\n return;\n }\n\n // Success! Reset counter and proceed\n retryCount = 0;\n\n const ctx = canvasRef.getContext('2d') as ChartItem;\n\n // Clean unwrap and a safe copy of options\n const rawOptions = unwrap(merged.options);\n const configOptions = { ...rawOptions };\n\n // Handle the radar scale issue without mutating props\n if (merged.type !== 'radar' && configOptions.scales?.r) {\n const { r: _, ...otherScales } = configOptions.scales;\n configOptions.scales = otherScales;\n }\n\n chart = new Chart(ctx, {\n type: merged.type,\n data: unwrap(merged.data), // unwrap stores before passing to external libs\n options: configOptions,\n plugins: merged.plugins,\n });\n };\n\n onMount(() => init());\n\n createEffect(\n on(\n () => merged.data,\n (newData) => {\n if (chart) {\n chart.data = unwrap(newData);\n chart.update('none'); // Use 'none' for better performance on data updates\n }\n },\n { defer: true },\n ),\n );\n\n createEffect(\n on(\n () => merged.options,\n (newOptions) => {\n if (chart) {\n chart.options = unwrap(newOptions);\n chart.update();\n }\n },\n { defer: true },\n ),\n );\n\n createEffect(\n on(\n [() => merged.width, () => merged.height],\n () => chart?.resize(merged.width, merged.height),\n { defer: true },\n ),\n );\n\n createEffect(\n on(\n () => merged.type,\n () => {\n if (chart) {\n chart.destroy();\n init();\n }\n },\n { defer: true },\n ),\n );\n\n onCleanup(() => {\n chart?.destroy();\n // Standard cleanup for the ref\n mergeRefs(props.ref, null);\n });\n\n return (\n <canvas\n ref={mergeRefs(props.ref, (el) => (canvasRef = el))}\n height={merged.height}\n width={merged.width}\n >\n {merged.fallback}\n </canvas>\n );\n};\n","import type { ChartComponent } from 'chart.js';\n\nimport {\n ArcElement,\n BarController,\n BarElement,\n BubbleController,\n CategoryScale,\n Chart,\n Colors,\n DoughnutController,\n Legend,\n LinearScale,\n LineController,\n LineElement,\n PieController,\n PointElement,\n PolarAreaController,\n RadarController,\n RadialLinearScale,\n ScatterController,\n SubTitle,\n Title,\n Tooltip,\n} from 'chart.js';\n\n/**\n * Global registration helper for custom components and plugins.\n * Use this to register 3rd party plugins or custom scales.\n */\nexport const registerComponent = (...args: ChartComponent[]) => Chart.register(...args);\n\n/**\n * Essential plugins most charts need.\n */\nexport const registerCore = () => registerComponent(Tooltip, Legend);\n\n/**\n * Extra standard plugins for titles and automatic color palettes.\n */\nexport const registerCoreExtra = () => registerComponent(Title, Tooltip, Legend, Colors, SubTitle);\n\n/**\n * Essential for Line chart.\n */\nexport const registerLine = () =>\n registerComponent(LineController, CategoryScale, LinearScale, PointElement, LineElement);\n\n/**\n * Essential for Bar chart.\n */\nexport const registerBar = () =>\n registerComponent(BarController, CategoryScale, LinearScale, BarElement);\n\n/**\n * Essential for Radar chart.\n */\nexport const registerRadar = () =>\n registerComponent(RadarController, RadialLinearScale, PointElement, LineElement);\n\n/**\n * Essential for Doughnut chart.\n */\nexport const registerDoughnut = () => registerComponent(DoughnutController, ArcElement);\n\n/**\n * Essential for Pie chart.\n */\nexport const registerPie = () => registerComponent(PieController, ArcElement);\n\n/**\n * Essential for PolarArea chart.\n */\nexport const registerPolarArea = () =>\n registerComponent(PolarAreaController, RadialLinearScale, ArcElement);\n\n/**\n * Essential for Bubble chart.\n */\nexport const registerBubble = () => registerComponent(BubbleController, LinearScale, PointElement);\n\n/**\n * Essential for Scatter chart.\n */\nexport const registerScatter = () =>\n registerComponent(ScatterController, LinearScale, PointElement);\n","import type { ChartProps } from './types';\nimport type { Component } from 'solid-js';\n\nimport { DefaultChart } from './chart';\n\n// Omit 'type' from props since these components define the type themselves\nexport type TypedChartProps = Omit<ChartProps, 'type'>;\ntype TypedChart = Component<TypedChartProps>;\n\nexport const Line: TypedChart = (props) => <DefaultChart {...props} type=\"line\" />;\nexport const Bar: TypedChart = (props) => <DefaultChart {...props} type=\"bar\" />;\nexport const Radar: TypedChart = (props) => <DefaultChart {...props} type=\"radar\" />;\nexport const Doughnut: TypedChart = (props) => <DefaultChart {...props} type=\"doughnut\" />;\nexport const PolarArea: TypedChart = (props) => <DefaultChart {...props} type=\"polarArea\" />;\nexport const Bubble: TypedChart = (props) => <DefaultChart {...props} type=\"bubble\" />;\nexport const Pie: TypedChart = (props) => <DefaultChart {...props} type=\"pie\" />;\nexport const Scatter: TypedChart = (props) => <DefaultChart {...props} type=\"scatter\" />;\n"],"names":["MAX_RETRIES","DefaultChart","props","retryCount","canvasRef","chart","merged","mergeProps","width","height","type","data","options","responsive","plugins","init","isConnected","console","warn","error","requestAnimationFrame","ctx","getContext","configOptions","unwrap","rawOptions","scales","r","_","otherScales","Chart","onMount","createEffect","on","newData","update","defer","newOptions","resize","destroy","onCleanup","mergeRefs","ref","_el$","_tmpl$","_ref$","el","_$use","_$insert","fallback","_$effect","_p$","_v$","_v$2","e","_$setAttribute","t","undefined","registerComponent","args","registerCore","Tooltip","Legend","registerCoreExtra","Title","Colors","SubTitle","registerLine","LineController","CategoryScale","LinearScale","PointElement","LineElement","registerBar","BarController","BarElement","registerRadar","RadarController","RadialLinearScale","registerDoughnut","DoughnutController","ArcElement","registerPie","PieController","registerPolarArea","PolarAreaController","registerBubble","BubbleController","registerScatter","ScatterController","Line","_$createComponent","_$mergeProps","Bar","Radar","Doughnut","PolarArea","Bubble","Pie","Scatter"],"mappings":";;;;;;AAUA,MAAMA,IAAc,KAEPC,IAAuCC,CAAAA,MAAU;AAC5D,MAAIC,IAAa,GACbC,GACAC;AAEJ,QAAMC,IAASC,EACb;AAAA,IACEC,OAAO;AAAA,IACPC,QAAQ;AAAA,IACRC,MAAM;AAAA,IACNC,MAAM,CAAA;AAAA,IACNC,SAAS;AAAA,MAAEC,YAAY;AAAA,IAAA;AAAA,IACvBC,SAAS,CAAA;AAAA,EAAA,GAEXZ,CACF,GAEMa,IAAOA,MAAM;AACjB,QAAI,CAACX,EAAW;AAGhB,QAAI,CAACA,EAAUY,aAAa;AAU1B,UATAb,KAIIA,IAAa,QAAQ,KAEvBc,Q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INI",
|
|
6
6
|
"email": "amad3v@gmail.com",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@typescript-eslint/parser": "^8.52.0",
|
|
42
42
|
"eslint": "^9.39.2",
|
|
43
43
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
44
|
-
"eslint-plugin-
|
|
44
|
+
"eslint-plugin-import-x": "^4.16.1",
|
|
45
45
|
"eslint-plugin-solid": "^0.14.5",
|
|
46
46
|
"globals": "^17.0.0",
|
|
47
47
|
"pathe": "^2.0.3",
|
|
@@ -71,7 +71,8 @@
|
|
|
71
71
|
"scripts": {
|
|
72
72
|
"dev": "vite",
|
|
73
73
|
"build": "rimraf ./dist && vite build",
|
|
74
|
-
"lint": "eslint ./src -c eslint.config.js
|
|
74
|
+
"lint": "eslint ./src -c eslint.config.js",
|
|
75
|
+
"lint:fix": "eslint ./src -c eslint.config.js --fix",
|
|
75
76
|
"fmt": "prettier --write \"**/*.{mjs,cjs,js,jsx,ts,tsx,json}\"",
|
|
76
77
|
"lint:fmt": "pnpm fmt && pnpm lint"
|
|
77
78
|
}
|
package/src/chart.tsx
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ChartData, ChartItem, ChartOptions, Plugin } from 'chart.js';
|
|
2
|
+
import type { Component } from 'solid-js';
|
|
3
|
+
import type { ChartProps } from './types';
|
|
4
|
+
|
|
5
|
+
import { createEffect, mergeProps, on, onCleanup, onMount } from 'solid-js';
|
|
4
6
|
import { unwrap } from 'solid-js/store';
|
|
5
7
|
|
|
6
|
-
import {
|
|
8
|
+
import { mergeRefs } from '@solid-primitives/refs';
|
|
9
|
+
import { Chart } from 'chart.js';
|
|
10
|
+
|
|
11
|
+
const MAX_RETRIES = 300; // ~5 seconds of trying
|
|
7
12
|
|
|
8
13
|
export const DefaultChart: Component<ChartProps> = (props) => {
|
|
9
14
|
let retryCount = 0;
|
|
@@ -29,13 +34,19 @@ export const DefaultChart: Component<ChartProps> = (props) => {
|
|
|
29
34
|
if (!canvasRef.isConnected) {
|
|
30
35
|
retryCount++;
|
|
31
36
|
|
|
32
|
-
//
|
|
37
|
+
// Warns every ~2 second if it's still failing
|
|
33
38
|
// Assuming ~60fps, 60 retries is roughly 1 second.
|
|
34
|
-
if (retryCount ===
|
|
39
|
+
if (retryCount % 120 === 0) {
|
|
35
40
|
// eslint-disable-next-line no-console
|
|
36
41
|
console.warn('Solid-Chart: Canvas layout is delayed. Still retrying...');
|
|
37
42
|
}
|
|
38
43
|
|
|
44
|
+
if (retryCount >= MAX_RETRIES) {
|
|
45
|
+
// eslint-disable-next-line no-console
|
|
46
|
+
console.error('Solid-Chart: Initialisation failed. Canvas never connected to DOM.');
|
|
47
|
+
return; // Stop retrying
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
requestAnimationFrame(init);
|
|
40
51
|
return;
|
|
41
52
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,6 @@ export {
|
|
|
12
12
|
registerRadar,
|
|
13
13
|
registerScatter,
|
|
14
14
|
} from './registry';
|
|
15
|
-
export { Bar, Bubble, Doughnut, Line, Pie, PolarArea, Radar, Scatter } from './typedCharts';
|
|
16
15
|
export type { TypedChartProps } from './typedCharts';
|
|
16
|
+
export { Bar, Bubble, Doughnut, Line, Pie, PolarArea, Radar, Scatter } from './typedCharts';
|
|
17
17
|
export type { ChartProps } from './types';
|
package/src/registry.ts
CHANGED
package/src/typedCharts.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ChartProps } from './types';
|
|
2
|
+
import type { Component } from 'solid-js';
|
|
2
3
|
|
|
3
4
|
import { DefaultChart } from './chart';
|
|
4
|
-
import type { ChartProps } from './types';
|
|
5
5
|
|
|
6
6
|
// Omit 'type' from props since these components define the type themselves
|
|
7
7
|
export type TypedChartProps = Omit<ChartProps, 'type'>;
|