-
Notifications
You must be signed in to change notification settings - Fork 530
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
Upgraded Chart.js to version 4.4.2 #3233
Conversation
pontoon/base/templates/base.html
Outdated
<!-- Add Chart.js and Moment CDN link --> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/moment@^2.30.1"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@^1.0.1"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to avoid loading static files from external sources. Please instead include the files in the repo.
pontoon/base/templates/base.html
Outdated
<!-- Import Chart.js and Moment.js from static files --> | ||
<script language="javascript" type="text/javascript" src="{{ static('js/lib/chart.umd.min.js') }}"></script> | ||
<script language="javascript" type="text/javascript" src="{{ static('js/lib/moment.min.js') }}"></script> | ||
<script language="javascript" type="text/javascript" src="{{ static('js/lib/chartjs-adapter-moment.min.js') }}"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will load all these libs on most of the views, even when they aren't needed.
We should load them, like other static files, through Django pipeline in settings, and only in the views where Chart.js was previously used.
Also, seems like pontoon/base/static/js/lib/chart.umd.js.map
is not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I was getting a console error when I didn't include this file through base.html, but now that I've shifted over to local imports it seems this file isn't necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The libraries are now loaded as expected. Nice work!
Please see my comment inline for the Profile chart.
I've noticed that the charts on http://localhost:8000/insights/ don't load.
Also, the Age of unreviewed suggestions and the Time to review pretranslations charts on http://localhost:8000/sl/insights/ shouldn't have legends.
pontoon/base/templates/base.html
Outdated
@@ -28,7 +28,7 @@ | |||
{% block extend_css %} | |||
{% endblock %} | |||
{% endblock %} | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please restore this change.
beginAtZero: true, | ||
maxTicksLimit: 3, | ||
precision: 2, | ||
callback: (value) => nf.format(value), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change in the precision
and the callback
settings?
There are a few things that don't work as expected in the new Profile chart:
- The curve doesn't have a background.
- The Y scale data is off.
- The tooltip: items overlap, the data format is off and there is no border.
- The chart is cut-off at the top.
- Can we keep the line curved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at the code yet, but the changes look good. Nice work!
I noticed a few minor things, which should still be changed:
- On the X scales, there should be no day number (e.g. "Jun" instead of "Jun 1").
- We don't use a thousands separator on the Y scale ATM. I think it's a good idea to use it, but it should be
,
rather than.
(same as in the tooltip). - Borders in bullet points in the tooltips don't look the same as in production - they have a 3Dish look and the first one is bigger than the rest.
True, but I believe the situation is worse than on prod ATM, where e.g. for me all charts show months as "May" rather than "May 1", which is the case in some charts now. E.g. the chart on the /profile page shows months rightfully as "May", whereas the Time to review suggestions chart on /sl/insights shows months as "May 1". Also, it seems like charts on the /insights page are broken again. |
}, | ||
tooltipFormat: 'MMM YYYY', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and other instances of the same value) should remain MMMM YYYY
, which will show the full month name in the tooltip, where we have enough space.
The decision to switch from |
…perator for all locales
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very well done!
All charts work as expected.
Left some comments inline, mostly just to improve the code maintainability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work!
Just that minor Arrow function trick and we're good!
labelColor: (context) => { | ||
return Pontoon.insights.setLabelColor(context); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop the body braces and the word "return":
labelColor: (context) => { | |
return Pontoon.insights.setLabelColor(context); | |
}, | |
labelColor: (context) => | |
Pontoon.insights.setLabelColor(context), | |
}, |
The same applies for all other calls of this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\o/
Very well done!
Fix #2939
Upgraded Chart.js dependency to latest version (4.4.2). Previously, Chart.js was included via a
Chart.bundle.js
static file. Support for this method has ended, so the dependency was included via a CDN. Changed all instances of deprecated functions to the new equivalents according to the migration guide.