Skip to content

Commit 80b4cf3

Browse files
authored
Merge pull request plotly#2 from geopozo/pikul-music-import-promise
FIX and Add options to chart2music plotly integration
2 parents 2429e55 + af2ff80 commit 80b4cf3

File tree

12 files changed

+92
-29
lines changed

12 files changed

+92
-29
lines changed

devtools/test_dashboard/index-mathjax3.html

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ <h4>no MathJax: Apple: $2, Orange: $3</h4>
2424
<div id="graph"></div>
2525
</div>
2626
<div id="snapshot"></div>
27+
<div style="position:absolute; border-top: .3em solid #eee; bottom: 0px; left: 0; width: 100%">
28+
<div style="margin-top: -1.2em; padding-left: 3px; font-weight: bold; color: #555; width:100%;">Closed Captions</div>
29+
<div id="c2m-plotly-cc" style="width: 100%; height: 40px; padding: 18px 0 0 15px; color: #333">Test</div>
30+
</div>
2731

2832
<script>
2933
window.MathJax = {

devtools/test_dashboard/index-mathjax3chtml.html

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
<div id="graph"></div>
2323
</div>
2424
<div id="snapshot"></div>
25+
<div style="position:absolute; border-top: .3em solid #eee; bottom: 0px; left: 0; width: 100%">
26+
<div style="margin-top: -1.2em; padding-left: 3px; font-weight: bold; color: #555; width:100%;">Closed Captions</div>
27+
<div id="c2m-plotly-cc" style="width: 100%; height: 40px; padding: 18px 0 0 15px; color: #333">Test</div>
28+
</div>
2529

2630
<script>
2731
window.MathJax = window.MathJax || {

devtools/test_dashboard/index-strict.html

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
<div id="graph"></div>
2222
</div>
2323
<div id="snapshot"></div>
24+
<div style="position:absolute; border-top: .3em solid #eee; bottom: 0px; left: 0; width: 100%">
25+
<div style="margin-top: -1.2em; padding-left: 3px; font-weight: bold; color: #555; width:100%;">Closed Captions</div>
26+
<div id="c2m-plotly-cc" style="width: 100%; height: 40px; padding: 18px 0 0 15px; color: #333">Test</div>
27+
</div>
2428

2529
<script src="../../node_modules/mathjax-v2/MathJax.js?config=TeX-AMS-MML_SVG"></script>
2630
<script charset="utf-8" id="source" src="../../build/plotly.js"></script>

devtools/test_dashboard/index.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
<div id="graph"></div>
2121
</div>
2222
<div id="snapshot"></div>
23-
23+
<div style="position:absolute; border-top: .3em solid #eee; bottom: 0px; left: 0; width: 100%">
24+
<div style="margin-top: -1.2em; padding-left: 3px; font-weight: bold; color: #555; width:100%;">Closed Captions</div>
25+
<div id="c2m-plotly-cc" style="width: 100%; height: 40px; padding: 18px 0 0 15px; color: #333">Test</div>
26+
</div>
2427
<script src="../../node_modules/mathjax-v2/MathJax.js?config=TeX-AMS-MML_SVG"></script>
2528
<script charset="utf-8" id="source" src="../../build/plotly.js" type="module"></script>
2629
<script charset="utf-8" src="../../build/test_dashboard-bundle.js"></script>

draftlogs/6866_change.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add 'decimal' and 'thousands' formats for Brazilian Portuguese locale file [[#6866](https://github.com/plotly/plotly.js/pull/6866)], with thanks to @pazuza for the contribution!

lib/locales/pt-br.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ module.exports = {
7878
'Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun',
7979
'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'
8080
],
81-
date: '%d/%m/%Y'
81+
date: '%d/%m/%Y',
82+
decimal: ',',
83+
thousands: '.'
8284
}
8385
};

src/plot_api/accessibility.js

+46-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var Lib = require('../lib');
34
var c2m = require('chart2music');
45
var Fx = require('../components/fx');
56

@@ -9,24 +10,23 @@ function enable(gd) {
910
var accessibilityVars = gd._context.accessibility;
1011
var library = accessibilityVars.library;
1112
var options = accessibilityVars.options;
13+
var info = accessibilityVars.info;
14+
var closedCaptionsOptions = accessibilityVars.closedCaptions;
1215
if(!supportedAccessibilityLibraries.includes(library)) {
1316
// 'Accessibility not implemented for library: ' + library
1417
return;
1518
}
1619
if(library === 'chart2music') {
1720
var c2mData = {};
1821
var labels = [];
19-
var info = options.info;
20-
delete options.info;
2122
var fullData = gd._fullData;
22-
2323
for(var i = 0; i < fullData.length; i++) {
2424
var trace = fullData[i] ? fullData[i] : {};
2525
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+
var x = trace.x !== undefined ? trace.x : [];
27+
var y = trace.y !== undefined ? trace.y : [];
28+
var name = trace.name !== undefined ? trace.name : i;
29+
var text = trace.text !== undefined ? trace.text : [];
3030
if(type === 'scatter') {
3131
var traceData = [];
3232
if('y' in trace) {
@@ -38,6 +38,7 @@ function enable(gd) {
3838
label: text[p] ? text[p] : p
3939
});
4040
}
41+
if(traceData.length === 0) continue;
4142
c2mData[name] = traceData;
4243
labels.push(name);
4344
}
@@ -46,16 +47,43 @@ function enable(gd) {
4647
return;
4748
}
4849
}
50+
var closedCaptions;
51+
if(closedCaptionsOptions.generate) {
52+
closedCaptions = document.createElement('div'); // should this be Lib.getGraphDiv()?
53+
closedCaptions.id = closedCaptionsOptions.elId;
54+
closedCaptions.className = closedCaptionsOptions.elClassname;
55+
gd.parentNode.insertBefore(closedCaptions, gd.nextSibling); // this does get generated
56+
// TODO we need a better generator
57+
} else {
58+
closedCaptions = document.getElementById(closedCaptionsOptions.elId);
59+
if(closedCaptions === null) {
60+
// TODO maybe handle this better for the developer?
61+
return;
62+
}
63+
}
4964

50-
var closedCaptions = document.createElement('div');
51-
closedCaptions.id = 'cc';
52-
closedCaptions.className = 'closed_captions';
53-
gd.appendChild(closedCaptions); // this does get generated
65+
var titleText = 'Chart';
66+
if((gd._fullLayout.title !== undefined) && (gd._fullLayout.title.text !== undefined)) {
67+
titleText = gd._fullLayout.title.text;
68+
}
5469

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) {
70+
var xAxisText = 'X Axis';
71+
if((gd._fullLayout.xaxis !== undefined) &&
72+
(gd._fullLayout.xaxis.title !== undefined) &&
73+
(gd._fullLayout.xaxis.title.text !== undefined)) {
74+
xAxisText = gd._fullLayout.xaxis.title.text;
75+
}
76+
var yAxisText = 'Y Axis';
77+
if((gd._fullLayout.yaxis !== undefined) &&
78+
(gd._fullLayout.yaxis.title !== undefined) &&
79+
(gd._fullLayout.yaxis.title.text !== undefined)) {
80+
yAxisText = gd._fullLayout.yaxis.title.text;
81+
}
82+
// Arguably should pass all config as copy to C2M
83+
// If C2M eventually modifies them in any way (minus w/ _ prefix)
84+
// It will always break transition/redraw logic in react
85+
var options2 = Lib.extendDeepAll({}, options);
86+
options2.onFocusCallback = function(dataInfo) {
5987
Fx.hover(gd, [{
6088
curveNumber: labels.indexOf(dataInfo.slice),
6189
pointNumber: dataInfo.index
@@ -66,16 +94,16 @@ function enable(gd) {
6694
type: 'line',
6795
axes: {
6896
x: {
69-
label: xaxisText
97+
label: xAxisText
7098
},
7199
y: {
72-
label: yaxisText
100+
label: yAxisText
73101
},
74102
},
75103
element: gd,
76104
cc: closedCaptions,
77105
data: c2mData,
78-
options: options,
106+
options2: options,
79107
info: info
80108
});
81109
}

src/plot_api/plot_api.js

-4
Original file line numberDiff line numberDiff line change
@@ -2676,7 +2676,6 @@ function react(gd, data, layout, config) {
26762676
setPlotContext(gd, config);
26772677
configChanged = diffConfig(oldConfig, gd._context);
26782678
}
2679-
26802679
gd.data = data || [];
26812680
helpers.cleanData(gd.data);
26822681
gd.layout = layout || {};
@@ -2747,7 +2746,6 @@ function react(gd, data, layout, config) {
27472746

27482747
Plots.doCalcdata(gd);
27492748
subroutines.doAutoRangeAndConstraints(gd);
2750-
27512749
seq.push(function() {
27522750
return Plots.transitionFromReact(gd, restyleFlags, relayoutFlags, oldFullLayout);
27532751
});
@@ -3663,7 +3661,6 @@ function deleteFrames(gd, frameList) {
36633661
*/
36643662
function purge(gd) {
36653663
gd = Lib.getGraphDiv(gd);
3666-
36673664
var fullLayout = gd._fullLayout || {};
36683665
var fullData = gd._fullData || [];
36693666

@@ -3681,7 +3678,6 @@ function purge(gd) {
36813678

36823679
// in contrast to _doPlots.purge which does NOT clear _context!
36833680
delete gd._context;
3684-
36853681
return gd;
36863682
}
36873683

src/plot_api/plot_config.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,11 @@ var configAttributes = {
478478
dflt: {
479479
library: 'chart2music',
480480
enabled: true,
481-
options: {info: {}}
481+
options: {},
482+
info: {},
483+
closedCaptions: {generate: false, elId: 'c2m-plotly-cc', elClassname: 'c2m-plotly-closed_captions'}
482484
},
483-
description: ['Accessibility options: which library to use; whether to enable and the options to pass to the library.',
485+
description: ['Accessibility options: which library to use; whether to enable, options to pass to the library, info to pass to the library, closedCaptions to control how plotly renders the closed-captions element.',
484486
'chart2music is supported and options here include Options and Info from https://www.chart2music.com/docs/API/Config. '
485487
].join(' ')
486488
},

test/jasmine/assets/create_graph_div.js

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ module.exports = function createGraphDiv() {
55
gd.id = 'graph';
66
document.body.appendChild(gd);
77

8+
var closedCaptions = document.createElement('div');
9+
closedCaptions.id = 'c2m-plotly-cc';
10+
closedCaptions.className = 'c2m-plotly-closed_captions';
11+
document.body.appendChild(closedCaptions); // this does get generated
12+
813
// force the graph to be at position 0,0 no matter what
914
gd.style.position = 'fixed';
1015
gd.style.left = 0;

test/jasmine/tests/transition_test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,10 @@ describe('Plotly.react transitions:', function() {
558558
var data = [{y: [1, 2, 1]}];
559559
var layout = {transition: {duration: 10}};
560560
var config = {scrollZoom: true};
561-
562561
Plotly.react(gd, data, layout, config)
563562
.then(function() {
564563
assertSpies('first draw', [
565-
[Plots, 'transitionFromReact', 0]
564+
[Plots, 'transitionFromReact', 0] // so Plots.transitionFromReact should equal 0, ie didn't get called
566565
]);
567566
})
568567
.then(function() {
@@ -581,7 +580,7 @@ describe('Plotly.react transitions:', function() {
581580
})
582581
.then(function() {
583582
assertSpies('no config change', [
584-
[Plots, 'transitionFromReact', 1]
583+
[Plots, 'transitionFromReact', 1] // react is not calling transitionFromReact, why?
585584
]);
586585
})
587586
.then(done, done.fail);

test/plot-schema.json

+15
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@
104104
}
105105
},
106106
"config": {
107+
"accessibility": {
108+
"description": "Accessibility options: which library to use; whether to enable, options to pass to the library, info to pass to the library, closedCaptions to control how plotly renders the closed-captions element. chart2music is supported and options here include Options and Info from https://www.chart2music.com/docs/API/Config. ",
109+
"dflt": {
110+
"closedCaptions": {
111+
"elClassname": "c2m-plotly-closed_captions",
112+
"elId": "c2m-plotly-cc",
113+
"generate": false
114+
},
115+
"enabled": true,
116+
"info": {},
117+
"library": "chart2music",
118+
"options": {}
119+
},
120+
"valType": "any"
121+
},
107122
"autosizable": {
108123
"description": "Determines whether the graphs are plotted with respect to layout.autosize:true and infer its container size.",
109124
"dflt": false,

0 commit comments

Comments
 (0)