fix runchart X axis margin edge case
This commit is contained in:
parent
bc9d77a02d
commit
a736560c71
|
@ -30,11 +30,36 @@ func (c *RunChart) newChartGrid() ChartGrid {
|
|||
valueExtrema: getLocalExtrema(c.lines, timeRange),
|
||||
linesCount: linesCount,
|
||||
maxTimeWidth: c.Inner.Max.X,
|
||||
minTimeWidth: c.getMaxValueLength(),
|
||||
minTimeWidth: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *RunChart) renderAxes(buffer *ui.Buffer) {
|
||||
|
||||
// draw y axis labels
|
||||
if c.grid.valueExtrema.max != c.grid.valueExtrema.min {
|
||||
labelsCount := (c.Inner.Dy() - xAxisLabelsHeight - 1) / (yAxisLabelsIndent + yAxisLabelsHeight)
|
||||
valuePerY := (c.grid.valueExtrema.max - c.grid.valueExtrema.min) / float64(c.Inner.Dy()-xAxisLabelsHeight-3)
|
||||
for i := 0; i < int(labelsCount); i++ {
|
||||
val := c.grid.valueExtrema.max - (valuePerY * float64(i) * (yAxisLabelsIndent + yAxisLabelsHeight))
|
||||
fmt := util.FormatValue(val, c.scale)
|
||||
if len(fmt) > c.grid.minTimeWidth {
|
||||
c.grid.minTimeWidth = len(fmt)
|
||||
}
|
||||
buffer.SetString(
|
||||
fmt,
|
||||
ui.NewStyle(c.palette.BaseColor),
|
||||
image.Pt(c.Inner.Min.X, 1+c.Inner.Min.Y+i*(yAxisLabelsIndent+yAxisLabelsHeight)))
|
||||
}
|
||||
} else {
|
||||
fmt := util.FormatValue(c.grid.valueExtrema.max, c.scale)
|
||||
c.grid.minTimeWidth = len(fmt)
|
||||
buffer.SetString(
|
||||
fmt,
|
||||
ui.NewStyle(c.palette.BaseColor),
|
||||
image.Pt(c.Inner.Min.X, c.Inner.Min.Y+c.Inner.Dy()/2))
|
||||
}
|
||||
|
||||
// draw origin cell
|
||||
buffer.SetCell(
|
||||
ui.NewCell(ui.BOTTOM_LEFT, ui.NewStyle(c.palette.BaseColor)),
|
||||
|
@ -71,24 +96,6 @@ func (c *RunChart) renderAxes(buffer *ui.Buffer) {
|
|||
ui.NewStyle(c.palette.BaseColor),
|
||||
image.Pt(c.grid.maxTimeWidth-xAxisLabelsWidth/2-i*(xAxisGridWidth), c.Inner.Max.Y-1))
|
||||
}
|
||||
|
||||
// draw y axis labels
|
||||
if c.grid.valueExtrema.max != c.grid.valueExtrema.min {
|
||||
labelsCount := (c.Inner.Dy() - xAxisLabelsHeight - 1) / (yAxisLabelsIndent + yAxisLabelsHeight)
|
||||
valuePerY := (c.grid.valueExtrema.max - c.grid.valueExtrema.min) / float64(c.Inner.Dy()-xAxisLabelsHeight-3)
|
||||
for i := 0; i < int(labelsCount); i++ {
|
||||
value := c.grid.valueExtrema.max - (valuePerY * float64(i) * (yAxisLabelsIndent + yAxisLabelsHeight))
|
||||
buffer.SetString(
|
||||
util.FormatValue(value, c.scale),
|
||||
ui.NewStyle(c.palette.BaseColor),
|
||||
image.Pt(c.Inner.Min.X, 1+c.Inner.Min.Y+i*(yAxisLabelsIndent+yAxisLabelsHeight)))
|
||||
}
|
||||
} else {
|
||||
buffer.SetString(
|
||||
util.FormatValue(c.grid.valueExtrema.max, c.scale),
|
||||
ui.NewStyle(c.palette.BaseColor),
|
||||
image.Pt(c.Inner.Min.X, c.Inner.Min.Y+c.Inner.Dy()/2))
|
||||
}
|
||||
}
|
||||
|
||||
func (c *RunChart) getTimeRange(linesCount int) TimeRange {
|
||||
|
@ -139,23 +146,22 @@ func (r *TimeRange) isInRange(time time.Time) bool {
|
|||
return time.After(r.min) && time.Before(r.max)
|
||||
}
|
||||
|
||||
// TODO add boundaries for values in range
|
||||
func (c *RunChart) getMaxValueLength() int {
|
||||
|
||||
maxValueLength := -1
|
||||
|
||||
for _, line := range c.lines {
|
||||
for _, point := range line.points {
|
||||
l := len(util.FormatValue(point.value, c.scale))
|
||||
if l > maxValueLength {
|
||||
maxValueLength = l
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if maxValueLength < 0 {
|
||||
return DefaultValueLength
|
||||
}
|
||||
|
||||
return maxValueLength
|
||||
}
|
||||
//func (c *RunChart) getMaxValueLength() int {
|
||||
//
|
||||
// maxValueLength := -1
|
||||
//
|
||||
// for _, line := range c.lines {
|
||||
// for _, point := range line.points {
|
||||
// l := len(util.FormatValue(point.value, c.scale))
|
||||
// if l > maxValueLength {
|
||||
// maxValueLength = l
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if maxValueLength < 0 {
|
||||
// return DefaultValueLength
|
||||
// }
|
||||
//
|
||||
// return maxValueLength
|
||||
//}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package config
|
||||
|
||||
type Options struct {
|
||||
ConfigFile *string `short:"c" long:"config" required:"true" description:"Path to YAML config file"`
|
||||
ConfigFile *string `short:"c" long:"config" description:"Path to YAML config file"`
|
||||
LicenseKey *string `short:"l" long:"license" description:"License key. Visit www.sampler.dev for details"`
|
||||
Environment []string `short:"e" long:"env" description:"Specify name=value variable to use in script placeholder as $name. This flag takes precedence over the same name variables, specified in config yml"`
|
||||
Version bool `short:"v" long:"version" description:"Print version"`
|
||||
|
|
Loading…
Reference in New Issue