From f96f7ef17993f1989c0da26b8be0cfcb465d7691 Mon Sep 17 00:00:00 2001 From: Mike Jensen Date: Wed, 22 Jan 2025 19:15:14 -0700 Subject: [PATCH] Add tests for double Y-Axis for line and bar charts and fix axis color bug In addition this fixes a bug where the strike line is set as the strike color for an axis. --- bar_chart_test.go | 15 +++++++++++++++ line_chart_test.go | 15 +++++++++++++++ theme.go | 1 - theme_test.go | 3 +-- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/bar_chart_test.go b/bar_chart_test.go index 9b59435..10b876c 100644 --- a/bar_chart_test.go +++ b/bar_chart_test.go @@ -216,6 +216,21 @@ func TestBarChart(t *testing.T) { }, result: "", }, + { + name: "double_yaxis", + defaultTheme: true, + makeOptions: func() BarChartOption { + opt := makeBasicBarChartOption() + opt.Theme = GetTheme(ThemeLight) + opt.Title.Text = "T" + opt.SeriesList[1].YAxisIndex = 1 + opt.YAxis = append(opt.YAxis, opt.YAxis[0]) + opt.YAxis[0].AxisColor = opt.Theme.GetSeriesColor(0) + opt.YAxis[1].AxisColor = opt.Theme.GetSeriesColor(1) + return opt + }, + result: "T189168147126105846342210180160140120100806040200JanFebMarAprMayJunAugSepOctNovDec24.9723.225.676.7135.6162.232.6206.43.32.65.9926.428.770.7175.6182.248.718.862.3", + }, } for i, tt := range tests { diff --git a/line_chart_test.go b/line_chart_test.go index 70f304a..a5ae7e4 100644 --- a/line_chart_test.go +++ b/line_chart_test.go @@ -326,6 +326,21 @@ func TestLineChart(t *testing.T) { }, result: "1.5k1k5000", }, + { + name: "double_yaxis", + defaultTheme: true, + makeOptions: func() LineChartOption { + opt := makeBasicLineChartOption() + opt.Theme = GetTheme(ThemeLight) + opt.Title.Text = "T" + opt.SeriesList[1].YAxisIndex = 1 + opt.YAxis = append(opt.YAxis, opt.YAxis[0]) + opt.YAxis[0].AxisColor = opt.Theme.GetSeriesColor(0) + opt.YAxis[1].AxisColor = opt.Theme.GetSeriesColor(1) + return opt + }, + result: "12T1.43k1.36k1.29k1.22k1.15k1.08k1.01k94087080023421820218617015413812210690ABCDEFG", + }, { name: "zero_data", defaultTheme: true, diff --git a/theme.go b/theme.go index 0e641a9..5135184 100644 --- a/theme.go +++ b/theme.go @@ -336,7 +336,6 @@ func (t *themeColorPalette) WithAxisColor(c Color) ColorPalette { copy := *t copy.name += "-axis_mod" copy.axisStrokeColor = c - copy.axisSplitLineColor = c copy.textColor = c return © } diff --git a/theme_test.go b/theme_test.go index f0a4b76..2de35fe 100644 --- a/theme_test.go +++ b/theme_test.go @@ -174,13 +174,12 @@ func TestWithAxisColor(t *testing.T) { blackCP := whiteCP.WithAxisColor(drawing.ColorBlack) - assert.Equal(t, drawing.ColorWhite, whiteCP.axisSplitLineColor) assert.Equal(t, drawing.ColorWhite, whiteCP.axisStrokeColor) assert.Equal(t, drawing.ColorWhite, whiteCP.backgroundColor) assert.Equal(t, drawing.ColorWhite, whiteCP.textColor) assert.Equal(t, drawing.ColorWhite, whiteCP.seriesColors[0]) - assert.Equal(t, drawing.ColorBlack, blackCP.GetAxisSplitLineColor()) + assert.NotEqual(t, drawing.ColorBlack, blackCP.GetAxisSplitLineColor()) assert.Equal(t, drawing.ColorBlack, blackCP.GetAxisStrokeColor()) assert.Equal(t, drawing.ColorBlack, blackCP.GetTextColor()) assert.Equal(t, drawing.ColorWhite, blackCP.GetBackgroundColor())