aboutsummaryrefslogtreecommitdiffstats
path: root/stats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-19 16:09:56 +0100
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2021-01-20 08:47:18 +0100
commit4f58e9aa62d29a31ff8df74bea75cb770a0d50ff (patch)
tree5a33233faf90fd7cd1a74c8e145ec34928a339d9 /stats
parent2e2019dea7087937d7bcc0e9bd2598d61a758b65 (diff)
downloadsubsurface-4f58e9aa62d29a31ff8df74bea75cb770a0d50ff.tar.gz
statistics: render bar and pie labels onto fill color
The labels in bar an pie charts are realized as individual QSG pixmap nodes with an alpha channel. Sadly, rendering bright labels onto a transparent background gives very ugly artifacts. As a stop gap measure, until the problem is understood, render on a background with the color of the pie slice or bar. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats')
-rw-r--r--stats/barseries.cpp24
-rw-r--r--stats/barseries.h6
-rw-r--r--stats/chartitem.cpp7
-rw-r--r--stats/chartitem.h3
-rw-r--r--stats/pieseries.cpp8
5 files changed, 29 insertions, 19 deletions
diff --git a/stats/barseries.cpp b/stats/barseries.cpp
index ab9521315..766843703 100644
--- a/stats/barseries.cpp
+++ b/stats/barseries.cpp
@@ -92,7 +92,7 @@ BarSeries::BarLabel::BarLabel(StatsView &view, const std::vector<QString> &label
{
QFont f; // make configurable
item = view.createChartItem<ChartTextItem>(ChartZValue::SeriesLabels, f, labels, true);
- highlight(false, bin_nr, binCount);
+ //highlight(false, bin_nr, binCount);
}
void BarSeries::BarLabel::setVisible(bool visible)
@@ -100,13 +100,16 @@ void BarSeries::BarLabel::setVisible(bool visible)
item->setVisible(visible);
}
-void BarSeries::BarLabel::highlight(bool highlight, int bin_nr, int binCount)
+void BarSeries::BarLabel::highlight(bool highlight, int bin_nr, int binCount, const QColor &background)
{
- item->setColor(highlight || isOutside ? darkLabelColor : labelColor(bin_nr, binCount));
+ // For labels that are on top of a bar, use the corresponding bar color
+ // as background. Rendering on a transparent background gives ugly artifacts.
+ item->setColor(highlight || isOutside ? darkLabelColor : labelColor(bin_nr, binCount),
+ isOutside ? Qt::transparent : background);
}
void BarSeries::BarLabel::updatePosition(bool horizontal, bool center, const QRectF &rect,
- int bin_nr, int binCount)
+ int bin_nr, int binCount, const QColor &background)
{
QSizeF itemSize = item->getRect().size();
if (!horizontal) {
@@ -153,7 +156,7 @@ void BarSeries::BarLabel::updatePosition(bool horizontal, bool center, const QRe
}
setVisible(true);
// If label changed from inside to outside, or vice-versa, the color might change.
- highlight(false, bin_nr, binCount);
+ highlight(false, bin_nr, binCount, background);
}
BarSeries::Item::Item(BarSeries *series, double lowerBound, double upperBound,
@@ -181,12 +184,11 @@ void BarSeries::Item::highlight(int subitem, bool highlight, int binCount)
void BarSeries::SubItem::highlight(bool highlight, int binCount)
{
- if (highlight)
- item->setColor(highlightedColor, highlightedBorderColor);
- else
- item->setColor(binColor(bin_nr, binCount), ::borderColor);
+ fill = highlight ? highlightedColor : binColor(bin_nr, binCount);
+ QColor border = highlight ? highlightedBorderColor : ::borderColor;
+ item->setColor(fill, border);
if (label)
- label->highlight(highlight, bin_nr, binCount);
+ label->highlight(highlight, bin_nr, binCount, fill);
}
void BarSeries::Item::updatePosition(BarSeries *series, bool horizontal, bool stacked, int binCount)
@@ -229,7 +231,7 @@ void BarSeries::SubItem::updatePosition(BarSeries *series, bool horizontal, bool
QRectF rect(topLeft, bottomRight);
item->setRect(rect);
if (label)
- label->updatePosition(horizontal, stacked, rect, bin_nr, binCount);
+ label->updatePosition(horizontal, stacked, rect, bin_nr, binCount, fill);
}
std::vector<BarSeries::SubItem> BarSeries::makeSubItems(const std::vector<std::pair<double, std::vector<QString>>> &values) const
diff --git a/stats/barseries.h b/stats/barseries.h
index 50ef1e72d..9f9586fe8 100644
--- a/stats/barseries.h
+++ b/stats/barseries.h
@@ -11,6 +11,7 @@
#include <memory>
#include <vector>
+#include <QColor>
#include <QRectF>
class ChartBarItem;
@@ -86,8 +87,8 @@ private:
bool isOutside; // Is shown outside of bar
BarLabel(StatsView &view, const std::vector<QString> &labels, int bin_nr, int binCount);
void setVisible(bool visible);
- void updatePosition(bool horizontal, bool center, const QRectF &rect, int bin_nr, int binCount);
- void highlight(bool highlight, int bin_nr, int binCount);
+ void updatePosition(bool horizontal, bool center, const QRectF &rect, int bin_nr, int binCount, const QColor &background);
+ void highlight(bool highlight, int bin_nr, int binCount, const QColor &background);
};
struct SubItem {
@@ -96,6 +97,7 @@ private:
double value_from;
double value_to;
int bin_nr;
+ QColor fill;
void updatePosition(BarSeries *series, bool horizontal, bool stacked,
double from, double to, int binCount);
void highlight(bool highlight, int binCount);
diff --git a/stats/chartitem.cpp b/stats/chartitem.cpp
index 7c5339596..c8bdd130e 100644
--- a/stats/chartitem.cpp
+++ b/stats/chartitem.cpp
@@ -242,7 +242,12 @@ ChartTextItem::ChartTextItem(StatsView &v, ChartZValue z, const QFont &f, const
void ChartTextItem::setColor(const QColor &c)
{
- img->fill(Qt::transparent);
+ setColor(c, Qt::transparent);
+}
+
+void ChartTextItem::setColor(const QColor &c, const QColor &background)
+{
+ img->fill(background);
double y = 0.0;
painter->setPen(QPen(c));
painter->setFont(f);
diff --git a/stats/chartitem.h b/stats/chartitem.h
index 6c8919dec..cf20f55a8 100644
--- a/stats/chartitem.h
+++ b/stats/chartitem.h
@@ -89,7 +89,8 @@ class ChartTextItem : public ChartPixmapItem {
public:
ChartTextItem(StatsView &v, ChartZValue z, const QFont &f, const std::vector<QString> &text, bool center);
ChartTextItem(StatsView &v, ChartZValue z, const QFont &f, const QString &text);
- void setColor(const QColor &color);
+ void setColor(const QColor &color); // Draw on transparent background
+ void setColor(const QColor &color, const QColor &background); // Fill rectangle with given background color
private:
QFont f;
double fontHeight;
diff --git a/stats/pieseries.cpp b/stats/pieseries.cpp
index 50c76a8ed..8db3bdbe3 100644
--- a/stats/pieseries.cpp
+++ b/stats/pieseries.cpp
@@ -65,11 +65,11 @@ void PieSeries::Item::updatePositions(const QPointF &center, double radius)
void PieSeries::Item::highlight(ChartPieItem &item, int bin_nr, bool highlight, int numBins)
{
+ QColor fill = highlight ? highlightedColor : binColor(bin_nr, numBins);
+ QColor border = highlight ? highlightedBorderColor : ::borderColor;
if (innerLabel)
- innerLabel->setColor(highlight ? darkLabelColor : labelColor(bin_nr, numBins));
- item.drawSegment(angleFrom, angleTo,
- highlight ? highlightedColor : binColor(bin_nr, numBins),
- highlight ? highlightedBorderColor : ::borderColor);
+ innerLabel->setColor(highlight ? darkLabelColor : labelColor(bin_nr, numBins), fill);
+ item.drawSegment(angleFrom, angleTo, fill, border);
}
PieSeries::PieSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, const QString &categoryName,