Skip to content

Commit 8113423

Browse files
committed
Updated tests
1 parent 2cf1c79 commit 8113423

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

chartjs-java-model/src/test/java/software/xdev/chartjs/model/BarChartTest.java

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ void testStacked()
9090
.addDataset(dataset1)
9191
.addDataset(dataset2);
9292

93-
final BarOptions options = new BarOptions();
94-
options.setAnimation(false);
93+
final BarOptions options = new BarOptions()
94+
.setAnimation(false);
9595
options
9696
.getScales()
9797
.addScale(Scales.ScaleAxis.X, new BarScale<>().setStacked(true))
@@ -120,8 +120,8 @@ void testTicked()
120120
.setMax(100)
121121
.setStepSize(5);
122122

123-
final BarOptions options = new BarOptions();
124-
options.setAnimation(false);
123+
final BarOptions options = new BarOptions()
124+
.setAnimation(false);
125125
options
126126
.getScales()
127127
.addScale(Scales.ScaleAxis.Y, new BarScale<LinearTicks>().setTicks(ticks));
@@ -150,9 +150,9 @@ void testStackedHorizontal()
150150
.addDataset(dataset1)
151151
.addDataset(dataset2);
152152

153-
final BarOptions options = new BarOptions();
154-
options.setAnimation(false);
155-
options.setIndexAxis(BarOptions.IndexAxis.Y);
153+
final BarOptions options = new BarOptions()
154+
.setAnimation(false)
155+
.setIndexAxis(BarOptions.IndexAxis.Y);
156156
options
157157
.getScales()
158158
.addScale(Scales.ScaleAxis.X, new BarScale<>().setStacked(true))
@@ -164,4 +164,47 @@ void testStackedHorizontal()
164164
"StackedHorizontal"
165165
);
166166
}
167+
168+
@Test
169+
void testStackedWithGroups()
170+
{
171+
// This test orients itself on https://www.chartjs.org/docs/4.4.0/samples/bar/stacked-groups.html
172+
final BarDataset dataset1 = new BarDataset()
173+
.setLabel("First stack")
174+
.setData(65, 59, 80)
175+
.addBackgroundColors(Color.RED, Color.RED, Color.RED)
176+
.setStack("Stack 1");
177+
178+
final BarDataset dataset2 = new BarDataset()
179+
.setLabel("Second stack")
180+
.setData(28, 45, 10)
181+
.addBackgroundColors(Color.GREEN, Color.GREEN, Color.GREEN)
182+
.setStack("Stack 1");
183+
184+
final BarDataset dataset3 = new BarDataset()
185+
.setLabel("Third stack")
186+
.setData(10, 23, 45)
187+
.addBackgroundColors(Color.BLUE, Color.BLUE, Color.BLUE)
188+
.setStack("Stack 2");
189+
190+
final BarData data = new BarData()
191+
.addLabels("First", "Second", "Third")
192+
.addDataset(dataset1)
193+
.addDataset(dataset2)
194+
.addDataset(dataset3);
195+
196+
final BarOptions options = new BarOptions()
197+
.setAnimation(false)
198+
.setIndexAxis(BarOptions.IndexAxis.Y);
199+
options
200+
.getScales()
201+
.addScale(Scales.ScaleAxis.X, new BarScale<>().setStacked(true))
202+
.addScale(Scales.ScaleAxis.Y, new BarScale<>().setStacked(true));
203+
204+
this.createScreenshotAndCompare(
205+
new BarChart(data, options),
206+
this.getWebContainer(),
207+
"StackedWithGroups"
208+
);
209+
}
167210
}
18.2 KB
Loading

0 commit comments

Comments
 (0)