Commit 9ab14c41 authored by Administrator's avatar Administrator

speed / hr diagram

parent 91f218f2
......@@ -4,6 +4,7 @@ import 'package:encrateia/models/activity.dart';
import 'package:encrateia/widgets/activities_list_widget.dart';
import 'package:encrateia/widgets/athlete_power_widget.dart';
import 'package:encrateia/widgets/athlete_power_per_heart_rate_widget.dart';
import 'package:encrateia/widgets/athlete_speed_per_heart_rate_widget.dart';
import 'package:encrateia/utils/icon_utils.dart';
import 'package:flushbar/flushbar.dart';
......@@ -31,7 +32,7 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
length: 4,
child: Scaffold(
floatingActionButton: Visibility(
visible: floatingActionButtonVisible,
......@@ -56,6 +57,10 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
Tab(
icon: MyIcon.power,
text: "Power/HR",
),
Tab(
icon: MyIcon.speed,
text: "Speed/HR",
)
]),
),
......@@ -63,6 +68,7 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
ActivitiesListWidget(athlete: widget.athlete),
AthletePowerWidget(athlete: widget.athlete),
AthletePowerPerHeartRateWidget(athlete: widget.athlete),
AthleteSpeedPerHeartRateWidget(athlete: widget.athlete),
]),
),
);
......
import 'package:charts_flutter/flutter.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
class AthleteSpeedPerHeartRateChart extends StatelessWidget {
final List<Activity> activities;
AthleteSpeedPerHeartRateChart({@required this.activities});
@override
Widget build(BuildContext context) {
var nonZero = activities.where((value) => value.db.avgSpeed > 0).toList();
var data = [
new Series<Activity, DateTime>(
id: 'Average Speed',
colorFn: (_, __) => MaterialPalette.blue.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) =>
(100 * activity.db.avgSpeed / activity.db.avgHeartRate),
data: nonZero,
)
];
return new Container(
height: 300,
child: TimeSeriesChart(
data,
animate: false,
primaryMeasureAxis: NumericAxisSpec(
tickProviderSpec: BasicNumericTickProviderSpec(
zeroBound: false,
dataIsInWholeNumbers: false,
desiredTickCount: 6,
),
),
behaviors: [
ChartTitle(
'Speed per Heart Rate (km/h / 100 bpm)',
titleStyleSpec: TextStyleSpec(fontSize: 13),
behaviorPosition: BehaviorPosition.start,
titleOutsideJustification: OutsideJustification.end,
),
ChartTitle(
'Date',
titleStyleSpec: TextStyleSpec(fontSize: 13),
behaviorPosition: BehaviorPosition.bottom,
titleOutsideJustification: OutsideJustification.end,
),
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/utils/list_utils.dart';
import 'athlete_speed_per_heart_rate_chart.dart';
class AthleteSpeedPerHeartRateWidget extends StatefulWidget {
final Athlete athlete;
AthleteSpeedPerHeartRateWidget({this.athlete});
@override
_AthleteSpeedPerHeartRateWidgetState createState() => _AthleteSpeedPerHeartRateWidgetState();
}
class _AthleteSpeedPerHeartRateWidgetState extends State<AthleteSpeedPerHeartRateWidget> {
List<Activity> activities = [];
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(context) {
if (activities.length > 0) {
var powerValues = activities.map((value) => value.db.avgSpeed).nonZeroDoubles();
if (powerValues.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
child: ListView(
padding: EdgeInsets.only(left: 25),
children: <Widget>[
AthleteSpeedPerHeartRateChart(activities: activities),
],
),
);
} else {
return Center(
child: Text("No speed per heart rate data available."),
);
}
} else {
return Center(
child: Text("Loading"),
);
}
}
getData() async {
Athlete athlete = widget.athlete;
activities = await athlete.activities;
activities = activities.where((activity) => activity.db.sport == "running").toList();
setState(() {});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment