chartjs-plugin-chart2music 0.5.1 → 0.6.1
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 +10 -1
- package/dist/plugin.amd.js +459 -0
- package/dist/plugin.cjs +18 -16
- package/dist/plugin.js +7 -4
- package/dist/plugin.mjs +7 -4
- package/package.json +25 -20
package/README.md
CHANGED
|
@@ -77,6 +77,15 @@ new Chart(canvasElement, {
|
|
|
77
77
|
});
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
If you are using TypeScript, replace the first 4 lines with this:
|
|
81
|
+
```ts
|
|
82
|
+
import {Chart, type ChartTypeRegistry} from "chart.js/auto";
|
|
83
|
+
import chartjs2music from "chartjs-plugin-chart2music";
|
|
84
|
+
|
|
85
|
+
new Chart(canvasElement, {
|
|
86
|
+
type: "bar" as keyof ChartTypeRegistry,
|
|
87
|
+
```
|
|
88
|
+
|
|
80
89
|
## Supported features
|
|
81
90
|
|
|
82
91
|
This plugin is currently in beta, so not all of the chart.js features are currently supported.
|
|
@@ -88,6 +97,7 @@ A quick list of chart.js features we currently support includes:
|
|
|
88
97
|
* Axes options: `title`, `min`, `max`, `type="linear"`, `type="logarithmic"`.
|
|
89
98
|
* Chart title
|
|
90
99
|
* Most data structures (not including `parsing` or non-standard axes identifiers)
|
|
100
|
+
* Dataset visibility (when you show/hide a category from the legend)
|
|
91
101
|
|
|
92
102
|
Note that visual-specific chart features are ignored. This includes things like color, padding, line thickness, etc.
|
|
93
103
|
|
|
@@ -97,7 +107,6 @@ Things we plan to support in the future:
|
|
|
97
107
|
* Complex `parsing` options for data
|
|
98
108
|
* Date/Time support for axes
|
|
99
109
|
* Subtitle
|
|
100
|
-
* Dataset visibility (when you show/hide a category from the legend)
|
|
101
110
|
* Radar charts
|
|
102
111
|
* Custom formatting for axis tick values
|
|
103
112
|
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
define(['chart2music'], (function (c2mChart) { 'use strict';
|
|
2
|
+
|
|
3
|
+
const calcMedian = (nums) => (nums.length % 2) ? nums[Math.floor(nums.length / 2)] : (nums[nums.length / 2] + nums[nums.length / 2 - 1]) / 2;
|
|
4
|
+
const fiveNumberSummary = (nums) => {
|
|
5
|
+
const sortedNumbers = nums.sort();
|
|
6
|
+
let min, max, q1, q3;
|
|
7
|
+
const datamin = Math.min(...sortedNumbers);
|
|
8
|
+
const datamax = Math.max(...sortedNumbers);
|
|
9
|
+
const median = calcMedian(sortedNumbers);
|
|
10
|
+
const length = sortedNumbers.length;
|
|
11
|
+
if (length % 2) {
|
|
12
|
+
q1 = calcMedian(sortedNumbers.slice(0, Math.floor(length / 2)));
|
|
13
|
+
q3 = calcMedian(sortedNumbers.slice(Math.ceil(length % 2)));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
q1 = calcMedian(sortedNumbers.slice(0, length / 2 - 1));
|
|
17
|
+
q3 = calcMedian(sortedNumbers.slice(length / 2));
|
|
18
|
+
}
|
|
19
|
+
const iqr = q3 - q1;
|
|
20
|
+
if (datamax < q3 + iqr) {
|
|
21
|
+
max = datamax;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
max = sortedNumbers.reverse().find((num) => num < datamax) ?? datamax;
|
|
25
|
+
}
|
|
26
|
+
if (datamin < q1 - iqr) {
|
|
27
|
+
min = datamin;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
min = sortedNumbers.reverse().find((num) => num < datamin) ?? datamin;
|
|
31
|
+
}
|
|
32
|
+
const outlier = sortedNumbers.filter((num) => num < min || num > max);
|
|
33
|
+
return {
|
|
34
|
+
low: min,
|
|
35
|
+
high: max,
|
|
36
|
+
median,
|
|
37
|
+
q1,
|
|
38
|
+
q3,
|
|
39
|
+
...(outlier.length > 0 ? { outlier } : {})
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const whichBoxData = (data) => {
|
|
43
|
+
return data.map((row, index) => {
|
|
44
|
+
if (typeof row === "object" && "min" in row) {
|
|
45
|
+
return {
|
|
46
|
+
...row,
|
|
47
|
+
low: row.min,
|
|
48
|
+
high: row.max,
|
|
49
|
+
x: index,
|
|
50
|
+
...("outliers" in row ? { outlier: row.outliers } : {})
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (Array.isArray(row)) {
|
|
54
|
+
return {
|
|
55
|
+
...fiveNumberSummary(row),
|
|
56
|
+
x: index
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const processBoxData = (data) => {
|
|
62
|
+
if (data.datasets.length === 1) {
|
|
63
|
+
return {
|
|
64
|
+
data: whichBoxData(data.datasets[0].data)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const groups = [];
|
|
68
|
+
const result = {};
|
|
69
|
+
data.datasets.forEach((obj, index) => {
|
|
70
|
+
const groupName = obj.label ?? `Group ${index + 1}`;
|
|
71
|
+
groups.push(groupName);
|
|
72
|
+
result[groupName] = whichBoxData(obj.data);
|
|
73
|
+
});
|
|
74
|
+
return { groups, data: result };
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const chartStates = new Map();
|
|
78
|
+
const chartjs_c2m_converter = {
|
|
79
|
+
bar: "bar",
|
|
80
|
+
line: "line",
|
|
81
|
+
pie: "pie",
|
|
82
|
+
polarArea: "bar",
|
|
83
|
+
doughnut: "pie",
|
|
84
|
+
boxplot: "box",
|
|
85
|
+
radar: "bar",
|
|
86
|
+
wordCloud: "bar",
|
|
87
|
+
scatter: "scatter"
|
|
88
|
+
};
|
|
89
|
+
const processChartType = (chart) => {
|
|
90
|
+
const topLevelType = chart.config.type;
|
|
91
|
+
const panelTypes = chart.data.datasets.map(({ type }) => type ?? topLevelType);
|
|
92
|
+
const invalid = panelTypes.find((t) => !(t in chartjs_c2m_converter));
|
|
93
|
+
if (invalid) {
|
|
94
|
+
return {
|
|
95
|
+
valid: false,
|
|
96
|
+
invalidType: invalid
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if ([...new Set(panelTypes)].length === 1) {
|
|
100
|
+
return {
|
|
101
|
+
valid: true,
|
|
102
|
+
c2m_types: chartjs_c2m_converter[panelTypes[0]]
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
valid: true,
|
|
107
|
+
c2m_types: panelTypes.map((t) => chartjs_c2m_converter[t])
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const generateAxisInfo = (chartAxisInfo, chart) => {
|
|
111
|
+
const axis = {};
|
|
112
|
+
if (chartAxisInfo?.min !== undefined) {
|
|
113
|
+
if (typeof chartAxisInfo.min === "string") {
|
|
114
|
+
axis.minimum = chart.data.labels.indexOf(chartAxisInfo.min);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
axis.minimum = chartAxisInfo.min;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (chartAxisInfo?.max !== undefined) {
|
|
121
|
+
if (typeof chartAxisInfo.max === "string") {
|
|
122
|
+
axis.maximum = chart.data.labels.indexOf(chartAxisInfo.max);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
axis.maximum = chartAxisInfo.max;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const label = chartAxisInfo?.title?.text;
|
|
129
|
+
if (label) {
|
|
130
|
+
axis.label = label;
|
|
131
|
+
}
|
|
132
|
+
if (chartAxisInfo?.type === "logarithmic") {
|
|
133
|
+
axis.type = "log10";
|
|
134
|
+
}
|
|
135
|
+
return axis;
|
|
136
|
+
};
|
|
137
|
+
const generateAxes = (chart) => {
|
|
138
|
+
const axes = {
|
|
139
|
+
x: {
|
|
140
|
+
...generateAxisInfo(chart.options?.scales?.x, chart),
|
|
141
|
+
},
|
|
142
|
+
y: {
|
|
143
|
+
format: (value) => value.toLocaleString(),
|
|
144
|
+
...generateAxisInfo(chart.options?.scales?.y, chart),
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const xAxisValueLabels = chart.data.labels.slice(0);
|
|
148
|
+
if (xAxisValueLabels.length > 0) {
|
|
149
|
+
axes.x.valueLabels = xAxisValueLabels;
|
|
150
|
+
}
|
|
151
|
+
return axes;
|
|
152
|
+
};
|
|
153
|
+
const whichDataStructure = (data) => {
|
|
154
|
+
if (Array.isArray(data[0])) {
|
|
155
|
+
return data.map((arr, x) => {
|
|
156
|
+
let [low, high] = arr.sort();
|
|
157
|
+
return { x, low, high };
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return data;
|
|
161
|
+
};
|
|
162
|
+
const scrubX = (data) => {
|
|
163
|
+
const blackboard = JSON.parse(JSON.stringify(data));
|
|
164
|
+
let labels = [];
|
|
165
|
+
if (Array.isArray(data)) {
|
|
166
|
+
// console.log("not grouped");
|
|
167
|
+
// Not grouped
|
|
168
|
+
blackboard.forEach((item, x) => {
|
|
169
|
+
if (typeof item === "object" && item !== null && "x" in item) {
|
|
170
|
+
labels.push(item.x);
|
|
171
|
+
item.x = x;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return { labels, data: blackboard };
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const processData = (data, c2m_types) => {
|
|
178
|
+
if (c2m_types === "box") {
|
|
179
|
+
return processBoxData(data);
|
|
180
|
+
}
|
|
181
|
+
let groups = [];
|
|
182
|
+
if (data.datasets.length === 1) {
|
|
183
|
+
return {
|
|
184
|
+
data: whichDataStructure(data.datasets[0].data)
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const result = {};
|
|
188
|
+
data.datasets.forEach((obj, index) => {
|
|
189
|
+
const groupName = obj.label ?? `Group ${index + 1}`;
|
|
190
|
+
groups.push(groupName);
|
|
191
|
+
result[groupName] = whichDataStructure(obj.data);
|
|
192
|
+
});
|
|
193
|
+
return { groups, data: result };
|
|
194
|
+
};
|
|
195
|
+
const determineChartTitle = (options) => {
|
|
196
|
+
if (options.plugins?.title?.text) {
|
|
197
|
+
if (Array.isArray(options.plugins.title.text)) {
|
|
198
|
+
return options.plugins.title.text.join(", ");
|
|
199
|
+
}
|
|
200
|
+
return options.plugins.title.text;
|
|
201
|
+
}
|
|
202
|
+
return "";
|
|
203
|
+
};
|
|
204
|
+
const determineCCElement = (canvas, provided) => {
|
|
205
|
+
if (provided) {
|
|
206
|
+
return provided;
|
|
207
|
+
}
|
|
208
|
+
const cc = document.createElement("div");
|
|
209
|
+
canvas.insertAdjacentElement("afterend", cc);
|
|
210
|
+
return cc;
|
|
211
|
+
};
|
|
212
|
+
const displayPoint = (chart) => {
|
|
213
|
+
if (!chartStates.has(chart)) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const { c2m: ref, visible_groups } = chartStates.get(chart);
|
|
217
|
+
const { point, index } = ref.getCurrent();
|
|
218
|
+
try {
|
|
219
|
+
const highlightElements = [];
|
|
220
|
+
if ("custom" in point) {
|
|
221
|
+
highlightElements.push({
|
|
222
|
+
// @ts-ignore
|
|
223
|
+
datasetIndex: point.custom.group,
|
|
224
|
+
// @ts-ignore
|
|
225
|
+
index: point.custom.index
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
visible_groups.forEach((datasetIndex) => {
|
|
230
|
+
highlightElements.push({
|
|
231
|
+
datasetIndex,
|
|
232
|
+
index
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
chart?.setActiveElements(highlightElements);
|
|
237
|
+
chart?.tooltip?.setActiveElements(highlightElements, {});
|
|
238
|
+
chart?.update();
|
|
239
|
+
}
|
|
240
|
+
catch (e) {
|
|
241
|
+
// console.warn(e);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
const generateChart = (chart, options) => {
|
|
245
|
+
const { valid, c2m_types, invalidType } = processChartType(chart);
|
|
246
|
+
if (!valid) {
|
|
247
|
+
// @ts-ignore
|
|
248
|
+
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(", ")}`);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
let axes = generateAxes(chart);
|
|
252
|
+
if (chart.config.type === "wordCloud") {
|
|
253
|
+
delete axes.x.minimum;
|
|
254
|
+
delete axes.x.maximum;
|
|
255
|
+
delete axes.y.minimum;
|
|
256
|
+
delete axes.y.maximum;
|
|
257
|
+
if (!axes.x.label) {
|
|
258
|
+
axes.x.label = "Word";
|
|
259
|
+
}
|
|
260
|
+
if (!axes.y.label) {
|
|
261
|
+
axes.y.label = "Emphasis";
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// Generate CC element
|
|
265
|
+
const cc = determineCCElement(chart.canvas, options.cc);
|
|
266
|
+
const { data, groups } = processData(chart.data, c2m_types);
|
|
267
|
+
// lastDataObj = JSON.stringify(data);
|
|
268
|
+
let scrub = scrubX(data);
|
|
269
|
+
if (scrub?.labels && scrub?.labels?.length > 0) { // Something was scrubbed
|
|
270
|
+
if (!chart.data.labels || chart.data.labels.length === 0) {
|
|
271
|
+
axes.x.valueLabels = scrub.labels.slice(0);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (c2m_types === "scatter") {
|
|
275
|
+
delete scrub?.data;
|
|
276
|
+
delete axes.x.valueLabels;
|
|
277
|
+
}
|
|
278
|
+
axes = {
|
|
279
|
+
...axes,
|
|
280
|
+
x: {
|
|
281
|
+
...axes.x,
|
|
282
|
+
...(options.axes?.x)
|
|
283
|
+
},
|
|
284
|
+
y: {
|
|
285
|
+
...axes.y,
|
|
286
|
+
...(options.axes?.y)
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
const c2mOptions = {
|
|
290
|
+
cc,
|
|
291
|
+
element: chart.canvas,
|
|
292
|
+
type: c2m_types,
|
|
293
|
+
data: scrub?.data ?? data,
|
|
294
|
+
title: determineChartTitle(chart.options),
|
|
295
|
+
axes,
|
|
296
|
+
options: {
|
|
297
|
+
// @ts-ignore
|
|
298
|
+
onFocusCallback: () => {
|
|
299
|
+
displayPoint(chart);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
if (Array.isArray(c2mOptions.data)) {
|
|
304
|
+
if (isNaN(c2mOptions.data[0])) {
|
|
305
|
+
c2mOptions.data = c2mOptions.data.map((point, index) => {
|
|
306
|
+
return {
|
|
307
|
+
...point,
|
|
308
|
+
custom: {
|
|
309
|
+
group: 0,
|
|
310
|
+
index
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
c2mOptions.data = c2mOptions.data.map((num, index) => {
|
|
317
|
+
return {
|
|
318
|
+
x: index,
|
|
319
|
+
y: num,
|
|
320
|
+
custom: {
|
|
321
|
+
group: 0,
|
|
322
|
+
index
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
const groups = Object.keys(c2mOptions.data);
|
|
330
|
+
groups.forEach((groupName, groupNumber) => {
|
|
331
|
+
if (!isNaN(c2mOptions.data[groupName][0])) {
|
|
332
|
+
c2mOptions.data[groupName] = c2mOptions.data[groupName].map((num, index) => {
|
|
333
|
+
return {
|
|
334
|
+
x: index,
|
|
335
|
+
y: num,
|
|
336
|
+
custom: {
|
|
337
|
+
group: groupNumber,
|
|
338
|
+
index
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
c2mOptions.data[groupName] = c2mOptions.data[groupName].map((point, index) => {
|
|
345
|
+
return {
|
|
346
|
+
...point,
|
|
347
|
+
custom: {
|
|
348
|
+
group: groupNumber,
|
|
349
|
+
index
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
// @ts-ignore
|
|
357
|
+
if (chart.config.options?.scales?.x?.stacked) {
|
|
358
|
+
// @ts-ignore
|
|
359
|
+
c2mOptions.options.stack = true;
|
|
360
|
+
}
|
|
361
|
+
// @ts-ignore
|
|
362
|
+
if (options.audioEngine) {
|
|
363
|
+
// @ts-ignore
|
|
364
|
+
c2mOptions.audioEngine = options.audioEngine;
|
|
365
|
+
}
|
|
366
|
+
if (c2mOptions.data.length === 0) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (options.lang) {
|
|
370
|
+
c2mOptions.lang = options.lang;
|
|
371
|
+
}
|
|
372
|
+
const { err, data: c2m } = c2mChart(c2mOptions);
|
|
373
|
+
/* istanbul-ignore-next */
|
|
374
|
+
if (err) {
|
|
375
|
+
// @ts-ignore
|
|
376
|
+
options.errorCallback?.(err);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (!c2m) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
chartStates.set(chart, {
|
|
383
|
+
c2m,
|
|
384
|
+
visible_groups: groups?.map((g, i) => i) ?? []
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
const plugin = {
|
|
388
|
+
id: "chartjs2music",
|
|
389
|
+
afterInit: (chart, args, options) => {
|
|
390
|
+
if (!chartStates.has(chart)) {
|
|
391
|
+
generateChart(chart, options);
|
|
392
|
+
// Remove tooltip when the chart blurs
|
|
393
|
+
chart.canvas.addEventListener("blur", () => {
|
|
394
|
+
chart.setActiveElements([]);
|
|
395
|
+
chart.tooltip?.setActiveElements([], {});
|
|
396
|
+
try {
|
|
397
|
+
chart.update();
|
|
398
|
+
}
|
|
399
|
+
catch (e) {
|
|
400
|
+
// console.warn(e);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
// Show tooltip when the chart receives focus
|
|
404
|
+
chart.canvas.addEventListener("focus", () => {
|
|
405
|
+
displayPoint(chart);
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
afterDatasetUpdate: (chart, args, options) => {
|
|
410
|
+
if (!args.mode) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (!chartStates.has(chart)) {
|
|
414
|
+
generateChart(chart, options);
|
|
415
|
+
}
|
|
416
|
+
const { c2m: ref, visible_groups } = chartStates.get(chart);
|
|
417
|
+
if (!ref) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
// @ts-ignore
|
|
421
|
+
const groups = ref._groups.slice(0);
|
|
422
|
+
// @ts-ignore
|
|
423
|
+
if (ref._options.stack) {
|
|
424
|
+
groups.shift();
|
|
425
|
+
}
|
|
426
|
+
if (args.mode === "hide") {
|
|
427
|
+
const err = ref.setCategoryVisibility(groups[args.index], false);
|
|
428
|
+
visible_groups.splice(args.index, 1);
|
|
429
|
+
if (err) {
|
|
430
|
+
console.error(err);
|
|
431
|
+
}
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (args.mode === "show") {
|
|
435
|
+
const err = ref.setCategoryVisibility(groups[args.index], true);
|
|
436
|
+
visible_groups.push(args.index);
|
|
437
|
+
if (err) {
|
|
438
|
+
console.error(err);
|
|
439
|
+
}
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
afterDestroy: (chart) => {
|
|
444
|
+
const { c2m: ref } = chartStates.get(chart);
|
|
445
|
+
if (!ref) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
ref.cleanUp();
|
|
449
|
+
},
|
|
450
|
+
defaults: {
|
|
451
|
+
cc: null,
|
|
452
|
+
audioEngine: null,
|
|
453
|
+
errorCallback: null
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
return plugin;
|
|
458
|
+
|
|
459
|
+
}));
|
package/dist/plugin.cjs
CHANGED
|
@@ -5,23 +5,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _chart2music = _interopRequireDefault(require("chart2music"));
|
|
8
|
-
function _interopRequireDefault(
|
|
9
|
-
function _slicedToArray(
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
10
10
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
11
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
-
function _arrayWithHoles(
|
|
12
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
13
13
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
14
14
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
15
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
-
function _defineProperty(
|
|
16
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
17
17
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
18
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
-
function _toConsumableArray(
|
|
19
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
20
20
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
-
function _unsupportedIterableToArray(
|
|
22
|
-
function _iterableToArray(
|
|
23
|
-
function _arrayWithoutHoles(
|
|
24
|
-
function _arrayLikeToArray(
|
|
21
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
22
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
23
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
24
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
25
25
|
var calcMedian = function calcMedian(nums) {
|
|
26
26
|
return nums.length % 2 ? nums[Math.floor(nums.length / 2)] : (nums[nums.length / 2] + nums[nums.length / 2 - 1]) / 2;
|
|
27
27
|
};
|
|
@@ -149,14 +149,14 @@ var processChartType = function processChartType(chart) {
|
|
|
149
149
|
var generateAxisInfo = function generateAxisInfo(chartAxisInfo, chart) {
|
|
150
150
|
var _chartAxisInfo$title;
|
|
151
151
|
var axis = {};
|
|
152
|
-
if (chartAxisInfo
|
|
152
|
+
if ((chartAxisInfo === null || chartAxisInfo === void 0 ? void 0 : chartAxisInfo.min) !== undefined) {
|
|
153
153
|
if (typeof chartAxisInfo.min === "string") {
|
|
154
154
|
axis.minimum = chart.data.labels.indexOf(chartAxisInfo.min);
|
|
155
155
|
} else {
|
|
156
156
|
axis.minimum = chartAxisInfo.min;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
if (chartAxisInfo
|
|
159
|
+
if ((chartAxisInfo === null || chartAxisInfo === void 0 ? void 0 : chartAxisInfo.max) !== undefined) {
|
|
160
160
|
if (typeof chartAxisInfo.max === "string") {
|
|
161
161
|
axis.maximum = chart.data.labels.indexOf(chartAxisInfo.max);
|
|
162
162
|
} else {
|
|
@@ -175,15 +175,17 @@ var generateAxisInfo = function generateAxisInfo(chartAxisInfo, chart) {
|
|
|
175
175
|
var generateAxes = function generateAxes(chart) {
|
|
176
176
|
var _chart$options, _chart$options2;
|
|
177
177
|
var axes = {
|
|
178
|
-
x: _objectSpread(
|
|
179
|
-
|
|
180
|
-
}),
|
|
181
|
-
y: _objectSpread(_objectSpread({}, generateAxisInfo((_chart$options2 = chart.options) === null || _chart$options2 === void 0 || (_chart$options2 = _chart$options2.scales) === null || _chart$options2 === void 0 ? void 0 : _chart$options2.y, chart)), {}, {
|
|
178
|
+
x: _objectSpread({}, generateAxisInfo((_chart$options = chart.options) === null || _chart$options === void 0 || (_chart$options = _chart$options.scales) === null || _chart$options === void 0 ? void 0 : _chart$options.x, chart)),
|
|
179
|
+
y: _objectSpread({
|
|
182
180
|
format: function format(value) {
|
|
183
181
|
return value.toLocaleString();
|
|
184
182
|
}
|
|
185
|
-
})
|
|
183
|
+
}, generateAxisInfo((_chart$options2 = chart.options) === null || _chart$options2 === void 0 || (_chart$options2 = _chart$options2.scales) === null || _chart$options2 === void 0 ? void 0 : _chart$options2.y, chart))
|
|
186
184
|
};
|
|
185
|
+
var xAxisValueLabels = chart.data.labels.slice(0);
|
|
186
|
+
if (xAxisValueLabels.length > 0) {
|
|
187
|
+
axes.x.valueLabels = xAxisValueLabels;
|
|
188
|
+
}
|
|
187
189
|
return axes;
|
|
188
190
|
};
|
|
189
191
|
var whichDataStructure = function whichDataStructure(data) {
|
package/dist/plugin.js
CHANGED
|
@@ -110,7 +110,7 @@ var chartjs2music = (function (c2mChart) {
|
|
|
110
110
|
};
|
|
111
111
|
const generateAxisInfo = (chartAxisInfo, chart) => {
|
|
112
112
|
const axis = {};
|
|
113
|
-
if (chartAxisInfo?.min) {
|
|
113
|
+
if (chartAxisInfo?.min !== undefined) {
|
|
114
114
|
if (typeof chartAxisInfo.min === "string") {
|
|
115
115
|
axis.minimum = chart.data.labels.indexOf(chartAxisInfo.min);
|
|
116
116
|
}
|
|
@@ -118,7 +118,7 @@ var chartjs2music = (function (c2mChart) {
|
|
|
118
118
|
axis.minimum = chartAxisInfo.min;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
if (chartAxisInfo?.max) {
|
|
121
|
+
if (chartAxisInfo?.max !== undefined) {
|
|
122
122
|
if (typeof chartAxisInfo.max === "string") {
|
|
123
123
|
axis.maximum = chart.data.labels.indexOf(chartAxisInfo.max);
|
|
124
124
|
}
|
|
@@ -139,13 +139,16 @@ var chartjs2music = (function (c2mChart) {
|
|
|
139
139
|
const axes = {
|
|
140
140
|
x: {
|
|
141
141
|
...generateAxisInfo(chart.options?.scales?.x, chart),
|
|
142
|
-
valueLabels: chart.data.labels.slice(0)
|
|
143
142
|
},
|
|
144
143
|
y: {
|
|
144
|
+
format: (value) => value.toLocaleString(),
|
|
145
145
|
...generateAxisInfo(chart.options?.scales?.y, chart),
|
|
146
|
-
format: (value) => value.toLocaleString()
|
|
147
146
|
}
|
|
148
147
|
};
|
|
148
|
+
const xAxisValueLabels = chart.data.labels.slice(0);
|
|
149
|
+
if (xAxisValueLabels.length > 0) {
|
|
150
|
+
axes.x.valueLabels = xAxisValueLabels;
|
|
151
|
+
}
|
|
149
152
|
return axes;
|
|
150
153
|
};
|
|
151
154
|
const whichDataStructure = (data) => {
|
package/dist/plugin.mjs
CHANGED
|
@@ -109,7 +109,7 @@ const processChartType = (chart) => {
|
|
|
109
109
|
};
|
|
110
110
|
const generateAxisInfo = (chartAxisInfo, chart) => {
|
|
111
111
|
const axis = {};
|
|
112
|
-
if (chartAxisInfo?.min) {
|
|
112
|
+
if (chartAxisInfo?.min !== undefined) {
|
|
113
113
|
if (typeof chartAxisInfo.min === "string") {
|
|
114
114
|
axis.minimum = chart.data.labels.indexOf(chartAxisInfo.min);
|
|
115
115
|
}
|
|
@@ -117,7 +117,7 @@ const generateAxisInfo = (chartAxisInfo, chart) => {
|
|
|
117
117
|
axis.minimum = chartAxisInfo.min;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
if (chartAxisInfo?.max) {
|
|
120
|
+
if (chartAxisInfo?.max !== undefined) {
|
|
121
121
|
if (typeof chartAxisInfo.max === "string") {
|
|
122
122
|
axis.maximum = chart.data.labels.indexOf(chartAxisInfo.max);
|
|
123
123
|
}
|
|
@@ -138,13 +138,16 @@ const generateAxes = (chart) => {
|
|
|
138
138
|
const axes = {
|
|
139
139
|
x: {
|
|
140
140
|
...generateAxisInfo(chart.options?.scales?.x, chart),
|
|
141
|
-
valueLabels: chart.data.labels.slice(0)
|
|
142
141
|
},
|
|
143
142
|
y: {
|
|
143
|
+
format: (value) => value.toLocaleString(),
|
|
144
144
|
...generateAxisInfo(chart.options?.scales?.y, chart),
|
|
145
|
-
format: (value) => value.toLocaleString()
|
|
146
145
|
}
|
|
147
146
|
};
|
|
147
|
+
const xAxisValueLabels = chart.data.labels.slice(0);
|
|
148
|
+
if (xAxisValueLabels.length > 0) {
|
|
149
|
+
axes.x.valueLabels = xAxisValueLabels;
|
|
150
|
+
}
|
|
148
151
|
return axes;
|
|
149
152
|
};
|
|
150
153
|
const whichDataStructure = (data) => {
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chartjs-plugin-chart2music",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|
|
7
7
|
"module": "dist/plugin.mjs",
|
|
8
8
|
"exports": {
|
|
9
|
-
"import":
|
|
9
|
+
"import": {
|
|
10
|
+
"default": "./dist/plugin.mjs",
|
|
11
|
+
"types": "./dist/plugin.d.ts"
|
|
12
|
+
},
|
|
10
13
|
"require": "./dist/plugin.cjs"
|
|
11
14
|
},
|
|
12
15
|
"types": "dist/plugin.d.ts",
|
|
@@ -40,30 +43,32 @@
|
|
|
40
43
|
"prepack": "npm run clean && npm run build"
|
|
41
44
|
},
|
|
42
45
|
"devDependencies": {
|
|
43
|
-
"@babel/cli": "7.
|
|
44
|
-
"@babel/core": "7.
|
|
45
|
-
"@babel/plugin-transform-modules-commonjs": "7.
|
|
46
|
-
"@babel/preset-env": "7.
|
|
47
|
-
"@rollup/plugin-typescript": "
|
|
48
|
-
"@sgratzl/chartjs-chart-boxplot": "4.
|
|
49
|
-
"@types/jest": "29.5.
|
|
50
|
-
"canvas": "
|
|
51
|
-
"chartjs-
|
|
52
|
-
"chartjs-
|
|
46
|
+
"@babel/cli": "7.27.0",
|
|
47
|
+
"@babel/core": "7.26.10",
|
|
48
|
+
"@babel/plugin-transform-modules-commonjs": "7.26.3",
|
|
49
|
+
"@babel/preset-env": "7.26.9",
|
|
50
|
+
"@rollup/plugin-typescript": "12.1.2",
|
|
51
|
+
"@sgratzl/chartjs-chart-boxplot": "4.4.4",
|
|
52
|
+
"@types/jest": "29.5.14",
|
|
53
|
+
"canvas": "3.1.0",
|
|
54
|
+
"chartjs-adapter-luxon": "1.3.1",
|
|
55
|
+
"chartjs-chart-wordcloud": "4.4.4",
|
|
56
|
+
"chartjs-plugin-a11y-legend": "0.2.1",
|
|
53
57
|
"cross-env": "7.0.3",
|
|
54
58
|
"depcheck": "1.4.7",
|
|
55
59
|
"jest": "29.7.0",
|
|
56
60
|
"jest-environment-jsdom": "29.7.0",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
61
|
+
"luxon": "3.6.1",
|
|
62
|
+
"rimraf": "6.0.1",
|
|
63
|
+
"rollup": "4.40.0",
|
|
59
64
|
"rollup-plugin-copy": "3.5.0",
|
|
60
|
-
"ts-jest": "29.
|
|
61
|
-
"tslib": "2.
|
|
62
|
-
"typescript": "5.
|
|
63
|
-
"vite": "
|
|
65
|
+
"ts-jest": "29.3.2",
|
|
66
|
+
"tslib": "2.8.1",
|
|
67
|
+
"typescript": "5.8.3",
|
|
68
|
+
"vite": "6.2.6"
|
|
64
69
|
},
|
|
65
70
|
"dependencies": {
|
|
66
|
-
"chart.js": "4.4.
|
|
67
|
-
"chart2music": "1.
|
|
71
|
+
"chart.js": "4.4.8",
|
|
72
|
+
"chart2music": "1.18.1"
|
|
68
73
|
}
|
|
69
74
|
}
|