Dmytro-Shulha / obsidian-plotly

Obsidian plugin to embed Plotly charts into markdown notes.
MIT License
70 stars 4 forks source link

Load .plotly or .json file for display #9

Open gregmoille opened 2 years ago

gregmoille commented 2 years ago

Hi,

At the moment I believe there is only the possibility of displaying Plotly with embedded code inside the dataviewjs. Plotly allows to save a serialized version of their plot (JSON format, with .plotly) extension and was wondering if we could make it possible to load such file for display. This would simply a lot the notes I believe

something like should work I believe

function readTextFile(file, callback) {
    var rawFile = new XMLHttpRequest();
    rawFile.overrideMimeType("application/json");
    rawFile.open("GET", file, true);
    rawFile.onreadystatechange = function() {
        if (rawFile.readyState === 4 && rawFile.status == "200") {
            callback(rawFile.responseText);
        }
    }
    rawFile.send(null);
}

readTextFile("PlotlyFileSomehwere.plotly", function(text){
    var data = JSON.parse(text);
    dv.paragraph(data);
    window.renderPlotly(this.container, data)
});
Dmytro-Shulha commented 11 months ago

Hello!

That is correct - as of now, charts can only be created via plotly and dataviewjs code blocks. With dataviewjs block, it is already posible to load and draw plots from any file (but I haven't tested your code yet).

I support your idea to simplify this process and I see two approaches to that:

Other ideas and suggestions are appreciated.

Dmytro-Shulha commented 11 months ago

Also, as a sidenote, I think users should have a way to define their own custom functions that they would reuse across their plotly charts. Maybe in settings menu.