Skip to content

Introducing Plotly.update #875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Sep 7, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add test for Plotly.update
- testing that the correct subroutines are called.
  • Loading branch information
etpinard committed Aug 22, 2016
commit 26c407597c22d4ba749b06d70a40e0ce3db3f6db
77 changes: 77 additions & 0 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var Scatter = require('@src/traces/scatter');
var Bar = require('@src/traces/bar');
var Legend = require('@src/components/legend');
var pkg = require('../../../package.json');
var subroutines = require('@src/plot_api/subroutines');

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
Expand Down Expand Up @@ -879,4 +880,80 @@ describe('Test plot api', function() {
expect(gd.data[1].contours).toBeUndefined();
});
});

describe('Plotly.update should', function() {
var gd, calcdata;

beforeAll(function() {
Object.keys(subroutines).forEach(function(k) {
spyOn(subroutines, k).and.callThrough();
});
});

beforeEach(function(done) {
gd = createGraphDiv();
Plotly.plot(gd, [{ y: [2, 1, 2] }]).then(function() {
calcdata = gd.calcdata;
done();
});
});

afterEach(destroyGraphDiv);

it('call doTraceStyle on trace style updates', function(done) {
expect(subroutines.doTraceStyle).not.toHaveBeenCalled();

Plotly.update(gd, { 'marker.color': 'blue' }).then(function() {
expect(subroutines.doTraceStyle).toHaveBeenCalledTimes(1);
expect(calcdata).toBe(gd.calcdata);
done();
});
});

it('clear calcdata on data updates', function(done) {
Plotly.update(gd, { x: [[3, 1, 3]] }).then(function() {
expect(calcdata).not.toBe(gd.calcdata);
done();
});
});

it('call doLegend on legend updates', function(done) {
expect(subroutines.doLegend).not.toHaveBeenCalled();

Plotly.update(gd, {}, { 'showlegend': true }).then(function() {
expect(subroutines.doLegend).toHaveBeenCalledTimes(1);
expect(calcdata).toBe(gd.calcdata);
done();
});
});

it('call layoutReplot when adding update menu', function(done) {
expect(subroutines.layoutReplot).not.toHaveBeenCalled();

var layoutUpdate = {
updatemenus: [{
buttons: [{
method: 'relayout',
args: ['title', 'Hello World']
}]
}]
};

Plotly.update(gd, {}, layoutUpdate).then(function() {
expect(subroutines.doLegend).toHaveBeenCalledTimes(1);
expect(calcdata).toBe(gd.calcdata);
done();
});
});

it('call doModeBar when updating \'dragmode\'', function(done) {
expect(subroutines.doModeBar).not.toHaveBeenCalled();

Plotly.update(gd, {}, { 'dragmode': 'pan' }).then(function() {
expect(subroutines.doModeBar).toHaveBeenCalledTimes(1);
expect(calcdata).toBe(gd.calcdata);
done();
});
});
});
});