Fix .shared classing

Now that Graph#parentWays is cached, the specialized Graph#parentStructure
method is no longer necessary.

This commit also demonstrates that it's relatively easy to write specs for
rendering now!
This commit is contained in:
John Firebaugh
2013-01-11 11:53:05 -08:00
parent c24d6d83e3
commit 577398ca21
5 changed files with 28 additions and 15 deletions

View File

@@ -35,17 +35,6 @@ iD.Graph.prototype = {
return transients[key] = fn.call(entity);
},
parentStructure: function(ways) {
var nodes = {};
ways.forEach(function(w) {
_.uniq(w.nodes).forEach(function(n) {
if (typeof nodes[n.id] === 'undefined') nodes[n.id] = 0;
nodes[n.id]++;
});
});
return nodes;
},
parentWays: function(entity) {
var graph = this;
return this.transient(entity, 'parentWays',
@@ -63,7 +52,6 @@ iD.Graph.prototype = {
},
parentRelations: function(entity) {
// This is slow and a bad hack.
var graph = this;
return this.transient(entity, 'parentRelations',
function generateParentRelations() {

View File

@@ -9,8 +9,6 @@ iD.svg.Vertices = function() {
}
}
var parentStructure = graph.parentStructure(vertices);
var groups = surface.select('.layer-hit').selectAll('g.vertex')
.filter(filter)
.data(vertices, iD.Entity.key);
@@ -28,7 +26,7 @@ iD.svg.Vertices = function() {
.attr('r', 4);
groups.attr('transform', iD.svg.PointTransform(projection))
.classed('shared', function(d) { return parentStructure[d.id] > 1; });
.classed('shared', function(entity) { return graph.parentWays(entity).length > 1; });
// Selecting the following implicitly
// sets the data (vertix entity) on the elements

View File

@@ -139,6 +139,7 @@
<script src="spec/renderer/hash.js"></script>
<script src="spec/renderer/map.js"></script>
<script src="spec/svg/vertices.js"></script>
<script src="spec/svg/tag_classes.js"></script>
<script src="spec/ui/inspector.js"></script>

View File

@@ -57,6 +57,7 @@
<script src="spec/renderer/hash.js"></script>
<script src="spec/renderer/map.js"></script>
<script src="spec/svg/vertices.js"></script>
<script src="spec/svg/tag_classes.js"></script>
<script src="spec/ui/inspector.js"></script>

25
test/spec/svg/vertices.js Normal file
View File

@@ -0,0 +1,25 @@
describe("iD.svg.Vertices", function () {
var surface,
projection = d3.geo.mercator(),
filter = d3.functor(true);
beforeEach(function () {
surface = d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'svg'));
surface.append('g')
.attr('class', 'layer-hit');
});
// TODO: fill out
it("adds the .shared class to vertices that are members of two or more ways", function () {
var node = iD.Node({loc: [0, 0]}),
way1 = iD.Way({nodes: [node.id]}),
way2 = iD.Way({nodes: [node.id]}),
graph = iD.Graph([node, way1, way2]);
surface.call(iD.svg.Vertices(), graph, [node], filter, projection);
expect(surface.select('.vertex').classed('shared')).to.equal(true);
});
});