below is a sample of the graph code. I'm not bothering to check the times of the readings at the moment, just plotting what the last # of results are if they are valid. I've added toFloat() conversion like a madman just in case it was an integer issue with the division, but that didn't help. This code works flawlessly on the simulator (of course) and mostly flawlessly on the actual watch. And most of the time when I notice the graph is messed up, if I move my arm it brings it out of low power mode and the next re-draw fixes the graph....
I guess I just need to check if my actual HR difference is > the supposed max difference and not plot it then? Except one of the times the entire plot was outside the bounds, which isn't even possible unless the max or min got set to something nonsensical. I already have it checking if there is no difference from min to max and telling it to just draw along the bottom of the range.
BTW - this only draws about the last 1 to 2 hours of HR readings rather than all of them. I'd fix it to work off the times, but the simulator is so awful for the HR history... is there any way to set the data yourself so you can test more than just the one plain vanilla case?
var hrIter = Act.getHeartRateHistory(null, true);
var max = hrIter.getMax();
var min = hrIter.getMin();
var maxdiff = max - min;
var hr = hrIter.next();
var height = 18.0;
var bottomY = 28.0;
var minX = 64.0;
var x = screenWidth-65;
var y1 = bottomY.toFloat();
while(hr!=null && x >= minX){
if(hr.heartRate != Act.INVALID_HR_SAMPLE && hr.heartRate > 0){
var y2 = bottomY - (maxdiff > 0 ? (hr.heartRate.toFloat() - min.toFloat())/maxdiff.toFloat() * height.toFloat() : 0.0);
dc.setColor(Gfx.COLOR_LT_GRAY,Gfx.COLOR_TRANSPARENT);
dc.drawLine(x, y1, x, y2); //shade in gray
dc.setColor(Gfx.COLOR_WHITE,Gfx.COLOR_TRANSPARENT);
dc.drawPoint(x, y2); //draw white point at top for actual hr measure
}
x--;
hr = hrIter.next();
}
dc.setColor(Gfx.COLOR_DK_GRAY,Gfx.COLOR_TRANSPARENT);
dc.drawLine(screenWidth-65, 29, 63, 29);
*the watchface prints the current HR in another section