@@ -203,14 +203,14 @@ const createProductionResourceContainer = (textures, name, isHighlighted, operat
203
203
return container ;
204
204
} ;
205
205
206
- function cubicBezier ( p0 , p1 , p2 , p3 , t ) {
206
+ const cubicBezier = ( p0 , p1 , p2 , p3 , t ) => {
207
207
const c = 3 * ( p1 - p0 ) ;
208
208
const b = 3 * ( p2 - p1 ) - c ;
209
209
const a = p3 - p0 - c - b ;
210
210
return a * ( t * t * t ) + b * ( t * t ) + c * t + p0 ;
211
- }
211
+ } ;
212
212
213
- function drawArrow ( stage , x1 , y1 , x2 , y2 , cp1x , cp1y , cp2x , cp2y , size = 12 , isGrayedOut ) {
213
+ const drawArrow = ( x1 , y1 , x2 , y2 , cp1x , cp1y , cp2x , cp2y , size = 12 , isGrayedOut ) => {
214
214
const t = 0.5 ;
215
215
const midX = cubicBezier ( x1 , cp1x , cp2x , x2 , t ) ;
216
216
const midY = cubicBezier ( y1 , cp1y , cp2y , y2 , t ) ;
@@ -220,23 +220,22 @@ function drawArrow(stage, x1, y1, x2, y2, cp1x, cp1y, cp2x, cp2y, size = 12, isG
220
220
const angle = Math . atan2 ( dy , dx ) ;
221
221
222
222
const arrowGraphics = new Graphics ( ) ;
223
- arrowGraphics . fill ( { color : ! isGrayedOut ? 0xffffff : HIDDEN_LINK_COLOR , alpha : 1 } ) ;
224
223
arrowGraphics . poly ( [ 0 , 0 , - size , size / 2 , - size , - size / 2 ] ) ;
225
- arrowGraphics . endFill ( ) ;
224
+ arrowGraphics . fill ( { color : ! isGrayedOut ? 0xffffff : HIDDEN_LINK_COLOR , alpha : 1 } ) ;
226
225
arrowGraphics . x = midX ;
227
226
arrowGraphics . y = midY ;
228
227
arrowGraphics . rotation = angle ;
229
- stage . addChild ( arrowGraphics ) ;
230
- }
228
+ return arrowGraphics ;
229
+ } ;
231
230
232
- function cubicBezierDerivative ( p0 , p1 , p2 , p3 , t ) {
231
+ const cubicBezierDerivative = ( p0 , p1 , p2 , p3 , t ) => {
233
232
const c = 3 * ( p1 - p0 ) ;
234
233
const b = 3 * ( p2 - p1 ) - c ;
235
234
const a = p3 - p0 - c - b ;
236
235
return 3 * a * t * t + 2 * b * t + c ;
237
- }
236
+ } ;
238
237
239
- function drawDashedBezier ( ctx , x1 , y1 , cp1x , cp1y , cp2x , cp2y , x2 , y2 , dash = 4 , gap = 4 ) {
238
+ const drawDashedBezier = ( ctx , x1 , y1 , cp1x , cp1y , cp2x , cp2y , x2 , y2 , dash = 4 , gap = 4 ) => {
240
239
const segments = 80 ;
241
240
let prev = { x : x1 , y : y1 } ;
242
241
let dist = 0 ;
@@ -269,14 +268,17 @@ function drawDashedBezier(ctx, x1, y1, cp1x, cp1y, cp2x, cp2y, x2, y2, dash = 4,
269
268
dist += segLength ;
270
269
}
271
270
}
272
- }
271
+ } ;
273
272
274
273
const createLinkGraphics = ( links , setSelectedElementId , settings ) => {
275
274
const isLayoutHorizontal = settings ?. orientation === 'horizontal' ;
276
275
const spacingFactor = settings . spacing / 100.0 ;
277
276
278
277
return links . map ( ( link ) => {
278
+ const graphicsContainer = new Container ( ) ;
279
279
const graphics = new Graphics ( ) ;
280
+ graphicsContainer . addChild ( graphics ) ;
281
+
280
282
graphics . eventMode = 'static' ;
281
283
graphics . cursor = 'pointer' ;
282
284
@@ -334,9 +336,7 @@ const createLinkGraphics = (links, setSelectedElementId, settings) => {
334
336
) ;
335
337
336
338
graphics . lineTo ( target . x - targetOffset . x , target . y - targetOffset . y ) ;
337
-
338
- drawArrow (
339
- graphics ,
339
+ const arrow = drawArrow (
340
340
source . x + sourceOffset . x ,
341
341
source . y + sourceOffset . y ,
342
342
target . x - targetOffset . x ,
@@ -348,6 +348,7 @@ const createLinkGraphics = (links, setSelectedElementId, settings) => {
348
348
12 ,
349
349
link . isGrayedOut
350
350
) ;
351
+ graphicsContainer . addChild ( arrow ) ;
351
352
}
352
353
353
354
graphics . stroke ( {
@@ -360,7 +361,7 @@ const createLinkGraphics = (links, setSelectedElementId, settings) => {
360
361
graphics . filters = link . isSelected && settings . enableGlowEffect ? [ SELECTED_LINK_FILTER ] : [ ] ;
361
362
graphics . elementId = link . data . id ;
362
363
363
- return graphics ;
364
+ return graphicsContainer ;
364
365
} ) ;
365
366
} ;
366
367
@@ -411,9 +412,23 @@ const generateTextures = (app) => {
411
412
return textures ;
412
413
} ;
413
414
415
+ export const freeDisplayMemory = ( container ) => {
416
+ container . children . forEach ( ( child ) => {
417
+ freeDisplayMemory ( child ) ;
418
+ child . destroy ( {
419
+ children : true ,
420
+ texture : true ,
421
+ context : true ,
422
+ style : true ,
423
+ } ) ;
424
+ } ) ;
425
+ } ;
426
+
414
427
export const renderElements = ( sceneContainerRef , graphRef , setSelectedElementId , settings , resetBounds = true ) => {
415
428
if ( ! graphRef . current || ! sceneContainerRef . current ?. textures ) return ;
416
429
430
+ freeDisplayMemory ( sceneContainerRef . current ) ;
431
+
417
432
const { nodes, links } = graphRef . current ;
418
433
const textures = sceneContainerRef . current . textures ;
419
434
0 commit comments