add graph_view

This commit is contained in:
2026-01-26 16:12:38 +01:00
parent 78e27ac8d0
commit 8e612037d0
9 changed files with 573 additions and 1 deletions

View File

@@ -0,0 +1,62 @@
class ChartDataPoint {
final int stopNumber;
final double litersPerStop;
final double pricePerStop;
final double pricePerLiter;
ChartDataPoint({
required this.stopNumber,
required this.litersPerStop,
required this.pricePerStop,
required this.pricePerLiter,
});
}
class ChartData {
final List<ChartDataPoint> dataPoints;
ChartData({required this.dataPoints});
factory ChartData.fromTankList(List<dynamic> tankList) {
List<ChartDataPoint> points = [];
for (int i = 0; i < tankList.length; i++) {
final tank = tankList[i];
final liters = double.tryParse(tank.szLiters) ?? 0.0;
final priceTotal = double.tryParse(tank.szPriceTotal) ?? 0.0;
final pricePerLiter = double.tryParse(tank.szPricePerLiter) ?? 0.0;
points.add(
ChartDataPoint(
stopNumber: i + 1,
litersPerStop: liters,
pricePerStop: priceTotal,
pricePerLiter: pricePerLiter,
),
);
}
return ChartData(dataPoints: points);
}
double getMaxLiters() {
if (dataPoints.isEmpty) return 0;
return dataPoints
.map((p) => p.litersPerStop)
.reduce((a, b) => a > b ? a : b);
}
double getMaxPrice() {
if (dataPoints.isEmpty) return 0;
return dataPoints
.map((p) => p.pricePerStop)
.reduce((a, b) => a > b ? a : b);
}
double getMaxPricePerLiter() {
if (dataPoints.isEmpty) return 0;
return dataPoints
.map((p) => p.pricePerLiter)
.reduce((a, b) => a > b ? a : b);
}
}