I know this is likely easy, but I have been stuck for days and cannot figure it out on my own with my current meager knowledge.
The question has two parts:
- specific
- general
- what is the right/best way to load external libraries such as this one, which are not always needed, but may be needed by a block of code?
Prior knowledge:
- I have used GraphViz before, but in the command line. I have not used Viz.js before outside of the WYSIWYG editor they provide at https://viz-js.com/
- I have loaded python libraries with kits and pyodide (but cannot figure out how to do the same with js)
- essentially zero javascript. At most, I can read or very minorly modify existing code.
What I have tried so far:
- look for an existing solution through website searches and in the forums.
- These threads are related Support rendering charts, like Graphviz and Stronger GraphViz control but do not provide guidance.
- There is the plug-in logseq diagrams as code, but it acts as a wrapper for an external API.
import { instance } from "../assets/custom/vizjs-3.8.0/viz-standalone.js";
in a block and run it with kits using{{evalparent}}
- Error:
Uncaught (in promise) SyntaxError: Cannot use import statement outside a module
. I went on an exploration about how to solve this, but most about the explanation on modules, and react and node.js specific cases escape me at this time.
- Error:
- load
viz-standalone.js
with thecustom-js.url:
line inconfig.edn
. I am unsure if this loads the script and I do know know how to use it or if it never loads. Searching in thesources
tab of the electron inspector does not show the fileviz-standalone.js
anywhere. When I run the examples, in Viz.js - API, the console returnsReferenceError: Viz is not defined
orReferenceError: instance is not defined
, which tells me it either did not load or I am invoking it wrong.-
instance().then(viz => { const svg = viz.renderSVGElement("digraph { a -> b }"); document.getElementById("graph").appendChild(svg); });
-
Viz.instance().then(function(viz) { var svg = viz.renderSVGElement("digraph { a -> b }"); document.getElementById("graph").appendChild(svg); });
-
- create a skeleton plugin and load
viz-standalone.js
with it fromindex.html
with<script type="module" crossorigin src="./assets/viz-standalone-3.8.0.js"></script>
- The plugin loads, although with a warning that it takes long to load and will delay app startup time (ideally, it would only load on use). However, I am unable to generate a graph with either of the two examples above. The errors are the same as when with the
custom-js:
inconfig.edn
option.
- The plugin loads, although with a warning that it takes long to load and will delay app startup time (ideally, it would only load on use). However, I am unable to generate a graph with either of the two examples above. The errors are the same as when with the
Thank you very much in advance to anyone who can help : ).