diagramo
v0.2.0
Published
Tree-shaped diagram language renderer for Surface, Core, and NCF diagrams.
Maintainers
Readme
diagramo
Diagramo renders Surface, Core, and NCF S-expression diagrams into SVG.
This package includes:
src/diagramo.js: editable source modulesrc/browser-entry.js: browser-global auto-render entrydist/diagramo.js: npm ESM entrydist/diagramo.browser.js: standalone browser bundle for static pages
Install
npm install diagramoDev Demo
clone repo then enter root project repo
python -m http.serverPublishable package layout
Edit src/diagramo.js, then regenerate the browser bundle with:
npm install
npm run buildThat command:
- copies
src/diagramo.jstodist/diagramo.js - bundles
src/browser-entry.jstodist/diagramo.browser.js
ESM usage
import { renderAll, renderElement, renderSource, compileSource } from "diagramo";
renderAll(document);Render a single element:
import { renderElement } from "diagramo";
const el = document.querySelector("pre.diagramo");
renderElement(el, { zoom: false });Render directly into a host element:
import { renderSource } from "diagramo";
const host = document.querySelector("#diagram-host");
renderSource(`(program (X) (-> f X Y))`, host, { zoom: false, height: 320 });Static page drop-in
After publishing, you can use the browser bundle from a CDN:
<pre class="diagramo">
(program
(X)
(ZinsideX:X)
(-> f A B)
(-> g B A)
(-> h X Y)
)</pre>
<script src="https://unpkg.com/diagramo/dist/diagramo.browser.js"></script>The browser bundle auto-renders pre.diagramo elements on page load.
Default behavior
- zoom is off by default
- source
<pre>elements are replaced with rendered hosts - labels default to IDs in Surface shorthand
(-> f A B)synthesizes missing nodesAandB- the host auto-grows to avoid clipping labels and arrowheads
Data attributes
These can be placed on the source element or the host:
data-diagramo-mode="auto|surface|core|ncf"data-diagramo-zoom="on|off"data-diagramo-ortho="on|off"data-diagramo-wiring="on|off"data-diagramo-glyphs="on|off"data-diagramo-height="360"
Example:
<pre class="diagramo" data-diagramo-height="420" data-diagramo-zoom="off">
(program
(X)
(-> f X Y)
)</pre>Browser global API
The standalone browser bundle exposes window.Diagramo with:
parseSexprcompileAstcompileSourceemitCoreDocemitNCFDocrenderSourcerenderElementrenderAllautoRender
API
compileSource(source, mode = "auto")
Returns:
{
kind, // "surface" | "core" | "ncf"
core, // canonical core doc object or null
ncf, // canonical ncf doc object
coreText, // core serialization
ncfText, // ncf serialization
warnings // array of warning strings
}renderSource(source, host, options = {})
Options:
modezoomorthowiringglyphsheightobserveResizereplaceSource
Returns:
{
host,
compiled,
fit,
rerender
}Surface shorthand supported
(A) ; node A, label "A"
(ZinsideX:X) ; child ZinsideX under X
(-> f A B) ; arrow f from A to B, label "f", synthesize A/B if neededFiles
src/diagramo.jssrc/browser-entry.jsscripts/build.mjsdist/diagramo.jsdist/diagramo.browser.jsexamples/static-page.html
