Skip to content

Commit

Permalink
Merge pull request #17 from ademille/fix-braille-plot
Browse files Browse the repository at this point in the history
Fix braille plot y-axis scaling
  • Loading branch information
navidys authored Nov 24, 2023
2 parents a75224e + 3578e68 commit 23229b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
6 changes: 4 additions & 2 deletions demos/plot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ func main() {
data[0] = make([]float64, n)
data[1] = make([]float64, n)
for i := 0; i < n; i++ {
data[0][i] = 1 + math.Sin(float64(i)/5)
data[1][i] = 1 + math.Cos(float64(i)/5)
data[0][i] = 1 + math.Sin(float64(i+1)/5)
// Avoid taking Cos(0) because it creates a high point of 2 that
// will never be hit again and makes the graph look a little funny
data[1][i] = 1 + math.Cos(float64(i+1)/5)
}
return data
}()
Expand Down
16 changes: 3 additions & 13 deletions plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,15 @@ func (plot *Plot) drawDotMarkerToScreen(screen tcell.Screen) {
}

func (plot *Plot) drawBrailleMarkerToScreen(screen tcell.Screen) {
var cellMaxY int

x, y, width, height := plot.getChartAreaRect()

plot.calcBrailleLines()

for point := range plot.getBrailleCells() {
if point.Y > cellMaxY {
cellMaxY = point.Y
}
}

diffMAxY := y + height - cellMaxY - 1

// print to screen
for point, cell := range plot.getBrailleCells() {
style := tcell.StyleDefault.Background(plot.GetBackgroundColor()).Foreground(cell.color)
if point.X < x+width && point.Y+diffMAxY < y+height {
tview.PrintJoinedSemigraphics(screen, point.X, point.Y+diffMAxY, cell.cRune, style)
if point.X < x+width && point.Y < y+height {
tview.PrintJoinedSemigraphics(screen, point.X, point.Y, cell.cRune, style)
}
}
}
Expand All @@ -288,7 +278,7 @@ func (plot *Plot) calcBrailleLines() {
continue
}

previousHeight := int((line[1] / maxVal) * float64(height-1))
previousHeight := int((line[0] / maxVal) * float64(height-1))

for j, val := range line[1:] {
lheight := int((val / maxVal) * float64(height-1))
Expand Down

0 comments on commit 23229b3

Please sign in to comment.