mirror of
https://github.com/gizak/termui.git
synced 2025-04-24 13:48:50 +08:00
Implement GetMinFloat64From2dSlice
This commit is contained in:
parent
8da7bb6861
commit
d372d9e539
16
utils.go
16
utils.go
@ -93,6 +93,22 @@ func GetMaxFloat64FromSlice(slice []float64) (float64, error) {
|
||||
return max, nil
|
||||
}
|
||||
|
||||
func GetMinFloat64From2dSlice(slices [][]float64) (float64, error) {
|
||||
if len(slices) == 0 {
|
||||
return 0, fmt.Errorf("cannot get min value from empty slice")
|
||||
}
|
||||
var min float64
|
||||
for _, slice := range slices {
|
||||
for _, val := range slice {
|
||||
if val < min {
|
||||
min = val
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return min, nil
|
||||
}
|
||||
|
||||
func GetMaxFloat64From2dSlice(slices [][]float64) (float64, error) {
|
||||
if len(slices) == 0 {
|
||||
return 0, fmt.Errorf("cannot get max value from empty slice")
|
||||
|
@ -86,7 +86,7 @@ func (self *Plot) renderBraille(buf *Buffer, drawArea image.Rectangle, minVal fl
|
||||
case ScatterPlot:
|
||||
for i, line := range self.Data {
|
||||
for j, val := range line {
|
||||
height := int(((val-minVal)/r)*float64(drawArea.Dy()-1))
|
||||
height := int(((val - minVal) / r) * float64(drawArea.Dy()-1))
|
||||
canvas.SetPoint(
|
||||
image.Pt(
|
||||
(drawArea.Min.X+(j*self.HorizontalScale))*2,
|
||||
@ -208,6 +208,9 @@ func (self *Plot) Draw(buf *Buffer) {
|
||||
if maxVal == 0 {
|
||||
maxVal, _ = GetMaxFloat64From2dSlice(self.Data)
|
||||
}
|
||||
if minVal == 0 {
|
||||
minVal, _ = GetMinFloat64From2dSlice(self.Data)
|
||||
}
|
||||
|
||||
if self.ShowAxes {
|
||||
self.plotAxes(buf, minVal, maxVal)
|
||||
|
Loading…
x
Reference in New Issue
Block a user