chartjs-plugin-chart2music 0.0.5 → 0.0.6

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
@@ -1,5 +1,5 @@
1
1
  # chartjs-plugin-chart2music
2
- chartjs plugin for chart2music.
2
+ [![npm version](https://badge.fury.io/js/chartjs-plugin-chart2music.svg)](https://badge.fury.io/js/chartjs-plugin-chart2music)
3
3
 
4
4
  **This is a beta release of this plugin**
5
5
 
@@ -13,9 +13,9 @@ Add the chartjs2music plugin to your existing chart.js code like this:
13
13
 
14
14
  ```js
15
15
  import {Chart} from "chart.js/auto";
16
- import plugin from "chartjs-plugin-chart2music";
16
+ import chartjs2music from "chartjs-plugin-chart2music";
17
17
 
18
- Chart.register(plugin);
18
+ Chart.register(chartjs2music);
19
19
  ```
20
20
 
21
21
  That will register the plugin globally. Alternatively, if you only want to enable for a given chart, you can do this:
@@ -36,12 +36,52 @@ new Chart(canvasElement, {
36
36
 
37
37
  ```
38
38
 
39
+ ## Available options
40
+
41
+ The following plugin options are available:
42
+ * `errorCallback` - A callback that will return errors if any arise while the plugin works.
43
+ * `cc` - the equivalent of the [chart2music option `cc`](https://chart2music.com/docs/API/Config#axes)
44
+ * `audioEngine` - the equivalent of the [chart2music option `audioEngine`](https://chart2music.com/docs/API/Config#cc)
45
+ * `axes` - the equivalent of the [chart2music option `axes`](https://chart2music.com/docs/API/Config#axes)
46
+
47
+ Here's an example for providing options:
48
+ ```js
49
+ import {Chart} from "chart.js/auto";
50
+ import chartjs2music from "chartjs-plugin-chart2music";
51
+
52
+ new Chart(canvasElement, {
53
+ type: "bar",
54
+ data: {
55
+ datasets: [{
56
+ data: [1,4,2,8]
57
+ }]
58
+ },
59
+ options: {
60
+ plugins: {
61
+ chartjs2music: {
62
+ // All errors should be logged as errors
63
+ errorCallback: console.error,
64
+ // Here's a div I made to be the CC
65
+ cc: myDiv,
66
+ // The Y values should all be money
67
+ axes: {
68
+ y: {
69
+ format: (value) => "$" + value
70
+ }
71
+ }
72
+ }
73
+ }
74
+ },
75
+ plugins: [chartjs2music]
76
+ });
77
+ ```
78
+
39
79
  ## Supported features
40
80
 
41
81
  This plugin is currently in beta, so not all of the chart.js features are currently supported.
42
82
 
43
83
  A quick list of chart.js features we currently support includes:
44
- * Chart types: bar, line, pie, doughnut, polar, radar, and combinations therein.
84
+ * Chart types: bar, doughnut, line, pie, polar, radar, scatter, and combinations therein.
45
85
  * Boxplots using the `@sgratzl/chartjs-chart-boxplot` plugin (only support boxplots when there are no other chart types present)
46
86
  * Wordclouds using the `chartjs-chart-wordcloud` plugin
47
87
  * Axes options: `title`, `min`, `max`, `type="linear"`, `type="logarithmic"`.
package/dist/plugin.js CHANGED
@@ -215,7 +215,7 @@ var chartjs2music = (function (c2mChart) {
215
215
  options.errorCallback?.(`Unable to connect chart2music to chart. The chart is of type "${invalidType}", which is not one of the supported chart types for this plugin. This plugin supports: ${Object.keys(chartjs_c2m_converter).join(", ")}`);
216
216
  return;
217
217
  }
218
- const axes = generateAxes(chart);
218
+ let axes = generateAxes(chart);
219
219
  if (chart.config.type === "wordCloud") {
220
220
  delete axes.x.minimum;
221
221
  delete axes.x.maximum;
@@ -242,6 +242,17 @@ var chartjs2music = (function (c2mChart) {
242
242
  delete scrub?.data;
243
243
  delete axes.x.valueLabels;
244
244
  }
245
+ axes = {
246
+ ...axes,
247
+ x: {
248
+ ...axes.x,
249
+ ...(options.axes?.x)
250
+ },
251
+ y: {
252
+ ...axes.y,
253
+ ...(options.axes?.y)
254
+ },
255
+ };
245
256
  const c2mOptions = {
246
257
  cc,
247
258
  element: chart.canvas,
package/dist/plugin.mjs CHANGED
@@ -214,7 +214,7 @@ const plugin = {
214
214
  options.errorCallback?.(`Unable to connect chart2music to chart. The chart is of type "${invalidType}", which is not one of the supported chart types for this plugin. This plugin supports: ${Object.keys(chartjs_c2m_converter).join(", ")}`);
215
215
  return;
216
216
  }
217
- const axes = generateAxes(chart);
217
+ let axes = generateAxes(chart);
218
218
  if (chart.config.type === "wordCloud") {
219
219
  delete axes.x.minimum;
220
220
  delete axes.x.maximum;
@@ -241,6 +241,17 @@ const plugin = {
241
241
  delete scrub?.data;
242
242
  delete axes.x.valueLabels;
243
243
  }
244
+ axes = {
245
+ ...axes,
246
+ x: {
247
+ ...axes.x,
248
+ ...(options.axes?.x)
249
+ },
250
+ y: {
251
+ ...axes.y,
252
+ ...(options.axes?.y)
253
+ },
254
+ };
244
255
  const c2mOptions = {
245
256
  cc,
246
257
  element: chart.canvas,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chartjs-plugin-chart2music",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "description": "Chart.js plugin for Chart2Music. Turns chart.js charts into music so the blind can hear data.",
6
6
  "main": "dist/plugin.js",