source: node_modules/d3-transition/src/transition/attrTween.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import {namespace} from "d3-selection";
2
3function attrInterpolate(name, i) {
4 return function(t) {
5 this.setAttribute(name, i.call(this, t));
6 };
7}
8
9function attrInterpolateNS(fullname, i) {
10 return function(t) {
11 this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
12 };
13}
14
15function attrTweenNS(fullname, value) {
16 var t0, i0;
17 function tween() {
18 var i = value.apply(this, arguments);
19 if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
20 return t0;
21 }
22 tween._value = value;
23 return tween;
24}
25
26function attrTween(name, value) {
27 var t0, i0;
28 function tween() {
29 var i = value.apply(this, arguments);
30 if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
31 return t0;
32 }
33 tween._value = value;
34 return tween;
35}
36
37export default function(name, value) {
38 var key = "attr." + name;
39 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
40 if (value == null) return this.tween(key, null);
41 if (typeof value !== "function") throw new Error;
42 var fullname = namespace(name);
43 return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
44}
Note: See TracBrowser for help on using the repository browser.