Skip to content

Commit

Permalink
add optional selector argument to dc.utils.appendOrSelect
Browse files Browse the repository at this point in the history
for @davisford
The final argument is still the tag to append
The middle argument is optional, a selector to look for
  • Loading branch information
gordonwoodhull committed Dec 6, 2014
1 parent 9b2a041 commit f590cdb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/coordinate-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ dc.coordinateGridMixin = function (_chart) {
// cannot select <clippath> elements; bug in WebKit, must select by id
// https://groups.google.com/forum/#!topic/d3-js/6EpAzQ2gU9I
var id = getClipPathId();
var chartBodyClip = dc.utils.appendOrSelect(defs, id).attr('id', id);
var chartBodyClip = dc.utils.appendOrSelect(defs, '#' + id, 'clipPath').attr('id', id);

var padding = _clipPadding * 2;

Expand Down
7 changes: 4 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ dc.utils.nameToId = function (name) {
return name.toLowerCase().replace(/[\s]/g, '_').replace(/[\.']/g, '');
};

dc.utils.appendOrSelect = function (parent, name) {
var element = parent.select(name);
dc.utils.appendOrSelect = function (parent, selector, tag) {
tag = tag || selector;
var element = parent.select(selector);
if (element.empty()) {
element = parent.append(name);
element = parent.append(tag);
}
return element;
};
Expand Down

1 comment on commit f590cdb

@davisford
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok -- good catch!

Please sign in to comment.