Skip to content

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

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

Some improvements and additions to the SimpleGraph.pl macro.#1379
drgrice1 wants to merge 3 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
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