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

Proposal: Use CSS variables in Statistics charts for colour customisation #4103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jon48
Copy link
Contributor

@jon48 jon48 commented Oct 31, 2021

Following our discussion in #4070, I actually found a way to restore some theme customisation at the JS level, and here is an implementation suggestion.
That only covers the Google Charts, as the Fan chart is generated at the PHP level.

There are quite a few file changes, but basically the main components are:

  • The transfer of the ColorService from PHP to JS (in the webtrees.colors namespace): the methods have been JS-ify without change to their logic, and a new method has been introduced that convert an array of "colours definition" to actual colours. The elements can be fixed colours, or a 2-elements array with a CSS variable and a fall-back colour.
  • the change of the chart views to use this new function, and get the interpolated palette when required.
    let colors = webtrees.colors.fromCss(<?= json_encode($colors, JSON_THROW_ON_ERROR) ?>);
    colors = webtrees.colors.interpolateRgb(colors[0], colors[1], <?= (int) $steps ?>);
  • the introduction of various CSS variables to customise colours in the charts. For instance:
    $color_to   = $color_to ??  ['--chart-values-high', '#84beff'];

I have "restored" in CSS the parameters that were different from the hardcoded default for the standard themes.

I know that this may only be a temporary need, if the Google Charts are refactored with another library at some point, but the logic may prove useful even with a future library for theming.

This is just a proposal; there are few implementation details than can be discussed, and as I mentioned in the issue, I can live as well without colour customisation until a new library is implemented

@codecov
Copy link

codecov bot commented Oct 31, 2021

Codecov Report

Merging #4103 (4d3e366) into main (9cfc37d) will decrease coverage by 0.02%.
The diff coverage is 85.55%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #4103      +/-   ##
============================================
- Coverage     24.76%   24.73%   -0.03%     
+ Complexity    11195    11185      -10     
============================================
  Files          1603     1602       -1     
  Lines         48444    48408      -36     
============================================
- Hits          11995    11975      -20     
+ Misses        36449    36433      -16     
Impacted Files Coverage Δ
app/Module/StatisticsChartModule.php 0.00% <0.00%> (ø)
app/Statistics/Google/ChartChildren.php 100.00% <ø> (ø)
app/Statistics/Google/ChartDistribution.php 44.06% <ø> (-0.94%) ⬇️
app/Statistics/Google/ChartNoChildrenFamilies.php 97.82% <ø> (ø)
resources/views/lists/chart-by-age.phtml 0.00% <0.00%> (ø)
resources/views/lists/chart-by-decade.phtml 0.00% <0.00%> (ø)
...sources/views/statistics/other/charts/column.phtml 0.00% <0.00%> (ø)
...esources/views/statistics/other/charts/combo.phtml 0.00% <0.00%> (ø)
...sources/views/statistics/other/charts/custom.phtml 0.00% <0.00%> (ø)
resources/views/statistics/other/charts/geo.phtml 0.00% <0.00%> (ø)
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cfc37d...4d3e366. Read the comment docs.

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

1 participant