StructV2/demoV2/demo2.html
2021-08-30 23:57:05 +08:00

149 lines
3.5 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 {
background-color: #fafafa;
border: 1px solid #ccc;
position: relative;
}
.down {
display: flex;
margin-top: 20px;
}
#container {
width: 100%;
height: 400px;
}
#freed {
width: 200px;
height: 300px;
margin-right: 30px;
}
#leak {
width: 400px;
height: 300px;
}
</style>
</head>
<body>
<div class="container" id="container"></div>
<button id="btn-prev">prev</button>
<button id="btn-next">next</button>
<button id="hide">隐藏</button>
<span id="pos"></span>
<div class="down">
<div id="freed" class="container"></div>
<div id="leak" class="container"></div>
</div>
<script src="./../dist/sv.js"></script>
<script>
const Group = SV.Group,
Bound = SV.Bound,
G6 = SV.G6,
Vector = SV.Vector;
</script>
<script src="./Layouter/LinkList.js"></script>
<script src="./Layouter/BinaryTree.js"></script>
<script src="./Layouter/Stack.js"></script>
<script src="./Layouter/LinkQueue.js"></script>
<script src="./Layouter/GeneralizedList.js"></script>
<script src="./Layouter/ChainHashTable.js"></script>
<script src="./Layouter/Array.js"></script>
<script src="./Layouter/HashTable.js"></script>
<script src="./Layouter/LinkStack.js"></script>
<script src="./Layouter/AdjoinMatrixGraph.js"></script>
<script src="./Layouter/AdjoinTableGraph.js"></script>
<script>
let cur = SV(document.getElementById('container'), {
freedContainer: document.getElementById('freed'),
leakContainer: document.getElementById('leak'),
view: {
groupPadding: 40,
},
});
let data = [{
"g1": {
"data": [
{ id: 0, neighbor: [4, 3] }, { id: 1, neighbor: [0, 3] }, { id: 2, neighbor: [4, 0] },
{ id: 3, neighbor: [5, 2] }, { id: 4 },
{ id: 5, neighbor: [0, 1] }
],
// "layouter": "AdjoinTableGraph"
"layouter": "AdjoinMatrixGraph"
}
}];
let dataIndex = 0,
curData = data[dataIndex];
cur.render(curData);
let f = true;
document.getElementById('hide').addEventListener('click', e => {
f ? cur.hideGroups(['BinaryTree']) : cur.hideGroups(['LinkList']);
f = !f;
});
document.getElementById('btn-next').addEventListener('click', e => {
curData = data[++dataIndex];
cur.render(curData);
});
document.getElementById('btn-prev').addEventListener('click', e => {
curData = data[--dataIndex]
cur.render(curData);
});
cur.on('onLeak', () => { });
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>