@@ -266,10 +266,12 @@ Plotly.plot = function(gd, data, layout, config) {
266266 // clean up old scenes that no longer have associated data
267267 // will this be a performance hit?
268268
269- // ... until subplot of different type play better together
270- if ( gd . _fullLayout . _hasGL3D ) plotGl3d ( gd ) ;
271- if ( gd . _fullLayout . _hasGeo ) plotGeo ( gd ) ;
272- if ( gd . _fullLayout . _hasGL2D ) plotGl2d ( gd ) ;
269+ var plotRegistry = plots . subplotsRegistry ;
270+
271+ // TODO incorporate cartesian and polar plots into this paradigm
272+ if ( fullLayout . _hasGL3D ) plotRegistry . gl3d . plot ( gd ) ;
273+ if ( fullLayout . _hasGeo ) plotRegistry . geo . plot ( gd ) ;
274+ if ( fullLayout . _hasGL2D ) plotRegistry . gl2d . plot ( gd ) ;
273275
274276 // in case of traces that were heatmaps or contour maps
275277 // previously, remove them and their colorbars explicitly
@@ -418,109 +420,6 @@ function setPlotContext(gd, config) {
418420 }
419421}
420422
421- function plotGl3d ( gd ) {
422- var fullLayout = gd . _fullLayout ,
423- fullData = gd . _fullData ,
424- sceneIds = plots . getSubplotIds ( fullLayout , 'gl3d' ) ;
425-
426- var i , sceneId , fullSceneData , scene , sceneOptions ;
427-
428- fullLayout . _paperdiv . style ( {
429- width : fullLayout . width + 'px' ,
430- height : fullLayout . height + 'px'
431- } ) ;
432-
433- gd . _context . setBackground ( gd , fullLayout . paper_bgcolor ) ;
434-
435- for ( i = 0 ; i < sceneIds . length ; i ++ ) {
436- sceneId = sceneIds [ i ] ;
437- fullSceneData = plots . getSubplotData ( fullData , 'gl3d' , sceneId ) ;
438- scene = fullLayout [ sceneId ] . _scene ; // ref. to corresp. Scene instance
439-
440- // If Scene is not instantiated, create one!
441- if ( scene === undefined ) {
442- sceneOptions = {
443- container : gd . querySelector ( '.gl-container' ) ,
444- id : sceneId ,
445- staticPlot : gd . _context . staticPlot ,
446- plotGlPixelRatio : gd . _context . plotGlPixelRatio
447- } ;
448- scene = new Plotly . Scene ( sceneOptions , fullLayout ) ;
449- fullLayout [ sceneId ] . _scene = scene ; // set ref to Scene instance
450- }
451-
452- scene . plot ( fullSceneData , fullLayout , gd . layout ) ; // takes care of business
453- }
454- }
455-
456- function plotGeo ( gd ) {
457- var fullLayout = gd . _fullLayout ,
458- fullData = gd . _fullData ,
459- geoIds = plots . getSubplotIds ( fullLayout , 'geo' ) ;
460-
461- var i , geoId , fullGeoData , geo ;
462-
463- // if 'plotly-geo-assets.js' is not included,
464- // initialize object to keep reference to every loaded topojson
465- if ( window . PlotlyGeoAssets === undefined ) {
466- window . PlotlyGeoAssets = { topojson : { } } ;
467- }
468-
469- for ( i = 0 ; i < geoIds . length ; i ++ ) {
470- geoId = geoIds [ i ] ;
471- fullGeoData = plots . getSubplotData ( fullData , 'geo' , geoId ) ;
472- geo = fullLayout [ geoId ] . _geo ;
473-
474- // If geo is not instantiated, create one!
475- if ( geo === undefined ) {
476- geo = new Plotly . Geo (
477- {
478- id : geoId ,
479- container : fullLayout . _geocontainer . node ( ) ,
480- topojsonURL : gd . _context . topojsonURL
481- } ,
482- fullLayout
483- ) ;
484- fullLayout [ geoId ] . _geo = geo ;
485- }
486-
487- geo . plot ( fullGeoData , fullLayout , gd . _promises ) ;
488- }
489- }
490-
491- function plotGl2d ( gd ) {
492- var fullLayout = gd . _fullLayout ,
493- fullData = gd . _fullData ,
494- subplotIds = plots . getSubplotIds ( fullLayout , 'gl2d' ) ;
495-
496- for ( var i = 0 ; i < subplotIds . length ; i ++ ) {
497- var subplotId = subplotIds [ i ] ,
498- subplotObj = fullLayout . _plots [ subplotId ] ,
499- fullSubplotData = plots . getSubplotData ( fullData , 'gl2d' , subplotId ) ;
500- var scene ;
501-
502- // ref. to corresp. Scene instance
503- scene = subplotObj . _scene2d ;
504-
505- // If Scene is not instantiated, create one!
506- if ( scene === undefined ) {
507- scene = new Plotly . Scene2D ( {
508- container : gd . querySelector ( '.gl-container' ) ,
509- id : subplotId ,
510- staticPlot : gd . _context . staticPlot ,
511- plotGlPixelRatio : gd . _context . plotGlPixelRatio
512- } ,
513- fullLayout
514- ) ;
515-
516- // set ref to Scene instance
517- subplotObj . _scene2d = scene ;
518- }
519-
520- scene . plot ( fullSubplotData , fullLayout , gd . layout ) ;
521- }
522- }
523-
524423function plotPolar ( gd , data , layout ) {
525424 // build or reuse the container skeleton
526425 var plotContainer = d3 . select ( gd ) . selectAll ( '.plot-container' )
@@ -866,8 +765,8 @@ function cleanData(data, existingData) {
866765 if ( trace . yaxis ) trace . yaxis = Plotly . Axes . cleanId ( trace . yaxis , 'y' ) ;
867766
868767 // scene ids scene1 -> scene
869- if ( trace . scene ) {
870- trace . scene = Plotly . Gl3dLayout . cleanId ( trace . scene ) ;
768+ if ( plots . traceIs ( trace , 'gl3d' ) && trace . scene ) {
769+ trace . scene = plots . subplotsRegistry . gl3d . cleanId ( trace . scene ) ;
871770 }
872771
873772 if ( ! plots . traceIs ( trace , 'pie' ) ) {
@@ -2593,10 +2492,8 @@ function makePlotFramework(gd) {
25932492 var gd3 = d3 . select ( gd ) ,
25942493 fullLayout = gd . _fullLayout ;
25952494
2596- /*
2597- * TODO - find a better place for 3D to initialize axes
2598- */
2599- if ( fullLayout . _hasGL3D ) Plotly . Gl3dLayout . initAxes ( gd ) ;
2495+ // TODO - find a better place for 3D to initialize axes
2496+ if ( fullLayout . _hasGL3D ) plots . subplotsRegistry . gl3d . initAxes ( gd ) ;
26002497
26012498 // Plot container
26022499 fullLayout . _container = gd3 . selectAll ( '.plot-container' ) . data ( [ 0 ] ) ;
0 commit comments