Skip to content

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

Merged
merged 3 commits into from
Mar 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 44 additions & 43 deletions src/traces/choropleth/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,50 +75,51 @@ plotChoropleth.plot = function(geo, choroplethData, geoLayout) {

gChoroplethTraces.exit().remove();

gChoroplethTraces
.each(function(trace) {
var cdi = plotChoropleth.calcGeoJSON(trace, geo.topojson),
cleanHoverLabelsFunc = makeCleanHoverLabelsFunc(geo, trace),
eventDataFunc = makeEventDataFunc(trace);

function handleMouseOver(pt, ptIndex) {
if(!geo.showHover) return;

var xy = geo.projection(pt.properties.ct);
cleanHoverLabelsFunc(pt);

Fx.loneHover({
x: xy[0],
y: xy[1],
name: pt.nameLabel,
text: pt.textLabel
}, {
container: geo.hoverContainer.node()
});
gChoroplethTraces.each(function(trace) {
var cdi = plotChoropleth.calcGeoJSON(trace, geo.topojson),
cleanHoverLabelsFunc = makeCleanHoverLabelsFunc(geo, trace),
eventDataFunc = makeEventDataFunc(trace);

function handleMouseOver(pt, ptIndex) {
if(!geo.showHover) return;

var xy = geo.projection(pt.properties.ct);
cleanHoverLabelsFunc(pt);

Fx.loneHover({
x: xy[0],
y: xy[1],
name: pt.nameLabel,
text: pt.textLabel
}, {
container: geo.hoverContainer.node()
});

geo.graphDiv.emit('plotly_hover', eventDataFunc(pt, ptIndex));
}

geo.graphDiv.emit('plotly_hover', eventDataFunc(pt, ptIndex));
}

function handleClick(pt, ptIndex) {
geo.graphDiv.emit('plotly_click', eventDataFunc(pt, ptIndex));
}

d3.select(this)
.selectAll('path.choroplethlocation')
.data(cdi)
.enter().append('path')
.attr('class', 'choroplethlocation')
.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'
});
function handleClick(pt, ptIndex) {
geo.graphDiv.emit('plotly_click', eventDataFunc(pt, ptIndex));
}

var paths = d3.select(this).selectAll('path.choroplethlocation')
.data(cdi);

paths.enter().append('path')
.classed('choroplethlocation', 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'

paths.exit().remove();
Copy link
Contributor Author

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.

});

// some baselayers are drawn over choropleth
gBaseLayerOverChoropleth.selectAll('*').remove();
Expand Down
168 changes: 85 additions & 83 deletions src/traces/scattergeo/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we have a performance hit removing these on each call to plot?

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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not handled on line 188?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 graph_interact.js so that it can be used with arbitrary pixel-to-coordinate transforms.

});

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')
Expand Down
Loading