diff --git a/_includes/examples/scatterplot.svg b/_includes/examples/scatterplot.svg index e1bf230..c9f7212 100644 --- a/_includes/examples/scatterplot.svg +++ b/_includes/examples/scatterplot.svg @@ -1,27 +1,88 @@ + - + - + Translation logic: + + For the x-axis of each dot to plot: move cx over + by the porportional amount of 270 to fit the 4 data + points. + + cx = 270px * ($X / 3) + ^[1] ^[2] ^[3] + + [1] width of graph = we choose 270 since it fits + nicely in our 350-60=290 remaining x-axis + canvas, and is divisible by N_of_points-1 (3). + [2] the current x-value to translate to 'cx'. + [3] max(x) = using 0 indexing with 4 x-values + [0,1,2,3], 3 is the max x-value. + e.g. Calculate cx of 2014-02-01 (the 2nd point) + cx = 270 * (1/3) = 90. + + + For the y-axis: translate the "upside down" y-down + into the data's "y-up" scale, and scale 0-80 into + 0-120. Subtract a proportional offset away from the + total possible offset of 120. + + cy = 120px - (($Y / 80) * 120px) + ^[1] ^[2] ^[3] ^[4] + + [1] top of graph = we choose to make the plot 120 so + it can upscale our points ranging from 0-80. + 120 fits nicely in our overall height 160, less + the 10 top margin already translated down. + [2] y-value = the current y-value to plot in the data: + [10, 20, 40, 80]. + [3] max(y) = the max y-value in the data, which when + converting from "y-up" to "y-down", should result + in a "y-down" SVG offset of 0 (top of the chart). + Thus we subtract from the top of the scale the + proportional offset upsampled from a max of 80 to + a new max of 120. + [4] scale = this matches [1] for the reason in [3]. + + e.g. Calculate cy of 2014-02-01, 20 dollars. + cy = 120 - (20 / 80) * 120 = 90. + + --> + + $10 $80 + + January 2014 April - \ No newline at end of file + diff --git a/z02-parts-of-a-graph.md b/z02-parts-of-a-graph.md index 9ca3a44..505c45c 100644 --- a/z02-parts-of-a-graph.md +++ b/z02-parts-of-a-graph.md @@ -96,15 +96,15 @@ We'll need to manually write out each point. Transform attributes are inherited by child elements, so we can use `` tags to move entire groups, such as the axes, or even offset the entire graph by a margin. -
+
+
+ {% include examples/scatterplot.svg %} +
{% highlight html %} {% include examples/scatterplot.svg %} {% endhighlight %}
-
- {% include examples/scatterplot.svg %} -
Man! All that work for such a simple graph? SVG is a lot of work!