StructV2/demo/demo.html
2021-05-17 14:02:19 +08:00

138 lines
2.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DEMO</title>
<style>
* {
padding: 0;
margin: 0;
user-select: none;
}
.container {
width: 100%;
height: 400px;
background-color: #fafafa;
border: 1px solid #ccc;
}
.down {
display: flex;
margin-top: 20px;
}
#freed {
width: 200px;
height: 300px;
border: 1px solid #ccc;
background-color: #fafafa;
margin-right: 30px;
}
#leak {
width: 400px;
height: 300px;
border: 1px solid #ccc;
background-color: #fafafa;
}
</style>
</head>
<body>
<div class="container" id="container"></div>
<button id="btn">change</button>
<button id="btn-next">reLayout</button>
<button id="btn-set">set</button>
<span id="pos"></span>
<div class="down">
<div id="freed"></div>
<div id="leak"></div>
</div>
<script src="./../dist/sv.js"></script>
<script>
const Engine = SV.Engine,
Group = SV.Group,
Bound = SV.Bound,
G6 = SV.G6,
Vector = SV.Vector;
</script>
<script src="./dataStruct/BinaryTree.js"></script>
<script src="./dataStruct/LinkList.js"></script>
<script src="./dataStruct/Array.js"></script>
<script src="./dataStruct/ChainHashTable.js"></script>
<script src="./dataStruct/Stack.js"></script>
<script src="./dataStruct/LinkStack.js"></script>
<script src="./dataStruct/LinkQueue.js"></script>
<script src="./dataStruct/Graph.js"></script>
<script src="./dataStruct/DirectedGraph.js"></script>
<script src="./dataStruct/RingArray.js"></script>
<script src="./dataStruct/GeneralizedList.js"></script>
<script>
const engines = {
0: BTree,
1: LList,
2: A,
3: CHT,
4: St,
5: LStack,
6: LQueue,
7: G,
8: DG,
9: RA,
10: GL
};
let dataCounter = 0;
let cur = engines[3](document.getElementById('container'), {
freedContainer: document.getElementById('freed'),
leakContainer: document.getElementById('leak')
});
cur.engine.render(cur.data[dataCounter]);
document.getElementById('btn').addEventListener('click', e => {
cur.engine.render(cur.data[++dataCounter]);
});
document.getElementById('btn-next').addEventListener('click', e => {
cur.engine.reLayout();
});
document.getElementById('btn-set').addEventListener('click', e => {
let els = cur.engine.getElements();
els.map(item => {
item.set('style', { fill: 'red' });
});
});
const container = document.getElementById('container'),
pos = document.getElementById('pos');
container.addEventListener('mousemove', e => {
let x = e.offsetX, y = e.offsetY;
pos.innerHTML = `${x},${y}`;
});
</script>
</body>
</html>