topologicpy 0.8.23__py3-none-any.whl → 0.8.25__py3-none-any.whl
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.
- topologicpy/Graph.py +768 -37
- topologicpy/version.py +1 -1
- {topologicpy-0.8.23.dist-info → topologicpy-0.8.25.dist-info}/METADATA +1 -1
- {topologicpy-0.8.23.dist-info → topologicpy-0.8.25.dist-info}/RECORD +7 -7
- {topologicpy-0.8.23.dist-info → topologicpy-0.8.25.dist-info}/WHEEL +1 -1
- {topologicpy-0.8.23.dist-info → topologicpy-0.8.25.dist-info}/licenses/LICENSE +0 -0
- {topologicpy-0.8.23.dist-info → topologicpy-0.8.25.dist-info}/top_level.txt +0 -0
topologicpy/Graph.py
CHANGED
@@ -65,6 +65,20 @@ except:
|
|
65
65
|
except:
|
66
66
|
warnings.warn("Graph - Error: Could not import tqdm.")
|
67
67
|
|
68
|
+
try:
|
69
|
+
from graphviz import Digraph
|
70
|
+
except:
|
71
|
+
print("Graph - Installing required graphviz library.")
|
72
|
+
try:
|
73
|
+
os.system("pip install graphviz")
|
74
|
+
except:
|
75
|
+
os.system("pip install graphviz --user")
|
76
|
+
try:
|
77
|
+
from graphviz import Digraph
|
78
|
+
print("Graph - graphviz library installed correctly.")
|
79
|
+
except:
|
80
|
+
warnings.warn("Graph - Error: Could not import graphviz.")
|
81
|
+
|
68
82
|
GraphQueueItem = namedtuple('GraphQueueItem', ['edges'])
|
69
83
|
|
70
84
|
class WorkerProcessPool(object):
|
@@ -264,6 +278,93 @@ class _DrawTree(object):
|
|
264
278
|
return self.__str__()
|
265
279
|
|
266
280
|
class Graph:
|
281
|
+
|
282
|
+
@staticmethod
|
283
|
+
def AccessibilityCentrality(graph, step: int = 2, normalize: bool = False, key: str = "accessibility_centrality", colorKey: str = "ac_color", colorScale: str = "viridis", mantissa: int = 6, tolerance: float = 0.0001, silent: bool = False):
|
284
|
+
"""
|
285
|
+
Computes the accessibility centrality of each vertex in the graph using random walks of fixed step length.
|
286
|
+
|
287
|
+
Parameters
|
288
|
+
----------
|
289
|
+
graph : topologic_core.Graph
|
290
|
+
The input graph.
|
291
|
+
step : int, optional
|
292
|
+
The length of the random walk (number of steps). Default is 2.
|
293
|
+
normalize : bool, optional
|
294
|
+
If True, normalize the output to the range 0 to 1. Default is False.
|
295
|
+
key : str, optional
|
296
|
+
Dictionary key to store the accessibility centrality value. Default is "accessibility_centrality".
|
297
|
+
colorKey : str, optional
|
298
|
+
Dictionary key to store the color value. Default is "ac_color".
|
299
|
+
colorScale : str, optional
|
300
|
+
Name of the Plotly color scale to use. Default is "viridis".
|
301
|
+
mantissa : int, optional
|
302
|
+
Decimal precision. Default is 6.
|
303
|
+
tolerance : float, optional
|
304
|
+
The desired Tolerance. Not used here but included for API compatibility. Default is 0.0001.
|
305
|
+
silent : bool, optional
|
306
|
+
If True, suppresses error/warning messages. Default is False.
|
307
|
+
|
308
|
+
Returns
|
309
|
+
-------
|
310
|
+
list
|
311
|
+
A list of accessibility centrality values for each vertex in the graph.
|
312
|
+
"""
|
313
|
+
import numpy as np
|
314
|
+
from topologicpy.Graph import Graph
|
315
|
+
from topologicpy.Topology import Topology
|
316
|
+
from topologicpy.Dictionary import Dictionary
|
317
|
+
from topologicpy.Color import Color
|
318
|
+
from topologicpy.Helper import Helper
|
319
|
+
|
320
|
+
if not Topology.IsInstance(graph, "graph"):
|
321
|
+
if not silent:
|
322
|
+
print("Graph.AccessibilityCentrality - Error: The input graph paramter is not a valid Topologic Graph. Returning None.")
|
323
|
+
return None
|
324
|
+
vertices = Graph.Vertices(graph)
|
325
|
+
n = len(vertices)
|
326
|
+
if n == 0:
|
327
|
+
return []
|
328
|
+
|
329
|
+
# Step 1: get transition matrix (row-normalized adjacency matrix)
|
330
|
+
A = np.array(Graph.AdjacencyMatrix(graph), dtype=float)
|
331
|
+
row_sums = A.sum(axis=1, keepdims=True)
|
332
|
+
row_sums[row_sums == 0] = 1 # prevent division by zero
|
333
|
+
P = A / row_sums
|
334
|
+
|
335
|
+
# Step 2: walk matrix of length `step`
|
336
|
+
P_h = np.linalg.matrix_power(P, step)
|
337
|
+
|
338
|
+
# Step 3: compute entropy-based accessibility for each vertex
|
339
|
+
values = []
|
340
|
+
for i in range(n):
|
341
|
+
probs = P_h[i]
|
342
|
+
probs = probs[probs > 0]
|
343
|
+
entropy = -np.sum(probs * np.log(probs))
|
344
|
+
acc = np.exp(entropy)
|
345
|
+
values.append(float(acc))
|
346
|
+
|
347
|
+
# Optional normalization
|
348
|
+
if normalize == True:
|
349
|
+
if mantissa > 0: # We cannot round numbers from 0 to 1 with a mantissa = 0.
|
350
|
+
values = [round(v, mantissa) for v in Helper.Normalize(values)]
|
351
|
+
else:
|
352
|
+
values = Helper.Normalize(values)
|
353
|
+
min_value = 0
|
354
|
+
max_value = 1
|
355
|
+
else:
|
356
|
+
min_value = min(values)
|
357
|
+
max_value = max(values)
|
358
|
+
|
359
|
+
# Assign Values and Colors to Dictionaries
|
360
|
+
for i, value in enumerate(values):
|
361
|
+
d = Topology.Dictionary(vertices[i])
|
362
|
+
color = Color.AnyToHex(Color.ByValueInRange(value, minValue=min_value, maxValue=max_value, colorScale=colorScale))
|
363
|
+
d = Dictionary.SetValuesAtKeys(d, [key, colorKey], [value, color])
|
364
|
+
vertices[i] = Topology.SetDictionary(vertices[i], d)
|
365
|
+
|
366
|
+
return values
|
367
|
+
|
267
368
|
@staticmethod
|
268
369
|
def AddEdge(graph, edge, transferVertexDictionaries: bool = False, transferEdgeDictionaries: bool = False, tolerance: float = 0.0001, silent: bool = False):
|
269
370
|
"""
|
@@ -1417,7 +1518,7 @@ class Graph:
|
|
1417
1518
|
from topologicpy.Helper import Helper
|
1418
1519
|
|
1419
1520
|
if weightKey:
|
1420
|
-
if "len" in weightKey.lower() or "dis" in
|
1521
|
+
if "len" in weightKey.lower() or "dis" in weightKey.lower():
|
1421
1522
|
weightKey = "length"
|
1422
1523
|
nx_graph = Graph.NetworkXGraph(graph)
|
1423
1524
|
if "vert" in method.lower():
|
@@ -4379,12 +4480,14 @@ class Graph:
|
|
4379
4480
|
|
4380
4481
|
@staticmethod
|
4381
4482
|
def Compare(graphA, graphB,
|
4483
|
+
weightAccessibilityCentrality: float = 0.0,
|
4382
4484
|
weightAttributes: float = 0.0,
|
4383
4485
|
weightGeometry: float = 0.0,
|
4384
4486
|
weightBetwennessCentrality: float = 0.0,
|
4385
4487
|
weightClosenessCentrality: float = 0.0,
|
4386
4488
|
weightDegreeCentrality: float = 0.0,
|
4387
4489
|
weightDiameter: float = 0.0,
|
4490
|
+
weightEigenCentrality: float = 0.0,
|
4388
4491
|
weightGlobalClusteringCoefficient: float = 0.0,
|
4389
4492
|
weightPageRank: float = 0.0,
|
4390
4493
|
weightStructure: float = 0.0,
|
@@ -4406,6 +4509,8 @@ class Graph:
|
|
4406
4509
|
The first input graph.
|
4407
4510
|
graphB : topologic Graph
|
4408
4511
|
The second input graph.
|
4512
|
+
weightAccessibilityCentrality : float , optional
|
4513
|
+
The desired weight for degree accessibility similarity (graph-level and node-level). Default is 0.0.
|
4409
4514
|
weightAttributes : float , optional
|
4410
4515
|
The desired weight for attribute similarity (dictionary key overlap at vertices). Default is 0.0.
|
4411
4516
|
weightBetwennessCentrality : float , optional
|
@@ -4416,6 +4521,8 @@ class Graph:
|
|
4416
4521
|
The desired weight for degree centrality similarity (graph-level and node-level). Default is 0.0.
|
4417
4522
|
weightDiameter : float , optional
|
4418
4523
|
The desired weight for diameter similarity (graph-level and node-level). Default is 0.0.
|
4524
|
+
weightEigenCentrality : float , optional
|
4525
|
+
The desired weight for eigen centrality similarity (graph-level and node-level). Default is 0.0.
|
4419
4526
|
weightGeometry : float , optional
|
4420
4527
|
The desired weight for geometric similarity (vertex positions). Default is 0.0.
|
4421
4528
|
weightGlobalClusteringCoefficient : float , optional
|
@@ -4447,10 +4554,12 @@ class Graph:
|
|
4447
4554
|
dict
|
4448
4555
|
A dictionary of similarity scores between 0 (completely dissimilar) and 1 (identical), based on weighted components.
|
4449
4556
|
The keys in the dictionary are:
|
4557
|
+
"accessibility_centrality"
|
4450
4558
|
"attribute"
|
4451
4559
|
"betwenness_centrality"
|
4452
4560
|
"closeness_centrality"
|
4453
4561
|
"degree_centrality"
|
4562
|
+
"eigen_centrality"
|
4454
4563
|
"geometry"
|
4455
4564
|
"global_clustering_coefficient"
|
4456
4565
|
"jaccard"
|
@@ -4573,6 +4682,14 @@ class Graph:
|
|
4573
4682
|
def safe_mean(lst):
|
4574
4683
|
return sum(lst)/len(lst) if lst else 0
|
4575
4684
|
|
4685
|
+
def accessibility_centrality_similarity(graphA, graphB, mantissa=6):
|
4686
|
+
v1 = safe_mean(Graph.AccessibilityCentrality(graphA))
|
4687
|
+
v2 = safe_mean(Graph.AccessibilityCentrality(graphB))
|
4688
|
+
if v1 == 0 and v2 == 0:
|
4689
|
+
return 1
|
4690
|
+
diff = abs(v1 - v2) / max(abs(v1), abs(v2), 1e-6)
|
4691
|
+
return round((1 - diff), mantissa)
|
4692
|
+
|
4576
4693
|
def betweenness_centrality_similarity(graphA, graphB, mantissa=6):
|
4577
4694
|
v1 = safe_mean(Graph.BetweennessCentrality(graphA))
|
4578
4695
|
v2 = safe_mean(Graph.BetweennessCentrality(graphB))
|
@@ -4605,6 +4722,14 @@ class Graph:
|
|
4605
4722
|
diff = abs(v1 - v2) / max(abs(v1), abs(v2), 1e-6)
|
4606
4723
|
return round((1 - diff), mantissa)
|
4607
4724
|
|
4725
|
+
def eigen_centrality_similarity(graphA, graphB, mantissa=6):
|
4726
|
+
v1 = safe_mean(Graph.EigenCentrality(graphA))
|
4727
|
+
v2 = safe_mean(Graph.EigenCentrality(graphB))
|
4728
|
+
if v1 == 0 and v2 == 0:
|
4729
|
+
return 1
|
4730
|
+
diff = abs(v1 - v2) / max(abs(v1), abs(v2), 1e-6)
|
4731
|
+
return round((1 - diff), mantissa)
|
4732
|
+
|
4608
4733
|
def global_clustering_coefficient_similarity(graphA, graphB, mantissa=6):
|
4609
4734
|
v1 = Graph.GlobalClusteringCoefficient(graphA)
|
4610
4735
|
v2 = Graph.GlobalClusteringCoefficient(graphB)
|
@@ -4675,23 +4800,26 @@ class Graph:
|
|
4675
4800
|
print("Graph.Compare - Error: The graphB input parameter is not a valid topologic graph. Returning None.")
|
4676
4801
|
return
|
4677
4802
|
|
4678
|
-
total_weight = sum([
|
4803
|
+
total_weight = sum([weightAccessibilityCentrality,
|
4804
|
+
weightAttributes,
|
4679
4805
|
weightGeometry,
|
4680
4806
|
weightBetwennessCentrality,
|
4681
4807
|
weightClosenessCentrality,
|
4682
4808
|
weightDegreeCentrality,
|
4683
4809
|
weightDiameter,
|
4810
|
+
weightEigenCentrality,
|
4684
4811
|
weightGlobalClusteringCoefficient,
|
4685
4812
|
weightPageRank,
|
4686
4813
|
weightStructure,
|
4687
4814
|
weightWeisfeilerLehman,
|
4688
4815
|
weightJaccard])
|
4689
|
-
|
4816
|
+
accessibility_centrality_score = accessibility_centrality_similarity(graphA, graphB, mantissa=mantissa) if weightAccessibilityCentrality else 0
|
4690
4817
|
attribute_score = attribute_similarity(graphA, graphB, mantissa=mantissa) if weightAttributes else 0
|
4691
4818
|
betweenness_centrality_score = betweenness_centrality_similarity(graphA, graphB, mantissa=mantissa) if weightBetwennessCentrality else 0
|
4692
4819
|
closeness_centrality_score = closeness_centrality_similarity(graphA, graphB, mantissa=mantissa) if weightClosenessCentrality else 0
|
4693
4820
|
degree_centrality_score = degree_centrality_similarity(graphA, graphB, mantissa=mantissa) if weightDegreeCentrality else 0
|
4694
4821
|
diameter_score = diameter_similarity(graphA, graphB, mantissa=mantissa) if weightDiameter else 0
|
4822
|
+
eigen_centrality_score = eigen_centrality_similarity(graphA, graphB, mantissa=mantissa) if weightEigenCentrality else 0
|
4695
4823
|
global_clustering_coefficient_score = global_clustering_coefficient_similarity(graphA, graphB, mantissa=mantissa) if weightGlobalClusteringCoefficient else 0
|
4696
4824
|
geometry_score = geometry_similarity(graphA, graphB, mantissa=mantissa) if weightGeometry else 0
|
4697
4825
|
jaccard_score = weighted_jaccard_similarity(graphA, graphB, vertexIDKey=vertexIDKey, edgeWeightKey=edgeWeightKey, mantissa=mantissa) if weightJaccard else 0
|
@@ -4700,11 +4828,13 @@ class Graph:
|
|
4700
4828
|
weisfeiler_lehman_score = weisfeiler_lehman_similarity(graphA, graphB, iterations, mantissa=mantissa) if weightWeisfeilerLehman else 0
|
4701
4829
|
|
4702
4830
|
weighted_sum = (
|
4831
|
+
accessibility_centrality_score * weightAccessibilityCentrality +
|
4703
4832
|
attribute_score * weightAttributes +
|
4704
4833
|
betweenness_centrality_score * weightBetwennessCentrality +
|
4705
4834
|
closeness_centrality_score * weightClosenessCentrality +
|
4706
4835
|
degree_centrality_score * weightDegreeCentrality +
|
4707
4836
|
diameter_score * weightDiameter +
|
4837
|
+
eigen_centrality_score * weightEigenCentrality +
|
4708
4838
|
geometry_score * weightGeometry +
|
4709
4839
|
global_clustering_coefficient_score * weightGlobalClusteringCoefficient +
|
4710
4840
|
jaccard_score * weightJaccard +
|
@@ -4719,10 +4849,12 @@ class Graph:
|
|
4719
4849
|
overall_score = weighted_sum / total_weight
|
4720
4850
|
|
4721
4851
|
return {
|
4852
|
+
"accessibility_centrality": round(accessibility_centrality_score, mantissa),
|
4722
4853
|
"attribute": round(attribute_score, mantissa),
|
4723
4854
|
"betwenness_centrality": round(betweenness_centrality_score, mantissa),
|
4724
4855
|
"closeness_centrality": round(closeness_centrality_score, mantissa),
|
4725
4856
|
"degree_centrality": round(degree_centrality_score, mantissa),
|
4857
|
+
"eigen_centrality": round(eigen_centrality_score, mantissa),
|
4726
4858
|
"geometry": round(geometry_score, mantissa),
|
4727
4859
|
"global_clustering_coefficient": round(global_clustering_coefficient_score, mantissa),
|
4728
4860
|
"jaccard": round(jaccard_score, mantissa),
|
@@ -5073,7 +5205,7 @@ class Graph:
|
|
5073
5205
|
Returns
|
5074
5206
|
-------
|
5075
5207
|
list
|
5076
|
-
The
|
5208
|
+
The closeness centrality of the input list of vertices within the input graph. The values are in the range 0 to 1.
|
5077
5209
|
|
5078
5210
|
"""
|
5079
5211
|
import warnings
|
@@ -5566,7 +5698,7 @@ class Graph:
|
|
5566
5698
|
|
5567
5699
|
"""
|
5568
5700
|
import numpy as np
|
5569
|
-
adj_matrix = Graph.AdjacencyMatrix(
|
5701
|
+
adj_matrix = Graph.AdjacencyMatrix(graph)
|
5570
5702
|
np_adj_matrix = np.array(adj_matrix)
|
5571
5703
|
degree_matrix = np.diag(np_adj_matrix.sum(axis=1))
|
5572
5704
|
return degree_matrix.tolist()
|
@@ -5918,6 +6050,87 @@ class Graph:
|
|
5918
6050
|
_ = graph.Edges(vertices, tolerance, edges) # Hook to Core
|
5919
6051
|
return list(dict.fromkeys(edges)) # remove duplicates
|
5920
6052
|
|
6053
|
+
@staticmethod
|
6054
|
+
def EigenCentrality(graph, normalize: bool = False, key: str = "eigen_centrality", colorKey: str = "ec_color", colorScale: str = "viridis", mantissa: int = 6, tolerance: float = 0.0001, silent: bool = False):
|
6055
|
+
"""
|
6056
|
+
Returns the eigenvector centrality of the input graph. The order of the returned list is the same as the order of vertices.
|
6057
|
+
|
6058
|
+
Parameters
|
6059
|
+
----------
|
6060
|
+
graph : topologic_core.Graph
|
6061
|
+
The input graph.
|
6062
|
+
weightKey : str, optional
|
6063
|
+
Ignored in this implementation. Reserved for future use if weighted adjacency matrix is desired.
|
6064
|
+
normalize : bool, optional
|
6065
|
+
If set to True, the centrality values are normalized to be in the range 0 to 1. The default is False.
|
6066
|
+
key : str, optional
|
6067
|
+
The desired dictionary key under which to store the eigenvector centrality score. The default is "eigen_centrality".
|
6068
|
+
colorKey : str, optional
|
6069
|
+
The desired dictionary key under which to store the eigenvector centrality color. The default is "ec_color".
|
6070
|
+
colorScale : str, optional
|
6071
|
+
The desired type of Plotly color scale to use (e.g., "viridis", "plasma"). Default is "viridis".
|
6072
|
+
For a full list of names, see https://plotly.com/python/builtin-colorscales/.
|
6073
|
+
Also supports color-blind friendly scales: "protanopia", "deuteranopia", "tritanopia".
|
6074
|
+
mantissa : int, optional
|
6075
|
+
The desired length of the mantissa. Default is 6.
|
6076
|
+
tolerance : float, optional
|
6077
|
+
The convergence tolerance for the power method. Default is 0.0001.
|
6078
|
+
silent : bool, optional
|
6079
|
+
If set to True, suppresses all messaging and warnings. Default is False.
|
6080
|
+
|
6081
|
+
Returns
|
6082
|
+
-------
|
6083
|
+
list
|
6084
|
+
A list of eigenvector centrality values corresponding to the vertices in the input graph.
|
6085
|
+
"""
|
6086
|
+
import numpy as np
|
6087
|
+
from topologicpy.Graph import Graph
|
6088
|
+
from topologicpy.Topology import Topology
|
6089
|
+
from topologicpy.Dictionary import Dictionary
|
6090
|
+
from topologicpy.Color import Color
|
6091
|
+
from topologicpy.Helper import Helper
|
6092
|
+
|
6093
|
+
if not Topology.IsInstance(graph, "graph"):
|
6094
|
+
if not silent:
|
6095
|
+
print("Graph.EigenCentrality - Error: The input graph is not a valie Topologic Graph. Returning None.")
|
6096
|
+
return None
|
6097
|
+
adjacency_matrix = Graph.AdjacencyMatrix(graph)
|
6098
|
+
vertices = Graph.Vertices(graph)
|
6099
|
+
n = len(vertices)
|
6100
|
+
if n == 0:
|
6101
|
+
return []
|
6102
|
+
|
6103
|
+
values = np.ones(n)
|
6104
|
+
for _ in range(100):
|
6105
|
+
x_new = np.dot(adjacency_matrix, values)
|
6106
|
+
norm = np.linalg.norm(x_new)
|
6107
|
+
if norm == 0:
|
6108
|
+
break
|
6109
|
+
x_new = x_new / norm
|
6110
|
+
if np.linalg.norm(values - x_new) < tolerance:
|
6111
|
+
break
|
6112
|
+
values = x_new
|
6113
|
+
values = [float(x) for x in values]
|
6114
|
+
if normalize == True:
|
6115
|
+
if mantissa > 0: # We cannot round numbers from 0 to 1 with a mantissa = 0.
|
6116
|
+
values = [round(v, mantissa) for v in Helper.Normalize(values)]
|
6117
|
+
else:
|
6118
|
+
values = Helper.Normalize(values)
|
6119
|
+
min_value = 0
|
6120
|
+
max_value = 1
|
6121
|
+
else:
|
6122
|
+
values = [round(v, mantissa) for v in values]
|
6123
|
+
min_value = min(values)
|
6124
|
+
max_value = max(values)
|
6125
|
+
|
6126
|
+
for i, value in enumerate(values):
|
6127
|
+
d = Topology.Dictionary(vertices[i])
|
6128
|
+
color = Color.AnyToHex(Color.ByValueInRange(value, minValue=min_value, maxValue=max_value, colorScale=colorScale))
|
6129
|
+
d = Dictionary.SetValuesAtKeys(d, [key, colorKey], [value, color])
|
6130
|
+
vertices[i] = Topology.SetDictionary(vertices[i], d)
|
6131
|
+
|
6132
|
+
return values
|
6133
|
+
|
5921
6134
|
@staticmethod
|
5922
6135
|
def ExportToAdjacencyMatrixCSV(adjacencyMatrix, path):
|
5923
6136
|
"""
|
@@ -6125,7 +6338,7 @@ class Graph:
|
|
6125
6338
|
format = "turtle"
|
6126
6339
|
ext = ".ttl"
|
6127
6340
|
n = len(ext)
|
6128
|
-
# Make sure the file extension is .
|
6341
|
+
# Make sure the file extension is .bot
|
6129
6342
|
ext = path[len(path)-n:len(path)]
|
6130
6343
|
if ext.lower() != ext:
|
6131
6344
|
path = path+ext
|
@@ -6674,7 +6887,7 @@ class Graph:
|
|
6674
6887
|
if not isinstance(path, str):
|
6675
6888
|
print("Graph.ExportToGEXF - Error: the input path parameter is not a valid string. Returning None.")
|
6676
6889
|
return None
|
6677
|
-
# Make sure the file extension is .
|
6890
|
+
# Make sure the file extension is .gexf
|
6678
6891
|
ext = path[len(path)-5:len(path)]
|
6679
6892
|
if ext.lower() != ".gexf":
|
6680
6893
|
path = path+".gexf"
|
@@ -6869,6 +7082,243 @@ class Graph:
|
|
6869
7082
|
create_gexf_file(nodes, edges, defaultEdgeType, node_attributes, edge_attributes, path)
|
6870
7083
|
return True
|
6871
7084
|
|
7085
|
+
@staticmethod
|
7086
|
+
def ExportToGraphVizGraph(graph,
|
7087
|
+
path,
|
7088
|
+
device = 'svg_inline', deviceKey=None,
|
7089
|
+
scale = 1, scaleKey=None,
|
7090
|
+
directed=False, directedKey=None,
|
7091
|
+
layout = 'dot', # or circo fdp neato nop nop1 nop2 osage patchwork sfdp twopi
|
7092
|
+
layoutKey=None,
|
7093
|
+
rankDir='TB', rankDirKey=None, # or LR, RL, BT
|
7094
|
+
bgColor='white', bgColorKey=None,
|
7095
|
+
fontName='Arial', fontNameKey=None,
|
7096
|
+
fontSize= 12, fontSizeKey=None,
|
7097
|
+
vertexSep= 0.5, vertexSepKey=None,
|
7098
|
+
rankSep= 0.5, rankSepKey=None,
|
7099
|
+
splines='True', splinesKey=None,
|
7100
|
+
showGraphLabel = False,
|
7101
|
+
graphLabel='', graphLabelKey=None,
|
7102
|
+
graphLabelLoc='t', graphLabelLocKey=None,
|
7103
|
+
showVertexLabel = False,
|
7104
|
+
vertexLabelPrefix='' , vertexLabelKey=None,
|
7105
|
+
vertexWidth=0.5, vertexWidthKey=None,
|
7106
|
+
vertexHeight=0.5, vertexHeightKey=None,
|
7107
|
+
vertexFixedSize=False, vertexFixedSizeKey=None,
|
7108
|
+
vertexShape='circle', vertexShapeKey=None,
|
7109
|
+
vertexStyle='filled', vertexStyleKey=None,
|
7110
|
+
vertexFillColor='lightgray', vertexFillColorKey=None,
|
7111
|
+
vertexColor='black', vertexColorKey=None,
|
7112
|
+
vertexFontColor='black', vertexFontColorKey=None,
|
7113
|
+
showEdgeLabel = False,
|
7114
|
+
edgeLabelPrefix='', edgeLabelKey=None,
|
7115
|
+
edgeColor='black', edgeColorKey=None,
|
7116
|
+
edgeWidth=1, edgeWidthKey=None,
|
7117
|
+
edgeStyle='solid', edgeStyleKey=None,
|
7118
|
+
edgeArrowhead='normal', edgeArrowheadKey=None,
|
7119
|
+
edgeFontColor='black', edgeFontColorKey=None,
|
7120
|
+
overwrite=False,
|
7121
|
+
silent=False):
|
7122
|
+
"""
|
7123
|
+
Exports the input graph to a GraphViz `.gv` (dot) file.
|
7124
|
+
|
7125
|
+
Parameters
|
7126
|
+
----------
|
7127
|
+
graph : topologic_core.Graph
|
7128
|
+
The input graph.
|
7129
|
+
path : str
|
7130
|
+
The path to the output file (e.g., "output.gv").
|
7131
|
+
device : str, optional
|
7132
|
+
The output format device, such as 'svg_inline', 'pdf', or 'png'. The default is 'svg_inline'.
|
7133
|
+
deviceKey : str, optional
|
7134
|
+
Dictionary key to override the `device` value. Default is None.
|
7135
|
+
scale : float, optional
|
7136
|
+
Global scaling factor. Default is 1.
|
7137
|
+
scaleKey : str, optional
|
7138
|
+
Dictionary key to override the `scale` per-graph. Default is None.
|
7139
|
+
directed : bool, optional
|
7140
|
+
Whether to treat the graph as directed. Default is False.
|
7141
|
+
directedKey : str, optional
|
7142
|
+
Dictionary key to override the `directed` flag per-graph. Default is None.
|
7143
|
+
layout : str, optional
|
7144
|
+
Layout engine to use. Options include 'dot', 'circo', 'fdp', 'neato', 'osage', 'sfdp', etc. Default is 'dot'.
|
7145
|
+
layoutKey : str, optional
|
7146
|
+
Dictionary key to override the `layout` per-graph. Default is None.
|
7147
|
+
rankDir : str, optional
|
7148
|
+
Direction of graph ranking. Options: 'TB' (top-bottom), 'LR' (left-right), 'RL', 'BT'. Default is 'TB'.
|
7149
|
+
rankDirKey : str, optional
|
7150
|
+
Dictionary key to override `rankDir` per-graph. Default is None.
|
7151
|
+
bgColor : str, optional
|
7152
|
+
Background color. Default is 'white'.
|
7153
|
+
bgColorKey : str, optional
|
7154
|
+
Dictionary key to override `bgColor`. Default is None.
|
7155
|
+
fontName : str, optional
|
7156
|
+
Name of the font to use for all text. Default is 'Arial'.
|
7157
|
+
fontNameKey : str, optional
|
7158
|
+
Dictionary key to override `fontName`. Default is None.
|
7159
|
+
fontSize : int or float, optional
|
7160
|
+
Size of font in points. Default is 12.
|
7161
|
+
fontSizeKey : str, optional
|
7162
|
+
Dictionary key to override `fontSize`. Default is None.
|
7163
|
+
vertexSep : float, optional
|
7164
|
+
Minimum separation between vertices. Default is 0.5.
|
7165
|
+
vertexSepKey : str, optional
|
7166
|
+
Dictionary key to override `vertexSep`. Default is None.
|
7167
|
+
rankSep : float, optional
|
7168
|
+
Separation between ranks. Default is 0.5.
|
7169
|
+
rankSepKey : str, optional
|
7170
|
+
Dictionary key to override `rankSep`. Default is None.
|
7171
|
+
splines : str, optional
|
7172
|
+
Whether to use spline edges. Can be 'true', 'false', or 'polyline'. Default is 'True'.
|
7173
|
+
splinesKey : str, optional
|
7174
|
+
Dictionary key to override `splines`. Default is None.
|
7175
|
+
showGraphLabel : bool, optional
|
7176
|
+
Whether to show a label for the whole graph. Default is False.
|
7177
|
+
graphLabel : str, optional
|
7178
|
+
Text for the graph label. Default is an empty string.
|
7179
|
+
graphLabelKey : str, optional
|
7180
|
+
Dictionary key to override `graphLabel`. Default is None.
|
7181
|
+
graphLabelLoc : str, optional
|
7182
|
+
Position of the graph label: 't' (top), 'b' (bottom), 'c' (center). Default is 't'.
|
7183
|
+
graphLabelLocKey : str, optional
|
7184
|
+
Dictionary key to override `graphLabelLoc`. Default is None.
|
7185
|
+
showVertexLabel : bool, optional
|
7186
|
+
Whether to display vertex labels. Default is False.
|
7187
|
+
vertexLabelPrefix : str, optional
|
7188
|
+
Text prefix for vertex labels. Default is empty string.
|
7189
|
+
vertexLabelKey : str, optional
|
7190
|
+
Dictionary key used to retrieve label text from vertex dictionary. Default is None.
|
7191
|
+
vertexWidth : float, optional
|
7192
|
+
Width of each vertex. Default is 0.5.
|
7193
|
+
vertexWidthKey : str, optional
|
7194
|
+
Dictionary key to override `vertexWidth`. Default is None.
|
7195
|
+
vertexHeight : float, optional
|
7196
|
+
Height of each vertex. Default is 0.5.
|
7197
|
+
vertexHeightKey : str, optional
|
7198
|
+
Dictionary key to override `vertexHeight`. Default is None.
|
7199
|
+
vertexFixedSize : bool, optional
|
7200
|
+
Whether vertices should be fixed in size. Default is False.
|
7201
|
+
vertexFixedSizeKey : str, optional
|
7202
|
+
Dictionary key to override `vertexFixedSize`. Default is None.
|
7203
|
+
vertexShape : str, optional
|
7204
|
+
Shape of the vertex ('circle', 'ellipse', 'box', etc.). Default is 'circle'.
|
7205
|
+
vertexShapeKey : str, optional
|
7206
|
+
Dictionary key to override `vertexShape`. Default is None.
|
7207
|
+
vertexStyle : str, optional
|
7208
|
+
Style of vertex (e.g., 'filled', 'dashed'). Default is 'filled'.
|
7209
|
+
vertexStyleKey : str, optional
|
7210
|
+
Dictionary key to override `vertexStyle`. Default is None.
|
7211
|
+
vertexFillColor : str, optional
|
7212
|
+
Fill color for vertices. Default is 'lightgray'.
|
7213
|
+
vertexFillColorKey : str, optional
|
7214
|
+
Dictionary key to override `vertexFillColor`. Default is None.
|
7215
|
+
vertexColor : str, optional
|
7216
|
+
Border color for vertices. Default is 'black'.
|
7217
|
+
vertexColorKey : str, optional
|
7218
|
+
Dictionary key to override `vertexColor`. Default is None.
|
7219
|
+
vertexFontColor : str, optional
|
7220
|
+
Font color for vertex labels. Default is 'black'.
|
7221
|
+
vertexFontColorKey : str, optional
|
7222
|
+
Dictionary key to override `vertexFontColor`. Default is None.
|
7223
|
+
showEdgeLabel : bool, optional
|
7224
|
+
Whether to display edge labels. Default is False.
|
7225
|
+
edgeLabelPrefix : str, optional
|
7226
|
+
Text prefix for edge labels. Default is empty string.
|
7227
|
+
edgeLabelKey : str, optional
|
7228
|
+
Dictionary key used to retrieve label text from edge dictionary. Default is None.
|
7229
|
+
edgeColor : str, optional
|
7230
|
+
Color of edges. Default is 'black'.
|
7231
|
+
edgeColorKey : str, optional
|
7232
|
+
Dictionary key to override `edgeColor`. Default is None.
|
7233
|
+
edgeWidth : float, optional
|
7234
|
+
Width (thickness) of edges. Default is 1.
|
7235
|
+
edgeWidthKey : str, optional
|
7236
|
+
Dictionary key to override `edgeWidth`. Default is None.
|
7237
|
+
edgeStyle : str, optional
|
7238
|
+
Style of the edge line (e.g., 'solid', 'dashed'). Default is 'solid'.
|
7239
|
+
edgeStyleKey : str, optional
|
7240
|
+
Dictionary key to override `edgeStyle`. Default is None.
|
7241
|
+
edgeArrowhead : str, optional
|
7242
|
+
Arrowhead style for directed edges. Default is 'normal'.
|
7243
|
+
edgeArrowheadKey : str, optional
|
7244
|
+
Dictionary key to override `edgeArrowhead`. Default is None.
|
7245
|
+
edgeFontColor : str, optional
|
7246
|
+
Font color for edge labels. Default is 'black'.
|
7247
|
+
edgeFontColorKey : str, optional
|
7248
|
+
Dictionary key to override `edgeFontColor`. Default is None.
|
7249
|
+
overwrite : bool, optional
|
7250
|
+
If True, overwrites existing files at the given path. Default is False.
|
7251
|
+
silent : bool, optional
|
7252
|
+
If True, suppresses console output. Default is False.
|
7253
|
+
|
7254
|
+
Returns
|
7255
|
+
-------
|
7256
|
+
bool
|
7257
|
+
True if the graph was successfully exported. False otherwise.
|
7258
|
+
"""
|
7259
|
+
|
7260
|
+
from topologicpy.Topology import Topology
|
7261
|
+
from os.path import exists
|
7262
|
+
dot = Graph.GraphVizGraph(
|
7263
|
+
graph,
|
7264
|
+
device = device, deviceKey = deviceKey,
|
7265
|
+
scale = scale, scaleKey = scaleKey,
|
7266
|
+
directed = directed, directedKey = directedKey,
|
7267
|
+
layout = layout,
|
7268
|
+
layoutKey = layoutKey,
|
7269
|
+
rankDir= rankDir, rankDirKey = rankDirKey,
|
7270
|
+
bgColor=bgColor, bgColorKey=bgColorKey,
|
7271
|
+
fontName=fontName, fontNameKey=fontNameKey,
|
7272
|
+
fontSize= fontSize, fontSizeKey=fontSizeKey,
|
7273
|
+
vertexSep= vertexSep, vertexSepKey=vertexSepKey,
|
7274
|
+
rankSep= rankSep, rankSepKey=rankSepKey,
|
7275
|
+
splines=splines, splinesKey=splinesKey,
|
7276
|
+
showGraphLabel = showGraphLabel,
|
7277
|
+
graphLabel=graphLabel, graphLabelKey=graphLabelKey,
|
7278
|
+
graphLabelLoc=graphLabelLoc, graphLabelLocKey=graphLabelLocKey,
|
7279
|
+
|
7280
|
+
showVertexLabel = showVertexLabel,
|
7281
|
+
vertexLabelPrefix=vertexLabelPrefix , vertexLabelKey=vertexLabelKey,
|
7282
|
+
vertexWidth=vertexWidth, vertexWidthKey=vertexWidthKey,
|
7283
|
+
vertexHeight=vertexHeight, vertexHeightKey=vertexHeightKey,
|
7284
|
+
vertexFixedSize=vertexFixedSize, vertexFixedSizeKey=vertexFixedSizeKey,
|
7285
|
+
vertexShape=vertexShape, vertexShapeKey=vertexShapeKey,
|
7286
|
+
vertexStyle=vertexStyle, vertexStyleKey=vertexStyleKey,
|
7287
|
+
vertexFillColor=vertexFillColor, vertexFillColorKey=vertexFillColorKey,
|
7288
|
+
vertexColor=vertexColor, vertexColorKey=vertexColorKey,
|
7289
|
+
vertexFontColor=vertexFontColor, vertexFontColorKey=vertexFontColorKey,
|
7290
|
+
|
7291
|
+
showEdgeLabel = showEdgeLabel,
|
7292
|
+
edgeLabelPrefix=edgeLabelPrefix, edgeLabelKey=edgeLabelKey,
|
7293
|
+
edgeColor=edgeColor, edgeColorKey=edgeColorKey,
|
7294
|
+
edgeWidth=edgeWidth, edgeWidthKey=edgeWidthKey,
|
7295
|
+
edgeStyle=edgeStyle, edgeStyleKey=edgeStyleKey,
|
7296
|
+
edgeArrowhead=edgeArrowhead, edgeArrowheadKey=edgeArrowheadKey,
|
7297
|
+
edgeFontColor=edgeFontColor, edgeFontColorKey=edgeFontColorKey,
|
7298
|
+
silent=silent)
|
7299
|
+
|
7300
|
+
if not Topology.IsInstance(graph, "Graph"):
|
7301
|
+
if not silent:
|
7302
|
+
print("Graph.ExportToGraphVizGraph - Error: the input graph parameter is not a valid graph. Returning None.")
|
7303
|
+
return None
|
7304
|
+
if not isinstance(path, str):
|
7305
|
+
if not silent:
|
7306
|
+
print("Graph.ExportToGraphVizGraph - Error: the input path parameter is not a valid string. Returning None.")
|
7307
|
+
return None
|
7308
|
+
# Make sure the file extension is .gv
|
7309
|
+
ext = path[len(path)-3:len(path)]
|
7310
|
+
if ext.lower() != ".gv":
|
7311
|
+
path = path+".gv"
|
7312
|
+
if not overwrite and exists(path):
|
7313
|
+
if not silent:
|
7314
|
+
print("Graph.ExportToGraphVizGraph - Error: a file already exists at the specified path and overwrite is set to False. Returning None.")
|
7315
|
+
return None
|
7316
|
+
try:
|
7317
|
+
dot.save(filename=path)
|
7318
|
+
return True
|
7319
|
+
except:
|
7320
|
+
return False
|
7321
|
+
|
6872
7322
|
@staticmethod
|
6873
7323
|
def ExportToJSON(graph, path, verticesKey="vertices", edgesKey="edges", vertexLabelKey="", edgeLabelKey="", xKey="x", yKey="y", zKey="z", indent=4, sortKeys=False, mantissa=6, overwrite=False):
|
6874
7324
|
"""
|
@@ -8187,6 +8637,287 @@ class Graph:
|
|
8187
8637
|
adjacency_matrix = Graph.AdjacencyMatrix(graph)
|
8188
8638
|
return global_clustering_coefficient(adjacency_matrix)
|
8189
8639
|
|
8640
|
+
@staticmethod
|
8641
|
+
def GraphVizGraph(
|
8642
|
+
graph,
|
8643
|
+
device = 'svg_inline', deviceKey=None,
|
8644
|
+
scale = 1, scaleKey=None,
|
8645
|
+
directed=False, directedKey=None,
|
8646
|
+
layout = 'dot', # or circo fdp neato nop nop1 nop2 osage patchwork sfdp twopi
|
8647
|
+
layoutKey=None,
|
8648
|
+
rankDir='TB', rankDirKey=None, # or LR, RL, BT
|
8649
|
+
bgColor='white', bgColorKey=None,
|
8650
|
+
fontName='Arial', fontNameKey=None,
|
8651
|
+
fontSize= 12, fontSizeKey=None,
|
8652
|
+
vertexSep= 0.5, vertexSepKey=None,
|
8653
|
+
rankSep= 0.5, rankSepKey=None,
|
8654
|
+
splines='true', splinesKey=None,
|
8655
|
+
showGraphLabel = False,
|
8656
|
+
graphLabel='', graphLabelKey=None,
|
8657
|
+
graphLabelLoc='t', graphLabelLocKey=None,
|
8658
|
+
|
8659
|
+
showVertexLabel = False,
|
8660
|
+
vertexLabelPrefix='' , vertexLabelKey=None,
|
8661
|
+
vertexWidth=0.5, vertexWidthKey=None,
|
8662
|
+
vertexHeight=0.5, vertexHeightKey=None,
|
8663
|
+
vertexFixedSize=False, vertexFixedSizeKey=None,
|
8664
|
+
vertexShape='circle', vertexShapeKey=None,
|
8665
|
+
vertexStyle='filled', vertexStyleKey=None,
|
8666
|
+
vertexFillColor='lightgray', vertexFillColorKey=None,
|
8667
|
+
vertexColor='black', vertexColorKey=None,
|
8668
|
+
vertexFontColor='black', vertexFontColorKey=None,
|
8669
|
+
|
8670
|
+
showEdgeLabel = False,
|
8671
|
+
edgeLabelPrefix='', edgeLabelKey=None,
|
8672
|
+
edgeColor='black', edgeColorKey=None,
|
8673
|
+
edgeWidth=1, edgeWidthKey=None,
|
8674
|
+
edgeStyle='solid', edgeStyleKey=None,
|
8675
|
+
edgeArrowhead='normal', edgeArrowheadKey=None,
|
8676
|
+
edgeFontColor='black', edgeFontColorKey=None,
|
8677
|
+
silent=False
|
8678
|
+
):
|
8679
|
+
"""
|
8680
|
+
Converts the input graph to a GraphViz graph. GraphViz should be installed separately, using your system's package manager.
|
8681
|
+
|
8682
|
+
Parameters
|
8683
|
+
----------
|
8684
|
+
graph : topologic_core.Graph
|
8685
|
+
The input graph.
|
8686
|
+
device : str, optional
|
8687
|
+
The output format device, such as 'svg_inline', 'pdf', or 'png'. The default is 'svg_inline'.
|
8688
|
+
deviceKey : str, optional
|
8689
|
+
Dictionary key to override the `device` value. Default is None.
|
8690
|
+
scale : float, optional
|
8691
|
+
Global scaling factor. Default is 1.
|
8692
|
+
scaleKey : str, optional
|
8693
|
+
Dictionary key to override the `scale` per-graph. Default is None.
|
8694
|
+
directed : bool, optional
|
8695
|
+
Whether to treat the graph as directed. Default is False.
|
8696
|
+
directedKey : str, optional
|
8697
|
+
Dictionary key to override the `directed` flag per-graph. Default is None.
|
8698
|
+
layout : str, optional
|
8699
|
+
Layout engine to use. Options include 'dot', 'circo', 'fdp', 'neato', 'osage', 'sfdp', etc. Default is 'dot'.
|
8700
|
+
layoutKey : str, optional
|
8701
|
+
Dictionary key to override the `layout` per-graph. Default is None.
|
8702
|
+
rankDir : str, optional
|
8703
|
+
Direction of graph ranking. Options: 'TB' (top-bottom), 'LR' (left-right), 'RL', 'BT'. Default is 'TB'.
|
8704
|
+
rankDirKey : str, optional
|
8705
|
+
Dictionary key to override `rankDir` per-graph. Default is None.
|
8706
|
+
bgColor : str, optional
|
8707
|
+
Background color. Default is 'white'.
|
8708
|
+
bgColorKey : str, optional
|
8709
|
+
Dictionary key to override `bgColor`. Default is None.
|
8710
|
+
fontName : str, optional
|
8711
|
+
Name of the font to use for all text. Default is 'Arial'.
|
8712
|
+
fontNameKey : str, optional
|
8713
|
+
Dictionary key to override `fontName`. Default is None.
|
8714
|
+
fontSize : int or float, optional
|
8715
|
+
Size of font in points. Default is 12.
|
8716
|
+
fontSizeKey : str, optional
|
8717
|
+
Dictionary key to override `fontSize`. Default is None.
|
8718
|
+
vertexSep : float, optional
|
8719
|
+
Minimum separation between vertices. Default is 0.5.
|
8720
|
+
vertexSepKey : str, optional
|
8721
|
+
Dictionary key to override `vertexSep`. Default is None.
|
8722
|
+
rankSep : float, optional
|
8723
|
+
Separation between ranks. Default is 0.5.
|
8724
|
+
rankSepKey : str, optional
|
8725
|
+
Dictionary key to override `rankSep`. Default is None.
|
8726
|
+
splines : str, optional
|
8727
|
+
Whether to use spline edges. Can be 'true', 'false', or 'polyline'. Default is 'True'.
|
8728
|
+
splinesKey : str, optional
|
8729
|
+
Dictionary key to override `splines`. Default is None.
|
8730
|
+
showGraphLabel : bool, optional
|
8731
|
+
Whether to show a label for the whole graph. Default is False.
|
8732
|
+
graphLabel : str, optional
|
8733
|
+
Text for the graph label. Default is an empty string.
|
8734
|
+
graphLabelKey : str, optional
|
8735
|
+
Dictionary key to override `graphLabel`. Default is None.
|
8736
|
+
graphLabelLoc : str, optional
|
8737
|
+
Position of the graph label: 't' (top), 'b' (bottom), 'c' (center). Default is 't'.
|
8738
|
+
graphLabelLocKey : str, optional
|
8739
|
+
Dictionary key to override `graphLabelLoc`. Default is None.
|
8740
|
+
showVertexLabel : bool, optional
|
8741
|
+
Whether to display vertex labels. Default is False.
|
8742
|
+
vertexLabelPrefix : str, optional
|
8743
|
+
Text prefix for vertex labels. Default is empty string.
|
8744
|
+
vertexLabelKey : str, optional
|
8745
|
+
Dictionary key used to retrieve label text from vertex dictionary. Default is None.
|
8746
|
+
vertexWidth : float, optional
|
8747
|
+
Width of each vertex. Default is 0.5.
|
8748
|
+
vertexWidthKey : str, optional
|
8749
|
+
Dictionary key to override `vertexWidth`. Default is None.
|
8750
|
+
vertexHeight : float, optional
|
8751
|
+
Height of each vertex. Default is 0.5.
|
8752
|
+
vertexHeightKey : str, optional
|
8753
|
+
Dictionary key to override `vertexHeight`. Default is None.
|
8754
|
+
vertexFixedSize : bool, optional
|
8755
|
+
Whether vertices should be fixed in size. Default is False.
|
8756
|
+
vertexFixedSizeKey : str, optional
|
8757
|
+
Dictionary key to override `vertexFixedSize`. Default is None.
|
8758
|
+
vertexShape : str, optional
|
8759
|
+
Shape of the vertex ('circle', 'ellipse', 'box', etc.). Default is 'circle'.
|
8760
|
+
vertexShapeKey : str, optional
|
8761
|
+
Dictionary key to override `vertexShape`. Default is None.
|
8762
|
+
vertexStyle : str, optional
|
8763
|
+
Style of vertex (e.g., 'filled', 'dashed'). Default is 'filled'.
|
8764
|
+
vertexStyleKey : str, optional
|
8765
|
+
Dictionary key to override `vertexStyle`. Default is None.
|
8766
|
+
vertexFillColor : str, optional
|
8767
|
+
Fill color for vertices. Default is 'lightgray'.
|
8768
|
+
vertexFillColorKey : str, optional
|
8769
|
+
Dictionary key to override `vertexFillColor`. Default is None.
|
8770
|
+
vertexColor : str, optional
|
8771
|
+
Border color for vertices. Default is 'black'.
|
8772
|
+
vertexColorKey : str, optional
|
8773
|
+
Dictionary key to override `vertexColor`. Default is None.
|
8774
|
+
vertexFontColor : str, optional
|
8775
|
+
Font color for vertex labels. Default is 'black'.
|
8776
|
+
vertexFontColorKey : str, optional
|
8777
|
+
Dictionary key to override `vertexFontColor`. Default is None.
|
8778
|
+
showEdgeLabel : bool, optional
|
8779
|
+
Whether to display edge labels. Default is False.
|
8780
|
+
edgeLabelPrefix : str, optional
|
8781
|
+
Text prefix for edge labels. Default is empty string.
|
8782
|
+
edgeLabelKey : str, optional
|
8783
|
+
Dictionary key used to retrieve label text from edge dictionary. Default is None.
|
8784
|
+
edgeColor : str, optional
|
8785
|
+
Color of edges. Default is 'black'.
|
8786
|
+
edgeColorKey : str, optional
|
8787
|
+
Dictionary key to override `edgeColor`. Default is None.
|
8788
|
+
edgeWidth : float, optional
|
8789
|
+
Width (thickness) of edges. Default is 1.
|
8790
|
+
edgeWidthKey : str, optional
|
8791
|
+
Dictionary key to override `edgeWidth`. Default is None.
|
8792
|
+
edgeStyle : str, optional
|
8793
|
+
Style of the edge line (e.g., 'solid', 'dashed'). Default is 'solid'.
|
8794
|
+
edgeStyleKey : str, optional
|
8795
|
+
Dictionary key to override `edgeStyle`. Default is None.
|
8796
|
+
edgeArrowhead : str, optional
|
8797
|
+
Arrowhead style for directed edges. Default is 'normal'.
|
8798
|
+
edgeArrowheadKey : str, optional
|
8799
|
+
Dictionary key to override `edgeArrowhead`. Default is None.
|
8800
|
+
edgeFontColor : str, optional
|
8801
|
+
Font color for edge labels. Default is 'black'.
|
8802
|
+
edgeFontColorKey : str, optional
|
8803
|
+
Dictionary key to override `edgeFontColor`. Default is None.
|
8804
|
+
overwrite : bool, optional
|
8805
|
+
If True, overwrites existing files at the given path. Default is False.
|
8806
|
+
silent : bool, optional
|
8807
|
+
If True, suppresses console output. Default is False.
|
8808
|
+
|
8809
|
+
Returns
|
8810
|
+
-------
|
8811
|
+
graphviz.graphs.Graph
|
8812
|
+
The created GraphViz graph.
|
8813
|
+
"""
|
8814
|
+
|
8815
|
+
from graphviz import Digraph
|
8816
|
+
from graphviz import Graph as Udgraph
|
8817
|
+
from topologicpy.Graph import Graph
|
8818
|
+
from topologicpy.Topology import Topology
|
8819
|
+
from topologicpy.Dictionary import Dictionary
|
8820
|
+
|
8821
|
+
if not Topology.IsInstance(graph, "Graph"):
|
8822
|
+
if not silent:
|
8823
|
+
print("Graph.GraphVizGraph - Error: the input graph parameter is not a valid graph. Returning None.")
|
8824
|
+
return None
|
8825
|
+
# Set Graph-level attributes
|
8826
|
+
def get_attr(dict, keyName, default):
|
8827
|
+
if keyName:
|
8828
|
+
return Dictionary.ValueAtKey(dict, keyName, default)
|
8829
|
+
return default
|
8830
|
+
|
8831
|
+
graph_dict = Topology.Dictionary(graph)
|
8832
|
+
|
8833
|
+
is_directed = get_attr(graph_dict, directedKey, directed)
|
8834
|
+
if is_directed:
|
8835
|
+
gv_graph = Digraph()
|
8836
|
+
else:
|
8837
|
+
gv_graph = Udgraph()
|
8838
|
+
|
8839
|
+
if showGraphLabel:
|
8840
|
+
label_value = get_attr(graph_dict, graphLabelKey, graphLabel)
|
8841
|
+
else:
|
8842
|
+
label_value = ''
|
8843
|
+
gv_graph.attr(
|
8844
|
+
layout = get_attr(graph_dict, layoutKey, layout),
|
8845
|
+
rankdir=get_attr(graph_dict, rankDirKey, rankDir),
|
8846
|
+
bgcolor=get_attr(graph_dict, bgColorKey, bgColor),
|
8847
|
+
fontname=get_attr(graph_dict, fontNameKey, fontName),
|
8848
|
+
fontsize=get_attr(graph_dict, fontSizeKey, str(fontSize)),
|
8849
|
+
vertexsep=get_attr(graph_dict, vertexSepKey, str(vertexSep)),
|
8850
|
+
ranksep=get_attr(graph_dict, rankSepKey, str(rankSep)),
|
8851
|
+
splines=get_attr(graph_dict, splinesKey, splines),
|
8852
|
+
label=label_value,
|
8853
|
+
labelloc=get_attr(graph_dict, graphLabelLocKey, graphLabelLoc),
|
8854
|
+
device = get_attr(graph_dict, deviceKey, device)
|
8855
|
+
)
|
8856
|
+
|
8857
|
+
# Get the Vertices and Edges from the Topologic Graph
|
8858
|
+
mesh_data = Graph.MeshData(graph)
|
8859
|
+
|
8860
|
+
# Set Vertex Attributes
|
8861
|
+
verts = mesh_data['vertices']
|
8862
|
+
vert_dicts = mesh_data['vertexDictionaries']
|
8863
|
+
for i, v in enumerate(verts):
|
8864
|
+
v_dict = vert_dicts[i]
|
8865
|
+
if showVertexLabel:
|
8866
|
+
label_value = get_attr(v_dict, vertexLabelKey, f"{vertexLabelPrefix}{i}")
|
8867
|
+
else:
|
8868
|
+
label_value = ''
|
8869
|
+
|
8870
|
+
fixed_size_value = get_attr(v_dict, vertexFixedSizeKey, vertexFixedSize)
|
8871
|
+
|
8872
|
+
if fixed_size_value:
|
8873
|
+
fixed_size_value = "True"
|
8874
|
+
else:
|
8875
|
+
fixed_size_value = "False"
|
8876
|
+
|
8877
|
+
if "nop" in get_attr(graph_dict, layoutKey, layout):
|
8878
|
+
pos_value = f"{v[0]*scale},{v[1]*scale}!"
|
8879
|
+
else:
|
8880
|
+
pos_value = ""
|
8881
|
+
gv_graph.node(
|
8882
|
+
str(i),
|
8883
|
+
pos = pos_value,
|
8884
|
+
label= label_value,
|
8885
|
+
shape=get_attr(v_dict, vertexShapeKey, vertexShape),
|
8886
|
+
width=str(get_attr(v_dict, vertexWidthKey, vertexWidth)),
|
8887
|
+
height=str(get_attr(v_dict, vertexHeightKey, vertexHeight)),
|
8888
|
+
fixedSize=fixed_size_value,
|
8889
|
+
style=get_attr(v_dict, vertexStyleKey, vertexStyle),
|
8890
|
+
fillcolor=get_attr(v_dict, vertexFillColorKey, vertexFillColor),
|
8891
|
+
color=get_attr(v_dict, vertexColorKey, vertexColor),
|
8892
|
+
fontcolor=get_attr(v_dict, vertexFontColorKey, vertexFontColor)
|
8893
|
+
)
|
8894
|
+
|
8895
|
+
# Set Edge attributes
|
8896
|
+
edges = mesh_data['edges']
|
8897
|
+
edge_dicts = mesh_data['edgeDictionaries']
|
8898
|
+
for i, e in enumerate(edges):
|
8899
|
+
sid = e[0]
|
8900
|
+
eid = e[1]
|
8901
|
+
|
8902
|
+
e_dict = edge_dicts[i]
|
8903
|
+
if showEdgeLabel:
|
8904
|
+
label_value = get_attr(e_dict, edgeLabelKey, f"{edgeLabelPrefix}{i}")
|
8905
|
+
else:
|
8906
|
+
label_value = ''
|
8907
|
+
|
8908
|
+
gv_graph.edge(
|
8909
|
+
str(sid),
|
8910
|
+
str(eid),
|
8911
|
+
label= label_value,
|
8912
|
+
color= get_attr(e_dict, edgeColorKey, edgeColor),
|
8913
|
+
penwidth=str(get_attr(e_dict, edgeWidthKey, edgeWidth)),
|
8914
|
+
style= get_attr(e_dict, edgeStyleKey, edgeStyle),
|
8915
|
+
arrowhead= get_attr(e_dict, edgeArrowheadKey, edgeArrowhead),
|
8916
|
+
fontcolor= get_attr(e_dict, edgeFontColorKey, edgeFontColor),
|
8917
|
+
)
|
8918
|
+
|
8919
|
+
return gv_graph
|
8920
|
+
|
8190
8921
|
@staticmethod
|
8191
8922
|
def Guid(graph):
|
8192
8923
|
"""
|
@@ -10544,36 +11275,36 @@ class Graph:
|
|
10544
11275
|
data = []
|
10545
11276
|
for graph in new_graphs:
|
10546
11277
|
data += Plotly.DataByGraph(graph,
|
10547
|
-
|
10548
|
-
|
10549
|
-
|
10550
|
-
|
10551
|
-
|
10552
|
-
|
10553
|
-
|
10554
|
-
|
10555
|
-
|
10556
|
-
|
10557
|
-
|
10558
|
-
|
10559
|
-
|
10560
|
-
|
10561
|
-
|
10562
|
-
|
10563
|
-
|
10564
|
-
|
10565
|
-
|
10566
|
-
|
10567
|
-
|
10568
|
-
|
10569
|
-
|
10570
|
-
|
10571
|
-
|
10572
|
-
|
10573
|
-
|
10574
|
-
|
10575
|
-
|
10576
|
-
|
11278
|
+
sagitta=sagitta,
|
11279
|
+
absolute=absolute,
|
11280
|
+
sides=sides,
|
11281
|
+
angle=angle,
|
11282
|
+
vertexColor=vertexColor,
|
11283
|
+
vertexColorKey=vertexColorKey,
|
11284
|
+
vertexSize=vertexSize,
|
11285
|
+
vertexSizeKey=vertexSizeKey,
|
11286
|
+
vertexLabelKey=vertexLabelKey,
|
11287
|
+
vertexGroupKey=vertexGroupKey,
|
11288
|
+
vertexGroups=vertexGroups,
|
11289
|
+
vertexMinGroup=vertexMinGroup,
|
11290
|
+
vertexMaxGroup=vertexMaxGroup,
|
11291
|
+
showVertices=showVertices,
|
11292
|
+
showVertexLabel=showVertexLabel,
|
11293
|
+
showVertexLegend=showVertexLegend,
|
11294
|
+
edgeColor=edgeColor,
|
11295
|
+
edgeColorKey=edgeColorKey,
|
11296
|
+
edgeWidth=edgeWidth,
|
11297
|
+
edgeWidthKey=edgeWidthKey,
|
11298
|
+
edgeLabelKey=edgeLabelKey,
|
11299
|
+
edgeGroupKey=edgeGroupKey,
|
11300
|
+
edgeGroups=edgeGroups,
|
11301
|
+
edgeMinGroup=edgeMinGroup,
|
11302
|
+
edgeMaxGroup=edgeMaxGroup,
|
11303
|
+
showEdges=showEdges,
|
11304
|
+
showEdgeLabel=showEdgeLabel,
|
11305
|
+
showEdgeLegend=showEdgeLegend,
|
11306
|
+
colorScale=colorScale,
|
11307
|
+
silent=silent)
|
10577
11308
|
fig = Plotly.FigureByData(data, width=width, height=height, xAxis=xAxis, yAxis=yAxis, zAxis=zAxis, axisSize=axisSize, backgroundColor=backgroundColor,
|
10578
11309
|
marginLeft=marginLeft, marginRight=marginRight, marginTop=marginTop, marginBottom=marginBottom, tolerance=tolerance)
|
10579
11310
|
Plotly.Show(fig, renderer=renderer, camera=camera, center=center, up=up, projection=projection)
|
topologicpy/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = '0.8.
|
1
|
+
__version__ = '0.8.25'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: topologicpy
|
3
|
-
Version: 0.8.
|
3
|
+
Version: 0.8.25
|
4
4
|
Summary: An AI-Powered Spatial Modelling and Analysis Software Library for Architecture, Engineering, and Construction.
|
5
5
|
Author-email: Wassim Jabi <wassim.jabi@gmail.com>
|
6
6
|
License: AGPL v3 License
|
@@ -12,7 +12,7 @@ topologicpy/Dictionary.py,sha256=Lf24WHW8q_RCq0l8VpT3XJTn6UuStY66JI4Lb4W08jI,341
|
|
12
12
|
topologicpy/Edge.py,sha256=pu4tZbRbK8qx2oqRbwHAeKuwU2X8JFGPSJjJMTJw8Q0,71418
|
13
13
|
topologicpy/EnergyModel.py,sha256=Pyb28gDDwhzlQIH0xqAygqS0P3SJxWyyV7OWS_AAfRs,53856
|
14
14
|
topologicpy/Face.py,sha256=7K46gB_UIKjKEKyzyY0JqGarqjwjH0ggS-JQTpDtWC4,184847
|
15
|
-
topologicpy/Graph.py,sha256=
|
15
|
+
topologicpy/Graph.py,sha256=v9iFyHVs-dlcH9Pdj4uT4ELgS2VIygfDKAMDoSnSAtI,562010
|
16
16
|
topologicpy/Grid.py,sha256=qRnFUvs079zMOZ6COWzBX6408niI7HyNz-BM0VRguXY,18245
|
17
17
|
topologicpy/Helper.py,sha256=JdvC30WMrla46mTj5TdwCV_bRv-6y8vK5Bkx0prluy4,29100
|
18
18
|
topologicpy/Honeybee.py,sha256=yctkwfdupKnp7bAOjP1Z4YaYpRrWoMEb4gz9Z5zaWwE,21751
|
@@ -29,9 +29,9 @@ topologicpy/Vector.py,sha256=mx7fgABdioikPWM9HzXKzmqfx3u_XBcU_jlLD4qK2x8,42407
|
|
29
29
|
topologicpy/Vertex.py,sha256=PIwfbA7_TxK_dSGlSeM5mson97TRr4dYrfZyOLgO150,80913
|
30
30
|
topologicpy/Wire.py,sha256=eRs4PM7h4yU5v6umPh0oBJR4cN8BwsqlVroaFdnvK4w,228499
|
31
31
|
topologicpy/__init__.py,sha256=RMftibjgAnHB1vdL-muo71RwMS4972JCxHuRHOlU428,928
|
32
|
-
topologicpy/version.py,sha256=
|
33
|
-
topologicpy-0.8.
|
34
|
-
topologicpy-0.8.
|
35
|
-
topologicpy-0.8.
|
36
|
-
topologicpy-0.8.
|
37
|
-
topologicpy-0.8.
|
32
|
+
topologicpy/version.py,sha256=RQuvvS5_gUL4CXqswj954OcBx7QfBRLpwl789EByiZc,23
|
33
|
+
topologicpy-0.8.25.dist-info/licenses/LICENSE,sha256=FK0vJ73LuE8PYJAn7LutsReWR47-Ooovw2dnRe5yV6Q,681
|
34
|
+
topologicpy-0.8.25.dist-info/METADATA,sha256=AZ8ca3QxNZAkqzohr2VAyEi_30MSXsfnm1v_v523aJ8,10535
|
35
|
+
topologicpy-0.8.25.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
36
|
+
topologicpy-0.8.25.dist-info/top_level.txt,sha256=J30bDzW92Ob7hw3zA8V34Jlp-vvsfIkGzkr8sqvb4Uw,12
|
37
|
+
topologicpy-0.8.25.dist-info/RECORD,,
|
File without changes
|
File without changes
|