11
11
12
12
var Plotly = require ( '../plotly' ) ;
13
13
var Lib = require ( '../lib' ) ;
14
- var helpers = require ( '../plot_api/helpers' ) ;
15
14
16
15
exports . executeAPICommand = function ( gd , method , args ) {
17
16
var apiMethod = Plotly [ method ] ;
@@ -37,10 +36,16 @@ exports.computeAPICommandBindings = function(gd, method, args) {
37
36
case 'relayout' :
38
37
bindings = computeLayoutBindings ( gd , args ) ;
39
38
break ;
40
- case 'animate ' :
39
+ case 'update ' :
41
40
bindings = computeDataBindings ( gd , [ args [ 0 ] , args [ 2 ] ] )
42
41
. concat ( computeLayoutBindings ( gd , [ args [ 1 ] ] ) ) ;
43
42
break ;
43
+ case 'animate' :
44
+ // This case could be analyzed more in-depth, but for a start,
45
+ // we'll assume that the only relevant modification an animation
46
+ // makes that's meaningfully tracked is the frame:
47
+ bindings = [ 'layout._currentFrame' ] ;
48
+ break ;
44
49
default :
45
50
// We'll elect to fail-non-fatal since this is a correct
46
51
// answer and since this is not a validation method.
@@ -49,7 +54,7 @@ exports.computeAPICommandBindings = function(gd, method, args) {
49
54
return bindings ;
50
55
} ;
51
56
52
- function computeLayoutBindings ( gd , args ) {
57
+ function computeLayoutBindings ( gd , args ) {
53
58
var bindings = [ ] ;
54
59
55
60
var astr = args [ 0 ] ;
@@ -62,15 +67,15 @@ function computeLayoutBindings (gd, args) {
62
67
return bindings ;
63
68
}
64
69
65
- crawl ( aobj , function ( path , attrName , attr ) {
70
+ crawl ( aobj , function ( path ) {
66
71
bindings . push ( 'layout' + path ) ;
67
72
} ) ;
68
73
69
74
return bindings ;
70
75
}
71
76
72
- function computeDataBindings ( gd , args ) {
73
- var i , traces , astr , attr , val , traces , aobj ;
77
+ function computeDataBindings ( gd , args ) {
78
+ var i , traces , astr , val , aobj ;
74
79
var bindings = [ ] ;
75
80
76
81
// Logic copied from Plotly.restyle:
@@ -91,33 +96,29 @@ function computeDataBindings (gd, args) {
91
96
return bindings ;
92
97
}
93
98
94
- if ( traces === undefined ) {
99
+ if ( traces === undefined ) {
95
100
traces = [ ] ;
96
- for ( i = 0 ; i < gd . data . length ; i ++ ) {
101
+ for ( i = 0 ; i < gd . data . length ; i ++ ) {
97
102
traces . push ( i ) ;
98
103
}
99
104
}
100
105
101
- crawl ( aobj , function ( path , attrName , attr ) {
106
+ crawl ( aobj , function ( path , attrName , attr ) {
102
107
var nAttr ;
103
- if ( Array . isArray ( attr ) ) {
108
+ if ( Array . isArray ( attr ) ) {
104
109
nAttr = Math . min ( attr . length , traces . length ) ;
105
110
} else {
106
111
nAttr = traces . length ;
107
112
}
108
- for ( var j = 0 ; j < nAttr ; j ++ ) {
113
+ for ( var j = 0 ; j < nAttr ; j ++ ) {
109
114
bindings . push ( 'data[' + traces [ j ] + ']' + path ) ;
110
115
}
111
116
} ) ;
112
117
113
118
return bindings ;
114
119
}
115
120
116
- function crawl ( attrs , callback , path , depth ) {
117
- if ( depth === undefined ) {
118
- depth = 0 ;
119
- }
120
-
121
+ function crawl ( attrs , callback , path ) {
121
122
if ( path === undefined ) {
122
123
path = '' ;
123
124
}
@@ -130,7 +131,7 @@ function crawl(attrs, callback, path, depth) {
130
131
var thisPath = path + '.' + attrName ;
131
132
132
133
if ( Lib . isPlainObject ( attr ) ) {
133
- crawl ( attr , callback , thisPath , depth + 1 ) ;
134
+ crawl ( attr , callback , thisPath ) ;
134
135
} else {
135
136
// Only execute the callback on leaf nodes:
136
137
callback ( thisPath , attrName , attr ) ;
0 commit comments