Skip to content

fix(AccountInfoDisplay): culture-safe PnL coloring + render cleanup#169

Open
AlbertoAmadorBelchistim wants to merge 4 commits into
AtasPlatform:Developfrom
AlbertoAmadorBelchistim:fix/AccountInfoDisplay-render-pass
Open

fix(AccountInfoDisplay): culture-safe PnL coloring + render cleanup#169
AlbertoAmadorBelchistim wants to merge 4 commits into
AtasPlatform:Developfrom
AlbertoAmadorBelchistim:fix/AccountInfoDisplay-render-pass

Conversation

@AlbertoAmadorBelchistim
Copy link
Copy Markdown
Contributor

Summary

Three small, independent changes to AccountInfoDisplay's render path:

  1. Bug fix - PnL coloring failed on cultures where , is the decimal separator (es-ES, fr-FR, de-DE, ...) for any PnL ≥ 1000 absolute.
    The old ExtractNumericValue formatted with N2 then re-parsed after stripping commas, which produced an invalid thousand-grouping in those cultures and the parse silently returned 0 — collapsing positive and negative PnL into the neutral colour.

  2. Perf - the border RenderPen was instantiated on every OnRender call. Cached as a field.

  3. Cleanup

  • _stringFormat was constructed but never passed to any DrawString. Removed.
  • Padding promoted to private const.
  • The Container?.Region == null guard made explicit (Region is a struct, so the null-conditional only checks Container).

No public API changes.

Commits

  • fix(account-info): culture-safe value coloring
  • perf(account-info): cache border RenderPen across renders
  • chore(account-info): drop dead RenderStringFormat field; tighten guard

Notes

  • Total PnL continues to use OpenPnL + ClosedPnL (session-level) rather than Portfolio.TotalPnL (cumulative). This is intentional and now documented inline in BuildLines.
  • RenderFont and RenderPen are sealed and do not implement IDisposable in the SDK, so no explicit disposal is required when references are replaced.

Verification

Commit Smoke test Result
1 Open chart with PnL ≥ 1000 EUR on es-ES regional → Open PnL positive shows green, negative shows red
1 Same scenario on en-US regional → no regression
2 Long scroll session → no growth in GC pressure or per-frame allocations from the border pen path
3 Recompile and apply → render output identical to commit 2 (no visual change expected)

Replace format-then-parse roundtrip with a record-backed line list
that carries the raw decimal alongside the formatted string. The
previous ExtractNumericValue stripped commas and re-parsed the
N2-formatted value with the current culture, which fails on cultures
where ',' is the decimal separator (es-ES, fr-FR, de-DE, ...) for any
PnL >= 1000 absolute. Parse failure yielded 0, collapsing positive and
negative PnL into the neutral colour.

Coloring decisions now read the original Portfolio.OpenPnL /
Portfolio.ClosedPnL values directly. ExtractNumericValue and
BuildDisplayText (string-with-pipe-delimiter contract) are removed.
The border RenderPen was instantiated on every OnRender call, and the
RenderFont was reassigned on every FontSize change without disposing
the previous instance. Both wrap GDI+ resources; reuse them and dispose
explicitly when replaced.
_stringFormat was constructed but never passed to any DrawString call
since the indicator draws by absolute coordinates. Remove the field.
Promote the rendering padding to a private const. The Container?.Region
null check effectively only validates Container (Region is a struct);
make that explicit so the intent reads clearly.
@Stig4all
Copy link
Copy Markdown
Collaborator

Reviewed and tested locally against current Develop.

The functional change looks good to me: PnL coloring now uses the raw decimal values instead of parsing formatted strings, so the culture-dependent coloring issue should be fixed. I also verified that the PR builds successfully, and all four pending PRs merge together into Develop without conflicts or build errors.

Minor non-blocking cleanup:

  • _borderPen is introduced but OnRender still creates new RenderPen(Color.Gray, 1) inline.
  • var old = _font; in FontSize setter is unused.
  • There is a broken character in the Total PnL comment.

No blocking issues from my side. OK to merge after optional cleanup.

- Use cached _borderPen instead of allocating per render
- Remove unused `var old = _font` from FontSize setter
- Fix mojibake in Total PnL comment (em-dash -> ASCII)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants