Skip to content

Commit

Permalink
feat(homepage): add network case demo
Browse files Browse the repository at this point in the history
  • Loading branch information
serjilyashenko committed Sep 18, 2024
1 parent e549a82 commit d8b7f20
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/homepage-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- master
paths:
- .github/workflows/homepage-deploy.yml
# - packages/**/* FIXME: do we need to watch packages ?
- packages/simple-pie/**/*
- apps/homepage/**/*

concurrency: ${{ github.workflow }}-${{ github.ref }}
Expand Down
6 changes: 4 additions & 2 deletions apps/homepage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/check": "0.9.3",
"@astrojs/starlight": "0.27.1",
"astro": "4.15.4",
"sharp": "0.33.5",
"@astrojs/check": "0.9.3",
"typescript": "5.5.4"
"simple-pie": "*",
"typescript": "5.5.4",
"vis-network": "9.1.9"
}
}
108 changes: 108 additions & 0 deletions apps/homepage/src/components/Network.astro
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>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: Introduction
description: A guide in my new Starlight docs site.
---
import Network from '@components/Network.astro'

The `simple-pie` package family offers an easy way to create `SVG` pie and doughnut charts. These packages are lightweight
and ideal for situations where you need small, simple charts, such as in network graphs or other compact visualizations.
Expand All @@ -24,4 +25,10 @@ That's where `simple-pie` comes in. It provides a straightforward solution for c
doughnut charts. These charts are perfect for embedding in network graphs, maps, or any application where you need
a simple and efficient way to visualize data without the bulk of heavier libraries.

![net and map cases](https://raw.githubusercontent.com/serjilyashenko/simple-pie-project/master/docs/images/map-and-net-case.png)
## Network

<Network />

## Map

![map case](https://raw.githubusercontent.com/serjilyashenko/simple-pie-project/master/docs/images/map-case.png)
12 changes: 10 additions & 2 deletions apps/homepage/tsconfig.json
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/*"]
}
}
}
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d8b7f20

Please sign in to comment.