@@ -25,61 +25,74 @@ exports.attrRegex = constants.attrRegex;
25
25
26
26
exports . attributes = require ( './attributes' ) ;
27
27
28
- exports . plot = function ( gd ) {
28
+ exports . plot = function ( gd , traces ) {
29
+ var cdSubplot , cd , trace , i , j , k , isFullReplot ;
30
+
29
31
var fullLayout = gd . _fullLayout ,
30
32
subplots = Plots . getSubplotIds ( fullLayout , 'cartesian' ) ,
31
33
calcdata = gd . calcdata ,
32
34
modules = fullLayout . _modules ;
33
35
34
- function getCdSubplot ( calcdata , subplot ) {
35
- var cdSubplot = [ ] ;
36
-
37
- for ( var i = 0 ; i < calcdata . length ; i ++ ) {
38
- var cd = calcdata [ i ] ;
39
- var trace = cd [ 0 ] . trace ;
40
-
41
- if ( trace . xaxis + trace . yaxis === subplot ) {
42
- cdSubplot . push ( cd ) ;
43
- }
36
+ if ( ! Array . isArray ( traces ) ) {
37
+ // If traces is not provided, then it's a complete replot and missing
38
+ // traces are removed
39
+ isFullReplot = true ;
40
+ traces = [ ] ;
41
+ for ( i = 0 ; i < calcdata . length ; i ++ ) {
42
+ traces . push ( i ) ;
44
43
}
45
-
46
- return cdSubplot ;
44
+ } else {
45
+ // If traces are explicitly specified, then it's a partial replot and
46
+ // traces are not removed.
47
+ isFullReplot = false ;
47
48
}
48
49
49
- function getCdModule ( cdSubplot , _module ) {
50
- var cdModule = [ ] ;
50
+ for ( i = 0 ; i < subplots . length ; i ++ ) {
51
+ var subplot = subplots [ i ] ,
52
+ subplotInfo = fullLayout . _plots [ subplot ] ;
53
+
54
+ // Get all calcdata for this subplot:
55
+ cdSubplot = [ ] ;
56
+ for ( j = 0 ; j < calcdata . length ; j ++ ) {
57
+ cd = calcdata [ j ] ;
58
+ trace = cd [ 0 ] . trace ;
51
59
52
- for ( var i = 0 ; i < cdSubplot . length ; i ++ ) {
53
- var cd = cdSubplot [ i ] ;
54
- var trace = cd [ 0 ] . trace ;
60
+ // Skip trace if whitelist provided and it's not whitelisted:
61
+ // if (Array.isArray(traces) && traces.indexOf(i) === -1) continue;
55
62
56
- if ( ( trace . _module === _module ) && ( trace . visible === true ) ) {
57
- cdModule . push ( cd ) ;
63
+ if ( trace . xaxis + trace . yaxis === subplot && traces . indexOf ( trace . index ) !== - 1 ) {
64
+ cdSubplot . push ( cd ) ;
58
65
}
59
66
}
60
67
61
- return cdModule ;
62
- }
63
-
64
- for ( var i = 0 ; i < subplots . length ; i ++ ) {
65
- var subplot = subplots [ i ] ,
66
- subplotInfo = fullLayout . _plots [ subplot ] ,
67
- cdSubplot = getCdSubplot ( calcdata , subplot ) ;
68
-
69
68
// remove old traces, then redraw everything
70
- // TODO: use enter/exit appropriately in the plot functions
71
- // so we don't need this - should sometimes be a big speedup
72
- if ( subplotInfo . plot ) subplotInfo . plot . selectAll ( 'g.trace' ) . remove ( ) ;
69
+ // TODO: scatterlayer is manually excluded from this since it knows how
70
+ // to update instead of fully removing and redrawing every time. The
71
+ // remaining plot traces should also be able to do this. Once implemented,
72
+ // we won't need this - which should sometimes be a big speedup.
73
+ if ( subplotInfo . plot ) {
74
+ subplotInfo . plot . selectAll ( 'g:not(.scatterlayer)' ) . selectAll ( 'g.trace' ) . remove ( ) ;
75
+ }
73
76
74
- for ( var j = 0 ; j < modules . length ; j ++ ) {
77
+ // Plot all traces for each module at once:
78
+ for ( j = 0 ; j < modules . length ; j ++ ) {
75
79
var _module = modules [ j ] ;
76
80
77
81
// skip over non-cartesian trace modules
78
82
if ( _module . basePlotModule . name !== 'cartesian' ) continue ;
79
83
80
84
// plot all traces of this type on this subplot at once
81
- var cdModule = getCdModule ( cdSubplot , _module ) ;
82
- _module . plot ( gd , subplotInfo , cdModule ) ;
85
+ var cdModule = [ ] ;
86
+ for ( k = 0 ; k < cdSubplot . length ; k ++ ) {
87
+ cd = cdSubplot [ k ] ;
88
+ trace = cd [ 0 ] . trace ;
89
+
90
+ if ( ( trace . _module === _module ) && ( trace . visible === true ) ) {
91
+ cdModule . push ( cd ) ;
92
+ }
93
+ }
94
+
95
+ _module . plot ( gd , subplotInfo , cdModule , isFullReplot ) ;
83
96
}
84
97
}
85
98
} ;
0 commit comments