mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-18 22:48:10 +02:00
Optimize hover behavior
Add entity IDs to the element class list, so that specific elements can be selected by ID rather than needing `filter`.
This commit is contained in:
@@ -33,17 +33,16 @@ iD.behavior.Hover = function() {
|
||||
function mouseover() {
|
||||
var datum = d3.event.target.__data__;
|
||||
|
||||
if (datum) {
|
||||
var hovered = [datum.id];
|
||||
if (datum && datum.type) {
|
||||
var selector = '.' + datum.id;
|
||||
|
||||
if (datum.type === 'relation') {
|
||||
hovered = hovered.concat(_.pluck(datum.members, 'id'));
|
||||
datum.members.forEach(function(member) {
|
||||
selector += ', .' + member.id;
|
||||
});
|
||||
}
|
||||
|
||||
hovered = d3.set(hovered);
|
||||
|
||||
selection.selectAll('*')
|
||||
.filter(function(d) { return d && hovered.has(d.id); })
|
||||
selection.selectAll(selector)
|
||||
.classed('hover', true);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ iD.svg.Areas = function(projection) {
|
||||
|
||||
paths.enter()
|
||||
.append('path')
|
||||
.attr('class', function(d) { return d.type + ' area ' + klass; });
|
||||
.attr('class', function(d) { return d.type + ' area ' + klass + ' ' + d.id; });
|
||||
|
||||
paths
|
||||
.order()
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ iD.svg.Lines = function(projection) {
|
||||
|
||||
paths.enter()
|
||||
.append('path')
|
||||
.attr('class', 'way line ' + klass);
|
||||
.attr('class', function(d) { return 'way line ' + klass + ' ' + d.id; });
|
||||
|
||||
paths
|
||||
.order()
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ iD.svg.Points = function(projection, context) {
|
||||
|
||||
var group = groups.enter()
|
||||
.append('g')
|
||||
.attr('class', 'node point')
|
||||
.attr('class', function(d) { return 'node point ' + d.id; })
|
||||
.order();
|
||||
|
||||
group.append('path')
|
||||
|
||||
@@ -57,7 +57,7 @@ iD.svg.Vertices = function(projection, context) {
|
||||
function draw(groups, graph, zoom) {
|
||||
var group = groups.enter()
|
||||
.insert('g', ':first-child')
|
||||
.attr('class', 'node vertex');
|
||||
.attr('class', function(d) { return 'node vertex ' + d.id; });
|
||||
|
||||
if (zoom < 17) {
|
||||
zoom = 0;
|
||||
@@ -68,10 +68,10 @@ iD.svg.Vertices = function(projection, context) {
|
||||
}
|
||||
|
||||
group.append('circle')
|
||||
.attr('class', 'node vertex shadow');
|
||||
.attr('class', function(d) { return 'node vertex shadow ' + d.id; });
|
||||
|
||||
group.append('circle')
|
||||
.attr('class', 'node vertex stroke');
|
||||
.attr('class', function(d) { return 'node vertex stroke ' + d.id; });
|
||||
|
||||
groups.attr('transform', iD.svg.PointTransform(projection))
|
||||
.call(iD.svg.TagClasses())
|
||||
@@ -118,7 +118,7 @@ iD.svg.Vertices = function(projection, context) {
|
||||
}, iD.Entity.key);
|
||||
|
||||
fill.enter().append('circle')
|
||||
.attr('class', 'node vertex fill')
|
||||
.attr('class', function(d) { return 'node vertex fill ' + d.id; })
|
||||
.each(center)
|
||||
.attr('r', radiuses.fill[zoom]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user