@@ -3,36 +3,50 @@ package graphic
33import "github.com/nsf/termbox-go"
44
55func drawDown (bins [][]float64 , count int , cfg Config , scale float64 ) error {
6- var cSetCount = len (bins )
7-
86 var cWidth , cHeight = termbox .Size ()
97
10- var cChanWidth = (cfg .BinWidth * count ) - cfg .SpaceWidth
11- var cPaddedWidth = (cfg .BinWidth * count * cSetCount ) - cfg .SpaceWidth
12- var cOffset = (cWidth - cPaddedWidth ) / 2
13-
148 var vHeight = cHeight - cfg .BaseThick
9+ if vHeight < 0 {
10+ vHeight = 0
11+ }
1512
1613 scale = float64 (vHeight ) / scale
1714
15+ var cPaddedWidth = (cfg .BinWidth * count * len (bins )) - cfg .SpaceWidth
16+
17+ if cPaddedWidth > cWidth || cPaddedWidth < 0 {
18+ cPaddedWidth = cWidth
19+ }
20+
1821 var xBin int
19- var xCol = cOffset
22+ var xCol = ( cWidth - cPaddedWidth ) / 2
2023 var delta = 1
2124
2225 for xCh := range bins {
2326 var stop , top = stopAndTop (bins [xCh ][xBin ]* scale , vHeight , false )
27+ if stop += cfg .BaseThick ; stop >= cHeight {
28+ stop = cHeight
29+ top = BarRune
30+ }
2431
2532 var lCol = xCol + cfg .BarWidth
26- var lColMax = xCol + cChanWidth
27-
28- for xCol < lColMax {
33+ var lColMax = xCol + (cfg .BinWidth * count ) - cfg .SpaceWidth
2934
35+ for {
3036 if xCol >= lCol {
37+ if xCol >= lColMax {
38+ break
39+ }
40+
3141 if xBin += delta ; xBin >= count || xBin < 0 {
3242 break
3343 }
3444
3545 stop , top = stopAndTop (bins [xCh ][xBin ]* scale , vHeight , false )
46+ if stop += cfg .BaseThick ; stop >= cHeight {
47+ stop = cHeight
48+ top = BarRune
49+ }
3650
3751 xCol += cfg .SpaceWidth
3852 lCol = xCol + cfg .BarWidth
@@ -65,20 +79,3 @@ func drawDown(bins [][]float64, count int, cfg Config, scale float64) error {
6579
6680 return nil
6781}
68-
69- // var stopAndTop = func(value float64) (stop int, top int) {
70- // if value *= scale; value < float64(vHeight) {
71- // top = int(value * NumRunes)
72- // } else {
73- // top = vHeight * NumRunes
74- // }
75- // stop = (top / NumRunes) + cfg.BaseThick
76- // top %= NumRunes
77-
78- // if stop > cHeight {
79- // stop = cHeight
80- // top = 0
81- // }
82-
83- // return
84- // }
0 commit comments