@@ -10,13 +10,24 @@ import {
1010import TraceTypeSelector , {
1111 TraceTypeSelectorButton ,
1212} from 'components/widgets/TraceTypeSelector' ;
13+ import RadioBlocks from 'components/widgets/RadioBlocks' ;
14+
1315import Field from './Field' ;
1416
17+ export const glAvailable = type => {
18+ return [ 'scatter' , 'scatterpolar' , 'scattergl' , 'scatterpolargl' ] . includes (
19+ type
20+ ) ;
21+ } ;
22+
1523class TraceSelector extends Component {
1624 constructor ( props , context ) {
1725 super ( props , context ) ;
1826
1927 this . updatePlot = this . updatePlot . bind ( this ) ;
28+ this . setGl = this . setGl . bind ( this ) ;
29+ this . glEnabled = this . glEnabled . bind ( this ) ;
30+ this . setTraceDefaults = this . setTraceDefaults . bind ( this ) ;
2031
2132 this . setTraceDefaults (
2233 props . container ,
@@ -26,6 +37,10 @@ class TraceSelector extends Component {
2637 this . setLocals ( props , context ) ;
2738 }
2839
40+ glEnabled ( ) {
41+ return this . props . container . type . endsWith ( 'gl' ) ? 'gl' : '' ;
42+ }
43+
2944 setLocals ( props , context ) {
3045 const _ = context . localize ;
3146 if ( props . traceOptions ) {
@@ -46,10 +61,11 @@ class TraceSelector extends Component {
4661 }
4762 }
4863
49- setTraceDefaults ( container , fullContainer , updateContainer ) {
64+ setTraceDefaults ( container , fullContainer , updateContainer , gl ) {
5065 if ( container && ! container . mode && fullContainer . type === 'scatter' ) {
5166 updateContainer ( {
52- type : 'scatter' ,
67+ type :
68+ 'scatter' + ( gl || this . context . glByDefault ? gl : this . glEnabled ( ) ) ,
5369 mode : fullContainer . mode || 'markers' ,
5470 } ) ;
5571 }
@@ -63,29 +79,70 @@ class TraceSelector extends Component {
6379
6480 updatePlot ( value ) {
6581 const { updateContainer} = this . props ;
82+ const { glByDefault} = this . context ;
6683 if ( updateContainer ) {
67- updateContainer ( traceTypeToPlotlyInitFigure ( value ) ) ;
84+ updateContainer (
85+ traceTypeToPlotlyInitFigure ( value , this . glEnabled ( ) || glByDefault )
86+ ) ;
6887 }
6988 }
7089
90+ setGl ( value ) {
91+ const { container, fullContainer, updateContainer} = this . props ;
92+ const gl = 'gl' ;
93+
94+ this . setTraceDefaults ( container , fullContainer , updateContainer , value ) ;
95+
96+ const traceType =
97+ this . fullValue . endsWith ( gl ) && value === ''
98+ ? this . fullValue . slice ( 0 , - gl . length )
99+ : this . fullValue ;
100+
101+ updateContainer ( traceTypeToPlotlyInitFigure ( traceType , value ) ) ;
102+ }
103+
71104 render ( ) {
72105 const props = Object . assign ( { } , this . props , {
73106 fullValue : this . fullValue ,
74107 updatePlot : this . updatePlot ,
75108 options : this . traceOptions ,
76109 clearable : false ,
77110 } ) ;
111+ const { localize : _ , advancedTraceTypeSelector} = this . context ;
112+
113+ const options = [
114+ { label : _ ( 'SVG' ) , value : '' } ,
115+ { label : _ ( 'WebGl' ) , value : 'gl' } ,
116+ ] ;
117+
78118 // Check and see if the advanced selector prop is true
79- const { advancedTraceTypeSelector} = this . context ;
80119 if ( advancedTraceTypeSelector ) {
81120 return (
82- < Field { ...props } >
83- < TraceTypeSelectorButton
84- { ...props }
85- traceTypesConfig = { this . context . traceTypesConfig }
86- handleClick = { ( ) => this . context . openModal ( TraceTypeSelector , props ) }
87- />
88- </ Field >
121+ < div >
122+ < Field { ...props } >
123+ < TraceTypeSelectorButton
124+ { ...props }
125+ traceTypesConfig = { this . context . traceTypesConfig }
126+ handleClick = { ( ) =>
127+ this . context . openModal ( TraceTypeSelector , {
128+ ...props ,
129+ glByDefault : this . context . glByDefault ,
130+ } )
131+ }
132+ />
133+ </ Field >
134+ { ! glAvailable ( this . props . container . type ) ? (
135+ ''
136+ ) : (
137+ < Field label = { _ ( 'Rendering' ) } >
138+ < RadioBlocks
139+ options = { options }
140+ activeOption = { this . glEnabled ( ) }
141+ onOptionChange = { this . setGl }
142+ />
143+ </ Field >
144+ ) }
145+ </ div >
89146 ) ;
90147 }
91148
@@ -100,6 +157,7 @@ TraceSelector.contextTypes = {
100157 plotSchema : PropTypes . object ,
101158 config : PropTypes . object ,
102159 localize : PropTypes . func ,
160+ glByDefault : PropTypes . bool ,
103161} ;
104162
105163TraceSelector . propTypes = {
0 commit comments