mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Abandon iD.svg.MemberClasses
Substantial performance hit for something that's barely used.
This commit is contained in:
+3
-15
@@ -156,18 +156,11 @@ path.shadow.selected {
|
||||
stroke-opacity: 0.7;
|
||||
}
|
||||
|
||||
path.area.stroke,
|
||||
path.line.member-type-multipolygon.stroke {
|
||||
stroke-width:2;
|
||||
}
|
||||
path.area.stroke.selected,
|
||||
path.line.member-type-multipolygon.stroke.selected {
|
||||
stroke-width:4 !important;
|
||||
path.area.stroke {
|
||||
stroke: white;
|
||||
stroke-width: 1;
|
||||
}
|
||||
|
||||
path.area.stroke {
|
||||
stroke:#fff;
|
||||
}
|
||||
path.area.fill {
|
||||
fill:#fff;
|
||||
fill-opacity:0.3;
|
||||
@@ -181,7 +174,6 @@ path.line.stroke {
|
||||
|
||||
path.stroke.tag-natural {
|
||||
stroke: #b6e199;
|
||||
stroke-width:1;
|
||||
}
|
||||
path.fill.tag-natural {
|
||||
fill: #b6e199;
|
||||
@@ -196,7 +188,6 @@ path.fill.tag-natural-water {
|
||||
|
||||
path.stroke.tag-amenity-school {
|
||||
stroke: #ffff94;
|
||||
stroke-width: 1;
|
||||
}
|
||||
path.fill.tag-amenity-school {
|
||||
fill: #ffff94;
|
||||
@@ -213,7 +204,6 @@ path.fill.tag-amenity-university {
|
||||
|
||||
path.stroke.tag-building {
|
||||
stroke: #e06e5f;
|
||||
stroke-width: 1;
|
||||
}
|
||||
path.fill.tag-building {
|
||||
fill: #e06e5f;
|
||||
@@ -229,7 +219,6 @@ path.stroke.tag-natural-grassland,
|
||||
path.stroke.tag-leisure-pitch,
|
||||
path.stroke.tag-leisure-park {
|
||||
stroke: #8cd05f;
|
||||
stroke-width: 1;
|
||||
}
|
||||
|
||||
path.stroke.tag-landuse-residential {
|
||||
@@ -398,7 +387,6 @@ path.fill.tag-landuse-industrial {
|
||||
|
||||
path.stroke.tag-amenity-parking {
|
||||
stroke: #aaa;
|
||||
stroke-width: 1;
|
||||
}
|
||||
path.fill.tag-amenity-parking {
|
||||
fill: #aaa;
|
||||
|
||||
@@ -51,7 +51,6 @@
|
||||
<script src="js/id/svg.js"></script>
|
||||
<script src="js/id/svg/areas.js"></script>
|
||||
<script src="js/id/svg/lines.js"></script>
|
||||
<script src="js/id/svg/member_classes.js"></script>
|
||||
<script src="js/id/svg/midpoints.js"></script>
|
||||
<script src="js/id/svg/points.js"></script>
|
||||
<script src="js/id/svg/surface.js"></script>
|
||||
|
||||
+1
-2
@@ -78,8 +78,7 @@ iD.svg.Areas = function(projection) {
|
||||
|
||||
paths
|
||||
.order()
|
||||
.attr('d', function(entity) { return path(entity.asGeoJSON(graph, closeWay)); })
|
||||
.call(iD.svg.MemberClasses(graph));
|
||||
.attr('d', function(entity) { return path(entity.asGeoJSON(graph, closeWay)); });
|
||||
|
||||
if (klass === 'fill') paths.call(setPattern);
|
||||
|
||||
|
||||
+1
-2
@@ -70,8 +70,7 @@ iD.svg.Lines = function(projection) {
|
||||
|
||||
paths
|
||||
.order()
|
||||
.attr('d', path)
|
||||
.call(iD.svg.MemberClasses(graph));
|
||||
.attr('d', path);
|
||||
|
||||
paths.exit()
|
||||
.remove();
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
iD.svg.MemberClasses = function(graph) {
|
||||
var tagClassRe = /^member-?/;
|
||||
|
||||
return function memberClassesSelection(selection) {
|
||||
selection.each(function memberClassesEach(d) {
|
||||
var classes, value = this.className;
|
||||
|
||||
if (value.baseVal !== undefined) value = value.baseVal;
|
||||
|
||||
classes = value.trim().split(/\s+/).filter(function(name) {
|
||||
return name.length && !tagClassRe.test(name);
|
||||
}).join(' ');
|
||||
|
||||
var relations = graph.parentRelations(d);
|
||||
|
||||
if (relations.length) {
|
||||
classes += ' member';
|
||||
}
|
||||
|
||||
relations.forEach(function(relation) {
|
||||
classes += ' member-type-' + relation.tags.type;
|
||||
classes += ' member-role-' + relation.memberById(d.id).role;
|
||||
});
|
||||
|
||||
classes = classes.trim();
|
||||
|
||||
if (classes !== value) {
|
||||
d3.select(this).attr('class', classes);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
+1
-2
@@ -47,8 +47,7 @@ iD.svg.Points = function(projection, context) {
|
||||
.attr('clip-path', 'url(#clip-square-12)');
|
||||
|
||||
groups.attr('transform', iD.svg.PointTransform(projection))
|
||||
.call(iD.svg.TagClasses())
|
||||
.call(iD.svg.MemberClasses(graph));
|
||||
.call(iD.svg.TagClasses());
|
||||
|
||||
// Selecting the following implicitly
|
||||
// sets the data (point entity) on the element
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
<script src="../js/id/svg.js"></script>
|
||||
<script src="../js/id/svg/areas.js"></script>
|
||||
<script src="../js/id/svg/lines.js"></script>
|
||||
<script src="../js/id/svg/member_classes.js"></script>
|
||||
<script src="../js/id/svg/midpoints.js"></script>
|
||||
<script src="../js/id/svg/points.js"></script>
|
||||
<script src="../js/id/svg/surface.js"></script>
|
||||
@@ -221,7 +220,6 @@
|
||||
<script src="spec/svg.js"></script>
|
||||
<script src="spec/svg/areas.js"></script>
|
||||
<script src="spec/svg/lines.js"></script>
|
||||
<script src="spec/svg/member_classes.js"></script>
|
||||
<script src="spec/svg/midpoints.js"></script>
|
||||
<script src="spec/svg/points.js"></script>
|
||||
<script src="spec/svg/vertices.js"></script>
|
||||
|
||||
@@ -63,7 +63,6 @@
|
||||
<script src="spec/svg.js"></script>
|
||||
<script src="spec/svg/areas.js"></script>
|
||||
<script src="spec/svg/lines.js"></script>
|
||||
<script src="spec/svg/member_classes.js"></script>
|
||||
<script src="spec/svg/midpoints.js"></script>
|
||||
<script src="spec/svg/points.js"></script>
|
||||
<script src="spec/svg/vertices.js"></script>
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
<script src="../js/id/svg.js"></script>
|
||||
<script src="../js/id/svg/areas.js"></script>
|
||||
<script src="../js/id/svg/lines.js"></script>
|
||||
<script src="../js/id/svg/member_classes.js"></script>
|
||||
<script src="../js/id/svg/midpoints.js"></script>
|
||||
<script src="../js/id/svg/points.js"></script>
|
||||
<script src="../js/id/svg/surface.js"></script>
|
||||
|
||||
@@ -28,18 +28,6 @@ describe("iD.svg.Areas", function () {
|
||||
expect(surface.select('.area')).to.be.classed('tag-building-yes');
|
||||
});
|
||||
|
||||
it("adds member classes", function () {
|
||||
var area = iD.Way({tags: {area: 'yes'}}),
|
||||
relation = iD.Relation({members: [{id: area.id, role: 'inner'}], tags: {type: 'multipolygon'}}),
|
||||
graph = iD.Graph([area, relation]);
|
||||
|
||||
surface.call(iD.svg.Areas(projection), graph, [area], filter);
|
||||
|
||||
expect(surface.select('.area')).to.be.classed('member');
|
||||
expect(surface.select('.area')).to.be.classed('member-role-inner');
|
||||
expect(surface.select('.area')).to.be.classed('member-type-multipolygon');
|
||||
});
|
||||
|
||||
it("preserves non-area paths", function () {
|
||||
var area = iD.Way({tags: {area: 'yes'}}),
|
||||
graph = iD.Graph([area]);
|
||||
|
||||
@@ -33,19 +33,6 @@ describe("iD.svg.Lines", function () {
|
||||
expect(surface.select('.line')).to.be.classed('tag-highway-residential');
|
||||
});
|
||||
|
||||
it("adds member classes", function () {
|
||||
var a = iD.Node({loc: [0, 0]}),
|
||||
b = iD.Node({loc: [1, 1]}),
|
||||
line = iD.Way({nodes: [a.id, b.id]}),
|
||||
relation = iD.Relation({members: [{id: line.id}], tags: {type: 'route'}}),
|
||||
graph = iD.Graph([a, b, line, relation]);
|
||||
|
||||
surface.call(iD.svg.Lines(projection), graph, [line], filter);
|
||||
|
||||
expect(surface.select('.line')).to.be.classed('member');
|
||||
expect(surface.select('.line')).to.be.classed('member-type-route');
|
||||
});
|
||||
|
||||
it("adds stroke classes for the tags of the parent relation of multipolygon members", function() {
|
||||
var a = iD.Node({loc: [0, 0]}),
|
||||
b = iD.Node({loc: [1, 1]}),
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
describe("iD.svg.MemberClasses", function () {
|
||||
var selection;
|
||||
|
||||
beforeEach(function () {
|
||||
selection = d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'g'));
|
||||
});
|
||||
|
||||
it("adds no classes to elements that aren't a member of any relations", function() {
|
||||
var node = iD.Node(),
|
||||
graph = iD.Graph([node]);
|
||||
|
||||
selection
|
||||
.datum(node)
|
||||
.call(iD.svg.MemberClasses(graph));
|
||||
|
||||
expect(selection.attr('class')).to.equal(null);
|
||||
});
|
||||
|
||||
it("adds tags for member, role, and type", function() {
|
||||
var node = iD.Node(),
|
||||
relation = iD.Relation({members: [{id: node.id, role: 'r'}], tags: {type: 't'}}),
|
||||
graph = iD.Graph([node, relation]);
|
||||
|
||||
selection
|
||||
.datum(node)
|
||||
.call(iD.svg.MemberClasses(graph));
|
||||
|
||||
expect(selection.attr('class')).to.equal('member member-type-t member-role-r');
|
||||
});
|
||||
|
||||
it('removes classes for tags that are no longer present', function() {
|
||||
var node = iD.Entity(),
|
||||
graph = iD.Graph([node]);
|
||||
|
||||
selection
|
||||
.attr('class', 'member member-type-t member-role-r')
|
||||
.datum(node)
|
||||
.call(iD.svg.MemberClasses(graph));
|
||||
|
||||
expect(selection.attr('class')).to.equal('');
|
||||
});
|
||||
|
||||
it("preserves existing non-'member-'-prefixed classes", function() {
|
||||
var node = iD.Entity(),
|
||||
graph = iD.Graph([node]);
|
||||
|
||||
selection
|
||||
.attr('class', 'selected')
|
||||
.datum(node)
|
||||
.call(iD.svg.MemberClasses(graph));
|
||||
|
||||
expect(selection.attr('class')).to.equal('selected');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user