From 8375f539db7fa2941aa11ea1af0b09f20ed82ca7 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Tue, 10 Aug 2021 21:02:59 +0100 Subject: [PATCH] Bar Chart and Group By Category Labels .. slightly improved category labels on a bar chart when groupby and date range is used. Labels for week, month and year are now specific e.g. 23/5, May and 2021 labels are applied respectively. --- src/Charts/UserChart.cpp | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Charts/UserChart.cpp b/src/Charts/UserChart.cpp index 7a4dde9e1..c845d393f 100644 --- a/src/Charts/UserChart.cpp +++ b/src/Charts/UserChart.cpp @@ -292,20 +292,53 @@ UserChart::setRide(const RideItem *item) // find the first series for axis.name foreach(GenericSeriesInfo s, seriesinfo) { if (s.xname == axis.name && s.user1) { + axis.categories.clear(); + + UserChartData *ucd = static_cast(s.user1); switch (axis.type) { case GenericAxisInfo::TIME: for(int i=0; ix.asNumeric().count(); i++) axis.categories << time_to_string(ucd->x.asNumeric()[i], true); break; - case GenericAxisInfo::DATERANGE: - for(int i=0; ix.asNumeric().count(); i++) axis.categories << earliest.addDays(ucd->x.asNumeric()[i]).toString("dd MMM yy"); + case GenericAxisInfo::DATERANGE: { + + // date labels, date, week #, month name, year + QString dateformat= "dd MMM yy"; + int ax=GenericAxisInfo::findAxis(axisinfo, s.xname); // lookup axisinfo + if (ax != -1 && axisinfo[ax].groupby != 0 && axisinfo[ax].type == GenericAxisInfo::DATERANGE) { + + // date format depends on how data was grouped + switch(axisinfo[ax].groupby) { + default: + case GenericAxisInfo::NONE: + case GenericAxisInfo::DAY: + dateformat= "dd MMM yy"; + break; + + case GenericAxisInfo::WEEK: + dateformat = "d/M"; // week commencing + + break; + case GenericAxisInfo::MONTH: + dateformat = "MMM yy"; + break; + + case GenericAxisInfo::YEAR: + dateformat = "yyyy"; + break; + } + } + // create the labels + for(int i=0; ix.asNumeric().count(); i++) + axis.categories << earliest.addDays(ucd->x.asNumeric()[i]).toString(dateformat); + } break; default: for(int i=0; ix.asString().count(); i++) axis.categories << ucd->x.asString()[i]; break; } - axis.type = GenericAxisInfo::CATEGORY; // xxx ack ack ack - groupby dates and bar charts.... + axis.type = GenericAxisInfo::CATEGORY; break; } }