Remove redundant options prop from Graph component

This commit is contained in:
Maciej Pędzich 2024-04-28 23:57:46 +02:00
parent 0e72f6ce97
commit b9a2b2e85c
Signed by: maciejpedzich
GPG Key ID: CE4A303D84882F0D
2 changed files with 12 additions and 8 deletions

View File

@ -4,16 +4,14 @@ import type { Node, Edge, Options } from 'vis-network/esnext';
interface Props {
nodes: Node[];
edges: Edge[];
options?: Options;
}
const { nodes, edges, options = {} } = Astro.props;
const { nodes, edges } = Astro.props;
---
<vis-graph
data-nodes={JSON.stringify(nodes)}
data-edges={JSON.stringify(edges)}
data-options={JSON.stringify(options)}
>
<div></div>
</vis-graph>
@ -59,8 +57,7 @@ const { nodes, edges, options = {} } = Astro.props;
levelSeparation: 80
}
},
physics: false,
...(JSON.parse(this.dataset.options as string) as Options)
physics: false
};
new Network(container, data, options);

View File

@ -100,9 +100,15 @@ if (paramsNotEqual) {
</p>
{
nodes.length > 0 && (
<>
<div id="graph-container">
<Graph nodes={nodes} edges={edges} />
</div>
<small>
Drag to pan, scroll to zoom. Click on a node to highlight it and its
links.
</small>
</>
)
}
@ -110,5 +116,6 @@ if (paramsNotEqual) {
#graph-container {
height: 600px;
border: 1px solid gray;
margin-bottom: 0.5rem;
}
</style>