import Graphin from '../Graphin' ; import { G6Event } from '../types' ; const dragWithForce = ( graphin ) => { const { graph , g6Options } = graphin ; const { autoFollowWithForce = true , autoPinWithForce = true , restartForceOnDrag = true , } = g6Options ! ; /** 拖拽Force节点：start */ graph ! . on ( 'node:dragstart' , ( ) => { if ( graphin . state . forceSimulation ) { graphin . state . forceSimulation . stop ( ) ; } } ) ; /** 拖拽结束 */ graph ! . on ( 'node:dragend' , ( e ) => { if ( graphin . state . forceSimulation && autoFollowWithForce && restartForceOnDrag ) { const nodeModel = e . item . get ( 'model' ) ; nodeModel . x = e . x ; nodeModel . y = e . y ; nodeModel . layout = { ... nodeModel . layout , force : { mass : autoPinWithForce ? 1000000 : null , } , } ; const drageNodes = [ nodeModel ] ; graphin . state . forceSimulation . restart ( drageNodes , graph ! ) ; graph ! . refreshPositions ( ) ; } } ) ; } ; export default dragWithForce ;