@cosmos.gl/graph 3.0.0-beta.3 → 3.0.0-beta.5
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/index.d.ts +5 -2
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +58 -58
- package/dist/index.min.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,11 @@ import { GraphData } from './modules/GraphData';
|
|
|
4
4
|
export declare class Graph {
|
|
5
5
|
config: GraphConfig;
|
|
6
6
|
graph: GraphData;
|
|
7
|
-
/** Promise that resolves
|
|
8
|
-
readonly
|
|
7
|
+
/** Promise that resolves when the graph is fully initialized and ready to use */
|
|
8
|
+
readonly ready: Promise<void>;
|
|
9
|
+
/** Whether the graph has completed initialization */
|
|
10
|
+
isReady: boolean;
|
|
11
|
+
private readonly deviceInitPromise;
|
|
9
12
|
/** Canvas element, assigned asynchronously during device initialization */
|
|
10
13
|
private canvas;
|
|
11
14
|
private attributionDivElement;
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { scaleLinear as j, scalePow as ce } from "d3-scale";
|
|
|
9
9
|
import { mat3 as V } from "gl-matrix";
|
|
10
10
|
import { Random as he } from "random";
|
|
11
11
|
import { Model as A } from "@luma.gl/engine";
|
|
12
|
-
import fe from "gl-bench
|
|
12
|
+
import fe from "gl-bench";
|
|
13
13
|
import { range as ue } from "d3-array";
|
|
14
14
|
import { zoomIdentity as W, zoom as Se } from "d3-zoom";
|
|
15
15
|
import { drag as pe } from "d3-drag";
|
|
@@ -5387,7 +5387,7 @@ class It {
|
|
|
5387
5387
|
}
|
|
5388
5388
|
class Ht {
|
|
5389
5389
|
constructor(t, i, o) {
|
|
5390
|
-
if (this.config = new Be(), this.graph = new it(this.config), this.requestAnimationFrameId = 0, this.isRightClickMouse = !1, this.store = new Ee(), this.zoomInstance = new vt(this.store, this.config), this.dragInstance = new It(this.store, this.config), this._findHoveredItemExecutionCount = 0, this._isMouseOnCanvas = !1, this._lastMouseX = 0, this._lastMouseY = 0, this._lastCheckedMouseX = 0, this._lastCheckedMouseY = 0, this._shouldForceHoverDetection = !1, this._isFirstRenderAfterInit = !0, this.isPointPositionsUpdateNeeded = !1, this.isPointColorUpdateNeeded = !1, this.isPointSizeUpdateNeeded = !1, this.isPointShapeUpdateNeeded = !1, this.isPointImageIndicesUpdateNeeded = !1, this.isLinksUpdateNeeded = !1, this.isLinkColorUpdateNeeded = !1, this.isLinkWidthUpdateNeeded = !1, this.isLinkArrowUpdateNeeded = !1, this.isPointClusterUpdateNeeded = !1, this.isForceManyBodyUpdateNeeded = !1, this.isForceLinkUpdateNeeded = !1, this.isForceCenterUpdateNeeded = !1, this.isPointImageSizesUpdateNeeded = !1, this._isDestroyed = !1, i && this.config.init(i), o)
|
|
5390
|
+
if (this.config = new Be(), this.graph = new it(this.config), this.isReady = !1, this.requestAnimationFrameId = 0, this.isRightClickMouse = !1, this.store = new Ee(), this.zoomInstance = new vt(this.store, this.config), this.dragInstance = new It(this.store, this.config), this._findHoveredItemExecutionCount = 0, this._isMouseOnCanvas = !1, this._lastMouseX = 0, this._lastMouseY = 0, this._lastCheckedMouseX = 0, this._lastCheckedMouseY = 0, this._shouldForceHoverDetection = !1, this._isFirstRenderAfterInit = !0, this.isPointPositionsUpdateNeeded = !1, this.isPointColorUpdateNeeded = !1, this.isPointSizeUpdateNeeded = !1, this.isPointShapeUpdateNeeded = !1, this.isPointImageIndicesUpdateNeeded = !1, this.isLinksUpdateNeeded = !1, this.isLinkColorUpdateNeeded = !1, this.isLinkWidthUpdateNeeded = !1, this.isLinkArrowUpdateNeeded = !1, this.isPointClusterUpdateNeeded = !1, this.isForceManyBodyUpdateNeeded = !1, this.isForceLinkUpdateNeeded = !1, this.isForceCenterUpdateNeeded = !1, this.isPointImageSizesUpdateNeeded = !1, this._isDestroyed = !1, i && this.config.init(i), o)
|
|
5391
5391
|
this.deviceInitPromise = o, this.shouldDestroyDevice = !1;
|
|
5392
5392
|
else {
|
|
5393
5393
|
const s = document.createElement("canvas");
|
|
@@ -5396,7 +5396,7 @@ class Ht {
|
|
|
5396
5396
|
this.deviceInitPromise.then((s) => {
|
|
5397
5397
|
if (this._isDestroyed)
|
|
5398
5398
|
return this.shouldDestroyDevice && s.destroy(), s;
|
|
5399
|
-
this.device = s;
|
|
5399
|
+
this.device = s, this.isReady = !0;
|
|
5400
5400
|
const n = this.validateDevice(s);
|
|
5401
5401
|
o && n.setProps({ useDevicePixels: this.config.pixelRatio }), this.store.div = t;
|
|
5402
5402
|
const r = n.canvas;
|
|
@@ -5426,7 +5426,8 @@ class Ht {
|
|
|
5426
5426
|
this.currentEvent = d, this.updateCanvasCursor();
|
|
5427
5427
|
}), this.canvasD3Selection.call(this.dragInstance.behavior).call(this.zoomInstance.behavior).on("click", this.onClick.bind(this)).on("mousemove", this.onMouseMove.bind(this)).on("contextmenu", this.onContextMenu.bind(this)), (!this.config.enableZoom || !this.config.enableDrag) && this.updateZoomDragBehaviors(), this.setZoomLevel(this.config.initialZoomLevel ?? 1), this.store.maxPointSize = $(s, this.config.pixelRatio), this.store.isSimulationRunning = this.config.enableSimulation, this.points = new At(s, this.config, this.store, this.graph), this.lines = new dt(s, this.config, this.store, this.graph, this.points), this.config.enableSimulation && (this.forceGravity = new He(s, this.config, this.store, this.graph, this.points), this.forceCenter = new we(s, this.config, this.store, this.graph, this.points), this.forceManyBody = new Le(s, this.config, this.store, this.graph, this.points), this.forceLinkIncoming = new J(s, this.config, this.store, this.graph, this.points), this.forceLinkOutgoing = new J(s, this.config, this.store, this.graph, this.points), this.forceMouse = new qe(s, this.config, this.store, this.graph, this.points)), this.clusters = new Ge(s, this.config, this.store, this.graph, this.points), this.store.backgroundColor = k(this.config.backgroundColor), this.store.setHoveredPointRingColor(this.config.hoveredPointRingColor ?? h.hoveredPointRingColor), this.store.setFocusedPointRingColor(this.config.focusedPointRingColor ?? h.focusedPointRingColor), this.config.focusedPointIndex !== void 0 && this.store.setFocusedPoint(this.config.focusedPointIndex), this.store.setGreyoutPointColor(this.config.pointGreyoutColor ?? Y), this.store.setHoveredLinkColor(this.config.hoveredLinkColor ?? h.hoveredLinkColor), this.store.updateLinkHoveringEnabled(this.config), this.config.showFPSMonitor && (this.fpsMonitor = new G(this.canvas)), this.config.randomSeed !== void 0 && this.store.addRandomSeed(this.config.randomSeed), s;
|
|
5428
5428
|
}).catch((s) => {
|
|
5429
|
-
throw console.error("Device initialization failed:", s), s;
|
|
5429
|
+
throw this.device = void 0, this.isReady = !1, console.error("Device initialization failed:", s), s;
|
|
5430
|
+
}), this.ready = this.deviceInitPromise.then(() => {
|
|
5430
5431
|
});
|
|
5431
5432
|
}
|
|
5432
5433
|
/**
|
|
@@ -6107,7 +6108,7 @@ class Ht {
|
|
|
6107
6108
|
*/
|
|
6108
6109
|
destroy() {
|
|
6109
6110
|
var t, i, o, s, n, r, a, l, d, c, f, p, u;
|
|
6110
|
-
this._isDestroyed || (this._isDestroyed = !0, window.clearTimeout(this._fitViewOnInitTimeoutID), this.stopFrames(), this.canvasD3Selection && this.canvasD3Selection.on("mouseenter.cosmos", null).on("mousemove.cosmos", null).on("mouseleave.cosmos", null).on("click", null).on("mousemove", null).on("contextmenu", null).on(".drag", null).on(".zoom", null), z(document).on("keydown.cosmos", null).on("keyup.cosmos", null), (t = this.zoomInstance) != null && t.behavior && this.zoomInstance.behavior.on("start.detect", null).on("zoom.detect", null).on("end.detect", null), (i = this.dragInstance) != null && i.behavior && this.dragInstance.behavior.on("start.detect", null).on("drag.detect", null).on("end.detect", null), (o = this.fpsMonitor) == null || o.destroy(), (s = this.points) == null || s.destroy(), (n = this.lines) == null || n.destroy(), (r = this.clusters) == null || r.destroy(), (a = this.forceGravity) == null || a.destroy(), (l = this.forceCenter) == null || l.destroy(), (d = this.forceManyBody) == null || d.destroy(), (c = this.forceLinkIncoming) == null || c.destroy(), (f = this.forceLinkOutgoing) == null || f.destroy(), (p = this.forceMouse) == null || p.destroy(), this.device && this.shouldDestroyDevice && (this.device.beginRenderPass({
|
|
6111
|
+
this._isDestroyed || (this._isDestroyed = !0, this.isReady = !1, window.clearTimeout(this._fitViewOnInitTimeoutID), this.stopFrames(), this.canvasD3Selection && this.canvasD3Selection.on("mouseenter.cosmos", null).on("mousemove.cosmos", null).on("mouseleave.cosmos", null).on("click", null).on("mousemove", null).on("contextmenu", null).on(".drag", null).on(".zoom", null), z(document).on("keydown.cosmos", null).on("keyup.cosmos", null), (t = this.zoomInstance) != null && t.behavior && this.zoomInstance.behavior.on("start.detect", null).on("zoom.detect", null).on("end.detect", null), (i = this.dragInstance) != null && i.behavior && this.dragInstance.behavior.on("start.detect", null).on("drag.detect", null).on("end.detect", null), (o = this.fpsMonitor) == null || o.destroy(), (s = this.points) == null || s.destroy(), (n = this.lines) == null || n.destroy(), (r = this.clusters) == null || r.destroy(), (a = this.forceGravity) == null || a.destroy(), (l = this.forceCenter) == null || l.destroy(), (d = this.forceManyBody) == null || d.destroy(), (c = this.forceLinkIncoming) == null || c.destroy(), (f = this.forceLinkOutgoing) == null || f.destroy(), (p = this.forceMouse) == null || p.destroy(), this.device && this.shouldDestroyDevice && (this.device.beginRenderPass({
|
|
6111
6112
|
clearColor: this.store.backgroundColor,
|
|
6112
6113
|
clearDepth: 1,
|
|
6113
6114
|
clearStencil: 0
|
|
@@ -6146,7 +6147,7 @@ class Ht {
|
|
|
6146
6147
|
* @returns true if device was not ready and operation was queued, false if device is ready
|
|
6147
6148
|
*/
|
|
6148
6149
|
ensureDevice(t) {
|
|
6149
|
-
return this.
|
|
6150
|
+
return this.isReady ? !1 : (this.ready.then(() => {
|
|
6150
6151
|
this._isDestroyed || t();
|
|
6151
6152
|
}).catch((i) => {
|
|
6152
6153
|
console.error("Device initialization failed", i);
|