Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redo: Add css class to edge, if they have that attribute set #151

Merged
merged 1 commit into from
Mar 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
});
});