Skip to content

Commit

Permalink
visualizar grafico
Browse files Browse the repository at this point in the history
  • Loading branch information
xhuniktzi committed Mar 6, 2021
1 parent 0ba2ede commit 98986b8
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 54 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
__pycache__/
*.xml
*.xml
*.dot
*.svg
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ verify_ssl = true
name = "pypi"

[packages]
graphviz = "*"

[dev-packages]
pylint = "*"
Expand Down
84 changes: 35 additions & 49 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,26 @@ def load_file(data: ListaEnlazada):
data.get_last().insert(int(obj_attrib['x'])-1,
int(obj_attrib['y'])-1, int(obj.text))

data.get_last().print_matrix()

def process_file(data: ListaEnlazada, output: ListaEnlazada):
pass

def print_info():
print('> Xhunik Nikol Miguel Mutzutz')
print('> 201900462')
print('> Introducción a la Programación y Computación 2, Sección D')
print('> Ingenieria en Ciencias y Sistemas')
print('> 4to Semestre')


def render_graph(data: ListaEnlazada):
count = 0
print('Selecciona una matriz: ')
while data.get_size() > count:
print('{}. {}'.format(count, data.get_by_index(count).name))
count = count + 1

matrix_index = int(input('> '))
data.get_by_index(matrix_index).render_matrix()


def main_menu(data: ListaEnlazada, output: ListaEnlazada):
Expand All @@ -41,13 +58,14 @@ def main_menu(data: ListaEnlazada, output: ListaEnlazada):
load_file(data)
continue
if opt == '2':
process_file(data, output)
continue
if opt == '3':
continue
if opt == '4':
print_info()
continue
if opt == '5':
render_graph(data)
continue
if opt == '6':
exit()
Expand Down
30 changes: 30 additions & 0 deletions src/models/Matriz.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from models import ListaEnlazada
from os import system, startfile


class Matriz:
Expand Down Expand Up @@ -35,3 +36,32 @@ def print_matrix(self):
self.row_list.get_by_index(count).print_list()
count = count + 1
print()

def render_matrix(self):
temp_file = open('graph.dot', 'w+')
temp_file.write('digraph G {\n') # begin file
temp_file.write('name [label="{}"];\n'.format(self.name))
temp_file.write('m [label="m={}"];\n'.format(self.m))
temp_file.write('n [label="n={}"];\n'.format(self.n))
temp_file.write('name -> m;')
temp_file.write('name -> n;')

x_count = 0
while self.m > x_count:

y_count = 0
while self.n > y_count:
temp_file.write('x{}y{} [label="{}"];\n'.format(
x_count, y_count, self.get(x_count, y_count)))

if not (y_count + 1) >= self.n:
temp_file.write(
'x{}y{} -> x{}y{};\n'.format(x_count, y_count, x_count, y_count+1))
y_count = y_count + 1

temp_file.write('name -> x{}y{};'.format(x_count, 0))
x_count = x_count + 1
temp_file.write('}\n') # end file
temp_file.close()
system('dot -Tsvg graph.dot -o output.svg')
startfile('output.svg')
4 changes: 4 additions & 0 deletions src/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from models import Matriz

matrix = Matriz('nombre', 3, 3)
matrix.print_matrix()

0 comments on commit 98986b8

Please sign in to comment.