Rename mbarchart to stackedbarchart

This commit is contained in:
Caleb Bassi 2018-11-28 18:50:44 -08:00
parent 7f3648562a
commit bcaa487074
4 changed files with 62 additions and 62 deletions

View File

@ -1,54 +0,0 @@
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
// +build ignore
package main
import ui "github.com/gizak/termui"
func main() {
err := ui.Init()
if err != nil {
panic(err)
}
defer ui.Close()
bc := ui.NewMBarChart()
math := []int{90, 85, 90, 80}
english := []int{70, 85, 75, 60}
science := []int{75, 60, 80, 85}
compsci := []int{100, 100, 100, 100}
bc.Data[0] = math
bc.Data[1] = english
bc.Data[2] = science
bc.Data[3] = compsci
studentsName := []string{"Ken", "Rob", "Dennis", "Linus"}
bc.BorderLabel = "Student's Marks X-Axis=Name Y-Axis=Marks[Math,English,Science,ComputerScience] in %"
bc.Width = 100
bc.Height = 30
bc.Y = 0
bc.BarWidth = 10
bc.DataLabels = studentsName
bc.ShowScale = true //Show y_axis scale value (min and max)
bc.SetMax(400)
bc.TextColor = ui.ColorGreen //this is color for label (x-axis)
bc.BarColor[3] = ui.ColorGreen //BarColor for computerscience
bc.BarColor[1] = ui.ColorYellow //Bar Color for english
bc.NumColor[3] = ui.ColorRed // Num color for computerscience
bc.NumColor[1] = ui.ColorRed // num color for english
//Other colors are automatically populated, btw All the students seems do well in computerscience. :p
ui.Render(bc)
for {
e := <-ui.PollEvent()
switch e.ID {
case "q", "<C-c>":
return
}
}
}

View File

@ -0,0 +1,54 @@
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
// +build ignore
package main
import ui "github.com/gizak/termui"
func main() {
err := ui.Init()
if err != nil {
panic(err)
}
defer ui.Close()
sbc := ui.NewStackedBarChart()
math := []int{90, 85, 90, 80}
english := []int{70, 85, 75, 60}
science := []int{75, 60, 80, 85}
compsci := []int{100, 100, 100, 100}
sbc.Data[0] = math
sbc.Data[1] = english
sbc.Data[2] = science
sbc.Data[3] = compsci
studentsName := []string{"Ken", "Rob", "Dennis", "Linus"}
sbc.BorderLabel = "Student's Marks X-Axis=Name Y-Axis=Marks[Math,English,Science,ComputerScience] in %"
sbc.Width = 100
sbc.Height = 30
sbc.Y = 0
sbc.BarWidth = 10
sbc.DataLabels = studentsName
sbc.ShowScale = true //Show y_axis scale value (min and max)
sbc.SetMax(400)
sbc.TextColor = ui.ColorGreen //this is color for label (x-axis)
sbc.BarColor[3] = ui.ColorGreen //BarColor for computerscience
sbc.BarColor[1] = ui.ColorYellow //Bar Color for english
sbc.NumColor[3] = ui.ColorRed // Num color for computerscience
sbc.NumColor[1] = ui.ColorRed // num color for english
//Other colors are automatically populated, btw All the students seems do well in computerscience. :p
ui.Render(sbc)
for {
e := <-ui.PollEvent()
switch e.ID {
case "q", "<C-c>":
return
}
}
}

View File

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 71 KiB

View File

@ -11,7 +11,7 @@ import (
// This is the implementation of multi-colored or stacked bar graph. This is different from default barGraph which is implemented in bar.go // This is the implementation of multi-colored or stacked bar graph. This is different from default barGraph which is implemented in bar.go
// Multi-Colored-BarChart creates multiple bars in a widget: // Multi-Colored-BarChart creates multiple bars in a widget:
/* /*
bc := termui.NewMBarChart() bc := termui.NewStackedBarChart()
data := make([][]int, 2) data := make([][]int, 2)
data[0] := []int{3, 2, 5, 7, 9, 4} data[0] := []int{3, 2, 5, 7, 9, 4}
data[1] := []int{7, 8, 5, 3, 1, 6} data[1] := []int{7, 8, 5, 3, 1, 6}
@ -25,7 +25,7 @@ import (
bc.BarColor = termui.ColorRed bc.BarColor = termui.ColorRed
bc.NumColor = termui.ColorYellow bc.NumColor = termui.ColorYellow
*/ */
type MBarChart struct { type StackedBarChart struct {
Block Block
BarColor [NumberofColors]Attribute BarColor [NumberofColors]Attribute
TextColor Attribute TextColor Attribute
@ -46,9 +46,9 @@ type MBarChart struct {
maxScale []rune maxScale []rune
} }
// NewMBarChart returns a new *MBarChart with current theme. // NewStackedBarChart returns a new *StackedBarChart with current theme.
func NewMBarChart() *MBarChart { func NewStackedBarChart() *StackedBarChart {
mbc := &MBarChart{ mbc := &StackedBarChart{
Block: *NewBlock(), Block: *NewBlock(),
TextColor: ThemeAttr("mbarchart.text.fg"), TextColor: ThemeAttr("mbarchart.text.fg"),
NumFmt: func(n int) string { return fmt.Sprint(n) }, NumFmt: func(n int) string { return fmt.Sprint(n) },
@ -60,7 +60,7 @@ func NewMBarChart() *MBarChart {
return mbc return mbc
} }
func (bc *MBarChart) layout() { func (bc *StackedBarChart) layout() {
bc.numBar = bc.innerArea.Dx() / (bc.BarGap + bc.BarWidth) bc.numBar = bc.innerArea.Dx() / (bc.BarGap + bc.BarWidth)
bc.labels = make([][]rune, bc.numBar) bc.labels = make([][]rune, bc.numBar)
DataLen := 0 DataLen := 0
@ -140,14 +140,14 @@ func (bc *MBarChart) layout() {
} }
func (bc *MBarChart) SetMax(max int) { func (bc *StackedBarChart) SetMax(max int) {
if max > 0 { if max > 0 {
bc.max = max bc.max = max
} }
} }
// Buffer implements Bufferer interface. // Buffer implements Bufferer interface.
func (bc *MBarChart) Buffer() Buffer { func (bc *StackedBarChart) Buffer() Buffer {
buf := bc.Block.Buffer() buf := bc.Block.Buffer()
bc.layout() bc.layout()