Hey all, I'm a backend developer and very new with Typescript/JS/Node/etc. That said, I am taking a shot at doing some d3 JS visualizations in a Joplin plugin.
My Goal: In a panel on the side of Joplin, render a small graph using d3 JS.
What I've tried:
- I created a new Plugin successfully with an index.s and a viz.js file.
- I set up some HTML from index.ts and had that display successfully.
- I then added my vis.js script to the panel (
await panels.addScript(view, './viz.js');
) and had vis.js log to the console successfully. Good so far - I then added d3.js to the panel:
await panels.addScript(view, './d3.v6.min.js');
- Now, this is where I had issues. I now want to run
d3.select()
inside my viz .js file
Issues
- Trying to call the
d3.select()
function returns an errord3 is undefined
. - Ok, that makes sense, I never imported it. I then tried adding
import * as d3 from './d3.min.js
to viz.js and got the error:Cannot use import statement outside a module
- I next tried
const d3 = require('d3')
after I didnpm install d3
but received the error:require is not define at viz.js:1
- After quite a bit of searching, I found this Joplin forum thread that sounded similar so I thought that I might have to compile my viz.js script. I remove the
require
andimport
from from viz.js and added it toextraScripts
in plugins.config.json. I then got the error:exports is not defined at viz.js:1
I did a lot of searching around the exports is not defined
but have no clue what's going on there. Looking in the dist/
directory, the very first line of the compiles scripts contains exports
.
Is there a simpler way to make d3JS available within a panel/webview for visualization? I read through most other plugins' source code but could not find example of anyone using JS libraries inside the webview vs directly from index.tx