-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(homepage): add network case demo
- Loading branch information
1 parent
e549a82
commit d8b7f20
Showing
6 changed files
with
134 additions
and
7 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
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,108 @@ | ||
--- | ||
--- | ||
|
||
<div id="network-container" class="network-container">hi</div> | ||
|
||
<script> | ||
import { simplePie } from "simple-pie"; | ||
import { DataSet } from "vis-data"; | ||
import { Network } from "vis-network"; | ||
import "vis-network/styles/vis-network.css"; | ||
|
||
function getRandomPieDataUri() { | ||
const values = Array.from({ length: Math.ceil(Math.random() * 10) }, () => | ||
Math.ceil(Math.random() * 10), | ||
); | ||
const element = simplePie(values); | ||
element.setAttribute("width", "70"); | ||
element.setAttribute("height", "70"); | ||
|
||
const svg = new XMLSerializer().serializeToString(element); | ||
|
||
return `data:image/svg+xml;base64,${btoa(svg)}`; | ||
} | ||
|
||
// @ts-ignore | ||
const nodes = new DataSet([ | ||
{ | ||
id: 1, | ||
shape: "image", | ||
image: getRandomPieDataUri(), | ||
shapeProperties: { useImageSize: true }, | ||
}, | ||
{ | ||
id: 2, | ||
shape: "image", | ||
image: getRandomPieDataUri(), | ||
shapeProperties: { useImageSize: true }, | ||
}, | ||
{ | ||
id: 3, | ||
shape: "image", | ||
image: getRandomPieDataUri(), | ||
shapeProperties: { useImageSize: true }, | ||
label: "Pull me! I'm interactive!", | ||
}, | ||
{ | ||
id: 4, | ||
shape: "image", | ||
image: getRandomPieDataUri(), | ||
shapeProperties: { useImageSize: true }, | ||
}, | ||
{ | ||
id: 5, | ||
shape: "image", | ||
image: getRandomPieDataUri(), | ||
shapeProperties: { useImageSize: true }, | ||
}, | ||
{ | ||
id: 6, | ||
shape: "image", | ||
image: getRandomPieDataUri(), | ||
shapeProperties: { useImageSize: true }, | ||
}, | ||
{ | ||
id: 7, | ||
shape: "image", | ||
image: getRandomPieDataUri(), | ||
shapeProperties: { useImageSize: true }, | ||
}, | ||
]); | ||
|
||
// @ts-ignore | ||
const edges = new DataSet([ | ||
{ from: 1, to: 2 }, | ||
{ from: 1, to: 3 }, | ||
{ from: 2, to: 4 }, | ||
{ from: 2, to: 5 }, | ||
{ from: 6, to: 2 }, | ||
{ from: 7, to: 2 }, | ||
]); | ||
|
||
// create a network | ||
const container = document.getElementById("network-container"); | ||
|
||
if (!container) { | ||
throw new Error("html container not found"); | ||
} | ||
|
||
const data = { | ||
nodes: nodes, | ||
edges: edges, | ||
}; | ||
const options = {}; | ||
|
||
new Network(container, data, options); | ||
</script> | ||
|
||
<style> | ||
.network-container { | ||
height: 400px; | ||
width: 100%; | ||
border: 1px dashed darksalmon; | ||
} | ||
|
||
.network-container .vis-network:focus{ | ||
outline: none; | ||
} | ||
</style> |
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
{ | ||
"extends": "astro/tsconfigs/strict" | ||
} | ||
"extends": "astro/tsconfigs/strict", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@assets/*": ["src/assets/*"], | ||
"@components/*": ["src/components/*"], | ||
"@content/*": ["src/content/*"] | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.