d3graph 2.4.3__tar.gz → 2.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {d3graph-2.4.3/d3graph.egg-info → d3graph-2.4.4}/PKG-INFO +2 -6
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph/__init__.py +1 -1
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph/d3graph.py +71 -7
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph/d3js/d3graphscript.js +18 -2
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph/examples.py +48 -8
- {d3graph-2.4.3 → d3graph-2.4.4/d3graph.egg-info}/PKG-INFO +2 -6
- {d3graph-2.4.3 → d3graph-2.4.4}/LICENSE +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/MANIFEST.in +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/README.md +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph/adjmat_vec.py +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph/d3js/__init__.py +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph/d3js/d3.v3.js +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph/d3js/index.html.j2 +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph/d3js/style.css +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph.egg-info/SOURCES.txt +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph.egg-info/dependency_links.txt +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph.egg-info/requires.txt +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/d3graph.egg-info/top_level.txt +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/setup.cfg +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/setup.py +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/tests/__init__.py +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/tests/conftest.py +0 -0
- {d3graph-2.4.3 → d3graph-2.4.4}/tests/test_d3graph.py +0 -0
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: d3graph
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.4
|
|
4
4
|
Summary: Python package to create interactive network based on d3js.
|
|
5
5
|
Home-page: https://erdogant.github.io/d3graph
|
|
6
|
-
Download-URL: https://github.com/erdogant/d3graph/archive/2.4.
|
|
6
|
+
Download-URL: https://github.com/erdogant/d3graph/archive/2.4.4.tar.gz
|
|
7
7
|
Author: Erdogan Taskesen
|
|
8
8
|
Author-email: erdogant@gmail.com
|
|
9
|
-
License: UNKNOWN
|
|
10
|
-
Platform: UNKNOWN
|
|
11
9
|
Classifier: Programming Language :: Python :: 3
|
|
12
10
|
Classifier: License :: OSI Approved :: BSD License
|
|
13
11
|
Classifier: Operating System :: OS Independent
|
|
@@ -121,5 +119,3 @@ Please cite d3graph in your publications if this is useful for your research. Se
|
|
|
121
119
|
* Erdogan Taskesen, github: [erdogant](https://github.com/erdogant)
|
|
122
120
|
* Contributions are welcome.
|
|
123
121
|
* If you wish to buy me a <a href="https://erdogant.github.io/donate/?currency=USD&amount=5">Coffee</a> for this work, it is very appreciated :)
|
|
124
|
-
|
|
125
|
-
|
|
@@ -193,7 +193,17 @@ class d3graph:
|
|
|
193
193
|
if os.path.isfile(file_location):
|
|
194
194
|
webbrowser.open(file_location, new=2)
|
|
195
195
|
|
|
196
|
-
def set_edge_properties(self,
|
|
196
|
+
def set_edge_properties(self,
|
|
197
|
+
edge_distance: int = None,
|
|
198
|
+
scaler: str = 'zscore',
|
|
199
|
+
minmax: List[float] = None,
|
|
200
|
+
directed: bool = False,
|
|
201
|
+
marker_start=None,
|
|
202
|
+
marker_end='arrow',
|
|
203
|
+
marker_color='#808080',
|
|
204
|
+
label: str = None,
|
|
205
|
+
label_color = '#808080',
|
|
206
|
+
label_fontsize : int = 8) -> dict:
|
|
197
207
|
"""Edge properties.
|
|
198
208
|
|
|
199
209
|
Parameters
|
|
@@ -219,6 +229,15 @@ class d3graph:
|
|
|
219
229
|
marker_end : (list of) str, (default: 'arrow')
|
|
220
230
|
The end of the edge can be one of the following markers:
|
|
221
231
|
'arrow','square','circle','stub',None or ''
|
|
232
|
+
marker_color : str, (default: '#808080')
|
|
233
|
+
The label color in hex.
|
|
234
|
+
label : str, (default: '')
|
|
235
|
+
The edge label.
|
|
236
|
+
label_color : str, (default: None)
|
|
237
|
+
The label color in hex.
|
|
238
|
+
None : Inherits the color from marker_color.
|
|
239
|
+
label_fontsize : int, (default: 8)
|
|
240
|
+
The fontsize of the label.
|
|
222
241
|
|
|
223
242
|
Returns
|
|
224
243
|
-------
|
|
@@ -229,8 +248,7 @@ class d3graph:
|
|
|
229
248
|
'color': color of the edge
|
|
230
249
|
|
|
231
250
|
"""
|
|
232
|
-
if minmax is None:
|
|
233
|
-
minmax = [0.5, 15.0]
|
|
251
|
+
if minmax is None: minmax = [0.5, 15.0]
|
|
234
252
|
self.config['directed'] = directed
|
|
235
253
|
self.config['edge_distance'] = 30 if edge_distance is None else edge_distance
|
|
236
254
|
self.config['minmax'] = minmax
|
|
@@ -239,6 +257,8 @@ class d3graph:
|
|
|
239
257
|
self.config['marker_end'] = marker_end
|
|
240
258
|
self.config['marker_color'] = marker_color
|
|
241
259
|
self.config['label'] = label
|
|
260
|
+
self.config['label_color'] = label_color
|
|
261
|
+
self.config['label_fontsize'] = label_fontsize
|
|
242
262
|
|
|
243
263
|
if (not directed) and (marker_end is not None) or (marker_start is not None):
|
|
244
264
|
logger.info('Set directed=True to see the markers!')
|
|
@@ -253,6 +273,8 @@ class d3graph:
|
|
|
253
273
|
marker_end=self.config['marker_end'],
|
|
254
274
|
marker_color=self.config['marker_color'],
|
|
255
275
|
label=self.config['label'],
|
|
276
|
+
label_color=self.config['label_color'],
|
|
277
|
+
label_fontsize=self.config['label_fontsize'],
|
|
256
278
|
)
|
|
257
279
|
|
|
258
280
|
logger.debug('Number of edges: %.0d', len(self.edge_properties.keys()))
|
|
@@ -796,6 +818,8 @@ def json_create(G: nx.Graph) -> str:
|
|
|
796
818
|
links[i]['marker_end'] = links[i]['marker_end']
|
|
797
819
|
links[i]['marker_color'] = links[i]['marker_color']
|
|
798
820
|
links[i]['label'] = links[i]['label']
|
|
821
|
+
links[i]['label_color'] = links[i]['label_color']
|
|
822
|
+
links[i]['label_fontsize'] = links[i]['label_fontsize']
|
|
799
823
|
links_new.append(links[i])
|
|
800
824
|
nodes = pd.DataFrame([*G.nodes.values()]).T.to_dict()
|
|
801
825
|
nodes_new = [None] * len(nodes)
|
|
@@ -816,7 +840,17 @@ def json_create(G: nx.Graph) -> str:
|
|
|
816
840
|
|
|
817
841
|
|
|
818
842
|
# %% Convert adjacency matrix to vector
|
|
819
|
-
def adjmat2dict(adjmat: pd.DataFrame,
|
|
843
|
+
def adjmat2dict(adjmat: pd.DataFrame,
|
|
844
|
+
min_weight: float = 0.0,
|
|
845
|
+
scaler: str = 'zscore',
|
|
846
|
+
minmax=None,
|
|
847
|
+
marker_start=None,
|
|
848
|
+
marker_end='arrow',
|
|
849
|
+
marker_color='#808080',
|
|
850
|
+
label=None,
|
|
851
|
+
label_color='#808080',
|
|
852
|
+
label_fontsize: int = 8,
|
|
853
|
+
) -> dict:
|
|
820
854
|
"""Convert adjacency matrix into vector with source and target.
|
|
821
855
|
|
|
822
856
|
Parameters
|
|
@@ -833,6 +867,21 @@ def adjmat2dict(adjmat: pd.DataFrame, min_weight: float = 0.0, scaler: str = 'zs
|
|
|
833
867
|
minmax : tuple(int,int), (default: [0.5, 15])
|
|
834
868
|
Weights are normalized between minimum and maximum
|
|
835
869
|
* [0.5, 15]
|
|
870
|
+
marker_start : (list of) str, (default: 'arrow')
|
|
871
|
+
The start of the edge can be one of the following markers:
|
|
872
|
+
'arrow','square','circle','stub',None or ''
|
|
873
|
+
marker_end : (list of) str, (default: 'arrow')
|
|
874
|
+
The end of the edge can be one of the following markers:
|
|
875
|
+
'arrow','square','circle','stub',None or ''
|
|
876
|
+
marker_color : str, (default: '#808080')
|
|
877
|
+
The label color in hex.
|
|
878
|
+
label : str, (default: None)
|
|
879
|
+
The edge label.
|
|
880
|
+
label_color : str, (default: None)
|
|
881
|
+
The label color in hex.
|
|
882
|
+
None : Inherits the color from marker_color.
|
|
883
|
+
label_fontsize : int, (default: 8)
|
|
884
|
+
The fontsize of the label.
|
|
836
885
|
|
|
837
886
|
Returns
|
|
838
887
|
-------
|
|
@@ -845,11 +894,12 @@ def adjmat2dict(adjmat: pd.DataFrame, min_weight: float = 0.0, scaler: str = 'zs
|
|
|
845
894
|
'marker_end': '', 'circle', 'square', 'arrow', 'stub'
|
|
846
895
|
'marker_color': hex color of the marker.
|
|
847
896
|
'label': Text label for the edge.
|
|
897
|
+
'label_color': color of the label.
|
|
898
|
+
'label_fontsize': fontsize of the label.
|
|
848
899
|
|
|
849
900
|
"""
|
|
850
901
|
# Convert adjacency matrix into vector
|
|
851
|
-
if minmax is None:
|
|
852
|
-
minmax = [0.5, 15]
|
|
902
|
+
if minmax is None: minmax = [0.5, 15]
|
|
853
903
|
df = adjmat.stack().reset_index()
|
|
854
904
|
# Set columns
|
|
855
905
|
df.columns = ['source', 'target', 'weight']
|
|
@@ -873,10 +923,14 @@ def adjmat2dict(adjmat: pd.DataFrame, min_weight: float = 0.0, scaler: str = 'zs
|
|
|
873
923
|
if marker_start is None: marker_start=''
|
|
874
924
|
if marker_end is None: marker_end=''
|
|
875
925
|
if label is None: label=''
|
|
926
|
+
|
|
927
|
+
# Store in dataframe
|
|
876
928
|
df['marker_start']=marker_start
|
|
877
929
|
df['marker_end']=marker_end
|
|
878
930
|
df['marker_color']=marker_color
|
|
879
931
|
df['label']=label
|
|
932
|
+
df['label_color']=label_color
|
|
933
|
+
df['label_fontsize']=label_fontsize
|
|
880
934
|
|
|
881
935
|
# Creation dictionary
|
|
882
936
|
source_target = list(zip(df['source'], df['target']))
|
|
@@ -886,7 +940,10 @@ def adjmat2dict(adjmat: pd.DataFrame, min_weight: float = 0.0, scaler: str = 'zs
|
|
|
886
940
|
'color': '#808080', 'marker_start': df['marker_start'].iloc[i],
|
|
887
941
|
'marker_end': df['marker_end'].iloc[i],
|
|
888
942
|
'marker_color': df['marker_color'].iloc[i],
|
|
889
|
-
'label': df['label'].iloc[i]
|
|
943
|
+
'label': df['label'].iloc[i],
|
|
944
|
+
'label_color': df['label_color'].iloc[i],
|
|
945
|
+
'label_fontsize': df['label_fontsize'].iloc[i],
|
|
946
|
+
} for
|
|
890
947
|
i, edge in enumerate(source_target)}
|
|
891
948
|
|
|
892
949
|
|
|
@@ -920,6 +977,8 @@ def edges2G(edge_properties: dict, G: nx.Graph = None) -> nx.Graph:
|
|
|
920
977
|
weight=np.abs(edge_properties[edge]['weight']),
|
|
921
978
|
color=edge_properties[edge]['color'],
|
|
922
979
|
label=edge_properties[edge]['label'],
|
|
980
|
+
label_color=edge_properties[edge]['label_color'],
|
|
981
|
+
label_fontsize=edge_properties[edge]['label_fontsize'],
|
|
923
982
|
)
|
|
924
983
|
return G
|
|
925
984
|
|
|
@@ -985,6 +1044,11 @@ def make_graph(node_properties: dict, edge_properties: dict) -> dict:
|
|
|
985
1044
|
def _normalize_size(getsizes, minscale: Union[int, float] = 0.5, maxscale: Union[int, float] = 4, scaler: str = 'zscore'):
|
|
986
1045
|
# Instead of Min-Max scaling, that shrinks any distribution in the [0, 1] interval, scaling the variables to
|
|
987
1046
|
# Z-scores is better. Min-Max Scaling is too sensitive to outlier observations and generates unseen problems,
|
|
1047
|
+
|
|
1048
|
+
# Set sizes to 0 if not available
|
|
1049
|
+
getsizes[np.isinf(getsizes)]=0
|
|
1050
|
+
getsizes[np.isnan(getsizes)]=0
|
|
1051
|
+
|
|
988
1052
|
# out-of-scale datapoints.
|
|
989
1053
|
if scaler == 'zscore' and len(np.unique(getsizes)) > 3:
|
|
990
1054
|
getsizes = (getsizes.flatten() - np.mean(getsizes)) / np.std(getsizes)
|
|
@@ -64,7 +64,7 @@ function d3graphscript(config = {
|
|
|
64
64
|
.links(graph.links)
|
|
65
65
|
.start();
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
// Create all the line svgs but without locations yet
|
|
68
68
|
var link = svg.selectAll(".link")
|
|
69
69
|
.data(graph.links)
|
|
70
70
|
.enter().append("line")
|
|
@@ -77,6 +77,18 @@ function d3graphscript(config = {
|
|
|
77
77
|
// .style("stroke-width", 1); // WIDTH OF THE LINKS
|
|
78
78
|
;
|
|
79
79
|
|
|
80
|
+
// ADD TEXT ON THE EDGES (PART 1/2)
|
|
81
|
+
var linkText = svg.selectAll(".link-text")
|
|
82
|
+
.data(graph.links)
|
|
83
|
+
.enter().append("text")
|
|
84
|
+
.attr("class", "link-text")
|
|
85
|
+
.attr("font-size", function(d) {return d.label_fontsize + "px";})
|
|
86
|
+
.style("fill", function(d) {return d.label_color;})
|
|
87
|
+
.style("font-family", "Arial")
|
|
88
|
+
//.attr("transform", "rotate(90)")
|
|
89
|
+
.text(function(d) { return d.label; });
|
|
90
|
+
|
|
91
|
+
|
|
80
92
|
//Do the same with the circles for the nodes
|
|
81
93
|
var node = svg.selectAll(".node")
|
|
82
94
|
.data(graph.nodes)
|
|
@@ -121,7 +133,11 @@ function d3graphscript(config = {
|
|
|
121
133
|
d3.selectAll("circle").attr("cx", function(d) { return d.x; })
|
|
122
134
|
.attr("cy", function(d) { return d.y; });
|
|
123
135
|
d3.selectAll("text").attr("x", function(d) { return d.x; })
|
|
124
|
-
.attr("y", function(d) { return d.y; })
|
|
136
|
+
.attr("y", function(d) { return d.y; })
|
|
137
|
+
linkText.attr("x", function(d) { return (d.source.x + d.target.x) / 2; }) // ADD TEXT ON THE EDGES (PART 2/2)
|
|
138
|
+
.attr("y", function(d) { return (d.source.y + d.target.y) / 2; })
|
|
139
|
+
.attr("text-anchor", "middle");
|
|
140
|
+
;
|
|
125
141
|
|
|
126
142
|
node.each(collide(config.collision)); //COLLISION DETECTION. High means a big fight to get untouchable nodes (default=0.5)
|
|
127
143
|
|
|
@@ -6,24 +6,64 @@ from d3graph import d3graph, adjmat2vec
|
|
|
6
6
|
|
|
7
7
|
# %% Edge link
|
|
8
8
|
d3 = d3graph()
|
|
9
|
-
adjmat, df = d3.import_example('
|
|
9
|
+
adjmat, df = d3.import_example('karate')
|
|
10
|
+
d3.graph(adjmat, color='cluster')
|
|
11
|
+
d3.show(filepath=r'c:\temp\\d3graph\d3graph1.html')
|
|
12
|
+
|
|
13
|
+
# %% Edge link
|
|
14
|
+
|
|
15
|
+
# Import
|
|
16
|
+
from d3graph import d3graph
|
|
17
|
+
# intialize to load example dataset
|
|
18
|
+
d3 = d3graph()
|
|
19
|
+
adjmat, _ = d3.import_example('bigbang')
|
|
20
|
+
|
|
21
|
+
# Initialize with clustering colors
|
|
10
22
|
d3.graph(adjmat, color='cluster')
|
|
11
|
-
d3.set_edge_properties(directed=True, marker_end='square', marker_color='#000000', label='TEST')
|
|
12
23
|
|
|
24
|
+
# Set all edge labels to "test"
|
|
25
|
+
d3.set_edge_properties(directed=True, label='test')
|
|
26
|
+
d3.show(filepath=r'c:\temp\\d3graph\edge_labels_1.html')
|
|
27
|
+
|
|
28
|
+
# Set edge labels
|
|
13
29
|
d3.edge_properties
|
|
14
|
-
|
|
30
|
+
|
|
31
|
+
# We will first set all label properties to None and then we will adjust two of them
|
|
32
|
+
d3.set_edge_properties(directed=True, marker_color='#000FFF', label=None)
|
|
33
|
+
d3.edge_properties['Amy', 'Bernadette']['weight_scaled']=10
|
|
34
|
+
d3.edge_properties['Amy', 'Bernadette']['label']='amy-bern'
|
|
35
|
+
d3.edge_properties['Amy', 'Bernadette']['label_color']='#000FFF'
|
|
36
|
+
d3.edge_properties['Amy', 'Bernadette']['label_fontsize']=8
|
|
37
|
+
d3.edge_properties['Bernadette', 'Howard']['label']='bern-how'
|
|
38
|
+
d3.edge_properties['Bernadette', 'Howard']['label_fontsize']=20
|
|
39
|
+
d3.edge_properties['Bernadette', 'Howard']['label_color']='#000000'
|
|
40
|
+
|
|
41
|
+
d3.show(filepath=r'c:\temp\\d3graph\edge_labels_2.html')
|
|
15
42
|
|
|
16
43
|
# %% Change color of text
|
|
44
|
+
|
|
45
|
+
# Import library
|
|
17
46
|
from d3graph import d3graph
|
|
18
47
|
|
|
48
|
+
# Initialize with defaults
|
|
19
49
|
d3 = d3graph()
|
|
20
|
-
adjmat, df = d3.import_example('bigbang')
|
|
21
|
-
d3.graph(adjmat, color='cluster')
|
|
22
|
-
d3.set_node_properties(color='cluster', scaler='minmax', fontcolor='node_color', fontsize=12)
|
|
23
|
-
d3.show(filepath=r'c:\temp\\d3graph\d3graph.html', click={'fill': 'black'})
|
|
24
|
-
d3.show(filepath=r'c:\temp\\d3graph\d3graph.html')
|
|
25
50
|
|
|
51
|
+
# Load example
|
|
52
|
+
adjmat, df = d3.import_example('bigbang')
|
|
53
|
+
# Color on clustering
|
|
54
|
+
d3.graph(adjmat)
|
|
26
55
|
fontsize=np.random.randint(low=6, high=40, size=adjmat.shape[0])
|
|
56
|
+
|
|
57
|
+
# Set some node properties
|
|
58
|
+
d3.set_node_properties(color='cluster', scaler='minmax', fontcolor='node_color')
|
|
59
|
+
|
|
60
|
+
# Set the click properties: Create green node on click with black border
|
|
61
|
+
d3.show(filepath=r'c:\temp\\d3graph\click_example_1.html', click={'fill': '#00FF00', 'stroke': '#000000'})
|
|
62
|
+
|
|
63
|
+
# Keep the original color but set the stroke to grey and increase both node size and stroke width
|
|
64
|
+
d3.show(filepath=r'c:\temp\\d3graph\click_example_2.html', click={'fill': None, 'stroke': '#F0F0F0', 'size': 2.5, 'stroke-width': 10})
|
|
65
|
+
|
|
66
|
+
|
|
27
67
|
d3.set_node_properties(color='cluster', scaler='minmax', fontcolor='node_color', fontsize=fontsize)
|
|
28
68
|
d3.show(filepath=r'c:\temp\\d3graph\d3graph.html')
|
|
29
69
|
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: d3graph
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.4
|
|
4
4
|
Summary: Python package to create interactive network based on d3js.
|
|
5
5
|
Home-page: https://erdogant.github.io/d3graph
|
|
6
|
-
Download-URL: https://github.com/erdogant/d3graph/archive/2.4.
|
|
6
|
+
Download-URL: https://github.com/erdogant/d3graph/archive/2.4.4.tar.gz
|
|
7
7
|
Author: Erdogan Taskesen
|
|
8
8
|
Author-email: erdogant@gmail.com
|
|
9
|
-
License: UNKNOWN
|
|
10
|
-
Platform: UNKNOWN
|
|
11
9
|
Classifier: Programming Language :: Python :: 3
|
|
12
10
|
Classifier: License :: OSI Approved :: BSD License
|
|
13
11
|
Classifier: Operating System :: OS Independent
|
|
@@ -121,5 +119,3 @@ Please cite d3graph in your publications if this is useful for your research. Se
|
|
|
121
119
|
* Erdogan Taskesen, github: [erdogant](https://github.com/erdogant)
|
|
122
120
|
* Contributions are welcome.
|
|
123
121
|
* If you wish to buy me a <a href="https://erdogant.github.io/donate/?currency=USD&amount=5">Coffee</a> for this work, it is very appreciated :)
|
|
124
|
-
|
|
125
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|