-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathindex.js
105 lines (76 loc) · 2.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
var Lib = require('../../lib');
var Plots = require('../plots');
var constants = require('./constants');
exports.name = 'cartesian';
exports.attr = ['xaxis', 'yaxis'];
exports.idRoot = ['x', 'y'];
exports.idRegex = constants.idRegex;
exports.attrRegex = constants.attrRegex;
exports.attributes = require('./attributes');
exports.plot = function(gd) {
var fullLayout = gd._fullLayout,
subplots = Plots.getSubplotIds(fullLayout, 'cartesian'),
calcdata = gd.calcdata,
modules = fullLayout._modules;
function getCdSubplot(calcdata, subplot) {
var cdSubplot = [];
for(var i = 0; i < calcdata.length; i++) {
var cd = calcdata[i];
var trace = cd[0].trace;
if(trace.xaxis + trace.yaxis === subplot) {
cdSubplot.push(cd);
}
}
return cdSubplot;
}
function getCdModule(cdSubplot, _module) {
var cdModule = [];
for(var i = 0; i < cdSubplot.length; i++) {
var cd = cdSubplot[i];
var trace = cd[0].trace;
if((trace._module === _module) && (trace.visible === true)) {
cdModule.push(cd);
}
}
return cdModule;
}
for(var i = 0; i < subplots.length; i++) {
var subplot = subplots[i],
subplotInfo = fullLayout._plots[subplot],
cdSubplot = getCdSubplot(calcdata, subplot);
// remove old traces, then redraw everything
// TODO: use enter/exit appropriately in the plot functions
// so we don't need this - should sometimes be a big speedup
if(subplotInfo.plot) subplotInfo.plot.selectAll('g.trace').remove();
for(var j = 0; j < modules.length; j++) {
var _module = modules[j];
// skip over non-cartesian trace modules
if(_module.basePlotModule.name !== 'cartesian') continue;
// skip over pies, there are drawn below
if(_module.name === 'pie') continue;
// plot all traces of this type on this subplot at once
var cdModule = getCdModule(cdSubplot, _module);
_module.plot(gd, subplotInfo, cdModule);
Lib.markTime('done ' + (cdModule[0] && cdModule[0][0].trace.type));
}
}
// now draw stuff not on subplots (ie, only pies at the moment)
if(fullLayout._hasPie) {
var Pie = Plots.getModule('pie');
var cdPie = getCdModule(calcdata, Pie);
if(cdPie.length) Pie.plot(gd, cdPie);
}
};
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
if(oldFullLayout._hasPie && !newFullLayout._hasPie) {
oldFullLayout._pielayer.selectAll('g.trace').remove();
}
};