Reconcile CellChar color

This commit is contained in:
Zack Guo 2016-08-13 22:34:50 -04:00
parent 4e0083d6b1
commit 62281b0e23
1 changed files with 17 additions and 8 deletions

View File

@ -89,16 +89,27 @@ func (bc *BarChart) Buffer() Buffer {
for i := 0; i < bc.numBar && i < len(bc.Data) && i < len(bc.DataLabels); i++ { for i := 0; i < bc.numBar && i < len(bc.Data) && i < len(bc.DataLabels); i++ {
h := int(float64(bc.Data[i]) / bc.scale) h := int(float64(bc.Data[i]) / bc.scale)
oftX := i * (bc.BarWidth + bc.BarGap) 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 // plot bar
for j := 0; j < bc.BarWidth; j++ { for j := 0; j < bc.BarWidth; j++ {
for k := 0; k < h; k++ { for k := 0; k < h; k++ {
c := Cell{ c := Cell{
Ch: bc.CellChar, Ch: bc.CellChar,
Bg: bc.BarColor, Bg: barBg,
} Fg: barFg,
if bc.BarColor == ColorDefault { // when color is default, space char treated as transparent!
c.Bg |= AttrReverse
} }
x := bc.innerArea.Min.X + i*(bc.BarWidth+bc.BarGap) + j x := bc.innerArea.Min.X + i*(bc.BarWidth+bc.BarGap) + j
y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 2 - k y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 2 - k
buf.Set(x, y, c) buf.Set(x, y, c)
@ -122,11 +133,9 @@ func (bc *BarChart) Buffer() Buffer {
c := Cell{ c := Cell{
Ch: bc.dataNum[i][j], Ch: bc.dataNum[i][j],
Fg: bc.NumColor, Fg: bc.NumColor,
Bg: bc.BarColor, Bg: barBg,
}
if bc.BarColor == ColorDefault { // the same as above
c.Bg |= AttrReverse
} }
if h == 0 { if h == 0 {
c.Bg = bc.Bg c.Bg = bc.Bg
} }