Cached both main and footer charts in single linear chart view.
This commit is contained in:
parent
2055cc70d1
commit
25c97a3ee8
|
@ -822,7 +822,7 @@ ChartWidget::ChartWidget(not_null<Ui::RpWidget*> parent)
|
|||
, _animationController([=] {
|
||||
_chartArea->update();
|
||||
if (_animationController.footerAnimating()
|
||||
|| !_linearChartView.main->isFinished()) {
|
||||
|| !_linearChartView->isFinished()) {
|
||||
_footer->update();
|
||||
}
|
||||
}) {
|
||||
|
@ -900,7 +900,7 @@ void ChartWidget::setupChartArea() {
|
|||
now,
|
||||
_horizontalLines,
|
||||
_bottomLine.dates,
|
||||
_linearChartView.main);
|
||||
_linearChartView);
|
||||
|
||||
const auto chartRect = chartAreaRect();
|
||||
|
||||
|
@ -934,7 +934,7 @@ void ChartWidget::setupChartArea() {
|
|||
for (const auto &line : _chartData.lines) {
|
||||
_details.widget->setLineAlpha(
|
||||
line.id,
|
||||
_linearChartView.main->alpha(line.id));
|
||||
_linearChartView->alpha(line.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -949,15 +949,15 @@ void ChartWidget::setupChartArea() {
|
|||
// QPainter::Antialiasing,
|
||||
// !_animationController.isFPSSlow()
|
||||
// || !_animationController.animating());
|
||||
PainterHighQualityEnabler hp(p);
|
||||
_linearChartView.main->paint(
|
||||
_linearChartView->paint(
|
||||
p,
|
||||
_chartData,
|
||||
_animationController.currentXIndices(),
|
||||
_animationController.currentXLimits(),
|
||||
_animationController.currentHeightLimits(),
|
||||
chartRect,
|
||||
detailsPaintContext);
|
||||
detailsPaintContext,
|
||||
false);
|
||||
}
|
||||
|
||||
for (auto &horizontalLine : _horizontalLines) {
|
||||
|
@ -1074,14 +1074,15 @@ void ChartWidget::setupFooter() {
|
|||
// !_animationController.isFPSSlow()
|
||||
// || !_animationController.animating());
|
||||
PainterHighQualityEnabler hp(p);
|
||||
_linearChartView.footer->paint(
|
||||
_linearChartView->paint(
|
||||
p,
|
||||
_chartData,
|
||||
{ 0., float64(_chartData.x.size() - 1) },
|
||||
fullXLimits,
|
||||
_animationController.currentFooterHeightLimits(),
|
||||
r,
|
||||
detailsPaintContext);
|
||||
detailsPaintContext,
|
||||
true);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1097,7 +1098,7 @@ void ChartWidget::setupFooter() {
|
|||
_animationController.setXPercentageLimits(
|
||||
_chartData,
|
||||
xPercentageLimits,
|
||||
_linearChartView.main,
|
||||
_linearChartView,
|
||||
now);
|
||||
updateChartFullWidth(_chartArea->width());
|
||||
updateBottomDates();
|
||||
|
@ -1215,12 +1216,12 @@ void ChartWidget::setupFilterButtons() {
|
|||
_filterButtons->buttonEnabledChanges(
|
||||
) | rpl::start_with_next([=](const ChartLinesFilterWidget::Entry &e) {
|
||||
const auto now = crl::now();
|
||||
_linearChartView.main->setEnabled(e.id, e.enabled, now);
|
||||
_linearChartView->setEnabled(e.id, e.enabled, now);
|
||||
|
||||
_animationController.setXPercentageLimits(
|
||||
_chartData,
|
||||
_animationController.currentXLimits(),
|
||||
_linearChartView.main,
|
||||
_linearChartView,
|
||||
now);
|
||||
}, _filterButtons->lifetime());
|
||||
}
|
||||
|
@ -1228,8 +1229,7 @@ void ChartWidget::setupFilterButtons() {
|
|||
void ChartWidget::setChartData(Data::StatisticalChart chartData) {
|
||||
_chartData = std::move(chartData);
|
||||
|
||||
_linearChartView.main = std::make_unique<LinearChartView>();
|
||||
_linearChartView.footer = std::make_unique<LinearChartView>();
|
||||
_linearChartView = std::make_unique<LinearChartView>();
|
||||
|
||||
setupDetails();
|
||||
setupFilterButtons();
|
||||
|
@ -1237,7 +1237,7 @@ void ChartWidget::setChartData(Data::StatisticalChart chartData) {
|
|||
_animationController.setXPercentageLimits(
|
||||
_chartData,
|
||||
{ _chartData.xPercentage.front(), _chartData.xPercentage.back() },
|
||||
_linearChartView.main,
|
||||
_linearChartView,
|
||||
0);
|
||||
updateChartFullWidth(_chartArea->width());
|
||||
updateBottomDates();
|
||||
|
|
|
@ -131,10 +131,7 @@ private:
|
|||
base::unique_qptr<ChartLinesFilterWidget> _filterButtons;
|
||||
Data::StatisticalChart _chartData;
|
||||
|
||||
struct {
|
||||
std::unique_ptr<LinearChartView> main;
|
||||
std::unique_ptr<LinearChartView> footer;
|
||||
} _linearChartView;
|
||||
std::unique_ptr<LinearChartView> _linearChartView;
|
||||
|
||||
struct {
|
||||
base::unique_qptr<PointDetailsWidget> widget;
|
||||
|
|
|
@ -64,7 +64,8 @@ void LinearChartView::paint(
|
|||
const Limits &xPercentageLimits,
|
||||
const Limits &heightLimits,
|
||||
const QRect &rect,
|
||||
DetailsPaintContext &detailsPaintContext) {
|
||||
DetailsPaintContext &detailsPaintContext,
|
||||
bool footer) {
|
||||
|
||||
const auto cacheToken = LinearChartView::CacheToken(
|
||||
xIndices,
|
||||
|
@ -72,42 +73,38 @@ void LinearChartView::paint(
|
|||
heightLimits,
|
||||
rect.size());
|
||||
|
||||
const auto imageSize = rect.size() * style::DevicePixelRatio();
|
||||
const auto cacheScale = 1. / style::DevicePixelRatio();
|
||||
auto &caches = (footer ? _footerCaches : _mainCaches);
|
||||
|
||||
for (auto i = 0; i < chartData.lines.size(); i++) {
|
||||
const auto &line = chartData.lines[i];
|
||||
p.setOpacity(alpha(line.id));
|
||||
if (!p.opacity()) {
|
||||
continue;
|
||||
}
|
||||
if (p.opacity() < 1.) {
|
||||
// p.setRenderHint(QPainter::Antialiasing, false);
|
||||
}
|
||||
|
||||
////
|
||||
auto &cache = _caches[line.id];
|
||||
auto &cache = caches[line.id];
|
||||
|
||||
const auto isSameToken = (cache.lastToken == cacheToken);
|
||||
if (isSameToken && cache.hq) {
|
||||
if ((isSameToken && cache.hq)
|
||||
|| (p.opacity() < 1. && !isEnabled(line.id))) {
|
||||
p.drawImage(rect.topLeft(), cache.image);
|
||||
continue;
|
||||
}
|
||||
const auto ratio = style::DevicePixelRatio();
|
||||
cache.hq = isSameToken;
|
||||
auto image = QImage();
|
||||
image = QImage(
|
||||
rect.size() * style::DevicePixelRatio() * (isSameToken ? 1. : ratio),
|
||||
imageSize * (isSameToken ? 1. : cacheScale),
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
image.setDevicePixelRatio(style::DevicePixelRatio());
|
||||
image.fill(Qt::transparent);
|
||||
// image.fill(Qt::darkRed);
|
||||
{
|
||||
auto imagePainter = QPainter(&image);
|
||||
imagePainter.setRenderHint(QPainter::Antialiasing, true);
|
||||
if (isSameToken) {
|
||||
// PainterHighQualityEnabler hp(imagePainter);
|
||||
} else {
|
||||
imagePainter.scale(ratio, ratio);
|
||||
auto hq = PainterHighQualityEnabler(imagePainter);
|
||||
if (!isSameToken) {
|
||||
imagePainter.scale(cacheScale, cacheScale);
|
||||
}
|
||||
////
|
||||
|
||||
PaintChartLine(
|
||||
imagePainter,
|
||||
|
@ -120,7 +117,10 @@ void LinearChartView::paint(
|
|||
}
|
||||
|
||||
if (!isSameToken) {
|
||||
image = image.scaled(rect.size() * style::DevicePixelRatio(), Qt::IgnoreAspectRatio, Qt::FastTransformation);
|
||||
image = image.scaled(
|
||||
imageSize,
|
||||
Qt::IgnoreAspectRatio,
|
||||
Qt::FastTransformation);
|
||||
}
|
||||
p.drawImage(rect.topLeft(), image);
|
||||
cache.lastToken = cacheToken;
|
||||
|
|
|
@ -29,7 +29,8 @@ public:
|
|||
const Limits &xPercentageLimits,
|
||||
const Limits &heightLimits,
|
||||
const QRect &rect,
|
||||
DetailsPaintContext &detailsPaintContext);
|
||||
DetailsPaintContext &detailsPaintContext,
|
||||
bool footer);
|
||||
|
||||
void setEnabled(int id, bool enabled, crl::time now);
|
||||
[[nodiscard]] bool isEnabled(int id) const;
|
||||
|
@ -78,7 +79,8 @@ private:
|
|||
bool hq = false;
|
||||
};
|
||||
|
||||
base::flat_map<int, Cache> _caches;
|
||||
base::flat_map<int, Cache> _mainCaches;
|
||||
base::flat_map<int, Cache> _footerCaches;
|
||||
|
||||
struct Entry final {
|
||||
bool enabled = false;
|
||||
|
|
Loading…
Reference in New Issue