Showing
3 changed files
with
29 additions
and
3 deletions
@@ -25,12 +25,14 @@ class BarDataSet extends Dataset { | @@ -25,12 +25,14 @@ class BarDataSet extends Dataset { | ||
25 | this.borderColor, | 25 | this.borderColor, |
26 | this.borderWidth = 1.5, | 26 | this.borderWidth = 1.5, |
27 | PdfColor color = PdfColors.blue, | 27 | PdfColor color = PdfColors.blue, |
28 | - this.drawBorder = true, | 28 | + bool drawBorder, |
29 | this.drawSurface = true, | 29 | this.drawSurface = true, |
30 | this.surfaceOpacity = 1, | 30 | this.surfaceOpacity = 1, |
31 | this.width = 10, | 31 | this.width = 10, |
32 | this.offset = 0, | 32 | this.offset = 0, |
33 | - }) : assert(drawBorder || drawSurface), | 33 | + }) : drawBorder = drawBorder ?? borderColor != null && color != borderColor, |
34 | + assert((drawBorder ?? borderColor != null && color != borderColor) || | ||
35 | + drawSurface), | ||
34 | super( | 36 | super( |
35 | legend: legend, | 37 | legend: legend, |
36 | color: color, | 38 | color: color, |
@@ -53,7 +55,7 @@ class BarDataSet extends Dataset { | @@ -53,7 +55,7 @@ class BarDataSet extends Dataset { | ||
53 | final double y = (grid is CartesianGrid) ? grid.xAxisOffset : 0; | 55 | final double y = (grid is CartesianGrid) ? grid.xAxisOffset : 0; |
54 | final PdfPoint p = grid.toChart(value.point); | 56 | final PdfPoint p = grid.toChart(value.point); |
55 | 57 | ||
56 | - context.canvas.drawRect(p.x + offset - width / 2, y, width, p.y); | 58 | + context.canvas.drawRect(p.x + offset - width / 2, y, width, p.y - y); |
57 | } | 59 | } |
58 | 60 | ||
59 | @override | 61 | @override |
@@ -170,6 +170,29 @@ void main() { | @@ -170,6 +170,29 @@ void main() { | ||
170 | }); | 170 | }); |
171 | }); | 171 | }); |
172 | 172 | ||
173 | + group('BarChart test', () { | ||
174 | + test('Default BarChart', () { | ||
175 | + pdf.addPage(Page( | ||
176 | + pageFormat: PdfPageFormat.standard.landscape, | ||
177 | + build: (Context context) => Chart( | ||
178 | + grid: CartesianGrid( | ||
179 | + xAxis: FixedAxis<int>(<int>[0, 1, 2, 3, 4, 5, 6]), | ||
180 | + yAxis: FixedAxis<int>(<int>[0, 3, 6, 9], divisions: true), | ||
181 | + ), | ||
182 | + datasets: <Dataset>[ | ||
183 | + BarDataSet( | ||
184 | + data: const <LineChartValue>[ | ||
185 | + LineChartValue(1, 1), | ||
186 | + LineChartValue(2, 3), | ||
187 | + LineChartValue(3, 7), | ||
188 | + ], | ||
189 | + ), | ||
190 | + ], | ||
191 | + ), | ||
192 | + )); | ||
193 | + }); | ||
194 | + }); | ||
195 | + | ||
173 | tearDownAll(() { | 196 | tearDownAll(() { |
174 | final File file = File('widgets-chart.pdf'); | 197 | final File file = File('widgets-chart.pdf'); |
175 | file.writeAsBytesSync(pdf.save()); | 198 | file.writeAsBytesSync(pdf.save()); |
-
Please register or login to post a comment