From f0053d46194bb75dc8f277d7ba6f91ea02effae7 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 3 Apr 2026 14:52:35 -0700 Subject: [PATCH] jotpluggler: state transition view is only for enums (#37761) * jotpluggler: state transition view is only for enums * cleaner --- tools/jotpluggler/plot.cc | 82 ++------------------------------------- 1 file changed, 3 insertions(+), 79 deletions(-) diff --git a/tools/jotpluggler/plot.cc b/tools/jotpluggler/plot.cc index a3c68ddcef..5d9d644808 100644 --- a/tools/jotpluggler/plot.cc +++ b/tools/jotpluggler/plot.cc @@ -6,7 +6,6 @@ #include #include #include -#include constexpr double PLOT_Y_PAD_FRACTION = 0.4; @@ -74,10 +73,6 @@ struct StateBlock { std::string label; }; -struct PaneEnumContext { - std::vector enums; -}; - struct PaneValueFormatContext { SeriesFormat format; bool valid = false; @@ -106,38 +101,6 @@ bool curves_are_bool_like(const std::vector &prepared_curves) { return true; } -bool curve_is_state_like(const PreparedCurve &curve) { - if (!curve.display_info.integer_like || curve.xs.size() < 2 || curve.xs.size() != curve.ys.size()) { - return false; - } - if (curve.enum_info != nullptr) { - return true; - } - std::unordered_set distinct_values; - for (double value : curve.ys) { - if (!std::isfinite(value)) { - continue; - } - distinct_values.insert(static_cast(std::llround(value))); - if (distinct_values.size() > 12) { - return false; - } - } - return !distinct_values.empty(); -} - -bool curves_use_state_blocks(const std::vector &prepared_curves) { - if (prepared_curves.empty()) { - return false; - } - for (const PreparedCurve &curve : prepared_curves) { - if (!curve_is_state_like(curve)) { - return false; - } - } - return true; -} - ImU32 state_block_color(int value, float alpha = 1.0f) { static constexpr std::array, 8> kPalette = {{ {{111, 143, 175}}, @@ -307,36 +270,6 @@ std::optional app_sample_xy_value_at_time(const std::vector &xs, return y0 + (y1 - y0) * alpha; } -int format_enum_axis_tick(double value, char *buf, int size, void *user_data) { - const auto *ctx = static_cast(user_data); - const int idx = static_cast(std::llround(value)); - if (ctx != nullptr && idx >= 0 && std::abs(value - static_cast(idx)) < 0.01) { - std::vector names; - names.reserve(ctx->enums.size()); - for (const EnumInfo *info : ctx->enums) { - if (info == nullptr || static_cast(idx) >= info->names.size()) { - continue; - } - const std::string &name = info->names[static_cast(idx)]; - if (name.empty()) continue; - if (std::find(names.begin(), names.end(), std::string_view(name)) == names.end()) { - names.emplace_back(name); - } - } - if (!names.empty()) { - std::string joined; - for (size_t i = 0; i < names.size(); ++i) { - if (i != 0) { - joined += ", "; - } - joined += names[i]; - } - return std::snprintf(buf, size, "%d (%s)", idx, joined.c_str()); - } - } - return std::snprintf(buf, size, "%.6g", value); -} - int format_numeric_axis_tick(double value, char *buf, int size, void *user_data) { const auto *ctx = static_cast(user_data); if (ctx == nullptr || !ctx->valid) { @@ -831,23 +764,16 @@ void draw_plot(const AppSession &session, Pane *pane, UiState *state) { } const PlotBounds bounds = compute_plot_bounds(*pane, prepared_curves, *state); - PaneEnumContext enum_context; PaneValueFormatContext pane_value_format; - const bool state_block_mode = curves_use_state_blocks(prepared_curves); - bool all_enum_curves = !prepared_curves.empty(); + bool state_block_mode = !prepared_curves.empty(); size_t max_legend_label_width = 0; for (const PreparedCurve &curve : prepared_curves) { max_legend_label_width = std::max(max_legend_label_width, curve.label.size()); - if (curve.enum_info != nullptr) { - enum_context.enums.push_back(curve.enum_info); - } else { - all_enum_curves = false; + if (curve.enum_info == nullptr) { + state_block_mode = false; merge_pane_value_format(&pane_value_format, curve.display_info); } } - if (prepared_curves.empty()) { - all_enum_curves = false; - } const int supported_count = static_cast(prepared_curves.size()); const ImVec2 plot_size = ImGui::GetContentRegionAvail(); const bool has_cursor_time = state->has_tracker_time; @@ -895,8 +821,6 @@ void draw_plot(const AppSession &session, Pane *pane, UiState *state) { ImPlot::SetupAxisFormat(ImAxis_X1, "%.1f"); if (state_block_mode) { ImPlot::SetupAxisLimits(ImAxis_Y1, 0.0, 1.0, ImPlotCond_Always); - } else if (all_enum_curves && !enum_context.enums.empty()) { - ImPlot::SetupAxisFormat(ImAxis_Y1, format_enum_axis_tick, &enum_context); } else if (pane_value_format.valid) { ImPlot::SetupAxisFormat(ImAxis_Y1, format_numeric_axis_tick, &pane_value_format); } else {