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

Chartjs attempt #13897

Merged
merged 19 commits into from Nov 11, 2023
Merged

Chartjs attempt #13897

merged 19 commits into from Nov 11, 2023

Conversation

allanjoseph98
Copy link
Contributor

@allanjoseph98 allanjoseph98 commented Nov 1, 2023

WIP. Needs a lot of cleaning. I've tried to keep the look and function as similar to the current one as possible.

  • Rating distribution
  • ACPL chart
  • Move-time chart
  • Lag gauge chart
  • Rating history
  • Insights

@ornicar ornicar self-assigned this Nov 6, 2023
ornicar and others added 4 commits November 6, 2023 13:19
* master: (254 commits)
  fix team update should not overwrite all fields - closes lichess-org#13869
  simul host.provisional is optional
  remove players in wrong variant on update
  scalafmtAll
  refactor
  show host proper rating with provisional
  Lpv scala code golf
  New Crowdin updates (lichess-org#13911)
  move to ctx.canPalantir
  ctx.kid: KidMode
  use ctx.kid in Account.info
  scalachess 15.6.9
  MsgSearch needs to know if the current request is in kid mode
  read canPalantir from ctx, not from user
  allow forcing kid mode with http header (lichess-org#13882)
  update MarkdownTest
  scalafmt
  distinguish links to private studies
  preventing moves list items from flickering and or dissapearing in explorer
  do not allow embedding private studies
  ...
* master:
  crowdv now only in schlawg branch
  correct the commit that fails to download in our unused, broken script
  open relation API endpoints to the mobile token
  update 2FA message to include titled players
  scalafmt
  Update play-json to 3.0.1
  Do not use `xhr.json` on study endpoints returning no content
@ornicar
Copy link
Collaborator

ornicar commented Nov 7, 2023

Looking promising. We don't need to port all the charts right away. I'd prefer to see one or two charts being completed, which we can merge. Then we attack the next ones later on.

What's missing to ship, say, the ACPL and movetime charts?

@ornicar
Copy link
Collaborator

ornicar commented Nov 7, 2023

@allanjoseph98
Copy link
Contributor Author

allanjoseph98 commented Nov 7, 2023

Functionally, it should all work. I'm mostly not happy with my code quality. There are lots of improvements to be made.

Problems:

  1. I'm not happy about bundle sizes. Currently, chartjs is being bundled custom for every chart; users have to download chartjs in multiple forms instead of using a big fat version that can be cached (like it is with highcharts currently). The big fat version is ~30kb larger than the highcharts. The pre-existing charts in opening and puzzle dashboard would also need to be upgraded to the chartjs version used in this pr.
  2. Annotations on the graph do not exist because I've opted to not use the extra annotations plugin as that adds an extra 30kb to minified file sizes. Instead, I've used some creative liberties to add annotations as plot points themselves. They show up in the tooltip on hover.
  3. The movetime chart does not take up the entire canvas area because of consequences of (2.) and using a linear x-axis scale for a bar chart. I thought this was the best compromise. Most users shouldn't notice and it only looks slightly weird when moves are > 100.
  4. I'm sure there will be some odd bugs that will come up that I have missed.

Wins:

  1. I've added types wherever they were missing
  2. Tooltips work a lot better when using a rtl language
  3. In insights, I've removed the numeral module and used Intl.NumberFormat instead to save ~30kb.

And what's this about?

It was just a note to self to add dynamic theme-changing which was added with 83b866d along with other misc changes. Insights support added with 850a98f

@ornicar
Copy link
Collaborator

ornicar commented Nov 7, 2023

Thanks.

I'm not happy about bundle sizes

I did notice an increase in the minified size, yes. Because the charts are not on critical pages (like homepage and gameplay), and because we can render the full page layout before loading them, I think it's ok.
I assume you already looked into chartjs treeshaking.

Currently, chartjs is being bundled custom for every chart; users have to download chartjs in multiple forms instead of using a big fat version that can be cached (like it is with highcharts currently)

As long as we only load one chartjs instance per page, and only after (rest of) the page is rendered and functional, then that's ok by me.

Annotations on the graph do not exist because I've opted to not use the extra annotations plugin as that adds an extra 30kb to minified file sizes.

A bit sad as I think it was nice to see directly on the chart. Kinda incredible that it adds 30kb minified JS. What even is in chartjs?

Of course there will be bugs, but that's ok, we'll sort them out.

@ornicar
Copy link
Collaborator

ornicar commented Nov 7, 2023

I think the ACPL and movetime charts already look good enough. Could we have bigger and/or more visible hover points, and also while litting up the "christmas tree"?

@ornicar
Copy link
Collaborator

ornicar commented Nov 7, 2023

Is it possible to retain the horizontal animation from https://lichess.org/stat/rating/distribution/blitz? I think the default chartjs vertical animation doesn't look as good on that page.

@allanjoseph98 allanjoseph98 marked this pull request as ready for review November 8, 2023 06:22
* master: (27 commits)
  replace   with space in french translations
  remove copy-pasted code that's also unnecessary
  wrapping an int in NumberLong is without effect and triggers a warning
  scala tweak
  remove unused opaque type
  add snabbdom key to notification to prevent DOM reuse - fixes lichess-org#13645
  remove unused python os import
  New Crowdin updates (lichess-org#13924)
  remove dubious and duplicated quotes
  scala tweaks
  Allow different asset url for requests from Dasher
  prettier
  fix games page overflow
  fix safari autoplay text
  ignore games over 4 hours
  hopefully touch drags enable audio context on ios safari now
  Fix translations
  Fix formatting
  Add translations
  remove confusing, unnecessary indirection
  ...
… into chartjs-attempt

* 'chartjs-attempt' of https://github.com/allanjoseph98/lila:
  Don't animate the christmas tree
  Animate charts ltr on load. +misc. fixes
@ornicar
Copy link
Collaborator

ornicar commented Nov 8, 2023

Almost there! Looks like ui/insight/chart could depend on chart/common to reuse the grid/label colors.

@schlawg
Copy link
Collaborator

schlawg commented Nov 8, 2023

This removes some godawful hacks I was hoping to sweep under the rug one day. Soon I will be able to pretend I never committed them!

@schlawg
Copy link
Collaborator

schlawg commented Nov 8, 2023

I don't want to throw a complication in here last minute, but Allan if your efforts were constrained because you were worried about that extra 30k... I assume there's a reason chart.js + annotations plugin can't be loaded (and cached browserside) dynamically as a module?

@allanjoseph98
Copy link
Contributor Author

I haven't looked into it yet but it should be possible in theory. I prioritised replicating the charts first and then looking at optimisations later so I never got around to looking into it. Compared to highcharts, a similar Chartjs + annotations implementation would be an extra ~30+30=60kb.

Essentially, the only thing missing is the text next to the annotation line. There is also the movetime chart size issue as a result of hacks that I highlighted earlier.

I didn't think that displaying extra text was worth a 30kb additional download so I never considered the plugin again. But yeah, you make a good point that since it would be cached it might not be too bad.

I leave it up to you guys to decide.

@schlawg
Copy link
Collaborator

schlawg commented Nov 8, 2023

Ok. Down the road, we can look into a custom bundle module with only the things we need from chartjs. Feel free to leave comments about any imports or code that bloat concerns stopped you from adding. Maybe it can be added when/if the module comes along.

ornicar and others added 2 commits November 10, 2023 13:40
* master: (31 commits)
  Revert "new PGN export patron tags, optional"
  New Crowdin updates (lichess-org#13949)
  pnpm format
  open POST /account/profile to mobile app
  dedup anon challenges
  scala tweaks
  require a sessionId to make an anon challenge
  fix racer zen alignment and content
  Update netty-transport-native-epoll to 4.1.101.Final
  Copy unmovedRooks when creating rematch games
  new PGN export patron tags, optional
  Fix removing fields from teams
  New Crowdin updates (lichess-org#13946)
  titles don't need to end with ":"
  too many newlines
  use automatic <br> with HTML translations
  don't manually edit I18nKeys, generate them with ./bin/trans-dump
  rename CC button - closes lichess-org#13945
  don't expand images in streamer mod notes
  fix new lines in translated HTML
  ...
@ornicar
Copy link
Collaborator

ornicar commented Nov 11, 2023

This is great, thank you so much. I'm merging this right now and will deploy it in the days to come, so we can get user feedback.
Feel free to keep polishing it and maybe even get rid of highcharts completely <3 in other PRs

@ornicar ornicar merged commit e3afabd into lichess-org:master Nov 11, 2023
4 checks passed
@allanjoseph98 allanjoseph98 deleted the chartjs-attempt branch January 6, 2024 06:48
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.

None yet

3 participants