Skip to content

Commit 09de224

Browse files
committed
lint
1 parent bf6793e commit 09de224

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

src/plot_api/plot_api.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,13 @@ var xmlnsNamespaces = require('../constants/xmlns_namespaces');
5050
Plotly.plot = function(gd, data, layout, config) {
5151
Lib.markTime('in plot');
5252

53-
5453
gd = getGraphDiv(gd);
5554

56-
/*
57-
* Events.init is idempotent and bails early if gd has already been init'd
58-
*/
55+
// Events.init is idempotent and bails early if gd has already been init'd
5956
Events.init(gd);
6057

6158
var okToPlot = Events.triggerHandler(gd, 'plotly_beforeplot', [data, layout, config]);
62-
if(okToPlot===false) return Promise.reject();
59+
if(okToPlot === false) return Promise.reject();
6360

6461
// if there's no data or layout, and this isn't yet a plotly plot
6562
// container, log a warning to help plotly.js users debug
@@ -89,22 +86,23 @@ Plotly.plot = function(gd, data, layout, config) {
8986
// complete, and empty out the promise list again.
9087
gd._promises = [];
9188

89+
var graphWasEmpty = ((gd.data || []).length === 0 && Array.isArray(data));
90+
9291
// if there is already data on the graph, append the new data
9392
// if you only want to redraw, pass a non-array for data
94-
var graphwasempty = ((gd.data||[]).length===0 && Array.isArray(data));
9593
if(Array.isArray(data)) {
9694
cleanData(data, gd.data);
9795

98-
if(graphwasempty) gd.data=data;
99-
else gd.data.push.apply(gd.data,data);
96+
if(graphWasEmpty) gd.data = data;
97+
else gd.data.push.apply(gd.data, data);
10098

10199
// for routines outside graph_obj that want a clean tab
102100
// (rather than appending to an existing one) gd.empty
103101
// is used to determine whether to make a new tab
104-
gd.empty=false;
102+
gd.empty = false;
105103
}
106104

107-
if(!gd.layout || graphwasempty) gd.layout = cleanLayout(layout);
105+
if(!gd.layout || graphWasEmpty) gd.layout = cleanLayout(layout);
108106

109107
// if the user is trying to drag the axes, allow new data and layout
110108
// to come in but don't allow a replot.
@@ -126,23 +124,24 @@ Plotly.plot = function(gd, data, layout, config) {
126124
// so we don't try to re-call Plotly.plot from inside
127125
// legend and colorbar, if margins changed
128126
gd._replotting = true;
129-
var hasData = gd._fullData.length>0;
127+
var hasData = gd._fullData.length > 0;
128+
129+
var subplots = Plotly.Axes.getSubplots(gd).join(''),
130+
oldSubplots = Object.keys(gd._fullLayout._plots || {}).join(''),
131+
hasSameSubplots = (oldSubplots === subplots);
130132

131133
// Make or remake the framework (ie container and axes) if we need to
132134
// note: if they container already exists and has data,
133135
// the new layout gets ignored (as it should)
134136
// but if there's no data there yet, it's just a placeholder...
135137
// then it should destroy and remake the plot
136-
if (hasData) {
137-
var subplots = Plotly.Axes.getSubplots(gd).join(''),
138-
oldSubplots = Object.keys(gd._fullLayout._plots || {}).join('');
139-
140-
if(gd.framework!==makePlotFramework || graphwasempty || (oldSubplots!==subplots)) {
138+
if(hasData) {
139+
if(gd.framework !== makePlotFramework || graphWasEmpty || !hasSameSubplots) {
141140
gd.framework = makePlotFramework;
142141
makePlotFramework(gd);
143142
}
144143
}
145-
else if(graphwasempty) makePlotFramework(gd);
144+
else if(graphWasEmpty) makePlotFramework(gd);
146145

147146
var fullLayout = gd._fullLayout;
148147

@@ -160,7 +159,7 @@ Plotly.plot = function(gd, data, layout, config) {
160159
}
161160

162161
// in case it has changed, attach fullData traces to calcdata
163-
for (var i = 0; i < gd.calcdata.length; i++) {
162+
for(var i = 0; i < gd.calcdata.length; i++) {
164163
gd.calcdata[i][0].trace = gd._fullData[i];
165164
}
166165

@@ -2133,8 +2132,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
21332132
undoit[ai] = (pleaf === 'reverse') ? vi : p.get();
21342133

21352134
// check autosize or autorange vs size and range
2136-
if(hw.indexOf(ai)!==-1) { doextra('autosize', false); }
2137-
else if(ai==='autosize') { doextra(hw, undefined); }
2135+
if(hw.indexOf(ai) !== -1) {
2136+
doextra('autosize', false);
2137+
}
2138+
else if(ai === 'autosize') {
2139+
doextra(hw, undefined);
2140+
}
21382141
else if(pleafPlus.match(/^[xyz]axis[0-9]*\.range(\[[0|1]\])?$/)) {
21392142
doextra(ptrunk+'.autorange', false);
21402143
}
@@ -2307,10 +2310,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
23072310
seq.push(function layoutReplot() {
23082311
// force plot() to redo the layout
23092312
gd.layout = undefined;
2313+
23102314
// force it to redo calcdata?
23112315
if(docalc) gd.calcdata = undefined;
2316+
23122317
// replot with the modified layout
2313-
return Plotly.plot(gd,'',layout);
2318+
return Plotly.plot(gd, '', layout);
23142319
});
23152320
}
23162321
else if(ak.length) {

0 commit comments

Comments
 (0)