title: How to wrap d3.svg.line?
body: <p>I have a webpage with multiple sparklines in it. The user selects certain parameters to control the sparklines, some require loading data from the server, and others don't require loading new data, for example, changing chart type (line, area, bar, etc).</p>
  
  <p>I dont want to reload the whole chart for those parameters, and so I've been trying to manipulate the paths, but I am stuck because I also need to get the original data of each path to rebuild x and y functions as well as my custom built color schema function which is based on a threshold that I compute from the data.</p>
  
  <p>This is how I build the paths:</p>
  
  <pre><code>var chart = d3.svg.line()
      .x(function(d,i) { return x(i); })
      .y(function(d) { return height-y(d); })
      .interpolate('basis');
  g.append("path")
      .datum(data)
      .attr("class", "chart-path-" + me.id)
      .attr("d", chart);
  </code></pre>
  
  <p>This is how I want to update it:</p>
  
  <pre><code>var line = function(data) {
      return d3.svg.line()
          .x(function(d,i) {
              var x = d3.scale.linear().domain([0, data.length]).range([0, width]);
              return x(i);
          })
          .y(function(d, i) {
              var y = d3.scale.linear().domain([0, d3.max(data)]).range([0, height]);
              return height-y(d);
          })
          .interpolate('basis');
  }
  d3.selectAll(".chart-path-" + me.id)
      .attr("d", function(data) { return line(data); });
  </code></pre>
  
  <p>The reason I am wrapping the line function is because d3.svg.line doesnot keep the original data passed to it, see the source code <a href="https://github.com/mbostock/d3/blob/master/src/svg/line.js" rel="nofollow">here</a>. But it seems like d3 does not accept a function. It throws this error:</p>
  
  <pre><code>Error: Problem parsing d="function n(n){function a(){s.push("M",u(t(f),l))}for(var o,s=[],f=[],h=-1,d=n.length,g=c(e),p=c(r);d&gt;++h;)i.call(this,o=n[h],h)?f.push([+g.call(this,o,h),+p.call(this,o,h)]):f.length&amp;&amp;(a(),f=[]);return f.length&amp;&amp;a(),s.length?s.join(""):null}"
  </code></pre>
  
  <p>I read that it expects a path or a path generated by d3 helper methods (line, area, etc) which is what I am returning in my function. How can I do this? Am I working in the wrong direction? Please ask if something is not clear.</p>