Skip to content

Add official chart explorer standard#10

Merged
robertoecf merged 1 commit into
mainfrom
codex/lightweight-charts-explorer
May 5, 2026
Merged

Add official chart explorer standard#10
robertoecf merged 1 commit into
mainfrom
codex/lightweight-charts-explorer

Conversation

@robertoecf
Copy link
Copy Markdown
Owner

Summary

  • Adds a /charts browser chart explorer using TradingView Lightweight Charts with the project brand color theme.
  • Codifies the official chart/source metadata standard in docs/CHART_STANDARDS.md and links it from the README.
  • Standardizes chart metadata: primary source, BRT extraction timestamp, data cutoff, source block below the chart, and a tiny Lightweight Charts attribution link.

Root cause / fixes

  • The earlier chart footer/source pattern was only a one-off artifact; the repo did not have an official reusable standard or /charts route.
  • The first browser run exposed two runtime risks before publish: the BCB ultimos endpoint is capped for large n, so the default preset now uses a bounded date-range endpoint; and Intl.DateTimeFormat with mixed style/time-zone options failed in the in-app browser, so extraction timestamps now use explicit BRT formatting.

Validation

  • node --check src/findata/web/static/chart-explorer.js
  • .venv/bin/ruff format --check src/ tests/ scripts/
  • .venv/bin/ruff check src/ tests/ scripts/
  • .venv/bin/python -m mypy src/findata
  • .venv/bin/python -m pytest tests/ -q
  • git diff --check
  • Browser check on http://127.0.0.1:8765/charts: initial series loaded as Série plotada., 731 points, no console errors, repo source link and Lightweight Charts link present.

UI evidence

  • Local screenshot: /Users/macbook/Documents/Codex/2026-05-05/findata_charts_deploy_check.png
  • DOM probe: source note below chart says Fontes dos dados... Dados Abertos de Mercado (findata-br)... Subsets originais: BCB SGS 432.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Warning

Rate limit exceeded

@robertoecf has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 30 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6e310bd0-6e37-475a-9e60-810a637d11dd

📥 Commits

Reviewing files that changed from the base of the PR and between e2ed2d3 and 117aba9.

📒 Files selected for processing (10)
  • README.md
  • docs/CHART_STANDARDS.md
  • src/findata/api/app.py
  • src/findata/web/landing.py
  • src/findata/web/static/chart-explorer.js
  • src/findata/web/static/site.css
  • src/findata/web/templates/charts.html
  • src/findata/web/templates/docs.html
  • src/findata/web/templates/index.html
  • tests/test_api.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/lightweight-charts-explorer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@robertoecf robertoecf marked this pull request as ready for review May 5, 2026 15:35
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new interactive chart explorer, enabling users to visualize financial time series data from the API. It includes a new /charts endpoint, a dedicated documentation file for chart standards, and a JavaScript implementation using the TradingView Lightweight Charts library. A review comment identifies an improvement opportunity in the parseTime function to support numeric Unix timestamps, which would increase the explorer's compatibility with different data sources.

Comment on lines +196 to +211
const parseTime = (value) => {
if (typeof value !== "string" && typeof value !== "number") return null;
const text = String(value).trim();
let match = text.match(/^(\d{2})\/(\d{2})\/(\d{4})$/);
if (match) return `${match[3]}-${match[2]}-${match[1]}`;

match = text.match(/^(\d{4})(\d{2})$/);
if (match) return `${match[1]}-${match[2]}-01`;

match = text.match(/^(\d{4})-(\d{2})-(\d{2})/);
if (match) return `${match[1]}-${match[2]}-${match[3]}`;

const parsed = new Date(text);
if (Number.isNaN(parsed.getTime())) return null;
return parsed.toISOString().slice(0, 10);
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The parseTime function does not correctly handle numeric timestamps (Unix timestamps). When converting a numeric value to a string and passing it to new Date(), JavaScript fails to interpret purely numeric strings as dates (e.g., new Date("1714900000000") returns Invalid Date). Since many financial APIs return dates as timestamps, it is recommended to handle the number type explicitly to improve the explorer's compatibility with various data sources.

  const parseTime = (value) => {
    if (typeof value === "number") {
      // Handle Unix timestamps (seconds vs milliseconds)
      const date = new Date(value > 1e11 ? value : value * 1000);
      return Number.isNaN(date.getTime()) ? null : date.toISOString().slice(0, 10);
    }
    if (typeof value !== "string") return null;
    const text = value.trim();
    let match = text.match(/^(\d{2})\/(\d{2})\/(\d{4})$/);
    if (match) return `${match[3]}-${match[2]}-${match[1]}`;

    match = text.match(/^(\d{4})(\d{2})$/);
    if (match) return `${match[1]}-${match[2]}-01`;

    match = text.match(/^(\d{4})-(\d{2})-(\d{2})/);
    if (match) return `${match[1]}-${match[2]}-${match[3]}`;

    const parsed = new Date(text);
    if (Number.isNaN(parsed.getTime())) return null;
    return parsed.toISOString().slice(0, 10);
  };

@robertoecf robertoecf merged commit 06338be into main May 5, 2026
7 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 117aba9312

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +205 to +206
match = text.match(/^(\d{4})-(\d{2})-(\d{2})/);
if (match) return `${match[1]}-${match[2]}-${match[3]}`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve intraday timestamps when normalizing date fields

The ISO-date branch truncates any YYYY-MM-DDTHH:mm... value to YYYY-MM-DD, so intraday series are reduced to one point per day when deduped.set(time, ...) runs later. This corrupts chart data for supported endpoints that emit datetime candles (for example /yahoo/chart with intraday intervals), because multiple records collapse under the same key and only the last one survives.

Useful? React with 👍 / 👎.

const dateKey = firstKey(firstRecord, DATE_KEYS);
if (!dateKey) throw new Error("Não encontrei campo de data conhecido.");

const shouldUseCandles = options.type === "candlestick" || hasOhlc(firstRecord);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Respect requested line mode for OHLC records

This condition forces candlestick rendering whenever the payload contains open/high/low/close, even if the preset explicitly asks for a scalar field (e.g., field: "close" in the Ibovespa preset). As a result, close-only comparisons cannot be rendered as lines for OHLC endpoints, which changes the intended visualization and summary semantics without user intent.

Useful? React with 👍 / 👎.

@robertoecf robertoecf deleted the codex/lightweight-charts-explorer branch May 7, 2026 00:59
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.

1 participant