From 68736ff549afc1201fe729a28aa962ea1d6af13c Mon Sep 17 00:00:00 2001 From: Martin Vuk Date: Tue, 9 Dec 2025 06:27:31 +0100 Subject: [PATCH] Fiddling with positions --- git-figure.typ | 135 ++++++++++++++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 51 deletions(-) diff --git a/git-figure.typ b/git-figure.typ index b954069..10a3e4f 100644 --- a/git-figure.typ +++ b/git-figure.typ @@ -3,67 +3,100 @@ #import "@preview/fletcher:0.5.8" as fletcher: diagram, node, edge #import fletcher.shapes: house, chevron, pill, hexagon -#let commit-node(coord, hash, ..args) = node(coord, raw(hash), shape: pill, fill: orange.lighten(10%), stroke: none, ..args) -#let commit-object(coord, hash, name, ..args) = node(coord, align(left, [#text(size: 8pt, gray.darken(50%), raw(hash))\ #name]), corner-radius: 7pt, fill: orange.lighten(10%), stroke: none, ..args) +#let commit-color = green +#let tag-color = orange +#let branch-color = purple +#let thin = 0.5pt; +#let thindotted = (thickness: thin, dash: "dotted"); +#let thindashed = (thickness: thin, dash: "dashed"); +#let commit-node(coord, hash, ..args) = node(coord, raw(hash), shape: pill, fill: commit-color.lighten(50%), stroke: thin, ..args) +#let commit-object(coord, hash, name, ..args) = node(coord, align(left, [#text(size: 8pt, gray.darken(50%), raw(hash))\ #name]), corner-radius: 7pt, fill: commit-color.lighten(50%), stroke: none, ..args) +#let tree-object(coord, hash, ..args) = commit-object(coord, hash, [tree], width: 2cm, fill: blue.lighten(50%), ..args) +#let file-object(coord, hash, name, ..args) = commit-object(coord, hash, name, width: 2cm, fill: gray.lighten(50%), ..args) #diagram(debug: 1, node-stroke: 2pt, edge-stroke: 1pt, { - let thin = 0.5pt; - let thindashed = (thickness: thin, dash: "dashed"); - let store = (1, 7) + let store = (0.3, 6.7) + let (co1, co2) = { + let x = 0.2 + let y = store.at(1) + ((x, y+0.5), (x, y+1)) + } + let (tree1, tree2) = { + let x = 1.2 + ((x, co1.at(1)), (x, co2.at(1))) + } + let (f1, f2, f3) = { + let x = 2.2; + let y = store.at(1) + ((x, y), (x, y + 0.5), (x, y + 1)) + } let (A, B, C, D, E, F, G) = ((2, 6), (2, 5), (2, 4), (2, 3), (2, 2), (2, 1), (2, 0)) let (B1, B2) = ((3, 4.5), (3, 3.5)) let (E1, E2, E3) = ((3, 1.5), (3, 0.5), (3, -0.5)) - let (Br1, Br2) = ((G.at(0)-0.5, G.at(1)), (E2.at(0)-0.5, E2.at(1))) + let (Br1, Br2) = ((F.at(0)-0.5, F.at(1)), (E2.at(0)-0.5, E2.at(1))) let (T1, T2) = ((E.at(0)-0.5, E.at(1)), (B.at(0)-0.5, B.at(1))) - let refs = (3, 8) + let refs = (2.7, store.at(1)) let tags = (0.5, 3) let commit = (3.7, 2.5) - let branches = (1.2, -1) - let stage =(3.7, -1) + let branches = (0.5, 0) + let stage =(3.7, 0) let mc = (2.5, D.at(1)-0.5) - commit-object(store, "e264a1", [second commit]) - commit-object((store.at(0), store.at(1)+0.3), "16f29", [first commit], width: 2.8cm) - node(store, [Content addressable object store], width: 3cm, stroke: none, - enclose:((store.at(0), store.at(1)), (store.at(0)+1, store.at(1)+2))) - //node(A, [A 16f299], shape: pill, name: ) + //node(store, [Content addressable object store], stroke: none, width: 4cm) + commit-object(co1, "e264a1", [second commit]) + commit-object(co2, "16f29", [first commit], width: 2.8cm) + tree-object(tree1, "16f29") + tree-object(tree2, "16f29") + file-object(f1, "16f29", [`new content`]) + file-object(f2, "16f29", [`unchanged`]) + file-object(f3, "16f29", [`first content`]) + edge(tree1, f2, [`bar.txt`], "->", label-angle: auto) + edge(tree1, f1, [`foo.txt`], "->", label-angle: auto) + edge(tree2, f2, [`bar.txt`], "->", label-angle: auto) + edge(tree2, f3, [`foo.txt`], "->", label-angle: auto) + edge(co2, tree2, "->") + edge(co1, tree1, "->") + + + + //node(store, width: 5cm, stroke: thin, enclose:(co1, f3, f1)) + commit-node(A, "A 16f299") - node(B, [B 16f299], shape: pill) - node(C, [C 16f299], shape: pill) - node(D, [D 16f299], shape: pill) - node(E, [E 16f299], shape: pill) - node(F, [F 16f299], shape: pill) - node(G, [16f299], shape: pill) + commit-node(B, "B 16f299") + commit-node(C, "C 16f299") + commit-node(D, "D 16f299") + commit-node(E, "E 16f299") + commit-node(F, "F 16f299") // merge commit node(mc, [Merge commit\ #text(size: 8pt)[commit with two parents]], stroke: thin, corner-radius: 10pt) // merged branch - node(B1, [B1 16f299], shape: pill) - node(B2, [B2 16f299], shape: pill) + commit-node(B1, "B1 16f299") + commit-node(B2, "B2 16f299") // unmerged branch - node(E1, [E1 16f299], shape: pill) - node(E2, [E2 16f299], shape: pill) - node(E3, [E3 16f299], shape: pill, stroke: (dash: "dashed")) + commit-node(E1, "E1 16f299") + commit-node(E2, "E2 16f299") + commit-node(E3, "E3 16f299", fill: none, stroke: thindashed) // branches - node(Br1, [main], shape: hexagon, stroke: purple) - node(Br2, [hotfix], shape: hexagon, stroke: purple) + node(Br1, [main], shape: hexagon, stroke: branch-color) + node(Br2, [hotfix], shape: hexagon, stroke: branch-color) // tags - node(T1, [v-1.0], shape: chevron, stroke: green) - node(T2, [v-1.1], shape: chevron, stroke: green) + node(T1, [v-1.0], shape: chevron, stroke: tag-color) + node(T2, [v-1.1], shape: chevron, stroke: tag-color) // refs - node(refs, stroke: none, snap: false, enclose: (refs, (refs.at(0)+2, refs.at(0)+2)), - table(columns: 1, align: left, [*References* (`.git/refs`)], [*Tags* (`.git/refs/tags`)\ `tag-1`: `8dd6d4b...`], [*Branches* (`.git/refs/heads`) \ `main`: `8dd6d4b...`\ + node(refs, stroke: none, snap: false, enclose: (refs, (refs.at(0)+2, refs.at(1)+2)), + table(columns: 1, stroke: thin, align: left+top, [*References* (`.git/refs`)], [*Tags* (`.git/refs/tags`)\ `tag-1`: `8dd6d4b...`], [*Branches* (`.git/refs/heads`) \ `main`: `8dd6d4b...`\ `feature-1`: `8dd6d4b...`\ `hotfix`: `8dd6d4b...`]) ) - node(branches, [#text(stroke: purple.darken(50%))[BRANCH]\ #text[reference that moves when commiting canges]], - stroke: thin, corner-radius: 10pt, inset: 0pt, width: 1cm, enclose: ( + node(branches, [#text(branch-color.darken(20%))[*BRANCH*]\ #text[reference that moves along when commiting canges]], + stroke: thin, corner-radius: 10pt, inset: 5pt, width: 3cm) /*, enclose: ( (branches.at(0)-0.5, branches.at(1)), - (branches.at(0)+0.5, branches.at(1)))) - node(tags, [#text(stroke: green.darken(50%))[TAG]\ reference that don't move], + (branches.at(0)+1, branches.at(1))))*/ + node(tags, [#text(tag-color)[*TAG*]\ reference that don't move], stroke: thin, corner-radius: 10pt, inset: 0pt, width: 1cm, enclose: ((tags.at(0)-0.5, tags.at(1)), (tags.at(0)+1, tags.at(1)))) node(stage, [*Staging area*\ #text(size: 8pt)[filesystem snapshot that will be commited in the next commit]], stroke: thindashed, corner-radius: 10pt, width: 3cm) node(commit, [ - *COMMIT*\ snapshot of filesystem tree in object store\ + #text(commit-color)[*COMMIT*]\ snapshot of filesystem tree in object store\ #rect[ ``` tree 65c47fee... @@ -75,20 +108,20 @@ Add bar.txt ```] ], width:5cm, stroke: thin, corner-radius: 10pt) node((G.at(0)+0.4, G.at(1) - 0.3), [*Version history*\ - #text(size: 8pt)[ - Commits are nodes in _Directed Acyclic Graph (DAG)_ that describes version history - ]], stroke:none, width: 5cm) - node(A, snap: false, enclose: (A, E3), stroke: thindashed, width: 3cm) - let ic = (A.at(0)-0.6, A.at(1)+0.2); + #align(left, text(size: 8pt)[ + _Directed Acyclic Graph (DAG)_ describes version history. + Commits are nodes in DAG, while an edge connect a commit with its parent. + ])], stroke:none, width: 5cm) + node(A, snap: false, enclose: (A, E3), stroke: thindashed, width: 3cm, fill: gray.lighten(70%)) + let ic = (A.at(0)+0.7, A.at(1)-0.2); node(ic, [Initial commit], shape: pill, stroke: thin) - edge(ic, A, stroke: thin) + edge(ic, A, stroke: thindotted) // history edge(B, A, "->") edge(C, B, "->") edge(D, C, "->") edge(E, D, "->") edge(F, E, "->") - edge(G, F, "->") // merged branch edge(B1, B, "->", layer: 1, label: [parent of], label-angle: auto) edge(B2, B1, "->") @@ -98,17 +131,17 @@ Add bar.txt edge(E2, E1, "->") edge(E3, E2, "->", stroke: (dash: "dashed")) // refs - edge(Br1, G) + edge(Br1, F) edge(Br2, E2) edge(T1, E) edge(T2, B) - edge(Br1, branches, stroke: thin) - edge(Br2, branches, stroke: thin) - edge(T1, tags, stroke: thin) - edge(T2, tags, stroke: thin) - edge(commit, E, stroke: thin) - edge(stage, E3, stroke: thindashed) + edge(Br1, branches, stroke: thindotted) + edge(Br2, branches, stroke: thindotted) + edge(T1, tags, stroke: thindotted) + edge(T2, tags, stroke: thindotted) + edge(commit, E, stroke: thindotted) + edge(stage, E3, stroke: thindotted) edge((-0.5, A.at(1)), (-0.5, G.at(1)), "->", label: [time], label-side: left, label-angle: 90deg) - edge(mc, D, stroke: thin) + edge(mc, D, stroke: thindotted) } ) \ No newline at end of file