Skip to content

Commit

Permalink
Add shaded power zones for watt per kilogram series in histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
grauser committed Dec 2, 2012
1 parent 28faf74 commit eaa8477
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/PowerHist.cpp
Expand Up @@ -211,7 +211,7 @@ PowerHist::refreshZoneLabels()

if (!rideItem) return;

if (series == RideFile::watts) {
if (series == RideFile::watts || series == RideFile::wattsKg) {
const Zones *zones = rideItem->zones;
int zone_range = rideItem->zoneRange();

Expand Down Expand Up @@ -964,7 +964,7 @@ PowerHist::setSeries(RideFile::SeriesType x) {

bool PowerHist::shadeZones() const
{
return (rideItem && rideItem->ride() && series == RideFile::watts && !zoned && shade == true);
return (rideItem && rideItem->ride() && (series == RideFile::watts || series == RideFile::wattsKg) && !zoned && shade == true);
}

bool PowerHist::shadeHRZones() const
Expand Down
30 changes: 24 additions & 6 deletions src/PowerHist.h
Expand Up @@ -262,9 +262,21 @@ class PowerHistBackground: public QwtPlotItem
shading_color.saturation() / 4,
shading_color.value()
);
r.setLeft(xMap.transform(zone_lows[z]));
if (z + 1 < num_zones)
r.setRight(xMap.transform(zone_lows[z + 1]));

double wattsLeft = zone_lows[z];
if (parent->series == RideFile::wattsKg) {
wattsLeft = wattsLeft / rideItem->ride()->getWeight();
}
r.setLeft(xMap.transform(wattsLeft));

if (z + 1 < num_zones) {
double wattsRight = zone_lows[z + 1];
if (parent->series == RideFile::wattsKg) {
wattsRight = wattsRight / rideItem->ride()->getWeight();
}
r.setRight(xMap.transform(wattsRight));
}

if (r.right() >= r.left())
painter->fillRect(r, shading_color);
}
Expand Down Expand Up @@ -316,7 +328,7 @@ class PowerHistZoneLabel: public QwtPlotItem
(1.5 * zone_lows[zone_number] - 0.5 * zone_lows[zone_number - 1]) :
2.0 * zone_lows[zone_number]
)
);
);

text = QwtText(zone_names[zone_number]);
text.setFont(QFont("Helvetica",24, QFont::Bold));
Expand All @@ -337,8 +349,14 @@ class PowerHistZoneLabel: public QwtPlotItem
const QwtScaleMap &xMap, const QwtScaleMap &,
const QRectF &rect) const
{
if (parent->shadeZones()) {
int x = xMap.transform(watts);
RideItem *rideItem = parent->rideItem;

if (parent->shadeZones()) {
double position = watts;
if (parent->series == RideFile::wattsKg) {
position = watts / rideItem->ride()->getWeight();
}
int x = xMap.transform(position);
int y = (rect.bottom() + rect.top()) / 2;

// the following code based on source for QwtPlotMarker::draw()
Expand Down

0 comments on commit eaa8477

Please sign in to comment.