Skip to content

Commit d0ea7c9

Browse files
committed
adapt scattergeo to new geo layers and projection logic
- note that we now bind a calcdata item with a ref to geojson to the scattergeo line nodes, instead of stitching calcdata things onto geojson feature.
1 parent 9faa1b1 commit d0ea7c9

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

src/traces/scattergeo/hover.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,24 @@ var getTraceColor = require('../scatter/get_trace_color');
1717
var attributes = require('./attributes');
1818

1919

20-
module.exports = function hoverPoints(pointData) {
20+
module.exports = function hoverPoints(pointData, xval, yval) {
2121
var cd = pointData.cd,
2222
trace = cd[0].trace,
2323
xa = pointData.xa,
2424
ya = pointData.ya,
25-
geo = pointData.subplot;
26-
27-
function c2p(lonlat) {
28-
return geo.projection(lonlat);
29-
}
25+
geo = pointData.subplot,
26+
projection = geo.projection;
3027

3128
function distFn(d) {
3229
var lonlat = d.lonlat;
3330

3431
if(lonlat[0] === BADNUM) return Infinity;
32+
if(projection.isLonLatOverEdges(lonlat)) return Infinity;
3533

36-
if(geo.isLonLatOverEdges(lonlat)) return Infinity;
37-
38-
var pos = c2p(lonlat);
39-
40-
var xPx = xa.c2p(),
41-
yPx = ya.c2p();
34+
var dx = Math.abs(xa.c2p(lonlat) - xa.c2p([xval, lonlat[1]]));
35+
var dy = Math.abs(ya.c2p(lonlat) - ya.c2p([lonlat[0], yval]));
4236

43-
var dx = Math.abs(xPx - pos[0]),
44-
dy = Math.abs(yPx - pos[1]),
45-
rad = Math.max(3, d.mrc || 0);
37+
var rad = Math.max(3, d.mrc || 0);
4638

4739
// N.B. d.mrc is the calculated marker radius
4840
// which is only set for trace with 'markers' mode.
@@ -57,7 +49,7 @@ module.exports = function hoverPoints(pointData) {
5749

5850
var di = cd[pointData.index],
5951
lonlat = di.lonlat,
60-
pos = c2p(lonlat),
52+
pos = [xa.c2p(lonlat), ya.c2p(lonlat)],
6153
rad = di.mrc || 1;
6254

6355
pointData.x0 = pos[0] - rad;

src/traces/scattergeo/plot.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ var subTypes = require('../scatter/subtypes');
2323

2424

2525
module.exports = function plot(geo, calcData) {
26+
for(var i = 0; i < calcData.length; i++) {
27+
calcGeoJSON(calcData[i], geo.topojson);
28+
}
2629

2730
function keyFunc(d) { return d[0].trace.uid; }
2831

@@ -32,11 +35,7 @@ module.exports = function plot(geo, calcData) {
3235
}
3336
}
3437

35-
for(var i = 0; i < calcData.length; i++) {
36-
fillLocationLonLat(calcData[i], geo.topojson);
37-
}
38-
39-
var gScatterGeoTraces = geo.framework.select('.scattergeolayer')
38+
var gScatterGeoTraces = geo.layers.frontplot.select('.scatterlayer')
4039
.selectAll('g.trace.scattergeo')
4140
.data(calcData, keyFunc);
4241

@@ -49,20 +48,20 @@ module.exports = function plot(geo, calcData) {
4948
gScatterGeoTraces.selectAll('*').remove();
5049

5150
gScatterGeoTraces.each(function(calcTrace) {
52-
var s = d3.select(this);
51+
var s = calcTrace[0].node3 = d3.select(this);
5352
var trace = calcTrace[0].trace;
5453

5554
if(subTypes.hasLines(trace) || trace.fill !== 'none') {
5655
var lineCoords = geoJsonUtils.calcTraceToLineCoords(calcTrace);
5756

5857
var lineData = (trace.fill !== 'none') ?
59-
geoJsonUtils.makePolygon(lineCoords, trace) :
60-
geoJsonUtils.makeLine(lineCoords, trace);
58+
geoJsonUtils.makePolygon(lineCoords) :
59+
geoJsonUtils.makeLine(lineCoords);
6160

6261
s.selectAll('path.js-line')
63-
.data([lineData])
62+
.data([{geojson: lineData, trace: trace}])
6463
.enter().append('path')
65-
.classed('js-line', true);
64+
.classed('js-line', true)
6665
}
6766

6867
if(subTypes.hasMarkers(trace)) {
@@ -86,7 +85,7 @@ module.exports = function plot(geo, calcData) {
8685
style(geo);
8786
};
8887

89-
function fillLocationLonLat(calcTrace, topojson) {
88+
function calcGeoJSON(calcTrace, topojson) {
9089
var trace = calcTrace[0].trace;
9190

9291
if(!Array.isArray(trace.locations)) return;

0 commit comments

Comments
 (0)