diff --git a/asciigraph.go b/asciigraph.go index 608eb6a..d018ed1 100644 --- a/asciigraph.go +++ b/asciigraph.go @@ -17,7 +17,7 @@ func PlotMany(data [][]float64, options ...Option) string { var logMaximum float64 config := configure(config{ Offset: 3, - Precision: 2, + Precision: nil, }, options) // Create a deep copy of the input data @@ -103,7 +103,11 @@ func PlotMany(data [][]float64, options ...Option) string { plot[i] = line } - precision := config.Precision + var precision uint = 2 //Default precision to maintain backwards compatibility + if config.Precision != nil { + precision = *config.Precision + } + logMaximum = math.Log10(math.Max(math.Abs(maximum), math.Abs(minimum))) //to find number of zeros after decimal if minimum == float64(0) && maximum == float64(0) { logMaximum = float64(-1) @@ -117,7 +121,7 @@ func PlotMany(data [][]float64, options ...Option) string { } else { precision += uint(math.Abs(logMaximum) - 1.0) } - } else if logMaximum > 2 { + } else if logMaximum > 2 && config.Precision == nil { precision = 0 } diff --git a/options.go b/options.go index 17dd4d0..ae49ef1 100644 --- a/options.go +++ b/options.go @@ -15,7 +15,7 @@ type config struct { LowerBound, UpperBound *float64 Offset int Caption string - Precision uint + Precision *uint CaptionColor AnsiColor AxisColor AnsiColor LabelColor AnsiColor @@ -80,7 +80,7 @@ func Offset(o int) Option { // Precision sets the graphs precision. func Precision(p uint) Option { - return optionFunc(func(c *config) { c.Precision = p }) + return optionFunc(func(c *config) { c.Precision = &p }) } // Caption sets the graphs caption.