Skip to content

Some improvements and additions to the SimpleGraph.pl macro.#1379

Open
drgrice1 wants to merge 6 commits intoopenwebwork:developfrom
drgrice1:simplegraph-improvements
Open

Some improvements and additions to the SimpleGraph.pl macro.#1379
drgrice1 wants to merge 6 commits intoopenwebwork:developfrom
drgrice1:simplegraph-improvements

Conversation

@drgrice1
Copy link
Member

@drgrice1 drgrice1 commented Mar 4, 2026

First, change the weight color used from red to FireBrick. This color has a contrast ratio of 6.68 against the white background. The red color has a contrast ration of 4.00 which is not sufficient for accessibility purposes.

Second, improve label positioning. Instead of trying to place the labels using the coordinates, use the anchor and padding options to get better positioning. The primary advantage is now the labels don't float away when the image is enlarged. This was not done originally because at the time this macro was implemented the anchor and padding options didn't exist.

The weights for the default layout and the wheel layout are still positioned along the perpendicular vector for now. The problem is that those labels are rotated, and that does not work well with the anchor. This is a TikZ issue (I implemented the anchor for JSXGraph to work the same as the TikZ anchor option). The problem is that the rotation is around the position of the anchor, and not around the center of the text. The usual solution for this in TikZ is to use a \rotatebox on the node contents. Perhaps another rotation option could be addded to the plots macro that would rotate the text instead of rotating around the anchor position.

Third, add a components method that returns the components of the graph. The method returns an array containing references to arrays that form a partition the vertex indices into the connected components of the graph. For example, for the graph with vertices E, F, G, H, I, J, K, and L, and edge set {{{E, L}, {F, G}, {F, L}, {G, J}, {H, I}, {J, K}, {J, L}}}, the method will return ([E, F, G, J, K, L], [H, I]).

This color has a contrast ratio of 6.68 against the white background.
The red color has a contrast ration of 4.00 which is not sufficient for
accessibility purposes.
The method returns an array containing references to arrays that form a
partition the vertex indices into the connected components of the graph.
For example, for the graph with vertices E, F, G, H, I, J, K, and L, and
edge set {{{E, L}, {F, G}, {F, L}, {G, J}, {H, I}, {J, K}, {J, L}}}, the
method will return ([E, F, G, J, K, L], [H, I]).
@drgrice1 drgrice1 changed the base branch from main to develop March 4, 2026 02:20
Instead of trying to place the labels using the coordinates, use the
`anchor` and padding options to get better positioning.  The primary
advantage is now the labels don't float away when the image is enlarged.
This was not done originally because at the time this macro was
implemented the `anchor` and `padding` options didn't exist.

The weights for the default layout and the wheel layout are still
positioned along the perpendicular vector for now.  The problem is that
those labels are rotated, and that does not work well with the anchor.
This is a TikZ issue (I implemented the anchor for JSXGraph to work the
same as the TikZ anchor option).  The problem is that the rotation is
around the position of the anchor, and not around the center of the
text. The usual solution for this in TikZ is to use a `\rotatebox` on
the node contents. Perhaps another rotation option could be addded to
the plots macro that would rotate the text instead of rotating around
the anchor position.
@drgrice1 drgrice1 force-pushed the simplegraph-improvements branch from 869f31c to 2abaee7 Compare March 4, 2026 11:45
an invalid edge set for a graph with a single edge.
@drgrice1 drgrice1 force-pushed the simplegraph-improvements branch from d0eca9c to da670d0 Compare March 4, 2026 21:26
@drgrice1
Copy link
Member Author

drgrice1 commented Mar 4, 2026

There is one more change that I just added. It is a bug fix. The edgeSet method was not creating a valid GraphTheory::SimpleGraph::Value::EdgeSet object if a graph happened to have exactly one edge. To fix that the last argument to the GraphTheory::SimpleGraph::Value::EdgeSet new method needed to be passed as an array reference instead of just an array.

@drgrice1
Copy link
Member Author

drgrice1 commented Mar 6, 2026

Another change added. Improvements to the sortedEdgesPath method. See the updated POD and last commit message for details.

@drgrice1 drgrice1 force-pushed the simplegraph-improvements branch from a153ae2 to 92eeadf Compare March 6, 2026 13:33
First, the method is now quite a bit more efficient.  Rather than
finding and sorting only the weights of the edges in the graph, and then
searching through the graph to find those edges at each step in the
algorithm, the edges with the weights are all listed and sorted by
weight (more like the actual sorted edges algorithm works).  So there is
no need to find the edge later, you just follow the algorithm and
process the edges in order.

Second, the return value of the method is reordered and more data
returned.  See the updated POD for good documentation on what is
returned.

This makes the method return a lot more useful information that can be
used for constructing a solution to problems using the sorted edges
algorithm.
@drgrice1 drgrice1 force-pushed the simplegraph-improvements branch from 92eeadf to c67600d Compare March 6, 2026 15:02
@drgrice1
Copy link
Member Author

drgrice1 commented Mar 6, 2026

One more change added. Improvements to the kruskalGraph method. See the updated POD and last commit message for details. This change parallels the changes made to the sortedEdgesPath method.

First, the method is now quite a bit more efficient.  Rather than
finding and sorting only the weights of the edges in the graph, and then
searching through the graph to find those edges at each step in the
algorithm, the edges with the weights are all listed and sorted by
weight (more like the actual sorted edges algorithm works).  So there is
no need to find the edge later, you just follow the algorithm and
process the edges in order.

Also make the algorithm terminate once the minimal spanning tree is
complete as it should.

Second, the return value of the method returns more data. See the
updated POD for good documentation on what is returned.

This makes the method return more useful information that can be used
for constructing a solution to problems using the sorted edges
algorithm.

These is the basically the same changes that were made for the
`sortedEdgesPath` method.
@drgrice1 drgrice1 force-pushed the simplegraph-improvements branch from e92ff39 to 924c2fe Compare March 6, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant