topo-engine 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/style.css +11 -11
- package/dist/topo-engine.cjs +65 -10
- package/dist/topo-engine.cjs.map +1 -1
- package/dist/topo-engine.js +65 -10
- package/dist/topo-engine.js.map +1 -1
- package/dist/topo-engine.umd.cjs +65 -10
- package/dist/topo-engine.umd.cjs.map +1 -1
- package/package.json +1 -1
package/dist/topo-engine.js
CHANGED
|
@@ -52,6 +52,13 @@ class TopoApi {
|
|
|
52
52
|
_assertReady() {
|
|
53
53
|
if (!this._graph) throw new Error("[TopoApi] 图实例未就绪,请等待渲染完成");
|
|
54
54
|
}
|
|
55
|
+
/** 画布中心兼容取值:G6 v5 getCanvasCenter 返回数组 [x,y,z],历史代码按 {x,y} 对象使用 */
|
|
56
|
+
_canvasCenterXY() {
|
|
57
|
+
const c = this._graph.getCanvasCenter();
|
|
58
|
+
if (Array.isArray(c)) return { x: c[0], y: c[1] };
|
|
59
|
+
if (c && typeof c === "object") return { x: c.x || 0, y: c.y || 0 };
|
|
60
|
+
return { x: 0, y: 0 };
|
|
61
|
+
}
|
|
55
62
|
/** 安全合并 style:保留现有字段,只覆盖传入字段 */
|
|
56
63
|
_safeNodeStyle(nodeId, style) {
|
|
57
64
|
try {
|
|
@@ -371,7 +378,7 @@ class TopoApi {
|
|
|
371
378
|
try {
|
|
372
379
|
this._graph.focusElement(nodeId);
|
|
373
380
|
} catch {
|
|
374
|
-
const center = this.
|
|
381
|
+
const center = this._canvasCenterXY();
|
|
375
382
|
this._graph.translateTo({ x: center.x - p.x * (zoom || this._graph.getZoom()), y: center.y - p.y * (zoom || this._graph.getZoom()) });
|
|
376
383
|
}
|
|
377
384
|
}
|
|
@@ -379,7 +386,7 @@ class TopoApi {
|
|
|
379
386
|
getViewport() {
|
|
380
387
|
this._assertReady();
|
|
381
388
|
const zoom = this._graph.getZoom();
|
|
382
|
-
const center = this.
|
|
389
|
+
const center = this._canvasCenterXY();
|
|
383
390
|
return { zoom, center };
|
|
384
391
|
}
|
|
385
392
|
// ============================================================
|
|
@@ -752,11 +759,25 @@ class TopoApi {
|
|
|
752
759
|
if (!container) return;
|
|
753
760
|
const pos = this._layout.pos.get(nodeId);
|
|
754
761
|
if (!pos) return;
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
762
|
+
let client = null;
|
|
763
|
+
try {
|
|
764
|
+
if (typeof this._graph.getClientByCanvas === "function") {
|
|
765
|
+
const r = this._graph.getClientByCanvas([pos.x, pos.y]);
|
|
766
|
+
client = Array.isArray(r) ? { x: r[0], y: r[1] } : r;
|
|
767
|
+
}
|
|
768
|
+
} catch (e2) {
|
|
769
|
+
}
|
|
770
|
+
let screenX, screenY;
|
|
771
|
+
if (client && isFinite(client.x)) {
|
|
772
|
+
screenX = client.x;
|
|
773
|
+
screenY = client.y;
|
|
774
|
+
} else {
|
|
775
|
+
const zoom = this._graph.getZoom();
|
|
776
|
+
const canvasCenter = this._canvasCenterXY();
|
|
777
|
+
const containerRect = container.getBoundingClientRect();
|
|
778
|
+
screenX = containerRect.left + canvasCenter.x + pos.x * zoom;
|
|
779
|
+
screenY = containerRect.top + canvasCenter.y + pos.y * zoom;
|
|
780
|
+
}
|
|
760
781
|
const el = document.createElement("div");
|
|
761
782
|
el.className = "topo-card";
|
|
762
783
|
el.dataset.nodeId = nodeId;
|
|
@@ -28188,6 +28209,34 @@ const _sfc_main$2 = {
|
|
|
28188
28209
|
const id2 = evt.target.id;
|
|
28189
28210
|
selectNodeWithInfo(id2);
|
|
28190
28211
|
});
|
|
28212
|
+
function hitTestNodeAtCanvas(evt) {
|
|
28213
|
+
const c = evt && (evt.canvas || evt.viewport) || {};
|
|
28214
|
+
const cx = c.x, cy = c.y;
|
|
28215
|
+
if (cx == null || cy == null) return null;
|
|
28216
|
+
let best = null, bestD = Infinity;
|
|
28217
|
+
let all = [];
|
|
28218
|
+
try {
|
|
28219
|
+
all = graph.getNodeData();
|
|
28220
|
+
} catch {
|
|
28221
|
+
return null;
|
|
28222
|
+
}
|
|
28223
|
+
for (const nd of all || []) {
|
|
28224
|
+
if (nd && nd.data && nd.data.isStationFrame) continue;
|
|
28225
|
+
const st = nd && nd.style;
|
|
28226
|
+
if (!st || st.x == null || st.y == null) continue;
|
|
28227
|
+
const size = st.size || [0, 0];
|
|
28228
|
+
const w = size[0] || 0, h = size[1] || 0;
|
|
28229
|
+
if (w <= 0 || h <= 0) continue;
|
|
28230
|
+
if (cx >= st.x - w / 2 && cx <= st.x + w / 2 && cy >= st.y - h / 2 && cy <= st.y + h / 2) {
|
|
28231
|
+
const d2 = Math.abs(cx - st.x) + Math.abs(cy - st.y);
|
|
28232
|
+
if (d2 < bestD) {
|
|
28233
|
+
bestD = d2;
|
|
28234
|
+
best = nd.id;
|
|
28235
|
+
}
|
|
28236
|
+
}
|
|
28237
|
+
}
|
|
28238
|
+
return best;
|
|
28239
|
+
}
|
|
28191
28240
|
graph.on("node:pointerenter", (evt) => {
|
|
28192
28241
|
const id2 = evt.target.id;
|
|
28193
28242
|
const data3 = graph.getNodeData(id2);
|
|
@@ -28210,6 +28259,11 @@ const _sfc_main$2 = {
|
|
|
28210
28259
|
api._emit("edge:click", { edgeId: id2, source: src, target: tgt });
|
|
28211
28260
|
});
|
|
28212
28261
|
graph.on("canvas:click", (evt) => {
|
|
28262
|
+
const hitId = hitTestNodeAtCanvas(evt);
|
|
28263
|
+
if (hitId) {
|
|
28264
|
+
selectNodeWithInfo(hitId);
|
|
28265
|
+
return;
|
|
28266
|
+
}
|
|
28213
28267
|
if (selectedId) {
|
|
28214
28268
|
const data3 = graph.getNodeData(selectedId);
|
|
28215
28269
|
const existing = data3 && data3.style || {};
|
|
@@ -28222,7 +28276,8 @@ const _sfc_main$2 = {
|
|
|
28222
28276
|
});
|
|
28223
28277
|
graph.on("viewportchange", (evt) => {
|
|
28224
28278
|
const zoom = graph.getZoom();
|
|
28225
|
-
const
|
|
28279
|
+
const raw2 = graph.getCanvasCenter();
|
|
28280
|
+
const center = Array.isArray(raw2) ? { x: raw2[0], y: raw2[1] } : raw2;
|
|
28226
28281
|
api._emit("viewport:change", { zoom, center });
|
|
28227
28282
|
});
|
|
28228
28283
|
graph.render().then(() => {
|
|
@@ -28334,7 +28389,7 @@ const _sfc_main$2 = {
|
|
|
28334
28389
|
};
|
|
28335
28390
|
}
|
|
28336
28391
|
};
|
|
28337
|
-
const TopoGraph = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-
|
|
28392
|
+
const TopoGraph = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-b02bff98"]]);
|
|
28338
28393
|
const _hoisted_1$1 = ["data-theme"];
|
|
28339
28394
|
const _hoisted_2$1 = { class: "panel-head" };
|
|
28340
28395
|
const _hoisted_3$1 = {
|
|
@@ -28644,7 +28699,7 @@ const _sfc_main = {
|
|
|
28644
28699
|
}
|
|
28645
28700
|
};
|
|
28646
28701
|
const DistanceTop10 = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-438b6017"]]);
|
|
28647
|
-
const VERSION = "0.1.
|
|
28702
|
+
const VERSION = "0.1.6";
|
|
28648
28703
|
const DESCRIPTION = "配电台区单线图拓扑成图引擎";
|
|
28649
28704
|
export {
|
|
28650
28705
|
DESCRIPTION,
|