mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
User Chart Pie and Bar charts now work
.. since we can now set category data using string vectors we can support bar and pie charts in the user chart. .. there were a few issues switching between bar and pie charts related to the way axes were being configured that have been resolved in this commit.
This commit is contained in:
@@ -736,6 +736,8 @@ GenericPlot::addCurve(QString name, QVector<double> xseries, QVector<double> yse
|
||||
{
|
||||
// set up the curves
|
||||
QPieSeries *add = new QPieSeries();
|
||||
add->setPieSize(0.7);
|
||||
add->setHoleSize(0.5);
|
||||
|
||||
// setup the slices
|
||||
for(int i=0; i<yseries.size(); i++) {
|
||||
@@ -840,7 +842,6 @@ GenericPlot::finaliseChart()
|
||||
if (axisinfo->log) vaxis= new QLogValueAxis(qchart);
|
||||
else vaxis= new QValueAxis(qchart);
|
||||
add=vaxis; // gets added later
|
||||
|
||||
vaxis->setMin(axisinfo->min());
|
||||
vaxis->setMax(axisinfo->max());
|
||||
|
||||
@@ -1019,6 +1020,7 @@ GenericPlot::configureAxis(QString name, bool visible, int align, double min, do
|
||||
// min should be minimum value for all attached series
|
||||
foreach(QAbstractSeries *series, axis->series) {
|
||||
if (series->type() == QAbstractSeries::SeriesType::SeriesTypeScatter ||
|
||||
series->type() == QAbstractSeries::SeriesType::SeriesTypeBar ||
|
||||
series->type() == QAbstractSeries::SeriesType::SeriesTypeLine) {
|
||||
foreach(QPointF point, static_cast<QXYSeries*>(series)->pointsVector()) {
|
||||
if (usey) {
|
||||
@@ -1044,6 +1046,7 @@ GenericPlot::configureAxis(QString name, bool visible, int align, double min, do
|
||||
// min should be minimum value for all attached series
|
||||
foreach(QAbstractSeries *series, axis->series) {
|
||||
if (series->type() == QAbstractSeries::SeriesType::SeriesTypeScatter ||
|
||||
series->type() == QAbstractSeries::SeriesType::SeriesTypeBar ||
|
||||
series->type() == QAbstractSeries::SeriesType::SeriesTypeLine) {
|
||||
foreach(QPointF point, static_cast<QXYSeries*>(series)->pointsVector()) {
|
||||
if (usey) {
|
||||
|
||||
@@ -163,7 +163,7 @@ UserChart::setRide(RideItem *item)
|
||||
series.yseries = ucd->y.asNumeric();
|
||||
|
||||
// pie charts need labels
|
||||
if (chartinfo.type == GC_CHART_PIE || chartinfo.type == GC_CHART_BAR) {
|
||||
if (chartinfo.type == GC_CHART_PIE) {
|
||||
series.labels.clear();
|
||||
for(int i=0; i<ucd->x.asString().count(); i++) series.labels << ucd->x.asString()[i];
|
||||
|
||||
@@ -202,6 +202,42 @@ UserChart::setRide(RideItem *item)
|
||||
// it works for now.
|
||||
if (axis.orientation == Qt::Horizontal) axis.labelcolor = axis.axiscolor = GColor(CPLOTMARKER);
|
||||
|
||||
// on a user chart the series sets the categories for a bar chart
|
||||
// find the first series for this axis and set the categories
|
||||
// to the x series values.
|
||||
if (chartinfo.type == GC_CHART_BAR && axis.orientation == Qt::Horizontal) {
|
||||
// find the first series for axis.name
|
||||
foreach(GenericSeriesInfo s, seriesinfo) {
|
||||
if (s.xname == axis.name && s.user1) {
|
||||
axis.type = GenericAxisInfo::CATEGORY;
|
||||
axis.categories.clear();
|
||||
UserChartData *ucd = static_cast<UserChartData*>(s.user1);
|
||||
for(int i=0; i<ucd->x.asString().count(); i++) axis.categories << ucd->x.asString()[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we need to set max and min based upon the barsets for bar charts since
|
||||
// the generic plot only looks are series associated with an axis and we have 0 of those
|
||||
if (min==-1 && max==-1 && chartinfo.type == GC_CHART_BAR && axis.orientation == Qt::Vertical) {
|
||||
|
||||
// loop through all the series and look at max and min y values
|
||||
bool first=true;
|
||||
foreach(GenericSeriesInfo s, seriesinfo) {
|
||||
if (s.yname == axis.name && s.user1) {
|
||||
UserChartData *ucd = static_cast<UserChartData*>(s.user1);
|
||||
for(int i=0; i<ucd->y.asNumeric().count(); i++) {
|
||||
double yy = ucd->y.asNumeric()[i];
|
||||
if (first || yy > max) max = yy;
|
||||
if (first || yy < min) min = yy;
|
||||
first = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we do NOT set align, this is managed in generic plot on our behalf
|
||||
// we also don't hide axes, so visible is always set to true
|
||||
chart->configureAxis(axis.name, true, -1, min, max, axis.type,
|
||||
|
||||
Reference in New Issue
Block a user