Giter VIP home page Giter VIP logo

obsidian-plotly's Introduction

obsidian-plotly

Obsidian plugin, which allow user to embed Plotly charts into markdown notes.

Usage

Basic (using plotly block)

Use Command Palette (Ctrl-P) to add basic plotly template: Command example

This approach allows you to create JSON or YAML inside plotly block with payload for data, layout and config objects. It does NOT support JavaScript examples from plotly.com site - it only support static payload forvarding to Plotly.newPlot function. For JavaScript support use Advanced approach with DataViewJS.

Basic example (those YAML and JSON result in identical plots):

    ```plotly
    data:
    	- x: [0,1,2]
    	  y: [0,1,0]
    ```
    ```plotly
    {
        "data": [{
            "x":[0, 1, 2],
            "y":[0, 1, 0]
        }]
    }
    ```

Advanced (using dataviewjs block)

Use Command Palette (Ctrl-P) to add plotly template: Command example

This approach DOES support any example from plotly.com. (I haven't checked them all, feel free to create issue if some aren't working). However, this approach require DataView plugin to process JavaScript. As a benefit, you can create plots based on data from you notes which you retrieve via DataView API! (By the way, this sounds similar to what obsidian-tracker plugin does).

To use it, just add DataviewJS block with Plotly command, copy desired example and paste it. NOTE: All examples use Plotly.newPlot(component, data, layout, config) to draw, and it takes some extra code to work in Obsidian. There is a wrapper function available as window.renderPlotly(this.component, data, layout, config), which will draw plot inside DataViewJS block. (Wrapper parameters should be same as in example).

A lot of examples are on Plotly official site.

How to copy examples from plotly.com

NOTE: Some examples also require d3 library. This is large library and rarely needed. That's why I do not want to have it in plugin. If you need this library, there is a workaround: you can download d3 library from official site (Open link->Right click->Save as...), place it in your vault and import using require;

    ```dataviewjs
        //Some plotly examples require d3 library to work.
        //Since it's large and used by few examples,
        //I propose a workaround to import d3;
        //You need to download dependency from https://d3js.org/d3.v7.min.js
        //and place it in your vault.
        let path = app.vault.adapter.basePath;//absolute path to your vault
        var d3 = require(path+"\\utils\\d3.v7.min.js");

        //Replace this block with any example from plotly.com
        //NOTE: `Plotly.newPlot` won't work here, use `window.renderPlotly` instead
        var data = [
            {x:[0,1,2,3,4,5,6,7,8,9],y:[4,4,2,2,3,3,2,2,4,4]},
            {x:[0,1,2,3,4,5,6,7,8,9],y:[3,3,1,1,2,2,1,1,3,3]}
        ];
        var layout = {title:"Example in DataViewJS"};
        var config = {displaylogo:false};

        window.renderPlotly(this.container, data, layout, config)
    ```

Examples

Some more obsidian examples of this plugin here

More examples on Plotly official site.

obsidian-plotly's People

Contributors

antoshidza avatar dlbpointon avatar dmytro-shulha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

obsidian-plotly's Issues

Implement feature: command palette - on create plot - add modal with basic chart examples list

Basically, when 'create plot' command is executed, list of examples should be shown.
User should be able to choose one and click 'Enter", then such example will be pasted at current cursor position.

Since plotly documentation has plenty of examples, some additional hierarchical organizing structure is preferable (such as in "community plugin - browse" view).

However, it is better to start with simple list and basic examples.

docs would be greatly appreciated

Pasting code directly from Plotly website is not working.

obraz

  • I get things like this. I've been able to figure it out for some basic charts, but for some more complex ones (for example stacked bars, box plot etc) some instructions would be greatly appreciated.

Set default values in settings

As a user, I want to be able to define default 'layout' and 'config' values in settings.

Also, dataviewjs-based template now have hardcoded part with path to d3 dependency.
It also should be defined in settings.

Toggling path to lib insertion would be a good addition.

Syntax error with more complex graphs

Hi! I have tried to get the plotly plugin to work but it only allows me to make basic plots. If I use another example from plotly.com it shows me a syntax error. So, how can we achieve more complex plots with this tool?

Thanks in advance

Bug: plugin commands do not appear on palette (sometimes)

OS: Windows 10 Pro version 22H2
Obsidian:

  • installer version 1.3.7
  • current version 1.4.2
    Plotly plugin: version 0.0.6

I have noticed strange plugin behavior during development.
If I create new empty vault, install plotly plugin, enable it and open command palette, commands do not appear on the list. Even after reloading vault, commands still do not appear.

This bug was reproduced on:

  • fresh new vault (with zero other plugins)
  • my personal vault (with lots of additional plugins enabled)
  • vault dedicated for plugin development (though eventually I have triggered comands to appear somehow)

However, this bug was not reproduced on Obsidian Help sandbox vault - commands appeared on the palette list successfully on first attempt for some reason.

As of now I have no idea what is happenning here, hope I will eventually figure it out.

Latex in Charts

I tried to add LaTex to the graph and failed to do so.

As in the Documentation stated, there is the MathJax Engine to be loaded for correctly loading LaTex with MathJax.js?config=TeX-MML-AM_CHTML. In the Documentation, they load it within the HTML Script. What are the options to make this work in the Plugin?

Dataviewjs does not show title

```dataviewjs
 let path = app.vault.adapter.basePath;//absolute path to your vault
 var d3 = require(path+"\\utils\\d3.v7.min.js");

var trace1 = { 
	x: [1, 2, 3, 4, 5], 
	y: [1, 5, 3, 5, 1], 
	mode: 'lines+markers', 
	name: 'spline', 
	line: {shape: 'spline'}, 
	type: 'scatter' };

var data = [trace1]; 

var layout = {  
	title: {text: 'my title'},
	margin: { l: 20, r: 20, b: 40, t: 20, pad: 4 },
	autosize: false, 
	height: 200,
	showlegend: true,
	yaxis: { title: "y Axis"},
	xaxis: { title: "x Axis"}};
	
window.renderPlotly(this.container, data, layout, {staticPlot: true});
``` ```

is not able to show the title of the graph, neither the axis titles.

Math support

How can I enable math support?
Currently, the graph does just not render when text contains latex notation. The Obsidian console shows:
image

The chart-studio.plotly.com -Export contains the following section:

<script type="text/javascript">
    window.MathJax = {
        root: 'mathjax',
        config: 'TeX-AMS-MML_SVG.js',
        extensions: ['Safe.js']
    };
</script>
<script type="text/javascript" src="mathjax/MathJax.js"></script>

I am not certain how Obsidian handles math, maybe there is another/a better way.

Sample Graph (click to open)
let path = app.vault.adapter.basePath;//absolute path to your vault
var d3 = require(path+"\\Attachments\\d3.v7.min.js");

var data = [
        {
            "mode": "markers",
            "type": "scatter",
            "x": [
                "0"
            ],
            "y": [
                "0"
            ]
        }
    ];
var layout = {
        "title": {
            "text": "$Division: \\frac{z1}{z2}$"
        },
        "xaxis": {
            "type": "linear",
            "range": [
                -0.03357993312190732,
                0.601359413680969
            ],
            "title": {
                "text": "$\\text{Re} z$"
            },
        },
        "yaxis": {
            "type": "linear",
            "range": [
                -0.03635300993571011,
                0.002220923436586791
            ],
            "title": {
                "text": "$i \\text{Im} z$"
            },
        },
		"annotations": [
            {
                "x": 0.5862068965517241,
                "y": -0.034482758620689655,
                "ax": 0,
                "ay": 0,
                "font": {
                    "size": 12,
                    "family": "Arial"
                },
                "text": "",
                "xref": "x",
                "yref": "y",
                "align": "center",
                "axref": "x",
                "ayref": "y",
                "xanchor": "left",
                "yanchor": "bottom",
                "arrowhead": 2,
                "arrowsize": 1.5,
                "showarrow": true,
                "arrowcolor": "rgb(51, 129, 228)",
                "arrowwidth": 2
            },
            {
                "x": 0.5862068965517241,
                "y": -0.034482758620689655,
                "text": "$\\frac{34}{58}+\\frac{-2}{58}i$",
                "yanchor": "top",
                "showarrow": false
            }
        ]
    };
var config = {staticPlot: true};

window.renderPlotly(this.container, data, layout, config)

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)
});

Implement feature: width and height scaling to auto fill, or partially fill screen

User should be able to set width and height scaling.

For each plot individually, I believe it is possible to do via layout or config properties of each plot.

For all plots, the ability to set global default values will be implemented in #4

Also, in case abovementioned options won't be sufficient, then possibility to provide additional scaling options should be investigated.

Implement feature: settings - custom d3 path; maybe download from settings menu

Since some plotly charts rely on D3 library, which is big and I do not want it to be part of plugin bundle, managing it's usage should be simplified.

As of now, the only way to use D3 is to download .min.js file from official site, place it somewhere in a vault and provide correct path in your dataviewjs block with chart code (using hardcoded output of 'create new chart' command).

Better way would be an option to set path to D3 in settings menu.
Downloading D3 lib also can be done from settings menu, but that might expose user to security risks and needs to be investigated.

This change will eliminate need to explicitly set path to D3 lib in each chart.

Separated from #4

Plotly: New Plotly Chart doesn't work

ctrl + P -> Plotly: New Plotly Chart generates and it doesn't render anything

data:
	- x: [0,1,2]
	  y: [0,1,0]

Instead it prints Couldn't render plot:YAMLParseError: Tabs are not allowed as indentation at line 2, column 1: data: - x: [0,1,2] ^

Installed from win obsidian Plotly version 0.0.6

Instead it should be

data:
- x: [0,1,2]
  y: [0,1,0]

How to create time-series charts?

I would like to use dataviewjs and plot various values on a timeline, be it in a line chart or bar chart or such. But I couldn't figure out how to do that from examples.

If, say, I have a CharacterCount key with some value in several notes, I can use pg.CharacterCount.values to plot the numbers. I don't know how to use inherent metadata, e.g. file.cday, to assign the values to their dates. I found a workaround in providing another key in those notes, e.g. Cdate, with the date value (which works only if surrounded with quotes, as far as i can tell). Not ideal but doable.
I also dont know how to show dates with no values with corresponding 0 values (I mean for days when no note contains CharacterCount, meaning nothing was written).

I would be glad for any help and i am already grateful for the plugin, really cool, thanks.

Insert chart gui (like obsidian-charts)

Great work getting plotly graph into obsidian! Can't thank you enough =)

A couple of improvement points that would be great:

  • Insert chart gui, like obsidian-graphs have to create basic line and scatter charts as a starting point (others can be added later, plotly has a huge amount of setups, but at least basic ones would be wonderful), personally I think yaml works best with obsidian
  • Width and height scaling to auto fill, or partially fill screen.
  • Standard color scheme to match active theme

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.