Skip to content

Commit

Permalink
fix for directed edges by using nx.DiGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
erdogant committed Apr 2, 2022
1 parent fe2a1b1 commit 9d5ee8f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion d3graph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

__author__ = 'Erdogan Tasksen'
__email__ = '[email protected]'
__version__ = '2.0.3'
__version__ = '2.0.4'

import jinja2
if version.parse(jinja2.__version__) > version.parse("2.11.3"):
Expand Down
9 changes: 6 additions & 3 deletions d3graph/d3graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ def edges2G(edge_properties, G=None):
"""
# Create new graph G
if G is None:
G = nx.Graph()
# G = nx.Graph()
G = nx.DiGraph()
edges = [*edge_properties]
# Create edges in graph
for edge in edges:
Expand All @@ -670,7 +671,8 @@ def nodes2G(node_properties, G=None):
"""
# Create new graph G
if G is None:
G = nx.Graph()
# G = nx.Graph()
G = nx.DiGraph()
# Get node properties
node_properties = pd.DataFrame(node_properties).T
# Store node properties in Graph
Expand Down Expand Up @@ -703,7 +705,8 @@ def make_graph(node_properties, edge_properties):
"""
# Create new Graph
G = nx.Graph()
# G = nx.Graph()
G = nx.DiGraph()
# Add edges to graph
G = edges2G(edge_properties, G=G)
# Add nodes to graph
Expand Down
31 changes: 24 additions & 7 deletions d3graph/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
from d3graph import d3graph


# %% Convert source-target to adjmat
from d3graph import d3graph, vec2adjmat
source = ['Penny', 'Penny', 'Amy', 'Bernadette', 'Bernadette', 'Sheldon', 'Sheldon', 'Sheldon', 'Rajesh']
target = ['Leonard', 'Amy', 'Bernadette', 'Rajesh', 'Howard', 'Howard', 'Leonard', 'Amy', 'Penny']
adjmat = vec2adjmat(source, target)
d3 = d3graph()
print(d3.config)

d3.graph(adjmat)
# d3.show(showfig=True)

d3.set_edge_properties(directed=False, edge_distance_minmax=[5, 30])
d3.show(showfig=True)


# %%
from d3graph import d3graph
d3 = d3graph()
Expand Down Expand Up @@ -45,20 +60,22 @@
# %% Convert source-target to adjmat
from d3graph import d3graph, vec2adjmat

source = ['Penny', 'Penny', 'Amy', 'Bernadette', 'Bernadette', 'Sheldon', 'Sheldon', 'Sheldon', 'Rajesh']
target = ['Leonard', 'Amy', 'Bernadette', 'Rajesh', 'Howard', 'Howard', 'Leonard', 'Amy', 'Penny']
source = ['Penny', 'Penny', 'Amy', 'Bernadette', 'Bernadette', 'Sheldon', 'Sheldon', 'Sheldon', 'Rajesh']
target = ['Leonard', 'Amy', 'Bernadette', 'Rajesh', 'Howard', 'Howard', 'Leonard', 'Amy', 'Penny']
adjmat = vec2adjmat(source, target)
d3 = d3graph()
print(d3.config)

adjmat.iloc[0,0]=2
adjmat.iloc[0,1]=3
adjmat.iloc[0,2]=4
adjmat.iloc[1,3]=12
# adjmat.iloc[0,0]=2
# adjmat.iloc[0,1]=3
# adjmat.iloc[0,2]=4
# adjmat.iloc[1,3]=12

d3.graph(adjmat)
d3.show(showfig=True)
# d3.show(showfig=True)

d3.set_edge_properties(directed=True, edge_distance_minmax=[5, 30])
d3.show(showfig=True)



Expand Down

0 comments on commit 9d5ee8f

Please sign in to comment.