Example #1
0
func (ig *ImageGraphics) Line(x0, y0, x1, y1 int, style chart.Style) {
	if style.LineWidth <= 0 {
		style.LineWidth = 1
	}
	ig.setStyle(style)
	ig.gc.MoveTo(float64(x0), float64(y0))
	ig.gc.LineTo(float64(x1), float64(y1))
	ig.gc.Stroke()
}
Example #2
0
func (g *TextGraphics) Boxes(boxes []chart.Box, width int, style chart.Style) {
	if width%2 == 0 {
		width += 1
	}
	hbw := (width - 1) / 2
	if style.Symbol == 0 {
		style.Symbol = '*'
	}

	for _, box := range boxes {
		x := int(box.X)
		q1, q3 := int(box.Q1), int(box.Q3)
		g.tb.Rect(x-hbw, q1, 2*hbw, q3-q1, 0, ' ')
		if !math.IsNaN(box.Med) {
			med := int(box.Med)
			g.tb.Put(x-hbw, med, '+')
			for i := 0; i < hbw; i++ {
				g.tb.Put(x-i, med, '-')
				g.tb.Put(x+i, med, '-')
			}
			g.tb.Put(x+hbw, med, '+')
		}

		if !math.IsNaN(box.Avg) && style.Symbol != 0 {
			g.tb.Put(x, int(box.Avg), rune(style.Symbol))
		}

		if !math.IsNaN(box.High) {
			for y := int(box.High); y < q3; y++ {
				g.tb.Put(x, y, '|')
			}
		}

		if !math.IsNaN(box.Low) {
			for y := int(box.Low); y > q1; y-- {
				g.tb.Put(x, y, '|')
			}
		}

		for _, ol := range box.Outliers {
			y := int(ol)
			g.tb.Put(x, y, rune(style.Symbol))
		}
	}
}