Constrain asciigraph dependency to revision

Turns out if you don't constrain a dependency to a revision, it picks the latest version (which I'm guessing corresponds to a git tag)
This means if you're using a fork for the sake of an extra commit that you want, you need to point at that revision (or perhaps just specify branch="master")
Otherwise we'll end up pointing at an older commit
pull/1/head
Jesse Duffield 5 years ago
parent ccca53914d
commit ad9b62e95e

5
Gopkg.lock generated

@ -58,12 +58,11 @@
revision = "9fd32a8b3d3d3f9d43c341bfe098430e07609480"
[[projects]]
digest = "1:a3b08eb3ec49caec29db596d8f2aae79614413a8d2068d5082b92fa23b5b6d80"
digest = "1:8abef4b9ca2f94e008688685bf8fb7bb27e5c82b353a82ef9276a27b4a6d2020"
name = "github.com/carlosms/asciigraph"
packages = ["."]
pruneopts = "NUT"
revision = "b8c6bd8cace5d89062a57acb2012b0be08fb9525"
version = "v0.4.1"
revision = "22e3e1b9e3cd5ab4f79619cd65987f426d2d3dc4"
[[projects]]
branch = "master"

@ -41,6 +41,6 @@
branch = "master"
name = "github.com/spkg/bom"
# [[constraint]]
# name = "github.com/docker/docker"
# version = "v17"
[[constraint]]
name = "github.com/carlosms/asciigraph"
revision = "22e3e1b9e3cd5ab4f79619cd65987f426d2d3dc4"

@ -9,6 +9,7 @@ import (
// Plot returns ascii graph for a series.
func Plot(series []float64, options ...Option) string {
var logMaximum float64
config := configure(config{
Offset: 3,
}, options)
@ -18,6 +19,13 @@ func Plot(series []float64, options ...Option) string {
}
minimum, maximum := minMaxFloat64Slice(series)
if config.Min != nil && *config.Min < minimum {
minimum = *config.Min
}
if config.Max != nil && *config.Max > maximum {
maximum = *config.Max
}
interval := math.Abs(maximum - minimum)
if config.Height <= 0 {
@ -32,7 +40,12 @@ func Plot(series []float64, options ...Option) string {
config.Offset = 3
}
ratio := float64(config.Height) / interval
var ratio float64
if interval != 0 {
ratio = float64(config.Height) / interval
} else {
ratio = 1
}
min2 := round(minimum * ratio)
max2 := round(maximum * ratio)
@ -54,7 +67,10 @@ func Plot(series []float64, options ...Option) string {
}
precision := 2
logMaximum := math.Log10(math.Max(math.Abs(maximum), math.Abs(minimum))) //to find number of zeros after decimal
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)
}
if logMaximum < 0 {
// negative log
@ -74,7 +90,14 @@ func Plot(series []float64, options ...Option) string {
// axis and labels
for y := intmin2; y < intmax2+1; y++ {
label := fmt.Sprintf("%*.*f", maxWidth+1, precision, maximum-(float64(y-intmin2)*interval/float64(rows)))
var magnitude float64
if rows > 0 {
magnitude = maximum - (float64(y-intmin2) * interval / float64(rows))
} else {
magnitude = float64(y)
}
label := fmt.Sprintf("%*.*f", maxWidth+1, precision, magnitude)
w := y - intmin2
h := int(math.Max(float64(config.Offset)-float64(len(label)), 0))
@ -99,12 +122,9 @@ func Plot(series []float64, options ...Option) string {
} else {
if y0 > y1 {
plot[rows-y1][x+config.Offset] = "╰"
} else {
plot[rows-y1][x+config.Offset] = "╭"
}
if y0 > y1 {
plot[rows-y0][x+config.Offset] = "╮"
} else {
plot[rows-y1][x+config.Offset] = "╭"
plot[rows-y0][x+config.Offset] = "╯"
}

@ -12,6 +12,7 @@ type Option interface {
// config holds various graph options
type config struct {
Width, Height int
Min, Max *float64
Offset int
Caption string
}
@ -54,6 +55,18 @@ func Height(h int) Option {
})
}
// Min sets the graph's minimum value for the vertical axis. It will be ignored
// if the series contains a lower value.
func Min(min float64) Option {
return optionFunc(func(c *config) { c.Min = &min })
}
// Max sets the graph's maximum value for the vertical axis. It will be ignored
// if the series contains a bigger value.
func Max(max float64) Option {
return optionFunc(func(c *config) { c.Max = &max })
}
// Offset sets the graphs offset.
func Offset(o int) Option {
return optionFunc(func(c *config) { c.Offset = o })

Loading…
Cancel
Save