Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance: replace recharts charting lib with Chart.js #12952

Open
wants to merge 40 commits into
base: dev
Choose a base branch
from

Conversation

nhsz
Copy link
Member

@nhsz nhsz commented May 13, 2024

This PR replaces the recharts charting lib with Chart.js, with the goal of providing a lighter alternative and reduce the bundle size.

We currently have 2 types of charts on the site, the /StatsBoxGrid/GridItem on the homepage and EnergyConsumptionChart

Description

  • updates src/components/StatsBoxGrid/GridItem.tsx with Chart.js implementation
  • updates src/components/EnergyConsumptionChart.tsx with Chart.js implementation
  • updates constants.ts
  • adds charts.ts to /lib/utils
  • updates dependencies

Charts location

Previews

Parsed size comparison

Chart.js (152.54kb)

Screen Shot 2024-05-21 at 10 51 38

recharts (271.81kb)

Screen Shot 2024-05-21 at 10 52 00

Reduction of 43.88%

Note

Found a small glitch on the StatsBox chart (don't think it's a blocker) that happens from time to time on some browsers like Chrome/Brave. Works ok on Firefox & Safari. From the comments on github, seems to be a browser issue and can't be fixed on the lib

Screen Shot 2024-06-03 at 14 17 06

Check the comments below:

@nhsz nhsz self-assigned this May 13, 2024
@github-actions github-actions bot added dependencies 📦 Changes related to project dependencies needs review 👀 labels May 13, 2024
Copy link

netlify bot commented May 13, 2024

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit 308c521
🔍 Latest deploy log https://app.netlify.com/sites/ethereumorg/deploys/665dde212281a10008faf4d0
😎 Deploy Preview https://deploy-preview-12952--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
7 paths audited
Performance: 49 (🟢 up 11 from production)
Accessibility: 92 (no change from production)
Best Practices: 89 (🔴 down 3 from production)
SEO: 93 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the tooling 🔧 Changes related to tooling of the project label May 13, 2024
@wackerow
Copy link
Member

Screen.Recording.2024-05-15.at.09.47.34.mov

@nhsz Noticing this when playing around. It's a fairly unnatural approach for someone to resize a window like that, but also noticing it starts getting cramped on mobile:

image
(From a larger iPhone)

@nhsz
Copy link
Member Author

nhsz commented May 15, 2024

Screen.Recording.2024-05-15.at.09.47.34.mov
@nhsz Noticing this when playing around. It's a fairly unnatural approach for someone to resize a window like that, but also noticing it starts getting cramped on mobile:

image (From a larger iPhone)

@wackerow Yes, still working on the responsive fixes, thanks

Copy link
Member

Choose a reason for hiding this comment

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

Having a couple issues here on desktop... In the Netlify preview, the homepage loads correctly showing the 30-day charts, but clicking on the 90-day button for any of them gives me the dreaded Application error: a client-side exception has occurred (see the browser console for more information).

image

Locally I do not get this, and I am able to toggle between them. I then notice a difference in our transition between 30 and 90 days, where it seems to only be showing 30 days worth of data during the transition (in both directions) leaving a dead space in the chart during the transition.

Screen.Recording.2024-05-16.at.11.47.24.mov

Is there a way to maintain all 90 days in the state while this transitions?

Copy link
Member

Choose a reason for hiding this comment

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

Noting the same @nhsz. Locally (dev) its working fine but on the preview deploy it is crashing.


const chartOptions = {
// chart styles
barThickness: 38,
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we could pass a responsive Chakra token here to make the width responsive... or perhaps we could use a maxBarThickness here to cap it on Mobile.

src/components/EnergyConsumptionChart.tsx Show resolved Hide resolved
barThickness: 38,
borderRadius: 4,
aspectRatio: 1.1,
responsive: true,
Copy link
Member

Choose a reason for hiding this comment

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

Odd that the chart doesn't re-expand if you shrink then widen the device window... Would think this would take care of it, and the Box it's contained within should be responsive... Will keep an eye out for a possible patch

src/components/EnergyConsumptionChart.tsx Outdated Show resolved Hide resolved
src/lib/constants.ts Outdated Show resolved Hide resolved
src/lib/utils/charts.ts Show resolved Hide resolved
src/components/Buttons/ButtonLink.tsx Outdated Show resolved Hide resolved
@nhsz nhsz marked this pull request as ready for review May 20, 2024 11:39
Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

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

@nhsz good job! Left a couple of observations.

src/components/StatsBoxGrid/GridItem.tsx Outdated Show resolved Hide resolved
src/components/StatsBoxGrid/GridItem.tsx Outdated Show resolved Hide resolved
src/components/EnergyConsumptionChart.tsx Outdated Show resolved Hide resolved
src/components/EnergyConsumptionChart.tsx Show resolved Hide resolved
src/components/EnergyConsumptionChart.tsx Outdated Show resolved Hide resolved
src/components/EnergyConsumptionChart.tsx Outdated Show resolved Hide resolved
src/components/EnergyConsumptionChart.tsx Outdated Show resolved Hide resolved
@nhsz nhsz requested review from pettinarip and wackerow June 3, 2024 12:22
Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

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

@nhsz looking good, the energy one is working perfectly. The only thing is that the home stats are crashing when you change the date range.

Copy link
Member

Choose a reason for hiding this comment

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

Noting the same @nhsz. Locally (dev) its working fine but on the preview deploy it is crashing.

@wackerow
Copy link
Member

wackerow commented Jun 5, 2024

https://deploy-preview-12952--ethereumorg.netlify.app/en/energy-consumption

From Safari:
image

From Brave:

Screen.Recording.2024-06-05.at.11.16.26.mov
Screen.Recording.2024-06-05.at.11.22.29.mov

Cleared cache and tried this out... seeing some strange behavior on the engergy consumption chart where it glitches by loading/animating the chart twice, and seems to not be placing them in the correct sorting order. These adjust a little when the window size is adjusted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies 📦 Changes related to project dependencies tooling 🔧 Changes related to tooling of the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants