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

Make vega charts dark mode compatible #431

Merged
merged 1 commit into from
Oct 30, 2023
Merged

Make vega charts dark mode compatible #431

merged 1 commit into from
Oct 30, 2023

Conversation

stefanw
Copy link
Member

@stefanw stefanw commented Oct 30, 2023

This means style information needs to be removed from spec config key in plugins via e.g.

import json
from fragdenstaat_de.fds_cms.cms_plugins import VegaChartCMSPlugin

charts = VegaChartCMSPlugin.objects.all()
for chart in charts:
    vega = json.loads(chart.vega_json)
    changed = vega.pop("background", None)
    config = vega.get("config")
    if config and config.get("axis", {}).get("domainColor"):
        vega.pop("config")
        changed = True
    if changed:
        print(chart.title)
        print(vega.get("background"), vega.get("config"))
        chart.vega_json = json.dumps(vega)
        chart.save()

Ideally, the chart specs do not come with colour values. This PR makes it so that the spec colours takes precedence over the theme colors, in case you want to adjust per chart.

@stefanw stefanw requested a review from krmax44 October 30, 2023 09:07
This means style information needs to be removed from spec config key in database via e.g.
```python
import json
from fragdenstaat_de.fds_cms.cms_plugins import VegaChartCMSPlugin

charts = VegaChartCMSPlugin.objects.all()
for chart in charts:
    vega = json.loads(chart.vega_json)
    changed = vega.pop("background", None)
    config = vega.get("config")
    if config and config.get("axis", {}).get("domainColor"):
        vega.pop("config")
        changed = True
    if changed:
        print(chart.title)
        print(vega.get("background"), vega.get("config"))
        chart.vega_json = json.dumps(vega)
        chart.save()
```
@krmax44 krmax44 merged commit 378cd7d into main Oct 30, 2023
3 checks passed
@krmax44 krmax44 deleted the stefanw/vega-dark branch October 30, 2023 12:37
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.

2 participants