mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
2e2019dea7
commit
4f58e9aa62
5 changed files with 29 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -65,11 +65,11 @@ void PieSeries::Item::updatePositions(const QPointF ¢er, 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,
|
||||
|
|
Loading…
Add table
Reference in a new issue