Commit e886a571 authored by Stefan Haslinger's avatar Stefan Haslinger

heart rate zones in lap heart rate diagram

parent aaf964fa
......@@ -7,6 +7,8 @@ import 'package:encrateia/models/event.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/utils/num_utils.dart';
import 'heart_rate_zone_schema.dart';
class Lap {
DbLap db;
Activity activity;
......@@ -439,4 +441,14 @@ class Lap {
);
return powerZoneSchema;
}
getHeartRateZoneSchema() async {
var dbActivity = await DbActivity().getById(db.activitiesId);
var heartRateZoneSchema = await HeartRateZoneSchema.getBy(
athletesId: dbActivity.athletesId,
date: dbActivity.timeCreated,
);
return heartRateZoneSchema;
}
}
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/heart_rate_zone.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/event.dart';
import 'package:encrateia/utils/graph_utils.dart';
class LapHeartRateChart extends StatelessWidget {
final List<Event> records;
final List<HeartRateZone> heartRateZones;
LapHeartRateChart({this.records});
LapHeartRateChart({
this.records,
this.heartRateZones,
});
@override
Widget build(BuildContext context) {
var offset = records.first.db.distance.round();
List<Series<dynamic, num>> data = [
Series<Event, int>(
Series<Event, int>(
id: 'Heart Rate',
colorFn: (_, __) => MaterialPalette.red.shadeDefault,
domainFn: (Event record, _) => record.db.distance.round() - offset,
......@@ -22,7 +27,7 @@ class LapHeartRateChart extends StatelessWidget {
)
];
return Container(
return Container(
height: 300,
child: LineChart(
data,
......@@ -33,9 +38,19 @@ class LapHeartRateChart extends StatelessWidget {
desiredTickCount: 6),
),
animate: false,
behaviors: GraphUtils.axis(
measureTitle: 'Heart Rate (bpm)',
),
behaviors: [
RangeAnnotation(
GraphUtils.heartRateZoneAnnotations(
heartRateZones: heartRateZones,
),
),
ChartTitle(
"Heart Rate (bpm)",
titleStyleSpec: TextStyleSpec(fontSize: 13),
behaviorPosition: BehaviorPosition.bottom,
titleOutsideJustification: OutsideJustification.end,
),
],
),
);
}
......
import 'package:encrateia/models/heart_rate_zone.dart';
import 'package:encrateia/models/heart_rate_zone_schema.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/lap.dart';
import 'package:encrateia/models/event.dart';
......@@ -17,6 +19,8 @@ class _LapHeartRateWidgetState extends State<LapHeartRateWidget> {
List<Event> records = [];
String avgHeartRateString = "Loading ...";
String sdevHeartRateString = "Loading ...";
HeartRateZoneSchema heartRateZoneSchema;
List<HeartRateZone> heartRateZones;
@override
void initState() {
......@@ -38,7 +42,10 @@ class _LapHeartRateWidgetState extends State<LapHeartRateWidget> {
child: ListView(
padding: EdgeInsets.only(left: 25),
children: <Widget>[
LapHeartRateChart(records: records),
LapHeartRateChart(
records: records,
heartRateZones: heartRateZones,
),
ListTile(
leading: MyIcon.average,
title: Text(Lap.avgHeartRate(records: records)),
......@@ -82,6 +89,12 @@ class _LapHeartRateWidgetState extends State<LapHeartRateWidget> {
getData() async {
Lap lap = widget.lap;
records = await lap.records;
heartRateZoneSchema = await lap.getHeartRateZoneSchema();
if (heartRateZoneSchema != null)
heartRateZones = await heartRateZoneSchema.heartRateZones;
else
heartRateZones = [];
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