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