axis labels!

This commit is contained in:
Will Charczuk 2016-07-07 20:26:07 -07:00
parent 5c8836f9bd
commit 4bbc7978a2
7 changed files with 178 additions and 31 deletions

View file

@ -3,13 +3,16 @@ package chart
import (
"fmt"
"math"
"github.com/blendlabs/go-util"
)
// Range represents a continuous range,
type Range struct {
Min float64
Max float64
Domain int
Min float64
Max float64
Domain int
Formatter Formatter
}
// IsZero returns if the range has been set or not.
@ -27,6 +30,14 @@ func (r Range) String() string {
return fmt.Sprintf("Range [%.2f,%.2f] => %d", r.Min, r.Max, r.Domain)
}
// Format formats the value based on the range's formatter.
func (r Range) Format(v interface{}) string {
if r.Formatter != nil {
return r.Formatter(v)
}
return util.StringEmpty
}
// Translate maps a given value into the range space.
// An example would be a 600 px image, with a min of 10 and a max of 100.
// Translate(50) would yield (50.0/90.0)*600 ~= 333.33