Skip to content

Commit

Permalink
D3VertexIconDecorator supports adding color to each icon from config
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbordas committed Aug 12, 2015
1 parent 25d8fc1 commit 52a6f0a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 5 additions & 1 deletion dist/planar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,11 @@
return iconGroup.append("rect").attr("class", "vertex-icon-overlay vertex-icon-overlay-" + iconId).attr("rx", borderRadius).attr("ry", borderRadius).attr("width", size).attr("height", size);
}
function createIcon(iconGroup, icon, iconId, iconPadding) {
return iconGroup.append("use").attr("class", "vertex-icon vertex-icon-" + iconId).attr("transform", "translate(" + iconPadding + ", " + iconPadding + ")").attr("xlink:href", "#" + icon.id);
var iconSvg = iconGroup.append("use").attr("class", "vertex-icon vertex-icon-" + iconId).attr("transform", "translate(" + iconPadding + ", " + iconPadding + ")").attr("xlink:href", "#" + icon.id);
if (icon.color) {
iconSvg.attr("style", "fill:" + icon.color);
}
return iconSvg;
}
utils.mixin(D3VertexIconDecorator.prototype, ElementRendererDecorator);
utils.mixin(D3VertexIconDecorator.prototype, {
Expand Down
7 changes: 4 additions & 3 deletions dist/planar.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions samples/d3-image-vertices.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
},
{
id: 'share'
},
{
id: 'share',
color: 'red'
}
]);

Expand Down
8 changes: 7 additions & 1 deletion src/view/d3/decorator/D3VertexIconDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ var D3VertexIconDecorator = (function () {
}

function createIcon(iconGroup, icon, iconId, iconPadding) {
return iconGroup.append('use').
var iconSvg = iconGroup.append('use').
attr('class', 'vertex-icon vertex-icon-' + iconId).
attr('transform', 'translate(' + iconPadding + ', ' + iconPadding + ')').
attr('xlink:href', '#' + icon.id);

if (icon.color) {
iconSvg.attr('style', 'fill:'+icon.color);
}

return iconSvg;
}

utils.mixin(D3VertexIconDecorator.prototype, ElementRendererDecorator);
Expand Down

0 comments on commit 52a6f0a

Please sign in to comment.