-
-
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.
Refactor: Make inheritance graph reusable
For example to display a full graph of the model on the explorer index page…
- Loading branch information
1 parent
c363bd6
commit 1a102db
Showing
3 changed files
with
52 additions
and
61 deletions.
There are no files selected for viewing
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.label})`); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,21 @@ | ||
--- | ||
import { RichContent } from 'astro-theme-docs/components'; | ||
import SchemaLink from '@components/explorer/SchemaLink.astro'; | ||
import Mermaid from '@components/common/Mermaid.astro'; | ||
import { getInheritanceAdjacency } from '@util/ftm'; | ||
import { schemaLink } from '@util/links'; | ||
import InheritanceGraph from '@components/explorer/InheritanceGraph.astro'; | ||
const { schema, ...rest } = Astro.props; | ||
const base = Astro.site?.pathname; | ||
const parents = schema.getExtends(); | ||
const edges = getInheritanceAdjacency(schema); | ||
const nodes = new Set(); | ||
nodes.add(schema); | ||
for (const [child, parent] of edges) { | ||
nodes.add(child); | ||
nodes.add(parent); | ||
} | ||
const graphDef = []; | ||
for (const node of nodes) { | ||
graphDef.push(`${node.name}(${node.label})`); | ||
if (node !== schema) { | ||
graphDef.push(`click ${node.name} "${schemaLink(base, node)}"`); | ||
} | ||
} | ||
graphDef.push(`class ${schema.name} node-primary`); | ||
for (const [child, parent] of edges) { | ||
graphDef.push(`${child.name}-->${parent.name}`); | ||
} | ||
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> | ||
|
||
<Mermaid> | ||
graph BT | ||
{graphDef.join('\n')} | ||
</Mermaid> | ||
<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