Skip to content

Commit c877c27

Browse files
committed
move subplot creation from makePlotFramework -> Cartesian.plot
1 parent 668428d commit c877c27

File tree

2 files changed

+188
-172
lines changed

2 files changed

+188
-172
lines changed

src/plot_api/plot_api.js

Lines changed: 2 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ var subroutines = require('./subroutines');
3535
/**
3636
* Main plot-creation function
3737
*
38-
* Note: will call makePlotFramework if necessary to create the framework
39-
*
4038
* @param {string id or DOM element} gd
4139
* the id or DOM element of the graph container div
4240
* @param {array of objects} data
@@ -2720,21 +2718,12 @@ function makePlotFramework(gd) {
27202718
fullLayout._shapeLowerLayer = layerBelow.append('g')
27212719
.classed('shapelayer', true);
27222720

2723-
var subplots = Plotly.Axes.getSubplots(gd);
2724-
if(subplots.join('') !== Object.keys(gd._fullLayout._plots || {}).join('')) {
2725-
makeSubplots(gd, subplots);
2726-
}
2727-
2728-
if(fullLayout._has('cartesian')) makeCartesianPlotFramwork(gd, subplots);
2721+
// single cartesian layer for the whole plot
2722+
fullLayout._cartesianlayer = fullLayout._paper.append('g').classed('cartesianlayer', true);
27292723

27302724
// single ternary layer for the whole plot
27312725
fullLayout._ternarylayer = fullLayout._paper.append('g').classed('ternarylayer', true);
27322726

2733-
// shape layers in subplots
2734-
var layerSubplot = fullLayout._paper.selectAll('.layer-subplot');
2735-
fullLayout._imageSubplotLayer = layerSubplot.selectAll('.imagelayer');
2736-
fullLayout._shapeSubplotLayer = layerSubplot.selectAll('.shapelayer');
2737-
27382727
// upper shape layer
27392728
// (only for shapes to be drawn above the whole plot, including subplots)
27402729
var layerAbove = fullLayout._paper.append('g')
@@ -2773,162 +2762,3 @@ function makePlotFramework(gd) {
27732762

27742763
return frameWorkDone;
27752764
}
2776-
2777-
// create '_plots' object grouping x/y axes into subplots
2778-
// to be better manage subplots
2779-
function makeSubplots(gd, subplots) {
2780-
var _plots = gd._fullLayout._plots = {};
2781-
var subplot, plotinfo;
2782-
2783-
function getAxisFunc(subplot, axLetter) {
2784-
return function() {
2785-
return Plotly.Axes.getFromId(gd, subplot, axLetter);
2786-
};
2787-
}
2788-
2789-
for(var i = 0; i < subplots.length; i++) {
2790-
subplot = subplots[i];
2791-
plotinfo = _plots[subplot] = {};
2792-
2793-
plotinfo.id = subplot;
2794-
2795-
// references to the axis objects controlling this subplot
2796-
plotinfo.x = getAxisFunc(subplot, 'x');
2797-
plotinfo.y = getAxisFunc(subplot, 'y');
2798-
2799-
// TODO investigate why replacing calls to .x and .y
2800-
// for .xaxis and .yaxis makes the `pseudo_html`
2801-
// test image fail
2802-
plotinfo.xaxis = plotinfo.x();
2803-
plotinfo.yaxis = plotinfo.y();
2804-
}
2805-
}
2806-
2807-
function makeCartesianPlotFramwork(gd, subplots) {
2808-
var fullLayout = gd._fullLayout;
2809-
2810-
// Layers to keep plot types in the right order.
2811-
// from back to front:
2812-
// 1. heatmaps, 2D histos and contour maps
2813-
// 2. bars / 1D histos
2814-
// 3. errorbars for bars and scatter
2815-
// 4. scatter
2816-
// 5. box plots
2817-
function plotLayers(svg) {
2818-
svg.append('g').classed('imagelayer', true);
2819-
svg.append('g').classed('maplayer', true);
2820-
svg.append('g').classed('barlayer', true);
2821-
svg.append('g').classed('boxlayer', true);
2822-
svg.append('g').classed('scatterlayer', true);
2823-
}
2824-
2825-
// create all the layers in order, so we know they'll stay in order
2826-
var overlays = [];
2827-
2828-
fullLayout._paper.selectAll('g.subplot').data(subplots)
2829-
.enter().append('g')
2830-
.classed('subplot', true)
2831-
.each(function(subplot) {
2832-
var plotinfo = fullLayout._plots[subplot],
2833-
plotgroup = plotinfo.plotgroup = d3.select(this).classed(subplot, true),
2834-
xa = plotinfo.xaxis,
2835-
ya = plotinfo.yaxis;
2836-
2837-
// references to any subplots overlaid on this one
2838-
plotinfo.overlays = [];
2839-
2840-
// is this subplot overlaid on another?
2841-
// ax.overlaying is the id of another axis of the same
2842-
// dimension that this one overlays to be an overlaid subplot,
2843-
// the main plot must exist make sure we're not trying to
2844-
// overlay on an axis that's already overlaying another
2845-
var xa2 = Plotly.Axes.getFromId(gd, xa.overlaying) || xa;
2846-
if(xa2 !== xa && xa2.overlaying) {
2847-
xa2 = xa;
2848-
xa.overlaying = false;
2849-
}
2850-
2851-
var ya2 = Plotly.Axes.getFromId(gd, ya.overlaying) || ya;
2852-
if(ya2 !== ya && ya2.overlaying) {
2853-
ya2 = ya;
2854-
ya.overlaying = false;
2855-
}
2856-
2857-
var mainplot = xa2._id + ya2._id;
2858-
if(mainplot !== subplot && subplots.indexOf(mainplot) !== -1) {
2859-
plotinfo.mainplot = mainplot;
2860-
overlays.push(plotinfo);
2861-
2862-
// for now force overlays to overlay completely... so they
2863-
// can drag together correctly and share backgrounds.
2864-
// Later perhaps we make separate axis domain and
2865-
// tick/line domain or something, so they can still share
2866-
// the (possibly larger) dragger and background but don't
2867-
// have to both be drawn over that whole domain
2868-
xa.domain = xa2.domain.slice();
2869-
ya.domain = ya2.domain.slice();
2870-
}
2871-
else {
2872-
// main subplot - make the components of
2873-
// the plot and containers for overlays
2874-
plotinfo.bg = plotgroup.append('rect')
2875-
.style('stroke-width', 0);
2876-
2877-
// back layer for shapes and images to
2878-
// be drawn below a subplot
2879-
var backlayer = plotgroup.append('g')
2880-
.classed('layer-subplot', true);
2881-
2882-
plotinfo.shapelayer = backlayer.append('g')
2883-
.classed('shapelayer', true);
2884-
plotinfo.imagelayer = backlayer.append('g')
2885-
.classed('imagelayer', true);
2886-
plotinfo.gridlayer = plotgroup.append('g');
2887-
plotinfo.overgrid = plotgroup.append('g');
2888-
plotinfo.zerolinelayer = plotgroup.append('g');
2889-
plotinfo.overzero = plotgroup.append('g');
2890-
plotinfo.plot = plotgroup.append('g').call(plotLayers);
2891-
plotinfo.overplot = plotgroup.append('g');
2892-
plotinfo.xlines = plotgroup.append('path');
2893-
plotinfo.ylines = plotgroup.append('path');
2894-
plotinfo.overlines = plotgroup.append('g');
2895-
plotinfo.xaxislayer = plotgroup.append('g');
2896-
plotinfo.yaxislayer = plotgroup.append('g');
2897-
plotinfo.overaxes = plotgroup.append('g');
2898-
2899-
// make separate drag layers for each subplot,
2900-
// but append them to paper rather than the plot groups,
2901-
// so they end up on top of the rest
2902-
}
2903-
plotinfo.draglayer = fullLayout._draggers.append('g');
2904-
});
2905-
2906-
// now make the components of overlaid subplots
2907-
// overlays don't have backgrounds, and append all
2908-
// their other components to the corresponding
2909-
// extra groups of their main Plots.
2910-
overlays.forEach(function(plotinfo) {
2911-
var mainplot = fullLayout._plots[plotinfo.mainplot];
2912-
mainplot.overlays.push(plotinfo);
2913-
2914-
plotinfo.gridlayer = mainplot.overgrid.append('g');
2915-
plotinfo.zerolinelayer = mainplot.overzero.append('g');
2916-
plotinfo.plot = mainplot.overplot.append('g').call(plotLayers);
2917-
plotinfo.xlines = mainplot.overlines.append('path');
2918-
plotinfo.ylines = mainplot.overlines.append('path');
2919-
plotinfo.xaxislayer = mainplot.overaxes.append('g');
2920-
plotinfo.yaxislayer = mainplot.overaxes.append('g');
2921-
});
2922-
2923-
// common attributes for all subplots, overlays or not
2924-
subplots.forEach(function(subplot) {
2925-
var plotinfo = fullLayout._plots[subplot];
2926-
2927-
plotinfo.xlines
2928-
.style('fill', 'none')
2929-
.classed('crisp', true);
2930-
plotinfo.ylines
2931-
.style('fill', 'none')
2932-
.classed('crisp', true);
2933-
});
2934-
}

0 commit comments

Comments
 (0)