Commit 1ec75e1f authored by David Blyth's avatar David Blyth

Moved things into axis.go

parent c47e5b52
......@@ -7,6 +7,20 @@ import (
"gonum.org/v1/plot"
)
type LogScale struct{}
func (LogScale) Normalize(min, max, x float64) float64 {
logMin := log10(min)
return (log10(x) - logMin) / (log10(max) - logMin)
}
func log10(x float64) float64 {
if x <= 0 {
return -1
}
return math.Log10(x)
}
type PreciseTicks struct {
NSuggestedTicks int
}
......@@ -103,6 +117,26 @@ func round(x float64, prec int) float64 {
return x / pow
}
type LogTicks struct{}
func (LogTicks) Ticks(min, max float64) []plot.Tick {
val := math.Pow10(int(log10(min)))
max = math.Pow10(int(math.Ceil(log10(max))))
var ticks []plot.Tick
for val < max {
for i := 1; i < 10; i++ {
if i == 1 {
ticks = append(ticks, plot.Tick{Value: val, Label: formatFloatTick(val, -1)})
}
ticks = append(ticks, plot.Tick{Value: val * float64(i)})
}
val *= 10
}
ticks = append(ticks, plot.Tick{Value: val, Label: formatFloatTick(val, -1)})
return ticks
}
func formatFloatTick(v float64, prec int) string {
return strconv.FormatFloat(v, 'g', prec, 64)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment