-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: use highchart offline export for downloads #3135
base: master
Are you sure you want to change the base?
feat: use highchart offline export for downloads #3135
Conversation
🚀 Deployed on https://pr-3135.data-visualizer.netlify.dhis2.org |
3822611
to
41e6cf4
Compare
This comment was marked as resolved.
This comment was marked as resolved.
abea112
to
0b434bf
Compare
languages: new Set([ | ||
'arq', | ||
'ar', // Technically maps to both Arab and Syrc but we assume Arab | ||
// 'az', (Arab + Cyrl) |
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.
For languages like az
that can be written in multiple non-latin scripts, it is strictly speaking impossible to establish the correct font bundle based on a language code.
In this current implementation I have commented out these entries, so for these languages the default Noto font bundle will be used for a PDF export, unless the locale had a script section specified.
We could also take an alternative approach, where we work with "default language-scripts". For example, we could say that "all/most DHIS2 implementations using the az
language only use the Arab
script, so we want to serve the NotoSansArabic
bundle for the az
language.
To switch from the first approach to the second would only mean uncommenting the line above. No other changes are required, and we would still be able to serve other fonts for this language if the locale were to include a script
section (this is currently not supported but will be starting 2.42, see DHIS2-17927).
I guess you could say the current approach is implementing things purely based on the locale standards, while the second approach takes a more pragmatic approach. The downside of the second approach is that it creates a level of ambiguity since we would basically be deciding what the default script for a language should be. And this would also mean a bit more work.
I am leaning more towards the current implementation, but felt I should at least explain the alternative I considered.
return ( | ||
findCustomNotoFont(({ scripts }) => scripts.has(script)) ?? | ||
findCustomNotoFont(({ languages }) => languages.has(language)) ?? | ||
NOTO_SANS_BASE_FONT_NAME | ||
) |
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.
Note that the script of the locale takes precedence over the language.
0b434bf
to
989db95
Compare
989db95
to
e80039c
Compare
3f9bed9
to
2e2120f
Compare
b635a2d
to
5e362e0
Compare
Implements DHIS2-17722 and also fixes DHIS2-12103.
Requires dhis2/analytics#1731
Key features
Description
exportChartLocal()
method.exportChartLocal()
method, we need access to the current chart in theuseDownload
hook. Previously we just kept the SVG string in the global redux store, but now we need access to the HighChartsChart
instance which has theexportChartLocal()
method. A redux store is only supposed to contain serialisable data and we were violating that principle by putting the chart instance in there, so I moved the chart into a context. (FYI: it wasn't just a matter of principle I also remember getting an error when I tried to put the Chart instance into the redux store)Font bugs
During a KFMT session we found various font-related bugs.
It seems that at least in-part these three bugs are related to each other.
Bug 1: PNG font-family consistency
What I found was the following:
font-family
from the root SVG.<text>
nodes in our charts in the browser's element-inspector, we can see that the font-family is correctly set toRoboto, sans-serif
, but these styles are inherited from elements such as the document body and some other selectors, not from the root SVG element.(I have some elaborate theories on why this actually fixes things, but since I am not actually 100% sure, I'll refrain from going into detail)
To address this, we could add the following rule to
src/components/VisualizationPlugin/styles/ChartPlugin.module.css
(this file will be in the current branch after the Highcharts upgrade PR #3288 is merged:Bug 2: PDF font-family consistency
I expect that this fix for this bug builds upon the bugfix nr 1. It's possible that it is actually solved already after implementing it. But if not, I expect the following two steps may be needed:
chart.update()
and set the chart's font-family to a variety ofNoto Sans
fontFamily: '"Noto Sans Khmer", "Noto Sans", sans-serif
Bug 3: Text alignment
We expect the text alignment issues to be resolved once the font-family issues have been tackled. Suppose that in in the fix for bug nr 2 we only need to do step 1, and we find that we still have the text alignment issue, then this could require us to take step to after all. It could be possible that Highcharts passes some measurements of the SVG to the PDF generation process, and in order for these measurements to be correct, it will need to have the correct font rendered on the page.
TODO
Known issues
script
section. However it is currently not possible to add a script to a DB locale. See DHIS2-17927Screenshots