mirror of
https://github.com/navidys/tvxwidgets.git
synced 2025-04-28 13:48:52 +08:00
Merge pull request #17 from ademille/fix-braille-plot
Fix braille plot y-axis scaling
This commit is contained in:
commit
23229b36a7
@ -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
16
plot.go
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user