obsidian-plotly
obsidian-plotly copied to clipboard
Load .plotly or .json file for display
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)
});
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:
- by providing additional block processor (
plotly-file
or something) - by providing user a single function for loading and rendering file
Other ideas and suggestions are appreciated.
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.