-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Better geo streaming #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better geo streaming #324
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,99 +125,101 @@ plotScatterGeo.plot = function(geo, scattergeoData) { | |
|
||
gScatterGeoTraces.exit().remove(); | ||
|
||
// TODO add hover - how? | ||
gScatterGeoTraces | ||
.each(function(trace) { | ||
if(!subTypes.hasLines(trace)) return; | ||
// TODO find a way to order the inner nodes on update | ||
gScatterGeoTraces.selectAll('*').remove(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a few ideas that would allow us to remove this dirty purge call. See: for some examples. But I want to benchmark these patterns before implementing them in the code. So I opted for the easy route in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will we have a performance hit removing these on each call to Edit: Didn't refresh for too long... |
||
|
||
d3.select(this) | ||
.append('path') | ||
.datum(makeLineGeoJSON(trace)) | ||
.attr('class', 'js-line'); | ||
}); | ||
gScatterGeoTraces.each(function(trace) { | ||
var s = d3.select(this); | ||
|
||
gScatterGeoTraces.append('g') | ||
.attr('class', 'points') | ||
.each(function(trace) { | ||
var s = d3.select(this), | ||
showMarkers = subTypes.hasMarkers(trace), | ||
showText = subTypes.hasText(trace); | ||
|
||
if((!showMarkers && !showText)) return; | ||
|
||
var cdi = plotScatterGeo.calcGeoJSON(trace, geo.topojson), | ||
cleanHoverLabelsFunc = makeCleanHoverLabelsFunc(geo, trace), | ||
eventDataFunc = makeEventDataFunc(trace); | ||
|
||
var hoverinfo = trace.hoverinfo, | ||
hasNameLabel = ( | ||
hoverinfo === 'all' || | ||
hoverinfo.indexOf('name') !== -1 | ||
); | ||
|
||
function handleMouseOver(pt, ptIndex) { | ||
if(!geo.showHover) return; | ||
|
||
var xy = geo.projection([pt.lon, pt.lat]); | ||
cleanHoverLabelsFunc(pt); | ||
|
||
Fx.loneHover({ | ||
x: xy[0], | ||
y: xy[1], | ||
name: hasNameLabel ? trace.name : undefined, | ||
text: pt.textLabel, | ||
color: pt.mc || (trace.marker || {}).color | ||
}, { | ||
container: geo.hoverContainer.node() | ||
}); | ||
|
||
geo.graphDiv.emit('plotly_hover', eventDataFunc(pt, ptIndex)); | ||
} | ||
|
||
function handleClick(pt, ptIndex) { | ||
geo.graphDiv.emit('plotly_click', eventDataFunc(pt, ptIndex)); | ||
} | ||
|
||
if(showMarkers) { | ||
s.selectAll('path.point') | ||
.data(cdi) | ||
.enter().append('path') | ||
.attr('class', 'point') | ||
.on('mouseover', handleMouseOver) | ||
.on('click', handleClick) | ||
.on('mouseout', function() { | ||
Fx.loneUnhover(geo.hoverContainer); | ||
}) | ||
.on('mousedown', function() { | ||
// to simulate the 'zoomon' event | ||
Fx.loneUnhover(geo.hoverContainer); | ||
}) | ||
.on('mouseup', handleMouseOver); // ~ 'zoomend' | ||
} | ||
|
||
if(showText) { | ||
s.selectAll('g') | ||
.data(cdi) | ||
.enter().append('g') | ||
.append('text'); | ||
} | ||
}); | ||
if(!subTypes.hasLines(trace)) return; | ||
|
||
s.selectAll('path.js-line') | ||
.data([makeLineGeoJSON(trace)]) | ||
.enter().append('path') | ||
.classed('js-line', true); | ||
|
||
// TODO add hover - how? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this not handled on line 188? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 188 handles hover for markers, not lines unfortunately. That will come when someone has the guts to refactor |
||
}); | ||
|
||
gScatterGeoTraces.each(function(trace) { | ||
var s = d3.select(this), | ||
showMarkers = subTypes.hasMarkers(trace), | ||
showText = subTypes.hasText(trace); | ||
|
||
if(!showMarkers && !showText) return; | ||
|
||
var cdi = plotScatterGeo.calcGeoJSON(trace, geo.topojson), | ||
cleanHoverLabelsFunc = makeCleanHoverLabelsFunc(geo, trace), | ||
eventDataFunc = makeEventDataFunc(trace); | ||
|
||
var hoverinfo = trace.hoverinfo, | ||
hasNameLabel = ( | ||
hoverinfo === 'all' || | ||
hoverinfo.indexOf('name') !== -1 | ||
); | ||
|
||
function handleMouseOver(pt, ptIndex) { | ||
if(!geo.showHover) return; | ||
|
||
var xy = geo.projection([pt.lon, pt.lat]); | ||
cleanHoverLabelsFunc(pt); | ||
|
||
Fx.loneHover({ | ||
x: xy[0], | ||
y: xy[1], | ||
name: hasNameLabel ? trace.name : undefined, | ||
text: pt.textLabel, | ||
color: pt.mc || (trace.marker || {}).color | ||
}, { | ||
container: geo.hoverContainer.node() | ||
}); | ||
|
||
geo.graphDiv.emit('plotly_hover', eventDataFunc(pt, ptIndex)); | ||
} | ||
|
||
function handleClick(pt, ptIndex) { | ||
geo.graphDiv.emit('plotly_click', eventDataFunc(pt, ptIndex)); | ||
} | ||
|
||
if(showMarkers) { | ||
s.selectAll('path.point').data(cdi) | ||
.enter().append('path') | ||
.classed('point', true) | ||
.on('mouseover', handleMouseOver) | ||
.on('click', handleClick) | ||
.on('mouseout', function() { | ||
Fx.loneUnhover(geo.hoverContainer); | ||
}) | ||
.on('mousedown', function() { | ||
// to simulate the 'zoomon' event | ||
Fx.loneUnhover(geo.hoverContainer); | ||
}) | ||
.on('mouseup', handleMouseOver); // ~ 'zoomend' | ||
} | ||
|
||
if(showText) { | ||
s.selectAll('g').data(cdi) | ||
.enter().append('g') | ||
.append('text'); | ||
} | ||
}); | ||
|
||
plotScatterGeo.style(geo); | ||
}; | ||
|
||
plotScatterGeo.style = function(geo) { | ||
var selection = geo.framework.selectAll('g.trace.scattergeo'); | ||
|
||
selection.style('opacity', function(trace) { return trace.opacity; }); | ||
selection.style('opacity', function(trace) { | ||
return trace.opacity; | ||
}); | ||
|
||
selection.selectAll('g.points') | ||
.each(function(trace) { | ||
d3.select(this).selectAll('path.point') | ||
.call(Drawing.pointStyle, trace); | ||
d3.select(this).selectAll('text') | ||
.call(Drawing.textPointStyle, trace); | ||
}); | ||
selection.each(function(trace) { | ||
d3.select(this).selectAll('path.point') | ||
.call(Drawing.pointStyle, trace); | ||
d3.select(this).selectAll('text') | ||
.call(Drawing.textPointStyle, trace); | ||
}); | ||
|
||
// GeoJSON calc data is incompatible with Drawing.lineGroupStyle | ||
selection.selectAll('path.js-line') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously, existing choropleth nodes were not removed.