Skip to content

Commit

Permalink
Merge pull request #151 from torpedro/feature/edge-classes
Browse files Browse the repository at this point in the history
Add css class to edge, if they have that attribute set
  • Loading branch information
cpettitt committed Mar 31, 2015
2 parents 9044108 + 757ec39 commit 09dee08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/create-edge-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ function createEdgePaths(selection, g, arrows) {
util.applyTransition(svgPaths, g)
.style("opacity", 1);

// Save DOM element in the path group, and set ID
// Save DOM element in the path group, and set ID and class
svgPaths.each(function(e) {
var domEdge = d3.select(this);
var edge = g.edge(e);
edge.elem = this;

if (edge.id) {
d3.select(this).attr("id", edge.id);
domEdge.attr("id", edge.id);
}

util.applyClass(domEdge, edge["class"],
(domEdge.classed("update") ? "update " : "") + "edgePath");
});

svgPaths.selectAll("path.path")
Expand Down
11 changes: 11 additions & 0 deletions test/bundle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,16 @@ describe("dagreD3", function() {
expect(d3.select("#a").classed("a-class")).to.be.true;
expect(d3.select("#b").classed("b-class")).to.be.true;
});

it("can be set for edges", function() {
g.setNode("a", { id: "a" });
g.setNode("b", { id: "b" });
g.setEdge("a", "b", { id: "c", class: function(d) { return d.v + d.w + "-class"; } });
g.setEdge("b", "a", { id: "d", class: "d-class" });
dagreD3.render()(svg, g);

expect(d3.select("#c").classed("ab-class")).to.be.true;
expect(d3.select("#d").classed("d-class")).to.be.true;
});
});
});

0 comments on commit 09dee08

Please sign in to comment.