David PHAM-VAN

Fix Bar graph offset

... ... @@ -4,6 +4,7 @@
## 1.12.0
- Add textDirection parameter to PageTheme
- Fix Bar graph offset
## 1.11.2
... ...
... ... @@ -25,12 +25,14 @@ class BarDataSet extends Dataset {
this.borderColor,
this.borderWidth = 1.5,
PdfColor color = PdfColors.blue,
this.drawBorder = true,
bool drawBorder,
this.drawSurface = true,
this.surfaceOpacity = 1,
this.width = 10,
this.offset = 0,
}) : assert(drawBorder || drawSurface),
}) : drawBorder = drawBorder ?? borderColor != null && color != borderColor,
assert((drawBorder ?? borderColor != null && color != borderColor) ||
drawSurface),
super(
legend: legend,
color: color,
... ... @@ -53,7 +55,7 @@ class BarDataSet extends Dataset {
final double y = (grid is CartesianGrid) ? grid.xAxisOffset : 0;
final PdfPoint p = grid.toChart(value.point);
context.canvas.drawRect(p.x + offset - width / 2, y, width, p.y);
context.canvas.drawRect(p.x + offset - width / 2, y, width, p.y - y);
}
@override
... ...
... ... @@ -170,6 +170,29 @@ void main() {
});
});
group('BarChart test', () {
test('Default BarChart', () {
pdf.addPage(Page(
pageFormat: PdfPageFormat.standard.landscape,
build: (Context context) => Chart(
grid: CartesianGrid(
xAxis: FixedAxis<int>(<int>[0, 1, 2, 3, 4, 5, 6]),
yAxis: FixedAxis<int>(<int>[0, 3, 6, 9], divisions: true),
),
datasets: <Dataset>[
BarDataSet(
data: const <LineChartValue>[
LineChartValue(1, 1),
LineChartValue(2, 3),
LineChartValue(3, 7),
],
),
],
),
));
});
});
tearDownAll(() {
final File file = File('widgets-chart.pdf');
file.writeAsBytesSync(pdf.save());
... ...