add graph_view
This commit is contained in:
62
lib/models/chart_model.dart
Normal file
62
lib/models/chart_model.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
0
lib/models/graph_model.dart
Normal file
0
lib/models/graph_model.dart
Normal file
Reference in New Issue
Block a user