-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for Graphviz diagrams #2052
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cda28bd
Add support for Graphviz dot diagrams
dscho a7cac47
graphviz: use <img> elements instead of <svg> ones
dscho f2d5b6f
graphviz: make the diagrams' background transparent by default
dscho d9f9c5b
graphviz: allow overriding the engine
dscho e458803
graphviz: optionally pre-generate the SVGs
dscho 66d59f7
graphviz: support the `alt` attribute
dscho 4f58ebc
deploy/ci: pre-render the Graphviz diagrams
dscho 352dbbf
Replace the diagrams in `about/distributed` with Graphviz versions
dscho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,22 +27,101 @@ <h4>Subversion-Style Workflow</h4> | |
A centralized workflow is very common, especially from people transitioning from a centralized system. Git will not allow you to push if someone has pushed since the last time you fetched, so a centralized model where all developers push to the same server works just fine. | ||
</p> | ||
<p class="center"> | ||
<img src="{{< relurl "images/about/[email protected]" >}}" width="415" height="209" alt="Workflow A"> | ||
{{< graphviz alt="workflow A" >}} | ||
digraph dev_workflow { | ||
layout=neato; | ||
overlap=false; | ||
sep="+10"; | ||
node [shape=box, style="filled,rounded", penwidth=0, fontname="Helvetica"]; | ||
edge [penwidth=3, color="gray", arrowsize=0.5, dir=both]; | ||
|
||
shared_repo [label="shared repository", fillcolor=teal, fontcolor=white, pos="2,1.5!"]; | ||
|
||
developer1 [label="developer", fillcolor=lightblue, pos="0,0!"]; | ||
developer2 [label="developer", fillcolor=lightblue, pos="2,0!"]; | ||
developer3 [label="developer", fillcolor=lightblue, pos="4,0!"]; | ||
|
||
developer1 -> shared_repo; | ||
developer2 -> shared_repo; | ||
developer3 -> shared_repo; | ||
} | ||
{{< /graphviz >}} | ||
</p> | ||
<h4>Integration Manager Workflow</h4> | ||
<p> | ||
Another common Git workflow involves an integration manager — a single person who commits to the 'blessed' repository. A number of developers then clone from that repository, push to their own independent repositories, and ask the integrator to pull in their changes. This is the type of development model often seen with open source or GitHub repositories. | ||
</p> | ||
<p class="center"> | ||
<img src="{{< relurl "images/about/[email protected]" >}}" width="407" height="164" alt="Workflow B"> | ||
{{< graphviz alt="workflow B" >}} | ||
digraph workflow { | ||
layout=neato; | ||
overlap=false; | ||
node [shape=box, style="filled,rounded", penwidth=0, fontname="Helvetica"]; | ||
edge [penwidth=3, color="gray", arrowsize=0.5]; | ||
|
||
// Nodes | ||
blessed_repo [label="blessed\nrepository", fillcolor=teal, fontcolor=white, margin="0.3", pos="0,3!"]; | ||
integration_manager [label="integration\nmanager", fillcolor=orange, fontcolor=white, pos="0,1!"]; | ||
|
||
dev_pub1 [label="developer\npublic", fillcolor="#CCAA00", fontcolor=black, pos="2,3!"]; | ||
dev_pub2 [label="developer\npublic", fillcolor="#CCAA00", fontcolor=black, pos="4,3!"]; | ||
|
||
dev_priv1 [label="developer\nprivate", fillcolor="#CCAA00", fontcolor=black, pos="2,1!"]; | ||
dev_priv2 [label="developer\nprivate", fillcolor="#CCAA00", fontcolor=black, pos="4,1!"]; | ||
|
||
// Edges with labels | ||
dev_priv1 -> dev_pub1; | ||
dev_priv2 -> dev_pub2; | ||
integration_manager -> blessed_repo; | ||
|
||
dev_pub1 -> integration_manager [color="lightgray"]; | ||
dev_pub2 -> integration_manager [color="lightgray"]; | ||
blessed_repo -> dev_priv1 [color="lightgray"]; | ||
blessed_repo -> dev_priv2 [color="lightgray"]; | ||
} | ||
{{< /graphviz >}} | ||
</p> | ||
<h4>Dictator and Lieutenants Workflow</h4> | ||
<p> | ||
For more massive projects, a development workflow like that of the Linux kernel is often effective. | ||
In this model, some people ('lieutenants') are in charge of a specific subsystem of the project and they merge in all changes related to that subsystem. Another integrator (the 'dictator') can pull changes from only his/her lieutenants and then push to the 'blessed' repository that everyone then clones from again. | ||
</p> | ||
<p class="center"> | ||
<img src="{{< relurl "images/about/[email protected]" >}}" width="562" height="303" alt="Workflow C"> | ||
{{< graphviz alt="workflow C" >}} | ||
digraph workflow { | ||
layout=neato; | ||
overlap=false; | ||
node [shape=box, style="filled,rounded", penwidth=0, fontname="Helvetica"]; | ||
edge [penwidth=3, color="gray", arrowsize=0.5]; | ||
|
||
// Nodes | ||
blessed_repo [label="blessed\nrepository", fillcolor=teal, fontcolor=white, margin="0.3", pos="6,4!"]; | ||
dictator [label="dictator", fillcolor=red, fontcolor=white, pos="0,4!"]; | ||
|
||
lieutenant1 [label="lieutenant", fillcolor="#CCAA00", fontcolor=white, pos="0,2.5!"]; | ||
lieutenant2 [label="lieutenant", fillcolor="#CCAA00", fontcolor=white, pos="2,3!"]; | ||
|
||
developer1 [label="developer", fillcolor=lightblue, fontcolor=black, pos="0,1!"]; | ||
developer2 [label="developer", fillcolor=lightblue, fontcolor=black, pos="2,1!"]; | ||
developer3 [label="developer", fillcolor=lightblue, fontcolor=black, pos="4,1!"]; | ||
developer4 [label="developer", fillcolor=lightblue, fontcolor=black, pos="6,1!"]; | ||
|
||
// Edges | ||
dictator -> blessed_repo; | ||
lieutenant1 -> dictator; | ||
lieutenant2 -> dictator; | ||
|
||
developer1 -> lieutenant1; | ||
developer2 -> lieutenant1; | ||
developer3 -> lieutenant2; | ||
developer4 -> lieutenant2; | ||
|
||
blessed_repo -> developer1; | ||
blessed_repo -> developer2; | ||
blessed_repo -> developer3; | ||
blessed_repo -> developer4; | ||
} | ||
{{< /graphviz >}} | ||
</p> | ||
<div class="bottom-nav" style="display: block;"> | ||
<a href="{{< relurl "about/small-and-fast" >}}" class="previous" data-section-id="small-and-fast">← Small and Fast</a> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
To1ne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
outputs: | ||
- json | ||
--- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{{- $diagram_list := where .Site.Pages "RawContent" "like" "{{< graphviz" -}} | ||
{{- $diagram_list | jsonify -}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<pre class="graphviz"{{ if (ne "" (.Get "engine")) }} engine="{{(.Get "engine")}}"{{ end }}{{ if (ne "" (.Get "alt")) }} alt="{{ (.Get "alt") }}"{{ end }}> | ||
{{ .Inner | htmlEscape | safeHTML }} | ||
</pre> | ||
{{ .Page.Store.Set "hasGraphviz" true }} | ||
To1ne marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env node | ||
|
||
import { readFileSync, writeFileSync } from "node:fs" | ||
import { parse } from "node-html-parser" | ||
import Viz from "../static/js/viz-global.js" | ||
|
||
/* | ||
* This script post-processes the site as generated via Hugo, replacing the | ||
* `<pre class="graphviz">` elements with inline `<svg>` ones, pre-rendered | ||
* via `viz-js`. | ||
*/ | ||
;(async () => { | ||
for (const { Path: pathInPublic } of JSON.parse(readFileSync("public/diagram-list.json", "utf-8"))) { | ||
const path = `public${pathInPublic}.html` | ||
const contents = readFileSync(path, "utf-8") | ||
const html = parse(contents) | ||
const vizImport = html.querySelector('script[src$="viz-global.js"]') | ||
if (!vizImport) { | ||
To1ne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.error(`No 'viz-global.js' import found in ${path}; skipping`) | ||
continue | ||
} | ||
vizImport.nextElementSibling.remove() // remove the inline script | ||
vizImport.remove() // remove the import | ||
|
||
for (const pre of html.querySelectorAll("pre.graphviz")) { | ||
const engine = pre.getAttribute("engine") || "dot" | ||
const svg = (await Viz.instance()).renderString(pre.textContent, { | ||
format: "svg", | ||
graphAttributes: { | ||
bgcolor: "transparent", | ||
}, | ||
engine, | ||
}) | ||
const alt = pre.getAttribute("alt") | ||
const altAttr = !alt ? '' : ` alt='${alt.replaceAll("&", "&").replaceAll("'", "'")}'` | ||
const dataURL = `data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}` | ||
pre.replaceWith(`<img${altAttr} src="${dataURL}" />`) | ||
} | ||
console.log(`Rewriting ${path}`) | ||
writeFileSync(`${path}`, html.toString()) | ||
} | ||
})().catch((e) => { | ||
console.error(e) | ||
process.exitCode = 1 | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the commit message:
@dscho That no longer seems to be the case now
<svg>
is no longer is inlined. It's a nitpick on the commit message, I don't consider this an issue that it's not the case. Do you think it worthy to edit the commit message?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I force-pushed a fix:
Range-diff
1: a2c59d6 ! 1: 352dbbf Replace the diagrams in
about/distributed
with Graphviz versions