1
0
mirror of synced 2024-12-13 08:21:07 +01:00
ImHex/plugins/builtin/source/content/pl_visualizers/scatter_plot.cpp
Nik f9a9ed4846
impr: Vastly improved 3D Visualizer (#1456)
Based entirely on @paxcut's amazing PR #1443

---------

Co-authored-by: paxcut <paxcut@outlook.com>
Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
2023-12-05 10:49:51 +01:00

33 lines
1.1 KiB
C++

#include <hex/helpers/utils.hpp>
#include <content/pl_visualizers/visualizer_helpers.hpp>
#include <implot.h>
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
namespace hex::plugin::builtin {
void drawScatterPlotVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
static std::vector<float> xValues, yValues;
auto xPattern = arguments[0].toPattern();
auto yPattern = arguments[1].toPattern();
if (ImPlot::BeginPlot("##plot", ImVec2(400, 250), ImPlotFlags_CanvasOnly)) {
ImPlot::SetupAxes("X", "Y", ImPlotAxisFlags_AutoFit, ImPlotAxisFlags_AutoFit);
if (shouldReset) {
xValues.clear(); yValues.clear();
xValues = sampleData(patternToArray<float>(xPattern.get()), ImPlot::GetPlotSize().x * 4);
yValues = sampleData(patternToArray<float>(yPattern.get()), ImPlot::GetPlotSize().x * 4);
}
ImPlot::PlotScatter("##scatter", xValues.data(), yValues.data(), xValues.size());
ImPlot::EndPlot();
}
}
}