aboutsummaryrefslogtreecommitdiff
path: root/core/client.cpp
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2026-06-11 22:54:09 +0200
committerPaul Oliver <contact@pauloliver.dev>2026-06-11 22:54:09 +0200
commitae277ee25856e5f49d5651dd670c7c12d8116c1c (patch)
tree898b0257a73185d647974c8ec5afbea9ac83295e /core/client.cpp
parente35f39df2cc1570d33a45b98dff48184db023d08 (diff)
Makes heat-map scale plot-independent
Diffstat (limited to 'core/client.cpp')
-rw-r--r--core/client.cpp76
1 files changed, 36 insertions, 40 deletions
diff --git a/core/client.cpp b/core/client.cpp
index ca2f878..ba0f3d6 100644
--- a/core/client.cpp
+++ b/core/client.cpp
@@ -142,6 +142,7 @@ typedef int (*AxisFormatter)(double value, char *buff, int size, void *data);
struct Plot {
Plot(const char *name, const char *section);
virtual ~Plot();
+ virtual void handle_input(int key, int mods);
virtual void flag_for_reset();
const char *get_name() const;
const char *get_section() const;
@@ -182,6 +183,7 @@ private:
struct PlotHeatmap : public Plot {
PlotHeatmap(const char *name, const char *section, const char *trace_key);
+ void handle_input(int key, int mods);
void flag_for_reset();
private:
float right_margin() const;
@@ -190,6 +192,7 @@ private:
void render_end(const ImVec2 &frame_size);
void render_post(const ImVec2 &frame_size);
const char *m_trace_key;
+ float m_tex_scale_pow;
float m_tex_scale_high;
size_t m_tex_rendered_last;
size_t m_rows_rendered;
@@ -343,7 +346,6 @@ int g_plot_cols = 2;
size_t g_plot_col_selected;
size_t g_plot_row_selected;
float g_plot_height = 300.f;
-float g_hm_scale_pow = HM_SCALE_POW_MIN;
ImPlotColormap g_hm_colormap_id;
std::map<const char *, TraceNamed<ImS64> *, StringComparator> g_trace_map;
@@ -472,6 +474,11 @@ Plot::Plot(const char *name, const char *section) : m_visible(true), m_name(name
Plot::~Plot() {}
+void Plot::handle_input(int key, int mods) {
+ (void)key;
+ (void)mods;
+}
+
void Plot::flag_for_reset() {}
const char *Plot::get_name() const {
@@ -643,7 +650,23 @@ void PlotStacked::render_internal(const ImVec2 &frame_size) {
// ----------------------------------------------------------------------------
// [SECTION] PlotHeatmap definition
// ----------------------------------------------------------------------------
-PlotHeatmap::PlotHeatmap(const char *name, const char *section, const char *trace_key) : Plot(name, section), m_trace_key(trace_key), m_tex_scale_high(0.f), m_tex_rendered_last(0), m_rows_rendered(0), m_tex_id(0), m_tex_render(), m_needs_reset(true) {}
+PlotHeatmap::PlotHeatmap(const char *name, const char *section, const char *trace_key) : Plot(name, section), m_trace_key(trace_key), m_tex_scale_pow(-1.f), m_tex_scale_high(0.f), m_tex_rendered_last(0), m_rows_rendered(0), m_tex_id(0), m_tex_render(), m_needs_reset(true) {}
+
+void PlotHeatmap::handle_input(int key, int mods) {
+ switch (mods) {
+ case GLFW_MOD_CONTROL:
+ switch (key) {
+ case GLFW_KEY_K:
+ m_tex_scale_pow = std::clamp(m_tex_scale_pow - 1, HM_SCALE_POW_MIN, HM_SCALE_POW_MAX);
+ m_needs_reset = true;
+ break;
+ case GLFW_KEY_L:
+ m_tex_scale_pow = std::clamp(m_tex_scale_pow + 1, HM_SCALE_POW_MIN, HM_SCALE_POW_MAX);
+ m_needs_reset = true;
+ break;
+ }
+ }
+}
void PlotHeatmap::flag_for_reset() {
m_needs_reset = true;
@@ -685,7 +708,7 @@ void PlotHeatmap::render_internal(const ImVec2 &frame_size) {
return;
}
- if (g_hm_scale_pow == HM_SCALE_POW_MIN) {
+ if (m_tex_scale_pow == HM_SCALE_POW_MIN) {
ImS64 max = 0;
for (size_t i = trace->start_offset(); i < trace->size(); i++) {
@@ -694,7 +717,7 @@ void PlotHeatmap::render_internal(const ImVec2 &frame_size) {
m_tex_scale_high = (float)max;
} else {
- m_tex_scale_high = pow(2.f, g_hm_scale_pow);
+ m_tex_scale_high = pow(2.f, m_tex_scale_pow);
}
m_tex_render.reserve((trace->size() - m_tex_rendered_last) * 3);
@@ -756,7 +779,7 @@ void PlotHeatmap::render_end(const ImVec2 &frame_size) {
ImVec2 bmax(g_hm_left + g_hm_pixel_count * pow(2.f, g_hm_pixel_pow), (float)g_x_axis_double.back());
ImVec2 uv0(0.f, 1.f);
ImVec2 uv1(1.f, 0.f);
- double scale_max = g_hm_scale_pow == HM_SCALE_POW_MIN ? (double)m_tex_scale_high : pow(2., (double)g_hm_scale_pow);
+ double scale_max = m_tex_scale_pow == HM_SCALE_POW_MIN ? (double)m_tex_scale_high : pow(2., (double)m_tex_scale_pow);
ImPlot::PlotImage(get_name(), (ImTextureID)m_tex_id, bmin, bmax, uv0, uv1);
ImGui::SameLine();
@@ -777,16 +800,6 @@ int64_t data_max_hm_pixel_pow(void) {
return (int64_t)floor(log2((double)(MVEC_SIZE - g_hm_left) / (double)g_hm_pixel_count));
}
-void data_flag_heatmaps_for_reset(void) {
- for (auto &heatmap : g_core_plots_heatmaps) {
- heatmap.flag_for_reset();
- }
-
- for (auto &heatmap : g_arch_plots_heatmaps) {
- heatmap.flag_for_reset();
- }
-}
-
void data_on_field_change(void) {
g_entries = std::clamp(g_entries, 1l, DEFVAL_ENTRIES);
g_nth = std::clamp(g_nth, DEFVAL_NTH, INT64_MAX);
@@ -1040,7 +1053,6 @@ void gui_render_data_col(void) {
ImGui::SeparatorText("Layout");
ImGui::DragInt("cols", &g_plot_cols, 1, PLOT_MIN_COLS, PLOT_MAX_COLS);
ImGui::DragFloat("plot-height", &g_plot_height, PLOT_HEIGHT_INTERVAL, PLOT_MIN_HEIGHT, PLOT_MAX_HEIGHT, "%.0f");
- ImGui::DragFloat("hm-pow", &g_hm_scale_pow, HM_SCALE_POW_INTERVAL, HM_SCALE_POW_MIN, HM_SCALE_POW_MAX, "%.0f");
ImGui::SeparatorText("Plots");
if (ImGui::Button("Show all", ImVec2(-1.f, 0.f))) for (auto &plot : g_plots) plot->m_visible = true;
@@ -1271,18 +1283,6 @@ void app_key_callback_plot_maximized(int key, int mods) {
case GLFW_KEY_C:
glfwSetWindowShouldClose(g_window, GLFW_TRUE);
break;
- case GLFW_KEY_COMMA:
- g_hm_scale_pow = std::max(g_hm_scale_pow - HM_SCALE_POW_INTERVAL, HM_SCALE_POW_MIN);
- data_flag_heatmaps_for_reset();
- break;
- case GLFW_KEY_PERIOD:
- g_hm_scale_pow = std::min(g_hm_scale_pow + HM_SCALE_POW_INTERVAL, HM_SCALE_POW_MAX);
- data_flag_heatmaps_for_reset();
- break;
- case GLFW_KEY_0:
- g_hm_scale_pow = HM_SCALE_POW_MIN;
- data_flag_heatmaps_for_reset();
- break;
}
break;
@@ -1299,6 +1299,10 @@ void app_key_callback_plot_maximized(int key, int mods) {
break;
}
+
+ if (g_plot_selected->m_visible) {
+ g_plot_selected->handle_input(key, mods);
+ }
}
void app_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
@@ -1343,18 +1347,6 @@ void app_key_callback(GLFWwindow* window, int key, int scancode, int action, int
g_plot_height = std::max(g_plot_height - PLOT_HEIGHT_INTERVAL, PLOT_MIN_HEIGHT);
gui_plot_queue_scroll_to_position(false);
break;
- case GLFW_KEY_COMMA:
- g_hm_scale_pow = std::max(g_hm_scale_pow - HM_SCALE_POW_INTERVAL, HM_SCALE_POW_MIN);
- data_flag_heatmaps_for_reset();
- break;
- case GLFW_KEY_PERIOD:
- g_hm_scale_pow = std::min(g_hm_scale_pow + HM_SCALE_POW_INTERVAL, HM_SCALE_POW_MAX);
- data_flag_heatmaps_for_reset();
- break;
- case GLFW_KEY_0:
- g_hm_scale_pow = HM_SCALE_POW_MIN;
- data_flag_heatmaps_for_reset();
- break;
}
break;
@@ -1389,6 +1381,10 @@ void app_key_callback(GLFWwindow* window, int key, int scancode, int action, int
break;
}
+
+ if (g_plot_selected->m_visible) {
+ g_plot_selected->handle_input(key, mods);
+ }
}
void app_mouse_button_callback(GLFWwindow* window, int button, int action, int mods) {