Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions asciigraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type config struct {
LowerBound, UpperBound *float64
Offset int
Caption string
Precision uint
Precision *uint
CaptionColor AnsiColor
AxisColor AnsiColor
LabelColor AnsiColor
Expand Down Expand Up @@ -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.
Expand Down
Loading