"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(frontend): sync chart legend colors, factor spread format, and payoff axis
shadowinlife1b92f8924f45
diff --git a/frontend/src/components/charts/AttributionCumulativeChart.tsx b/frontend/src/components/charts/AttributionCumulativeChart.tsxindex 62c57095c..e9e10ada2 100644--- a/frontend/src/components/charts/AttributionCumulativeChart.tsx+++ b/frontend/src/components/charts/AttributionCumulativeChart.tsx@@ -78,6 +78,8 @@ export function AttributionCumulativeChart({ data, height = 300 }: Props) {data: data.map((d) => +(d.portfolio * 100).toFixed(4)),smooth: false,symbol: "none",+ // itemStyle drives the legend swatch; keep it in sync with lineStyle.+ itemStyle: { color: t.infoColor },lineStyle: { color: t.infoColor, width: 2 },},{@@ -86,6 +88,7 @@ export function AttributionCumulativeChart({ data, height = 300 }: Props) {data: data.map((d) => +(d.benchmark * 100).toFixed(4)),smooth: false,symbol: "none",+ itemStyle: { color: t.textColor },lineStyle: { color: t.textColor, width: 1.5 },},{@@ -94,6 +97,7 @@ export function AttributionCumulativeChart({ data, height = 300 }: Props) {data: data.map((d) => +(d.active * 100).toFixed(4)),smooth: false,symbol: "none",+ itemStyle: { color: pnl.profit },lineStyle: { color: pnl.profit, width: 1.5, type: "dashed" },},],diff --git a/frontend/src/components/charts/FactorResearchPanel.tsx b/frontend/src/components/charts/FactorResearchPanel.tsxindex b6c7b58fa..17123814c 100644--- a/frontend/src/components/charts/FactorResearchPanel.tsx+++ b/frontend/src/components/charts/FactorResearchPanel.tsx@@ -29,6 +29,17 @@ function pct(value: unknown, digits = 2): string {return parsed == null ? "—" : `${(parsed * 100).toFixed(digits)}%`;}+function signedPct(value: unknown, digits = 2): string {+ const parsed = num(value);+ return parsed == null ? "—" : `${parsed > 0 ? "+" : ""}${(parsed * 100).toFixed(digits)}%`;+}++function signTone(value: unknown): "normal" | "positive" | "negative" {+ const parsed = num(value);+ if (parsed == null || parsed === 0) return "normal";+ return parsed > 0 ? "positive" : "negative";+}+/** Stride-sample long series for rendering, keeping the LAST point pinned. */function downsample<T>(rows: T[], maxPoints = MAX_CHART_POINTS): T[] {if (rows.length <= maxPoints) return rows;@@ -232,12 +243,12 @@ export function FactorResearchPanel({ report }: { report: FactorReportPayload })<RunCardPanel title={t("factor.icStats")} icon={Sigma}><div className="grid grid-cols-2 gap-3 md:grid-cols-4">- <RunCardStat label={t("factor.icMean")} value={fixed(stats?.ic_mean)} />+ <RunCardStat label={t("factor.icMean")} value={fixed(stats?.ic_mean)} tone={signTone(stats?.ic_mean)} /><RunCardStat label={t("factor.icStd")} value={fixed(stats?.ic_std)} />- <RunCardStat label={t("factor.ir")} value={fixed(stats?.ir)} />+ <RunCardStat label={t("factor.ir")} value={fixed(stats?.ir)} tone={signTone(stats?.ir)} /><RunCardStat label={t("factor.icPositiveRatio")} value={pct(stats?.ic_positive_ratio)} /><RunCardStat label={t("factor.icCount")} value={stats?.ic_count != null ? String(stats.ic_count) : "—"} />- <RunCardStat label={t("factor.longShortSpread")} value={fixed(selected.long_short_spread)} />+ <RunCardStat label={t("factor.longShortSpread")} value={signedPct(selected.long_short_spread)} tone={signTone(selected.long_short_spread)} /><RunCardStat label={t("factor.nGroups")} value={selected.n_groups ? String(selected.n_groups) : "—"} /></div></RunCardPanel>diff --git a/frontend/src/components/charts/OptionsPayoffChart.tsx b/frontend/src/components/charts/OptionsPayoffChart.tsxindex 8b499d95f..ccf5516b9 100644--- a/frontend/src/components/charts/OptionsPayoffChart.tsx+++ b/frontend/src/components/charts/OptionsPayoffChart.tsx@@ -66,6 +66,9 @@ export function OptionsPayoffChart({ curve, entrySpot, breakevens, height = 340grid: { left: 8, right: 16, top: 36, bottom: 8, containLabel: true },xAxis: {type: "value",+ // Pin to the curve's spot range: the default nice domain extends to 0 and leaves a dead zone.+ min: "dataMin",+ max: "dataMax",name: i18n.t("options.payoff.spot"),nameTextStyle: { color: t.textColor, fontSize: 10 },nameLocation: "middle",@@ -90,6 +93,7 @@ export function OptionsPayoffChart({ curve, entrySpot, breakevens, height = 340data: pairs,smooth: false,symbol: "none",+ itemStyle: { color: t.infoColor },lineStyle: { color: t.infoColor, width: 2 },markLine: {silent: true,diff --git a/frontend/src/components/charts/RollingBetaAlphaChart.tsx b/frontend/src/components/charts/RollingBetaAlphaChart.tsxindex 431839ee8..cc260e81c 100644--- a/frontend/src/components/charts/RollingBetaAlphaChart.tsx+++ b/frontend/src/components/charts/RollingBetaAlphaChart.tsx@@ -87,6 +87,8 @@ export function RollingBetaAlphaChart({ data, height = 280 }: Props) {data: betas,smooth: false,symbol: "none",+ // itemStyle drives the legend swatch; keep it in sync with lineStyle.+ itemStyle: { color: t.infoColor },lineStyle: { color: t.infoColor, width: 2 },},{@@ -96,6 +98,7 @@ export function RollingBetaAlphaChart({ data, height = 280 }: Props) {data: alphas,smooth: false,symbol: "none",+ itemStyle: { color: t.warningColor },lineStyle: { color: t.warningColor, width: 1.5 },},],diff --git a/frontend/src/components/charts/__tests__/ChartOptionConsistency.test.tsx b/frontend/src/components/charts/__tests__/ChartOptionConsistency.test.tsxnew file mode 100644index 000000000..7e7c6ff6e--- /dev/null+++ b/frontend/src/components/charts/__tests__/ChartOptionConsistency.test.tsx@@ -0,0 +1,101 @@+import { beforeEach, describe, expect, it, vi } from "vitest";+import { render } from "@testing-library/react";+import type { Mock } from "vitest";+import { AttributionCumulativeChart } from "../AttributionCumulativeChart";+import { RollingBetaAlphaChart } from "../RollingBetaAlphaChart";+import { OptionsPayoffChart } from "../OptionsPayoffChart";++vi.mock("@/lib/echarts", () => ({+ echarts: { init: vi.fn() },+ CHART_GROUP: "quant-charts",+ connectCharts: vi.fn(),+}));++import { echarts } from "@/lib/echarts";++interface FakeChart {+ setOption: Mock;+ resize: Mock;+ dispose: Mock;+ group: string;+}++interface SeriesSlice {+ name?: string;+ itemStyle?: { color?: string };+ lineStyle?: { color?: string };+}++const charts: FakeChart[] = [];++function lastOption(): Record<string, unknown> {+ const chart = charts[charts.length - 1];+ const call = chart.setOption.mock.calls[chart.setOption.mock.calls.length - 1];+ return call[0] as Record<string, unknown>;+}++beforeEach(() => {+ charts.length = 0;+ vi.mocked(echarts.init).mockImplementation((() => {+ const chart: FakeChart = { setOption: vi.fn(), resize: vi.fn(), dispose: vi.fn(), group: "" };+ charts.push(chart);+ return chart;+ }) as unknown as typeof echarts.init);+});++describe("legend swatch colors stay in sync with line colors", () => {+ it("AttributionCumulativeChart sets itemStyle color equal to lineStyle color on every series", () => {+ render(+ <AttributionCumulativeChart+ data={[+ { date: "2024-01-01", portfolio: 0.01, benchmark: 0.008, active: 0.002 },+ { date: "2024-01-02", portfolio: 0.02, benchmark: 0.015, active: 0.005 },+ ]}+ />,+ );++ const series = lastOption().series as SeriesSlice[];+ expect(series).toHaveLength(3);+ for (const entry of series) {+ expect(entry.itemStyle?.color).toBeDefined();+ expect(entry.itemStyle?.color).toBe(entry.lineStyle?.color);+ }+ });++ it("RollingBetaAlphaChart sets itemStyle color equal to lineStyle color on every series", () => {+ render(+ <RollingBetaAlphaChart+ data={[+ { date: "2024-01-01", beta: 0.2, alpha_annualized: -0.04 },+ { date: "2024-01-02", beta: 0.3, alpha_annualized: -0.05 },+ ]}+ />,+ );++ const series = lastOption().series as SeriesSlice[];+ expect(series).toHaveLength(2);+ for (const entry of series) {+ expect(entry.itemStyle?.color).toBeDefined();+ expect(entry.itemStyle?.color).toBe(entry.lineStyle?.color);+ }+ });++ it("OptionsPayoffChart pins the spot axis to the data extents and syncs the legend color", () => {+ render(+ <OptionsPayoffChart+ curve={{ spot: [80, 90, 100, 110, 120], pnl: [-120, -60, 40, 140, 240] }}+ entrySpot={100}+ breakevens={[96]}+ />,+ );++ const option = lastOption();+ const xAxis = option.xAxis as { min?: unknown; max?: unknown };+ expect(xAxis.min).toBe("dataMin");+ expect(xAxis.max).toBe("dataMax");++ const pnlSeries = (option.series as SeriesSlice[])[0];+ expect(pnlSeries.itemStyle?.color).toBeDefined();+ expect(pnlSeries.itemStyle?.color).toBe(pnlSeries.lineStyle?.color);+ });+});diff --git a/frontend/src/components/charts/__tests__/FactorResearchPanel.test.tsx b/frontend/src/components/charts/__tests__/FactorResearchPanel.test.tsxindex 9be5414b9..687633cb6 100644--- a/frontend/src/components/charts/__tests__/FactorResearchPanel.test.tsx+++ b/frontend/src/components/charts/__tests__/FactorResearchPanel.test.tsx@@ -61,7 +61,7 @@ describe("FactorResearchPanel", () => {expect(screen.getByText("0.8734")).toBeInTheDocument(); // irexpect(screen.getByText("62.50%")).toBeInTheDocument(); // ic_positive_ratioexpect(screen.getByText("128")).toBeInTheDocument(); // ic_count- expect(screen.getByText("0.0210")).toBeInTheDocument(); // long_short_spread+ expect(screen.getByText("+2.10%")).toBeInTheDocument(); // long_short_spread as signed percent});it("renders the factor selector only with multiple factors and switches the selection", () => {@@ -82,6 +82,7 @@ describe("FactorResearchPanel", () => {expect(screen.getByTestId("factor-selected")).toHaveTextContent("value_pe");expect(screen.getByText("-0.0113")).toBeInTheDocument();+ expect(screen.getByText("-1.20%")).toBeInTheDocument(); // negative spread keeps its signexpect(screen.queryByText("0.0521")).not.toBeInTheDocument();});diff --git a/frontend/src/components/run/RunCard.tsx b/frontend/src/components/run/RunCard.tsxindex f66c529d6..667fc4999 100644--- a/frontend/src/components/run/RunCard.tsx+++ b/frontend/src/components/run/RunCard.tsx@@ -7,11 +7,16 @@ import { cn } from "@/lib/utils";* FactorResearchPanel can reuse them without importing the page module (which* imports FactorResearchPanel back, creating a circular import).*/-export function RunCardStat({ label, value, tone = "normal" }: { label: string; value: string; tone?: "normal" | "warning" }) {+export function RunCardStat({ label, value, tone = "normal" }: { label: string; value: string; tone?: "normal" | "warning" | "positive" | "negative" }) {return (<div className="rounded-xl border border-border/60 bg-card p-4 shadow-sm"><div className="text-xs text-muted-foreground">{label}</div>- <div className={cn("mt-1 truncate text-sm font-medium", tone === "warning" ? "text-warning" : "")}>{value}</div>+ <div className={cn(+ "mt-1 truncate text-sm font-medium",+ tone === "warning" && "text-warning",+ tone === "positive" && "text-success",+ tone === "negative" && "text-danger",+ )}>{value}</div></div>);}