Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
Added new chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Qizot committed Apr 14, 2020
1 parent 916a0f9 commit c397036
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:coronavirus_visualizer/src/models/timeline_item.dart';
import 'package:coronavirus_visualizer/src/ui/charts/total_timeline_details_dialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class DailyCasesTimeline extends StatelessWidget {


final List<charts.Series> seriesList;
final bool animate;

DailyCasesTimeline(List<TimelineItem> timelineItems, {this.animate}): seriesList = generateTimeSeries(timelineItems);

static List<charts.Series<TimelineItem, DateTime>> generateTimeSeries(List<TimelineItem> timelineItems) {
return [
charts.Series<TimelineItem, DateTime>(
id: 'Daily Cases',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (TimelineItem item, _) => item.date,
measureFn: (TimelineItem item, _) => item.newCases,
data: timelineItems,
),
];
}

_onSelectionChanged(BuildContext context) {
return (charts.SelectionModel<DateTime> model) {
final selectedDatum = model.selectedDatum;

if (selectedDatum.isNotEmpty) {
final item = model.selectedDatum.first.datum as TimelineItem;
showDialog(context: context, builder: (context) {
return TotalTimelineDetailsDialog(timelineItem: item);
});

}
};
}


@override
Widget build(BuildContext context) {
return charts.TimeSeriesChart(
seriesList,
animate: animate,
defaultRenderer: charts.LineRendererConfig(),
customSeriesRenderers: [
charts.PointRendererConfig(
customRendererId: 'customPoint')
],
selectionModels: [
charts.SelectionModelConfig(
type: charts.SelectionModelType.info,
changedListener: _onSelectionChanged(context),
)
],
dateTimeFactory: const charts.LocalDateTimeFactory(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,9 @@ class TotalTimelineChart extends StatelessWidget {
return charts.TimeSeriesChart(
seriesList,
animate: animate,
// Configure the default renderer as a line renderer. This will be used
// for any series that does not define a rendererIdKey.
//
// This is the default configuration, but is shown here for illustration.
defaultRenderer: charts.LineRendererConfig(),
// Custom renderer configuration for the point series.
customSeriesRenderers: [
charts.PointRendererConfig(
// ID used to link series to this renderer.
customRendererId: 'customPoint')
],
selectionModels: [
Expand All @@ -75,9 +69,6 @@ class TotalTimelineChart extends StatelessWidget {
changedListener: _onSelectionChanged(context),
)
],
// Optionally pass in a [DateTimeFactory] used by the chart. The factory
// should create the same type of [DateTime] as the data provided. If none
// specified, the default creates local date time.
dateTimeFactory: const charts.LocalDateTimeFactory(),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@




import 'package:coronavirus_visualizer/src/bloc/timeline_bloc/bloc.dart';
import 'package:coronavirus_visualizer/src/ui/splash/error_screen.dart';
import 'package:coronavirus_visualizer/src/ui/splash/loading_screen.dart';
import 'package:coronavirus_visualizer/src/ui/total_timeline/daily_cases_chart_card.dart';
import 'package:coronavirus_visualizer/src/ui/total_timeline/total_timeline_chart_card.dart';
import 'package:coronavirus_visualizer/src/ui/total_timeline/total_timeline_circle_chart_card.dart';
import 'package:coronavirus_visualizer/src/ui/total_timeline/total_timeline_stats.dart';
Expand Down Expand Up @@ -52,6 +49,8 @@ class _CountryTimelineScreenState extends State<CountryTimelineScreen> {
children: <Widget>[
TotalTimelineChartCard(timeline: state.countryTimeline.timeline),
SizedBox(height: 15),
DailyCasesChartCard(timeline: state.countryTimeline.timeline),
SizedBox(height: 15),
TotalTimelineCircleChartCard(timeline: state.countryTimeline.timeline),
SizedBox(height: 15),
TotalTimelineStats(timeline: state.countryTimeline.timeline)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:coronavirus_visualizer/src/bloc/timeline_bloc/bloc.dart';
import 'package:coronavirus_visualizer/src/models/global_timeline.dart';
import 'package:coronavirus_visualizer/src/ui/splash/error_screen.dart';
import 'package:coronavirus_visualizer/src/ui/splash/loading_screen.dart';
import 'package:coronavirus_visualizer/src/ui/total_timeline/daily_cases_chart_card.dart';
import 'package:coronavirus_visualizer/src/ui/total_timeline/total_timeline_chart_card.dart';
import 'package:coronavirus_visualizer/src/ui/total_timeline/total_timeline_circle_chart_card.dart';
import 'package:coronavirus_visualizer/src/ui/total_timeline/total_timeline_stats.dart';
Expand Down Expand Up @@ -58,6 +59,8 @@ class _GlobalTimelineScreenState extends State<GlobalTimelineScreen> {
children: <Widget>[
TotalTimelineChartCard(timeline: globalTimeline.timeline),
SizedBox(height: 15),
DailyCasesChartCard(timeline: globalTimeline.timeline),
SizedBox(height: 15),
TotalTimelineCircleChartCard(timeline: globalTimeline.timeline),
SizedBox(height: 15),
TotalTimelineStats(timeline: globalTimeline.timeline)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

import 'package:coronavirus_visualizer/src/models/timeline_item.dart';
import 'package:coronavirus_visualizer/src/ui/charts/daily_cases_timeline_chart.dart';
import 'package:coronavirus_visualizer/src/ui/total_timeline/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class DailyCasesChartCard extends StatelessWidget {
final List<TimelineItem> timeline;

DailyCasesChartCard({this.timeline});

@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(8),
margin: EdgeInsets.all(8),
decoration: defaultGradientDecoration,
child: Column(
children: <Widget>[
SizedBox(height: 10),
Text("New cases daily", style: TextStyle(fontFamily: "Baloo", fontSize: 30, color: Colors.white, fontWeight: FontWeight.w600)),
SizedBox(height: 20),
Container(
height: 300,
child: DailyCasesTimeline(timeline, animate: true)
)
],
)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@


import 'package:coronavirus_visualizer/src/models/timeline_item.dart';
import 'package:coronavirus_visualizer/src/ui/charts/total_timeline_chart.dart';
import 'package:coronavirus_visualizer/src/ui/total_timeline/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

Expand All @@ -15,28 +14,7 @@ class TotalTimelineChartCard extends StatelessWidget {
return Container(
padding: EdgeInsets.all(8),
margin: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
gradient: LinearGradient(
colors: [
const Color(0xFF353535), // yellow sun
const Color(0xFF111111),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight
),
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 20.0,
spreadRadius: 5.0,
offset: Offset(
10,
10
)
)
]
),
decoration: defaultGradientDecoration,
child: Column(
children: <Widget>[
SizedBox(height: 20),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TotalTimelineStats extends StatelessWidget {
physics: ScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 2,
childAspectRatio: 1.8,
children: <Widget>[
// new cases and new deaths are only submitted a day before
_info("Total cases", timeline.first.totalCases ?? 0),
Expand All @@ -64,15 +65,13 @@ class TotalTimelineStats extends StatelessWidget {
}

Widget _info(String text, int amount) {
return Container(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(text, style: TextStyle(fontFamily: "Baloo", fontSize: 20, color: Colors.white, fontWeight: FontWeight.w500)),
SizedBox(height: 10),
Text(amount.toString(), style: TextStyle(fontFamily: "Baloo", fontSize: 25, color: Colors.white, fontWeight: FontWeight.w700))
],
),
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(text, style: TextStyle(fontFamily: "Baloo", fontSize: 20, color: Colors.white, fontWeight: FontWeight.w500)),
SizedBox(height: 10),
Text(amount.toString(), style: TextStyle(fontFamily: "Baloo", fontSize: 25, color: Colors.white, fontWeight: FontWeight.w700))
],
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

final defaultGradientDecoration = BoxDecoration(
borderRadius: BorderRadius.circular(8),
gradient: LinearGradient(
colors: [
const Color(0xFF353535), // yellow sun
const Color(0xFF111111),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight
),
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 20.0,
spreadRadius: 5.0,
offset: Offset(
10,
10
)
)
]
);

0 comments on commit c397036

Please sign in to comment.