-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display inheritance graph in model explorer (#1114)
* Add basic inheritance graph for schema docs * Fix schema explorer TOC * Add loading indicator * Make use of Mermaid’s own theming * Refactor: Make inheritance graph reusable For example to display a full graph of the model on the explorer index page… * Implement workaround for Astro bug This is a workaround due to an Astro bug. The bug has been fixed, but we're still on an older Astro version, and using a different file extension works fine for now. * Improve dark mode * Adjust edge/arrow styles * Use schema name (instead of label) in model explorer Most people using the model explorer will probably search for the schema name as that is what they use when creating mappings, writing crawlers, debugging problems with Aleph etc. The schema label is still visible on the index page, but we now use the name consistently in headings, page titles, navigation links etc.
- Loading branch information
1 parent
eba3773
commit 3ec49e0
Showing
18 changed files
with
1,291 additions
and
67 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,77 @@ | ||
--- | ||
import Spinner from '@components/common/Spinner.astro'; | ||
--- | ||
|
||
<script> | ||
import mermaid from 'mermaid'; | ||
import themeCSS from './mermaid-theme.css.txt?raw'; | ||
|
||
mermaid.initialize({ | ||
themeCSS, | ||
securityLevel: 'loose', | ||
fontFamily: 'var(--font-family)', | ||
startOnLoad: false, | ||
}); | ||
|
||
mermaid.run({ | ||
querySelector: '.mermaid__graph', | ||
postRenderCallback: (id) => { | ||
const element = document.getElementById(id); | ||
element.parentNode.dataset.rendered = 'true'; | ||
}, | ||
}); | ||
</script> | ||
|
||
<style> | ||
.mermaid { | ||
position: relative; | ||
padding: var(--space-sm); | ||
aspect-ratio: 16 / 9; | ||
|
||
background-color: var(--color-bg-elevated); | ||
border: 1px solid var(--color-border-default); | ||
border-radius: var(--radius); | ||
} | ||
|
||
@media screen and (prefers-color-scheme: dark) { | ||
.mermaid { | ||
background-color: rgba(0, 0, 0, 0.15); | ||
border-color: rgba(255, 255, 255, 0.1); | ||
} | ||
} | ||
|
||
.mermaid__graph:not([data-processed='true']) { | ||
display: none; | ||
} | ||
|
||
.mermaid__graph[data-rendered='true'] + .mermaid__spinner { | ||
display: none; | ||
} | ||
|
||
.mermaid__graph { | ||
display: flex; | ||
width: 100%; | ||
height: 100%; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.mermaid__graph > :global(svg) { | ||
max-width: 100%; | ||
max-height: 100%; | ||
} | ||
|
||
.mermaid__spinner { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
} | ||
</style> | ||
|
||
<div class="mermaid"> | ||
<div class="mermaid__graph"> | ||
<slot /> | ||
</div> | ||
<Spinner class="mermaid__spinner" /> | ||
</div> |
This file contains 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,43 @@ | ||
--- | ||
const { class: className } = Astro.props; | ||
--- | ||
|
||
<style> | ||
@keyframes spinner { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
.spinner__circle { | ||
display: inline-block; | ||
width: var(--space-xl); | ||
height: var(--space-xl); | ||
border-radius: 50%; | ||
border: 3px solid var(--color-fg-muted); | ||
border-right-color: var(--color-bg-subtle); | ||
animation: spinner 1s linear infinite; | ||
} | ||
|
||
.spinner__progress { | ||
position: absolute; | ||
width: 1px; | ||
height: 1px; | ||
margin: -1px; | ||
border: 0; | ||
padding: 0; | ||
|
||
white-space: nowrap; | ||
clip-path: inset(100%); | ||
clip: rect(0 0 0 0); | ||
overflow: hidden; | ||
} | ||
</style> | ||
|
||
<div class:list={['spinner', className]}> | ||
<progress class="spinner__progress"></progress> | ||
<span class="spinner__circle"></span> | ||
</div> |
This file contains 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,42 @@ | ||
.node .label-container { | ||
fill: var(--color-bg-default); | ||
stroke: var(--color-border-default); | ||
} | ||
|
||
.node.clickable:hover .label-container { | ||
fill: var(--color-bg-subtle); | ||
stroke: var(--color-border-emphasis); | ||
} | ||
|
||
.node-primary .label-container { | ||
fill: var(--color-bg-primary); | ||
stroke: var(--color-border-primary); | ||
} | ||
|
||
.node .nodeLabel { | ||
color: var(--color-fg-muted); | ||
} | ||
|
||
.node-primary .nodeLabel { | ||
color: var(--color-fg-primary); | ||
} | ||
|
||
.node.clickable:hover .nodeLabel { | ||
color: var(--color-fg-default); | ||
} | ||
|
||
.flowchart-link { | ||
stroke-width: 1.5px; | ||
stroke: var(--color-fg-muted); | ||
} | ||
|
||
.marker { | ||
fill: var(--color-fg-muted); | ||
stroke: none; | ||
} | ||
|
||
.arrowMarkerPath { | ||
// Workaround to change size of arrow heads as there is no | ||
// Mermaid config option | ||
transform: scale(0.75) translate(4px, 2px) | ||
} |
This file contains 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 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,31 @@ | ||
--- | ||
import Mermaid from '@components/common/Mermaid.astro'; | ||
import { getInheritanceEdges } from '@util/ftm'; | ||
import { schemaLink } from '@util/links'; | ||
const { schemata, activeSchema } = Astro.props; | ||
const base = Astro.site?.pathname; | ||
const edges = getInheritanceEdges(schemata); | ||
const graph = []; | ||
for (const schema of schemata) { | ||
graph.push(`${schema.name}(${schema.name})`); | ||
if (schema !== activeSchema) { | ||
graph.push(`click ${schema.name} "${schemaLink(base, schema)}"`); | ||
} | ||
} | ||
if (activeSchema) { | ||
graph.push(`class ${activeSchema.name} node-primary`); | ||
} | ||
for (const [child, parent] of edges) { | ||
graph.push(`${child.name}-->${parent.name}`); | ||
} | ||
--- | ||
|
||
<Mermaid> | ||
graph BT | ||
{graph.join('\n')} | ||
</Mermaid> |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,21 @@ | ||
--- | ||
import { RichContent } from 'astro-theme-docs/components'; | ||
import InheritanceGraph from '@components/explorer/InheritanceGraph.astro'; | ||
const { schema, ...rest } = Astro.props; | ||
const parents = schema.getParents(); | ||
const children = schema | ||
.getChildren() | ||
.filter((child) => child.getExtends().includes(schema)); | ||
--- | ||
|
||
<div class="schema-inheritance" {...rest}> | ||
<RichContent> | ||
<h2 class="beta">Inheritance</h2> | ||
<InheritanceGraph | ||
schemata={[schema, ...parents, ...children]} | ||
activeSchema={schema} | ||
/> | ||
</RichContent> | ||
</div> |
This file contains 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 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 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 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 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 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
Oops, something went wrong.