Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 32 lines (21 sloc) 0.862 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
from . import interface
import networkx as nx
from traits.api import HasTraits, Instance
from traits.api import DelegatesTo
from traits.has_traits import implements
from ._abstract import AbstractGraph


class NxGraph(AbstractGraph):
    implements(interface.IGraph)


    nx_graph = Instance(nx.Graph, allow_none=False)

    number_of_nodes = DelegatesTo('nx_graph')
    number_of_edges = DelegatesTo('nx_graph')



    def __init__(self, graph_type=nx.Graph, data=None, **kwargs):
        self.nx_graph = graph_type(data=data, **kwargs)

    def add_node(self):
        node_index = self.index_store.take()
        self.nx_graph.add_node(node_index)
        return node_index

    def add_edge(self, source, target):
        self.nx_graph.add_edge(source, target)

    def remove_edge(self, source, target):
        self.nx_graph.remove_edge(source, target)
Something went wrong with that request. Please try again.