Skip to content

Commit

Permalink
apply mini to bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Jan 29, 2024
1 parent a6f8317 commit 5ae296f
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions pkg/bar_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,9 @@ func (c *BarChart) GetStacked(xData []string, yData [][]float64, zData [][]float
}
series = append(series, s)
}

titleSizes := GetTitleSizes(req)
opt := charts.ChartOption{
Title: charts.TitleOption{
Text: req.ChartTitle,
Subtext: req.ChartSubtitle,
SubtextFontSize: DEFAULT_SUBTITLE_FONT_SIZE,
SubtextFontColor: DEFAULT_SUBTITLE_COLOR,
Left: charts.PositionCenter,
},
Title: titleSizes,
XAxis: charts.NewXAxisOption(xData),
Legend: charts.NewLegendOption(names),
YAxisOptions: []charts.YAxisOption{
Expand Down Expand Up @@ -163,22 +157,33 @@ func (c *BarChart) GetStacked(xData []string, yData [][]float64, zData [][]float
}

func (c *BarChart) GetHorizontal(xData []string, yData [][]float64, names []string, req *ChartRequest) ([]byte, error) {
isMini := IsMiniChart(req)
showLegend := true
paddings := GetPaddings(req)
titleSizes := GetTitleSizes(req)
if isMini {
showLegend = false
}
p, err := charts.HorizontalBarRender(
yData,
charts.TitleOptionFunc(charts.TitleOption{
Text: req.ChartTitle,
Subtext: req.ChartSubtitle,
SubtextFontSize: DEFAULT_SUBTITLE_FONT_SIZE,
SubtextFontColor: DEFAULT_SUBTITLE_COLOR,
Left: charts.PositionCenter,
}),
charts.TitleOptionFunc(titleSizes),
charts.HeightOptionFunc(req.Height),
charts.WidthOptionFunc(req.Width),
charts.PaddingOptionFunc(paddings),
charts.YAxisDataOptionFunc(xData),
charts.LegendOptionFunc(charts.LegendOption{
Orient: charts.OrientHorizontal,
Data: names,
Left: charts.PositionLeft,
Show: &showLegend,
}),
func(opt *charts.ChartOption) {
opt.Theme = req.Theme
opt.Type = req.Output
opt.ValueFormatter = func(f float64) string {
if isMini {
return "-"
}
return fmt.Sprintf("%s %s", NumberToK(&f), req.Metric)
}
},
Expand Down

0 comments on commit 5ae296f

Please sign in to comment.