import { Edge , Score , Node , TypedNode , Graph } from 'nf-grapher' ; export class DirectedScore { constructor ( private score = new Score ( ) ) { } graphId ( ) { return this . score . graph . id ; } toJSON ( ) { return this . score ; } incomingEdges ( id ) ; incomingEdges ( node ) ; incomingEdges ( nodeOrId ) { const id = typeof nodeOrId === 'string' ? nodeOrId : nodeOrId . id ; const edges = this . score . graph . edges . filter ( edge => edge . target === id ) ; return edges ; } outgoingEdges ( id ) ; outgoingEdges ( node ) ; outgoingEdges ( nodeOrId ) { const id = typeof nodeOrId === 'string' ? nodeOrId : nodeOrId . id ; const edges = this . score . graph . edges . filter ( edge => edge . source === id ) ; return edges ; } leaves ( ) { const leaves = [ ] ; for ( let node of this . score . graph . nodes ) { const edges = this . outgoingEdges ( node ) ; if ( edges . length === 0 ) { leaves . push ( node ) ; } } return leaves ; } source ( edge ) { const node = this . score . graph . nodes . find ( n => edge . source === n . id ) ; return node ; } target ( edge ) { const node = this . score . graph . nodes . find ( n => edge . target === n . id ) ; return node ; } byId ( id ) { const node = this . score . graph . nodes . find ( n => n . id === id ) ; return node ; } }