Skip to content

Commit

Permalink
Add tests for double Y-Axis for line and bar charts and fix axis colo…
Browse files Browse the repository at this point in the history
…r bug

In addition this fixes a bug where the strike line is set as the strike color for an axis.
  • Loading branch information
jentfoo committed Jan 23, 2025
1 parent e48c5ed commit f96f7ef
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
15 changes: 15 additions & 0 deletions bar_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ func TestBarChart(t *testing.T) {
},
result: "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 600 400\"><path d=\"M 0 0\nL 600 0\nL 600 400\nL 0 400\nL 0 0\" style=\"stroke:none;fill:white\"/><path d=\"M 85 304\nL 95 304\nL 95 349\nL 85 349\nL 85 304\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 365 225\nL 375 225\nL 375 349\nL 365 349\nL 365 225\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 225 225\nL 235 225\nL 235 349\nL 225 349\nL 225 225\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 505 67\nL 515 67\nL 515 349\nL 505 349\nL 505 67\" style=\"stroke:none;fill:rgb(145,204,117)\"/></svg>",
},
{
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: "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 600 400\"><path d=\"M 0 0\nL 600 0\nL 600 400\nL 0 400\nL 0 0\" style=\"stroke:none;fill:white\"/><text x=\"10\" y=\"25\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">T</text><text x=\"563\" y=\"47\" style=\"stroke:none;fill:rgb(145,204,117);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">189</text><text x=\"563\" y=\"82\" style=\"stroke:none;fill:rgb(145,204,117);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">168</text><text x=\"563\" y=\"118\" style=\"stroke:none;fill:rgb(145,204,117);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">147</text><text x=\"563\" y=\"153\" style=\"stroke:none;fill:rgb(145,204,117);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">126</text><text x=\"563\" y=\"189\" style=\"stroke:none;fill:rgb(145,204,117);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">105</text><text x=\"563\" y=\"224\" style=\"stroke:none;fill:rgb(145,204,117);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">84</text><text x=\"563\" y=\"260\" style=\"stroke:none;fill:rgb(145,204,117);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">63</text><text x=\"563\" y=\"295\" style=\"stroke:none;fill:rgb(145,204,117);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">42</text><text x=\"563\" y=\"331\" style=\"stroke:none;fill:rgb(145,204,117);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">21</text><text x=\"563\" y=\"367\" style=\"stroke:none;fill:rgb(145,204,117);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">0</text><text x=\"10\" y=\"47\" style=\"stroke:none;fill:rgb(84,112,198);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">180</text><text x=\"10\" y=\"82\" style=\"stroke:none;fill:rgb(84,112,198);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">160</text><text x=\"10\" y=\"118\" style=\"stroke:none;fill:rgb(84,112,198);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">140</text><text x=\"10\" y=\"153\" style=\"stroke:none;fill:rgb(84,112,198);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">120</text><text x=\"10\" y=\"189\" style=\"stroke:none;fill:rgb(84,112,198);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">100</text><text x=\"19\" y=\"224\" style=\"stroke:none;fill:rgb(84,112,198);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">80</text><text x=\"19\" y=\"260\" style=\"stroke:none;fill:rgb(84,112,198);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">60</text><text x=\"19\" y=\"295\" style=\"stroke:none;fill:rgb(84,112,198);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">40</text><text x=\"19\" y=\"331\" style=\"stroke:none;fill:rgb(84,112,198);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">20</text><text x=\"28\" y=\"367\" style=\"stroke:none;fill:rgb(84,112,198);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">0</text><path d=\"M 47 40\nL 553 40\" style=\"stroke-width:1;stroke:rgb(224,230,242);fill:none\"/><path d=\"M 47 75\nL 553 75\" style=\"stroke-width:1;stroke:rgb(224,230,242);fill:none\"/><path d=\"M 47 111\nL 553 111\" style=\"stroke-width:1;stroke:rgb(224,230,242);fill:none\"/><path d=\"M 47 146\nL 553 146\" style=\"stroke-width:1;stroke:rgb(224,230,242);fill:none\"/><path d=\"M 47 182\nL 553 182\" style=\"stroke-width:1;stroke:rgb(224,230,242);fill:none\"/><path d=\"M 47 217\nL 553 217\" style=\"stroke-width:1;stroke:rgb(224,230,242);fill:none\"/><path d=\"M 47 253\nL 553 253\" style=\"stroke-width:1;stroke:rgb(224,230,242);fill:none\"/><path d=\"M 47 288\nL 553 288\" style=\"stroke-width:1;stroke:rgb(224,230,242);fill:none\"/><path d=\"M 47 324\nL 553 324\" style=\"stroke-width:1;stroke:rgb(224,230,242);fill:none\"/><path d=\"M 47 365\nL 47 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 89 365\nL 89 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 131 365\nL 131 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 173 365\nL 173 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 215 365\nL 215 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 257 365\nL 257 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 342 365\nL 342 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 384 365\nL 384 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 426 365\nL 426 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 468 365\nL 468 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 510 365\nL 510 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 553 365\nL 553 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><path d=\"M 47 360\nL 553 360\" style=\"stroke-width:1;stroke:rgb(110,112,121);fill:none\"/><text x=\"46\" y=\"385\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Jan</text><text x=\"97\" y=\"385\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Feb</text><text x=\"138\" y=\"385\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Mar</text><text x=\"182\" y=\"385\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Apr</text><text x=\"221\" y=\"385\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">May</text><text x=\"265\" y=\"385\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Jun</text><text x=\"349\" y=\"385\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Aug</text><text x=\"392\" y=\"385\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Sep</text><text x=\"435\" y=\"385\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Oct</text><text x=\"475\" y=\"385\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Nov</text><text x=\"526\" y=\"385\" style=\"stroke:none;fill:rgb(70,70,70);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Dec</text><path d=\"M 52 357\nL 66 357\nL 66 359\nL 52 359\nL 52 357\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 94 352\nL 108 352\nL 108 359\nL 94 359\nL 94 352\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 136 348\nL 150 348\nL 150 359\nL 136 359\nL 136 348\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 178 319\nL 192 319\nL 192 359\nL 178 359\nL 178 319\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 220 315\nL 234 315\nL 234 359\nL 220 359\nL 220 315\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 262 224\nL 276 224\nL 276 359\nL 262 359\nL 262 224\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 305 119\nL 319 119\nL 319 359\nL 305 359\nL 305 119\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 347 72\nL 361 72\nL 361 359\nL 347 359\nL 347 72\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 389 303\nL 403 303\nL 403 359\nL 389 359\nL 389 303\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 431 325\nL 445 325\nL 445 359\nL 431 359\nL 431 325\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 473 349\nL 487 349\nL 487 359\nL 473 359\nL 473 349\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 515 355\nL 529 355\nL 529 359\nL 515 359\nL 515 355\" style=\"stroke:none;fill:rgb(84,112,198)\"/><path d=\"M 69 356\nL 83 356\nL 83 359\nL 69 359\nL 69 356\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 111 351\nL 125 351\nL 125 359\nL 111 359\nL 111 351\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 153 345\nL 167 345\nL 167 359\nL 153 359\nL 153 345\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 195 316\nL 209 316\nL 209 359\nL 195 359\nL 195 316\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 237 312\nL 251 312\nL 251 359\nL 237 359\nL 237 312\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 279 241\nL 293 241\nL 293 359\nL 279 359\nL 279 241\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 322 63\nL 336 63\nL 336 359\nL 322 359\nL 322 63\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 364 52\nL 378 52\nL 378 359\nL 364 359\nL 364 52\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 406 278\nL 420 278\nL 420 359\nL 406 359\nL 406 278\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 448 329\nL 462 329\nL 462 359\nL 448 359\nL 448 329\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 490 350\nL 504 350\nL 504 359\nL 490 359\nL 490 350\" style=\"stroke:none;fill:rgb(145,204,117)\"/><path d=\"M 532 357\nL 546 357\nL 546 359\nL 532 359\nL 532 357\" style=\"stroke:none;fill:rgb(145,204,117)\"/><text x=\"55\" y=\"352\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">2</text><text x=\"92\" y=\"347\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">4.9</text><text x=\"139\" y=\"343\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">7</text><text x=\"172\" y=\"314\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">23.2</text><text x=\"214\" y=\"310\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">25.6</text><text x=\"256\" y=\"219\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">76.7</text><text x=\"296\" y=\"114\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">135.6</text><text x=\"338\" y=\"67\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">162.2</text><text x=\"383\" y=\"298\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">32.6</text><text x=\"431\" y=\"320\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">20</text><text x=\"471\" y=\"344\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">6.4</text><text x=\"513\" y=\"350\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">3.3</text><text x=\"67\" y=\"351\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">2.6</text><text x=\"109\" y=\"346\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">5.9</text><text x=\"156\" y=\"340\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">9</text><text x=\"189\" y=\"311\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">26.4</text><text x=\"231\" y=\"307\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">28.7</text><text x=\"273\" y=\"236\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">70.7</text><text x=\"313\" y=\"58\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">175.6</text><text x=\"355\" y=\"47\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">182.2</text><text x=\"400\" y=\"273\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">48.7</text><text x=\"442\" y=\"324\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">18.8</text><text x=\"493\" y=\"345\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">6</text><text x=\"530\" y=\"352\" style=\"stroke:none;fill:rgb(70,70,70);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">2.3</text></svg>",
},
}

for i, tt := range tests {
Expand Down
Loading

0 comments on commit f96f7ef

Please sign in to comment.