2 nv.models.line = function() {
5 var margin = {top: 0, right: 0, bottom: 0, left: 0},
8 color = nv.utils.defaultColor(), // function that returns colors
9 id = Math.floor(Math.random() * 10000), //Create semi-unique ID incase user doesn't select one
10 getX = function(d) { return d.x }, // accessor to get the x value from a data point
11 getY = function(d) { return d.y }, // accessor to get the y value from a data point
12 clipEdge = false, // if true, masks lines within x and y scale
13 interpolate = "linear"; // controls the line interpolation
16 var scatter = nv.models.scatter()
18 .size(16) // default size
19 .sizeDomain([16,256]), //set to speed up calculation, needs to be unset if there is a custom size accessor
20 //x = scatter.xScale(),
21 //y = scatter.yScale(),
26 function chart(selection) {
27 selection.each(function(data) {
28 var availableWidth = width - margin.left - margin.right,
29 availableHeight = height - margin.top - margin.bottom;
31 //get the scales inscase scatter scale was set manually
32 x = x || scatter.xScale();
33 y = y || scatter.yScale();
35 //store old scales if they exist
40 var wrap = d3.select(this).selectAll('g.nv-wrap.nv-line').data([data]);
41 var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-line');
42 var defsEnter = wrapEnter.append('defs');
43 var gEnter = wrapEnter.append('g');
44 var g = wrap.select('g')
46 wrapEnter.append('g').attr('class', 'nv-scatterWrap');
47 var scatterWrap = wrap.select('.nv-scatterWrap').datum(data);
49 gEnter.append('g').attr('class', 'nv-groups');
53 .width(availableWidth)
54 .height(availableHeight)
56 d3.transition(scatterWrap).call(scatter);
59 wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
62 defsEnter.append('clipPath')
63 .attr('id', 'nv-edge-clip-' + id)
66 wrap.select('#nv-edge-clip-' + id + ' rect')
67 .attr('width', availableWidth)
68 .attr('height', availableHeight);
70 g .attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + id + ')' : '');
72 .attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + id + ')' : '');
77 var groups = wrap.select('.nv-groups').selectAll('.nv-group')
78 .data(function(d) { return d }, function(d) { return d.key });
79 groups.enter().append('g')
80 .style('stroke-opacity', 1e-6)
81 .style('fill-opacity', 1e-6);
82 d3.transition(groups.exit())
83 .style('stroke-opacity', 1e-6)
84 .style('fill-opacity', 1e-6)
87 .attr('class', function(d,i) { return 'nv-group nv-series-' + i })
88 .classed('hover', function(d) { return d.hover })
89 .style('fill', function(d,i){ return color(d, i) })
90 .style('stroke', function(d,i){ return color(d, i) })
92 .style('stroke-opacity', 1)
93 .style('fill-opacity', .5)
96 var paths = groups.selectAll('path')
97 .data(function(d, i) { return [d.values] });
98 paths.enter().append('path')
99 .attr('class', 'nv-line')
100 .attr('d', d3.svg.line()
101 .interpolate(interpolate)
102 .x(function(d,i) { return x0(getX(d,i)) })
103 .y(function(d,i) { return y0(getY(d,i)) })
105 d3.transition(groups.exit().selectAll('path'))
106 .attr('d', d3.svg.line()
107 .interpolate(interpolate)
108 .x(function(d,i) { return x(getX(d,i)) })
109 .y(function(d,i) { return y(getY(d,i)) })
111 .remove(); // redundant? line is already being removed
113 .attr('d', d3.svg.line()
114 .interpolate(interpolate)
115 .x(function(d,i) { return x(getX(d,i)) })
116 .y(function(d,i) { return y(getY(d,i)) })
120 //store old scales for use in transitions on update, to animate from old to new positions
130 chart.dispatch = scatter.dispatch;
132 d3.rebind(chart, scatter, 'interactive', 'size', 'xScale', 'yScale', 'zScale', 'xDomain', 'yDomain', 'xRange', 'yRange', 'sizeDomain', 'forceX', 'forceY', 'forceSize', 'clipVoronoi', 'clipRadius');
134 chart.options = nv.utils.optionsFunc.bind(chart);
136 chart.margin = function(_) {
137 if (!arguments.length) return margin;
142 chart.width = function(_) {
143 if (!arguments.length) return width;
148 chart.height = function(_) {
149 if (!arguments.length) return height;
154 chart.x = function(_) {
155 if (!arguments.length) return getX;
161 chart.y = function(_) {
162 if (!arguments.length) return getY;
168 chart.clipEdge = function(_) {
169 if (!arguments.length) return clipEdge;
174 chart.color = function(_) {
175 if (!arguments.length) return color;
176 color = nv.utils.getColor(_);
177 scatter.color(color);
181 chart.id = function(_) {
182 if (!arguments.length) return id;
187 chart.interpolate = function(_) {
188 if (!arguments.length) return interpolate;
193 chart.defined = function(_) {
194 if (!arguments.length) return defined;