UNPKG

cytoscape

Version:

Graph theory (a.k.a. network) library for analysis and visualisation

77 lines (59 loc) • 2.15 kB
import * as math from '../../../../math.mjs'; import { arrowPrefixes, getArrowScale } from '../../../../style/arrow-scale.mjs'; var BRp = {}; function pushBezierPts( r, edge, pts ){ var qbezierAt = function( p1, p2, p3, t ){ return math.qbezierAt( p1, p2, p3, t ); }; var _p = edge._private; var bpts = _p.rstyle.bezierPts; for( var i = 0; i < r.bezierProjPcts.length; i++ ){ var p = r.bezierProjPcts[i]; bpts.push( { x: qbezierAt( pts[0], pts[2], pts[4], p ), y: qbezierAt( pts[1], pts[3], pts[5], p ) } ); } } BRp.storeEdgeProjections = function( edge ){ var _p = edge._private; var rs = _p.rscratch; var et = rs.edgeType; // clear the cached points state _p.rstyle.bezierPts = null; _p.rstyle.linePts = null; _p.rstyle.haystackPts = null; if( et === 'multibezier' || et === 'bezier' || et === 'self' || et === 'compound' ){ _p.rstyle.bezierPts = []; for( var i = 0; i + 5 < rs.allpts.length; i += 4 ){ pushBezierPts( this, edge, rs.allpts.slice( i, i + 6 ) ); } } else if( et === 'segments' ){ var lpts = _p.rstyle.linePts = []; for( var i = 0; i + 1 < rs.allpts.length; i += 2 ){ lpts.push( { x: rs.allpts[ i ], y: rs.allpts[ i + 1] } ); } } else if( et === 'haystack' ){ var hpts = rs.haystackPts; _p.rstyle.haystackPts = [ { x: hpts[0], y: hpts[1] }, { x: hpts[2], y: hpts[3] } ]; } let edgeWidth = edge.pstyle('width').pfValue; let arrowWidths = _p.rstyle.arrowWidths = _p.rstyle.arrowWidths || {}; let maxScale = 0; for( let i = 0; i < arrowPrefixes.length; i++ ){ let prefix = arrowPrefixes[ i ]; let scale = getArrowScale( edge, prefix ); arrowWidths[ prefix ] = this.getArrowWidth( edgeWidth, scale ) * this.arrowShapeWidth; if( scale > maxScale ){ maxScale = scale; } } // kept for callers that want one width covering every arrow on the edge _p.rstyle.arrowWidth = this.getArrowWidth( edgeWidth, maxScale ) * this.arrowShapeWidth; }; BRp.recalculateEdgeProjections = function( edges ){ this.findEdgeControlPoints( edges ); }; export default BRp;