-
Notifications
You must be signed in to change notification settings - Fork 46
/
line-series.js
61 lines (52 loc) · 1.43 KB
/
line-series.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
(function() {
'use strict';
/*
*
* @name lineSeries
*/
d4.feature('lineSeries', function(name) {
var line = d3.svg.line();
line.interpolate('linear');
return {
accessors: {
classes: function(d, n) {
return 'line stroke series' + n;
},
key: d4.functor(d4.defaultKey),
x: function(d) {
return this.x(d[this.x.$key]);
},
y: function(d) {
return this.y(d[this.y.$key]);
}
},
proxies: [{
target: line
}],
render: function(scope, data, selection) {
var group = d4.appendOnce(selection, 'g.' + name);
line
.x(d4.functor(scope.accessors.x).bind(this))
.y(d4.functor(scope.accessors.y).bind(this));
var lineGroups = group.selectAll('g')
.data(data, d4.functor(scope.accessors.key).bind(this));
lineGroups.enter().append('g')
.attr('data-key', function(d) {
return d.key;
})
.attr('class', d4.functor(scope.accessors.classes).bind(this));
var lines = lineGroups.selectAll('path')
.data(function(d) {
return [d];
});
lines.enter().append('path');
lines.attr('d', function(d) {
return line(d.values);
});
lines.exit().remove();
lineGroups.exit().remove();
return lineGroups;
}
};
});
}).call(this);