Skip to content

More newPlot calls in tests #5393

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 4 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 1 addition & 1 deletion devtools/test_dashboard/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var Tabs = {
var mockURL = '/test/image/mocks/' + mockName + '.json';

d3.json(mockURL, function(err, fig) {
Plotly.plot(Tabs.fresh(id), fig);
Plotly.newPlot(Tabs.fresh(id), fig);

console.warn('Plotting:', mockURL);
});
Expand Down
4 changes: 2 additions & 2 deletions test/jasmine/assets/check_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function checkComponent(Plotly) {

beforeEach(function(done) {
gd = createGraphDiv();
Plotly.plot(gd, mock.data, mock.layout).then(done);
Plotly.newPlot(gd, mock.data, mock.layout).then(done);
});

afterEach(destroyGraphDiv);
Expand Down Expand Up @@ -74,7 +74,7 @@ module.exports = function checkComponent(Plotly) {

beforeEach(function(done) {
gd = createGraphDiv();
Plotly.plot(gd, mock.data, mock.layout).then(done);
Plotly.newPlot(gd, mock.data, mock.layout).then(done);
});

afterEach(destroyGraphDiv);
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/assets/check_event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function checkEventData(mock, x, y, additionalFields) {
beforeEach(function(done) {
gd = createGraphDiv();

Plotly.plot(gd, mockCopy.data, mockCopy.layout)
Plotly.newPlot(gd, mockCopy.data, mockCopy.layout)
.then(done);
});

Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/assets/fail_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @example
*
* Plotly.plot(...)
* Plotly.newPlot(...)
* .then(function(gd) {
* assert(...);
* assert(...);
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/bundle_tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Bundle with bar', function() {
var mock = require('@mocks/bar_line.json');

beforeEach(function(done) {
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done);
});

afterEach(destroyGraphDiv);
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/bundle_tests/choropleth_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Bundle with choropleth', function() {
afterEach(destroyGraphDiv);

it('should graph choropleth traces', function(done) {
Plotly.plot(gd, mock.data, mock.layout)
Plotly.newPlot(gd, mock.data, mock.layout)
.then(function() {
var nodes = d3.selectAll('g.trace.choropleth');

Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/bundle_tests/contour_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Bundle with contour', function() {
var mock = require('@mocks/contour_scatter.json');

beforeEach(function(done) {
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done);
});

afterEach(destroyGraphDiv);
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/bundle_tests/core_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Bundle with core only', function() {

beforeEach(function(done) {
gd = createGraphDiv();
Plotly.plot(gd, mock.data, mock.layout).then(done);
Plotly.newPlot(gd, mock.data, mock.layout).then(done);
});

afterEach(destroyGraphDiv);
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/bundle_tests/finance_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Bundle with finance trace type', function() {
});

it('should graph ohlc and candlestick traces', function(done) {
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(function() {
Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(function() {
var gSubplot = d3.select('g.cartesianlayer');

expect(gSubplot.selectAll('g.trace.ohlc').size()).toEqual(1);
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/bundle_tests/histogram2dcontour_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Bundle with histogram2dcontour and histogram', function() {
var mock = require('@mocks/2dhistogram_contour_subplots.json');

beforeEach(function(done) {
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done);
});

afterEach(destroyGraphDiv);
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/bundle_tests/mathjax_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Test MathJax:', function() {
function testTitleScoot(fig, opts) {
var xCategories = opts.xCategories;

return Plotly.plot(gd, fig)
return Plotly.newPlot(gd, fig)
.then(function() { assertNoIntersect('base'); })
.then(function() { return Plotly.relayout(gd, 'xaxis.titlefont.size', 40); })
.then(function() { assertNoIntersect('large title font size'); })
Expand Down
4 changes: 2 additions & 2 deletions test/jasmine/tests/contour_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,13 @@ describe('contour hover', function() {
afterAll(destroyGraphDiv);

it('should not display hover on missing data and hoverongaps is disabled', function() {
var pt = _hover(gd, 10, 100)[0];

var hoverData;
gd.on('plotly_hover', function(data) {
hoverData = data;
});

var pt = _hover(gd, 10, 100)[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch 🤦


expect(hoverData).toEqual(undefined);
expect(pt).toEqual(undefined);
});
Expand Down
143 changes: 86 additions & 57 deletions test/jasmine/tests/geo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ describe('Test geo interactions', function() {
}

gd.calcdata = undefined;
Plotly.plot(gd);
Plotly.newPlot(gd, gd.data, gd.layout);
i++;
}, INTERVAL);
});
Expand Down Expand Up @@ -1247,7 +1247,7 @@ describe('Test geo interactions', function() {
}

gd.calcdata = undefined;
Plotly.plot(gd);
Plotly.newPlot(gd, gd.data, gd.layout);
i++;
}, INTERVAL);
});
Expand Down Expand Up @@ -1278,7 +1278,7 @@ describe('Test geo interactions', function() {
}

gd.calcdata = undefined;
Plotly.plot(gd);
Plotly.newPlot(gd, gd.data, gd.layout);
i++;
}, INTERVAL);
});
Expand All @@ -1293,7 +1293,8 @@ describe('Test geo interactions', function() {
trace1.locations.shift();

gd.calcdata = undefined;
Plotly.plot(gd).then(function() {
Plotly.newPlot(gd, gd.data, gd.layout)
.then(function() {
expect(countTraces('scattergeo')).toBe(1);
expect(countTraces('choropleth')).toBe(1);

Expand All @@ -1319,7 +1320,8 @@ describe('Test geo interactions', function() {
trace1.z = zQueue;

gd.calcdata = undefined;
Plotly.plot(gd).then(function() {
Plotly.newPlot(gd, gd.data, gd.layout)
.then(function() {
expect(countTraces('scattergeo')).toBe(1);
expect(countTraces('choropleth')).toBe(1);

Expand Down Expand Up @@ -2108,16 +2110,16 @@ describe('Test geo zoom/pan/drag interactions:', function() {
var eventData;
var dblClickCnt = 0;

afterEach(destroyGraphDiv);
beforeEach(function() { gd = createGraphDiv(); });

function plot(fig) {
gd = createGraphDiv();
afterEach(destroyGraphDiv);

var newPlot = function(fig) {
return Plotly.newPlot(gd, fig).then(function() {
gd.on('plotly_relayout', function(d) { eventData = d; });
gd.on('plotly_doubleclick', function() { dblClickCnt++; });
});
}
};

function assertEventData(msg, eventKeys) {
if(eventKeys === 'dblclick') {
Expand Down Expand Up @@ -2196,7 +2198,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
}

it('- base case', function(done) {
plot(fig).then(function() {
newPlot(fig).then(function() {
_assert('base', [
[-90, 0], [-90, 0], 1
], [
Expand Down Expand Up @@ -2261,7 +2263,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
it('- fitbounds case', function(done) {
fig.layout.geo.fitbounds = 'locations';

plot(fig).then(function() {
newPlot(fig).then(function() {
_assert('base', [
[undefined, 0], [undefined, undefined], undefined
], [
Expand Down Expand Up @@ -2345,7 +2347,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
}

it('- base case', function(done) {
plot(fig).then(function() {
newPlot(fig).then(function() {
_assert('base', [
[-75, 45], 1
], [
Expand Down Expand Up @@ -2408,7 +2410,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
it('- fitbounds case', function(done) {
fig.layout.geo.fitbounds = 'locations';

plot(fig).then(function() {
newPlot(fig).then(function() {
_assert('base', [
[undefined, undefined], undefined
], [
Expand Down Expand Up @@ -2496,7 +2498,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
}

it('- base case', function(done) {
plot(fig).then(function() {
newPlot(fig).then(function() {
_assert('base', [
[15, 57.5], 1,
], [
Expand Down Expand Up @@ -2549,7 +2551,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
it('- fitbounds case', function(done) {
fig.layout.geo.fitbounds = 'locations';

plot(fig).then(function() {
newPlot(fig).then(function() {
_assert('base', [
[undefined, undefined], undefined,
], [
Expand Down Expand Up @@ -2631,7 +2633,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
assertEventData(msg, eventKeys);
}

plot(fig).then(function() {
newPlot(fig).then(function() {
_assert('base', [
[-96.6, 38.7], 1,
], [
Expand Down Expand Up @@ -2689,7 +2691,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
fig.layout.width = 700;
fig.layout.height = 500;

plot(fig)
newPlot(fig)
.then(function() { return scroll([131, 159], [-200, 200]); })
.then(function() {
// scrolling outside subplot frame should log errors,
Expand Down Expand Up @@ -2719,7 +2721,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
assertEventData(msg, eventKeys);
}

plot(fig)
newPlot(fig)
.then(function() {
_assert('base', [1], [101.9], undefined);
})
Expand All @@ -2730,12 +2732,24 @@ describe('Test geo zoom/pan/drag interactions:', function() {
['geo.projection.rotation.lon', 'geo.center.lon', 'geo.center.lat', 'geo.projection.scale']
);
})
.then(function() { return Plotly.plot(gd, [], {}, {scrollZoom: false}); })
.then(function() {
return newPlot({
data: gd.data,
layout: gd.layout,
config: {scrollZoom: false}
});
})
.then(function() { return scroll([200, 250], [-200, -200]); })
.then(function() {
_assert('with scrollZoom:false', [1.3], [134.4], undefined);
})
.then(function() { return Plotly.plot(gd, [], {}, {scrollZoom: 'geo'}); })
.then(function() {
return newPlot({
data: gd.data,
layout: gd.layout,
config: {scrollZoom: 'geo'}
});
})
.then(function() { return scroll([200, 250], [-200, -200]); })
.then(function() {
_assert('with scrollZoom:geo',
Expand All @@ -2745,44 +2759,59 @@ describe('Test geo zoom/pan/drag interactions:', function() {
})
.then(done, done.fail);
});
});

describe('plotly_relayouting', function() {
var mocks = {
'non-clipped': require('@mocks/geo_winkel-tripel'),
'clipped': require('@mocks/geo_orthographic'),
'scoped': require('@mocks/geo_europe-bubbles')
};
['non-clipped', 'clipped', 'scoped'].forEach(function(zoomHandler) {
['pan'].forEach(function(dragmode) {
it('should emit events on ' + dragmode + ' for ' + zoomHandler, function(done) {
var events = []; var path = [[300, 300], [350, 300], [350, 400]];
var relayoutCnt = 0; var relayoutEvent;
var fig = Lib.extendDeep({}, mocks[zoomHandler]);
fig.layout.dragmode = dragmode;
fig.layout.width = 700;
fig.layout.height = 500;

gd = createGraphDiv();
Plotly.newPlot(gd, fig)
.then(function() {
gd.on('plotly_relayout', function(e) {
relayoutCnt++;
relayoutEvent = e;
});
gd.on('plotly_relayouting', function(e) {
events.push(e);
});
return drag({path: path, noCover: true});
})
.then(function() {
expect(events.length).toEqual(path.length - 1);
expect(relayoutCnt).toEqual(1);
Object.keys(relayoutEvent).sort().forEach(function(key) {
expect(Object.keys(events[0])).toContain(key);
});
})
.then(done, done.fail);
});
describe('plotly_relayouting', function() {
var gd;
var events;
var relayoutCnt;
var relayoutEvent;

beforeEach(function() { gd = createGraphDiv(); });

afterEach(destroyGraphDiv);

var newPlot = function(fig) {
events = [];
relayoutCnt = 0;

return Plotly.newPlot(gd, fig).then(function() {
gd.on('plotly_relayout', function(e) {
relayoutCnt++;
relayoutEvent = e;
});
gd.on('plotly_relayouting', function(e) {
events.push(e);
});
});
};

var mocks = {
'non-clipped': require('@mocks/geo_winkel-tripel'),
'clipped': require('@mocks/geo_orthographic'),
'scoped': require('@mocks/geo_europe-bubbles')
};
['non-clipped', 'clipped', 'scoped'].forEach(function(zoomHandler) {
['pan'].forEach(function(dragmode) {
it('should emit events on ' + dragmode + ' for ' + zoomHandler, function(done) {
var path = [[300, 300], [350, 300], [350, 400]];
var fig = Lib.extendDeep({}, mocks[zoomHandler]);
fig.layout.dragmode = dragmode;
fig.layout.width = 700;
fig.layout.height = 500;

newPlot(fig)
.then(function() {
return drag({path: path, noCover: true});
})
.then(function() {
expect(events.length).toEqual(path.length - 1);
expect(relayoutCnt).toEqual(1);
Object.keys(relayoutEvent).sort().forEach(function(key) {
expect(Object.keys(events[0])).toContain(key);
});
})
.then(done, done.fail);
});
});
});
Expand Down
Loading