summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt <kurt.w.jung@gmail.com>2018-04-05 10:53:43 -0400
committerKurt <kurt.w.jung@gmail.com>2018-04-05 10:53:43 -0400
commitf2f3e9500092af921abde270a026e8ceb2098ec4 (patch)
tree5bfd386085af198aa643a1cba905d250d49b8bb0
parent7a47e7018ccde09a294789f42534c8c3cbe8a538 (diff)
Add relative position method to grid
-rw-r--r--grid.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/grid.go b/grid.go
index 825fa3b..aca8508 100644
--- a/grid.go
+++ b/grid.go
@@ -162,6 +162,22 @@ func (g GridType) Wd(dataWd float64) float64 {
return g.xm * dataWd
}
+// XY converts dataX and dataY, specified in logical data units, to the X and Y
+// position on the current page.
+func (g GridType) XY(dataX, dataY float64) (x, y float64) {
+ return g.xm*dataX + g.xb, g.ym*dataY + g.yb
+}
+
+// Pos returns the point, in page units, indicated by the relative positions
+// xRel and yRel. These are values between 0 and 1. xRel specifies the relative
+// position between the grid's left and right edges. yRel specifies the
+// relative position between the grid's bottom and top edges.
+func (g GridType) Pos(xRel, yRel float64) (x, y float64) {
+ x = g.w*xRel + g.x
+ y = g.h*(1-yRel) + g.y
+ return
+}
+
// X converts dataX, specified in logical data units, to the X position on the
// current page.
func (g GridType) X(dataX float64) float64 {