@@ -245,48 +245,31 @@ export default class CanvasDrawer {
245245 const edges = this . cytoscape . edges ( ) . toArray ( ) ;
246246 const hasSelection = this . selectionNeighborhood . size ( ) > 0 ;
247247
248- // transparent edges
249- if ( hasSelection ) {
250- ctx . globalAlpha = 0.25 ;
248+ const transparentEdges = edges . filter ( edge => hasSelection && ! this . selectionNeighborhood . has ( edge ) ) ;
249+ const opaqueEdges = edges . filter ( edge => ! hasSelection || this . selectionNeighborhood . has ( edge ) ) ;
251250
252- for ( let i = 0 ; i < edges . length ; i ++ ) {
253- const edge = edges [ i ] ;
254-
255- if ( ! this . selectionNeighborhood . has ( edge ) ) {
256- this . _drawEdge ( ctx , edge , now ) ;
257- }
258- }
259- }
260-
261- // visible edges
251+ ctx . globalAlpha = 0.25 ;
252+ this . _drawEdges ( ctx , transparentEdges , now )
262253 ctx . globalAlpha = 1 ;
263-
264- for ( let i = 0 ; i < edges . length ; i ++ ) {
265- const edge = edges [ i ] ;
266-
267- if ( ! hasSelection || this . selectionNeighborhood . has ( edge ) ) {
268- this . _drawEdge ( ctx , edge , now ) ;
269- }
270- }
271-
254+ this . _drawEdges ( ctx , opaqueEdges , now )
272255 ctx . restore ( ) ;
273256 }
274257
275- _drawEdge ( ctx : CanvasRenderingContext2D , edge : cytoscape . EdgeSingular , now : number ) {
258+ _drawEdges ( ctx : CanvasRenderingContext2D , edges : Array < cytoscape . EdgeSingular > , now : number ) {
276259 const cy = this . cytoscape ;
277- const sourcePoint = edge . sourceEndpoint ( ) ;
278- const targetPoint = edge . targetEndpoint ( ) ;
279-
280- // draw edge line
281- this . _drawEdgeLine ( ctx , edge , sourcePoint , targetPoint ) ;
282260
283- // draw particles
284- this . _drawEdgeParticles ( ctx , edge , sourcePoint , targetPoint , now ) ;
285-
286- // draw label
261+ for ( const edge of edges ) {
262+ const sourcePoint = edge . sourceEndpoint ( ) ;
263+ const targetPoint = edge . targetEndpoint ( ) ;
264+ this . _drawEdgeLine ( ctx , edge , sourcePoint , targetPoint ) ;
265+ this . _drawEdgeParticles ( ctx , edge , sourcePoint , targetPoint , now ) ;
266+ }
267+
287268 const { showConnectionStats } = this . controller . getSettings ( ) ;
288269 if ( showConnectionStats && cy . zoom ( ) > 1 ) {
289- this . _drawEdgeLabel ( ctx , edge ) ;
270+ for ( const edge of edges ) {
271+ this . _drawEdgeLabel ( ctx , edge ) ;
272+ }
290273 }
291274 }
292275
0 commit comments