Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 10dff2c

Browse files
committed
Merge pull request plotly#52 from plotly/plot-promises-fixups
Plot promises fixups
2 parents aa18721 + c2969da commit 10dff2c

File tree

2 files changed

+51
-29
lines changed

2 files changed

+51
-29
lines changed

src/plot_api/plot_api.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Plotly.plot = function(gd, data, layout, config) {
178178
return plots.previousPromises(gd);
179179
}
180180

181-
function marginPushersAgain(){
181+
function marginPushersAgain() {
182182
// in case the margins changed, draw margin pushers again
183183
var seq = JSON.stringify(fullLayout._size)===oldmargins ?
184184
[] : [marginPushers, layoutStyles];
@@ -335,7 +335,7 @@ Plotly.plot = function(gd, data, layout, config) {
335335
return plots.previousPromises(gd);
336336
}
337337

338-
function cleanUp(){
338+
function cleanUp() {
339339
// now we're REALLY TRULY done plotting...
340340
// so mark it as done and let other procedures call a replot
341341
gd._replotting = false;
@@ -484,7 +484,7 @@ function plotGeo(gd) {
484484
fullLayout[geoId]._geo = geo;
485485
}
486486

487-
geo.plot(fullGeoData, fullLayout);
487+
geo.plot(fullGeoData, fullLayout, gd._promises);
488488
}
489489
}
490490

@@ -570,7 +570,7 @@ function plotPolar(gd, data, layout) {
570570
if(txt === '' || !txt) opacity = 0;
571571
var placeholderText = 'Click to enter title';
572572

573-
var titleLayout = function(){
573+
var titleLayout = function() {
574574
this.call(Plotly.util.convertToTspans);
575575
//TODO: html/mathjax
576576
//TODO: center title
@@ -586,17 +586,17 @@ function plotPolar(gd, data, layout) {
586586
title.attr({'data-unformatted': placeholderText})
587587
.text(placeholderText)
588588
.style({opacity: opacity})
589-
.on('mouseover.opacity',function(){
589+
.on('mouseover.opacity',function() {
590590
d3.select(this).transition().duration(100)
591591
.style('opacity',1);
592592
})
593-
.on('mouseout.opacity',function(){
593+
.on('mouseout.opacity',function() {
594594
d3.select(this).transition().duration(1000)
595595
.style('opacity',0);
596596
});
597597
}
598598

599-
var setContenteditable = function(){
599+
var setContenteditable = function() {
600600
this.call(Plotly.util.makeEditable)
601601
.on('edit', function(text){
602602
gd.framework({layout: {title: text}});
@@ -605,7 +605,7 @@ function plotPolar(gd, data, layout) {
605605
.call(titleLayout);
606606
this.call(setContenteditable);
607607
})
608-
.on('cancel', function(){
608+
.on('cancel', function() {
609609
var txt = this.attr('data-unformatted');
610610
this.text(txt).call(titleLayout);
611611
});
@@ -940,7 +940,7 @@ Plotly.redraw = function(gd) {
940940
Plotly.newPlot = function (gd, data, layout, config) {
941941
gd = getGraphDiv(gd);
942942
plots.purge(gd);
943-
Plotly.plot(gd, data, layout, config);
943+
return Plotly.plot(gd, data, layout, config);
944944
};
945945

946946
function doCalcdata(gd) {
@@ -1747,7 +1747,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
17471747
}
17481748

17491749
// make a new empty vals array for undoit
1750-
function a0(){ return traces.map(function(){ return undefined; }); }
1750+
function a0() { return traces.map(function() { return undefined; }); }
17511751

17521752
// for autoranging multiple axes
17531753
function addToAxlist(axid) {
@@ -1764,11 +1764,11 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
17641764
// attr can be an array to set several at once (all to the same val)
17651765
function doextra(attr,val,i) {
17661766
if(Array.isArray(attr)) {
1767-
attr.forEach(function(a){ doextra(a,val,i); });
1767+
attr.forEach(function(a) { doextra(a,val,i); });
17681768
return;
17691769
}
17701770
// quit if explicitly setting this elsewhere
1771-
if(attr in aobj) { return; }
1771+
if(attr in aobj) return;
17721772

17731773
var extraparam;
17741774
if(attr.substr(0, 6) === 'LAYOUT') {
@@ -2055,7 +2055,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
20552055
// a complete layout redraw takes care of plot and
20562056
var seq;
20572057
if(dolayout) {
2058-
seq = [function changeLayout(){
2058+
seq = [function changeLayout() {
20592059
var copyLayout = gd.layout;
20602060
gd.layout = undefined;
20612061
return Plotly.plot(gd, '', copyLayout);
@@ -2068,7 +2068,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
20682068
plots.supplyDefaults(gd);
20692069
seq = [plots.previousPromises];
20702070
if(dostyle) {
2071-
seq.push(function doStyle(){
2071+
seq.push(function doStyle() {
20722072
// first see if we need to do arraysToCalcdata
20732073
// call it regardless of what change we made, in case
20742074
// supplyDefaults brought in an array that was already
@@ -2085,7 +2085,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
20852085
});
20862086
}
20872087
if(docolorbars) {
2088-
seq.push(function doColorBars(){
2088+
seq.push(function doColorBars() {
20892089
gd.calcdata.forEach(function(cd) {
20902090
if((cd[0].t || {}).cb) {
20912091
var trace = cd[0].trace,
@@ -2114,7 +2114,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
21142114

21152115
if(!plotDone || !plotDone.then) plotDone = Promise.resolve();
21162116

2117-
return plotDone.then(function(){
2117+
return plotDone.then(function() {
21182118
gd.emit('plotly_restyle',
21192119
Plotly.Lib.extendDeep([], [redoit, traces]));
21202120
});
@@ -2432,7 +2432,7 @@ Plotly.relayout = function relayout(gd, astr, val) {
24322432
seq = [plots.previousPromises];
24332433

24342434
if(doplot || docalc) {
2435-
seq.push(function layoutReplot(){
2435+
seq.push(function layoutReplot() {
24362436
// force plot() to redo the layout
24372437
gd.layout = undefined;
24382438
// force it to redo calcdata?
@@ -2447,7 +2447,7 @@ Plotly.relayout = function relayout(gd, astr, val) {
24472447
fullLayout = gd._fullLayout;
24482448

24492449
if(dolegend) {
2450-
seq.push(function doLegend(){
2450+
seq.push(function doLegend() {
24512451
Plotly.Legend.draw(gd);
24522452
return plots.previousPromises(gd);
24532453
});
@@ -2456,7 +2456,7 @@ Plotly.relayout = function relayout(gd, astr, val) {
24562456
if(dolayoutstyle) seq.push(layoutStyles);
24572457

24582458
if(doticks) {
2459-
seq.push(function(){
2459+
seq.push(function() {
24602460
Plotly.Axes.doTicks(gd,'redraw');
24612461
Plotly.Titles.draw(gd, 'gtitle');
24622462
return plots.previousPromises(gd);
@@ -2486,7 +2486,7 @@ Plotly.relayout = function relayout(gd, astr, val) {
24862486

24872487
if(!plotDone || !plotDone.then) plotDone = Promise.resolve();
24882488

2489-
return plotDone.then(function(){
2489+
return plotDone.then(function() {
24902490
gd.emit('plotly_relayout',
24912491
Plotly.Lib.extendDeep({}, redoit));
24922492
});
@@ -2671,7 +2671,7 @@ function makePlotFramework(gd) {
26712671
// position and style the containers, make main title
26722672
var frameWorkDone = Plotly.Lib.syncOrAsync([
26732673
layoutStyles,
2674-
function goAxes(){ return Plotly.Axes.doTicks(gd,'redraw'); },
2674+
function goAxes() { return Plotly.Axes.doTicks(gd,'redraw'); },
26752675
Plotly.Fx.init
26762676
], gd);
26772677

src/plots/geo/geo.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = Geo;
6060

6161
var proto = Geo.prototype;
6262

63-
proto.plot = function(geoData, fullLayout) {
63+
proto.plot = function(geoData, fullLayout, promises) {
6464
var _this = this,
6565
geoLayout = fullLayout[_this.id],
6666
graphSize = fullLayout._size;
@@ -100,17 +100,39 @@ proto.plot = function(geoData, fullLayout) {
100100
_this.topojsonName
101101
);
102102

103-
// N.B this is async
104-
d3.json(topojsonPath, function(error, topojson) {
105-
_this.topojson = topojson;
106-
PlotlyGeoAssets.topojson[_this.topojsonName] = topojson;
107-
_this.onceTopojsonIsLoaded(geoData, geoLayout);
108-
});
103+
promises.push(new Promise(function(resolve, reject) {
104+
d3.json(topojsonPath, function(error, topojson) {
105+
if(error) {
106+
if(error.status === 404) {
107+
reject(new Error([
108+
'plotly.js could not find topojson file at',
109+
topojsonPath, '.',
110+
'Make sure the *topojsonURL* plot config option',
111+
'is set properly.'
112+
].join(' ')));
113+
}
114+
else {
115+
reject(new Error([
116+
'unexpected error while fetching topojson file at',
117+
topojsonPath
118+
].join(' ')));
119+
}
120+
return;
121+
}
122+
123+
_this.topojson = topojson;
124+
PlotlyGeoAssets.topojson[_this.topojsonName] = topojson;
125+
126+
_this.onceTopojsonIsLoaded(geoData, geoLayout);
127+
resolve();
128+
});
129+
}));
109130
}
110131
}
111132
else _this.onceTopojsonIsLoaded(geoData, geoLayout);
112133

113-
// TODO handle topojson-is-loading case (for streaming)
134+
// TODO handle topojson-is-loading case
135+
// to avoid making multiple request while streaming
114136
};
115137

116138
proto.onceTopojsonIsLoaded = function(geoData, geoLayout) {

0 commit comments

Comments
 (0)