mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-04 07:56:33 +08:00
fix(network): ensure consistent node positions by storing and reusing seed
This commit is contained in:
@@ -31,13 +31,11 @@
|
|||||||
let network;
|
let network;
|
||||||
let nodes = new vis.DataSet();
|
let nodes = new vis.DataSet();
|
||||||
let edges = new vis.DataSet();
|
let edges = new vis.DataSet();
|
||||||
|
let seed = "";
|
||||||
/* global vis */
|
/* global vis */
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
const url = new URL('api/streams.dot' + location.search, location.href);
|
const url = new URL('api/streams.dot' + location.search, location.href);
|
||||||
const options = {
|
const options = {
|
||||||
layout: {
|
|
||||||
randomSeed: "0.4597730541017021:1718519934576"
|
|
||||||
},
|
|
||||||
edges: {
|
edges: {
|
||||||
font: { align: 'middle' },
|
font: { align: 'middle' },
|
||||||
smooth: false,
|
smooth: false,
|
||||||
@@ -66,16 +64,19 @@
|
|||||||
edges = new vis.DataSet(data.edges);
|
edges = new vis.DataSet(data.edges);
|
||||||
network = new vis.Network(container, { nodes, edges }, options);
|
network = new vis.Network(container, { nodes, edges }, options);
|
||||||
network.storePositions();
|
network.storePositions();
|
||||||
|
seed = network.getSeed();
|
||||||
} else {
|
} else {
|
||||||
const positions = network.getPositions();
|
const positions = network.getPositions();
|
||||||
const viewState = network.getViewPosition();
|
const viewState = network.getViewPosition();
|
||||||
const scale = network.getScale();
|
const scale = network.getScale();
|
||||||
|
network.setOptions({layout: {
|
||||||
|
randomSeed: seed
|
||||||
|
}})
|
||||||
network.setData(data);
|
network.setData(data);
|
||||||
|
|
||||||
for (const nodeId in positions) {
|
for (const nodeId in positions) {
|
||||||
if (positions.hasOwnProperty(nodeId)) {
|
if (positions.hasOwnProperty(nodeId)) {
|
||||||
network.moveNode(nodeId, positions[nodeId].x, positions[nodeId].y);
|
network.moveNode(nodeId, Math.floor(positions[nodeId].x), Math.floor(positions[nodeId].y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user