StructV2/demoV2/demo2.html

215 lines
5.6 KiB
HTML
Raw Normal View History

2021-07-31 16:43:01 +00:00
<!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;
2021-08-10 16:10:37 +00:00
position: relative;
2021-07-31 16:43:01 +00:00
}
.down {
display: flex;
margin-top: 20px;
}
2021-08-10 16:10:37 +00:00
#container {
width: 100%;
height: 400px;
}
2021-07-31 16:43:01 +00:00
#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">
2021-08-10 16:10:37 +00:00
<div id="freed" class="container"></div>
<div id="leak" class="container"></div>
2021-07-31 16:43:01 +00:00
</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>
let cur = SV(document.getElementById('container'), {
freedContainer: document.getElementById('freed'),
leakContainer: document.getElementById('leak')
});
2021-08-10 16:10:37 +00:00
let data = [{
"LinkQueue": {
"data": [
{
"type": "head",
"name": "Qptr",
"id": "0x616eb0",
"label": "front",
"front": "node#0x616ed0",
"external": [
"lq"
]
},
{
"type": "head",
"name": "Qptr",
"id": "0x616eb1",
"label": "rear",
"rear": "node#0x616ed0",
"external": null
},
{
"type": "node",
"id": "0x616ed0",
"data": "",
"next": null,
"root": true
},
{
"type": "node",
"id": "0x616ef0",
"data": "D",
"next": null,
"root": true,
"external": [
"p"
]
}
],
"layouter": "LinkQueue"
}
},{
"LinkQueue": {
"data": [
{
"type": "head",
"name": "Qptr",
"id": "0x616eb0",
"label": "front",
"front": "node#0x616ed0",
"external": [
"lq"
]
},
{
"type": "head",
"name": "Qptr",
"id": "0x616eb1",
"label": "rear",
"rear": "node#0x616ed0",
"external": null
},
{
"type": "node",
"id": "0x616ed0",
"data": "",
"next": null,
"root": true
},
{
"type": "node",
"id": "0x616ef0",
"data": "",
"next": null,
"root": true,
"external": [
"p"
],
"freed": true
}
],
"layouter": "LinkQueue"
}
}];
2021-07-31 16:43:01 +00:00
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>