11'use strict' ;
22
3+ var Lib = require ( '../lib' ) ;
34var c2m = require ( 'chart2music' ) ;
45var 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 }
0 commit comments