Skip to content

Commit 9fea24b

Browse files
committed
use newPlot intead of plot in various tests
1 parent b2f15e5 commit 9fea24b

19 files changed

+210
-134
lines changed

devtools/test_dashboard/devtools.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var Tabs = {
6060
var mockURL = '/test/image/mocks/' + mockName + '.json';
6161

6262
d3.json(mockURL, function(err, fig) {
63-
Plotly.plot(Tabs.fresh(id), fig);
63+
Plotly.newPlot(Tabs.fresh(id), fig);
6464

6565
console.warn('Plotting:', mockURL);
6666
});

test/jasmine/assets/check_component.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = function checkComponent(Plotly) {
3838

3939
beforeEach(function(done) {
4040
gd = createGraphDiv();
41-
Plotly.plot(gd, mock.data, mock.layout).then(done);
41+
Plotly.newPlot(gd, mock.data, mock.layout).then(done);
4242
});
4343

4444
afterEach(destroyGraphDiv);
@@ -74,7 +74,7 @@ module.exports = function checkComponent(Plotly) {
7474

7575
beforeEach(function(done) {
7676
gd = createGraphDiv();
77-
Plotly.plot(gd, mock.data, mock.layout).then(done);
77+
Plotly.newPlot(gd, mock.data, mock.layout).then(done);
7878
});
7979

8080
afterEach(destroyGraphDiv);

test/jasmine/assets/check_event_data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = function checkEventData(mock, x, y, additionalFields) {
1414
beforeEach(function(done) {
1515
gd = createGraphDiv();
1616

17-
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
17+
Plotly.newPlot(gd, mockCopy.data, mockCopy.layout)
1818
.then(done);
1919
});
2020

test/jasmine/assets/fail_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @example
99
*
10-
* Plotly.plot(...)
10+
* Plotly.newPlot(...)
1111
* .then(function(gd) {
1212
* assert(...);
1313
* assert(...);

test/jasmine/bundle_tests/bar_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Bundle with bar', function() {
1515
var mock = require('@mocks/bar_line.json');
1616

1717
beforeEach(function(done) {
18-
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
18+
Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done);
1919
});
2020

2121
afterEach(destroyGraphDiv);

test/jasmine/bundle_tests/choropleth_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Bundle with choropleth', function() {
2626
afterEach(destroyGraphDiv);
2727

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

test/jasmine/bundle_tests/contour_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Bundle with contour', function() {
1515
var mock = require('@mocks/contour_scatter.json');
1616

1717
beforeEach(function(done) {
18-
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
18+
Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done);
1919
});
2020

2121
afterEach(destroyGraphDiv);

test/jasmine/bundle_tests/core_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Bundle with core only', function() {
1414

1515
beforeEach(function(done) {
1616
gd = createGraphDiv();
17-
Plotly.plot(gd, mock.data, mock.layout).then(done);
17+
Plotly.newPlot(gd, mock.data, mock.layout).then(done);
1818
});
1919

2020
afterEach(destroyGraphDiv);

test/jasmine/bundle_tests/finance_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('Bundle with finance trace type', function() {
2828
});
2929

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

3434
expect(gSubplot.selectAll('g.trace.ohlc').size()).toEqual(1);

test/jasmine/bundle_tests/histogram2dcontour_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('Bundle with histogram2dcontour and histogram', function() {
1616
var mock = require('@mocks/2dhistogram_contour_subplots.json');
1717

1818
beforeEach(function(done) {
19-
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
19+
Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done);
2020
});
2121

2222
afterEach(destroyGraphDiv);

test/jasmine/bundle_tests/mathjax_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('Test MathJax:', function() {
5656
function testTitleScoot(fig, opts) {
5757
var xCategories = opts.xCategories;
5858

59-
return Plotly.plot(gd, fig)
59+
return Plotly.newPlot(gd, fig)
6060
.then(function() { assertNoIntersect('base'); })
6161
.then(function() { return Plotly.relayout(gd, 'xaxis.titlefont.size', 40); })
6262
.then(function() { assertNoIntersect('large title font size'); })

test/jasmine/tests/geo_test.js

+86-57
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ describe('Test geo interactions', function() {
12161216
}
12171217

12181218
gd.calcdata = undefined;
1219-
Plotly.plot(gd);
1219+
Plotly.newPlot(gd, gd.data, gd.layout);
12201220
i++;
12211221
}, INTERVAL);
12221222
});
@@ -1247,7 +1247,7 @@ describe('Test geo interactions', function() {
12471247
}
12481248

12491249
gd.calcdata = undefined;
1250-
Plotly.plot(gd);
1250+
Plotly.newPlot(gd, gd.data, gd.layout);
12511251
i++;
12521252
}, INTERVAL);
12531253
});
@@ -1278,7 +1278,7 @@ describe('Test geo interactions', function() {
12781278
}
12791279

12801280
gd.calcdata = undefined;
1281-
Plotly.plot(gd);
1281+
Plotly.newPlot(gd, gd.data, gd.layout);
12821282
i++;
12831283
}, INTERVAL);
12841284
});
@@ -1293,7 +1293,8 @@ describe('Test geo interactions', function() {
12931293
trace1.locations.shift();
12941294

12951295
gd.calcdata = undefined;
1296-
Plotly.plot(gd).then(function() {
1296+
Plotly.newPlot(gd, gd.data, gd.layout)
1297+
.then(function() {
12971298
expect(countTraces('scattergeo')).toBe(1);
12981299
expect(countTraces('choropleth')).toBe(1);
12991300

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

13211322
gd.calcdata = undefined;
1322-
Plotly.plot(gd).then(function() {
1323+
Plotly.newPlot(gd, gd.data, gd.layout)
1324+
.then(function() {
13231325
expect(countTraces('scattergeo')).toBe(1);
13241326
expect(countTraces('choropleth')).toBe(1);
13251327

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

2111-
afterEach(destroyGraphDiv);
2113+
beforeEach(function() { gd = createGraphDiv(); });
21122114

2113-
function plot(fig) {
2114-
gd = createGraphDiv();
2115+
afterEach(destroyGraphDiv);
21152116

2117+
var newPlot = function(fig) {
21162118
return Plotly.newPlot(gd, fig).then(function() {
21172119
gd.on('plotly_relayout', function(d) { eventData = d; });
21182120
gd.on('plotly_doubleclick', function() { dblClickCnt++; });
21192121
});
2120-
}
2122+
};
21212123

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

21982200
it('- base case', function(done) {
2199-
plot(fig).then(function() {
2201+
newPlot(fig).then(function() {
22002202
_assert('base', [
22012203
[-90, 0], [-90, 0], 1
22022204
], [
@@ -2261,7 +2263,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
22612263
it('- fitbounds case', function(done) {
22622264
fig.layout.geo.fitbounds = 'locations';
22632265

2264-
plot(fig).then(function() {
2266+
newPlot(fig).then(function() {
22652267
_assert('base', [
22662268
[undefined, 0], [undefined, undefined], undefined
22672269
], [
@@ -2345,7 +2347,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
23452347
}
23462348

23472349
it('- base case', function(done) {
2348-
plot(fig).then(function() {
2350+
newPlot(fig).then(function() {
23492351
_assert('base', [
23502352
[-75, 45], 1
23512353
], [
@@ -2408,7 +2410,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
24082410
it('- fitbounds case', function(done) {
24092411
fig.layout.geo.fitbounds = 'locations';
24102412

2411-
plot(fig).then(function() {
2413+
newPlot(fig).then(function() {
24122414
_assert('base', [
24132415
[undefined, undefined], undefined
24142416
], [
@@ -2496,7 +2498,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
24962498
}
24972499

24982500
it('- base case', function(done) {
2499-
plot(fig).then(function() {
2501+
newPlot(fig).then(function() {
25002502
_assert('base', [
25012503
[15, 57.5], 1,
25022504
], [
@@ -2549,7 +2551,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
25492551
it('- fitbounds case', function(done) {
25502552
fig.layout.geo.fitbounds = 'locations';
25512553

2552-
plot(fig).then(function() {
2554+
newPlot(fig).then(function() {
25532555
_assert('base', [
25542556
[undefined, undefined], undefined,
25552557
], [
@@ -2631,7 +2633,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
26312633
assertEventData(msg, eventKeys);
26322634
}
26332635

2634-
plot(fig).then(function() {
2636+
newPlot(fig).then(function() {
26352637
_assert('base', [
26362638
[-96.6, 38.7], 1,
26372639
], [
@@ -2689,7 +2691,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
26892691
fig.layout.width = 700;
26902692
fig.layout.height = 500;
26912693

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

2722-
plot(fig)
2724+
newPlot(fig)
27232725
.then(function() {
27242726
_assert('base', [1], [101.9], undefined);
27252727
})
@@ -2730,12 +2732,24 @@ describe('Test geo zoom/pan/drag interactions:', function() {
27302732
['geo.projection.rotation.lon', 'geo.center.lon', 'geo.center.lat', 'geo.projection.scale']
27312733
);
27322734
})
2733-
.then(function() { return Plotly.plot(gd, [], {}, {scrollZoom: false}); })
2735+
.then(function() {
2736+
return newPlot({
2737+
data: gd.data,
2738+
layout: gd.layout,
2739+
config: {scrollZoom: false}
2740+
});
2741+
})
27342742
.then(function() { return scroll([200, 250], [-200, -200]); })
27352743
.then(function() {
27362744
_assert('with scrollZoom:false', [1.3], [134.4], undefined);
27372745
})
2738-
.then(function() { return Plotly.plot(gd, [], {}, {scrollZoom: 'geo'}); })
2746+
.then(function() {
2747+
return newPlot({
2748+
data: gd.data,
2749+
layout: gd.layout,
2750+
config: {scrollZoom: 'geo'}
2751+
});
2752+
})
27392753
.then(function() { return scroll([200, 250], [-200, -200]); })
27402754
.then(function() {
27412755
_assert('with scrollZoom:geo',
@@ -2745,44 +2759,59 @@ describe('Test geo zoom/pan/drag interactions:', function() {
27452759
})
27462760
.then(done, done.fail);
27472761
});
2762+
});
27482763

2749-
describe('plotly_relayouting', function() {
2750-
var mocks = {
2751-
'non-clipped': require('@mocks/geo_winkel-tripel'),
2752-
'clipped': require('@mocks/geo_orthographic'),
2753-
'scoped': require('@mocks/geo_europe-bubbles')
2754-
};
2755-
['non-clipped', 'clipped', 'scoped'].forEach(function(zoomHandler) {
2756-
['pan'].forEach(function(dragmode) {
2757-
it('should emit events on ' + dragmode + ' for ' + zoomHandler, function(done) {
2758-
var events = []; var path = [[300, 300], [350, 300], [350, 400]];
2759-
var relayoutCnt = 0; var relayoutEvent;
2760-
var fig = Lib.extendDeep({}, mocks[zoomHandler]);
2761-
fig.layout.dragmode = dragmode;
2762-
fig.layout.width = 700;
2763-
fig.layout.height = 500;
2764-
2765-
gd = createGraphDiv();
2766-
Plotly.newPlot(gd, fig)
2767-
.then(function() {
2768-
gd.on('plotly_relayout', function(e) {
2769-
relayoutCnt++;
2770-
relayoutEvent = e;
2771-
});
2772-
gd.on('plotly_relayouting', function(e) {
2773-
events.push(e);
2774-
});
2775-
return drag({path: path, noCover: true});
2776-
})
2777-
.then(function() {
2778-
expect(events.length).toEqual(path.length - 1);
2779-
expect(relayoutCnt).toEqual(1);
2780-
Object.keys(relayoutEvent).sort().forEach(function(key) {
2781-
expect(Object.keys(events[0])).toContain(key);
2782-
});
2783-
})
2784-
.then(done, done.fail);
2785-
});
2764+
describe('plotly_relayouting', function() {
2765+
var gd;
2766+
var events;
2767+
var relayoutCnt;
2768+
var relayoutEvent;
2769+
2770+
beforeEach(function() { gd = createGraphDiv(); });
2771+
2772+
afterEach(destroyGraphDiv);
2773+
2774+
var newPlot = function(fig) {
2775+
events = [];
2776+
relayoutCnt = 0;
2777+
2778+
return Plotly.newPlot(gd, fig).then(function() {
2779+
gd.on('plotly_relayout', function(e) {
2780+
relayoutCnt++;
2781+
relayoutEvent = e;
2782+
});
2783+
gd.on('plotly_relayouting', function(e) {
2784+
events.push(e);
2785+
});
2786+
});
2787+
};
2788+
2789+
var mocks = {
2790+
'non-clipped': require('@mocks/geo_winkel-tripel'),
2791+
'clipped': require('@mocks/geo_orthographic'),
2792+
'scoped': require('@mocks/geo_europe-bubbles')
2793+
};
2794+
['non-clipped', 'clipped', 'scoped'].forEach(function(zoomHandler) {
2795+
['pan'].forEach(function(dragmode) {
2796+
it('should emit events on ' + dragmode + ' for ' + zoomHandler, function(done) {
2797+
var path = [[300, 300], [350, 300], [350, 400]];
2798+
var fig = Lib.extendDeep({}, mocks[zoomHandler]);
2799+
fig.layout.dragmode = dragmode;
2800+
fig.layout.width = 700;
2801+
fig.layout.height = 500;
2802+
2803+
newPlot(fig)
2804+
.then(function() {
2805+
return drag({path: path, noCover: true});
2806+
})
2807+
.then(function() {
2808+
expect(events.length).toEqual(path.length - 1);
2809+
expect(relayoutCnt).toEqual(1);
2810+
Object.keys(relayoutEvent).sort().forEach(function(key) {
2811+
expect(Object.keys(events[0])).toContain(key);
2812+
});
2813+
})
2814+
.then(done, done.fail);
27862815
});
27872816
});
27882817
});

0 commit comments

Comments
 (0)