g6/demos/viewport-fitView.html
2018-06-14 15:34:37 +08:00

59 lines
1.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>视口-自适应</title>
</head>
<body>
适应视口:
<button class="fitView">tl</button>
<button class="fitView">tc</button>
<button class="fitView">tr</button>
<button class="fitView">cc</button>
<button class="fitView">lc</button>
<button class="fitView">rc</button>
<button class="fitView">bl</button>
<button class="fitView">bc</button>
<button class="fitView">br</button>
<button class="fitView">autoZoom</button>
<div id="mountNode"></div>
<script src="../build/g6.js"></script>
<script>
const data = {
nodes: [{
id: 'node1',
x: 100,
y: 200
}, {
id: 'node2',
x: 300,
y: 200
}],
edges: [{
id: 'edge1',
target: 'node2',
source: 'node1'
}]
};
const graph = new G6.Graph({
container: 'mountNode',
fitView: 'cc',
height: window.innerHeight,
fitView: 'cc'
});
graph.read(data);
const buttons = document.getElementsByClassName('fitView');
for (let index = 0; index < buttons.length; index++) {
const button = buttons[index];
button.onclick = () => {
graph.setFitView(button.innerHTML);
};
}
</script>
</body>
</html>