95 lines
3.0 KiB
C++
95 lines
3.0 KiB
C++
//
|
|
// Created by Lenn on 2025/10/17.
|
|
//
|
|
|
|
#include "heatmap.hh"
|
|
#include "heatmap.impl.hh"
|
|
#include "qcustomplot/qcustomplot.h"
|
|
#include <qcolor.h>
|
|
#include <qcolormap.h>
|
|
#include <qcontainerfwd.h>
|
|
#include <qnamespace.h>
|
|
#include <qobject.h> #include <qsize.h>
|
|
|
|
BasicPlot::BasicPlot() : pimpl{std::make_unique<Impl>(*this)} {}
|
|
|
|
void BasicPlot::set_matrix_size(const QSize& size) {
|
|
pimpl->set_matrix_size(size);
|
|
}
|
|
|
|
void BasicPlot::set_matrix_size(const int& w, const int& h) {
|
|
QSize size(w, h);
|
|
pimpl->set_matrix_size(size);
|
|
}
|
|
|
|
void BasicPlot::set_xlabel_text(const QString& text) {
|
|
pimpl->set_xlabel_text(text);
|
|
}
|
|
|
|
void BasicPlot::set_ylabel_text(const QString& text) {
|
|
pimpl->set_ylabel_text(text);
|
|
}
|
|
|
|
void BasicPlot::load_theme_manager(ThemeManager& mgr) {
|
|
|
|
}
|
|
|
|
QSize BasicPlot::get_matrix_size() {
|
|
return matrix_size;
|
|
}
|
|
void BasicPlot::init_plot() {
|
|
QCPColorMap* cpmp = new QCPColorMap(xAxis, yAxis);
|
|
cpmp->data()->setSize(matrix_size.width(), matrix_size.height());
|
|
cpmp->data()->setRange(QCPRange(0.5, matrix_size.width()), (QCPRange(0.5, matrix_size.height())));
|
|
// cpmp ->setSize(matrix_size.width(), matrix_size.height());
|
|
// cpmp ->setRange(QCPRange(0.5, matrix_size.width() - 0.5), QCPRange(0.5, matrix_size.height() - 0.5));
|
|
QSharedPointer<QCPAxisTickerText> xticker(new QCPAxisTickerText);
|
|
QSharedPointer<QCPAxisTickerText> yticker(new QCPAxisTickerText);
|
|
xticker->setSubTickCount(1);
|
|
xticker->setSubTickCount(1);
|
|
xAxis->setTicker(xticker);
|
|
yAxis->setTicker(yticker);
|
|
xAxis->grid()->setPen(Qt::NoPen);
|
|
yAxis->grid()->setPen(Qt::NoPen);
|
|
xAxis->grid()->setSubGridVisible(true);
|
|
yAxis->grid()->setSubGridVisible(true);
|
|
xAxis->setSubTicks(true);
|
|
yAxis->setSubTicks(true);
|
|
xAxis->setTickLength(0);
|
|
yAxis->setTickLength(0);
|
|
xAxis->setSubTickLength(6);
|
|
yAxis->setSubTickLength(6);
|
|
xAxis->setRange(0, matrix_size.width());
|
|
yAxis->setRange(0, matrix_size.height());
|
|
|
|
QCPColorScale* color_scale = new QCPColorScale(this);
|
|
color_scale->setType(QCPAxis::atBottom);
|
|
this->plotLayout()->addElement(1, 0, color_scale);
|
|
cpmp->setColorScale(color_scale);
|
|
QCPColorGradient gradient;
|
|
gradient.setColorStopAt(0.0, QColor("#F6EFA6"));
|
|
gradient.setColorStopAt(1.0, QColor("#BF444C"));
|
|
cpmp->setGradient(gradient);
|
|
|
|
cpmp->setDataRange(QCPRange(0, 10));
|
|
cpmp->setInterpolate(false);
|
|
|
|
QCPMarginGroup *margin_group = new QCPMarginGroup(this);
|
|
axisRect()->setMarginGroup(QCP::msLeft | QCP::msRight, margin_group);
|
|
color_scale->setMarginGroup(QCP::msLeft | QCP::msRight, margin_group);
|
|
}
|
|
|
|
void BasicPlot::update_dynamic_heatmap(QVector<PointData>& map) {
|
|
auto *cpmp = static_cast<QCPColorMap*>(this->plottable(0));
|
|
|
|
size_t key_size = cpmp->data()->keySize();
|
|
size_t value_size = cpmp->data()->valueSize();
|
|
for (auto& item: map) {
|
|
if (cpmp->data()->alpha(item.x, item.y)) {
|
|
cpmp->data()->setCell(item.x, item.y, item.z);
|
|
}
|
|
}
|
|
|
|
replot();
|
|
}
|