phibr0 / obsidian-charts

Charts - Obsidian Plugin | Create editable, interactive and animated Charts in Obsidian via Chart.js
https://charts.phib.ro/
GNU Affero General Public License v3.0
568 stars 26 forks source link

[Bug]: Theme colors are not applied when multiple charts are present in Live Preview #62

Open kepano opened 1 year ago

kepano commented 1 year ago

Describe the bug

When a note contains multiple charts, several colors are no longer respected if you are in Live Preview. This is especially noticeable in dark mode.

  1. Axes numbers switch from theme color (I think --text-muted) to black
  2. Some grid lines are either removed or go transparent, I am not sure
  3. --chart-color-1 etc are reset to default and do not use the theme color

Example from Minimal Theme with Solarized color (available via Minimal Theme Settings plugin). Issue 1 and 2 are also present when using the default theme.

Reading mode

Screen Shot 2022-10-27 at 1 05 31 PM

Live preview

Screen Shot 2022-10-27 at 1 05 28 PM

Relevant errors (if available)

No response

Steps to reproduce

Expected Behavior

No response

Additional context

No response

Code

type: line
legend: false
layout: columns
beginAtZero: false
time: month
yMin: 0

Operating system

macOS

phibr0 commented 1 year ago

Thats weird, I will take a look over the weekend

kepano commented 1 year ago

Note that this issue started a few months ago, it wasn't always the case. I can't identify exactly when it started though.

TomHall2020 commented 1 year ago

Not sure if you got any further with this but just found the same problem with chart text turning black when multiple charts are rendered. For me the issue only happens when the contextual typography plugin is enabled to control the block widths; disabling the plugin solves it.

Also worth noting that for me the dataviewjs charts appear rendered at 100% full width regardless of what I set the chart size to in minimal theme settings, which I guess makes sense as they are in a dataviewjs block not a chart block but is still confusing.

AllJavi commented 1 year ago

I have had the same problem, for some reason the grid disappeared and the units appeared in black. I have been researching a bit and it turns out that for some reason the plugin is loaded before the variables that it accesses to put the colors of those elements:

# chartRenderer.ts (lines: 54 - 60)
        ...
        const gridColor = getComputedStyle(el).getPropertyValue('--background-modifier-border');

        let chartOptions: ChartConfiguration;

        Chart.defaults.color = getComputedStyle(el).getPropertyValue('--text-muted');
        Chart.defaults.font.family = getComputedStyle(el).getPropertyValue('--mermaid-font');
        Chart.defaults.plugins = {
       ...

and this generates them to stay black. The simplest way to fix it and considering that it doesn't happen to everyone, is to put, like in the previous parameters, an option in the YAML that allows configuring these colors.

sillvva commented 10 months ago

Forked this to modify the above to allow configuration.

Changed

Chart.defaults.color = getComputedStyle(el).getPropertyValue('--text-muted');

to

Chart.defaults.color = yaml.textColor || getComputedStyle(el).getPropertyValue('--text-muted');

Result

One is using textColor: lightgrey. The other is using textColor: red

CleanShot 2023-10-21 at 19 22 27@2x