mirror of
https://github.com/gizak/termui.git
synced 2025-04-30 13:49:00 +08:00
Merge 28667e1f55d695754a68c1f179e972fa153fe09e into 2b8f0c7960e9553acea6d579a740713066da5e13
This commit is contained in:
commit
fc9279f2ac
@ -31,6 +31,8 @@ type Plot struct {
|
|||||||
PlotType PlotType
|
PlotType PlotType
|
||||||
HorizontalScale int
|
HorizontalScale int
|
||||||
DrawDirection DrawDirection // TODO
|
DrawDirection DrawDirection // TODO
|
||||||
|
YAxisFmter func(v float64) string
|
||||||
|
XAxisFmter func(v int) string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -176,10 +178,12 @@ func (self *Plot) plotAxes(buf *Buffer, maxVal float64) {
|
|||||||
)
|
)
|
||||||
// draw rest
|
// draw rest
|
||||||
for x := self.Inner.Min.X + yAxisLabelsWidth + (xAxisLabelsGap)*self.HorizontalScale + 1; x < self.Inner.Max.X-1; {
|
for x := self.Inner.Min.X + yAxisLabelsWidth + (xAxisLabelsGap)*self.HorizontalScale + 1; x < self.Inner.Max.X-1; {
|
||||||
label := fmt.Sprintf(
|
val := (x-(self.Inner.Min.X+yAxisLabelsWidth)-1)/(self.HorizontalScale) + 1
|
||||||
"%d",
|
label := fmt.Sprintf("%d", val)
|
||||||
(x-(self.Inner.Min.X+yAxisLabelsWidth)-1)/(self.HorizontalScale)+1,
|
if self.XAxisFmter != nil {
|
||||||
)
|
label = self.XAxisFmter(val)
|
||||||
|
}
|
||||||
|
|
||||||
buf.SetString(
|
buf.SetString(
|
||||||
label,
|
label,
|
||||||
NewStyle(ColorWhite),
|
NewStyle(ColorWhite),
|
||||||
@ -190,8 +194,13 @@ func (self *Plot) plotAxes(buf *Buffer, maxVal float64) {
|
|||||||
// draw y axis labels
|
// draw y axis labels
|
||||||
verticalScale := maxVal / float64(self.Inner.Dy()-xAxisLabelsHeight-1)
|
verticalScale := maxVal / float64(self.Inner.Dy()-xAxisLabelsHeight-1)
|
||||||
for i := 0; i*(yAxisLabelsGap+1) < self.Inner.Dy()-1; i++ {
|
for i := 0; i*(yAxisLabelsGap+1) < self.Inner.Dy()-1; i++ {
|
||||||
|
val := float64(i) * verticalScale * (yAxisLabelsGap + 1)
|
||||||
|
label := fmt.Sprintf("%.2f", val)
|
||||||
|
if self.YAxisFmter != nil {
|
||||||
|
label = self.YAxisFmter(val)
|
||||||
|
}
|
||||||
buf.SetString(
|
buf.SetString(
|
||||||
fmt.Sprintf("%.2f", float64(i)*verticalScale*(yAxisLabelsGap+1)),
|
label,
|
||||||
NewStyle(ColorWhite),
|
NewStyle(ColorWhite),
|
||||||
image.Pt(self.Inner.Min.X, self.Inner.Max.Y-(i*(yAxisLabelsGap+1))-2),
|
image.Pt(self.Inner.Min.X, self.Inner.Max.Y-(i*(yAxisLabelsGap+1))-2),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user