Returned support of detail dots to linear chart view class.
This commit is contained in:
parent
25c97a3ee8
commit
3e55380eed
|
@ -939,16 +939,12 @@ void ChartWidget::setupChartArea() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto detailsPaintContext = DetailsPaintContext{
|
|
||||||
.xIndex = (_details.widget && (detailsAlpha > 0.))
|
|
||||||
? _details.widget->xIndex()
|
|
||||||
: -1,
|
|
||||||
};
|
|
||||||
if (_chartData) {
|
if (_chartData) {
|
||||||
// p.setRenderHint(
|
// p.setRenderHint(
|
||||||
// QPainter::Antialiasing,
|
// QPainter::Antialiasing,
|
||||||
// !_animationController.isFPSSlow()
|
// !_animationController.isFPSSlow()
|
||||||
// || !_animationController.animating());
|
// || !_animationController.animating());
|
||||||
|
PainterHighQualityEnabler hp(p);
|
||||||
_linearChartView->paint(
|
_linearChartView->paint(
|
||||||
p,
|
p,
|
||||||
_chartData,
|
_chartData,
|
||||||
|
@ -956,7 +952,6 @@ void ChartWidget::setupChartArea() {
|
||||||
_animationController.currentXLimits(),
|
_animationController.currentXLimits(),
|
||||||
_animationController.currentHeightLimits(),
|
_animationController.currentHeightLimits(),
|
||||||
chartRect,
|
chartRect,
|
||||||
detailsPaintContext,
|
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -971,13 +966,16 @@ void ChartWidget::setupChartArea() {
|
||||||
QRect(bottom.x(), bottom.y(), bottom.width(), st::lineWidth),
|
QRect(bottom.x(), bottom.y(), bottom.width(), st::lineWidth),
|
||||||
st::windowSubTextFg);
|
st::windowSubTextFg);
|
||||||
}
|
}
|
||||||
for (const auto &dot : detailsPaintContext.dots) {
|
if (_details.widget && (detailsAlpha > 0.)) {
|
||||||
p.setBrush(st::boxBg);
|
|
||||||
p.setPen(QPen(dot.color, st::statisticsChartLineWidth));
|
|
||||||
const auto r = st::statisticsDetailsDotRadius;
|
|
||||||
auto hq = PainterHighQualityEnabler(p);
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
auto o = ScopedPainterOpacity(p, dot.alpha * detailsAlpha);
|
auto o = ScopedPainterOpacity(p, detailsAlpha);
|
||||||
p.drawEllipse(dot.point, r, r);
|
_linearChartView->paintSelectedXIndex(
|
||||||
|
p,
|
||||||
|
_chartData,
|
||||||
|
_animationController.currentXLimits(),
|
||||||
|
_animationController.currentHeightLimits(),
|
||||||
|
chartRect,
|
||||||
|
_details.widget->xIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
p.setPen(st::windowSubTextFg);
|
p.setPen(st::windowSubTextFg);
|
||||||
|
@ -1067,7 +1065,6 @@ void ChartWidget::setupFooter() {
|
||||||
QPainter &p,
|
QPainter &p,
|
||||||
const QRect &r) {
|
const QRect &r) {
|
||||||
if (_chartData) {
|
if (_chartData) {
|
||||||
auto detailsPaintContext = DetailsPaintContext{ .xIndex = -1 };
|
|
||||||
p.fillRect(r, st::boxBg);
|
p.fillRect(r, st::boxBg);
|
||||||
// p.setRenderHint(
|
// p.setRenderHint(
|
||||||
// QPainter::Antialiasing,
|
// QPainter::Antialiasing,
|
||||||
|
@ -1081,7 +1078,6 @@ void ChartWidget::setupFooter() {
|
||||||
fullXLimits,
|
fullXLimits,
|
||||||
_animationController.currentFooterHeightLimits(),
|
_animationController.currentFooterHeightLimits(),
|
||||||
r,
|
r,
|
||||||
detailsPaintContext,
|
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,7 +64,6 @@ void LinearChartView::paint(
|
||||||
const Limits &xPercentageLimits,
|
const Limits &xPercentageLimits,
|
||||||
const Limits &heightLimits,
|
const Limits &heightLimits,
|
||||||
const QRect &rect,
|
const QRect &rect,
|
||||||
DetailsPaintContext &detailsPaintContext,
|
|
||||||
bool footer) {
|
bool footer) {
|
||||||
|
|
||||||
const auto cacheToken = LinearChartView::CacheToken(
|
const auto cacheToken = LinearChartView::CacheToken(
|
||||||
|
@ -128,6 +127,47 @@ void LinearChartView::paint(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LinearChartView::paintSelectedXIndex(
|
||||||
|
QPainter &p,
|
||||||
|
const Data::StatisticalChart &chartData,
|
||||||
|
const Limits &xPercentageLimits,
|
||||||
|
const Limits &heightLimits,
|
||||||
|
const QRect &rect,
|
||||||
|
int selectedXIndex) {
|
||||||
|
if (selectedXIndex < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
p.setBrush(st::boxBg);
|
||||||
|
const auto r = st::statisticsDetailsDotRadius;
|
||||||
|
const auto i = selectedXIndex;
|
||||||
|
const auto isSameToken = (_selectedPoints.lastXIndex == selectedXIndex)
|
||||||
|
&& (_selectedPoints.lastHeightLimits.min == heightLimits.min)
|
||||||
|
&& (_selectedPoints.lastHeightLimits.max == heightLimits.max);
|
||||||
|
for (const auto &line : chartData.lines) {
|
||||||
|
const auto lineAlpha = alpha(line.id);
|
||||||
|
const auto useCache = isSameToken
|
||||||
|
|| (lineAlpha < 1. && !isEnabled(line.id));
|
||||||
|
if (!useCache) {
|
||||||
|
// Calculate.
|
||||||
|
const auto xPoint = rect.width()
|
||||||
|
* ((chartData.xPercentage[i] - xPercentageLimits.min)
|
||||||
|
/ (xPercentageLimits.max - xPercentageLimits.min));
|
||||||
|
const auto yPercentage = (line.y[i] - heightLimits.min)
|
||||||
|
/ float64(heightLimits.max - heightLimits.min);
|
||||||
|
const auto yPoint = (1. - yPercentage) * rect.height();
|
||||||
|
_selectedPoints.points[line.id] = QPointF(xPoint, yPoint)
|
||||||
|
+ rect.topLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Paint.
|
||||||
|
auto o = ScopedPainterOpacity(p, lineAlpha * p.opacity());
|
||||||
|
p.setPen(QPen(line.color, st::statisticsChartLineWidth));
|
||||||
|
p.drawEllipse(_selectedPoints.points[line.id], r, r);
|
||||||
|
}
|
||||||
|
_selectedPoints.lastXIndex = selectedXIndex;
|
||||||
|
_selectedPoints.lastHeightLimits = heightLimits;
|
||||||
|
}
|
||||||
|
|
||||||
void LinearChartView::setEnabled(int id, bool enabled, crl::time now) {
|
void LinearChartView::setEnabled(int id, bool enabled, crl::time now) {
|
||||||
const auto it = _entries.find(id);
|
const auto it = _entries.find(id);
|
||||||
if (it == end(_entries)) {
|
if (it == end(_entries)) {
|
||||||
|
|
|
@ -16,7 +16,6 @@ struct StatisticalChart;
|
||||||
namespace Statistic {
|
namespace Statistic {
|
||||||
|
|
||||||
struct Limits;
|
struct Limits;
|
||||||
struct DetailsPaintContext;
|
|
||||||
|
|
||||||
class LinearChartView {
|
class LinearChartView {
|
||||||
public:
|
public:
|
||||||
|
@ -29,9 +28,16 @@ public:
|
||||||
const Limits &xPercentageLimits,
|
const Limits &xPercentageLimits,
|
||||||
const Limits &heightLimits,
|
const Limits &heightLimits,
|
||||||
const QRect &rect,
|
const QRect &rect,
|
||||||
DetailsPaintContext &detailsPaintContext,
|
|
||||||
bool footer);
|
bool footer);
|
||||||
|
|
||||||
|
void paintSelectedXIndex(
|
||||||
|
QPainter &p,
|
||||||
|
const Data::StatisticalChart &chartData,
|
||||||
|
const Limits &xPercentageLimits,
|
||||||
|
const Limits &heightLimits,
|
||||||
|
const QRect &rect,
|
||||||
|
int selectedXIndex);
|
||||||
|
|
||||||
void setEnabled(int id, bool enabled, crl::time now);
|
void setEnabled(int id, bool enabled, crl::time now);
|
||||||
[[nodiscard]] bool isEnabled(int id) const;
|
[[nodiscard]] bool isEnabled(int id) const;
|
||||||
[[nodiscard]] bool isFinished() const;
|
[[nodiscard]] bool isFinished() const;
|
||||||
|
@ -82,6 +88,13 @@ private:
|
||||||
base::flat_map<int, Cache> _mainCaches;
|
base::flat_map<int, Cache> _mainCaches;
|
||||||
base::flat_map<int, Cache> _footerCaches;
|
base::flat_map<int, Cache> _footerCaches;
|
||||||
|
|
||||||
|
struct SelectedPoints final {
|
||||||
|
int lastXIndex = -1;
|
||||||
|
Limits lastHeightLimits;
|
||||||
|
base::flat_map<int, QPointF> points;
|
||||||
|
};
|
||||||
|
SelectedPoints _selectedPoints;
|
||||||
|
|
||||||
struct Entry final {
|
struct Entry final {
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
crl::time startedAt = 0;
|
crl::time startedAt = 0;
|
||||||
|
|
|
@ -14,16 +14,4 @@ struct Limits final {
|
||||||
float64 max = 0;
|
float64 max = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Dot on line charts.
|
|
||||||
struct DetailsPaintContext final {
|
|
||||||
int xIndex = -1;
|
|
||||||
|
|
||||||
struct Dot {
|
|
||||||
QPointF point;
|
|
||||||
QColor color;
|
|
||||||
float64 alpha = 0.;
|
|
||||||
};
|
|
||||||
std::vector<Dot> dots;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Statistic
|
} // namespace Statistic
|
||||||
|
|
Loading…
Reference in New Issue
Block a user