Skip to content

Commit 07fb7c3

Browse files
authored
Merge pull request #5412 from plotly/make-Plotly.plot-internal
Drop Plotly.plot from the API
2 parents 997946b + d688bba commit 07fb7c3

15 files changed

+89
-73
lines changed

src/plot_api/edit_types.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ var traceOpts = {
1818
flags: ['calc', 'clearAxisTypes', 'plot', 'style', 'markerSize', 'colorbars'],
1919
description: [
2020
'trace attributes should include an `editType` string matching this flaglist.',
21-
'*calc* is the most extensive: a full `Plotly.plot` starting by clearing `gd.calcdata`',
21+
'*calc* is the most extensive: a full (re)plot starting by clearing `gd.calcdata`',
2222
'to force it to be regenerated',
2323
'*clearAxisTypes* resets the types of the axes this trace is on, because new data could',
2424
'cause the automatic axis type detection to change. Log type will not be cleared, as that',
2525
'is never automatically chosen so must have been user-specified.',
26-
'*plot* calls `Plotly.plot` but without first clearing `gd.calcdata`.',
26+
'*plot* (re)plots but without first clearing `gd.calcdata`.',
2727
'*style* only calls `module.style` (or module.editStyle) for all trace modules and redraws the legend.',
2828
'*markerSize* is like *style*, but propagate axis-range changes due to scatter `marker.size`',
2929
'*colorbars* only redraws colorbars.'
@@ -39,9 +39,9 @@ var layoutOpts = {
3939
],
4040
description: [
4141
'layout attributes should include an `editType` string matching this flaglist.',
42-
'*calc* is the most extensive: a full `Plotly.plot` starting by clearing `gd.calcdata`',
42+
'*calc* is the most extensive: a full (re)plot starting by clearing `gd.calcdata`',
4343
'to force it to be regenerated',
44-
'*plot* calls `Plotly.plot` but without first clearing `gd.calcdata`.',
44+
'*plot* (re)plots but without first clearing `gd.calcdata`.',
4545
'*legend* only redraws the legend.',
4646
'*ticks* only redraws axis ticks, labels, and gridlines.',
4747
'*axrange* minimal sequence when updating axis ranges.',

src/plot_api/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
var main = require('./plot_api');
1212

13-
exports.plot = main.plot;
13+
exports._doPlot = main._doPlot;
1414
exports.newPlot = main.newPlot;
1515
exports.restyle = main.restyle;
1616
exports.relayout = main.relayout;

src/plot_api/plot_api.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var numericNameWarningCount = 0;
4141
var numericNameWarningCountLimit = 5;
4242

4343
/**
44-
* Main plot-creation function
44+
* Internal plot-creation function
4545
*
4646
* @param {string id or DOM element} gd
4747
* the id or DOM element of the graph container div
@@ -61,7 +61,7 @@ var numericNameWarningCountLimit = 5;
6161
* object containing `data`, `layout`, `config`, and `frames` members
6262
*
6363
*/
64-
function plot(gd, data, layout, config) {
64+
function _doPlot(gd, data, layout, config) {
6565
var frames;
6666

6767
gd = Lib.getGraphDiv(gd);
@@ -83,7 +83,7 @@ function plot(gd, data, layout, config) {
8383
// if there's no data or layout, and this isn't yet a plotly plot
8484
// container, log a warning to help plotly.js users debug
8585
if(!data && !layout && !Lib.isPlotDiv(gd)) {
86-
Lib.warn('Calling Plotly.plot as if redrawing ' +
86+
Lib.warn('Calling _doPlot as if redrawing ' +
8787
'but this container doesn\'t yet have a plot.', gd);
8888
}
8989

@@ -139,7 +139,7 @@ function plot(gd, data, layout, config) {
139139
var fullLayout = gd._fullLayout;
140140
var hasCartesian = fullLayout._has('cartesian');
141141

142-
// so we don't try to re-call Plotly.plot from inside
142+
// so we don't try to re-call _doPlot from inside
143143
// legend and colorbar, if margins changed
144144
fullLayout._replotting = true;
145145

@@ -167,7 +167,7 @@ function plot(gd, data, layout, config) {
167167
// prepare the data and find the autorange
168168

169169
// generate calcdata, if we need to
170-
// to force redoing calcdata, just delete it before calling Plotly.plot
170+
// to force redoing calcdata, just delete it before calling _doPlot
171171
var recalc = !gd.calcdata || gd.calcdata.length !== (gd._fullData || []).length;
172172
if(recalc) Plots.doCalcdata(gd);
173173

@@ -552,7 +552,7 @@ function redraw(gd) {
552552
helpers.cleanLayout(gd.layout);
553553

554554
gd.calcdata = undefined;
555-
return exports.plot(gd).then(function() {
555+
return exports._doPlot(gd).then(function() {
556556
gd.emit('plotly_redraw');
557557
return gd;
558558
});
@@ -573,7 +573,7 @@ function newPlot(gd, data, layout, config) {
573573
Plots.cleanPlot([], {}, gd._fullData || [], gd._fullLayout || {});
574574

575575
Plots.purge(gd);
576-
return exports.plot(gd, data, layout, config);
576+
return exports._doPlot(gd, data, layout, config);
577577
}
578578

579579
/**
@@ -1284,7 +1284,7 @@ function restyle(gd, astr, val, _traces) {
12841284
var seq = [];
12851285

12861286
if(flags.fullReplot) {
1287-
seq.push(exports.plot);
1287+
seq.push(exports._doPlot);
12881288
} else {
12891289
seq.push(Plots.previousPromises);
12901290

@@ -2313,7 +2313,7 @@ function update(gd, traceUpdate, layoutUpdate, _traces) {
23132313
// relayoutFlags.layoutReplot and restyleFlags.fullReplot are true
23142314
seq.push(subroutines.layoutReplot);
23152315
} else if(restyleFlags.fullReplot) {
2316-
seq.push(exports.plot);
2316+
seq.push(exports._doPlot);
23172317
} else {
23182318
seq.push(Plots.previousPromises);
23192319
axRangeSupplyDefaultsByPass(gd, relayoutFlags, relayoutSpecs) || Plots.supplyDefaults(gd);
@@ -2705,7 +2705,7 @@ function react(gd, data, layout, config) {
27052705
});
27062706
} else if(restyleFlags.fullReplot || relayoutFlags.layoutReplot || configChanged) {
27072707
gd._fullLayout._skipDefaults = true;
2708-
seq.push(exports.plot);
2708+
seq.push(exports._doPlot);
27092709
} else {
27102710
for(var componentType in relayoutFlags.arrays) {
27112711
var indices = relayoutFlags.arrays[componentType];
@@ -3604,7 +3604,7 @@ function deleteFrames(gd, frameList) {
36043604
}
36053605

36063606
/**
3607-
* Purge a graph container div back to its initial pre-Plotly.plot state
3607+
* Purge a graph container div back to its initial pre-_doPlot state
36083608
*
36093609
* @param {string id or DOM element} gd
36103610
* the id or DOM element of the graph container div
@@ -3627,7 +3627,7 @@ function purge(gd) {
36273627
// remove plot container
36283628
if(fullLayout._container) fullLayout._container.remove();
36293629

3630-
// in contrast to Plotly.Plots.purge which does NOT clear _context!
3630+
// in contrast to _doPlots.purge which does NOT clear _context!
36313631
delete gd._context;
36323632

36333633
return gd;
@@ -3808,7 +3808,7 @@ exports.moveTraces = moveTraces;
38083808
exports.prependTraces = prependTraces;
38093809

38103810
exports.newPlot = newPlot;
3811-
exports.plot = plot;
3811+
exports._doPlot = _doPlot;
38123812
exports.purge = purge;
38133813

38143814
exports.react = react;

src/plot_api/plot_config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/**
1212
* This will be transferred over to gd and overridden by
13-
* config args to Plotly.plot.
13+
* config args to Plotly.newPlot.
1414
*
1515
* The defaults are the appropriate settings for plotly.js,
1616
* so we get the right experience without any config argument.

src/plot_api/subroutines.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ exports.doColorBars = function(gd) {
536536
exports.layoutReplot = function(gd) {
537537
var layout = gd.layout;
538538
gd.layout = undefined;
539-
return Registry.call('plot', gd, '', layout);
539+
return Registry.call('_doPlot', gd, '', layout);
540540
};
541541

542542
exports.doLegend = function(gd) {

src/plot_api/to_image.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ function toImage(gd, opts) {
229229
}
230230

231231
return new Promise(function(resolve, reject) {
232-
plotApi.plot(clonedGd, data, layoutImage, configImage)
232+
plotApi.newPlot(clonedGd, data, layoutImage, configImage)
233233
.then(redrawFunc)
234234
.then(wait)
235235
.then(convert)

src/plots/mapbox/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ module.exports = {
167167
'Missing Mapbox access token.',
168168
'Mapbox trace type require a Mapbox access token to be registered.',
169169
'For example:',
170-
' Plotly.plot(gd, data, layout, { mapboxAccessToken: \'my-access-token\' });',
170+
' Plotly.newPlot(gd, data, layout, { mapboxAccessToken: \'my-access-token\' });',
171171
'More info here: https://www.mapbox.com/help/define-access-token/'
172172
].join('\n'),
173173

src/plots/plots.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ plots.previousPromises = function(gd) {
124124

125125
/**
126126
* Adds the 'Edit chart' link.
127-
* Note that now Plotly.plot() calls this so it can regenerate whenever it replots
127+
* Note that now _doPlot calls this so it can regenerate whenever it replots
128128
*
129129
* Add source links to your graph inside the 'showSources' config argument.
130130
*/
@@ -1750,7 +1750,7 @@ plots.purge = function(gd) {
17501750
delete gd.autoplay; // are we doing an action that doesn't go in undo queue?
17511751
delete gd.changed;
17521752

1753-
// these get recreated on Plotly.plot anyway, but just to be safe
1753+
// these get recreated on _doPlot anyway, but just to be safe
17541754
// (and to have a record of them...)
17551755
delete gd._promises;
17561756
delete gd._redrawTimer;
@@ -2077,7 +2077,7 @@ plots.doAutoMargin = function(gd) {
20772077
var maxNumberOfRedraws = 3 * (1 + Object.keys(pushMarginIds).length);
20782078

20792079
if(fullLayout._redrawFromAutoMarginCount < maxNumberOfRedraws) {
2080-
return Registry.call('plot', gd);
2080+
return Registry.call('_doPlot', gd);
20812081
} else {
20822082
fullLayout._size = oldMargins;
20832083
Lib.warn('Too many auto-margin redraws.');

src/snapshot/toimage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function toImage(gd, opts) {
6161

6262
var redrawFunc = helpers.getRedrawFunc(clonedGd);
6363

64-
Registry.call('plot', clonedGd, clone.data, clone.layout, clone.config)
64+
Registry.call('_doPlot', clonedGd, clone.data, clone.layout, clone.config)
6565
.then(redrawFunc)
6666
.then(wait)
6767
.catch(function(err) {

tasks/util/container_commands.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var constants = require('./constants');
33
var containerCommands = {
44
cdHome: 'cd ' + constants.testContainerHome,
55
cpIndex: 'cp -f test/image/index.html ../server_app/index.html',
6+
replacePlotbyNewPlot: 'sed -i \'s/Plotly.plot/Plotly.newPlot/g\' ../server_app/main.js',
67
injectEnv: [
78
'sed -i',
89
's/process.env.PLOTLY_MAPBOX_DEFAULT_ACCESS_TOKEN/\\\'' + constants.mapboxAccessToken + '\\\'/',
@@ -20,6 +21,7 @@ containerCommands.ping = [
2021
containerCommands.setup = [
2122
containerCommands.cpIndex,
2223
containerCommands.injectEnv,
24+
containerCommands.replacePlotbyNewPlot,
2325
containerCommands.restart,
2426
containerCommands.ping,
2527
'sleep 5'

test/jasmine/tests/parcoords_test.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
var Plotly = require('@lib/index');
22
var Lib = require('@src/lib');
3+
var Registry = require('@src/registry');
4+
function _doPlot(gd, fig) {
5+
return Registry.call('_doPlot', gd, fig.data, fig.layout);
6+
}
7+
38
var d3Select = require('../../strict-d3').select;
49
var d3SelectAll = require('../../strict-d3').selectAll;
510
var Plots = require('@src/plots/plots');
@@ -668,7 +673,7 @@ describe('parcoords Lifecycle methods', function() {
668673
.then(function() {
669674
expect(gd.data.length).toEqual(1);
670675
expect(document.querySelectorAll('.y-axis').length).toEqual(10);
671-
return Plotly.plot(gd, mockCopy2);
676+
return _doPlot(gd, mockCopy2);
672677
})
673678
.then(function() {
674679
expect(gd.data.length).toEqual(2);
@@ -737,7 +742,7 @@ describe('parcoords Lifecycle methods', function() {
737742
});
738743

739744
describe('Having two datasets', function() {
740-
it('@gl Two subsequent calls to Plotly.plot should create two parcoords rows', function(done) {
745+
it('@gl Two subsequent calls to _doPlot should create two parcoords rows', function(done) {
741746
var mockCopy = Lib.extendDeep({}, mock);
742747
var mockCopy2 = Lib.extendDeep({}, mock);
743748
mockCopy.data[0].domain = {x: [0, 0.45]};
@@ -752,7 +757,7 @@ describe('parcoords Lifecycle methods', function() {
752757
expect(document.querySelectorAll('.gl-container').length).toEqual(1);
753758
expect(gd.data.length).toEqual(1);
754759

755-
return Plotly.plot(gd, mockCopy2);
760+
return _doPlot(gd, mockCopy2);
756761
})
757762
.then(function() {
758763
expect(1).toEqual(1);
@@ -944,15 +949,15 @@ describe('parcoords basic use', function() {
944949
.then(done, done.fail);
945950
});
946951

947-
it('@gl Calling `Plotly.plot` again should add the new parcoords', function(done) {
952+
it('@gl Calling _doPlot again should add the new parcoords', function(done) {
948953
var reversedMockCopy = Lib.extendDeep({}, mockCopy);
949954
reversedMockCopy.data[0].dimensions = reversedMockCopy.data[0].dimensions.slice().reverse();
950955
reversedMockCopy.data[0].dimensions.forEach(function(d) {d.id = 'R_' + d.id;});
951956
reversedMockCopy.data[0].dimensions.forEach(function(d) {d.label = 'R_' + d.label;});
952957

953958
Plotly.react(gd, mockCopy)
954959
.then(function() {
955-
return Plotly.plot(gd, reversedMockCopy);
960+
return _doPlot(gd, reversedMockCopy);
956961
})
957962
.then(function() {
958963
expect(gd.data.length).toEqual(2);

test/jasmine/tests/plot_api_react_test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('@noCIdep Plotly.react', function() {
3737
beforeEach(function() {
3838
gd = createGraphDiv();
3939

40-
spyOn(plotApi, 'plot').and.callThrough();
40+
spyOn(plotApi, '_doPlot').and.callThrough();
4141
spyOn(Registry, 'call').and.callThrough();
4242

4343
mockedMethods.forEach(function(m) {
@@ -54,7 +54,7 @@ describe('@noCIdep Plotly.react', function() {
5454
afterEach(destroyGraphDiv);
5555

5656
function countPlots() {
57-
plotApi.plot.calls.reset();
57+
plotApi._doPlot.calls.reset();
5858
subroutines.layoutStyles.calls.reset();
5959
annotations.draw.calls.reset();
6060
annotations.drawOne.calls.reset();
@@ -73,13 +73,13 @@ describe('@noCIdep Plotly.react', function() {
7373
subroutines[m].calls.reset();
7474
});
7575

76-
// calls to Plotly.newPlot via plot_api.js or Registry.call('plot')
77-
var plotCalls = plotApi.plot.calls.count() +
76+
// calls to Plotly.newPlot via plot_api.js or Registry.call('_doPlot')
77+
var plotCalls = plotApi._doPlot.calls.count() +
7878
Registry.call.calls.all()
79-
.filter(function(d) { return d.args[0] === 'plot'; })
79+
.filter(function(d) { return d.args[0] === '_doPlot'; })
8080
.length;
8181
expect(plotCalls).toBe(counts.plot || 0, 'Plotly.newPlot calls');
82-
plotApi.plot.calls.reset();
82+
plotApi._doPlot.calls.reset();
8383
Registry.call.calls.reset();
8484

8585
// only consider annotation and image draw calls if we *don't* do a full plot.

0 commit comments

Comments
 (0)