Skip to content

Commit 5467001

Browse files
committed
Generate the web page for VanGraph
1 parent 5a199b8 commit 5467001

File tree

10 files changed

+458
-5
lines changed

10 files changed

+458
-5
lines changed

codegen/gen.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
bun run transform-vanui-readme.ts ../../van/components/README.md vanui-README.md
22
bun run gen-code.ts codegen-template.ts vanui-README.md ../sitegen/vanui.ts
33
bun run gen-code.ts codegen-template.ts ../../converter/README.md ../sitegen/convert-lib.ts
4+
bun run gen-code.ts codegen-template.ts ../../van/graph/README.md ../sitegen/graph.ts

graph.html

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<!DOCTYPE html>
2+
<html lang="en"><head>
3+
<link rel="icon" href="/logo.svg">
4+
<title>VanGraph - Visualize Dependencies in Your App</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<style>
8+
@font-face {
9+
font-family: 'Poppins';
10+
font-style: normal;
11+
font-weight: 400;
12+
src: url(https://fonts.gstatic.com/s/poppins/v20/pxiEyp8kv8JHgFVrJJfedw.ttf) format('truetype');
13+
}
14+
</style>
15+
<link rel="stylesheet" href="/code/w3-v1.css">
16+
<link rel="stylesheet" href="/code/prism-v1.css">
17+
<link rel="stylesheet" href="/vanjs.css">
18+
</head>
19+
<body class="line-numbers" data-prismjs-copy="📋">
20+
<!-- Google tag (gtag.js) -->
21+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Q0NB75RY7E"></script>
22+
<script>
23+
window.dataLayer = window.dataLayer || [];
24+
function gtag(){dataLayer.push(arguments);}
25+
gtag('js', new Date());
26+
27+
gtag('config', 'G-Q0NB75RY7E');
28+
</script>
29+
<script type="text/javascript" src="/code/prism-v1.js" defer></script>
30+
<!-- Sidebar/menu -->
31+
<nav class="w3-sidebar w3-red w3-collapse w3-top w3-large w3-padding" style="z-index:3;width:280px;font-weight:bold;" id="mySidebar"><br>
32+
<a href="javascript:void(0)" onclick="w3_close()" class="w3-button w3-hide-large w3-display-topleft" style="width:100%;font-size:22px">Close Menu</a>
33+
<div class="w3-container">
34+
<h1 class="w3-padding-16 w3-xxxlarge">
35+
<img src="/logo.svg" alt="VanJS" width="192px" height="192px">
36+
</h1>
37+
</div>
38+
<div id="nav" class="w3-bar-block"><a href="/" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Home</a><a href="/start" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Getting Started</a><a href="/tutorial" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Tutorial</a><a href="/demo" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">VanJS by Example</a><a href="/convert" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">HTML/MD to VanJS</a><a href="/vanui" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">VanUI</a><a href="/minivan" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Mini-Van</a><a href="/ssr" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">SSR &amp; Hydration</a><a href="/x" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">X</a><a href="/advanced" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Advanced Topics</a><a href="/media" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Media Coverage</a><a href="/about" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">About</a></div>
39+
</nav>
40+
41+
<!-- Top menu on small screens -->
42+
<header class="w3-container w3-top w3-hide-large w3-red w3-xlarge w3-padding">
43+
<a href="javascript:void(0)" class="w3-button w3-red w3-margin-right" onclick="w3_open()"></a>
44+
<span id="title-bar"></span>
45+
</header>
46+
47+
<!-- Overlay effect when opening sidebar on small screens -->
48+
<div class="w3-overlay w3-hide-large" onclick="w3_close()" style="cursor:pointer" title="close side menu" id="myOverlay"></div>
49+
50+
<!-- !PAGE CONTENT! -->
51+
<div class="w3-main" style="margin-left:300px;">
52+
<div id="page">
53+
<div id="content"><h1 class="w3-xxlarge"><strong>VanGraph</strong>: Visualize Dependencies in Your App</h1><p><strong>VanGraph</strong> is a library that helps you visualize dependency graph among states and DOM nodes with the help of <a href="https://graphviz.org/" class="w3-hover-opacity">Graphviz</a>. Here is the sample usage:</p><pre><code class="language-js">const firstName = van.state("Tao"), lastName = van.state("Xin")
54+
const fullName = van.derive(() =&gt; `${firstName.val} ${lastName.val}`)
55+
56+
// Build the DOM tree...
57+
58+
// To visualize the dependency graph among `firstName`, `lastName`, `fullName`, and all the
59+
// derived states and DOM nodes from them.
60+
vanGraph.show({firstName, lastName, fullName})
61+
</code></pre><p>Checkout a demo in <a href="https://codesandbox.io/p/devbox/github/vanjs-org/van/tree/main/graph/examples/basic?file=%2Fsrc%2Fmain.ts" class="w3-hover-opacity">CodeSandbox</a>.</p><h2 class="w3-xxlarge w3-text-red" id="installation"><a class="self-link" href="#installation">Installation</a></h2><hr style="width:50px;border:5px solid red" class="w3-round"><h3 class="w3-large w3-text-red" id="via-npm"><a class="self-link" href="#via-npm">Via NPM</a></h3><p>The library is published as NPM package <a href="https://www.npmjs.com/package/vanjs-graph" class="w3-hover-opacity">vanjs-graph</a>. Run the following command to install the package:</p><pre><code class="language-shell">npm install vanjs-graph
62+
</code></pre><p>To use the NPM package, add this line to your script:</p><pre><code class="language-js">import * as vanGraph from "vanjs-graph"
63+
</code></pre><h3 class="w3-large w3-text-red" id="via-a-script-tag"><a class="self-link" href="#via-a-script-tag">Via a Script Tag</a></h3><p>Alternatively, you can import <strong>VanGraph</strong> from CDN via a <code class="symbol">&lt;script type="text/javascript"&gt;</code> tag:</p><pre><code class="language-html">&lt;script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/van-graph.nomodule.min.js"&gt;&lt;/script&gt;
64+
</code></pre><p><code class="symbol">https://cdn.jsdelivr.net/npm/[email protected]/dist/van-graph.nomodule.js</code> can be used for the non-minified version.</p><p>Note that: you need to import <strong>VanJS</strong> and <code class="symbol">@viz-js/viz</code> before <strong>VanGraph</strong> for it to be used properly:</p><pre><code class="language-html">&lt;script type="text/javascript" src="https://cdn.jsdelivr.net/gh/vanjs-org/van/public/van-1.5.2.nomodule.min.js"&gt;&lt;/script&gt;
65+
&lt;script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@viz-js/[email protected]/lib/viz-standalone.js"&gt;&lt;/script&gt;
66+
</code></pre><p><a href="https://jsfiddle.net/zo49cqys/1/" class="w3-hover-opacity">Try on jsfiddle</a></p><h2 class="w3-xxlarge w3-text-red" id="documentation"><a class="self-link" href="#documentation">Documentation</a></h2><hr style="width:50px;border:5px solid red" class="w3-round"><pre><code class="language-js">vanGraph.show(states[, options]) =&gt; Promise&lt;SVGSVGElement&gt;
67+
</code></pre><p>The parameter <code class="symbol">states</code> represents a collection of <code class="symbol">State</code> objects whose dependency graph we want to visualize. All the <code class="symbol">State</code> objects and their dependents will be rendered in the dependency graph. <code class="symbol">states</code> can either be specified as a plain object, e.g.: <code class="symbol">{firstName, lastName, fullName}</code>, or as an array, e.g.: <code class="symbol">[firstName, lastName, fullName]</code>. If <code class="symbol">states</code> is specified as an array, the variable names won't be shown in the rendered graph.</p><p><code class="symbol">options</code> is a plain object with the following properties:</p><ul><li><code class="symbol">rankdir</code>: Type <code class="symbol">string</code>. Default <code class="symbol">"LR"</code>. Optional. Corresponding to the graph attribute <code class="symbol">rankdir</code> in Graphviz.</li></ul><p>The function returns a <code class="symbol">Promise&lt;SVGSVGElement&gt;</code> so that you can await the result and then attach <code class="symbol">SVGSVGElement</code> to the main DOM tree.</p></div>
68+
<aside id="toc"><ul><li><a href="#installation" class="w3-hover-opacity">Installation</a><ul><li><a href="#via-npm" class="w3-hover-opacity">Via NPM</a></li><li><a href="#via-a-script-tag" class="w3-hover-opacity">Via a Script Tag</a></li></ul></li><li><a href="#documentation" class="w3-hover-opacity">Documentation</a></li></ul></aside>
69+
</div>
70+
</div>
71+
<script>
72+
// Script to open and close sidebar
73+
const w3_open = () => {
74+
document.getElementById("mySidebar").style.display = "block"
75+
document.getElementById("myOverlay").style.display = "block"
76+
}
77+
78+
const w3_close = () => {
79+
document.getElementById("mySidebar").style.display = "none"
80+
document.getElementById("myOverlay").style.display = "none"
81+
}
82+
83+
const tocDom = document.getElementById("toc")
84+
85+
// Tracks the current toc item
86+
const trackToc = () => {
87+
const allHeadings = [...document.querySelectorAll("h2,h3")]
88+
const currentHeadingIndex = allHeadings.findIndex(h => h.getBoundingClientRect().top >= 0)
89+
let currentHeading
90+
if (currentHeadingIndex < 0) currentHeading = allHeadings[allHeadings.length - 1]; else {
91+
currentHeading = allHeadings[currentHeadingIndex]
92+
if (currentHeadingIndex > 0 && currentHeading.getBoundingClientRect().top > innerHeight)
93+
currentHeading = allHeadings[currentHeadingIndex - 1]
94+
}
95+
for (const e of document.querySelectorAll("#toc li a"))
96+
if (e.href.split("#")[1] === currentHeading?.id) {
97+
e.classList.add("current-heading")
98+
const {top: tocTop, bottom: tocBottom} = tocDom.getBoundingClientRect()
99+
const {top: eTop, bottom: eBottom} = e.getBoundingClientRect()
100+
if (eBottom > tocBottom) tocDom.scrollTop += eBottom - tocBottom
101+
else if (eTop < tocTop) tocDom.scrollTop -= tocTop - eTop
102+
} else
103+
e.classList.remove("current-heading")
104+
}
105+
trackToc()
106+
document.addEventListener("scroll", trackToc)
107+
addEventListener("resize", trackToc)
108+
109+
const copy = e => {
110+
const file = e.previousElementSibling.innerText
111+
const importLine = file.includes("nomodule") ?
112+
`<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/vanjs-org/van/public/${file}"><\/script>` :
113+
`import van from "https://cdn.jsdelivr.net/gh/vanjs-org/van/public/${file}"`
114+
navigator.clipboard.writeText(importLine)
115+
.then(() => e.querySelector(".tooltip").innerText = "Copied")
116+
.catch(() => e.querySelector(".tooltip").innerText = "Copy failed")
117+
}
118+
119+
const resetTooltip = e => e.querySelector(".tooltip").innerText = "Copy import line"
120+
</script>
121+
<!-- Place this tag in your head or just before your close body tag. -->
122+
<script async defer src="https://buttons.github.io/buttons.js"></script>
123+
124+
125+
<link rel="prefetch" href="/code/prism-v1.js" as="script"><link rel="prefetch" href="https://www.gstatic.com/charts/loader.js" as="script"><link rel="prefetch" href="/code/diff.min.js" as="script"><link rel="prefetch" href="/code/van-1.5.2.nomodule.min.js" as="script"><link rel="prefetch" href="/code/van-x-0.6.1.nomodule.min.js" as="script"></body></html>

0 commit comments

Comments
 (0)