chore: drop react-google-charts, consolidate all charts on Highcharts - #133
Open
iacapuca wants to merge 1 commit into
Open
chore: drop react-google-charts, consolidate all charts on Highcharts#133iacapuca wants to merge 1 commit into
iacapuca wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces all 5
react-google-chartsusages with Highcharts (which is already the app's primary charting library — used in 5 other components). Removes thereact-google-chartsdependency entirely.Why
react-google-chartsworks by injecting a<script>pointing atwww.gstatic.com/charts/loader.jsat runtime, which then dynamically fetches the Google Charts bundle:This is the actual cost:
gstatic.combefore any chart pixel renders/dados/loaor/dados/dom(same way Google Fonts does) — a privacy concern for a civic-tech NGO that otherwise avoids Google's tracking surfaceHighcharts is already bundled (
~618 KBchunk), 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:
app/components/Loa/sections/BudgetCharts.tsxapp/components/Loa/sections/BudgetCharts.tsxapp/routes/dados.dom.index.tsxapp/routes/dados.dom.index.tsxapp/routes/dados.dom.index.tsxBehavior preserved:
#38A169green,#3182CEblue,#E53E3Ered)R$ 1.234.567,89)R$ 1.2 Mi,R$ 3.5 Bi)legendTogglepropOne concession — query shape left alone:
app/queries/dados.dom.tsstill emits the old Google-Charts-shaped 2D arrays ([header, ...rows]) forchartData.yearlyComparison/goodActionsYearly/totalSpendingYearly. The dom route file gets a small inlinetoHighchartsConfig(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 filesnpm run build— clean in 8.2s; bundle size unchanged (charts reuse the existing Highcharts chunk)/dados/loaand/dados/domafter 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 bluegstatic.comwhen these pages loadFollow-up ideas (not in this PR)
app/queries/dados.dom.tsto emit{ categories, series }instead of the 2D table format, so the dom route can drop its inline helper🤖 Generated with Claude Code