-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proof of concept custom raw charts with inject hook #330
Conversation
|
Got web workers work also for custom charts @bianchimro 😎 |
…ks in web workers
…1 for uploaded files
… on charts steps cache only valid charts pkgs
Thanks to the suggestions of @bianchimro and @osioalberto i write a tiny AMD loader that also works with WebWorkers. Yes, as UMD you can load the charts itself using for example: https://cdn.jsdelivr.net/npm/@rawgraphs/rawgraphs-charts I also notify the user to be careful to load third party javascript with a simple modal. To have a friendly url to try i upload the bundled version of https://github.com/gffuma/custom-rawcharts-template-test
So if your starts the app from this branch and link the correct version of the core ... if you visit: You will see: The caution modal: ... If you continue the custom chart: |
A proof of concept demo of custom raw charts.
This demo can load a new chart(s) and auto save it when you reload the pages using the caches api.
How does it work?
This demo expose
d3
andrawgraphsCore
on thewindow
object thanks to this the custom charts can mark this dependencies as global and with the changes of rawgraphs/rawgraphs-charts#110 the baseline size of a chart including the svg icons is ~7KB.This demo expose a global "stack" on window (
RAWGRAPH_APP_INJECT_HOOK
) this approach is similar to how google analytics, react dev tools and other libraries works.When a new chart is loaded we append a script to head (this is how code splitting works), we wait them and we pop all the stack inside the inject hook. This approach is much better instead of exposing static prop Ex
RAWGRAPH_CUSTOM_CHART = ...
because we can executed scripts in parallel an wait for all them and them simply pop the stack.For the purpose of the demo i use a naive approach to compute "the name of the script" i simply split the chart graph and take the first piece this is the name of our pack and i used to save it to the storage cache.
The only temp downside of this demo is that i disabled WebWorkers for simplicity, (we can still easy use web workers for core charts) to use WebWorker for custom charts we need to make also the chart imported a worker this need future investigation.
How can i try this???
Start the repo on this branch.
Clone this: https://github.com/gffuma/custom-rawcharts-template-test
Hack your custom chart.
Run
npm install
andnpm run build
from the custom chart repo.Upload to RawApp the file inside the custom chart repo called
lib/index.iife.js
Now you can see your chart! 🚀