-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdu.js
81 lines (69 loc) · 2.04 KB
/
du.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function constant(value) {
return function() {
return value
}
}
function compose(fun1, fun2) {
if(arguments.length === 2) {
return function(/*args*/) {
return fun1(fun2.apply(null, arguments))
}
} else {
var functions = Array.prototype.slice.call(arguments)
var len = functions.length
return function(/*args*/) {
var value = (functions[len - 1]).apply(null, arguments)
var i
for(i = Math.max(0, len - 2); i >= 0; i--) {
value = (functions[i]).call(null, value)
}
return value
}
}
}
function property(key) {
return function(thing) {
return thing[key]
}
}
function key(obj) {
return obj.key
}
function value(obj) {
return obj.value
}
function window2(a) {
return a.map(function(value, index, array) {
return [value, array[index + 1]]
}).slice(0, a.length - 1)
}
function bind0(rootSelection, cssClass, element, dataFlow) {
element = element || 'g' // fixme switch from variadic to curried
dataFlow = typeof dataFlow === 'function' ? dataFlow
: (dataFlow === void(0) ? function(d) {return [d]} : constant(dataFlow))
var binding = rootSelection.selectAll('.' + cssClass).data(dataFlow, key)
binding.entered = binding.enter().append(element)
binding.entered.classed(cssClass, true)
return binding
}
function bind(object, key) {
var result = bind0.apply(null, arguments)
object[key] = result
return result
}
function translate(funX, funY) {
return function(d, i) {
return 'translate(' + (typeof funX === 'function' ? funX(d, i) : funX) + ','
+ (typeof funY === 'function' ? funY(d, i) : funY) + ')'
}
}
function translateX(funX) {
return function(d, i) {
return 'translate(' + (typeof funX === 'function' ? funX(d, i) : funX) + ', 0)'
}
}
function translateY(funY) {
return function(d, i) {
return 'translate(0, ' + (typeof funY === 'function' ? funY(d, i) : funY) + ')'
}
}