Skip to content

Commit

Permalink
Dynamically evaluate attr & style functions
Browse files Browse the repository at this point in the history
Fixes caged#174
  • Loading branch information
asteffey committed Jan 28, 2020
1 parent 9058856 commit d585939
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export default function() {
node = initNode(),
svg = null,
point = null,
target = null
target = null,
attrFuncs = [],
styleFuncs = []

function tip(vis) {
svg = getSVGNode(vis)
Expand All @@ -45,6 +47,9 @@ export default function() {
scrollLeft = document.documentElement.scrollLeft ||
rootElement.scrollLeft

attrFuncs.forEach(attrFunc => attrFunc.apply(this, args))
styleFuncs.forEach(styleFunc => styleFunc.apply(this, args))

nodel.html(content)
.style('opacity', 1).style('pointer-events', 'all')

Expand Down Expand Up @@ -79,8 +84,16 @@ export default function() {
return getNodeEl().attr(n)
}

var args = Array.prototype.slice.call(arguments)
selection.prototype.attr.apply(getNodeEl(), args)
if (arguments.length === 2 && typeof v === 'function') {
attrFuncs.push(function() {
var value = v.apply(this, arguments)
getNodeEl().attr(n, value)
})
} else {
var args = Array.prototype.slice.call(arguments)
selection.prototype.attr.apply(getNodeEl(), args)
}

return tip
}

Expand All @@ -97,8 +110,16 @@ export default function() {
return getNodeEl().style(n)
}

var args = Array.prototype.slice.call(arguments)
selection.prototype.style.apply(getNodeEl(), args)
if (arguments.length === 2 && typeof v === 'function') {
styleFuncs.push(function() {
var value = v.apply(this, arguments)
getNodeEl().style(n, value)
})
} else {
var args = Array.prototype.slice.call(arguments)
selection.prototype.style.apply(getNodeEl(), args)
}

return tip
}

Expand Down

0 comments on commit d585939

Please sign in to comment.