Exemple #1
0
func (g *TextGraphics) Rect(x, y, w, h int, style chart.Style) {
	chart.SanitizeRect(x, y, w, h, 1)
	// Border
	if style.LineWidth > 0 {
		for i := 0; i < w; i++ {
			g.tb.Put(x+i, y, rune(style.Symbol))
			g.tb.Put(x+i, y+h-1, rune(style.Symbol))
		}
		for i := 1; i < h-1; i++ {
			g.tb.Put(x, y+i, rune(style.Symbol))
			g.tb.Put(x+w-1, y+i, rune(style.Symbol))
		}
	}

	// Filling
	if style.FillColor != nil {
		// TODO: fancier logic
		var s int
		_, _, _, a := style.FillColor.RGBA()
		if a == 0xffff {
			s = '#' // black
		} else if a == 0 {
			s = ' ' // white
		} else {
			s = style.Symbol
		}
		for i := 1; i < h-1; i++ {
			for j := 1; j < w-1; j++ {
				g.tb.Put(x+j, y+i, rune(s))
			}
		}
	}
}
Exemple #2
0
func (sg *SvgGraphics) Rect(x, y, w, h int, style chart.Style) {
	var s string
	x, y, w, h = chart.SanitizeRect(x, y, w, h, style.LineWidth)
	linecol := style.LineColor
	if linecol != nil {
		s = fmt.Sprintf("stroke:%s; ", hexcol(linecol))
		s += fmt.Sprintf("stroke-opacity: %s; ", alpha(linecol))
	} else {
		s = "stroke:#808080; "
	}
	s += fmt.Sprintf("stroke-width: %d; ", style.LineWidth)
	if style.FillColor != nil {
		s += fmt.Sprintf("fill: %s; fill-opacity: %s", hexcol(style.FillColor), alpha(style.FillColor))
	} else {
		s += "fill-opacity: 0"
	}
	sg.svg.Rect(x, y, w, h, s)
	// GenericRect(sg, x, y, w, h, style) // TODO
}