From f681b8334c833223a8e9c8b817747e4bf9e3716c Mon Sep 17 00:00:00 2001 From: Stephen Bannasch Date: Thu, 8 Mar 2012 17:37:47 -0500 Subject: [PATCH] grapher: shift right when plotting past right edge --- lib/simple-graph.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/simple-graph.js b/lib/simple-graph.js index 88359cc..71af0c0 100644 --- a/lib/simple-graph.js +++ b/lib/simple-graph.js @@ -212,8 +212,8 @@ function simpleGraph(elem, data, options) { return d ? "#ccc" : "#666"; }, - fx = xScale.tickFormat(options.datacount), - fy = xScale.tickFormat(options.datacount); + fx = xScale.tickFormat(10), + fy = xScale.tickFormat(10); // Regenerate x-ticks… var gx = vis.selectAll("g.x") @@ -568,8 +568,18 @@ function simpleGraph(elem, data, options) { graph.set_data = function(_) { if (!arguments.length) return data; + var domain = xScale.domain(), + xextent = domain[1] - domain[0], + shift = xextent * 0.8; graph.generateDataPoints(_); - graph.update(); + if (points.length > domain[1]) { + domain[0] += shift; + domain[1] += shift; + xScale.domain(domain); + graph.redraw(); + } else { + graph.update(); + } return graph; };