Skip to content

Commit 94fd466

Browse files
committed
simplify Plotly.Fx and Plotly.Plots in the API
1 parent 373d4ff commit 94fd466

File tree

8 files changed

+36
-23
lines changed

8 files changed

+36
-23
lines changed

src/core.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,19 @@ if(window.PlotlyLocales && Array.isArray(window.PlotlyLocales)) {
7474
exports.Icons = require('./fonts/ploticon');
7575

7676
// unofficial 'beta' plot methods, use at your own risk
77-
exports.Plots = require('./plots/plots');
78-
exports.Fx = require('./components/fx');
77+
var Fx = require('./components/fx');
78+
var Plots = require('./plots/plots');
79+
80+
exports.Plots = {
81+
resize: Plots.resize,
82+
graphJson: Plots.graphJson
83+
};
84+
exports.Fx = {
85+
hover: Fx.hover,
86+
unhover: Fx.unhover,
87+
loneHover: Fx.loneHover,
88+
loneUnhover: Fx.loneUnhover
89+
};
7990
exports.Snapshot = require('./snapshot');
8091
exports.PlotSchema = require('./plot_api/plot_schema');
8192
exports.Queue = require('./lib/queue');

test/jasmine/bundle_tests/finance_test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var Plots = require('@src/plots/plots');
12
var Plotly = require('@lib/core');
23
var ohlc = require('@lib/ohlc');
34
var candlestick = require('@lib/candlestick');
@@ -14,13 +15,13 @@ describe('Bundle with finance trace type', function() {
1415
var mock = require('@mocks/finance_style.json');
1516

1617
it('should not register transforms anymore', function() {
17-
var transformModules = Object.keys(Plotly.Plots.transformsRegistry);
18+
var transformModules = Object.keys(Plots.transformsRegistry);
1819

1920
expect(transformModules).toEqual([]);
2021
});
2122

2223
it('should register the correct trace modules for the generated traces', function() {
23-
var traceModules = Object.keys(Plotly.Plots.modules);
24+
var traceModules = Object.keys(Plots.modules);
2425

2526
// scatter is registered no matter what
2627
// ohlc uses some parts of box by direct require but does not need to register it.

test/jasmine/tests/animate_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var Plotly = require('@lib/index');
22
var Lib = require('@src/lib');
33
var Registry = require('@src/registry');
4-
var Plots = Plotly.Plots;
4+
var Plots = require('@src/plots/plots');
55

66
var d3Select = require('../../strict-d3').select;
77
var d3SelectAll = require('../../strict-d3').selectAll;

test/jasmine/tests/click_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var Plotly = require('@lib/index');
2+
var Plots = require('@src/plots/plots');
23
var Lib = require('@src/lib');
34
var Drawing = require('@src/components/drawing');
45
var DBLCLICKDELAY = require('@src/plot_api/plot_config').dfltConfig.doubleClickDelay;
@@ -50,7 +51,7 @@ describe('Test click interactions:', function() {
5051

5152
function doubleClick(x, y) {
5253
return doubleClickRaw(x, y).then(function() {
53-
return Plotly.Plots.previousPromises(gd);
54+
return Plots.previousPromises(gd);
5455
});
5556
}
5657

test/jasmine/tests/command_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var Plotly = require('@lib/index');
22
var Registry = require('@src/registry');
3-
var Plots = Plotly.Plots;
3+
var Plots = require('@src/plots/plots');
44
var createGraphDiv = require('../assets/create_graph_div');
55
var destroyGraphDiv = require('../assets/destroy_graph_div');
66
var failTest = require('../assets/fail_test');

test/jasmine/tests/config_test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var Plotly = require('@lib/index');
2-
var Plots = Plotly.Plots;
2+
var Plots = require('@src/plots/plots');
33
var Lib = require('@src/lib');
44

55
var d3Select = require('../../strict-d3').select;
@@ -533,7 +533,7 @@ describe('config argument', function() {
533533
expect(gd._context.plotlyServerURL).not.toBe('https://chart-studio.plotly.com');
534534
expect(gd._context.plotlyServerURL).toBe('');
535535

536-
Plotly.Plots.sendDataToCloud(gd);
536+
Plots.sendDataToCloud(gd);
537537
expect(form).toBe(undefined);
538538
})
539539
.then(done, done.fail);
@@ -546,7 +546,7 @@ describe('config argument', function() {
546546
.then(function() {
547547
expect(gd._context.plotlyServerURL).toBe('https://chart-studio.plotly.com');
548548

549-
Plotly.Plots.sendDataToCloud(gd);
549+
Plots.sendDataToCloud(gd);
550550
expect(form.action).toBe('https://chart-studio.plotly.com/external');
551551
expect(form.method).toBe('post');
552552
})
@@ -558,7 +558,7 @@ describe('config argument', function() {
558558
.then(function() {
559559
expect(gd._context.plotlyServerURL).toBe('dummy');
560560

561-
Plotly.Plots.sendDataToCloud(gd);
561+
Plots.sendDataToCloud(gd);
562562
expect(form.action).toContain('/dummy/external');
563563
expect(form.method).toBe('post');
564564
})
@@ -572,7 +572,7 @@ describe('config argument', function() {
572572
.then(function() {
573573
expect(gd._context.plotlyServerURL).toBe('dummy');
574574

575-
Plotly.Plots.sendDataToCloud(gd);
575+
Plots.sendDataToCloud(gd);
576576
expect(form.action).toContain('/yo/external');
577577
expect(form.method).toBe('post');
578578
})
@@ -687,7 +687,7 @@ describe('config argument', function() {
687687
fillParent(1, 1);
688688
var cntWindowResize = 0;
689689
window.addEventListener('resize', function() {cntWindowResize++;});
690-
spyOn(Plotly.Plots, 'resize').and.callThrough();
690+
spyOn(Plots, 'resize').and.callThrough();
691691

692692
Plotly.newPlot(gd, data, {}, {responsive: true})
693693
.then(function() {return Plotly.restyle(gd, 'y[0]', data[0].y[0] + 2);})
@@ -696,7 +696,7 @@ describe('config argument', function() {
696696
// .then(function() {viewport.set(newWidth, 2 * newHeight);}).then(delay(200))
697697
.then(function() {
698698
expect(cntWindowResize).toBe(1);
699-
expect(Plotly.Plots.resize.calls.count()).toBe(1);
699+
expect(Plots.resize.calls.count()).toBe(1);
700700
})
701701
.then(done, done.fail);
702702
});
@@ -807,7 +807,7 @@ describe('config argument', function() {
807807
});
808808

809809
it('should not resize if gd is hidden', function(done) {
810-
spyOn(Plotly.Plots, 'resize').and.callThrough();
810+
spyOn(Plots, 'resize').and.callThrough();
811811

812812
fillParent(1, 1);
813813
Plotly.newPlot(gd, data, {}, {responsive: true})
@@ -817,7 +817,7 @@ describe('config argument', function() {
817817
})
818818
.then(delay(RESIZE_DELAY))
819819
.then(function() {
820-
expect(Plotly.Plots.resize.calls.count()).toBe(0);
820+
expect(Plots.resize.calls.count()).toBe(0);
821821
})
822822
.then(done, done.fail);
823823
});

test/jasmine/tests/plots_test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ describe('Test Plots', function() {
336336
gd.style.width = '400px';
337337
gd.style.height = '400px';
338338

339-
return Plotly.Plots.resize(gd);
339+
return Plots.resize(gd);
340340
})
341341
.then(done);
342342
});
@@ -390,7 +390,7 @@ describe('Test Plots', function() {
390390
expect(typeof gd.id).toBe('string');
391391
expect(gd.id).toBeTruthy();
392392

393-
Plotly.Plots.resize(gd.id)
393+
Plots.resize(gd.id)
394394
.then(done, done.fail);
395395
});
396396
});
@@ -412,7 +412,7 @@ describe('Test Plots', function() {
412412

413413
Plotly.newPlot(gd, [], {})
414414
.then(function() { _assert({l: 74, r: 74, t: 82, b: 66}); })
415-
.then(function() { return Plotly.Plots.resize(gd); })
415+
.then(function() { return Plots.resize(gd); })
416416
.then(function() { _assert({l: 74, r: 74, t: 82, b: 66}); })
417417
.then(done, done.fail);
418418
});
@@ -428,9 +428,9 @@ describe('Test Plots', function() {
428428
.then(function() {
429429
gd.style.width = '500px';
430430
gd.style.height = '500px';
431-
p.push(Plotly.Plots.resize(gd));
432-
p.push(Plotly.Plots.resize(gd));
433-
p.push(Plotly.Plots.resize(gd));
431+
p.push(Plots.resize(gd));
432+
p.push(Plots.resize(gd));
433+
p.push(Plots.resize(gd));
434434
return Promise.all(p);
435435
})
436436
.then(function(v) {

test/jasmine/tests/transition_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var Plotly = require('@lib/index');
22
var Lib = require('@src/lib');
3-
var Plots = Plotly.Plots;
3+
var Plots = require('@src/plots/plots');
44
var plotApiHelpers = require('@src/plot_api/helpers');
55
var Axes = require('@src/plots/cartesian/axes');
66
var Registry = require('@src/registry');

0 commit comments

Comments
 (0)