feat(market): persist chart range + style across sessions

The chart interval (Live/1H/1D/1W/1M) and the line/candle style were
session-only statics. Persist both like the selected exchange/pair: new
chart_interval / chart_style settings (defaults 1M / candlestick),
loaded into the market view on first show and saved on each interval
click / style toggle.

Verified: writing chart_interval=2, chart_style=0 to settings.json and
launching restores them (not reset to defaults) and re-saves them intact.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-12 12:05:36 -05:00
parent 76708e9191
commit e82514f46a
3 changed files with 20 additions and 1 deletions

View File

@@ -76,6 +76,12 @@ static void LoadMarketState(config::Settings* settings, const std::vector<data::
break;
}
}
// Restore the chart range + style (validated).
int iv = settings->getChartInterval();
if (iv >= 0 && iv <= 4) s_mkt.chartInterval = iv;
int st = settings->getChartStyle();
if (st == 0 || st == 1) s_mkt.chartStyle = st;
}
// Helper: format compact currency
@@ -1407,6 +1413,7 @@ static void mktDrawPriceChart(const MktCtx& cx)
ImGui::PushID(9100 + b);
if (ImGui::InvisibleButton("##civ", ImVec2(bw, pillH))) {
s_mkt.chartInterval = kIvs[b].iv;
if (app->settings()) { app->settings()->setChartInterval(kIvs[b].iv); app->settings()->save(); }
}
if (ImGui::IsItemHovered()) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
ImGui::PopID();
@@ -1429,8 +1436,10 @@ static void mktDrawPriceChart(const MktCtx& cx)
ImVec2(tmn.x + (pillH - tiSz.x) * 0.5f, tmn.y + (pillH - tiSz.y) * 0.5f),
thov ? OnSurface() : OnSurfaceMedium(), styleIcon);
ImGui::SetCursorScreenPos(tmn);
if (ImGui::InvisibleButton("##ChartStyle", ImVec2(pillH, pillH)))
if (ImGui::InvisibleButton("##ChartStyle", ImVec2(pillH, pillH))) {
s_mkt.chartStyle = isCandle ? 0 : 1;
if (app->settings()) { app->settings()->setChartStyle(s_mkt.chartStyle); app->settings()->save(); }
}
if (ImGui::IsItemHovered())
material::Tooltip("%s", TR(isCandle ? "market_style_line" : "market_style_candle"));
bx += pillH;