|
1 |
| -"use strict"; |
| 1 | +'use strict'; |
2 | 2 |
|
3 |
| -var underlyingModule = import('chart2music'); |
| 3 | +var c2m = require('chart2music'); |
| 4 | +var Fx = require('../components/fx'); |
4 | 5 |
|
5 |
| - |
6 |
| -const supportedAccessibilityLibraries = ['chart2music']; |
| 6 | +var supportedAccessibilityLibraries = ['chart2music']; |
7 | 7 |
|
8 | 8 | function enable(gd) {
|
9 |
| - const {library, options} = gd._context.accessibility; |
10 |
| - if (!supportedAccessibilityLibraries.includes(library)) { |
| 9 | + var accessibilityVars = gd._context.accessibility; |
| 10 | + var library = accessibilityVars.library; |
| 11 | + var options = accessibilityVars.options; |
| 12 | + if(!supportedAccessibilityLibraries.includes(library)) { |
11 | 13 | // 'Accessibility not implemented for library: ' + library
|
12 | 14 | return;
|
13 | 15 | }
|
14 |
| - console.log("We're enabled!"); |
15 |
| - if (library === 'chart2music') { |
16 |
| - console.log("Library === chart2music"); |
17 |
| - const c2mData = {}; |
18 |
| - const labels = []; |
19 |
| - const info = options.info; |
| 16 | + if(library === 'chart2music') { |
| 17 | + var c2mData = {}; |
| 18 | + var labels = []; |
| 19 | + var info = options.info; |
20 | 20 | delete options.info;
|
21 |
| - const fullData = gd._fullData; |
| 21 | + var fullData = gd._fullData; |
22 | 22 |
|
23 | 23 | for(var i = 0; i < fullData.length; i++) {
|
24 |
| - var trace = fullData[i] ?? {}; |
25 |
| - var {type, x = [], y = [], name = i, text = []} = trace; |
| 24 | + var trace = fullData[i] ? fullData[i] : {}; |
| 25 | + var type = trace.type; |
| 26 | + var x = trace.x ? trace.x : []; |
| 27 | + var y = trace.y ? trace.y : []; |
| 28 | + var name = trace.name ? trace.name : i; |
| 29 | + var text = trace.text ? trace.text : []; |
26 | 30 | if(type === 'scatter') {
|
27 |
| - console.log("Found a scatter"); |
28 | 31 | var traceData = [];
|
29 |
| - if ('y' in trace) { |
| 32 | + if('y' in trace) { |
30 | 33 | for(var p = 0; p < y.length; p++) {
|
31 | 34 | traceData.push(
|
32 | 35 | {
|
33 | 36 | x: x.length > 0 ? x[p] : p,
|
34 | 37 | y: y[p],
|
35 |
| - label: text[p] ?? p |
36 |
| - }) |
| 38 | + label: text[p] ? text[p] : p |
| 39 | + }); |
37 | 40 | }
|
38 |
| - console.log("TraceData.length: " + String(traceData.length)); |
39 | 41 | c2mData[name] = traceData;
|
40 | 42 | labels.push(name);
|
41 | 43 | }
|
42 |
| - } |
43 |
| - else { |
| 44 | + } else { |
44 | 45 | // 'Accessibility not implemented for trace type: ' + trace.type
|
45 |
| - console.log("Accessibility not implemented for trace type."); |
46 | 46 | return;
|
47 |
| - }; |
48 |
| - }; |
49 |
| - |
50 |
| - var closed_captions = document.createElement('div'); |
51 |
| - closed_captions.id = 'cc'; |
52 |
| - closed_captions.className = 'closed_captions'; |
53 |
| - gd.appendChild(closed_captions); // this does get generated |
| 47 | + } |
| 48 | + } |
54 | 49 |
|
55 |
| - const { |
56 |
| - title: {text: title_text = ''} = {}, |
57 |
| - xaxis: {title: {text: xaxis_text = ''} = {}} = {}, |
58 |
| - yaxis: {title: {text: yaxis_text = ''} = {}} = {}, |
59 |
| - } = gd._fullLayout; // I do not understand this notation that well anyway. |
| 50 | + var closedCaptions = document.createElement('div'); |
| 51 | + closedCaptions.id = 'cc'; |
| 52 | + closedCaptions.className = 'closed_captions'; |
| 53 | + gd.appendChild(closedCaptions); // this does get generated |
60 | 54 |
|
61 |
| - return underlyingModule.then( function(mod) { |
62 |
| - console.log("Got underlying module!"); |
63 |
| - console.log(mod); |
64 |
| - var ret = mod.c2mChart({ |
65 |
| - title: title_text, |
66 |
| - type: "line", |
67 |
| - axes: { |
68 |
| - x: { |
69 |
| - label: xaxis_text |
70 |
| - }, |
71 |
| - y: { |
72 |
| - label: yaxis_text |
73 |
| - } |
| 55 | + var titleText = gd._fullLayout.title.text ? gd._fullLayout.title.text : 'Chart'; |
| 56 | + var xaxisText = gd._fullLayout.xaxis.title.text ? gd._fullLayout.xaxis.title.text : 'X Axis'; |
| 57 | + var yaxisText = gd._fullLayout.yaxis.title.text ? gd._fullLayout.yaxis.title.text : 'Y Axis'; |
| 58 | + options.onFocusCallback = function(dataInfo) { |
| 59 | + Fx.hover(gd, [{ |
| 60 | + curveNumber: labels.indexOf(dataInfo.slice), |
| 61 | + pointNumber: dataInfo.index |
| 62 | + }]); |
| 63 | + }; |
| 64 | + c2m.c2mChart({ |
| 65 | + title: titleText, |
| 66 | + type: 'line', |
| 67 | + axes: { |
| 68 | + x: { |
| 69 | + label: xaxisText |
74 | 70 | },
|
75 |
| - element: gd, |
76 |
| - cc: closed_captions, |
77 |
| - data: c2mData, |
78 |
| - options: { |
79 |
| - onFocusCallback: ({slice, index}) => { |
80 |
| - Plotly.Fx.hover(gd, [{ |
81 |
| - curveNumber: labels.indexOf(slice), |
82 |
| - pointNumber: index |
83 |
| - }]) |
84 |
| - }, |
85 |
| - ...options |
| 71 | + y: { |
| 72 | + label: yaxisText |
86 | 73 | },
|
87 |
| - info: info |
88 |
| - }); |
89 |
| - console.log(ret); |
| 74 | + }, |
| 75 | + element: gd, |
| 76 | + cc: closedCaptions, |
| 77 | + data: c2mData, |
| 78 | + options: options, |
| 79 | + info: info |
90 | 80 | });
|
91 |
| - }; |
92 |
| -}; |
93 |
| -module.exports = { enable }; |
| 81 | + } |
| 82 | +} |
| 83 | +exports.enable = enable; |
0 commit comments