@@ -298,8 +298,8 @@ export function rendererPointToPoint({ x, y }: XYPosition, { x: tx, y: ty, zoom:
298
298
export function pointToRendererPoint (
299
299
{ x, y } : XYPosition ,
300
300
{ x : tx , y : ty , zoom : tScale } : ViewportTransform ,
301
- snapToGrid : boolean ,
302
- [ snapX , snapY ] : [ snapX : number , snapY : number ] ,
301
+ snapToGrid : boolean = false ,
302
+ [ snapX , snapY ] : [ snapX : number , snapY : number ] = [ 1 , 1 ] ,
303
303
) : XYPosition {
304
304
const position : XYPosition = {
305
305
x : ( x - tx ) / tScale ,
@@ -373,37 +373,41 @@ export function getRectOfNodes(nodes: GraphNode[]) {
373
373
export function getNodesInside (
374
374
nodes : GraphNode [ ] ,
375
375
rect : Rect ,
376
- { x : tx , y : ty , zoom : tScale } : ViewportTransform = { x : 0 , y : 0 , zoom : 1 } ,
376
+ viewport : ViewportTransform = { x : 0 , y : 0 , zoom : 1 } ,
377
377
partially = false ,
378
378
// set excludeNonSelectableNodes if you want to pay attention to the nodes "selectable" attribute
379
379
excludeNonSelectableNodes = false ,
380
380
) {
381
381
const paneRect = {
382
- x : ( rect . x - tx ) / tScale ,
383
- y : ( rect . y - ty ) / tScale ,
384
- width : rect . width / tScale ,
385
- height : rect . height / tScale ,
382
+ ...pointToRendererPoint ( rect , viewport ) ,
383
+ width : rect . width / viewport . zoom ,
384
+ height : rect . height / viewport . zoom ,
386
385
}
387
386
388
- return nodes . filter ( ( node ) => {
389
- const { computedPosition = { x : 0 , y : 0 } , dimensions = { width : 0 , height : 0 } , selectable } = node
387
+ const visibleNodes : GraphNode [ ] = [ ]
390
388
391
- if ( excludeNonSelectableNodes && ! selectable ) {
392
- return false
389
+ for ( const node of nodes ) {
390
+ const { dimensions, selectable = true , hidden = false } = node
391
+ const width = dimensions . width ?? node . width ?? null
392
+ const height = dimensions . height ?? node . height ?? null
393
+
394
+ if ( ( excludeNonSelectableNodes && ! selectable ) || hidden ) {
395
+ continue
393
396
}
394
397
395
- const nodeRect = { ...computedPosition , width : dimensions . width || 0 , height : dimensions . height || 0 }
396
- const overlappingArea = getOverlappingArea ( paneRect , nodeRect )
397
- const notInitialized =
398
- typeof dimensions . width === 'undefined' ||
399
- typeof dimensions . height === 'undefined' ||
400
- dimensions . width === 0 ||
401
- dimensions . height === 0
398
+ const overlappingArea = getOverlappingArea ( paneRect , nodeToRect ( node ) )
399
+ const notInitialized = width === null || height === null
402
400
403
401
const partiallyVisible = partially && overlappingArea > 0
404
- const area = dimensions . width * dimensions . height
405
- return notInitialized || partiallyVisible || overlappingArea >= area
406
- } )
402
+ const area = ( width ?? 0 ) * ( height ?? 0 )
403
+ const isVisible = notInitialized || partiallyVisible || overlappingArea >= area
404
+
405
+ if ( isVisible || node . dragging ) {
406
+ visibleNodes . push ( node )
407
+ }
408
+ }
409
+
410
+ return visibleNodes
407
411
}
408
412
409
413
export function getConnectedEdges < E extends Edge > ( nodesOrId : Node [ ] | string , edges : E [ ] ) {
0 commit comments