mirror of
https://github.com/navidys/tvxwidgets.git
synced 2025-04-30 13:48:57 +08:00
feat option to draw y or x axis label independently (#25)
Signed-off-by: Hidayat Hamir <hidayat.03@erajaya.com>
This commit is contained in:
parent
82465e0608
commit
d8a9aeb20e
@ -35,6 +35,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
bmLineChart.SetMarker(tvxwidgets.PlotMarkerBraille)
|
bmLineChart.SetMarker(tvxwidgets.PlotMarkerBraille)
|
||||||
bmLineChart.SetData(sinData)
|
bmLineChart.SetData(sinData)
|
||||||
|
bmLineChart.SetDrawXAxisLabel(false)
|
||||||
|
|
||||||
dmLineChart := tvxwidgets.NewPlot()
|
dmLineChart := tvxwidgets.NewPlot()
|
||||||
dmLineChart.SetBorder(true)
|
dmLineChart.SetBorder(true)
|
||||||
@ -72,6 +73,7 @@ func main() {
|
|||||||
dmScatterPlot.SetPlotType(tvxwidgets.PlotTypeScatter)
|
dmScatterPlot.SetPlotType(tvxwidgets.PlotTypeScatter)
|
||||||
dmScatterPlot.SetMarker(tvxwidgets.PlotMarkerDot)
|
dmScatterPlot.SetMarker(tvxwidgets.PlotMarkerDot)
|
||||||
dmScatterPlot.SetData(scatterPlotData)
|
dmScatterPlot.SetData(scatterPlotData)
|
||||||
|
dmScatterPlot.SetDrawYAxisLabel(false)
|
||||||
|
|
||||||
bmScatterPlot := tvxwidgets.NewPlot()
|
bmScatterPlot := tvxwidgets.NewPlot()
|
||||||
bmScatterPlot.SetBorder(true)
|
bmScatterPlot.SetBorder(true)
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 46 KiB |
30
plot.go
30
plot.go
@ -50,6 +50,8 @@ type Plot struct {
|
|||||||
axesColor tcell.Color
|
axesColor tcell.Color
|
||||||
axesLabelColor tcell.Color
|
axesLabelColor tcell.Color
|
||||||
drawAxes bool
|
drawAxes bool
|
||||||
|
drawXAxisLabel bool
|
||||||
|
drawYAxisLabel bool
|
||||||
brailleCellMap map[image.Point]brailleCell
|
brailleCellMap map[image.Point]brailleCell
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
@ -64,6 +66,8 @@ func NewPlot() *Plot {
|
|||||||
axesColor: tcell.ColorDimGray,
|
axesColor: tcell.ColorDimGray,
|
||||||
axesLabelColor: tcell.ColorDimGray,
|
axesLabelColor: tcell.ColorDimGray,
|
||||||
drawAxes: true,
|
drawAxes: true,
|
||||||
|
drawXAxisLabel: true,
|
||||||
|
drawYAxisLabel: true,
|
||||||
lineColors: []tcell.Color{
|
lineColors: []tcell.Color{
|
||||||
tcell.ColorSteelBlue,
|
tcell.ColorSteelBlue,
|
||||||
},
|
},
|
||||||
@ -109,6 +113,16 @@ func (plot *Plot) SetDrawAxes(draw bool) {
|
|||||||
plot.drawAxes = draw
|
plot.drawAxes = draw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetDrawXAxisLabel set true in order to draw x axis label to screen.
|
||||||
|
func (plot *Plot) SetDrawXAxisLabel(draw bool) {
|
||||||
|
plot.drawXAxisLabel = draw
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDrawYAxisLabel set true in order to draw y axis label to screen.
|
||||||
|
func (plot *Plot) SetDrawYAxisLabel(draw bool) {
|
||||||
|
plot.drawYAxisLabel = draw
|
||||||
|
}
|
||||||
|
|
||||||
// SetMarker sets marker type braille or dot mode.
|
// SetMarker sets marker type braille or dot mode.
|
||||||
func (plot *Plot) SetMarker(marker Marker) {
|
func (plot *Plot) SetMarker(marker Marker) {
|
||||||
plot.marker = marker
|
plot.marker = marker
|
||||||
@ -192,7 +206,18 @@ func (plot *Plot) drawAxesToScreen(screen tcell.Screen) {
|
|||||||
y+height-plotXAxisLabelsHeight-1,
|
y+height-plotXAxisLabelsHeight-1,
|
||||||
tview.BoxDrawingsLightUpAndRight, axesStyle)
|
tview.BoxDrawingsLightUpAndRight, axesStyle)
|
||||||
|
|
||||||
// draw x axis labels
|
if plot.drawXAxisLabel {
|
||||||
|
plot.drawXAxisLabelToScreen(screen, plotYAxisLabelsWidth, x, y, width, height)
|
||||||
|
}
|
||||||
|
|
||||||
|
if plot.drawYAxisLabel {
|
||||||
|
plot.drawYAxisLabelToScreen(screen, plotYAxisLabelsWidth, x, y, height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (plot *Plot) drawXAxisLabelToScreen(
|
||||||
|
screen tcell.Screen, plotYAxisLabelsWidth int, x int, y int, width int, height int,
|
||||||
|
) {
|
||||||
tview.Print(screen, "0",
|
tview.Print(screen, "0",
|
||||||
x+plotYAxisLabelsWidth,
|
x+plotYAxisLabelsWidth,
|
||||||
y+height-plotXAxisLabelsHeight,
|
y+height-plotXAxisLabelsHeight,
|
||||||
@ -210,8 +235,9 @@ func (plot *Plot) drawAxesToScreen(screen tcell.Screen) {
|
|||||||
|
|
||||||
labelX += (len(label) + plotXAxisLabelsGap) * plotHorizontalScale
|
labelX += (len(label) + plotXAxisLabelsGap) * plotHorizontalScale
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// draw Y axis labels
|
func (plot *Plot) drawYAxisLabelToScreen(screen tcell.Screen, plotYAxisLabelsWidth int, x int, y int, height int) {
|
||||||
verticalScale := plot.maxVal / float64(height-plotXAxisLabelsHeight-1)
|
verticalScale := plot.maxVal / float64(height-plotXAxisLabelsHeight-1)
|
||||||
|
|
||||||
for i := 0; i*(plotYAxisLabelsGap+1) < height-1; i++ {
|
for i := 0; i*(plotYAxisLabelsGap+1) < height-1; i++ {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user