mirror of
https://github.com/navidys/tvxwidgets.git
synced 2025-05-01 22:18:14 +08:00
added SetXAxisLabelFunc method to provide custom X-Axis labels
Signed-off-by: Markus Ressel <mail@markusressel.de>
This commit is contained in:
parent
40e5944bdc
commit
d3dc728102
19
plot.go
19
plot.go
@ -64,6 +64,7 @@ type Plot struct {
|
||||
axesLabelColor tcell.Color
|
||||
drawAxes bool
|
||||
drawXAxisLabel bool
|
||||
xAxisLabelFunc func(int) string
|
||||
drawYAxisLabel bool
|
||||
yAxisLabelDataType PlotYAxisLabelDataType
|
||||
yAxisAutoScaleMin bool
|
||||
@ -83,6 +84,7 @@ func NewPlot() *Plot {
|
||||
axesLabelColor: tcell.ColorDimGray,
|
||||
drawAxes: true,
|
||||
drawXAxisLabel: true,
|
||||
xAxisLabelFunc: func(i int) string { return strconv.Itoa(i) },
|
||||
drawYAxisLabel: true,
|
||||
yAxisLabelDataType: PlotYAxisLabelDataFloat,
|
||||
yAxisAutoScaleMin: false,
|
||||
@ -152,6 +154,11 @@ func (plot *Plot) SetDrawXAxisLabel(draw bool) {
|
||||
plot.drawXAxisLabel = draw
|
||||
}
|
||||
|
||||
// SetXAxisLabelFunc sets x axis label function.
|
||||
func (plot *Plot) SetXAxisLabelFunc(f func(int) string) {
|
||||
plot.xAxisLabelFunc = f
|
||||
}
|
||||
|
||||
// SetDrawYAxisLabel set true in order to draw y axis label to screen.
|
||||
func (plot *Plot) SetDrawYAxisLabel(draw bool) {
|
||||
plot.drawYAxisLabel = draw
|
||||
@ -273,15 +280,9 @@ func (plot *Plot) drawAxesToScreen(screen tcell.Screen) {
|
||||
func (plot *Plot) drawXAxisLabelToScreen(
|
||||
screen tcell.Screen, plotYAxisLabelsWidth int, x int, y int, width int, height int,
|
||||
) {
|
||||
tview.Print(screen, "0",
|
||||
x+plotYAxisLabelsWidth,
|
||||
y+height-plotXAxisLabelsHeight,
|
||||
1,
|
||||
tview.AlignLeft, plot.axesLabelColor)
|
||||
|
||||
for labelX := x + plotYAxisLabelsWidth +
|
||||
(plotXAxisLabelsGap)*plotHorizontalScale + 1; labelX < x+width-1; {
|
||||
label := strconv.Itoa((labelX-(x+plotYAxisLabelsWidth)-1)/(plotHorizontalScale) + 1)
|
||||
for labelX := x + plotYAxisLabelsWidth; labelX < x+width-1; {
|
||||
labelIndex := (labelX-(x+plotYAxisLabelsWidth)-1)/(plotHorizontalScale) + 1
|
||||
label := plot.xAxisLabelFunc(labelIndex)
|
||||
|
||||
tview.Print(screen, label, labelX, y+height-plotXAxisLabelsHeight, width, tview.AlignLeft, plot.axesLabelColor)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user