Skip to content

Commit

Permalink
plot: remove log func from package scope
Browse files Browse the repository at this point in the history
Having a function named `log` is relatively annoying when one is
debugging, especially in conjunction with `goimports`:
adding `log.Fatalf("foo")` statements is confusing `goimports` as a
function with the name `log` is already defined.

Remove `func log` and directly move its checks inside `LogScaler.Normalize`.
  • Loading branch information
sbinet committed Jan 17, 2019
1 parent 9f5dec1 commit 11e7162
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions axis.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ var _ Normalizer = LogScale{}
// Normalize returns the fractional logarithmic distance of
// x between min and max.
func (LogScale) Normalize(min, max, x float64) float64 {
logMin := log(min)
return (log(x) - logMin) / (log(max) - logMin)
if min <= 0 || max <= 0 || x <= 0 {
panic("Values must be greater than 0 for a log scale.")
}
logMin := math.Log(min)
return (math.Log(x) - logMin) / (math.Log(max) - logMin)
}

// InvertedScale can be used as the value of an Axis.Scale function to
Expand Down Expand Up @@ -610,13 +613,6 @@ func tickLabelWidth(sty draw.TextStyle, ticks []Tick) vg.Length {
return maxWidth
}

func log(x float64) float64 {
if x <= 0 {
panic("Values must be greater than 0 for a log scale.")
}
return math.Log(x)
}

// formatFloatTick returns a g-formated string representation of v
// to the specified precision.
func formatFloatTick(v float64, prec int) string {
Expand Down

0 comments on commit 11e7162

Please sign in to comment.