improved graph appearance to be more clear
This commit is contained in:
@@ -12,10 +12,6 @@ class ReadingGraph extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_readings.isEmpty) {
|
||||
return Text('No readings on record.');
|
||||
}
|
||||
|
||||
final spots = _readings
|
||||
.map<FlSpot>(
|
||||
(e) => FlSpot(
|
||||
@@ -46,6 +42,7 @@ class ReadingGraph extends StatelessWidget {
|
||||
],
|
||||
titlesData: FlTitlesData(
|
||||
bottomTitles: getBottomTitles(spots),
|
||||
leftTitles: getLeftTitles(spots),
|
||||
topTitles: const AxisTitles(sideTitles: SideTitles()),
|
||||
rightTitles: const AxisTitles(sideTitles: SideTitles()),
|
||||
),
|
||||
@@ -54,28 +51,31 @@ class ReadingGraph extends StatelessWidget {
|
||||
}
|
||||
|
||||
AxisTitles getBottomTitles(List<FlSpot> spots) {
|
||||
final maxX = double.parse(
|
||||
spots.map<double>((e) => (e.x)).reduce(max).toStringAsFixed(0));
|
||||
final minX = double.parse(
|
||||
spots.map<double>((e) => e.x).reduce(min).toStringAsFixed(0));
|
||||
final middle =
|
||||
double.parse(spots[spots.length ~/ 2].x.toStringAsFixed(0)) + 4;
|
||||
|
||||
return AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
interval: 1,
|
||||
interval: 90,
|
||||
reservedSize: 40,
|
||||
showTitles: true,
|
||||
getTitlesWidget: (value, meta) {
|
||||
String text = '';
|
||||
if (value == maxX) {
|
||||
text = getDate(spots.first.x);
|
||||
} else if (double.parse(value.toStringAsFixed(0)) == minX) {
|
||||
text = getDate(spots.last.x);
|
||||
} else if (value == middle) {
|
||||
text = getDate(middle);
|
||||
maxIncluded: false,
|
||||
getTitlesWidget: (value, meta) => SideTitleWidget(
|
||||
meta: meta,
|
||||
child: Text(getDate(value)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Text(text);
|
||||
},
|
||||
|
||||
AxisTitles getLeftTitles(List<FlSpot> spots) {
|
||||
return AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
reservedSize: 50,
|
||||
showTitles: true,
|
||||
maxIncluded: false,
|
||||
minIncluded: false,
|
||||
getTitlesWidget: (value, meta) => SideTitleWidget(
|
||||
meta: meta,
|
||||
child: Text(value.toStringAsFixed(2)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,19 +19,17 @@ class FloodStationPage extends StatelessWidget {
|
||||
future: Api.fetchReadingsFromStation(_floodStation.id),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return ReadingGraph(
|
||||
if (snapshot.data!.isEmpty) {
|
||||
return Text('No readings on record.');
|
||||
}
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
|
||||
child: ReadingGraph(
|
||||
readings: snapshot.data!,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// return ListView.builder(
|
||||
// itemBuilder: (context, index) {
|
||||
// return ListTile(
|
||||
// title:
|
||||
// Text(snapshot.data!.elementAt(index).value.toString()),
|
||||
// );
|
||||
// },
|
||||
// itemCount: snapshot.data!.length,
|
||||
// );
|
||||
} else {
|
||||
return Placeholder();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user