-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathline.js
More file actions
105 lines (90 loc) · 2.76 KB
/
line.js
File metadata and controls
105 lines (90 loc) · 2.76 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
define(function (require) {
var d3 = require("d3");
var path = require("src/modules/element/svg/path");
var builder = require("builder");
var valuator = require("valuator");
return function line() {
// Private variables
var x = function (d) { return d.x; };
var y = function (d) { return d.y; };
var xScale = d3.time.scale.utc();
var yScale = d3.scale.linear();
var interpolate = "linear";
var tension = 0.7;
var defined = function (d) { return d.y !== null; };
var properties = {
class: "line",
fill: "none",
stroke: function (d, i) { return d3.scale.category10()(i); },
strokeWidth: 3,
opacity: 1
};
function component(selection) {
selection.each(function () {
var d3line = d3.svg.line()
.x(X)
.y(Y)
.interpolate(interpolate)
.tension(tension)
.defined(defined);
var line = path()
.pathGenerator(d3line);
d3.select(this)
.append("g")
.call(builder(properties, line));
});
}
function X(d, i) {
return xScale(x.call(this, d, i));
}
function Y(d, i) {
return yScale(y.call(this, d, i));
}
// Public API
component.x = function (_) {
if (!arguments.length) { return x; }
x = valuator(_);
return component;
};
component.y = function (_) {
if (!arguments.length) { return y; }
y = valuator(_);
return component;
};
component.xScale = function (_) {
if (!arguments.length) { return xScale; }
xScale = _;
return component;
};
component.yScale = function (_) {
if (!arguments.length) { return yScale; }
yScale = _;
return component;
};
component.interpolate = function (_) {
if (!arguments.length) { return interpolate; }
interpolate = _;
return component;
};
component.tension = function (_) {
if (!arguments.length) { return tension; }
tension = _;
return component;
};
component.defined = function (_) {
if (!arguments.length) { return defined; }
defined = _;
return component;
};
component.properties = function (_) {
if (!arguments.length) { return properties; }
properties.class = typeof _.class !== "undefined" ? _.class : properties.class;
properties.fill = typeof _.fill !== "undefined" ? _.fill : properties.fill;
properties.stroke = typeof _.stroke !== "undefined" ? _.stroke : properties.stroke;
properties.strokeWidth = typeof _.strokeWidth !== "undefined" ? _.strokeWidth : properties.strokeWidth;
properties.opacity = typeof _.opacity !== "undefined" ? _.opacity : properties.opacity;
return component;
};
return component;
};
});