@amad3v/solid-chart 1.0.2 → 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 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 that chart instances stay in sync with Solid's fine-grained reactivity without the "Wrapper Tax" of older implementations.
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
- > 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**.
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
- - **Zero-Signal Architecture**: Uses synchronous `onMount` ref handling to prevent `getComputedStyle` errors.
22
- - **Prop Protection**: Automatically unwraps Solid Stores before passing them to Chart.js to prevent Proxy-related crashes.
23
- - **Typed Components**: Includes pre-defined components for `Line`, `Bar`, `Doughnut`, ...
24
- - **Registration Utilities**: Built-in helpers to register only what you need, keeping your bundle small.
25
- - **ESM-First**: Optimised for modern bundlers like Vite and Rspack.
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
- To keep the bundle lean, `solid-chart` does not register Chart.js components globally by default. We provide utilities to register exactly what you need in your entry point (e.g., `index.tsx`):
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
- If you have custom requirements or 3rd party plugins, use the exposed `registerComponent` helper:
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
- Using the library is straightforward. You can use the generic `DefaultChart` or any of the typed exports.
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`: Type-safe shortcuts.
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 | Raw access to Chart.register(...args). |
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 for any improvements, bug fixes, or new features. Be sure to follow best practices and ensure all tests pass before submitting.
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) file for details.
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 [solid-chartjs](https://github.com/s0ftik3/solid-chartjs), tailored to support modern SolidJS and Chart.js 4.5+ architectures. All credit for the original [solid-chartjs](https://github.com/s0ftik3/solid-chartjs) library and its initial implementation goes to the original [authors](https://github.com/s0ftik3).
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 solution. It was developed out of necessity for personal projects, and it may not meet the quality or stability standards required for a fully-fledged production environment. It is intended for personal use and experimentation, and contributions are highly encouraged to improve its functionality and stability.
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 [CHANGELOG.md](./CHANGELOG.md).
169
+ Detailed changes for each release are documented in the
170
+ [CHANGELOG.md](./CHANGELOG.md).
@@ -1,12 +1,12 @@
1
- import { template as x, use as D, insert as O, effect as T, setAttribute as w, createComponent as i, mergeProps as s } from "solid-js/web";
2
- import { mergeRefs as P } from "@solid-primitives/refs";
3
- import { Chart as S, PointElement as f, LinearScale as m, BubbleController as _, Legend as A, Tooltip as B, SubTitle as $, Colors as k, Title as q, ArcElement as v, DoughnutController as z, LineElement as L, CategoryScale as E, LineController as F, PieController as M, RadialLinearScale as R, PolarAreaController as j, RadarController as G, ScatterController as H, BarElement as I, BarController as J } from "chart.js";
4
- import { mergeProps as K, onMount as N, createEffect as p, on as d, onCleanup as Q } from "solid-js";
5
- import { unwrap as g } from "solid-js/store";
6
- var U = /* @__PURE__ */ x("<canvas>");
7
- const l = (e) => {
8
- let h = 0, c, o;
9
- const t = K({
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 (!c) return;
20
- if (!c.isConnected) {
21
- h++, h === 60 && console.warn("Solid-Chart: Canvas layout is delayed. Still retrying..."), requestAnimationFrame(C);
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
- h = 0;
25
- const n = c.getContext("2d"), r = {
26
- ...g(t.options)
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: b,
31
- ...u
34
+ r: v,
35
+ ...p
32
36
  } = r.scales;
33
- r.scales = u;
37
+ r.scales = p;
34
38
  }
35
- o = new S(n, {
39
+ o = new P(n, {
36
40
  type: t.type,
37
- data: g(t.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 N(() => C()), p(d(() => t.data, (n) => {
44
- o && (o.data = g(n), o.update("none"));
47
+ return _(() => C()), d(g(() => t.data, (n) => {
48
+ o && (o.data = f(n), o.update("none"));
45
49
  }, {
46
50
  defer: !0
47
- })), p(d(() => t.options, (n) => {
48
- o && (o.options = g(n), o.update());
51
+ })), d(g(() => t.options, (n) => {
52
+ o && (o.options = f(n), o.update());
49
53
  }, {
50
54
  defer: !0
51
- })), p(d([() => t.width, () => t.height], () => o?.resize(t.width, t.height), {
55
+ })), d(g([() => t.width, () => t.height], () => o?.resize(t.width, t.height), {
52
56
  defer: !0
53
- })), p(d(() => t.type, () => {
57
+ })), d(g(() => t.type, () => {
54
58
  o && (o.destroy(), C());
55
59
  }, {
56
60
  defer: !0
57
- })), Q(() => {
58
- o?.destroy(), P(e.ref, null);
61
+ })), I(() => {
62
+ o?.destroy(), w(e.ref, null);
59
63
  }), (() => {
60
- var n = U(), y = P(e.ref, (r) => c = r);
61
- return typeof y == "function" && D(y, n), O(n, () => t.fallback), T((r) => {
62
- var b = t.height, u = t.width;
63
- return b !== r.e && w(n, "height", r.e = b), u !== r.t && w(n, "width", r.t = u), r;
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) => S.register(...e), ee = () => a(B, A), te = () => a(q, B, A, k, $), re = () => a(F, E, m, f, L), oe = () => a(J, E, m, I), ne = () => a(G, R, f, L), ae = () => a(z, v), ie = () => a(M, v), se = () => a(j, R, v), le = () => a(_, m, f), ce = () => a(H, m, f), ue = (e) => i(l, s({
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
- }, e)), pe = (e) => i(l, s({
75
+ })), de = (e) => i(l, s(e, {
72
76
  type: "bar"
73
- }, e)), de = (e) => i(l, s({
77
+ })), ge = (e) => i(l, s(e, {
74
78
  type: "radar"
75
- }, e)), ge = (e) => i(l, s({
79
+ })), fe = (e) => i(l, s(e, {
76
80
  type: "doughnut"
77
- }, e)), fe = (e) => i(l, s({
81
+ })), he = (e) => i(l, s(e, {
78
82
  type: "polarArea"
79
- }, e)), me = (e) => i(l, s({
83
+ })), me = (e) => i(l, s(e, {
80
84
  type: "bubble"
81
- }, e)), he = (e) => i(l, s({
85
+ })), Ce = (e) => i(l, s(e, {
82
86
  type: "pie"
83
- }, e)), Ce = (e) => i(l, s({
87
+ })), ye = (e) => i(l, s(e, {
84
88
  type: "scatter"
85
- }, e));
89
+ }));
86
90
  export {
87
- pe as Bar,
91
+ de as Bar,
88
92
  me as Bubble,
89
93
  l as DefaultChart,
90
- ge as Doughnut,
91
- ue as Line,
92
- he as Pie,
93
- fe as PolarArea,
94
- de as Radar,
95
- Ce as Scatter,
96
- oe as registerBar,
97
- le as registerBubble,
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
- ee as registerCore,
100
- te as registerCoreExtra,
101
- ae as registerDoughnut,
102
- re as registerLine,
103
- ie as registerPie,
104
- se as registerPolarArea,
105
- ne as registerRadar,
106
- ce as registerScatter
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
@@ -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 type=\"line\" {...props} />;\nexport const Bar: TypedChart = (props) => <DefaultChart type=\"bar\" {...props} />;\nexport const Radar: TypedChart = (props) => <DefaultChart type=\"radar\" {...props} />;\nexport const Doughnut: TypedChart = (props) => <DefaultChart type=\"doughnut\" {...props} />;\nexport const PolarArea: TypedChart = (props) => <DefaultChart type=\"polarArea\" {...props} />;\nexport const Bubble: TypedChart = (props) => <DefaultChart type=\"bubble\" {...props} />;\nexport const Pie: TypedChart = (props) => <DefaultChart type=\"pie\" {...props} />;\nexport const Scatter: TypedChart = (props) => <DefaultChart type=\"scatter\" {...props} />;\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","registerSc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GACrE+F,KAAmB/F,CAAAA,MAAKwF,EAAMzF,GAAY0F,EAAA;AAAA,EAACjF,MAAI;AAAA,GAAWR,CAAK,CAAA,GAC/DgG,KAAuBhG,CAAAA,MAAKwF,EAAMzF,GAAY0F,EAAA;AAAA,EAACjF,MAAI;AAAA,GAAeR,CAAK,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,QAAQC,KAAK,0DAA0D,GAGrEf,KAAcH,GAAa;AAE7BiB,gBAAQE,MAAM,oEAAoE;AAClF;AAAA,MACF;AAEAC,4BAAsBL,CAAI;AAC1B;AAAA,IACF;AAGAZ,IAAAA,IAAa;AAEb,UAAMkB,IAAMjB,EAAUkB,WAAW,IAAI,GAI/BC,IAAgB;AAAA,MAAE,GADLC,EAAOlB,EAAOM,OAAO;AAAA,IACba;AAG3B,QAAInB,EAAOI,SAAS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,MAAI;AAAA,CAAA,CAAA,GAC3DmF,KAAmB3F,CAAAA,MAAKyF,EAAM1F,GAAY2F,EAAK1F,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA,GAC1DoF,KAAqB5F,CAAAA,MAAKyF,EAAM1F,GAAY2F,EAAK1F,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA,GAC5DqF,KAAwB7F,CAAAA,MAAKyF,EAAM1F,GAAY2F,EAAK1F,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA,GAC/DsF,KAAyB9F,CAAAA,MAAKyF,EAAM1F,GAAY2F,EAAK1F,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA,GAChEuF,KAAsB/F,CAAAA,MAAKyF,EAAM1F,GAAY2F,EAAK1F,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA,GAC7DwF,KAAmBhG,CAAAA,MAAKyF,EAAM1F,GAAY2F,EAAK1F,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA,GAC1DyF,KAAuBjG,CAAAA,MAAKyF,EAAM1F,GAAY2F,EAAK1F,GAAK;AAAA,EAAEQ,MAAI;AAAA,CAAA,CAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amad3v/solid-chart",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "author": {
5
5
  "name": "Mohamed JOUINI",
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-simple-import-sort": "^12.1.1",
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 --fix",
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 { mergeRefs } from '@solid-primitives/refs';
2
- import { Chart, ChartData, ChartItem, ChartOptions, Plugin } from 'chart.js';
3
- import { Component, createEffect, mergeProps, on, onCleanup, onMount } from 'solid-js';
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 { ChartProps } from './types';
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
- // Warn if it takes an abnormally long time (> 1 second)
37
+ // Warns every ~2 second if it's still failing
33
38
  // Assuming ~60fps, 60 retries is roughly 1 second.
34
- if (retryCount === 60) {
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
@@ -1,3 +1,5 @@
1
+ import type { ChartComponent } from 'chart.js';
2
+
1
3
  import {
2
4
  ArcElement,
3
5
  BarController,
@@ -5,7 +7,6 @@ import {
5
7
  BubbleController,
6
8
  CategoryScale,
7
9
  Chart,
8
- ChartComponent,
9
10
  Colors,
10
11
  DoughnutController,
11
12
  Legend,
@@ -1,17 +1,17 @@
1
- import { Component } from 'solid-js';
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'>;
8
8
  type TypedChart = Component<TypedChartProps>;
9
9
 
10
- export const Line: TypedChart = (props) => <DefaultChart type="line" {...props} />;
11
- export const Bar: TypedChart = (props) => <DefaultChart type="bar" {...props} />;
12
- export const Radar: TypedChart = (props) => <DefaultChart type="radar" {...props} />;
13
- export const Doughnut: TypedChart = (props) => <DefaultChart type="doughnut" {...props} />;
14
- export const PolarArea: TypedChart = (props) => <DefaultChart type="polarArea" {...props} />;
15
- export const Bubble: TypedChart = (props) => <DefaultChart type="bubble" {...props} />;
16
- export const Pie: TypedChart = (props) => <DefaultChart type="pie" {...props} />;
17
- export const Scatter: TypedChart = (props) => <DefaultChart type="scatter" {...props} />;
10
+ export const Line: TypedChart = (props) => <DefaultChart {...props} type="line" />;
11
+ export const Bar: TypedChart = (props) => <DefaultChart {...props} type="bar" />;
12
+ export const Radar: TypedChart = (props) => <DefaultChart {...props} type="radar" />;
13
+ export const Doughnut: TypedChart = (props) => <DefaultChart {...props} type="doughnut" />;
14
+ export const PolarArea: TypedChart = (props) => <DefaultChart {...props} type="polarArea" />;
15
+ export const Bubble: TypedChart = (props) => <DefaultChart {...props} type="bubble" />;
16
+ export const Pie: TypedChart = (props) => <DefaultChart {...props} type="pie" />;
17
+ export const Scatter: TypedChart = (props) => <DefaultChart {...props} type="scatter" />;