@@ -56,12 +56,14 @@ export class BasicToolbar extends SimpleComponent {
5656 //const {hasSelection, hasFilter, activeTrace, tbl_id, hasSelected, dragmode} = this.state;
5757 const { activeTrace, hasFilter, hasSelection, tbl_id, dragmode} = this . state ;
5858
59- const showSelectionPart = get ( getChartData ( chartId ) , `data.${ activeTrace } .type` , '' ) . includes ( 'heatmap' ) ;
59+ const type = get ( getChartData ( chartId ) , `data.${ activeTrace } .type` , '' ) ;
60+ const showSelectionPart = type . includes ( 'heatmap' ) ;
61+ const is3d = type . endsWith ( '3d' ) || type === 'surface' ;
6062
6163 return (
6264 < div className = 'ChartToolbar' >
6365 < ActiveTraceSelect style = { { marginRight : 20 } } { ...{ chartId, activeTrace} } />
64- < DragModePart { ...{ chartId, tbl_id, dragmode} } />
66+ < DragModePart { ...{ chartId, tbl_id, dragmode, hasSelectionMode : showSelectionPart , is3d } } />
6567 { showSelectionPart && < div className = 'ChartToolbar__buttons' style = { { margin : '0 5px' } } >
6668 { hasFilter && < ClearFilter { ...{ tbl_id} } /> }
6769 { hasSelection && < FilterSelection { ...{ chartId} } /> }
@@ -91,12 +93,14 @@ function SelectionPart({chartId, hasFilter, hasSelection, hasSelected, tbl_id})
9193 ) ;
9294}
9395
94- function DragModePart ( { chartId, tbl_id, dragmode} ) {
96+ function DragModePart ( { chartId, tbl_id, dragmode, hasSelectionMode , is3d } ) {
9597 return (
9698 < div className = 'ChartToolbar__buttons' style = { { margin : '0 5px' } } >
9799 < ZoomBtn { ...{ chartId, dragmode} } />
98100 < PanBtn { ...{ chartId, dragmode} } />
99- { tbl_id && < SelectBtn { ...{ chartId, dragmode} } /> }
101+ { is3d && < OrbitBtn { ...{ chartId, dragmode} } /> }
102+ { is3d && < TurntableBtn { ...{ chartId, dragmode} } /> }
103+ { tbl_id && hasSelectionMode && < SelectBtn { ...{ chartId, dragmode} } /> }
100104 </ div >
101105 ) ;
102106}
@@ -119,6 +123,24 @@ function PanBtn({style={}, chartId, dragmode}) {
119123 ) ;
120124}
121125
126+ function TurntableBtn ( { style= { } , chartId, dragmode} ) {
127+ const selected = dragmode === 'turntable' ? 'selected' : '' ;
128+ return (
129+ < div style = { style } onClick = { ( ) => dispatchChartUpdate ( { chartId, changes :{ 'layout.dragmode' : 'turntable' , 'selection' : undefined } } ) }
130+ title = 'Turntable rotation'
131+ className = { `ChartToolbar__turntable ${ selected } ` } />
132+ ) ;
133+ }
134+
135+ function OrbitBtn ( { style= { } , chartId, dragmode} ) {
136+ const selected = dragmode === 'orbit' ? 'selected' : '' ;
137+ return (
138+ < div style = { style } onClick = { ( ) => dispatchChartUpdate ( { chartId, changes :{ 'layout.dragmode' : 'orbit' , 'selection' : undefined } } ) }
139+ title = 'Orbital rotation'
140+ className = { `ChartToolbar__orbital ${ selected } ` } />
141+ ) ;
142+ }
143+
122144function SelectBtn ( { style= { } , chartId, dragmode} ) {
123145 const selected = dragmode === 'select' ? 'selected' : '' ;
124146 return (
@@ -129,15 +151,21 @@ function SelectBtn({style={}, chartId, dragmode}) {
129151}
130152
131153function ResetZoomBtn ( { style= { } , chartId} ) {
132- const { _original} = getChartData ( chartId ) || { } ;
154+ const { _original, layout } = getChartData ( chartId ) || { } ;
133155 const doClick = ( ) => {
134- // TODO: this only handles chart with 2 axes
156+ // 2d axes
135157 const changes = [ 'xaxis' , 'yaxis' ] . reduce ( ( pv , axis ) => {
136- pv [ `layout.${ axis } .autorange` ] = get ( _original , `layout.${ axis } .autorange` , true ) ;
137- pv [ `layout.${ axis } .range` ] = get ( _original , `layout.${ axis } .range` ) ;
158+ if ( get ( layout , `${ axis } ` ) ) {
159+ pv [ `layout.${ axis } .autorange` ] = get ( _original , `layout.${ axis } .autorange` , true ) ;
160+ pv [ `layout.${ axis } .range` ] = get ( _original , `layout.${ axis } .range` ) ;
161+ }
138162 return pv ;
139163 } , { } ) ;
140- dispatchChartUpdate ( { chartId, changes} ) ;
164+ // 3d axes
165+ changes [ 'layout.scene.camera' ] = get ( _original , 'layout.scene.camera' , { } ) ;
166+ if ( ! isEmpty ( changes ) ) {
167+ dispatchChartUpdate ( { chartId, changes} ) ;
168+ }
141169 } ;
142170 return (
143171 < div style = { style } onClick = { doClick }
0 commit comments