summaryrefslogtreecommitdiff
path: root/drawer
diff options
context:
space:
mode:
authorAndrew Guschin <guschin@altlinux.org>2024-10-28 19:22:34 +0400
committerAndrew Guschin <guschin@altlinux.org>2024-10-28 19:25:29 +0400
commit4471a89bef824e9f9886228718fae99bff6c35e7 (patch)
tree47923493944b70d1044ba44473719d940829dacc /drawer
parent25d3c40871c9bca9e4bee1b767c8a1480d05c701 (diff)
feat: add program for visualizing graphs
Diffstat (limited to 'drawer')
-rw-r--r--drawer/.gitignore10
-rw-r--r--drawer/README.md3
-rw-r--r--drawer/pyproject.toml30
-rw-r--r--drawer/requirements-dev.lock37
-rw-r--r--drawer/requirements.lock37
-rw-r--r--drawer/src/drawer/__init__.py24
6 files changed, 141 insertions, 0 deletions
diff --git a/drawer/.gitignore b/drawer/.gitignore
new file mode 100644
index 0000000..ae8554d
--- /dev/null
+++ b/drawer/.gitignore
@@ -0,0 +1,10 @@
+# python generated files
+__pycache__/
+*.py[oc]
+build/
+dist/
+wheels/
+*.egg-info
+
+# venv
+.venv
diff --git a/drawer/README.md b/drawer/README.md
new file mode 100644
index 0000000..ec1579b
--- /dev/null
+++ b/drawer/README.md
@@ -0,0 +1,3 @@
+# drawer
+
+Describe your project here.
diff --git a/drawer/pyproject.toml b/drawer/pyproject.toml
new file mode 100644
index 0000000..04acc19
--- /dev/null
+++ b/drawer/pyproject.toml
@@ -0,0 +1,30 @@
+[project]
+name = "drawer"
+version = "0.1.0"
+description = "Add your description here"
+authors = [
+ { name = "Andrew Guschin", email = "guschin@altlinux.org" }
+]
+dependencies = [
+ "networkx>=3.4.2",
+ "matplotlib>=3.9.2",
+]
+readme = "README.md"
+requires-python = ">= 3.8"
+
+[project.scripts]
+start = "drawer:main"
+
+[build-system]
+requires = ["hatchling"]
+build-backend = "hatchling.build"
+
+[tool.rye]
+managed = true
+dev-dependencies = []
+
+[tool.hatch.metadata]
+allow-direct-references = true
+
+[tool.hatch.build.targets.wheel]
+packages = ["src/drawer"]
diff --git a/drawer/requirements-dev.lock b/drawer/requirements-dev.lock
new file mode 100644
index 0000000..94671b2
--- /dev/null
+++ b/drawer/requirements-dev.lock
@@ -0,0 +1,37 @@
+# generated by rye
+# use `rye lock` or `rye sync` to update this lockfile
+#
+# last locked with the following flags:
+# pre: false
+# features: []
+# all-features: false
+# with-sources: false
+# generate-hashes: false
+# universal: false
+
+-e file:.
+contourpy==1.3.0
+ # via matplotlib
+cycler==0.12.1
+ # via matplotlib
+fonttools==4.54.1
+ # via matplotlib
+kiwisolver==1.4.7
+ # via matplotlib
+matplotlib==3.9.2
+ # via drawer
+networkx==3.4.2
+ # via drawer
+numpy==2.1.2
+ # via contourpy
+ # via matplotlib
+packaging==24.1
+ # via matplotlib
+pillow==11.0.0
+ # via matplotlib
+pyparsing==3.2.0
+ # via matplotlib
+python-dateutil==2.9.0.post0
+ # via matplotlib
+six==1.16.0
+ # via python-dateutil
diff --git a/drawer/requirements.lock b/drawer/requirements.lock
new file mode 100644
index 0000000..94671b2
--- /dev/null
+++ b/drawer/requirements.lock
@@ -0,0 +1,37 @@
+# generated by rye
+# use `rye lock` or `rye sync` to update this lockfile
+#
+# last locked with the following flags:
+# pre: false
+# features: []
+# all-features: false
+# with-sources: false
+# generate-hashes: false
+# universal: false
+
+-e file:.
+contourpy==1.3.0
+ # via matplotlib
+cycler==0.12.1
+ # via matplotlib
+fonttools==4.54.1
+ # via matplotlib
+kiwisolver==1.4.7
+ # via matplotlib
+matplotlib==3.9.2
+ # via drawer
+networkx==3.4.2
+ # via drawer
+numpy==2.1.2
+ # via contourpy
+ # via matplotlib
+packaging==24.1
+ # via matplotlib
+pillow==11.0.0
+ # via matplotlib
+pyparsing==3.2.0
+ # via matplotlib
+python-dateutil==2.9.0.post0
+ # via matplotlib
+six==1.16.0
+ # via python-dateutil
diff --git a/drawer/src/drawer/__init__.py b/drawer/src/drawer/__init__.py
new file mode 100644
index 0000000..ef47fbc
--- /dev/null
+++ b/drawer/src/drawer/__init__.py
@@ -0,0 +1,24 @@
+import networkx as nx
+import tempfile
+
+def main():
+ g6 = "I?opuIiBw"
+ with tempfile.NamedTemporaryFile(delete=False) as f:
+ _ = f.write(g6.encode())
+ _ = f.seek(0)
+ g = nx.read_graph6(f.name)
+
+ tikz_options = "scale=4"
+ node_options = {n: "line width=1.5, draw=black, circle" for n in g.nodes}
+ edge_options = {e: "line width=1.5" for e in g.edges}
+ print(nx.to_latex(
+ g, nx.circular_layout(g),
+ caption=f"Визуализация графа <<{g6}>>",
+ figure_wrapper='\\begin{{figure}}\\centering\n{content}{caption}{label}\n\\end{{figure}}',
+ as_document=False,
+ tikz_options=tikz_options,
+ node_options=node_options,
+ edge_options=edge_options
+ ))
+ # nx.write_latex(g, "graph.tex", as_document=True)
+ # nx.draw(g)