-
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.
- Loading branch information
Showing
20 changed files
with
897 additions
and
219 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,14 @@ | ||
<script lang="ts"> | ||
import GraphRendering from "./GraphRendering" | ||
import GraphControls from "./GraphControls" | ||
</script> | ||
|
||
<main> | ||
<GraphRendering/> | ||
<GraphControls/> | ||
</main> | ||
|
||
<style lang="sass"> | ||
main | ||
position: relative | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<script lang="ts"> | ||
import {ALL_RULES} from "./hypergraphs/rules"; | ||
import HyperGraphRule from "./hypergraphs/hyperGraphRule"; | ||
import {activeRule, ruleProgress} from "./stores"; | ||
let rules: Array<HyperGraphRule> = ALL_RULES; | ||
</script> | ||
|
||
<section class="controls"> | ||
<div class="controls-in"> | ||
{#each rules as rule} | ||
<div class="controls-item" on:click={() => activeRule.set(rule)}> | ||
<p>{rule.name}</p> | ||
<div class="controls-item-time"> | ||
{#if rule === $activeRule} | ||
<span style="width: {$ruleProgress}%"></span> | ||
{/if} | ||
</div> | ||
</div> | ||
{/each} | ||
</div> | ||
</section> | ||
|
||
<style lang="sass"> | ||
@import "styles/variables" | ||
.controls | ||
position: absolute | ||
top: 0 | ||
left: 0 | ||
height: 100% | ||
width: 100% | ||
display: flex | ||
justify-content: flex-end | ||
align-items: center | ||
pointer-events: none | ||
&-in | ||
max-width: 275px | ||
width: 100% | ||
margin-right: 60px | ||
pointer-events: all | ||
&-item | ||
position: relative | ||
width: 100% | ||
color: $c-main | ||
cursor: pointer | ||
p | ||
margin: 0 | ||
padding: 15px 0 5px | ||
font-size: 18px | ||
font-family: 'Avenir', serif | ||
&-time | ||
position: absolute | ||
left: 0 | ||
bottom: 0 | ||
width: 100% | ||
height: 2px | ||
border-radius: 3px | ||
border: 1px $c-main solid | ||
span | ||
display: block | ||
width: 1px | ||
height: 100% | ||
background-color: $c-main | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<script lang="ts"> | ||
import ForceGraph3D, {ForceGraph3DInstance} from '3d-force-graph'; | ||
import "./styles/style.sass"; | ||
import HyperGraph from "./hypergraphs/hyperGraph"; | ||
import {MathUtils} from "three"; | ||
import generateUUID = MathUtils.generateUUID; | ||
import HyperGraphRule from "./hypergraphs/hyperGraphRule"; | ||
import {activeRule, currentTick, ruleProgress} from "./stores"; | ||
import {onMount} from "svelte"; | ||
const EXPANDED_EDGES_SIGNATURE: string = 'expanded'; | ||
const EXPANDED_EDGES_COLOR: string = 'rbga(0,0,0,0)'; | ||
interface GraphData { | ||
nodes: object[], | ||
links: object[], | ||
} | ||
// * star expansion algorithm for converting hypergraphs to graphs | ||
function convertToGraph(hyperGraph: HyperGraph): GraphData { | ||
let result: GraphData = {nodes: [], links: []}; | ||
for (let i of hyperGraph.nodes) { | ||
result.nodes.push({id: i}); | ||
} | ||
for (let edge of hyperGraph.edges){ | ||
if(edge.length >= 3) { | ||
let newNodeId = generateUUID(); | ||
result.nodes.push({id: newNodeId, [EXPANDED_EDGES_SIGNATURE]: EXPANDED_EDGES_COLOR}); | ||
for(let i of edge) { | ||
result.links.push({source: i, target: newNodeId}) | ||
} | ||
} | ||
if(edge.length == 2) { | ||
result.links.push({source: edge[0], target: edge[1]}) | ||
} | ||
if(edge.length < 2) { | ||
throw Error('Edge must have at least two nodes'); | ||
} | ||
} | ||
return result; | ||
} | ||
let interval; | ||
function renderGraph(graph: ForceGraph3DInstance, rule: HyperGraphRule, speed: number) { | ||
clearInterval(interval); | ||
ruleProgress.set(0, { | ||
duration: 0 | ||
}); | ||
currentTick.set(1); | ||
let graphData = rule.optimalInitialPositions; | ||
graph.graphData(convertToGraph(graphData)); | ||
interval = setInterval(() => { | ||
if($currentTick >= rule.optimalTicksAmount) { | ||
clearInterval(interval); | ||
} | ||
graphData = rule.apply(graphData); | ||
graph.graphData(convertToGraph(graphData)); | ||
graph.zoomToFit(speed, 200); | ||
ruleProgress.set((100 / rule.optimalTicksAmount) * $currentTick); | ||
currentTick.update(n => n + 1); | ||
}, speed); | ||
} | ||
onMount(async () => { | ||
const element = document.getElementById('graph-rendering'); | ||
const graph = ForceGraph3D() | ||
(element) | ||
.linkOpacity(0.5) | ||
.nodeColor(EXPANDED_EDGES_SIGNATURE); | ||
activeRule.subscribe(activeRule => { | ||
renderGraph(graph, activeRule, 750); | ||
}) | ||
}) | ||
</script> | ||
|
||
|
||
<section id="graph-rendering"> | ||
</section> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.