add parameters to control auto scaling behavior and prevent breaking change

Signed-off-by: Markus Ressel <mail@markusressel.de>
This commit is contained in:
Markus Ressel 2024-10-12 14:54:53 +02:00
parent 4632165f80
commit 7e3024f613
No known key found for this signature in database
GPG Key ID: F79626FAB2A3AACF

20
plot.go
View File

@ -66,6 +66,8 @@ type Plot struct {
drawXAxisLabel bool
drawYAxisLabel bool
yAxisLabelDataType PlotYAxisLabelDataType
YAxisAutoScaleMin bool
YAxisAutoScaleMax bool
brailleCellMap map[image.Point]brailleCell
mu sync.Mutex
}
@ -83,6 +85,8 @@ func NewPlot() *Plot {
drawXAxisLabel: true,
drawYAxisLabel: true,
yAxisLabelDataType: PlotYAxisLabelDataFloat,
YAxisAutoScaleMin: false,
YAxisAutoScaleMax: true,
lineColors: []tcell.Color{
tcell.ColorSteelBlue,
},
@ -118,6 +122,14 @@ func (plot *Plot) SetYAxisLabelDataType(dataType PlotYAxisLabelDataType) {
plot.yAxisLabelDataType = dataType
}
func (plot *Plot) SetYAxisAutoScaleMin(autoScale bool) {
plot.YAxisAutoScaleMin = autoScale
}
func (plot *Plot) SetYAxisAutoScaleMax(autoScale bool) {
plot.YAxisAutoScaleMax = autoScale
}
// SetAxesColor sets axes x and y lines color.
func (plot *Plot) SetAxesColor(color tcell.Color) {
plot.axesColor = color
@ -160,8 +172,12 @@ func (plot *Plot) SetData(data [][]float64) {
plot.brailleCellMap = make(map[image.Point]brailleCell)
plot.data = data
plot.maxVal = getMaxFloat64From2dSlice(data)
plot.minVal = getMinFloat64From2dSlice(data)
if plot.YAxisAutoScaleMax {
plot.maxVal = getMaxFloat64From2dSlice(data)
}
if plot.YAxisAutoScaleMin {
plot.minVal = getMinFloat64From2dSlice(data)
}
}
func (plot *Plot) SetMaxVal(maxVal float64) {