Skip to content

chore: drop react-google-charts, consolidate all charts on Highcharts - #133

Open
iacapuca wants to merge 1 commit into
mainfrom
chore/google-charts-to-highcharts
Open

chore: drop react-google-charts, consolidate all charts on Highcharts#133
iacapuca wants to merge 1 commit into
mainfrom
chore/google-charts-to-highcharts

Conversation

@iacapuca

Copy link
Copy Markdown
Collaborator

Summary

Replaces all 5 react-google-charts usages with Highcharts (which is already the app's primary charting library — used in 5 other components). Removes the react-google-charts dependency entirely.

Why

react-google-charts works by injecting a <script> pointing at www.gstatic.com/charts/loader.js at runtime, which then dynamically fetches the Google Charts bundle:

<!-- Every chart render triggers this -->
<script async src="https://www.gstatic.com/charts/loader.js"></script>
<!-- Then another roundtrip to load the 'bar' package -->

This is the actual cost:

  • Two network roundtrips to gstatic.com before any chart pixel renders
  • Render blocks on those requests — chart area is blank until Google's runtime loads
  • Google sees a pageview for every visitor hitting /dados/loa or /dados/dom (same way Google Fonts does) — a privacy concern for a civic-tech NGO that otherwise avoids Google's tracking surface
  • Offline / poor connectivity = broken charts — even cached pages can't render them
  • Two chart libraries in one codebase — duplicate tooltip/legend conventions across pages

Highcharts is already bundled (~618 KB chunk), so moving the 5 remaining charts to it is a net bundle-neutral change that eliminates the CDN dependency.

What changed

5 bar charts migrated across 2 files:

File Chart
app/components/Loa/sections/BudgetCharts.tsx "Evolução Orçamentária Climática" (Orçado vs Executado 2020-2025)
app/components/Loa/sections/BudgetCharts.tsx "Orçamento Total por Ano" (2020-2025)
app/routes/dados.dom.index.tsx "Evolução do Orçamento Sustentável" (Sustentável vs Não sustentável)
app/routes/dados.dom.index.tsx "Tendência de Investimentos Sustentáveis" (single series)
app/routes/dados.dom.index.tsx "Orçamento Total por Ano" (single series)

Behavior preserved:

  • Same bar colors (#38A169 green, #3182CE blue, #E53E3E red)
  • Bottom legend placement
  • pt-BR formatted tooltips (R$ 1.234.567,89)
  • Short-format Y-axis labels (R$ 1.2 Mi, R$ 3.5 Bi)
  • Highcharts' built-in legend-click-to-toggle replaces the legendToggle prop

One concession — query shape left alone: app/queries/dados.dom.ts still emits the old Google-Charts-shaped 2D arrays ([header, ...rows]) for chartData.yearlyComparison / goodActionsYearly / totalSpendingYearly. The dom route file gets a small inline toHighchartsConfig(table, colors) helper that translates that shape into Highcharts categories + series. Refactoring the query file to emit a cleaner shape is worth doing but out of scope here — it would force changes in the query file + any consumer still relying on the 2D shape.

Dep removed: react-google-charts (along with its transitive @types/*).

Verification

  • npm run typecheck — zero new errors in migrated files
  • npm run build — clean in 8.2s; bundle size unchanged (charts reuse the existing Highcharts chunk)
  • ❌ Visual verification — I can't run the browser from this env. Needs spot-check on /dados/loa and /dados/dom after merge.

Test plan

Visual sanity checks to do in the browser after merge:

  • /dados/loa — "Evolução Orçamentária Climática" chart: 2 series (green Orçado, blue Executado), years 2020-2025 on X axis, R$-short-formatted Y labels
  • /dados/loa — "Orçamento Total por Ano" chart: 1 series (blue), years 2020-2025, no legend visible (single series)
  • /dados/dom — "Evolução do Orçamento Sustentável" chart: 2 series (green Sustentável, red Não sustentável), years 2021/2023/2024, tooltips show Portuguese-locale R$ formatting
  • /dados/dom — "Tendência de Investimentos Sustentáveis": 1 series green
  • /dados/dom — "Orçamento Total por Ano": 1 series blue
  • Network tab — confirm no request to gstatic.com when these pages load

Follow-up ideas (not in this PR)

  • Refactor app/queries/dados.dom.ts to emit { categories, series } instead of the 2D table format, so the dom route can drop its inline helper
  • The remaining Y-axis title says "Values" by default on Highcharts; consider localizing or hiding

🤖 Generated with Claude Code

react-google-charts loads the Google Charts runtime from
www.gstatic.com at runtime (packages/loader.js + the `bar` package
bundle) every time the /dados/loa or /dados/dom pages render charts.
This:

- Blocks chart render on two round-trips to Google's CDN
- Fires a Google-observable pageview per chart load (privacy-
  sensitive for a civic-tech NGO)
- Breaks the charts on slow/offline connections
- Splits the app across two chart libraries (the other 5 chart
  components already use Highcharts), each with its own tooltip,
  legend, and export conventions

Highcharts is already bundled in the app (~618KB chunk), so
consolidating is a net bundle-wash with no runtime CDN fetch.

Migrated 5 bar charts across 2 files:
- app/components/Loa/sections/BudgetCharts.tsx
  * "Evolução Orçamentária Climática" (Orçado vs Executado 2020-2025)
  * "Orçamento Total por Ano" (2020-2025)
- app/routes/dados.dom.index.tsx
  * "Evolução do Orçamento Sustentável" (Sustentável vs Não sustentável)
  * "Tendência de Investimentos Sustentáveis" (single series)
  * "Orçamento Total por Ano" (single series)

Behavior preserved: bar colors match, bottom legend, pt-BR tooltips
with R$ formatting, Mi/Bi short-format on the Y axis. Highcharts'
default legend-click-to-toggle replaces the old `legendToggle` prop.

The dom file gets a small inline helper that translates the
Google-Charts-shaped 2D arrays (still emitted by app/queries/
dados.dom.ts) into Highcharts categories + series — refactoring the
query file to emit a better shape is out of scope here.

Deploy.tsx docs updated to remove the react-google-charts entry.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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