|
6 | 6 | #include <cmath> |
7 | 7 | #include <cstdio> |
8 | 8 | #include <limits> |
9 | | -#include <unordered_set> |
10 | 9 |
|
11 | 10 | constexpr double PLOT_Y_PAD_FRACTION = 0.4; |
12 | 11 |
|
@@ -74,10 +73,6 @@ struct StateBlock { |
74 | 73 | std::string label; |
75 | 74 | }; |
76 | 75 |
|
77 | | -struct PaneEnumContext { |
78 | | - std::vector<const EnumInfo *> enums; |
79 | | -}; |
80 | | - |
81 | 76 | struct PaneValueFormatContext { |
82 | 77 | SeriesFormat format; |
83 | 78 | bool valid = false; |
@@ -106,38 +101,6 @@ bool curves_are_bool_like(const std::vector<PreparedCurve> &prepared_curves) { |
106 | 101 | return true; |
107 | 102 | } |
108 | 103 |
|
109 | | -bool curve_is_state_like(const PreparedCurve &curve) { |
110 | | - if (!curve.display_info.integer_like || curve.xs.size() < 2 || curve.xs.size() != curve.ys.size()) { |
111 | | - return false; |
112 | | - } |
113 | | - if (curve.enum_info != nullptr) { |
114 | | - return true; |
115 | | - } |
116 | | - std::unordered_set<int> distinct_values; |
117 | | - for (double value : curve.ys) { |
118 | | - if (!std::isfinite(value)) { |
119 | | - continue; |
120 | | - } |
121 | | - distinct_values.insert(static_cast<int>(std::llround(value))); |
122 | | - if (distinct_values.size() > 12) { |
123 | | - return false; |
124 | | - } |
125 | | - } |
126 | | - return !distinct_values.empty(); |
127 | | -} |
128 | | - |
129 | | -bool curves_use_state_blocks(const std::vector<PreparedCurve> &prepared_curves) { |
130 | | - if (prepared_curves.empty()) { |
131 | | - return false; |
132 | | - } |
133 | | - for (const PreparedCurve &curve : prepared_curves) { |
134 | | - if (!curve_is_state_like(curve)) { |
135 | | - return false; |
136 | | - } |
137 | | - } |
138 | | - return true; |
139 | | -} |
140 | | - |
141 | 104 | ImU32 state_block_color(int value, float alpha = 1.0f) { |
142 | 105 | static constexpr std::array<std::array<uint8_t, 3>, 8> kPalette = {{ |
143 | 106 | {{111, 143, 175}}, |
@@ -307,36 +270,6 @@ std::optional<double> app_sample_xy_value_at_time(const std::vector<double> &xs, |
307 | 270 | return y0 + (y1 - y0) * alpha; |
308 | 271 | } |
309 | 272 |
|
310 | | -int format_enum_axis_tick(double value, char *buf, int size, void *user_data) { |
311 | | - const auto *ctx = static_cast<const PaneEnumContext *>(user_data); |
312 | | - const int idx = static_cast<int>(std::llround(value)); |
313 | | - if (ctx != nullptr && idx >= 0 && std::abs(value - static_cast<double>(idx)) < 0.01) { |
314 | | - std::vector<std::string_view> names; |
315 | | - names.reserve(ctx->enums.size()); |
316 | | - for (const EnumInfo *info : ctx->enums) { |
317 | | - if (info == nullptr || static_cast<size_t>(idx) >= info->names.size()) { |
318 | | - continue; |
319 | | - } |
320 | | - const std::string &name = info->names[static_cast<size_t>(idx)]; |
321 | | - if (name.empty()) continue; |
322 | | - if (std::find(names.begin(), names.end(), std::string_view(name)) == names.end()) { |
323 | | - names.emplace_back(name); |
324 | | - } |
325 | | - } |
326 | | - if (!names.empty()) { |
327 | | - std::string joined; |
328 | | - for (size_t i = 0; i < names.size(); ++i) { |
329 | | - if (i != 0) { |
330 | | - joined += ", "; |
331 | | - } |
332 | | - joined += names[i]; |
333 | | - } |
334 | | - return std::snprintf(buf, size, "%d (%s)", idx, joined.c_str()); |
335 | | - } |
336 | | - } |
337 | | - return std::snprintf(buf, size, "%.6g", value); |
338 | | -} |
339 | | - |
340 | 273 | int format_numeric_axis_tick(double value, char *buf, int size, void *user_data) { |
341 | 274 | const auto *ctx = static_cast<const PaneValueFormatContext *>(user_data); |
342 | 275 | if (ctx == nullptr || !ctx->valid) { |
@@ -831,23 +764,16 @@ void draw_plot(const AppSession &session, Pane *pane, UiState *state) { |
831 | 764 | } |
832 | 765 |
|
833 | 766 | const PlotBounds bounds = compute_plot_bounds(*pane, prepared_curves, *state); |
834 | | - PaneEnumContext enum_context; |
835 | 767 | PaneValueFormatContext pane_value_format; |
836 | | - const bool state_block_mode = curves_use_state_blocks(prepared_curves); |
837 | | - bool all_enum_curves = !prepared_curves.empty(); |
| 768 | + bool state_block_mode = !prepared_curves.empty(); |
838 | 769 | size_t max_legend_label_width = 0; |
839 | 770 | for (const PreparedCurve &curve : prepared_curves) { |
840 | 771 | max_legend_label_width = std::max(max_legend_label_width, curve.label.size()); |
841 | | - if (curve.enum_info != nullptr) { |
842 | | - enum_context.enums.push_back(curve.enum_info); |
843 | | - } else { |
844 | | - all_enum_curves = false; |
| 772 | + if (curve.enum_info == nullptr) { |
| 773 | + state_block_mode = false; |
845 | 774 | merge_pane_value_format(&pane_value_format, curve.display_info); |
846 | 775 | } |
847 | 776 | } |
848 | | - if (prepared_curves.empty()) { |
849 | | - all_enum_curves = false; |
850 | | - } |
851 | 777 | const int supported_count = static_cast<int>(prepared_curves.size()); |
852 | 778 | const ImVec2 plot_size = ImGui::GetContentRegionAvail(); |
853 | 779 | const bool has_cursor_time = state->has_tracker_time; |
@@ -895,8 +821,6 @@ void draw_plot(const AppSession &session, Pane *pane, UiState *state) { |
895 | 821 | ImPlot::SetupAxisFormat(ImAxis_X1, "%.1f"); |
896 | 822 | if (state_block_mode) { |
897 | 823 | ImPlot::SetupAxisLimits(ImAxis_Y1, 0.0, 1.0, ImPlotCond_Always); |
898 | | - } else if (all_enum_curves && !enum_context.enums.empty()) { |
899 | | - ImPlot::SetupAxisFormat(ImAxis_Y1, format_enum_axis_tick, &enum_context); |
900 | 824 | } else if (pane_value_format.valid) { |
901 | 825 | ImPlot::SetupAxisFormat(ImAxis_Y1, format_numeric_axis_tick, &pane_value_format); |
902 | 826 | } else { |
|
0 commit comments