git.haldean.org sousvide / f59902f
Switch to using polylines for graphing. Will Haldean Brown 8 years ago
1 changed file(s) with 18 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
4444 if h.Heating {
4545 x0 := int(float64(i) * pxPerUnitX)
4646 svgs.Rect(x0, 0, int(math.Ceil(pxPerUnitX)), ImgHeight,
47 "fill:#F0F0F0")
47 "fill:#F7F7F7")
4848 }
4949 }
5050 }
5151
5252 // draw grid before data so it's under everything
53 for i := 0; i <= ImgHeight; i += int(10 * pxPerUnitY) {
53 even := true
54 for i := 0; i <= ImgHeight; i += int(5 * pxPerUnitY) {
5455 y := ImgHeight - i
55 svgs.Line(0, y, ImgWidth, y, "stroke:#DDD; stroke-width:1")
56 if even {
57 svgs.Line(0, y, ImgWidth, y, "stroke:#DDD; stroke-width:1")
58 } else {
59 svgs.Line(0, y, ImgWidth, y, "stroke:#EEE; stroke-width:1")
60 }
61 even = !even
5662 }
5763
5864 // draw data
5965 if N > 1 {
60 lastX := int(0)
61 lastTempY := int(s.History[0].Temp * pxPerUnitY)
62 lastTargetY := int(s.History[0].Target * pxPerUnitY)
63 for i, h := range s.History[1:] {
64 x := int(float64(i + 1) * pxPerUnitX)
65 tempY := int(h.Temp * pxPerUnitY)
66 targetY := int(h.Target * pxPerUnitY)
67 svgs.Line(lastX, ImgHeight - lastTempY, x, ImgHeight - tempY,
68 "stroke:#FF0000; stroke-width:2")
69 svgs.Line(lastX, ImgHeight - lastTargetY, x, ImgHeight - targetY,
70 "stroke:#0000FF; stroke-width:2")
71 lastX = x
72 lastTempY = tempY
73 lastTargetY = targetY
66 xs := make([]int, N)
67 temps := make([]int, N)
68 targets := make([]int, N)
69 for i, h := range s.History {
70 xs[i] = int(float64(i) * pxPerUnitX)
71 temps[i] = ImgHeight - int(h.Temp * pxPerUnitY)
72 targets[i] = ImgHeight - int(h.Target * pxPerUnitY)
7473 }
74 svgs.Polyline(xs, temps, "stroke:#FF0000; stroke-width:1; fill:none")
75 svgs.Polyline(xs, targets, "stroke:#0000FF; stroke-width:1; fill:none")
7576 }
7677
7778 // draw axes last so they're on top of everything else