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
546 stars 25 forks source link

Ability to add `hidden: true` to a chart codeblock #82

Open holroy opened 1 year ago

holroy commented 1 year ago

Describe the feature

I would like the ability to hide some of the datasets by default when using a chart codeblock, similar to what can be done using the javascript variant.

So to extend the default line chart example, I would like for the following to work:

```chart  
type: line  
labels: [Monday,Tuesday,Wednesday,Thursday,Friday]
series:  
  - title: Title 1  
    hidden: true
    data: [1,2,3,4,5]  
  - title: Title 2
    data: [5,4,3,2,1]
  - title: Title 3  
    data: [8,2,5,-1,4]  


And that this displays as a default display of the example after clicking on the first title icon to hide it:
![image](https://user-images.githubusercontent.com/11348165/228807608-332202b4-4abb-4f51-8896-ca9a85d0212f.png)

### Does this fix a problem? If so, specify.

It's not so much a problem, as an inconvenience if one want to include data for multiple various datasets readily available for display, but not displayed from the start.

### Did you consider other alternatives?

It can be solved if using a javascript variant to render the chart, as shown [in this Obsidian forum thread](https://forum.obsidian.md/t/how-to-set-default-state-of-a-chart-dataset-to-off/57204/4?u=holroy), by utilising the `hidden: true` feature of the underlying `chart.js` library, so I reckon it shouldn't be too hard to implement. Also see https://www.chartjs.org/docs/latest/api/interfaces/ControllerDatasetOptions.html#hidden for original definition of the variable, and how it propagates into multiple other DatasetOption variants.

I've also tried moving the `hidden: true` statement around in the codeblock definition, but I could not get it to trigger in the places I've tried. Please do prove me wrong, if this in indeed is already possible, and I've just not found the correct way to enter it. 

### Screenshots and recordings

_No response_