Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for the Digraphs package #14

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions PackageInfo.g
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# graphviz: This package facilitates the creation of graph descriptions in the
# DOT language of the Graphviz graph drawing software from GAP
#
# This file contains package meta data. For additional information on
# the meaning and correct usage of these fields, please consult the
# manual of the "Example" package as well as the comments in its
# PackageInfo.g file.
#
#############################################################################
##
## PackageInfo.g
## Copyright (C) 2024 Matthew Pancer
##
## Licensing information can be found in the README file of this package.
##
#############################################################################
##

SetPackageInfo(rec(

PackageName := "graphviz",
Expand All @@ -26,12 +27,24 @@ Persons := [
PostalAddress := Concatenation("Mathematical Institute, North Haugh,",
" St Andrews, Fife, KY16 9SS, Scotland"),
Place := "St Andrews",
Institution := "University of St Andrews"),
rec(
FirstNames := "Matthew",
LastName := "Pancer",
Email := "[email protected]",
IsAuthor := true,
IsMaintainer := true,
PostalAddress := Concatenation("Mathematical Institute, North Haugh,",
" St Andrews, Fife, KY16 9SS, Scotland"),
# TODO correct? Or should be cs?
Place := "St Andrews",
Institution := "University of St Andrews")],

SourceRepository := rec(Type := "git",
URL := "https://github.com/digraphs/graphviz"),
IssueTrackerURL := "https://github.com/digraphs/graphviz/issues",
PackageWWWHome := "TODO",
PackageWWWHome := Concatenation("https://digraphs.github.io/",
~.PackageName),

PackageInfoURL := Concatenation(~.PackageWWWHome, "PackageInfo.g"),
README_URL := Concatenation(~.PackageWWWHome, "README.md"),
Expand Down
4 changes: 4 additions & 0 deletions etc/gaplint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e

gaplint --disable W004 $@ *.g gap/* read.g init.g PackageInfo.g makedoc.g tst/testall.g tst/*.tst tst/examples/*.tst
40 changes: 40 additions & 0 deletions etc/tst-local-vars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
"""
This simple script adds the local variables used in a GAP tst file to the top
of the file.
"""
import os
import re
import sys
import textwrap

import yaml
from bs4 import BeautifulSoup


def main():
if sys.version_info[0] < 3:
raise Exception("Python 3 is required")
args = sys.argv[1:]
pattern1 = re.compile(r"(\w+)\s*:=")
pattern2 = re.compile(r"for (\w+) in")
for fname in args:
lvars = []
with open(fname, "r") as f:
lines = f.read()
lvars.extend([x.group(1) for x in re.finditer(pattern1, lines)])
lvars.extend([x.group(1) for x in re.finditer(pattern2, lines)])
lvars = ", ".join(sorted([*{*lvars}]))
lvars = [x if x[-1] != "," else x[:-1] for x in textwrap.wrap(lvars, width=72)]
lvars = [""] + ["#@local " + x for x in lvars]
lines = lines.split("\n")
pos = next(i for i in range(len(lines)) if "START_TEST" in lines[i])
lines = lines[:pos] + lvars + lines[pos:]
lines = "\n".join(lines)
with open(fname, "w") as f:
print(f"Writing local variables to {fname}...")
f.write(lines)


if __name__ == "__main__":
main()
18 changes: 15 additions & 3 deletions examples/angles.gi → examples/angles.g
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#############################################################################
##
## angles.g
## Copyright (C) 2024 Matthew Pancer
##
## Licensing information can be found in the README file of this package.
##
#############################################################################
##

# https://graphviz.readthedocs.io/en/stable/examples.html
# https://www.graphviz.org/Gallery/gradient/angles.html

Expand All @@ -21,7 +31,7 @@ for pair in pairs do
od;
GraphvizSetAttr(cluster1,
"label",
"\"Linear Angle Variations (white to black gradient)\"");
"Linear Angle Variations (white to black gradient)");

cluster2 := GraphvizAddSubgraph(g, "cluster_2");
GraphvizSetAttr(cluster2, "fontcolor", "white");
Expand All @@ -38,7 +48,9 @@ for pair in pairs do
pair[1], pair[2]));
od;
GraphvizSetAttr(cluster2, "label",
"\"Radial Angle Variations (white to black gradient)\"");
"Radial Angle Variations (white to black gradient)");

GraphvizAddEdge(g, "n5", "n14");
Print(AsString(g), "\n");
Print(AsString(g));
Splash(g);
QUIT;
39 changes: 39 additions & 0 deletions examples/btree.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#############################################################################
##
## btree.g
## Copyright (C) 2024 Matthew Pancer
##
## Licensing information can be found in the README file of this package.
##
#############################################################################
##

# https://graphviz.readthedocs.io/en/stable/examples.html
# https://graphviz.org/Gallery/directed/unix.html
LoadPackage("graphviz");

s := GraphvizDigraph("g");
GraphvizSetAttr(s, "node [shape=record, height=.1]");

GraphvizSetAttr(GraphvizAddNode(s, "node0"), "label", "<f0> |<f1> G|<f2>");
GraphvizSetAttr(GraphvizAddNode(s, "node1"), "label", "<f0> |<f1> E|<f2>");
GraphvizSetAttr(GraphvizAddNode(s, "node2"), "label", "<f0> |<f1> B|<f2>");
GraphvizSetAttr(GraphvizAddNode(s, "node3"), "label", "<f0> |<f1> F|<f2>");
GraphvizSetAttr(GraphvizAddNode(s, "node4"), "label", "<f0> |<f1> R|<f2>");
GraphvizSetAttr(GraphvizAddNode(s, "node5"), "label", "<f0> |<f1> H|<f2>");
GraphvizSetAttr(GraphvizAddNode(s, "node6"), "label", "<f0> |<f1> Y|<f2>");
GraphvizSetAttr(GraphvizAddNode(s, "node7"), "label", "<f0> |<f1> A|<f2>");
GraphvizSetAttr(GraphvizAddNode(s, "node8"), "label", "<f0> |<f1> C|<f2>");

GraphvizAddEdge(s, "node0:f2", "node4:f1");
GraphvizAddEdge(s, "node0:f0", "node1:f1");
GraphvizAddEdge(s, "node1:f0", "node2:f1");
GraphvizAddEdge(s, "node1:f2", "node3:f1");
GraphvizAddEdge(s, "node2:f2", "node8:f1");
GraphvizAddEdge(s, "node2:f0", "node7:f1");
GraphvizAddEdge(s, "node4:f2", "node6:f1");
GraphvizAddEdge(s, "node4:f0", "node5:f1");

Print(AsString(s));
Splash(s);
QUIT;
27 changes: 0 additions & 27 deletions examples/btree.gi

This file was deleted.

12 changes: 12 additions & 0 deletions examples/cluster.gi → examples/cluster.g
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#############################################################################
##
## cluster.g
## Copyright (C) 2024 Matthew Pancer
##
## Licensing information can be found in the README file of this package.
##
#############################################################################
##

# https://graphviz.readthedocs.io/en/stable/examples.html
LoadPackage("graphviz");
graph := GraphvizDigraph("G");
Expand Down Expand Up @@ -31,3 +41,5 @@ GraphvizSetAttr(graph["start"], "shape", "Mdiamond");
GraphvizSetAttr(graph["end"], "shape", "Msquare");

Print(AsString(graph));
Splash(graph);
QUIT;
15 changes: 13 additions & 2 deletions examples/cluster_edge.gi → examples/cluster_edge.g
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#############################################################################
##
## cluster_edge.g
## Copyright (C) 2024 Matthew Pancer
##
## Licensing information can be found in the README file of this package.
##
#############################################################################
##

# https://graphviz.readthedocs.io/en/stable/examples.html
# """https://www.graphviz.org/pdf/dotguide.pdf, Figure 20"""
# https://www.graphviz.org/pdf/dotguide.pdf, Figure 20

LoadPackage("graphviz");

Expand Down Expand Up @@ -28,4 +38,5 @@ GraphvizSetAttr(e, "ltail", "cluster0");

GraphvizAddEdge(g, "d", "h");

Print(AsString(g));
Splash(g);
QUIT;
35 changes: 35 additions & 0 deletions examples/colors.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#############################################################################
##
## colors.g
## Copyright (C) 2024 Matthew Pancer
##
## Licensing information can be found in the README file of this package.
##
#############################################################################
##

# https://graphviz.readthedocs.io/en/stable/examples.html
# https://graphviz.org/docs/attr-types/color

LoadPackage("graphviz");
g := GraphvizGraph();

node := GraphvizAddNode(g, "RGB: #40e0d0");
GraphvizSetAttr(node, "style", "filled");
GraphvizSetAttr(node, "fillcolor", "\"#40e0d0\"");

node := GraphvizAddNode(g, "RGBA: #ff000042");
GraphvizSetAttr(node, "style", "filled");
GraphvizSetAttr(node, "fillcolor", "\"#ff000042\"");

node := GraphvizAddNode(g, "HSV: 0.051 0.718 0.627");
GraphvizSetAttr(node, "style", "filled");
GraphvizSetAttr(node, "fillcolor", "0.051 0.718 0.627");

node := GraphvizAddNode(g, "name: deeppink");
GraphvizSetAttr(node, "style", "filled");
GraphvizSetAttr(node, "fillcolor", "deeppink");

Print(AsString(g));
Splash(g);
QUIT;
23 changes: 0 additions & 23 deletions examples/colors.gi

This file was deleted.

14 changes: 13 additions & 1 deletion examples/er.gi → examples/er.g
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#############################################################################
##
## er.g
## Copyright (C) 2024 Matthew Pancer
##
## Licensing information can be found in the README file of this package.
##
#############################################################################
##

# https://graphviz.readthedocs.io/en/stable/examples.html
# """https://graphviz.org/Gallery/undirected/ER.html"""
# https://graphviz.org/Gallery/undirected/ER.html
LoadPackage("graphviz");
e := GraphvizGraph("ER");
GraphvizSetAttr(e, "engine=\"neato\"");
Expand Down Expand Up @@ -49,3 +59,5 @@ GraphvizSetAttr(e, "label=\"Entity Relation Diagram\ndrawn by NEATO\"");
GraphvizSetAttr(e, "fontsize=\"20\"");

Print(AsString(e));
Splash(e);
QUIT;
14 changes: 13 additions & 1 deletion examples/fsm.gi → examples/fsm.g
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#############################################################################
##
## fsm.g
## Copyright (C) 2024 Matthew Pancer
##
## Licensing information can be found in the README file of this package.
##
#############################################################################
##

# https://graphviz.readthedocs.io/en/stable/examples.html
# """https://graphviz.org/Gallery/directed/fsm.html"""
# https://graphviz.org/Gallery/directed/fsm.html
LoadPackage("graphviz");

f := GraphvizDigraph("finite_state_machine");
Expand Down Expand Up @@ -31,3 +41,5 @@ GraphvizSetAttr(GraphvizAddEdge(nodes, "LR_8", "LR_6"), "label", "\"S(b)\"");
GraphvizSetAttr(GraphvizAddEdge(nodes, "LR_8", "LR_5"), "label", "\"S(a)\"");

Print(AsString(f));
Splash(f);
QUIT;
14 changes: 13 additions & 1 deletion examples/g_c_n.gi → examples/g_c_n.g
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#############################################################################
##
## g_c_n.g
## Copyright (C) 2024 Matthew Pancer
##
## Licensing information can be found in the README file of this package.
##
#############################################################################
##

# https://graphviz.readthedocs.io/en/stable/examples.html
# """https://www.graphviz.org/Gallery/gradient/g_c_n.html"""
# https://www.graphviz.org/Gallery/gradient/g_c_n.html

LoadPackage("graphviz");

Expand All @@ -16,3 +26,5 @@ GraphvizSetAttr(cluster1, Concatenation(
GraphvizAddNode(cluster1, "anode");

Print(AsString(g));
Splash(g);
QUIT;
17 changes: 17 additions & 0 deletions examples/hello.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#############################################################################
##
## hello.g
## Copyright (C) 2024 Matthew Pancer
##
## Licensing information can be found in the README file of this package.
##
#############################################################################
##

# https://graphviz.readthedocs.io/en/stable/examples.html
LoadPackage("graphviz");
graph := GraphvizDigraph("G");
GraphvizAddEdge(graph, "hello", "world");
Print(AsString(graph));
Splash(graph);
QUIT;
6 changes: 0 additions & 6 deletions examples/hello.gi

This file was deleted.

Loading
Loading