Class Graph

A directed/undirected graph. Each instance of JsPlumb has a Graph at its core.

Methods

  • Adds an edge to the graph.

    Parameters

    • params: AddEdgeOptions
    • OptionalidFunction: IdFunction
    • OptionalconnectableFilterFunction: Function

    Returns Edge

  • Adds a list of Nodes to the Graph

    Parameters

    • data: ObjectData[]

      List of data objects, one for each Node to be added.

    • OptionalidFunction: IdFunction

      Optional function to use to retrieve ID from backing data. Defaults to retrieving id from data object.

    Returns void

  • Deletes an Edge.

    Parameters

    • edge: string | Edge

      Edge, or ID of Edge, to delete.

    Returns void

  • Deletes a Group

    Parameters

    • g: string | Group

      Either a Group, or a Group id.

    • OptionalremoveMembers: boolean

      If true, also remove all the Nodes/Groups that are members of the Group.

    Returns GroupDeletion

  • Finds the shortest path from source to target, using the Djikstra algorithm.

    Parameters

    • source: string | Vertex

      Source Node or Node ID.

    • target: string | Vertex

      Target Node or Node ID.

    • Optionalstrict: boolean

      Defaults to true. Sets whether or not paths are searched strictly by the given source/target. If, for instance, you supply a node as the source, but there are only edges connected to ports on that node, by default these edges will be ignored. Switching strict to false will mean these edges are considered.

    • OptionalnodeFilter: Function

      Optional function that is given each Node's backing data and asked to return true or false - true means include the Node, false means exclude it.

    • OptionaledgeFilter: Function

      Optional function that is given each Edge's backing data and asked to return true or false - true means include the Edge, false means exclude it.

    Returns ShortestPathResult

    A ShortestPathResult object.

  • Gets every edge in the Graph.

    Returns Edge[]

  • Gets a list of groups that are ancestors of the given node/group/port. The list of ancestors is ordered in terms of their proximity to the focus, ie. the first entry is the focus vertex's immediate parent.

    Parameters

    Returns Group[]

  • Returns the betweenness centrality of the given node.

    Parameters

    • vertex: string | Vertex

      Vertex, or Vertex ID, to retrieve betweenness centrality for.

    Returns number

    Vertex's "betweenness" centrality.

  • Returns the Closeness centrality of the given vertex. This is the inverse of the vertex's farness.

    Parameters

    • vertex: string | Vertex

      Vertex, or Vertex ID, to retrieve closeness for.

    Returns number

    Node's "closeness".

    getFarness

  • Calculates "clusters" of nodes (and groups), where a 'cluster' is a set of Nodes/Groups that are connected. Direction of connections is not taken into account. Nodes that are children of Groups are included in all cluster calculations, which might cause some weird situations, but this functionality is mostly intended just for Nodes anyway.

    Returns Cluster[]

    An array of arrays, each entry being a list of nodes in the cluster.

  • Returns the diameter of the Graph.

    Parameters

    • OptionaldontUseMax: boolean

      Whether or not to return Infinity if there is at least one pair of nodes for which there is no available path. Defaults to false.

    Returns number

    Diameter of the Graph.

  • Finds the distance between source and target.

    Parameters

    • source: Vertex

      Source vertex or vertex ID.

    • target: Vertex

      Target vertex or vertex ID.

    • Optionalstrict: boolean

      Defauls to true. Sets whether or not paths are searched strictly by the given source/target. If, for instance, you supply a node as the source, but there are only edges connected to ports on that node, by default these edges will be ignored. Switching strict to false will mean these edges are considered.

    Returns number

    Distance from the source to the target.

  • Gets an Edge by id, or if the given object is already an Edge, hands that back.

    Parameters

    • e: any

      ID of the Edge to retrieve, or an actual Edge, or some data from which an ID could be derived.

    Returns Edge

    The requested Edge, if found, otherwise null.

  • Returns the total number of Edges in the graph.

    Returns number

    The total number of Edges.

  • For some given node, get a subset of edges that match the given filter function.

    Parameters

    • Optionalparams: {
          filter?: ((e: Edge) => boolean);
          node?: string | Vertex;
          source?: boolean;
          target?: boolean;
      }

      Method parameters

      • Optionalfilter?: ((e: Edge) => boolean)

        Optional edge filter.

          • (e): boolean
          • Parameters

            Returns boolean

      • Optionalnode?: string | Vertex
      • Optionalsource?: boolean

        If true, only match edges for which this node is the source.

      • Optionaltarget?: boolean

        If true, only match edges for which this node is the target.

    Returns Edge[]

  • Returns the farness centrality of the given node, ie. the sum of its distance from all other nodes, where the distance from one vertex to another is given by the associated cost of the Edge joining the two nodes.

    Parameters

    • vertex: string | Vertex

      Vertex, or Vertex ID, to retrieve farness for.

    Returns number

    Vertex's "farness".

  • Returns the Group at the given index.

    Parameters

    • idx: number

      Index into group list

    Returns Group

    a Group, or null if not found.

  • Gets the Groups in the graph.

    Returns Group[]

    All the groups in the Graph.

  • Returns the indegree centrality of the given vertex (number of connections entering the vertex)

    Parameters

    • vertex: string | Vertex

      Vertex, or Vertex ID, to retrieve indegree centrality for.

    Returns number

    Vertex's indegree centrality.

  • Returns the outdegree centrality of the given vertex (number of connections exiting the vertex)

    Parameters

    • vertex: string | Vertex

      Vertex, or Vertex ID, to retrieve outdegree centrality for.

    Returns number

    Vertex's indegree centrality.

  • Gets the current port separator.

    Returns string

    Port separator string. Default is "."

  • Gets the type for some data, by running it through the current typeFunction.

    Parameters

    Returns string

    The calculated type for the given object.

  • Returns the vertex at the given index (used for bulk init type purposes)

    Parameters

    • index: number

      Index of the Node to retrieve

    Returns Node

    vertex at the given index.

  • Looks up a vertex identified by the port id, which is in full port id (vertexId.portId) format, returning null if nothing found. (Note that we show full port id format as vertexId.portId, but the '.' is just the default portSeparator; it is possible to change that to some other character)

    Parameters

    • portId: string

      ID of the port to find a vertex for.

    Returns Vertex

  • Gets the count of nodes in the Graph.

    Returns number

  • Gets all the nodes in the Graph.

    Returns Node[]

  • Returns whether or not possibleAncestor is in fact an ancestor of the given focus node/group/port

    Parameters

    Returns boolean

  • This is the original serialize method, which writes out ports, unnecessarily. From 6.12.0 onwards the serializer does not write out ports, but you can - for the time being - use an export type of LEGACY_JSON to invoke this method.

    Returns any

  • Returns the path from source to target as a string.

    Parameters

    Returns string

    Printed path. Mostly useful for debugging.

  • Serialize the graph.

    Returns any

  • Sets whether or not Nodes are Graphs themselves, and can have child Nodes. If you enable this then you cannot use slashes (/) in your Node ids, as they will be treated as components of a path to a Node in a nested Graph.

    Parameters

    • enable: boolean

      True to enable, false to disable.

    Returns void

  • Sets the character(s) used to separate ports from nodes in port ids. By default this is '.', ie a port is addressed as nodeId.portId. This may need to be changed depending on the data in your model.

    Parameters

    • separator: string

      Separator to use.

    Returns void

  • Sets the source Group/Node/Port for some Edge.

    Parameters

    • edge: Edge

      The Edge to change the source for

    • o: string | Vertex

      Group/Node/Port or id for new Edge source

    Returns {
        edge?: Edge;
        new?: Vertex;
        old?: Vertex;
        success: boolean;
    }

  • Sets the target Group/Node/Port for some Edge.

    Parameters

    • edge: Edge

      The Edge to change the target for

    • o: string | Vertex

      group/Node/Port/id for new Edge target

    Returns {
        edge?: Edge;
        new?: Vertex;
        old?: Vertex;
        success: boolean;
    }

  • Splits the given port id using the current portSeparator.

    Parameters

    • portId: string

      Port ID to split.

    Returns string[]

    An array of [ vertexId, portId], or [] if the portId was null.

Version :