Skip to content

Commit f0053d4

Browse files
jotpluggler: state transition view is only for enums (#37761)
* jotpluggler: state transition view is only for enums * cleaner
1 parent 052692b commit f0053d4

File tree

1 file changed

+3
-79
lines changed

1 file changed

+3
-79
lines changed

tools/jotpluggler/plot.cc

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <cmath>
77
#include <cstdio>
88
#include <limits>
9-
#include <unordered_set>
109

1110
constexpr double PLOT_Y_PAD_FRACTION = 0.4;
1211

@@ -74,10 +73,6 @@ struct StateBlock {
7473
std::string label;
7574
};
7675

77-
struct PaneEnumContext {
78-
std::vector<const EnumInfo *> enums;
79-
};
80-
8176
struct PaneValueFormatContext {
8277
SeriesFormat format;
8378
bool valid = false;
@@ -106,38 +101,6 @@ bool curves_are_bool_like(const std::vector<PreparedCurve> &prepared_curves) {
106101
return true;
107102
}
108103

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-
141104
ImU32 state_block_color(int value, float alpha = 1.0f) {
142105
static constexpr std::array<std::array<uint8_t, 3>, 8> kPalette = {{
143106
{{111, 143, 175}},
@@ -307,36 +270,6 @@ std::optional<double> app_sample_xy_value_at_time(const std::vector<double> &xs,
307270
return y0 + (y1 - y0) * alpha;
308271
}
309272

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-
340273
int format_numeric_axis_tick(double value, char *buf, int size, void *user_data) {
341274
const auto *ctx = static_cast<const PaneValueFormatContext *>(user_data);
342275
if (ctx == nullptr || !ctx->valid) {
@@ -831,23 +764,16 @@ void draw_plot(const AppSession &session, Pane *pane, UiState *state) {
831764
}
832765

833766
const PlotBounds bounds = compute_plot_bounds(*pane, prepared_curves, *state);
834-
PaneEnumContext enum_context;
835767
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();
838769
size_t max_legend_label_width = 0;
839770
for (const PreparedCurve &curve : prepared_curves) {
840771
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;
845774
merge_pane_value_format(&pane_value_format, curve.display_info);
846775
}
847776
}
848-
if (prepared_curves.empty()) {
849-
all_enum_curves = false;
850-
}
851777
const int supported_count = static_cast<int>(prepared_curves.size());
852778
const ImVec2 plot_size = ImGui::GetContentRegionAvail();
853779
const bool has_cursor_time = state->has_tracker_time;
@@ -895,8 +821,6 @@ void draw_plot(const AppSession &session, Pane *pane, UiState *state) {
895821
ImPlot::SetupAxisFormat(ImAxis_X1, "%.1f");
896822
if (state_block_mode) {
897823
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);
900824
} else if (pane_value_format.valid) {
901825
ImPlot::SetupAxisFormat(ImAxis_Y1, format_numeric_axis_tick, &pane_value_format);
902826
} else {

0 commit comments

Comments
 (0)