mirror of
https://kevinblog.sytes.net/Code/Jibo-Revival-Group/RoboCommander.git
synced 2026-06-18 15:56:10 +00:00
33 lines
904 B
JavaScript
33 lines
904 B
JavaScript
import {namespace} from "d3-selection";
|
|
|
|
function attrTweenNS(fullname, value) {
|
|
function tween() {
|
|
var node = this, i = value.apply(node, arguments);
|
|
return i && function(t) {
|
|
node.setAttributeNS(fullname.space, fullname.local, i(t));
|
|
};
|
|
}
|
|
tween._value = value;
|
|
return tween;
|
|
}
|
|
|
|
function attrTween(name, value) {
|
|
function tween() {
|
|
var node = this, i = value.apply(node, arguments);
|
|
return i && function(t) {
|
|
node.setAttribute(name, i(t));
|
|
};
|
|
}
|
|
tween._value = value;
|
|
return tween;
|
|
}
|
|
|
|
export default function(name, value) {
|
|
var key = "attr." + name;
|
|
if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
|
if (value == null) return this.tween(key, null);
|
|
if (typeof value !== "function") throw new Error;
|
|
var fullname = namespace(name);
|
|
return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
|
|
}
|