Skip to content

Commit 7db5f1f

Browse files
committed
emove custom plotmodified event
1 parent 57fcf96 commit 7db5f1f

File tree

3 files changed

+61
-15
lines changed

3 files changed

+61
-15
lines changed

src/plot_api/plot_api.js

+8-13
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,6 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
12041204

12051205
return plotDone.then(function() {
12061206
gd.emit('plotly_restyle', specs.eventData);
1207-
gd.emit('plotly_plotmodified');
12081207
return gd;
12091208
});
12101209
};
@@ -1711,7 +1710,6 @@ Plotly.relayout = function relayout(gd, astr, val) {
17111710

17121711
return plotDone.then(function() {
17131712
gd.emit('plotly_relayout', specs.eventData);
1714-
gd.emit('plotly_plotmodified');
17151713
return gd;
17161714
});
17171715
};
@@ -2126,7 +2124,6 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, traces) {
21262124
data: restyleSpecs.eventData,
21272125
layout: relayoutSpecs.eventData
21282126
});
2129-
gd.emit('plotly_plotmodified');
21302127

21312128
return gd;
21322129
});
@@ -2307,15 +2304,6 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
23072304
if(newFrame) {
23082305
gd._fullLayout._currentFrame = newFrame.name;
23092306

2310-
gd.emit('plotly_animatingframe', {
2311-
name: newFrame.name,
2312-
frame: newFrame.frame,
2313-
animation: {
2314-
frame: newFrame.frameOpts,
2315-
transition: newFrame.transitionOpts,
2316-
}
2317-
});
2318-
23192307
trans._lastFrameAt = Date.now();
23202308
trans._timeToNext = newFrame.frameOpts.duration;
23212309

@@ -2330,7 +2318,14 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
23302318
newFrame.transitionOpts
23312319
);
23322320

2333-
gd.emit('plotly_plotmodified');
2321+
gd.emit('plotly_animatingframe', {
2322+
name: newFrame.name,
2323+
frame: newFrame.frame,
2324+
animation: {
2325+
frame: newFrame.frameOpts,
2326+
transition: newFrame.transitionOpts,
2327+
}
2328+
});
23342329
} else {
23352330
// If there are no more frames, then stop the RAF loop:
23362331
stopAnimationLoop();

src/plots/command.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,23 @@ exports.createCommandObserver = function(gd, commandList, onchange) {
145145
return changed;
146146
};
147147

148-
gd._internalOn('plotly_plotmodified', check);
148+
var checkEvents = [
149+
'plotly_relayout',
150+
'plotly_redraw',
151+
'plotly_restyle',
152+
'plotly_update',
153+
'plotly_animatingframe',
154+
'plotly_afterplot'
155+
];
156+
157+
for(var i = 0; i < checkEvents.length; i++) {
158+
gd._internalOn(checkEvents[i], check);
159+
}
149160

150161
remove = function() {
151-
gd._removeInternalListener('plotly_plotmodified', check);
162+
for(var i = 0; i < checkEvents.length; i++) {
163+
gd._removeInternalListener(checkEvents[i], check);
164+
}
152165
};
153166
} else {
154167
lookupTable = {};

test/jasmine/tests/command_test.js

+38
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Plots = Plotly.Plots;
44
var createGraphDiv = require('../assets/create_graph_div');
55
var destroyGraphDiv = require('../assets/destroy_graph_div');
66
var fail = require('../assets/fail_test');
7+
var Lib = require('@src/lib');
78

89
describe('Plots.executeAPICommand', function() {
910
'use strict';
@@ -437,3 +438,40 @@ describe('Plots.computeAPICommandBindings', function() {
437438
});
438439
});
439440
});
441+
442+
describe('component bindings', function() {
443+
'use strict';
444+
445+
var gd;
446+
var mock = require('@mocks/binding.json');
447+
448+
beforeEach(function(done) {
449+
var mockCopy = Lib.extendDeep({}, mock);
450+
gd = createGraphDiv();
451+
452+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done);
453+
});
454+
455+
afterEach(function() {
456+
destroyGraphDiv(gd);
457+
});
458+
459+
it('udpates bound components when the value changes', function(done) {
460+
expect(gd.layout.sliders[0].active).toBe(0);
461+
462+
Plotly.restyle(gd, 'marker.color', 'blue').then(function() {
463+
expect(gd.layout.sliders[0].active).toBe(4);
464+
}).catch(fail).then(done);
465+
});
466+
467+
it('udpates bound components when the computed changes', function(done) {
468+
expect(gd.layout.sliders[0].active).toBe(0);
469+
470+
// The default line color comes from the marker color, if specified.
471+
// That is, the fact that the marker color changes is just incidental, but
472+
// nonetheless is bound by value to the component.
473+
Plotly.restyle(gd, 'line.color', 'blue').then(function() {
474+
expect(gd.layout.sliders[0].active).toBe(4);
475+
}).catch(fail).then(done);
476+
});
477+
});

0 commit comments

Comments
 (0)