From: W. Trevor King Date: Mon, 27 May 2013 19:08:04 +0000 (-0400) Subject: wtk_graph.asy: Fix palette positioning in graphMatrixFile X-Git-Tag: thesis-v1.0~20 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0edc194678f9fe129ead7812a3ae07a5b2cf53fe;p=reveal.js.git wtk_graph.asy: Fix palette positioning in graphMatrixFile We know where the figure axes end (k_u0 and dx) in graph coordinates, and the palette() function expects and initial and final pair in graph coordinates, but we want the palette offset to be in frame coordinates. This means we need to take our figure corners from graph coordinate through picture coordinates to frame frame coordinates, add our offset, and go back through picture coordinates to graph coordinates before passing the values in to palette(). --- diff --git a/media/src/asy/wtk_graph.asy b/media/src/asy/wtk_graph.asy index 77e1395..8397d49 100644 --- a/media/src/asy/wtk_graph.asy +++ b/media/src/asy/wtk_graph.asy @@ -143,6 +143,11 @@ real[][] extract_matrix(real[] xs, real[] ys, real[] zs) { return z_matrix; } +pair ScaleInv(picture pic=currentpicture, pair z) +{ + return (pic.scale.x.Tinv(z.x),pic.scale.y.Tinv(z.y)); +} + void graphMatrixFile(picture pic=currentpicture, string file="datafile", int xcol=0, int ycol=1, int zcol=2, real xscale=1, real yscale=1, @@ -170,13 +175,20 @@ void graphMatrixFile(picture pic=currentpicture, string file="datafile", xaxis(pic, x_label, BottomTop,LeftTicks,above=true); if (y_label != null) yaxis(pic, y_label, LeftRight,RightTicks,above=true); - transform graph_to_pic = pic.calculateTransform(); - transform pic_to_graph = inverse(graph_to_pic); - pair p_SE_pic = graph_to_pic * (xscale*max(xs), yscale*min(ys)); - pair p_initial_graph = pic_to_graph * (p_SE_pic + palette_offset*E); - pair p_NE_pic = graph_to_pic * (xscale*max(xs), yscale*max(ys)); - pair p_final_graph = pic_to_graph * (p_NE_pic - + (palette_offset+palette_width)*E); + transform pic_to_frame = pic.calculateTransform(); + transform frame_to_pic = inverse(pic_to_frame); + pair lower_right_graph = (final.x, initial.y); + pair lower_right_pic = Scale(lower_right_graph); + pair lower_right_frame = pic_to_frame * lower_right_pic; + pair p_initial_frame = lower_right_frame + palette_offset * E; + pair p_initial_pic = frame_to_pic * p_initial_frame; + pair p_initial_graph = ScaleInv(p_initial_pic); + pair upper_right_graph = final; + pair upper_right_pic = Scale(upper_right_graph); + pair upper_right_frame = pic_to_frame * upper_right_pic; + pair p_final_frame = upper_right_frame + (palette_offset+palette_width) * E; + pair p_final_pic = frame_to_pic * p_final_frame; + pair p_final_graph = ScaleInv(p_final_pic); if (palette_label == null) palette(pic, bounds=range, initial=p_initial_graph, final=p_final_graph, axis=Right, palette=p);