Skip to content

Commit f476e05

Browse files
committed
split pie trace base plot module from cartesian:
- so that _has??? are one-to-one with base plot modules - handle case where base plot module attrRegex isn't defined in plot schema.
1 parent b655cb0 commit f476e05

File tree

5 files changed

+47
-21
lines changed

5 files changed

+47
-21
lines changed

src/plot_api/plot_api.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,8 @@ Plotly.plot = function(gd, data, layout, config) {
277277
if(fullLayout._hasGL3D) plotRegistry.gl3d.plot(gd);
278278
if(fullLayout._hasGeo) plotRegistry.geo.plot(gd);
279279
if(fullLayout._hasGL2D) plotRegistry.gl2d.plot(gd);
280-
if(fullLayout._hasCartesian || fullLayout._hasPie) {
281-
plotRegistry.cartesian.plot(gd);
282-
}
280+
if(fullLayout._hasCartesian) plotRegistry.cartesian.plot(gd);
281+
if(fullLayout._hasPie) plotRegistry.pie.plot(gd);
283282
if(fullLayout._hasTernary) plotRegistry.ternary.plot(gd);
284283

285284
// clean up old scenes that no longer have associated data

src/plot_api/plot_schema.js

+2
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ function handleSubplotObjs(layoutAttributes) {
286286
var subplotRegistry = subplotsRegistry[subplotType],
287287
isSubplotObj;
288288

289+
if(!subplotRegistry.attrRegex) return;
290+
289291
if(subplotType === 'cartesian' || subplotType === 'gl2d') {
290292
isSubplotObj = (
291293
subplotRegistry.attrRegex.x.test(k) ||

src/plots/cartesian/index.js

-17
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,11 @@ exports.plot = function(gd) {
7878
// skip over non-cartesian trace modules
7979
if(_module.basePlotModule.name !== 'cartesian') continue;
8080

81-
// skip over pies, there are drawn below
82-
if(_module.name === 'pie') continue;
83-
8481
// plot all traces of this type on this subplot at once
8582
var cdModule = getCdModule(cdSubplot, _module);
8683
_module.plot(gd, subplotInfo, cdModule);
8784

8885
Lib.markTime('done ' + (cdModule[0] && cdModule[0][0].trace.type));
8986
}
9087
}
91-
92-
// now draw stuff not on subplots (ie, only pies at the moment)
93-
if(fullLayout._hasPie) {
94-
var Pie = Plots.getModule('pie');
95-
var cdPie = getCdModule(calcdata, Pie);
96-
97-
if(cdPie.length) Pie.plot(gd, cdPie);
98-
}
99-
};
100-
101-
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
102-
if(oldFullLayout._hasPie && !newFullLayout._hasPie) {
103-
oldFullLayout._pielayer.selectAll('g.trace').remove();
104-
}
10588
};

src/traces/pie/base_plot.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Plots = require('../../plots/plots');
12+
13+
14+
exports.name = 'pie';
15+
16+
exports.plot = function(gd) {
17+
var Pie = Plots.getModule('pie');
18+
var cdPie = getCdModule(gd.calcdata, Pie);
19+
20+
if(cdPie.length) Pie.plot(gd, cdPie);
21+
};
22+
23+
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
24+
if(oldFullLayout._hasPie && !newFullLayout._hasPie) {
25+
oldFullLayout._pielayer.selectAll('g.trace').remove();
26+
}
27+
};
28+
29+
function getCdModule(calcdata, _module) {
30+
var cdModule = [];
31+
32+
for(var i = 0; i < calcdata.length; i++) {
33+
var cd = calcdata[i];
34+
var trace = cd[0].trace;
35+
36+
if((trace._module === _module) && (trace.visible === true)) {
37+
cdModule.push(cd);
38+
}
39+
}
40+
41+
return cdModule;
42+
}

src/traces/pie/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Pie.styleOne = require('./style_one');
2121

2222
Pie.moduleType = 'trace';
2323
Pie.name = 'pie';
24-
Pie.basePlotModule = require('../../plots/cartesian');
24+
Pie.basePlotModule = require('./base_plot');
2525
Pie.categories = ['pie', 'showLegend'];
2626
Pie.layoutCategories = ['pie'];
2727
Pie.meta = {

0 commit comments

Comments
 (0)