@@ -259,28 +259,28 @@ func (d *Display) fillStyleBuffer(left, center, right int) {
259259}
260260
261261// Draw takes data and draws.
262- func (d * Display ) Draw (bufs [][]float64 , channels , count int , scale float64 ) error {
262+ func (d * Display ) Draw (bufs [][]float64 , channels , count int , scale float64 , invert bool ) error {
263263
264264 d .wg .Add (channels )
265265
266266 switch d .drawType {
267267 case DrawUp :
268- d .DrawUp (bufs , count , scale )
268+ d .DrawUp (bufs , count , scale , invert )
269269
270270 case DrawUpDown :
271- d .DrawUpDown (bufs , count , scale )
271+ d .DrawUpDown (bufs , count , scale , invert )
272272
273273 case DrawDown :
274- d .DrawDown (bufs , count , scale )
274+ d .DrawDown (bufs , count , scale , invert )
275275
276276 case DrawLeft :
277- d .DrawLeft (bufs , count , scale )
277+ d .DrawLeft (bufs , count , scale , invert )
278278
279279 case DrawLeftRight :
280- d .DrawLeftRight (bufs , count , scale )
280+ d .DrawLeftRight (bufs , count , scale , invert )
281281
282282 case DrawRight :
283- d .DrawRight (bufs , count , scale )
283+ d .DrawRight (bufs , count , scale , invert )
284284
285285 default :
286286 return nil
@@ -384,7 +384,7 @@ func sizeAndCap(value float64, space int, zeroBase bool, baseRune rune) (int, ru
384384// DRAWING METHODS
385385
386386// DrawUp will draw up.
387- func (d * Display ) DrawUp (bins [][]float64 , count int , scale float64 ) {
387+ func (d * Display ) DrawUp (bins [][]float64 , count int , scale float64 , invert bool ) {
388388
389389 barSpace := intMax (d .termHeight - d .baseSize , 0 )
390390 scale = float64 (barSpace ) / scale
@@ -400,6 +400,11 @@ func (d *Display) DrawUp(bins [][]float64, count int, scale float64) {
400400 for xBar := 0 ; xBar < count ; xBar ++ {
401401
402402 xBin := (xBar * (1 - xSet )) + (((count - 1 ) - xBar ) * xSet )
403+
404+ if invert {
405+ xBin = count - 1 - xBin
406+ }
407+
403408 start , bCap := sizeAndCap (chBins [xBin ]* scale , barSpace , true , BarRuneV )
404409
405410 xCol := (xBar * d .binSize ) + (channelWidth * xSet ) + edgeOffset
@@ -420,7 +425,7 @@ func (d *Display) DrawUp(bins [][]float64, count int, scale float64) {
420425}
421426
422427// DrawUpDown will draw up and down.
423- func (d * Display ) DrawUpDown (bins [][]float64 , count int , scale float64 ) {
428+ func (d * Display ) DrawUpDown (bins [][]float64 , count int , scale float64 , invert bool ) {
424429
425430 centerStart := intMax ((d .termHeight - d .baseSize )/ 2 , 0 )
426431 centerStop := centerStart + d .baseSize
@@ -440,7 +445,12 @@ func (d *Display) DrawUpDown(bins [][]float64, count int, scale float64) {
440445 rCap = BarRune
441446 }
442447
443- xCol := xBar * d .binSize + edgeOffset
448+ xCol := xBar
449+ if invert {
450+ xCol = count - 1 - xCol
451+ }
452+
453+ xCol = xCol * d .binSize + edgeOffset
444454 lCol := intMin (xCol + d .barSize , d .termWidth )
445455
446456 for ; xCol < lCol ; xCol ++ {
@@ -462,7 +472,7 @@ func (d *Display) DrawUpDown(bins [][]float64, count int, scale float64) {
462472}
463473
464474// DrawDown will draw down.
465- func (d * Display ) DrawDown (bins [][]float64 , count int , scale float64 ) {
475+ func (d * Display ) DrawDown (bins [][]float64 , count int , scale float64 , invert bool ) {
466476
467477 barSpace := intMax (d .termHeight - d .baseSize , 0 )
468478 scale = float64 (barSpace ) / scale
@@ -478,6 +488,11 @@ func (d *Display) DrawDown(bins [][]float64, count int, scale float64) {
478488 for xBar := 0 ; xBar < count ; xBar ++ {
479489
480490 xBin := (xBar * (1 - xSet )) + (((count - 1 ) - xBar ) * xSet )
491+
492+ if invert {
493+ xBin = count - 1 - xBin
494+ }
495+
481496 stop , bCap := sizeAndCap (chBins [xBin ]* scale , barSpace , false , BarRune )
482497 if stop += d .baseSize ; stop >= d .termHeight {
483498 stop = d .termHeight
@@ -501,7 +516,7 @@ func (d *Display) DrawDown(bins [][]float64, count int, scale float64) {
501516 }
502517}
503518
504- func (d * Display ) DrawLeft (bins [][]float64 , count int , scale float64 ) {
519+ func (d * Display ) DrawLeft (bins [][]float64 , count int , scale float64 , invert bool ) {
505520 barSpace := intMax (d .termWidth - d .baseSize , 0 )
506521 scale = float64 (barSpace ) / scale
507522
@@ -516,6 +531,11 @@ func (d *Display) DrawLeft(bins [][]float64, count int, scale float64) {
516531 for xBar := 0 ; xBar < count ; xBar ++ {
517532
518533 xBin := (xBar * (1 - xSet )) + (((count - 1 ) - xBar ) * xSet )
534+
535+ if invert {
536+ xBin = count - 1 - xBin
537+ }
538+
519539 start , bCap := sizeAndCap (chBins [xBin ]* scale , barSpace , true , BarRune )
520540
521541 xRow := (xBar * d .binSize ) + (channelWidth * xSet ) + edgeOffset
@@ -536,7 +556,7 @@ func (d *Display) DrawLeft(bins [][]float64, count int, scale float64) {
536556}
537557
538558// DrawLeftRight will draw left and right.
539- func (d * Display ) DrawLeftRight (bins [][]float64 , count int , scale float64 ) {
559+ func (d * Display ) DrawLeftRight (bins [][]float64 , count int , scale float64 , invert bool ) {
540560 centerStart := intMax ((d .termWidth - d .baseSize )/ 2 , 0 )
541561 centerStop := centerStart + d .baseSize
542562
@@ -558,7 +578,13 @@ func (d *Display) DrawLeftRight(bins [][]float64, count int, scale float64) {
558578 rCap = BarRuneH
559579 }
560580
561- xRow := xBar * d .binSize + edgeOffset
581+ xRow := xBar
582+ if invert {
583+ xRow = count - 1 - xRow
584+ }
585+
586+ xRow = xRow * d .binSize + edgeOffset
587+
562588 lRow := intMin (xRow + d .barSize , d .termHeight )
563589
564590 for ; xRow < lRow ; xRow ++ {
@@ -578,7 +604,7 @@ func (d *Display) DrawLeftRight(bins [][]float64, count int, scale float64) {
578604 }
579605}
580606
581- func (d * Display ) DrawRight (bins [][]float64 , count int , scale float64 ) {
607+ func (d * Display ) DrawRight (bins [][]float64 , count int , scale float64 , invert bool ) {
582608 barSpace := intMax (d .termWidth - d .baseSize , 0 )
583609 scale = float64 (barSpace ) / scale
584610
@@ -593,6 +619,11 @@ func (d *Display) DrawRight(bins [][]float64, count int, scale float64) {
593619 for xBar := 0 ; xBar < count ; xBar ++ {
594620
595621 xBin := (xBar * (1 - xSet )) + (((count - 1 ) - xBar ) * xSet )
622+
623+ if invert {
624+ xBin = count - 1 - xBin
625+ }
626+
596627 stop , bCap := sizeAndCap (chBins [xBin ]* scale , barSpace , false , BarRuneH )
597628 if stop += d .baseSize ; stop >= d .termWidth {
598629 stop = d .termWidth
0 commit comments