Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct today chart data #10

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 20 additions & 46 deletions lib/src/weather/view/today_chart.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:open_weather_client/models/weather_data.dart';
Expand Down Expand Up @@ -40,7 +41,8 @@ class _TodayChartState extends State<TodayChart> {

@override
Widget build(BuildContext context) {
final forecast = watchPropertyValue((WeatherModel m) => m.fiveDaysForCast);
final forecast =
watchPropertyValue((WeatherModel m) => m.notTodayFullForecast);
final mq = context.mq;

final cityName = watchPropertyValue((WeatherModel m) => m.lastLocation);
Expand All @@ -59,7 +61,7 @@ class _TodayChartState extends State<TodayChart> {
),
child: error != null
? ErrorView(error: error)
: forecast == null || data == null
: data == null
? Center(
child: YaruCircularProgressIndicator(
color: context.theme.colorScheme.onSurface,
Expand All @@ -71,7 +73,7 @@ class _TodayChartState extends State<TodayChart> {
padding: EdgeInsets.only(top: mq.size.height / 3),
scrollDirection: Axis.horizontal,
child: SizedBox(
width: forecast.length * 50,
width: forecast.length * 100,
height: 400,
child: LineChart(
mainData(forecast),
Expand Down Expand Up @@ -137,38 +139,13 @@ class _TodayChartState extends State<TodayChart> {
);

return SideTitleWidget(
fitInside: SideTitleFitInsideData.fromTitleMeta(meta),
axisSide: meta.axisSide,
child: text,
);
}

Widget leftTitleWidgets(double value, TitleMeta meta) {
const style = TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
);
String text;
switch (value.toInt()) {
case 1:
text = '10K';
break;
case 3:
text = '30k';
break;
case 5:
text = '50k';
break;
default:
return Container();
}

return Padding(
padding: const EdgeInsets.all(8.0),
child: Text(text, style: style, textAlign: TextAlign.left),
);
}

LineChartData mainData(List<WeatherData> data) {
LineChartData mainData(List<WeatherData> forecast) {
final outlineColor = context.theme.colorScheme.onSurface.withOpacity(0.2);

return LineChartData(
Expand Down Expand Up @@ -207,14 +184,12 @@ class _TodayChartState extends State<TodayChart> {
reservedSize: 35,
interval: 1,
getTitlesWidget: (value, meta) =>
bottomTitleWidgets(value, meta, data),
bottomTitleWidgets(value, meta, forecast),
),
),
leftTitles: AxisTitles(
leftTitles: const AxisTitles(
sideTitles: SideTitles(
showTitles: false,
interval: 1,
getTitlesWidget: leftTitleWidgets,
reservedSize: 0,
),
),
Expand All @@ -226,20 +201,19 @@ class _TodayChartState extends State<TodayChart> {
),
),
minX: 0,
maxX: 11,
minY: 0,
maxY: 6,
maxX: (forecast.length - 1).toDouble(),
minY: forecast.map((e) => e.temperature.currentTemperature).min,
maxY: forecast.map((e) => e.temperature.currentTemperature).max,
lineBarsData: [
LineChartBarData(
spots: const [
FlSpot(0, 3),
FlSpot(2.6, 2),
FlSpot(4.9, 5),
FlSpot(6.8, 3.1),
FlSpot(8, 4),
FlSpot(9.5, 3),
FlSpot(11, 4),
],
spots: forecast
.mapIndexed(
(i, e) => FlSpot(
i.toDouble(),
e.temperature.currentTemperature,
),
)
.toList(),
isCurved: true,
gradient: LinearGradient(
colors: gradientColors,
Expand Down