Skip to content

Commit efc1199

Browse files
committed
redraw scattergeo with angles on interactions
1 parent 5942253 commit efc1199

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

src/plots/geo/geo.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ module.exports = function createGeo(opts) {
6767
return new Geo(opts);
6868
};
6969

70-
proto.plot = function(geoCalcData, fullLayout, promises) {
70+
proto.plot = function(geoCalcData, fullLayout, promises, replot) {
7171
var _this = this;
72+
if(replot) return _this.update(geoCalcData, fullLayout, true);
73+
74+
_this._geoCalcData = geoCalcData;
75+
_this._fullLayout = fullLayout;
76+
7277
var geoLayout = fullLayout[this.id];
7378
var geoPromises = [];
7479

@@ -79,15 +84,24 @@ proto.plot = function(geoCalcData, fullLayout, promises) {
7984
break;
8085
}
8186
}
87+
88+
var hasMarkerAngles = false;
8289
for(var i = 0; i < geoCalcData.length; i++) {
8390
var trace = geoCalcData[0][0].trace;
8491
trace._geo = _this;
8592

8693
if(trace.locationmode) {
8794
needsTopojson = true;
88-
break;
95+
}
96+
97+
var marker = trace.marker;
98+
if(marker) {
99+
var angle = marker.angle;
100+
var angleref = marker.angleref;
101+
if(angle || angleref === 'north' || angleref === 'previous') hasMarkerAngles = true;
89102
}
90103
}
104+
this._hasMarkerAngles = hasMarkerAngles;
91105

92106
if(needsTopojson) {
93107
var topojsonNameNew = topojsonUtils.getTopojsonName(geoLayout);
@@ -140,7 +154,7 @@ proto.fetchTopojson = function() {
140154
});
141155
};
142156

143-
proto.update = function(geoCalcData, fullLayout) {
157+
proto.update = function(geoCalcData, fullLayout, replot) {
144158
var geoLayout = fullLayout[this.id];
145159

146160
// important: maps with choropleth traces have a different layer order
@@ -158,11 +172,13 @@ proto.update = function(geoCalcData, fullLayout) {
158172
}
159173
}
160174

161-
var hasInvalidBounds = this.updateProjection(geoCalcData, fullLayout);
162-
if(hasInvalidBounds) return;
175+
if(!replot) {
176+
var hasInvalidBounds = this.updateProjection(geoCalcData, fullLayout);
177+
if(hasInvalidBounds) return;
163178

164-
if(!this.viewInitial || this.scope !== geoLayout.scope) {
165-
this.saveViewInitial(geoLayout);
179+
if(!this.viewInitial || this.scope !== geoLayout.scope) {
180+
this.saveViewInitial(geoLayout);
181+
}
166182
}
167183
this.scope = geoLayout.scope;
168184

@@ -180,7 +196,7 @@ proto.update = function(geoCalcData, fullLayout) {
180196
var choroplethLayer = this.layers.backplot.select('.choroplethlayer');
181197
this.dataPaths.choropleth = choroplethLayer.selectAll('path');
182198

183-
this.render();
199+
this._render();
184200
};
185201

186202
proto.updateProjection = function(geoCalcData, fullLayout) {
@@ -594,8 +610,16 @@ proto.saveViewInitial = function(geoLayout) {
594610
Lib.extendFlat(this.viewInitial, extra);
595611
};
596612

613+
proto.render = function(mayRedrawOnUpdates) {
614+
if(this._hasMarkerAngles && mayRedrawOnUpdates) {
615+
this.plot(this._geoCalcData, this._fullLayout, [], true);
616+
} else {
617+
this._render();
618+
}
619+
};
620+
597621
// [hot code path] (re)draw all paths which depend on the projection
598-
proto.render = function() {
622+
proto._render = function() {
599623
var projection = this.projection;
600624
var pathFn = projection.getPath();
601625
var k;
@@ -622,7 +646,7 @@ proto.render = function() {
622646
for(k in this.dataPoints) {
623647
this.dataPoints[k]
624648
.attr('display', hideShowPoints)
625-
.attr('transform', translatePoints);
649+
.attr('transform', translatePoints); // TODO: need to redraw points with marker angle instead of calling translatePoints
626650
}
627651
};
628652

src/plots/geo/zoom.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function zoomScoped(geo, projection) {
7777
projection
7878
.scale(d3.event.scale)
7979
.translate(d3.event.translate);
80-
geo.render();
80+
geo.render(true);
8181

8282
var center = projection.invert(geo.midPt);
8383
geo.graphDiv.emit('plotly_relayouting', {
@@ -162,7 +162,7 @@ function zoomNonClipped(geo, projection) {
162162
}
163163

164164
didZoom = true;
165-
geo.render();
165+
geo.render(true);
166166

167167
var rotate = projection.rotate();
168168
var center = projection.invert(geo.midPt);
@@ -268,7 +268,7 @@ function zoomClipped(geo, projection) {
268268
sync(geo, projection, syncCb);
269269
})
270270
.on('zoom.redraw', function() {
271-
geo.render();
271+
geo.render(true);
272272

273273
var _rotate = projection.rotate();
274274
geo.graphDiv.emit('plotly_relayouting', {

0 commit comments

Comments
 (0)