From ae06310a2dab08c581c5548089850112533957d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Sundstr=C3=B6m?= Date: Wed, 18 Jul 2012 19:23:00 -0700 Subject: [PATCH] Prettified svg source a bit by rounding coords to 3 decimals. --- caltrain.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/caltrain.js b/caltrain.js index 50e8834f..1152aa44 100644 --- a/caltrain.js +++ b/caltrain.js @@ -33,8 +33,8 @@ vis.selectAll('path.line') .data([data]) .enter() .append('svg:path') - .attr('d', d3.svg.line().x(function(d, i) { return x(t0 + i * 10); }) - .y(function(d, i) { return y(d); })) + .attr('d', d3.svg.line().x(function(d, i) { return p(x(t0 + i * 10)); }) + .y(function(d, i) { return p(y(d)); })) ; function stationInfo(stop, i) { // stop: {"t":"08:15","s":29700} @@ -48,6 +48,7 @@ function stationInfo(stop, i) { // stop: {"t":"08:15","s":29700} } function I(i) { return i; } +function p(n) { return n.toFixed(3); } stops = schedule.stops.map(stationInfo).filter(I); @@ -56,10 +57,10 @@ y_ticks = vis.selectAll('.ticky') .data(stops) .enter() .append('svg:g') + .attr('class', 'ticky') .attr('transform', function(d) { - return 'translate(0, ' + y(d.lat) + ')'; + return 'translate(0,' + p(y(d.lat)) + ')'; }) - .attr('class', 'ticky') ; y_ticks.append('svg:line') .attr('y1', 0) @@ -77,12 +78,12 @@ x_ticks = vis.selectAll('.tickx') .data(stops) .enter() .append('svg:g') - .attr('transform', function(d, i) { - return 'translate(' + x(d.seconds) + ', 0)'; - }) .attr('class', function(d, i) { return 'tickx' + (i ? i == stops.length - 1 ? ' final' : '' : ' first'); }) + .attr('transform', function(d, i) { + return 'translate(' + p(x(d.seconds)) + ')'; + }) ; x_ticks.append('svg:line') .attr('y1', h) @@ -113,8 +114,8 @@ vis.selectAll('.point') .attr('r', function(d, i) { return d === max ? 6 : 4; }) - .attr('cx', function(d, i) { return x(d.seconds); }) - .attr('cy', function(d, i) { return y(d.lat); }) + .attr('cx', function(d, i) { return p(x(d.seconds)); }) + .attr('cy', function(d, i) { return p(y(d.lat)); }) .on('mouseover', hilight) .on('mouseout', unhilight) .on('click', function(d, i) { return console.log(d, i); })