diff --git a/axis.go b/axis.go index 6f9452b..48f92a3 100644 --- a/axis.go +++ b/axis.go @@ -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 +} diff --git a/charts.go b/charts.go index e7bda2e..0ed8ec4 100644 --- a/charts.go +++ b/charts.go @@ -58,6 +58,7 @@ type ( Title Title Legend Legend TickPosition chart.TickPosition + Log chart.Logger } ) @@ -142,16 +143,20 @@ func New(opt Options) (Graph, error) { } } - var yAxisOption *YAxisOption - if len(opt.YAxisOptions) != 0 { - yAxisOption = opt.YAxisOptions[0] - } var secondaryYAxisOption *YAxisOption + if len(opt.YAxisOptions) != 0 { + secondaryYAxisOption = opt.YAxisOptions[0] + } + + yAxisOption := &YAxisOption{ + Disabled: true, + } if len(opt.YAxisOptions) > 1 { - secondaryYAxisOption = opt.YAxisOptions[1] + yAxisOption = opt.YAxisOptions[1] } g := &chart.Chart{ + Log: opt.Log, ColorPalette: &ThemeColorPalette{ Theme: opt.Theme, }, diff --git a/echarts.go b/echarts.go index 6361837..0db130c 100644 --- a/echarts.go +++ b/echarts.go @@ -154,14 +154,10 @@ func convertEChartsSeries(e *ECharsOptions) ([]Series, chart.TickPosition) { } data[j] = sd } - yAxisType := chart.YAxisPrimary - if item.YAxisIndex != 0 { - yAxisType = chart.YAxisSecondary - } series[index] = Series{ - YAxis: yAxisType, - Data: data, - Type: item.Type, + YAxisIndex: item.YAxisIndex, + Data: data, + Type: item.Type, } } return series, tickPosition diff --git a/examples/main.go b/examples/main.go index 3d3d5d8..49d797f 100644 --- a/examples/main.go +++ b/examples/main.go @@ -288,9 +288,6 @@ var chartOptions = []map[string]string{ func render(theme string) ([]byte, error) { data := bytes.Buffer{} for _, m := range chartOptions { - if m["title"] != "折柱混合" { - continue - } chartHTML := []byte(`

{{title}}

{{option}}
diff --git a/range.go b/range.go index b062e51..f1869da 100644 --- a/range.go +++ b/range.go @@ -50,3 +50,11 @@ func (r Range) Translate(value float64) int { } return v } + +type HiddenRange struct { + chart.ContinuousRange +} + +func (r HiddenRange) GetDelta() float64 { + return 0 +} diff --git a/series.go b/series.go index 867051b..67d8c4d 100644 --- a/series.go +++ b/series.go @@ -32,11 +32,11 @@ type SeriesData struct { } type Series struct { - Type string - Name string - Data []SeriesData - XValues []float64 - YAxis chart.YAxisType + Type string + Name string + Data []SeriesData + XValues []float64 + YAxisIndex int } const lineStrokeWidth = 2 @@ -103,7 +103,10 @@ func GetSeries(series []Series, tickPosition chart.TickPosition, theme string) [ Style: style, YValues: yValues, TickPosition: tickPosition, - YAxis: item.YAxis, + YAxis: chart.YAxisSecondary, + } + if item.YAxisIndex != 0 { + baseSeries.YAxis = chart.YAxisPrimary } // TODO 判断类型 switch item.Type {