feat: support multi y axis

This commit is contained in:
vicanso 2021-12-18 09:49:44 +08:00
parent ead48fef8e
commit 23e2eca0c6
6 changed files with 62 additions and 61 deletions

72
axis.go
View file

@ -42,6 +42,7 @@ type (
type YAxisOption struct {
Formater chart.ValueFormatter
Disabled bool
}
const axisStrokeWidth = 1
@ -111,46 +112,6 @@ func defaultFloatFormater(v interface{}) string {
}
func GetSecondaryYAxis(theme string, option *YAxisOption) chart.YAxis {
// TODO
if theme == ThemeDark {
return chart.YAxis{}
}
// strokeColor := drawing.Color{
// R: 224,
// G: 230,
// B: 241,
// A: 255,
// }
formater := defaultFloatFormater
if option != nil {
if option.Formater != nil {
formater = option.Formater
}
}
hidden := chart.Hidden()
return chart.YAxis{
ValueFormatter: formater,
AxisType: chart.YAxisPrimary,
GridMajorStyle: hidden,
GridMinorStyle: hidden,
Style: chart.Style{
FontColor: getAxisColor(theme),
// alpha 0隐藏
StrokeColor: hiddenColor,
StrokeWidth: axisStrokeWidth,
},
}
// c := chart.Hidden()
// return chart.YAxis{
// ValueFormatter: defaultFloatFormater,
// AxisType: chart.YAxisPrimary,
// GridMajorStyle: c,
// GridMinorStyle: c,
// Style: c,
// }
}
func GetYAxis(theme string, option *YAxisOption) chart.YAxis {
strokeColor := getGridColor(theme)
formater := defaultFloatFormater
if option != nil {
@ -177,3 +138,34 @@ func GetYAxis(theme string, option *YAxisOption) chart.YAxis {
},
}
}
func GetYAxis(theme string, option *YAxisOption) chart.YAxis {
// strokeColor := getGridColor(theme)
formater := defaultFloatFormater
disabled := false
if option != nil {
if option.Formater != nil {
formater = option.Formater
}
disabled = option.Disabled
}
hidden := chart.Hidden()
yAxis := chart.YAxis{
ValueFormatter: formater,
AxisType: chart.YAxisPrimary,
GridMajorStyle: hidden,
GridMinorStyle: hidden,
Style: chart.Style{
FontColor: getAxisColor(theme),
// alpha 0隐藏
StrokeColor: hiddenColor,
StrokeWidth: axisStrokeWidth,
},
}
if disabled {
yAxis.Range = &HiddenRange{}
yAxis.Style.Hidden = true
}
return yAxis
}