@cosmograph/cosmos
Advanced tools
Comparing version 2.0.0-beta.7 to 2.0.0-beta.8
@@ -24,3 +24,2 @@ import 'd3-transition'; | ||
private fpsMonitor; | ||
private hasParticleSystemDestroyed; | ||
private currentEvent; | ||
@@ -41,2 +40,9 @@ /** | ||
private _fitViewOnInitTimeoutID; | ||
private _hasPointPositionsChanged; | ||
private _hasPointColorsChanged; | ||
private _hasPointSizesChanged; | ||
private _hasLinksChanged; | ||
private _hasLinkColorsChanged; | ||
private _hasLinkWidthsChanged; | ||
private _hasLinkArrowsChanged; | ||
constructor(canvas: HTMLCanvasElement, config?: GraphConfigInterface); | ||
@@ -303,3 +309,2 @@ /** | ||
pair(pointPositions: number[]): [number, number][]; | ||
private destroyParticleSystem; | ||
private update; | ||
@@ -306,0 +311,0 @@ private initPrograms; |
@@ -10,3 +10,2 @@ import { CoreModule } from '@/graph/modules/core-module'; | ||
run(): void; | ||
destroy(): void; | ||
} |
@@ -19,3 +19,2 @@ import regl from 'regl'; | ||
run(): void; | ||
destroy(): void; | ||
} |
@@ -14,3 +14,2 @@ import { CoreModule } from '@/graph/modules/core-module'; | ||
run(): void; | ||
destroy(): void; | ||
} |
@@ -12,3 +12,2 @@ import { CoreModule } from '@/graph/modules/core-module'; | ||
run(): void; | ||
destroy(): void; | ||
} |
@@ -10,3 +10,2 @@ import { CoreModule } from '@/graph/modules/core-module'; | ||
private curveLineBuffer; | ||
create(): void; | ||
initPrograms(): void; | ||
@@ -19,3 +18,2 @@ draw(): void; | ||
updateCurveLineGeometry(): void; | ||
destroy(): void; | ||
} |
@@ -27,3 +27,3 @@ import regl from 'regl'; | ||
private trackedIndices; | ||
create(): void; | ||
updatePositions(): void; | ||
initPrograms(): void; | ||
@@ -43,4 +43,3 @@ updateColor(): void; | ||
getSampledPointPositionsMap(): Map<number, [number, number]>; | ||
destroy(): void; | ||
private swapFbo; | ||
} |
{ | ||
"name": "@cosmograph/cosmos", | ||
"version": "2.0.0-beta.7", | ||
"version": "2.0.0-beta.8", | ||
"description": "GPU-based force graph layout and rendering", | ||
@@ -5,0 +5,0 @@ "jsdelivr": "dist/index.min.js", |
@@ -46,3 +46,3 @@ import { select, Selection } from 'd3-selection' | ||
private fpsMonitor: FPSMonitor | undefined | ||
private hasParticleSystemDestroyed = false | ||
private currentEvent: D3ZoomEvent<HTMLCanvasElement, undefined> | D3DragEvent<HTMLCanvasElement, undefined, Hovered> | MouseEvent | undefined | ||
@@ -64,2 +64,10 @@ /** | ||
private _hasPointPositionsChanged = false | ||
private _hasPointColorsChanged = false | ||
private _hasPointSizesChanged = false | ||
private _hasLinksChanged = false | ||
private _hasLinkColorsChanged = false | ||
private _hasLinkWidthsChanged = false | ||
private _hasLinkArrowsChanged = false | ||
public constructor (canvas: HTMLCanvasElement, config?: GraphConfigInterface) { | ||
@@ -260,2 +268,3 @@ if (config) this.config.init(config) | ||
this.graph.pointPositions = pointPositions | ||
this._hasPointPositionsChanged = true | ||
} | ||
@@ -272,2 +281,3 @@ | ||
this.graph.inputPointColors = pointColors | ||
this._hasPointColorsChanged = true | ||
} | ||
@@ -284,2 +294,3 @@ | ||
this.graph.inputPointSizes = pointSizes | ||
this._hasPointSizesChanged = true | ||
} | ||
@@ -296,2 +307,3 @@ | ||
this.graph.links = links | ||
this._hasLinksChanged = true | ||
} | ||
@@ -308,2 +320,3 @@ | ||
this.graph.inputLinkColors = linkColors | ||
this._hasLinkColorsChanged = true | ||
} | ||
@@ -320,2 +333,3 @@ | ||
this.graph.inputLinkWidths = linkWidths | ||
this._hasLinkWidthsChanged = true | ||
} | ||
@@ -332,2 +346,3 @@ | ||
this.graph.linkArrowsBoolean = linkArrows | ||
this._hasLinkArrowsChanged = true | ||
} | ||
@@ -356,3 +371,2 @@ | ||
this.stopFrames() | ||
this.destroyParticleSystem() | ||
select(this.canvas).style('cursor', null) | ||
@@ -454,3 +468,2 @@ this.reglInstance.clear({ | ||
const positions: number[] = [] | ||
if (this.hasParticleSystemDestroyed) return [] | ||
const pointPositionsPixels = readPixels(this.reglInstance, this.points.currentPositionFbo as regl.Framebuffer2D) | ||
@@ -724,3 +737,3 @@ positions.length = this.graph.pointsNumber * 2 | ||
this.stopFrames() | ||
this.destroyParticleSystem() | ||
this.reglInstance.destroy() | ||
// Clears the canvas after particle system is destroyed | ||
@@ -741,4 +754,32 @@ this.reglInstance.clear({ | ||
public create (): void { | ||
this.points.create() | ||
this.lines.create() | ||
if (this._hasPointPositionsChanged) { | ||
this.points.updatePositions() | ||
this._hasPointPositionsChanged = false | ||
} | ||
if (this._hasPointColorsChanged) { | ||
this.points.updateColor() | ||
this._hasPointColorsChanged = false | ||
} | ||
if (this._hasPointSizesChanged) { | ||
this.points.updateSize() | ||
this._hasPointSizesChanged = false | ||
} | ||
if (this._hasLinksChanged) { | ||
this.lines.updatePointsBuffer() | ||
this._hasLinksChanged = false | ||
} | ||
if (this._hasLinkColorsChanged) { | ||
this.lines.updateColor() | ||
this._hasLinkColorsChanged = false | ||
} | ||
if (this._hasLinkWidthsChanged) { | ||
this.lines.updateWidth() | ||
this._hasLinkWidthsChanged = false | ||
} | ||
if (this._hasLinkArrowsChanged) { | ||
this.lines.updateArrow() | ||
this._hasLinkArrowsChanged = false | ||
} | ||
this.lines.updateCurveLineGeometry() | ||
this.forceManyBody?.create() | ||
@@ -748,3 +789,2 @@ this.forceLinkIncoming?.create(LinkDirection.INCOMING) | ||
this.forceCenter?.create() | ||
this.hasParticleSystemDestroyed = false | ||
} | ||
@@ -775,14 +815,2 @@ | ||
private destroyParticleSystem (): void { | ||
if (this.hasParticleSystemDestroyed) return | ||
this.points.destroy() | ||
this.lines.destroy() | ||
this.forceCenter?.destroy() | ||
this.forceLinkIncoming?.destroy() | ||
this.forceLinkOutgoing?.destroy() | ||
this.forceManyBody?.destroy() | ||
this.reglInstance.destroy() | ||
this.hasParticleSystemDestroyed = true | ||
} | ||
private update (runSimulation: boolean): void { | ||
@@ -792,3 +820,2 @@ const { graph } = this | ||
this.store.linksTextureSize = Math.ceil(Math.sqrt((graph.linksNumber ?? 0) * 2)) | ||
this.destroyParticleSystem() | ||
this.create() | ||
@@ -800,3 +827,3 @@ this.initPrograms() | ||
if (runSimulation) { | ||
this.start() | ||
this.start(this.store.alpha) | ||
} else { | ||
@@ -803,0 +830,0 @@ this.step() |
@@ -18,2 +18,3 @@ import regl from 'regl' | ||
const { reglInstance } = this | ||
destroyFramebuffer(this.centermassFbo) | ||
this.centermassFbo = reglInstance.framebuffer({ | ||
@@ -86,6 +87,2 @@ color: reglInstance.texture({ | ||
} | ||
public destroy (): void { | ||
destroyFramebuffer(this.centermassFbo) | ||
} | ||
} |
@@ -58,2 +58,3 @@ import regl from 'regl' | ||
destroyFramebuffer(this.linkFirstIndicesAndAmountFbo) | ||
this.linkFirstIndicesAndAmountFbo = reglInstance.framebuffer({ | ||
@@ -68,2 +69,3 @@ color: reglInstance.texture({ | ||
}) | ||
destroyFramebuffer(this.indicesFbo) | ||
this.indicesFbo = reglInstance.framebuffer({ | ||
@@ -78,2 +80,3 @@ color: reglInstance.texture({ | ||
}) | ||
destroyFramebuffer(this.biasAndStrengthFbo) | ||
this.biasAndStrengthFbo = reglInstance.framebuffer({ | ||
@@ -88,2 +91,3 @@ color: reglInstance.texture({ | ||
}) | ||
destroyFramebuffer(this.randomDistanceFbo) | ||
this.randomDistanceFbo = reglInstance.framebuffer({ | ||
@@ -128,9 +132,2 @@ color: reglInstance.texture({ | ||
} | ||
public destroy (): void { | ||
destroyFramebuffer(this.linkFirstIndicesAndAmountFbo) | ||
destroyFramebuffer(this.indicesFbo) | ||
destroyFramebuffer(this.biasAndStrengthFbo) | ||
destroyFramebuffer(this.randomDistanceFbo) | ||
} | ||
} |
@@ -25,2 +25,6 @@ import regl from 'regl' | ||
this.quadtreeLevels = Math.log2(store.adjustedSpaceSize) | ||
this.levelsFbos.forEach(fbo => { | ||
destroyFramebuffer(fbo) | ||
}) | ||
this.levelsFbos.clear() | ||
for (let i = 0; i < this.quadtreeLevels; i += 1) { | ||
@@ -43,2 +47,3 @@ const levelTextureSize = Math.pow(2, i + 1) | ||
destroyFramebuffer(this.randomValuesFbo) | ||
this.randomValuesFbo = reglInstance.framebuffer({ | ||
@@ -195,10 +200,2 @@ color: reglInstance.texture({ | ||
} | ||
public destroy (): void { | ||
destroyFramebuffer(this.randomValuesFbo) | ||
this.levelsFbos.forEach(fbo => { | ||
destroyFramebuffer(fbo) | ||
}) | ||
this.levelsFbos.clear() | ||
} | ||
} |
@@ -22,2 +22,6 @@ import regl from 'regl' | ||
this.quadtreeLevels = Math.log2(store.adjustedSpaceSize) | ||
this.levelsFbos.forEach(fbo => { | ||
destroyFramebuffer(fbo) | ||
}) | ||
this.levelsFbos.clear() | ||
for (let i = 0; i < this.quadtreeLevels; i += 1) { | ||
@@ -43,2 +47,3 @@ const levelTextureSize = Math.pow(2, i + 1) | ||
destroyFramebuffer(this.randomValuesFbo) | ||
this.randomValuesFbo = reglInstance.framebuffer({ | ||
@@ -126,10 +131,2 @@ color: reglInstance.texture({ | ||
} | ||
public destroy (): void { | ||
destroyFramebuffer(this.randomValuesFbo) | ||
this.levelsFbos.forEach(fbo => { | ||
destroyFramebuffer(fbo) | ||
}) | ||
this.levelsFbos.clear() | ||
} | ||
} |
@@ -18,10 +18,2 @@ import regl from 'regl' | ||
public create (): void { | ||
this.updatePointsBuffer() | ||
this.updateColor() | ||
this.updateWidth() | ||
this.updateArrow() | ||
this.updateCurveLineGeometry() | ||
} | ||
public initPrograms (): void { | ||
@@ -135,2 +127,3 @@ const { reglInstance, config, store } = this | ||
} | ||
destroyBuffer(this.pointsBuffer) | ||
this.pointsBuffer = reglInstance.buffer(instancePoints) | ||
@@ -160,12 +153,5 @@ } | ||
this.curveLineGeometry = getCurveLineGeometry(curvedLinks ? curvedLinkSegments ?? defaultConfigValues.curvedLinkSegments : 1) | ||
destroyBuffer(this.curveLineBuffer) | ||
this.curveLineBuffer = reglInstance.buffer(this.curveLineGeometry) | ||
} | ||
public destroy (): void { | ||
destroyBuffer(this.pointsBuffer) | ||
destroyBuffer(this.colorBuffer) | ||
destroyBuffer(this.widthBuffer) | ||
destroyBuffer(this.arrowBuffer) | ||
destroyBuffer(this.curveLineBuffer) | ||
} | ||
} |
@@ -50,6 +50,7 @@ import regl from 'regl' | ||
public create (): void { | ||
public updatePositions (): void { | ||
const { reglInstance, store, data } = this | ||
const { pointsTextureSize } = store | ||
if (!pointsTextureSize || !data.pointPositions || data.pointsNumber === undefined) return | ||
const initialState = new Float32Array(pointsTextureSize * pointsTextureSize * 4) | ||
@@ -64,2 +65,3 @@ // if (!config.disableSimulation) this.rescaleInitialNodePositions() // TODO ⁉️ | ||
// Create position buffer | ||
destroyFramebuffer(this.currentPositionFbo) | ||
this.currentPositionFbo = reglInstance.framebuffer({ | ||
@@ -75,2 +77,3 @@ color: reglInstance.texture({ | ||
destroyFramebuffer(this.previousPositionFbo) | ||
this.previousPositionFbo = reglInstance.framebuffer({ | ||
@@ -88,2 +91,3 @@ color: reglInstance.texture({ | ||
// Create velocity buffer | ||
destroyFramebuffer(this.velocityFbo) | ||
this.velocityFbo = reglInstance.framebuffer({ | ||
@@ -101,2 +105,3 @@ color: reglInstance.texture({ | ||
// Create selected points buffer | ||
destroyFramebuffer(this.selectedFbo) | ||
this.selectedFbo = reglInstance.framebuffer({ | ||
@@ -112,2 +117,3 @@ color: reglInstance.texture({ | ||
destroyFramebuffer(this.hoveredFbo) | ||
this.hoveredFbo = reglInstance.framebuffer({ | ||
@@ -120,4 +126,2 @@ shape: [2, 2], | ||
this.updateSize() | ||
this.updateColor() | ||
this.updateGreyoutStatus() | ||
@@ -358,2 +362,3 @@ this.updateSampledPointsGrid() | ||
const { reglInstance, store } = this | ||
destroyFramebuffer(this.greyoutStatusFbo) | ||
this.greyoutStatusFbo = createGreyoutStatusBuffer(store.selectedIndices, reglInstance, store.pointsTextureSize) | ||
@@ -494,15 +499,2 @@ } | ||
public destroy (): void { | ||
destroyFramebuffer(this.currentPositionFbo) | ||
destroyFramebuffer(this.previousPositionFbo) | ||
destroyFramebuffer(this.velocityFbo) | ||
destroyFramebuffer(this.selectedFbo) | ||
destroyBuffer(this.colorBuffer) | ||
destroyBuffer(this.sizeBuffer) | ||
destroyFramebuffer(this.greyoutStatusFbo) | ||
destroyFramebuffer(this.hoveredFbo) | ||
destroyFramebuffer(this.trackedIndicesFbo) | ||
destroyFramebuffer(this.trackedPositionsFbo) | ||
} | ||
private swapFbo (): void { | ||
@@ -509,0 +501,0 @@ const temp = this.previousPositionFbo |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2243777
9435