-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathindex.js
98 lines (75 loc) · 2.99 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
/**
* 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 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, traces) {
var cdSubplot, cd, trace, i, j, k, isFullReplot;
var fullLayout = gd._fullLayout,
subplots = Plots.getSubplotIds(fullLayout, 'cartesian'),
calcdata = gd.calcdata,
modules = fullLayout._modules;
if (!Array.isArray(traces)) {
// If traces is not provided, then it's a complete replot and missing
// traces are removed
isFullReplot = true;
traces = [];
for (i = 0; i < calcdata.length; i++) {
traces.push(i);
}
} else {
// If traces are explicitly specified, then it's a partial replot and
// traces are not removed.
isFullReplot = false;
}
for(var i = 0; i < subplots.length; i++) {
var subplot = subplots[i],
subplotInfo = fullLayout._plots[subplot];
// Get all calcdata for this subplot:
cdSubplot = [];
for(j = 0; j < calcdata.length; j++) {
var cd = calcdata[j];
var trace = cd[0].trace;
// Skip trace if whitelist provided and it's not whitelisted:
// if (Array.isArray(traces) && traces.indexOf(i) === -1) continue;
if(trace.xaxis + trace.yaxis === subplot && traces.indexOf(trace.index) !== -1) {
cdSubplot.push(cd);
}
}
// remove old traces, then redraw everything
// TODO: scatterlayer is manually excluded from this since it knows how
// to update instead of fully removing and redrawing every time. The
// remaining plot traces should also be able to do this. Once implemented,
// we won't need this - which should sometimes be a big speedup.
if(subplotInfo.plot) {
subplotInfo.plot.selectAll('g:not(.scatterlayer)').selectAll('g.trace').remove();
}
// Plot all traces for each module at once:
for(j = 0; j < modules.length; j++) {
var _module = modules[j];
// skip over non-cartesian trace modules
if(_module.basePlotModule.name !== 'cartesian') continue;
// plot all traces of this type on this subplot at once
var cdModule = [];
for(k = 0; k < cdSubplot.length; k++) {
var cd = cdSubplot[k];
var trace = cd[0].trace;
if((trace._module === _module) && (trace.visible === true)) {
cdModule.push(cd);
}
}
_module.plot(gd, subplotInfo, cdModule, isFullReplot);
}
}
};