Merge pull request #17 from ademille/fix-braille-plot

Fix braille plot y-axis scaling
This commit is contained in:
Navid Yaghoobi 2023-11-24 15:27:40 +11:00 committed by GitHub
commit 23229b36a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 15 deletions

View File

@ -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
}()

16
plot.go
View File

@ -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)
}
}
}
@ -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))