@@ -86,8 +86,10 @@ public class ChartView extends View {
86
86
}
87
87
88
88
private final List <ChartValueSeries > seriesList = new LinkedList <>();
89
+ private final ChartValueSeries elevationSeries ;
89
90
private final ChartValueSeries speedSeries ;
90
91
private final ChartValueSeries paceSeries ;
92
+ private final ChartValueSeries heartRateSeries ;
91
93
92
94
private final LinkedList <ChartPoint > chartPoints = new LinkedList <>();
93
95
private final List <Marker > markers = new LinkedList <>();
@@ -123,6 +125,7 @@ public class ChartView extends View {
123
125
private boolean chartByDistance = false ;
124
126
private UnitSystem unitSystem = UnitSystem .defaultUnitSystem ();
125
127
private boolean reportSpeed = true ;
128
+ private boolean showPaceOrSpeed = true ;
126
129
private boolean showPointer = false ;
127
130
128
131
private final GestureDetectorCompat detectorScrollFlingTab = new GestureDetectorCompat (getContext (), new GestureDetector .SimpleOnGestureListener () {
@@ -176,17 +179,17 @@ public ChartView(Context context, AttributeSet attributeSet) {
176
179
int fontSizeSmall = ThemeUtils .getFontSizeSmallInPx (context );
177
180
int fontSizeMedium = ThemeUtils .getFontSizeMediumInPx (context );
178
181
179
- seriesList . add ( new ChartValueSeries (context ,
180
- Integer .MIN_VALUE ,
181
- Integer .MAX_VALUE ,
182
- new int []{5 , 10 , 25 , 50 , 100 , 250 , 500 , 1000 , 2500 , 5000 },
183
- R .string .description_altitude_metric ,
184
- R .string .description_altitude_imperial ,
185
- R .string .description_altitude_imperial ,
186
- R .color .chart_altitude_fill ,
187
- R .color .chart_altitude_border ,
188
- fontSizeSmall ,
189
- fontSizeMedium ) {
182
+ elevationSeries = new ChartValueSeries (context ,
183
+ Integer .MIN_VALUE ,
184
+ Integer .MAX_VALUE ,
185
+ new int []{5 , 10 , 25 , 50 , 100 , 250 , 500 , 1000 , 2500 , 5000 },
186
+ R .string .description_altitude_metric ,
187
+ R .string .description_altitude_imperial ,
188
+ R .string .description_altitude_imperial ,
189
+ R .color .chart_altitude_fill ,
190
+ R .color .chart_altitude_border ,
191
+ fontSizeSmall ,
192
+ fontSizeMedium ) {
190
193
@ Override
191
194
protected Double extractDataFromChartPoint (@ NonNull ChartPoint chartPoint ) {
192
195
return chartPoint .altitude ();
@@ -196,7 +199,8 @@ protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) {
196
199
protected boolean drawIfChartPointHasNoData () {
197
200
return false ;
198
201
}
199
- });
202
+ };
203
+ seriesList .add (elevationSeries );
200
204
201
205
speedSeries = new ChartValueSeries (context ,
202
206
0 ,
@@ -244,10 +248,15 @@ protected boolean drawIfChartPointHasNoData() {
244
248
};
245
249
seriesList .add (paceSeries );
246
250
247
- seriesList . add ( new ChartValueSeries (context ,
251
+ heartRateSeries = new ChartValueSeries (context ,
248
252
0 ,
249
253
Integer .MAX_VALUE ,
250
- new int []{25 , 50 },
254
+ // For Zone 5 cardio, the 25 value should result in nice visuals, as the values
255
+ // will range from ~70 - ~180 (around 4.5 intervals).
256
+ // For Zone 1 cardio, the 15 value should result in nice visuals, as the values
257
+ // will range from ~70 - ~120 (around 3.5 intervals)
258
+ // The fallback of 50 should give appropriate visuals for values outside this range.
259
+ new int []{15 , 25 , 50 },
251
260
R .string .description_sensor_heart_rate ,
252
261
R .string .description_sensor_heart_rate ,
253
262
R .string .description_sensor_heart_rate ,
@@ -264,7 +273,8 @@ protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) {
264
273
protected boolean drawIfChartPointHasNoData () {
265
274
return false ;
266
275
}
267
- });
276
+ };
277
+ seriesList .add (heartRateSeries );
268
278
269
279
seriesList .add (new ChartValueSeries (context ,
270
280
0 ,
@@ -343,9 +353,15 @@ protected boolean drawIfChartPointHasNoData() {
343
353
setClickable (true );
344
354
updateDimensions ();
345
355
346
- // either speedSeries or paceSeries should be enabled.
347
- speedSeries .setEnabled (reportSpeed );
348
- paceSeries .setEnabled (!reportSpeed );
356
+ // Either speedSeries or paceSeries should be enabled, if one is shown.
357
+ if (showPaceOrSpeed ) {
358
+ speedSeries .setEnabled (reportSpeed );
359
+ paceSeries .setEnabled (!reportSpeed );
360
+ }
361
+
362
+ // Defaults for our chart series.
363
+ heartRateSeries .setEnabled (true );
364
+ elevationSeries .setEnabled (true );
349
365
}
350
366
351
367
@ Override
@@ -379,6 +395,12 @@ public void setReportSpeed(boolean value) {
379
395
}
380
396
381
397
public boolean applyReportSpeed () {
398
+ if (!showPaceOrSpeed ) {
399
+ paceSeries .setEnabled (false );
400
+ speedSeries .setEnabled (false );
401
+ return true ;
402
+ }
403
+
382
404
if (reportSpeed ) {
383
405
if (!speedSeries .isEnabled ()) {
384
406
speedSeries .setEnabled (true );
@@ -396,6 +418,20 @@ public boolean applyReportSpeed() {
396
418
return false ;
397
419
}
398
420
421
+ void setShowElevation (boolean value ) {
422
+ elevationSeries .setEnabled (value );
423
+ }
424
+ void setShowPaceOrSpeed (boolean value ) {
425
+ showPaceOrSpeed = value ;
426
+
427
+ // we want to make sure we show whatever version the user has
428
+ // selected when we turn this back on.
429
+ applyReportSpeed ();
430
+ }
431
+ void setShowHeartRate (boolean value ) {
432
+ heartRateSeries .setEnabled (value );
433
+ }
434
+
399
435
public void setShowPointer (boolean value ) {
400
436
showPointer = value ;
401
437
}
@@ -644,10 +680,18 @@ private record TitleDimensions(
644
680
*/
645
681
private void drawSeriesTitles (Canvas canvas ) {
646
682
Iterator <TitlePosition > tpI = titleDimensions .titlePositions .iterator ();
683
+
647
684
for (ChartValueSeries chartValueSeries : seriesList ) {
648
685
if (chartValueSeries .isEnabled () && chartValueSeries .hasData () || allowIfEmpty (chartValueSeries )) {
649
686
String title = getContext ().getString (chartValueSeries .getTitleId (unitSystem ));
650
687
Paint paint = chartValueSeries .getTitlePaint ();
688
+
689
+ // It is possible for the titlePositions to become empty temporarily, while switching between
690
+ // chart screens quickly.
691
+ if (!tpI .hasNext ()) {
692
+ return ;
693
+ }
694
+
651
695
TitlePosition tp = tpI .next ();
652
696
int y = topBorder - spacer - (titleDimensions .lineCount - tp .line ) * (titleDimensions .lineHeight + spacer );
653
697
canvas .drawText (title , tp .xPos + getScrollX (), y , paint );
@@ -774,7 +818,7 @@ private void drawYAxis(Canvas canvas) {
774
818
775
819
//TODO
776
820
int markerXPosition = x - spacer ;
777
- int index = titleDimensions .titlePositions .size () - 1 ; // index only onver the visible chart series
821
+ int index = titleDimensions .titlePositions .size () - 1 ; // index only over the visible chart series
778
822
final int lastDrawn2ndLineMarkerIndex = getYmarkerCountOn1stLine ();
779
823
for (int i = seriesList .size ()-1 ; i >=0 ;--i ) { // draw markers from the last series to achieve right alignment
780
824
ChartValueSeries chartValueSeries = seriesList .get (i );
0 commit comments