Merge branch 'leighmcculloch-barchart-cell-char'
This commit is contained in:
		
						commit
						23b25db083
					
				
							
								
								
									
										29
									
								
								barchart.go
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								barchart.go
									
									
									
									
									
								
							@ -29,6 +29,7 @@ type BarChart struct {
 | 
			
		||||
	DataLabels []string
 | 
			
		||||
	BarWidth   int
 | 
			
		||||
	BarGap     int
 | 
			
		||||
	CellChar   rune
 | 
			
		||||
	labels     [][]rune
 | 
			
		||||
	dataNum    [][]rune
 | 
			
		||||
	numBar     int
 | 
			
		||||
@ -44,6 +45,7 @@ func NewBarChart() *BarChart {
 | 
			
		||||
	bc.TextColor = ThemeAttr("barchart.text.fg")
 | 
			
		||||
	bc.BarGap = 1
 | 
			
		||||
	bc.BarWidth = 3
 | 
			
		||||
	bc.CellChar = ' '
 | 
			
		||||
	return bc
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -87,16 +89,27 @@ func (bc *BarChart) Buffer() Buffer {
 | 
			
		||||
	for i := 0; i < bc.numBar && i < len(bc.Data) && i < len(bc.DataLabels); i++ {
 | 
			
		||||
		h := int(float64(bc.Data[i]) / bc.scale)
 | 
			
		||||
		oftX := i * (bc.BarWidth + bc.BarGap)
 | 
			
		||||
 | 
			
		||||
		barBg := bc.Bg
 | 
			
		||||
		barFg := bc.BarColor
 | 
			
		||||
 | 
			
		||||
		if bc.CellChar == ' ' {
 | 
			
		||||
			barBg = bc.BarColor
 | 
			
		||||
			barFg = ColorDefault
 | 
			
		||||
			if bc.BarColor == ColorDefault { // the same as above
 | 
			
		||||
				barBg |= AttrReverse
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// plot bar
 | 
			
		||||
		for j := 0; j < bc.BarWidth; j++ {
 | 
			
		||||
			for k := 0; k < h; k++ {
 | 
			
		||||
				c := Cell{
 | 
			
		||||
					Ch: ' ',
 | 
			
		||||
					Bg: bc.BarColor,
 | 
			
		||||
				}
 | 
			
		||||
				if bc.BarColor == ColorDefault { // when color is default, space char treated as transparent!
 | 
			
		||||
					c.Bg |= AttrReverse
 | 
			
		||||
					Ch: bc.CellChar,
 | 
			
		||||
					Bg: barBg,
 | 
			
		||||
					Fg: barFg,
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				x := bc.innerArea.Min.X + i*(bc.BarWidth+bc.BarGap) + j
 | 
			
		||||
				y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 2 - k
 | 
			
		||||
				buf.Set(x, y, c)
 | 
			
		||||
@ -120,11 +133,9 @@ func (bc *BarChart) Buffer() Buffer {
 | 
			
		||||
			c := Cell{
 | 
			
		||||
				Ch: bc.dataNum[i][j],
 | 
			
		||||
				Fg: bc.NumColor,
 | 
			
		||||
				Bg: bc.BarColor,
 | 
			
		||||
			}
 | 
			
		||||
			if bc.BarColor == ColorDefault { // the same as above
 | 
			
		||||
				c.Bg |= AttrReverse
 | 
			
		||||
				Bg: barBg,
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if h == 0 {
 | 
			
		||||
				c.Bg = bc.Bg
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user