Hide labels on mouseover

This commit is contained in:
Ansis Brammanis
2013-01-31 15:40:17 -05:00
parent 26dfaf8161
commit 8dcb215fe3
2 changed files with 27 additions and 0 deletions

View File

@@ -616,6 +616,14 @@ text.pointlabel {
pointer-events: none;
}
.layer-halo rect,
.layer-halo path,
.layer-label text {
-webkit-transition: opacity 100ms linear;
transition: opacity 100ms linear;
-moz-transition: opacity 100ms linear;
}
.pathlabel .textpath {
dominant-baseline: middle;
}

View File

@@ -200,12 +200,31 @@ iD.svg.Labels = function(projection) {
}
function hideOnMouseover() {
var mouse = d3.mouse(this),
pad = 50,
rect = new RTree.Rectangle(mouse[0] - pad, mouse[1] - pad, 2*pad, 2*pad),
labels = _.pluck(rtree.search(rect, this), 'leaf'),
selection = d3.select(this);
selection.selectAll('.layer-label text, .layer-halo path, .layer-halo rect')
.style('opacity', '');
if (!labels.length) return;
selection.selectAll('.layer-label text, .layer-halo path, .layer-halo rect')
.filter(function(d) {
return _.contains(labels, d.id);
})
.style('opacity', 0);
}
var rtree = new RTree(),
rectangles = {};
return function drawLabels(surface, graph, entities, filter, dimensions, fullRedraw) {
d3.select(surface.node().parentNode)
.on('mousemove.hidelabels', hideOnMouseover);
var hidePoints = !d3.select('.node.point').node();