Phase 2: Schaubild mit Cytoscape.js, Konzept v0.5
- App topologie: Graph aus den Daten (Hosts als Rahmen, Gäste, Bridges, Ports)
- Linien beschriftet mit CIDR und VLAN, abgeleitet aus den Daten ("?" bei Lücken)
- Drag & Drop, Positionen gespeichert über logische IDs, Anordnung zurücksetzen
- Hosts auf-/zuklappen, nur benutzte Ports (Schalter "Alle Ports zeigen")
- Filter Netz und Status, Detailbereich mit Link in den Admin
- Model: Schnittstelle.abgeleitete_netze(), vlan_angaben(), Bridge.netze()
- Cytoscape.js 3.35.0 lokal eingebunden
- Startseite mit Übersicht, Navigation
- README v0.5 (Kapitel 7.1, Homelab-Daten nach Netzplan), AUFBAUPLAN: Phase 2/3 getauscht
- 63 Tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c1766cd8ca
commit
ab8e0d8ffd
17 files changed
+1101
-46
No files matched your search
@@ -0,0 +1,433 @@
|
||||
/*
|
||||
* Schaubild des Netzwerk Planers (README Kapitel 7.1).
|
||||
*
|
||||
* Grundsatz: Verschieben ändert nur Positionen, nie die Daten.
|
||||
* Die Ansicht wird bei jeder Zustandsänderung (Host zu-/aufklappen, Ports
|
||||
* ein-/ausblenden) aus dem vollständigen Datensatz neu aufgebaut. Positionen
|
||||
* liegen dabei in `positionen` und werden nur für Blatt-Knoten gespeichert –
|
||||
* die Lage eines Rahmens ergibt sich immer aus seinem Inhalt.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const URLS = JSON.parse(document.getElementById("schaubild-urls").textContent);
|
||||
const SPEICHER_ZUGEKLAPPT = "netzwerk-planer:zugeklappt";
|
||||
|
||||
let cy;
|
||||
let alle = { knoten: new Map(), kanten: [] }; // vollständiger Datensatz
|
||||
const kinder = new Map(); // Knoten-ID → [direkte Kinder-IDs]
|
||||
const positionen = new Map(); // Knoten-ID → {x, y}
|
||||
const zugeklappt = new Set(JSON.parse(localStorage.getItem(SPEICHER_ZUGEKLAPPT) || "[]"));
|
||||
let allePorts = false;
|
||||
let griff = null; // Startlage beim Ziehen
|
||||
|
||||
// --- Darstellung ------------------------------------------------------------
|
||||
|
||||
const STIL = [
|
||||
{ selector: "node", style: {
|
||||
"shape": "round-rectangle", "background-color": "#ffffff",
|
||||
"border-width": 1.5, "border-color": "#6c757d",
|
||||
"label": "data(label)", "text-wrap": "wrap", "font-size": 11,
|
||||
"text-valign": "center", "text-halign": "center",
|
||||
"width": "data(breite)", "height": "data(hoehe)", "padding": 8,
|
||||
} },
|
||||
{ selector: ":parent", style: {
|
||||
"background-color": "#f8f9fa", "border-color": "#adb5bd",
|
||||
"text-valign": "top", "text-halign": "center", "text-margin-y": -4,
|
||||
"font-weight": "bold", "padding": 16,
|
||||
} },
|
||||
{ selector: "node.hypervisor", style: { "background-color": "#eef4ff", "border-color": "#0d6efd", "border-width": 2 } },
|
||||
{ selector: "node.gast", style: { "border-color": "#198754" } },
|
||||
{ selector: "node.bridge", style: { "shape": "ellipse", "background-color": "#fff3cd", "border-color": "#fd7e14", "padding": 10 } },
|
||||
{ selector: "node.port", style: { "shape": "rectangle", "font-size": 9, "padding": 4, "background-color": "#e9ecef" } },
|
||||
{ selector: "node.art-dsl", style: { "background-color": "#f8d7da", "border-color": "#dc3545" } },
|
||||
{ selector: "node.unbenutzt", style: { "border-style": "dashed", "color": "#adb5bd", "border-color": "#ced4da" } },
|
||||
{ selector: "node.status-geplant", style: { "border-style": "dashed" } },
|
||||
{ selector: "node.status-auslaufend", style: { "opacity": 0.45 } },
|
||||
{ selector: "node.zugeklappt", style: { "background-color": "#eef4ff", "border-color": "#0d6efd", "border-width": 3, "font-weight": "bold" } },
|
||||
{ selector: "node:selected", style: { "border-color": "#0d6efd", "border-width": 3 } },
|
||||
|
||||
{ selector: "edge", style: {
|
||||
"curve-style": "bezier", "width": 2, "line-color": "#adb5bd",
|
||||
"label": "data(label)", "font-size": 9, "color": "#495057",
|
||||
"text-background-color": "#ffffff", "text-background-opacity": 0.9, "text-background-padding": 2,
|
||||
} },
|
||||
{ selector: "edge.kabel", style: { "line-color": "#6c757d", "width": 3 } },
|
||||
{ selector: "edge.passthrough", style: { "line-color": "#fd7e14", "line-style": "dashed", "width": 3 } },
|
||||
{ selector: "edge.wlan", style: { "line-style": "dashed", "line-dash-pattern": [4, 4] } },
|
||||
{ selector: "edge.vpn", style: { "line-color": "#6f42c1", "line-style": "dashed", "width": 3 } },
|
||||
{ selector: "edge.verwaltet", style: {
|
||||
"line-style": "dotted", "line-color": "#6c757d",
|
||||
"target-arrow-shape": "triangle", "target-arrow-color": "#6c757d",
|
||||
} },
|
||||
{ selector: "edge.meta", style: { "width": 4 } },
|
||||
{ selector: "edge:selected", style: { "line-color": "#0d6efd" } },
|
||||
|
||||
{ selector: ".gedimmt", style: { "opacity": 0.12 } },
|
||||
{ selector: ".ausgeblendet", style: { "display": "none" } },
|
||||
{ selector: "edge.ohne-label", style: { "label": "" } },
|
||||
];
|
||||
|
||||
// --- Hilfen -----------------------------------------------------------------
|
||||
|
||||
// Knotengröße aus dem Text (Ersatz für das veraltete width/height: label)
|
||||
const messen = document.createElement("canvas").getContext("2d");
|
||||
function textGroesse(label, schrift) {
|
||||
messen.font = `${schrift}px sans-serif`;
|
||||
const zeilen = String(label || "").split("\n");
|
||||
const breite = Math.max(...zeilen.map((z) => messen.measureText(z).width), 10);
|
||||
return { breite: Math.ceil(breite), hoehe: Math.ceil(zeilen.length * schrift * 1.25) };
|
||||
}
|
||||
|
||||
function csrf() {
|
||||
const m = document.cookie.match(/(?:^|;\s*)csrftoken=([^;]+)/);
|
||||
return m ? decodeURIComponent(m[1]) : "";
|
||||
}
|
||||
|
||||
function senden(url, daten) {
|
||||
return fetch(url, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", "X-CSRFToken": csrf() },
|
||||
body: JSON.stringify(daten || {}),
|
||||
}).then((r) => {
|
||||
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
||||
return r.json();
|
||||
});
|
||||
}
|
||||
|
||||
function meldung(text, art) {
|
||||
const el = document.getElementById("meldung");
|
||||
el.innerHTML = "";
|
||||
const div = document.createElement("div");
|
||||
div.className = `alert alert-${art || "secondary"} py-2 px-3 small shadow-sm mb-0`;
|
||||
div.textContent = text;
|
||||
el.appendChild(div);
|
||||
setTimeout(() => div.remove(), 2500);
|
||||
}
|
||||
|
||||
function nachkommen(id) {
|
||||
const ergebnis = [];
|
||||
(kinder.get(id) || []).forEach((k) => ergebnis.push(k, ...nachkommen(k)));
|
||||
return ergebnis;
|
||||
}
|
||||
|
||||
function istRahmen(id) {
|
||||
return (kinder.get(id) || []).length > 0;
|
||||
}
|
||||
|
||||
function mittelpunkt(ids) {
|
||||
const punkte = ids.map((i) => positionen.get(i)).filter(Boolean);
|
||||
if (!punkte.length) return null;
|
||||
return {
|
||||
x: punkte.reduce((s, p) => s + p.x, 0) / punkte.length,
|
||||
y: punkte.reduce((s, p) => s + p.y, 0) / punkte.length,
|
||||
};
|
||||
}
|
||||
|
||||
// --- Sichtbare Elemente berechnen ------------------------------------------
|
||||
|
||||
function istSichtbar(id) {
|
||||
const k = alle.knoten.get(id);
|
||||
if (!allePorts && k.classes.includes("unbenutzt")) return false;
|
||||
let p = k.data.parent;
|
||||
while (p) {
|
||||
if (zugeklappt.has(p)) return false;
|
||||
p = alle.knoten.get(p).data.parent;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sichtbarer Vertreter eines Knotens: er selbst oder sein zugeklappter Host
|
||||
function vertreter(id) {
|
||||
let ergebnis = id;
|
||||
let p = alle.knoten.get(id).data.parent;
|
||||
while (p) {
|
||||
if (zugeklappt.has(p)) ergebnis = p;
|
||||
p = alle.knoten.get(p).data.parent;
|
||||
}
|
||||
return ergebnis;
|
||||
}
|
||||
|
||||
function sichtbareElemente() {
|
||||
const sichtbar = [...alle.knoten.keys()].filter(istSichtbar);
|
||||
const hatSichtbareKinder = new Set(
|
||||
sichtbar.map((id) => alle.knoten.get(id).data.parent).filter(Boolean)
|
||||
);
|
||||
|
||||
const knoten = sichtbar.map((id) => {
|
||||
const k = alle.knoten.get(id);
|
||||
const el = { group: "nodes", data: { ...k.data }, classes: k.classes };
|
||||
if (zugeklappt.has(id)) {
|
||||
el.classes += " zugeklappt";
|
||||
el.data.label = `${k.data.titel} · ${k.data.gaeste} Gäste`;
|
||||
}
|
||||
Object.assign(el.data, textGroesse(el.data.label, k.classes.includes("port") ? 9 : 11));
|
||||
if (!hatSichtbareKinder.has(id)) {
|
||||
// Blatt: eigene Position, ein leerer Rahmen liegt in der Mitte seines Inhalts
|
||||
el.position = istRahmen(id) ? mittelpunkt(nachkommen(id)) : positionen.get(id);
|
||||
if (!el.position) delete el.position;
|
||||
}
|
||||
return el;
|
||||
});
|
||||
|
||||
const kanten = [];
|
||||
const meta = new Map();
|
||||
alle.kanten.forEach((e) => {
|
||||
const q = vertreter(e.data.source);
|
||||
const z = vertreter(e.data.target);
|
||||
if (q === e.data.source && z === e.data.target) {
|
||||
kanten.push({ group: "edges", data: { ...e.data }, classes: e.classes });
|
||||
return;
|
||||
}
|
||||
if (q === z) return; // Linie liegt komplett im zugeklappten Host
|
||||
const schluessel = `meta:${q}|${z}|${e.classes}`;
|
||||
if (!meta.has(schluessel)) {
|
||||
meta.set(schluessel, { group: "edges", classes: `${e.classes} meta`,
|
||||
data: { id: schluessel, source: q, target: z, labels: [], info: [["Art", "zusammengefasst"]], url: "" } });
|
||||
}
|
||||
const m = meta.get(schluessel);
|
||||
if (!m.data.labels.includes(e.data.label)) m.data.labels.push(e.data.label);
|
||||
m.data.info.push(["Linie", `${e.data.source} → ${e.data.target}`]);
|
||||
});
|
||||
meta.forEach((m) => { m.data.label = m.data.labels.join("\n"); kanten.push(m); });
|
||||
|
||||
return knoten.concat(kanten);
|
||||
}
|
||||
|
||||
// --- Platzierung ohne gespeicherte Position ---------------------------------
|
||||
|
||||
// Neue Blatt-Knoten neben ihre Geschwister bzw. rechts neben das Bild legen
|
||||
function fehlendePlatzieren() {
|
||||
const fehlend = cy.nodes().filter((n) => n.isChildless() && !istRahmen(n.id()) && !positionen.has(n.id()));
|
||||
if (!fehlend.length) return [];
|
||||
const bb = cy.nodes().filter((n) => positionen.has(n.id())).boundingBox();
|
||||
let rechts = Number.isFinite(bb.x2) ? bb.x2 + 120 : 0;
|
||||
const versatz = new Map();
|
||||
const basis = new Map(); // je Rahmen: Mitte der bereits platzierten Geschwister, einmal ermittelt
|
||||
fehlend.forEach((n) => {
|
||||
const parent = n.data("parent");
|
||||
if (parent && !basis.has(parent)) {
|
||||
basis.set(parent, mittelpunkt((kinder.get(parent) || []).filter((k) => positionen.has(k))));
|
||||
}
|
||||
});
|
||||
fehlend.forEach((n) => {
|
||||
const parent = n.data("parent");
|
||||
let pos;
|
||||
if (parent && basis.get(parent)) {
|
||||
const b = basis.get(parent);
|
||||
const i = (versatz.get(parent) || 0) + 1;
|
||||
versatz.set(parent, i);
|
||||
pos = { x: b.x + 70 * (i - 1), y: b.y + 50 };
|
||||
} else {
|
||||
pos = { x: rechts, y: Number.isFinite(bb.y1) ? bb.y1 : 0 };
|
||||
rechts += 160;
|
||||
}
|
||||
n.position(pos);
|
||||
positionen.set(n.id(), pos);
|
||||
});
|
||||
return fehlend.map((n) => n.id());
|
||||
}
|
||||
|
||||
// --- Aufbau -----------------------------------------------------------------
|
||||
|
||||
function aufbauen() {
|
||||
// aktuelle Lage der Blätter übernehmen, bevor neu aufgebaut wird
|
||||
if (cy) {
|
||||
cy.nodes().forEach((n) => {
|
||||
if (n.isChildless() && !istRahmen(n.id())) positionen.set(n.id(), { ...n.position() });
|
||||
});
|
||||
}
|
||||
cy.elements().remove();
|
||||
cy.add(sichtbareElemente());
|
||||
const neu = fehlendePlatzieren();
|
||||
if (neu.length) speichern(neu);
|
||||
filterAnwenden();
|
||||
}
|
||||
|
||||
function speichern(ids) {
|
||||
const liste = ids.filter((id) => positionen.has(id)).map((id) => ({ id, ...positionen.get(id) }));
|
||||
if (!liste.length) return;
|
||||
senden(URLS.speichern, { positionen: liste }).catch(() => meldung("Position konnte nicht gespeichert werden.", "danger"));
|
||||
}
|
||||
|
||||
function anordnen() {
|
||||
const layout = cy.layout({ name: "cose", animate: false, randomize: true, nodeDimensionsIncludeLabels: true,
|
||||
idealEdgeLength: 90, nodeRepulsion: 12000, nodeOverlap: 40, componentSpacing: 120, padding: 30 });
|
||||
layout.on("layoutstop", () => {
|
||||
cy.nodes().forEach((n) => {
|
||||
if (n.isChildless() && !istRahmen(n.id())) positionen.set(n.id(), { ...n.position() });
|
||||
});
|
||||
speichern([...positionen.keys()]);
|
||||
cy.fit(undefined, 30);
|
||||
});
|
||||
layout.run();
|
||||
}
|
||||
|
||||
// --- Filter -----------------------------------------------------------------
|
||||
|
||||
function filterAnwenden() {
|
||||
cy.elements().removeClass("gedimmt ausgeblendet");
|
||||
|
||||
const erlaubt = new Set([...document.querySelectorAll(".filter-status:checked")].map((c) => c.value));
|
||||
cy.nodes().forEach((n) => {
|
||||
const status = n.data("status");
|
||||
if (status && !erlaubt.has(status)) n.union(n.descendants()).addClass("ausgeblendet");
|
||||
});
|
||||
|
||||
const netz = document.getElementById("filter-netz").value;
|
||||
if (netz) {
|
||||
const passend = cy.edges().filter((e) => (e.data("label") || "").includes(netz));
|
||||
const behalten = passend.union(passend.connectedNodes()).union(passend.connectedNodes().ancestors());
|
||||
cy.elements().not(behalten).addClass("gedimmt");
|
||||
}
|
||||
|
||||
const ohneLabel = !document.getElementById("beschriftung").checked;
|
||||
cy.edges().toggleClass("ohne-label", ohneLabel);
|
||||
}
|
||||
|
||||
// --- Details ----------------------------------------------------------------
|
||||
|
||||
function details(el) {
|
||||
const box = document.getElementById("details");
|
||||
box.innerHTML = "";
|
||||
const h = document.createElement("h2");
|
||||
h.className = "h6";
|
||||
h.textContent = el.data("titel") || el.data("label") || el.id();
|
||||
box.appendChild(h);
|
||||
|
||||
const tabelle = document.createElement("table");
|
||||
tabelle.className = "table table-sm small mb-2";
|
||||
(el.data("info") || []).forEach(([k, v]) => {
|
||||
const tr = tabelle.insertRow();
|
||||
const th = document.createElement("th");
|
||||
th.className = "fw-normal text-secondary";
|
||||
th.textContent = k;
|
||||
tr.appendChild(th);
|
||||
tr.insertCell().textContent = v;
|
||||
});
|
||||
box.appendChild(tabelle);
|
||||
|
||||
const id = el.isNode() ? el.id() : null;
|
||||
if (id && alle.knoten.get(id).classes.includes("hypervisor")) {
|
||||
const knopf = document.createElement("button");
|
||||
knopf.className = "btn btn-sm btn-outline-primary me-2";
|
||||
knopf.textContent = zugeklappt.has(id) ? "Aufklappen" : "Zuklappen";
|
||||
knopf.onclick = () => umschalten(id);
|
||||
box.appendChild(knopf);
|
||||
}
|
||||
if (el.data("url")) {
|
||||
const a = document.createElement("a");
|
||||
a.className = "btn btn-sm btn-outline-secondary";
|
||||
a.href = el.data("url");
|
||||
a.target = "_blank";
|
||||
a.rel = "noopener";
|
||||
a.textContent = "Bearbeiten (Admin)";
|
||||
box.appendChild(a);
|
||||
}
|
||||
}
|
||||
|
||||
function umschalten(id) {
|
||||
if (zugeklappt.has(id)) zugeklappt.delete(id); else zugeklappt.add(id);
|
||||
localStorage.setItem(SPEICHER_ZUGEKLAPPT, JSON.stringify([...zugeklappt]));
|
||||
aufbauen();
|
||||
const el = cy.getElementById(id);
|
||||
el.select();
|
||||
details(el);
|
||||
}
|
||||
|
||||
// --- Ereignisse -------------------------------------------------------------
|
||||
|
||||
function ereignisse() {
|
||||
cy.on("tap", "node, edge", (e) => details(e.target));
|
||||
cy.on("dbltap", "node.hypervisor", (e) => umschalten(e.target.id()));
|
||||
|
||||
cy.on("grab", "node", (e) => { griff = { ...e.target.position() }; });
|
||||
|
||||
cy.on("dragfree", "node", (e) => {
|
||||
const n = e.target;
|
||||
const id = n.id();
|
||||
let geaendert;
|
||||
if (n.isParent()) {
|
||||
// Rahmen gezogen: alle sichtbaren Blätter darin haben sich mitbewegt
|
||||
geaendert = n.descendants().filter((d) => d.isChildless()).map((d) => d.id());
|
||||
geaendert.forEach((d) => positionen.set(d, { ...cy.getElementById(d).position() }));
|
||||
} else if (istRahmen(id)) {
|
||||
// zugeklappter Host bzw. Gerät mit ausgeblendeten Ports: Inhalt mitverschieben
|
||||
const dx = n.position("x") - griff.x;
|
||||
const dy = n.position("y") - griff.y;
|
||||
geaendert = nachkommen(id).filter((d) => positionen.has(d));
|
||||
geaendert.forEach((d) => {
|
||||
const p = positionen.get(d);
|
||||
positionen.set(d, { x: p.x + dx, y: p.y + dy });
|
||||
});
|
||||
} else {
|
||||
positionen.set(id, { ...n.position() });
|
||||
geaendert = [id];
|
||||
}
|
||||
speichern(geaendert);
|
||||
});
|
||||
|
||||
document.getElementById("filter-netz").addEventListener("change", filterAnwenden);
|
||||
document.getElementById("beschriftung").addEventListener("change", filterAnwenden);
|
||||
document.querySelectorAll(".filter-status").forEach((c) => c.addEventListener("change", filterAnwenden));
|
||||
document.getElementById("alle-ports").addEventListener("change", (e) => { allePorts = e.target.checked; aufbauen(); });
|
||||
document.getElementById("einpassen").addEventListener("click", () => cy.fit(undefined, 30));
|
||||
document.getElementById("zuruecksetzen").addEventListener("click", () => {
|
||||
if (!confirm("Alle gespeicherten Positionen löschen und neu anordnen?")) return;
|
||||
senden(URLS.zuruecksetzen).then(() => {
|
||||
positionen.clear();
|
||||
zugeklappt.clear();
|
||||
localStorage.removeItem(SPEICHER_ZUGEKLAPPT);
|
||||
cy.elements().remove();
|
||||
cy.add(sichtbareElemente());
|
||||
filterAnwenden();
|
||||
anordnen();
|
||||
meldung("Anordnung zurückgesetzt.", "success");
|
||||
}).catch(() => meldung("Zurücksetzen fehlgeschlagen.", "danger"));
|
||||
});
|
||||
}
|
||||
|
||||
// --- Start ------------------------------------------------------------------
|
||||
|
||||
fetch(URLS.daten, { headers: { Accept: "application/json" } })
|
||||
.then((r) => {
|
||||
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
||||
return r.json();
|
||||
})
|
||||
.then((daten) => {
|
||||
daten.elemente.forEach((e) => {
|
||||
if (e.group === "nodes") {
|
||||
alle.knoten.set(e.data.id, e);
|
||||
if (e.position) positionen.set(e.data.id, e.position);
|
||||
if (e.data.parent) {
|
||||
if (!kinder.has(e.data.parent)) kinder.set(e.data.parent, []);
|
||||
kinder.get(e.data.parent).push(e.data.id);
|
||||
}
|
||||
} else {
|
||||
alle.kanten.push(e);
|
||||
}
|
||||
});
|
||||
// Zugeklappte Hosts, die es nicht mehr gibt, vergessen
|
||||
[...zugeklappt].forEach((id) => { if (!alle.knoten.has(id)) zugeklappt.delete(id); });
|
||||
|
||||
const auswahl = document.getElementById("filter-netz");
|
||||
daten.netze.forEach((cidr) => auswahl.add(new Option(cidr, cidr)));
|
||||
|
||||
const ersterAufruf = positionen.size === 0;
|
||||
cy = cytoscape({ container: document.getElementById("schaubild"), style: STIL });
|
||||
cy.add(sichtbareElemente());
|
||||
ereignisse();
|
||||
if (ersterAufruf) {
|
||||
anordnen();
|
||||
} else {
|
||||
const neu = fehlendePlatzieren();
|
||||
if (neu.length) speichern(neu);
|
||||
cy.fit(undefined, 30);
|
||||
}
|
||||
filterAnwenden();
|
||||
})
|
||||
.catch((fehler) => {
|
||||
document.getElementById("schaubild").innerHTML =
|
||||
`<div class="p-3 text-danger">Schaubild konnte nicht geladen werden (${fehler.message}).</div>`;
|
||||
});
|
||||
})();
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2026, The Cytoscape Consortium.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the “Software”), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).cytoscape=t()}(this,(function(){"use strict";function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t,n){return t&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,s(r.key),r)}}(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=u(e))||t){n&&(e=n);var r=0,a=function(){};return{s:a,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,i=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw i}}}}function a(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,a,i,o,s=[],l=!0,u=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=i.call(n)).done)&&(s.push(r.value),s.length!==t);l=!0);}catch(e){u=!0,a=e}finally{try{if(!l&&null!=n.return&&(o=n.return(),Object(o)!==o))return}finally{if(u)throw a}}return s}}(e,t)||u(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t){return function(t){if(Array.isArray(t))return e(t)}(t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||u(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof t?t:t+""}function l(e){return l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},l(e)}function u(t,n){if(t){if("string"==typeof t)return e(t,n);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(t,n):void 0}}var c="undefined"==typeof window?null:window,d=c?c.navigator:null;c&&c.document;var h,f,p,g,v,y,m,b,x,w,E,k,T,C,P,S,B,D,_,A,M,R,I,N,L,z,O,V,F=l(""),X=l({}),Y=l((function(){})),j="undefined"==typeof HTMLElement?"undefined":l(HTMLElement),q=function(e){return e&&e.instanceString&&H(e.instanceString)?e.instanceString():null},W=function(e){return null!=e&&l(e)==F},H=function(e){return null!=e&&l(e)===Y},U=function(e){return!Q(e)&&(Array.isArray?Array.isArray(e):null!=e&&e instanceof Array)},K=function(e){return null!=e&&l(e)===X&&!U(e)&&e.constructor===Object},G=function(e){return null!=e&&l(e)===l(1)&&!isNaN(e)},Z=function(e){return G(e)&&Math.floor(e)===e},$=function(e){return"undefined"===j?void 0:null!=e&&e instanceof HTMLElement},Q=function(e){return J(e)||ee(e)},J=function(e){return"collection"===q(e)&&e._private.single},ee=function(e){return"collection"===q(e)&&!e._private.single},te=function(e){return"core"===q(e)},ne=function(e){return"stylesheet"===q(e)},re=function(e){return null==e||!(""!==e&&!e.match(/^\s+$/))},ae=function(e){return function(e){return null!=e&&l(e)===X}(e)&&H(e.then)},ie=function(e,t){t||(t=function(){if(1===arguments.length)return arguments[0];if(0===arguments.length)return"undefined";for(var e=[],t=0;t<arguments.length;t++)e.push(arguments[t]);return e.join("$")});var n=function(){var r,a=arguments,i=t.apply(this,a),o=n.cache;return(r=o[i])||(r=o[i]=e.apply(this,a)),r};return n.cache={},n},oe=ie((function(e){return e.replace(/([A-Z])/g,(function(e){return"-"+e.toLowerCase()}))})),se=ie((function(e){return e.replace(/(-\w)/g,(function(e){return e[1].toUpperCase()}))})),le=ie((function(e,t){return e+t[0].toUpperCase()+t.substring(1)}),(function(e,t){return e+"$"+t})),ue=function(e){return re(e)?e:e.charALine truncated
|
||||
/*!
|
||||
Embeddable Minimum Strictly-Compliant Promises/A+ 1.1.1 Thenable
|
||||
Copyright (c) 2013-2014 Ralf S. Engelschall (http://engelschall.com)
|
||||
Licensed under The MIT License (http://opensource.org/licenses/MIT)
|
||||
*/
|
||||
var Kr=function(e){if(!(this instanceof Kr))return new Kr(e);this.id="Thenable/1.0.7",this.state=0,this.fulfillValue=void 0,this.rejectReason=void 0,this.onFulfilled=[],this.onRejected=[],this.proxy={then:this.then.bind(this)},"function"==typeof e&&e.call(this,this.fulfill.bind(this),this.reject.bind(this))};Kr.prototype={fulfill:function(e){return Gr(this,1,"fulfillValue",e)},reject:function(e){return Gr(this,2,"rejectReason",e)},then:function(e,t){var n=this,r=new Kr;return n.onFulfilled.push(Qr(e,r,"fulfill")),n.onRejected.push(Qr(t,r,"reject")),Zr(n),r.proxy}};var Gr=function(e,t,n,r){return 0===e.state&&(e.state=t,e[n]=r,Zr(e)),e},Zr=function(e){1===e.state?$r(e,"onFulfilled",e.fulfillValue):2===e.state&&$r(e,"onRejected",e.rejectReason)},$r=function(e,t,n){if(0!==e[t].length){var r=e[t];e[t]=[];var a=function(){for(var e=0;e<r.length;e++)r[e](n)};"function"==typeof setImmediate?setImmediate(a):setTimeout(a,0)}},Qr=function(e,t,n){return function(r){if("function"!=typeof e)t[n].call(t,r);else{var a;try{a=e(r)}catch(e){return void t.reject(e)}Jr(t,a)}}},Jr=function(e,t){if(e!==t&&e.proxy!==t){var n;if("object"===l(t)&&null!==t||"function"==typeof t)try{n=t.then}catch(t){return void e.reject(t)}if("function"!=typeof n)e.fulfill(t);else{var r=!1;try{n.call(t,(function(n){r||(r=!0,n===t?e.reject(new TypeError("circular thenable chain")):Jr(e,n))}),(function(t){r||(r=!0,e.reject(t))}))}catch(t){r||e.reject(t)}}}else e.reject(new TypeError("cannot resolve promise with itself"))};Kr.all=function(e){return new Kr((function(t,n){for(var r=new Array(e.length),a=0,i=function(n,i){r[n]=i,++a===e.length&&t(r)},o=0;o<e.length;o++)!function(t){var r=e[t];null!=r&&null!=r.then?r.then((function(e){i(t,e)}),(function(e){n(e)})):i(t,r)}(o)}))},Kr.resolve=function(e){return new Kr((function(t,n){t(e)}))},Kr.reject=function(e){return new Kr((function(t,n){n(e)}))};var ea="undefined"!=typeof Promise?Promise:Kr,ta=function(e,t,n){var r=te(e),a=!r,i=this._private=ye({duration:1e3},t,n);if(i.target=e,i.style=i.style||i.css,i.started=!1,i.playing=!1,i.hooked=!1,i.applying=!1,i.progress=0,i.completes=[],i.frames=[],i.complete&&H(i.complete)&&i.completes.push(i.complete),a){var o=e.position();i.startPosition=i.startPosition||{x:o.x,y:o.y},i.startStyle=i.startStyle||e.cy().style().getAnimationStartStyle(e,i.style)}if(r){var s=e.pan();i.startPan={x:s.x,y:s.y},i.startZoom=e.zoom()}this.length=1,this[0]=this},na=ta.prototype;ye(na,{instanceString:function(){return"animation"},hook:function(){var e=this._private;if(!e.hooked){var t=e.target._private.animation;(e.queue?t.queue:t.current).push(this),Q(e.target)&&e.target.cy().addToAnimationPool(e.target),e.hooked=!0}return this},play:function(){var e=this._private;return 1===e.progress&&(e.progress=0),e.playing=!0,e.started=!1,e.stopped=!1,this.hook(),this},playing:function(){return this._private.playing},apply:function(){var e=this._private;return e.applying=!0,e.started=!1,e.stopped=!1,this.hook(),this},applying:function(){return this._private.applying},pause:function(){var e=this._private;return e.playing=!1,e.started=!1,this},stop:function(){var e=this._private;return e.playing=!1,e.started=!1,e.stopped=!0,this},rewind:function(){return this.progress(0)},fastforward:function(){return this.progress(1)},time:function(e){var t=this._private;return void 0===e?t.progress*t.duration:this.progress(e/t.duration)},progress:function(e){var t=this._private,n=t.playing;return void 0===e?t.progress:(n&&this.pause(),t.progress=e,t.started=!1,n&&this.play(),this)},completed:function(){return 1===this._private.progress},reverse:function(){var e=this._private,t=e.playing;t&&this.pause(),e.progress=1-e.progress,e.started=!1;var n=function(t,n){var r=e[t];null!=r&&(e[t]=e[n],e[n]=r)};if(n("zoom","startZoom"),n("pan","startPan"),n("position","startPosition"),e.style)for(var r=0;r<e.style.length;r++){var a=e.style[r],i=a.name,o=e.startStyle[i];e.startStyle[i]=a,e.style[r]=o}return t&&this.play(),this},promise:function(e){var t,n=this._private;if("frame"===e)t=n.frames;else t=n.completes;return new ea((function(e,n){t.push((function(){e()}))}))}}),na.complete=na.completed,na.run=na.play,na.running=na.playing;var ra,aa,ia,oa,sa,la,ua,ca,da,ha,fa,pa,ga,va,ya,ma,ba,xa,wa,Ea,ka,Ta,Ca,Pa,Sa,Ba,Da,_a,Aa,Ma,Ra,Ia,Na,La,za,Oa,Va,Fa,Xa,Ya,ja,qa,Wa,Ha,Ua,Ka,Ga,Za,$a,Qa,Ja,ei,ti,ni,ri,ai,ii,oi,si,li,ui,ci,di,hi,fi,pi,gi,vi,yi,mi,bi,xi,wi,Ei,ki,Ti,Ci,Pi,Si,Bi,Di,_i,Ai,Mi,Ri,Ii,Ni={animated:function(){return function(){var e=this,t=void 0!==e.length?e:[e];if(!(this._private.cy||this).styleEnabled())return!1;var n=t[0];return n?n._private.animation.current.length>0:void 0}},clearQueue:function(){return function(){var e=this,t=void 0!==e.length?e:[e];if(!(this._private.cy||this).styleEnabled())return this;for(var n=0;n<t.length;n++){t[n]._private.animation.queue=[]}return this}},delay:function(){return function(e,t){return(this._private.cy||this).styleEnabled()?this.animate({delay:e,duration:e,complete:t}):this}},delaLine truncated
|
||||
/*! Bezier curve function generator. Copyright 2014-2026 Gaetan Renaudeau. MIT License: http://en.wikipedia.org/wiki/MIT_License
|
||||
* https://github.com/gre/bezier-easing */function eu(e,t,n,r){if(4!==arguments.length)return!1;for(var a=0;a<4;++a)if("number"!=typeof arguments[a]||isNaN(arguments[a])||!isFinite(arguments[a]))return!1;e=Math.min(e,1),n=Math.min(n,1),e=Math.max(e,0),n=Math.max(n,0);var i=e===t&&n===r,o=(3*e-3*n+1)/2,s=n-2*e,l=e,u=3*t-3*r+1,c=3*(r-2*t),d=3*t,h=function(e){if(i)return e;if(e<=0)return 0;if(e>=1)return 1;var t=function(e,t,n,r){var a,i=1/Math.max(r,Math.sqrt(e)),o=e*i,s=o*i,l=r*i,u=n*s,c=l*l+u,d=-l*(l*l+1.5*u)-t*o*s,h=d*d-c*c*c;if(0===c||h>1e-12*d*d){var f=-Jl(d<0?d-Math.sqrt(h):d+Math.sqrt(h));a=f+c/f||0}else{var p=Math.sqrt(c);a=2*p*Math.cos(Math.acos(Math.max(-1,Math.min(1,-d/(c*p))))/3)}return Math.min(1,o/(a+l))}(e,o,s,l);return((u*t+c)*t+d)*t};h.getControlPoints=function(){return[{x:e,y:t},{x:n,y:r}]};var f="generateBezier("+[e,t,n,r]+")";return h.toString=function(){return f},h}
|
||||
/*! Runge-Kutta spring physics function generator. Adapted from Framer.js, copyright Koen Bok. MIT License: http://en.wikipedia.org/wiki/MIT_License */var tu=function(){function e(e){return-e.tension*e.x-e.friction*e.v}function t(t,n,r){var a={x:t.x+r.dx*n,v:t.v+r.dv*n,tension:t.tension,friction:t.friction};return{dx:a.v,dv:e(a)}}function n(n,r){var a={dx:n.v,dv:e(n)},i=t(n,.5*r,a),o=t(n,.5*r,i),s=t(n,r,o),l=1/6*(a.dx+2*(i.dx+o.dx)+s.dx),u=1/6*(a.dv+2*(i.dv+o.dv)+s.dv);return n.x=n.x+l*r,n.v=n.v+u*r,n}return function e(t,r,a){var i,o,s,l={x:-1,v:0,tension:null,friction:null},u=[0],c=0,d=1e-4;for(t=parseFloat(t)||500,r=parseFloat(r)||20,a=a||null,l.tension=t,l.friction=r,o=(i=null!==a)?(c=e(t,r))/a*.016:.016;s=n(s||l,o),u.push(1+s.x),c+=16,Math.abs(s.x)>d&&Math.abs(s.v)>d;);return i?function(e){return u[e*(u.length-1)|0]}:c}}(),nu=function(e,t,n,r){var a=eu(e,t,n,r);return function(e,t,n){return e+(t-e)*a(n)}},ru={linear:function(e,t,n){return e+(t-e)*n},ease:nu(.25,.1,.25,1),"ease-in":nu(.42,0,1,1),"ease-out":nu(0,0,.58,1),"ease-in-out":nu(.42,0,.58,1),"ease-in-sine":nu(.47,0,.745,.715),"ease-out-sine":nu(.39,.575,.565,1),"ease-in-out-sine":nu(.445,.05,.55,.95),"ease-in-quad":nu(.55,.085,.68,.53),"ease-out-quad":nu(.25,.46,.45,.94),"ease-in-out-quad":nu(.455,.03,.515,.955),"ease-in-cubic":nu(.55,.055,.675,.19),"ease-out-cubic":nu(.215,.61,.355,1),"ease-in-out-cubic":nu(.645,.045,.355,1),"ease-in-quart":nu(.895,.03,.685,.22),"ease-out-quart":nu(.165,.84,.44,1),"ease-in-out-quart":nu(.77,0,.175,1),"ease-in-quint":nu(.755,.05,.855,.06),"ease-out-quint":nu(.23,1,.32,1),"ease-in-out-quint":nu(.86,0,.07,1),"ease-in-expo":nu(.95,.05,.795,.035),"ease-out-expo":nu(.19,1,.22,1),"ease-in-out-expo":nu(1,0,0,1),"ease-in-circ":nu(.6,.04,.98,.335),"ease-out-circ":nu(.075,.82,.165,1),"ease-in-out-circ":nu(.785,.135,.15,.86),spring:function(e,t,n){if(0===n)return ru.linear;var r=tu(e,t,n);return function(e,t,n){return e+(t-e)*r(n)}},"cubic-bezier":nu};function au(e,t,n,r,a){if(1===r)return n;if(t===n)return n;var i=a(t,n,r);return null==e||((e.roundValue||e.color)&&(i=Math.round(i)),void 0!==e.min&&(i=Math.max(i,e.min)),void 0!==e.max&&(i=Math.min(i,e.max))),i}function iu(e,t){return null!=e.pfValue||null!=e.value?null==e.pfValue||null!=t&&"%"===t.type.units?e.value:e.pfValue:e}function ou(e,t,n,r,a){var i=null!=a?a.type:null;n<0?n=0:n>1&&(n=1);var o=iu(e,a),s=iu(t,a);if(G(o)&&G(s))return au(i,o,s,n,r);if(U(o)&&U(s)){for(var l=[],u=0;u<s.length;u++){var c=o[u],d=s[u];if(null!=c&&null!=d){var h=au(i,c,d,n,r);l.push(h)}else l.push(d)}return l}}function su(e,t,n,r){var a=!r,i=e._private,o=t._private,s=o.easing,l=o.startTime,u=(r?e:e.cy()).style();if(!o.easingImpl)if(null==s)o.easingImpl=ru.linear;else{var c,d,h;if(W(s))c=u.parse("transition-timing-function",s).value;else c=s;W(c)?(d=c,h=[]):(d=c[1],h=c.slice(2).map((function(e){return+e}))),h.length>0?("spring"===d&&h.push(o.duration),o.easingImpl=ru[d].apply(null,h)):o.easingImpl=ru[d]}var f,p=o.easingImpl;if(f=0===o.duration?1:(n-l)/o.duration,o.applying&&(f=o.progress),f<0?f=0:f>1&&(f=1),null==o.delay){var g=o.startPosition,v=o.position;if(v&&a&&!e.locked()){var y={};lu(g.x,v.x)&&(y.x=ou(g.x,v.x,f,p)),lu(g.y,v.y)&&(y.y=ou(g.y,v.y,f,p)),e.position(y)}var m=o.startPan,b=o.pan,x=i.pan,w=null!=b&&r;w&&(lu(m.x,b.x)&&(x.x=ou(m.x,b.x,f,p)),lu(m.y,b.y)&&(x.y=ou(m.y,b.y,f,p)),e.emit("pan"));var E=o.startZoom,k=o.zoom,T=null!=k&&r;T&&(lu(E,k)&&(i.zoom=nn(i.minZoom,ou(E,k,f,p),i.maxZoom)),e.emit("zoom")),(w||T)&&e.emit("viewport");var C=o.style;if(C&&C.length>0&&a){for(var P=0;P<C.length;P++){var S=C[P],B=S.name,D=S,_=o.startStyle[B],A=ou(_,D,f,p,u.properties[_.name]);u.overrideBypass(e,B,A)}e.emit("style")}}return o.progress=f,f}function lu(e,t){return null!=e&&null!=t&&(!(!G(e)||!G(t))||!(!e||!t))}function uu(e,t,n,r){var a=t._private;a.started=!0,a.startTime=n-a.progress*a.duration}function cu(e,t){var n=t._private.aniEles,r=[];function a(t,n){var a=t._private,i=a.animation.current,o=a.animation.queue,s=!1;if(0===i.length){var l=o.shift();l&&i.push(l)}for(var u=function(e){for(var t=e.length-1;t>=0;t--){(0,e[t])()}e.splice(0,e.length)},c=i.length-1;c>=0;c--){var d=i[c],h=d._private;h.stopped?(i.splice(c,1),h.hooked=!1,h.playing=!1,h.started=!1,u(h.frames)):(h.playing||h.applying)&&(h.playing&&h.applying&&(h.applying=!1),h.started||uu(0,d,e),su(t,d,e,n),h.applying&&(h.applying=!1),u(h.frames),null!=h.step&&h.step(e),d.completed()&&(i.splice(c,1),h.hooked=!1,h.playing=!1,h.started=!1,u(h.completes)),s=!0)}return n||0!==i.length||0!==o.length||r.push(t),s}for(var i=!1,o=0;o<n.length;o++){var s=a(n[o]);i=i||s}var l=a(t,!0);(i||l)&&(n.length>0?t.notify("draw",n):t.notify("draw")),n.unmerge(r),t.emit("step")}var du={animate:So.animate(),animation:So.animation(),animated:So.animated(),clearQueue:So.clearQueue(),delay:So.delay(),delayAnimation:So.delayAnimation(),stop:So.stop(),addToAnimationPool:function(e){this.styleEnabled()&&this._private.aniEles.merge(e)},stopAnimationLoop:function()Line truncated
|
||||
Reference in new issue
Block a user