svg для графа сборки

This commit is contained in:
Mark Voltov 2024-06-03 03:34:25 +03:00
parent 052dd86d94
commit ecb43845a6
14 changed files with 318 additions and 0 deletions

View file

@ -0,0 +1,44 @@
import json
import networkx as nx
import matplotlib.pyplot as plt
from PIL import Image
import matplotlib.image as mpimg
from networkx.drawing.nx_agraph import graphviz_layout
def load_assembly_sequence(filepath):
with open(filepath, 'r') as file:
return json.load(file)
def create_assembly_graph(sequence):
G = nx.DiGraph()
for i, part in enumerate(sequence):
G.add_node(part, image=f'{part}.svg')
if i > 0:
G.add_edge(sequence[i-1], part)
return G
def draw_graph(G):
pos = graphviz_layout(G, prog='dot')
fig, ax = plt.subplots(figsize=(12, 8))
for node in G.nodes(data=True):
x, y = pos[node[0]]
img = mpimg.imread(node[1]['image'])
ax.imshow(img, aspect='auto', extent=(x-0.5, x+0.5, y-0.5, y+0.5), zorder=1)
ax.text(x, y-0.6, s=node[0], horizontalalignment='center', fontsize=12, zorder=2)
nx.draw_networkx_edges(G, pos, ax=ax, arrows=True)
plt.axis('off')
plt.show()
def main():
sequence = load_assembly_sequence('assembly_sequence.json')
assembly_graph = create_assembly_graph(sequence)
draw_graph(assembly_graph)
if __name__ == '__main__':
main()

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 650 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 658 KiB

18
test_models/img/bolt.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 22 KiB

18
test_models/img/bolt2.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 22 KiB

18
test_models/img/bolt3.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 22 KiB

18
test_models/img/bolt4.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 22 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 728 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 104 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 104 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 104 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 104 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 104 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 414 KiB