@@ -34,7 +34,9 @@ const (
3434 DrawUp
3535 DrawUpDown
3636 DrawDown
37+ DrawLeft
3738 DrawLeftRight
39+ DrawRight
3840 DrawMax
3941
4042 // DrawDefault is the default draw type.
@@ -228,10 +230,16 @@ func (d *Display) updateStyleBuffer() {
228230 case DrawDown :
229231 d .fillStyleBuffer (0 , d .baseSize , d .termHeight - d .baseSize )
230232
233+ case DrawLeft :
234+ d .fillStyleBuffer (d .termWidth - d .baseSize , d .baseSize , 0 )
235+
231236 case DrawLeftRight :
232237 centerStart := intMax ((d .termWidth - d .baseSize )/ 2 , 0 )
233238 centerStop := centerStart + d .baseSize
234239 d .fillStyleBuffer (centerStart , d .baseSize , d .termWidth - centerStop )
240+
241+ case DrawRight :
242+ d .fillStyleBuffer (0 , d .baseSize , d .termWidth - d .baseSize )
235243 }
236244}
237245
@@ -258,12 +266,22 @@ func (d *Display) Draw(bufs [][]float64, channels, count int, scale float64) err
258266 switch d .drawType {
259267 case DrawUp :
260268 d .DrawUp (bufs , count , scale )
269+
261270 case DrawUpDown :
262271 d .DrawUpDown (bufs , count , scale )
272+
263273 case DrawDown :
264274 d .DrawDown (bufs , count , scale )
275+
276+ case DrawLeft :
277+ d .DrawLeft (bufs , count , scale )
278+
265279 case DrawLeftRight :
266280 d .DrawLeftRight (bufs , count , scale )
281+
282+ case DrawRight :
283+ d .DrawRight (bufs , count , scale )
284+
267285 default :
268286 return nil
269287 }
@@ -336,6 +354,8 @@ func (d *Display) Bars(sets ...int) int {
336354 return (d .termWidth / d .binSize ) / x
337355 case DrawUpDown :
338356 return d .termWidth / d .binSize
357+ case DrawLeft , DrawRight :
358+ return (d .termHeight / d .binSize ) / x
339359 case DrawLeftRight :
340360 return d .termHeight / d .binSize
341361 default :
@@ -399,6 +419,48 @@ func (d *Display) DrawUp(bins [][]float64, count int, scale float64) {
399419 }
400420}
401421
422+ // DrawUpDown will draw up and down.
423+ func (d * Display ) DrawUpDown (bins [][]float64 , count int , scale float64 ) {
424+
425+ centerStart := intMax ((d .termHeight - d .baseSize )/ 2 , 0 )
426+ centerStop := centerStart + d .baseSize
427+
428+ scale = float64 (intMin (centerStart , d .termHeight - centerStop )) / scale
429+
430+ edgeOffset := intMax ((d .termWidth - ((d .binSize * count )- d .spaceSize ))/ 2 , 0 )
431+
432+ setCount := len (bins )
433+
434+ for xBar := 0 ; xBar < count ; xBar ++ {
435+
436+ lStart , lCap := sizeAndCap (bins [0 ][xBar ]* scale , centerStart , true , BarRuneV )
437+ rStop , rCap := sizeAndCap (bins [1 % setCount ][xBar ]* scale , centerStart , false , BarRune )
438+ if rStop += centerStop ; rStop >= d .termHeight {
439+ rStop = d .termHeight
440+ rCap = BarRune
441+ }
442+
443+ xCol := xBar * d .binSize + edgeOffset
444+ lCol := intMin (xCol + d .barSize , d .termWidth )
445+
446+ for ; xCol < lCol ; xCol ++ {
447+
448+ if lCap > BarRuneV {
449+ termbox .SetCell (xCol , lStart - 1 , lCap , d .styles .Foreground , d .styles .Background )
450+ }
451+
452+ for xRow := lStart ; xRow < rStop ; xRow ++ {
453+ termbox .SetCell (xCol , xRow , BarRune , d .styleBuffer [xRow ], d .styles .Background )
454+ }
455+
456+ // last part of right bars.
457+ if rCap < BarRune {
458+ termbox .SetCell (xCol , rStop , rCap , StyleReverse , d .styles .Foreground )
459+ }
460+ }
461+ }
462+ }
463+
402464// DrawDown will draw down.
403465func (d * Display ) DrawDown (bins [][]float64 , count int , scale float64 ) {
404466
@@ -439,43 +501,35 @@ func (d *Display) DrawDown(bins [][]float64, count int, scale float64) {
439501 }
440502}
441503
442- // DrawUpDown will draw up and down.
443- func (d * Display ) DrawUpDown (bins [][]float64 , count int , scale float64 ) {
444-
445- centerStart := intMax ((d .termHeight - d .baseSize )/ 2 , 0 )
446- centerStop := centerStart + d .baseSize
447-
448- scale = float64 (intMin (centerStart , d .termHeight - centerStop )) / scale
504+ func (d * Display ) DrawLeft (bins [][]float64 , count int , scale float64 ) {
505+ barSpace := intMax (d .termWidth - d .baseSize , 0 )
506+ scale = float64 (barSpace ) / scale
449507
450- edgeOffset := intMax ((d .termWidth - ((d .binSize * count )- d .spaceSize ))/ 2 , 0 )
508+ paddedWidth := (d .binSize * count * len (bins )) - d .spaceSize
509+ paddedWidth = intMax (intMin (paddedWidth , d .termHeight ), 0 )
451510
452- setCount := len (bins )
511+ channelWidth := d .binSize * count
512+ edgeOffset := (d .termHeight - paddedWidth ) / 2
453513
454- for xBar := 0 ; xBar < count ; xBar ++ {
514+ for xSet , chBins := range bins {
455515
456- lStart , lCap := sizeAndCap (bins [0 ][xBar ]* scale , centerStart , true , BarRuneV )
457- rStop , rCap := sizeAndCap (bins [1 % setCount ][xBar ]* scale , centerStart , false , BarRune )
458- if rStop += centerStop ; rStop >= d .termHeight {
459- rStop = d .termHeight
460- rCap = BarRune
461- }
516+ for xBar := 0 ; xBar < count ; xBar ++ {
462517
463- xCol := xBar * d . binSize + edgeOffset
464- lCol := intMin ( xCol + d . barSize , d . termWidth )
518+ xBin := ( xBar * ( 1 - xSet )) + ((( count - 1 ) - xBar ) * xSet )
519+ start , bCap := sizeAndCap ( chBins [ xBin ] * scale , barSpace , true , BarRune )
465520
466- for ; xCol < lCol ; xCol ++ {
521+ xRow := (xBar * d .binSize ) + (channelWidth * xSet ) + edgeOffset
522+ lRow := xRow + d .barSize
467523
468- if lCap > BarRuneV {
469- termbox .SetCell (xCol , lStart - 1 , lCap , d .styles .Foreground , d .styles .Background )
470- }
524+ for ; xRow < lRow ; xRow ++ {
471525
472- for xRow := lStart ; xRow < rStop ; xRow ++ {
473- termbox .SetCell (xCol , xRow , BarRune , d . styleBuffer [ xRow ] , d .styles .Background )
474- }
526+ if bCap > BarRune {
527+ termbox .SetCell (start - 1 , xRow , bCap , StyleReverse , d .styles .Background )
528+ }
475529
476- // last part of right bars.
477- if rCap < BarRune {
478- termbox . SetCell ( xCol , rStop , rCap , StyleReverse , d . styles . Foreground )
530+ for xCol := start ; xCol < d . termWidth ; xCol ++ {
531+ termbox . SetCell ( xCol , xRow , BarRune , d . styleBuffer [ xCol ], d . styles . Background )
532+ }
479533 }
480534 }
481535 }
@@ -523,3 +577,41 @@ func (d *Display) DrawLeftRight(bins [][]float64, count int, scale float64) {
523577 }
524578 }
525579}
580+
581+ func (d * Display ) DrawRight (bins [][]float64 , count int , scale float64 ) {
582+ barSpace := intMax (d .termWidth - d .baseSize , 0 )
583+ scale = float64 (barSpace ) / scale
584+
585+ paddedWidth := (d .binSize * count * len (bins )) - d .spaceSize
586+ paddedWidth = intMax (intMin (paddedWidth , d .termHeight ), 0 )
587+
588+ channelWidth := d .binSize * count
589+ edgeOffset := (d .termHeight - paddedWidth ) / 2
590+
591+ for xSet , chBins := range bins {
592+
593+ for xBar := 0 ; xBar < count ; xBar ++ {
594+
595+ xBin := (xBar * (1 - xSet )) + (((count - 1 ) - xBar ) * xSet )
596+ stop , bCap := sizeAndCap (chBins [xBin ]* scale , barSpace , false , BarRuneH )
597+ if stop += d .baseSize ; stop >= d .termWidth {
598+ stop = d .termWidth
599+ bCap = BarRune
600+ }
601+
602+ xRow := (xBar * d .binSize ) + (channelWidth * xSet ) + edgeOffset
603+ lRow := xRow + d .barSize
604+
605+ for ; xRow < lRow ; xRow ++ {
606+
607+ for xCol := 0 ; xCol < stop ; xCol ++ {
608+ termbox .SetCell (xCol , xRow , BarRune , d .styleBuffer [xCol ], d .styles .Background )
609+ }
610+
611+ if bCap < BarRuneH {
612+ termbox .SetCell (stop , xRow , bCap , d .styles .Foreground , d .styles .Foreground )
613+ }
614+ }
615+ }
616+ }
617+ }
0 commit comments