Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Dynamically evaluate attr & style functions #261

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
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
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.