Compare commits

..

1 Commits

Author SHA1 Message Date
Test User 3771202b69 HKG: Car Port for G80 2022 (3.5T, HDA2) 2026-04-02 17:30:28 -04:00
5 changed files with 86 additions and 10 deletions
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e53f4e0527766082ba7bde38e275def0fe3c14f6c59ae2854439e239884d3ecc
size 13393365
oid sha256:eb6992bd60bada6162fea298e1a414b6b3d6a326db4eda46b9de62bcd8554754
size 13393859
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ea89c50da3a16e710da292f97c81b083a982cfdee5c28eca0d37ed2fb99af6c5
size 13022642
oid sha256:86680a657bbb34f997034d1930bb2cb65c38b9222cea199732f72bd45791cfad
size 13022803
+2 -2
View File
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6263aa3fbb44cde6c68a34cdb7cd8c389789dbc02b15c1911afdac4e018281ae
size 23267151
oid sha256:7af05e03fd170653ff5771baf373a2c57b363da12c4c411cd416dee067b4cf58
size 23266366
+79 -3
View File
@@ -6,6 +6,7 @@
#include <cmath>
#include <cstdio>
#include <limits>
#include <unordered_set>
constexpr double PLOT_Y_PAD_FRACTION = 0.4;
@@ -73,6 +74,10 @@ struct StateBlock {
std::string label;
};
struct PaneEnumContext {
std::vector<const EnumInfo *> enums;
};
struct PaneValueFormatContext {
SeriesFormat format;
bool valid = false;
@@ -101,6 +106,38 @@ bool curves_are_bool_like(const std::vector<PreparedCurve> &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<int> distinct_values;
for (double value : curve.ys) {
if (!std::isfinite(value)) {
continue;
}
distinct_values.insert(static_cast<int>(std::llround(value)));
if (distinct_values.size() > 12) {
return false;
}
}
return !distinct_values.empty();
}
bool curves_use_state_blocks(const std::vector<PreparedCurve> &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<std::array<uint8_t, 3>, 8> kPalette = {{
{{111, 143, 175}},
@@ -270,6 +307,36 @@ std::optional<double> app_sample_xy_value_at_time(const std::vector<double> &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<const PaneEnumContext *>(user_data);
const int idx = static_cast<int>(std::llround(value));
if (ctx != nullptr && idx >= 0 && std::abs(value - static_cast<double>(idx)) < 0.01) {
std::vector<std::string_view> names;
names.reserve(ctx->enums.size());
for (const EnumInfo *info : ctx->enums) {
if (info == nullptr || static_cast<size_t>(idx) >= info->names.size()) {
continue;
}
const std::string &name = info->names[static_cast<size_t>(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<const PaneValueFormatContext *>(user_data);
if (ctx == nullptr || !ctx->valid) {
@@ -764,16 +831,23 @@ 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;
bool state_block_mode = !prepared_curves.empty();
const bool state_block_mode = curves_use_state_blocks(prepared_curves);
bool all_enum_curves = !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) {
state_block_mode = false;
if (curve.enum_info != nullptr) {
enum_context.enums.push_back(curve.enum_info);
} else {
all_enum_curves = 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<int>(prepared_curves.size());
const ImVec2 plot_size = ImGui::GetContentRegionAvail();
const bool has_cursor_time = state->has_tracker_time;
@@ -821,6 +895,8 @@ 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 {