135 lines
4.3 KiB
C++
135 lines
4.3 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 <qdebug.h>
|
|
#include <qnamespace.h>
|
|
#include <qobject.h>
|
|
#include <qsize.h>
|
|
|
|
BasicPlot::BasicPlot() : pimpl{std::make_unique<Impl>(*this)} {
|
|
init_plot();
|
|
}
|
|
|
|
BasicPlot::~BasicPlot() {}
|
|
|
|
void BasicPlot::set_matrix_size(const QSize& size) {
|
|
qDebug() << "set matrix size" << size;
|
|
matrix_size = size;
|
|
pimpl->set_matrix_size(size);
|
|
}
|
|
|
|
void BasicPlot::set_matrix_size(const int& w, const int& h) {
|
|
QSize size(w, h);
|
|
qDebug() << "set matrix size" << size;
|
|
matrix_size = size;
|
|
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() {
|
|
QVector<PointData> origin_data = {PointData{0, 0, 5}, PointData{0, 1, 3}, PointData{0, 2, 0},
|
|
PointData{1, 0, 5}, PointData{1, 1, 3}, PointData{1, 2, 9},
|
|
PointData{2, 0, 5}, PointData{2, 1, 3}, PointData{2, 2, 3},
|
|
PointData{3, 0, 5}, PointData{3, 1, 3}, PointData{3, 2, 8}};
|
|
QCPColorMap* cpmp = new QCPColorMap(xAxis, yAxis);
|
|
qDebug() << "cpmp->data()->setSize():" << matrix_size;
|
|
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());
|
|
|
|
for (const auto& item : origin_data) {
|
|
cpmp->data()->setCell(item.x, item.y, item.z);
|
|
}
|
|
|
|
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::dataChanged(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)) {
|
|
if (cpmp->data()->alpha(item.x, item.y)) {
|
|
cpmp->data()->setCell(item.x, item.y, item.z);
|
|
}
|
|
}
|
|
}
|
|
|
|
replot();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
using namespace creeper;
|
|
auto HeatMapPlot::paintEvent(QPaintEvent* event) -> void {
|
|
QCustomPlot::paintEvent(event);
|
|
}
|