Debian Codegraph @

src/js/Rickshaw.Graph.Renderer.LinePlot.js

raw
1 Rickshaw.namespace('Rickshaw.Graph.Renderer.LinePlot');
2
3 Rickshaw.Graph.Renderer.LinePlot = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
4
5 name: 'lineplot',
6
7 defaults: function($super) {
8
9 return Rickshaw.extend( $super(), {
10 unstack: true,
11 fill: false,
12 stroke: true,
13 padding:{ top: 0.01, right: 0.01, bottom: 0.01, left: 0.01 },
14 dotSize: 3,
15 strokeWidth: 2
16 } );
17 },
18
19 seriesPathFactory: function() {
20
21 var graph = this.graph;
22
23 var factory = d3.svg.line()
24 .x( function(d) { return graph.x(d.x) } )
25 .y( function(d) { return graph.y(d.y) } )
26 .interpolate(this.graph.interpolation).tension(this.tension);
27
28 factory.defined && factory.defined( function(d) { return d.y !== null } );
29 return factory;
30 },
31
32 render: function(args) {
33
34 args = args || {};
35
36 var graph = this.graph;
37
38 var series = args.series || graph.series;
39 var vis = args.vis || graph.vis;
40
41 var dotSize = this.dotSize;
42
43 vis.selectAll('*').remove();
44
45 var data = series
46 .filter(function(s) { return !s.disabled })
47 .map(function(s) { return s.stack });
48
49 var nodes = vis.selectAll("path")
50 .data(data)
51 .enter().append("svg:path")
52 .attr("d", this.seriesPathFactory());
53
54 var i = 0;
55 series.forEach(function(series) {
56 if (series.disabled) return;
57 series.path = nodes[0][i++];
58 this._styleSeries(series);
59 }, this);
60
61 series.forEach(function(series) {
62
63 if (series.disabled) return;
64
65 var nodes = vis.selectAll("x")
66 .data(series.stack.filter( function(d) { return d.y !== null } ))
67 .enter().append("svg:circle")
68 .attr("cx", function(d) { return graph.x(d.x) })
69 .attr("cy", function(d) { return graph.y(d.y) })
70 .attr("r", function(d) { return ("r" in d) ? d.r : dotSize});
71
72 Array.prototype.forEach.call(nodes[0], function(n) {
73 if (!n) return;
74 n.setAttribute('data-color', series.color);
75 n.setAttribute('fill', 'white');
76 n.setAttribute('stroke', series.color);
77 n.setAttribute('stroke-width', this.strokeWidth);
78
79 }.bind(this));
80
81 }, this);
82 }
83 } );
84