Skip to content

Commit ac729d1

Browse files
authored
Make HypergraphPlot not listable (#669)
## Changes * Removes listability from `HypergraphPlot` ## Comments * By doing this, vertices that are lists themselves are now supported: ```wl (* In[]:= *) HypergraphPlot[{{{1}}, {{1, 1}}, {{1, 2, 3}}}, ImageSize -> 100] ``` <img width="224" alt="image" src="https://user-images.githubusercontent.com/40190339/134544030-fa5f010a-85fd-4b3d-8973-1add17246c1d.png"> ## Examples * Before: ```wl (* In[]:= *) HypergraphPlot[{{{1}}, {{1, 1}}, {{1, 2, 3}}}, ImageSize -> 100] ``` <img width="602" alt="image" src="https://user-images.githubusercontent.com/40190339/134544199-b8b2f551-716b-43cd-bbaa-26233c8af01a.png"> * Now: ```wl (* In[]:= *) HypergraphPlot[#, ImageSize -> 100] & /@ {{{1}}, {{1, 1}}, {{1, 2, 3}}} ``` <img width="602" alt="image" src="https://user-images.githubusercontent.com/40190339/134544221-edfde139-6a22-43fd-8d55-645614ebf569.png"> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/maxitg/setreplace/669) <!-- Reviewable:end -->
1 parent af39d5f commit ac729d1

File tree

4 files changed

+15
-65
lines changed

4 files changed

+15
-65
lines changed
-41.9 KB
Binary file not shown.

Documentation/SymbolsAndFunctions/HypergraphPlot.md

+4-17
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ Edges of any arity can be mixed. The binary edges are displayed as non-filled ar
2222
circles around the vertices:
2323

2424
```wl
25-
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4}, {4, 3}, {4, 5,
26-
6}, {1}, {6}, {6}}]
25+
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4}, {4, 3}, {4, 5, 6}, {1}, {6}, {6}}]
2726
```
2827

2928
<img src="/Documentation/Images/BinaryAndUnaryEdgesPlot.png" width="478">
@@ -48,22 +47,11 @@ Multiedges are shown in a darker color (because of overlaid partially transparen
4847
depending on the layout (and are admittedly sometimes hard to understand):
4948

5049
```wl
51-
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {3, 4, 5}, {1, 6, 6}, {1, 6,
52-
6}}]
50+
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {3, 4, 5}, {1, 6, 6}, {1, 6, 6}}]
5351
```
5452

5553
<img src="/Documentation/Images/MultiedgesPlot.png" width="478">
5654

57-
`HypergraphPlot` is listable. Multiple hypergraphs can be plotted at the same time:
58-
59-
```wl
60-
In[] := HypergraphPlot[{{{1, 2, 3}},
61-
{{1, 2, 3}, {3, 4, 5}},
62-
{{1, 2, 3}, {3, 4, 5}, {5, 6, 7}}}]
63-
```
64-
65-
<img src="/Documentation/Images/MultiplePlots.png" width="698">
66-
6755
Many [`WolframModel`](WolframModelAndWolframModelEvolutionObject/WolframModelAndWolframModelEvolutionObject.md)
6856
properties, such as [`"FinalStatePlot"`](WolframModelAndWolframModelEvolutionObject/Properties/PlotsOfStates.md)
6957
and [`"EventStatesPlotsList"`](WolframModelAndWolframModelEvolutionObject/Properties/PlotsOfEvents.md),
@@ -216,14 +204,13 @@ In[] := HypergraphPlot[{{1, 2, 2}, {2, 3, 3}, {3, 1, 1}},
216204
hypergraphs. To demonstrate that, consider the difference:
217205

218206
```wl
219-
In[] := HypergraphPlot[{{{1}}, {{1, 1}}, {{1, 2, 3}}},
220-
"MaxImageSize" -> 100]
207+
In[] := HypergraphPlot[#, "MaxImageSize" -> 100] & /@ {{{1}}, {{1, 1}}, {{1, 2, 3}}}
221208
```
222209

223210
<img src="/Documentation/Images/PlotWithMaxImageSize.png" width="254">
224211

225212
```wl
226-
In[] := HypergraphPlot[{{{1}}, {{1, 1}}, {{1, 2, 3}}}, ImageSize -> 100]
213+
In[] := HypergraphPlot[#, ImageSize -> 100] & /@ {{{1}}, {{1, 1}}, {{1, 2, 3}}}
227214
```
228215

229216
<img src="/Documentation/Images/PlotWithImageSize.png" width="457">

Kernel/HypergraphPlot.m

+9-29
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,22 @@
7777

7878
hypergraphPlot[args___] /; !Developer`CheckArgumentCount[HypergraphPlot[args], 1, 2] := $Failed;
7979

80-
(* allow composite vertices, but not list-vertices *)
81-
$hypergraphPattern = _List ? (Function[h, AllTrue[h, ListQ[#] && Length[#] > 0 &] && AllTrue[h, Not @* ListQ, 2]]);
82-
$multiHypergraphPattern = $hypergraphPattern | {$hypergraphPattern...};
80+
$hypergraphPattern = _List ? (Function[h, VectorQ[h, (ListQ[#] && (# =!= {})) &]]);
8381

8482
declareMessage[
8583
General::invalidEdges,
86-
"First argument of HypergraphPlot must be a hypergraph, i.e., a list of lists, " <>
87-
"where elements represent vertices, or a list of such hypergraphs."];
84+
"First argument of HypergraphPlot must be a hypergraph, i.e., a list of lists, where elements represent vertices."];
8885

89-
hypergraphPlot[Except[$multiHypergraphPattern], _ : $defaultEdgeType, OptionsPattern[]] :=
86+
hypergraphPlot[Except[$hypergraphPattern], _ : $defaultEdgeType, OptionsPattern[]] :=
9087
throw[Failure["invalidEdges", <||>]];
9188

9289
declareMessage[General::invalidEdgeType, "Edge type `type` should be one of `allowedTypes`."];
9390

94-
hypergraphPlot[$multiHypergraphPattern,
95-
edgeType : Except[Alternatives[Alternatives @@ $edgeTypes, OptionsPattern[]]],
96-
OptionsPattern[]] :=
91+
hypergraphPlot[$hypergraphPattern,
92+
edgeType : Except[Alternatives[Alternatives @@ $edgeTypes, OptionsPattern[]]],
93+
OptionsPattern[]] :=
9794
throw[Failure["invalidEdgeType", <|"type" -> edgeType, "allowedTypes" -> $edgeTypes|>]];
9895

99-
hypergraphPlot[
100-
edges : {$hypergraphPattern..}, edgeType : Alternatives @@ $edgeTypes : $defaultEdgeType, o : OptionsPattern[]] := (
101-
checkHypergraphPlotOptions[HypergraphPlot, edges, {o}];
102-
hypergraphPlot[#, edgeType, o] & /@ edges
103-
);
104-
10596
parseHighlight[_, _, {}, _] := ConstantArray[Automatic, 3];
10697

10798
parseHighlight[vertices_, edges_, highlightList_, highlightStyle_] := ModuleScope[
@@ -210,12 +201,8 @@
210201
checkSize["Vertex size", OptionValue[HypergraphPlot, options, VertexSize], {}];
211202
checkSize["Arrowhead length", OptionValue[HypergraphPlot, options, "ArrowheadLength"], {Automatic}];
212203
checkPlotStyle[OptionValue[HypergraphPlot, options, PlotStyle]];
213-
checkStyleLength["vertices",
214-
MatchQ[edges, {$hypergraphPattern..}],
215-
Length[vertexList[edges]],
216-
OptionValue[HypergraphPlot, options, VertexStyle]];
217-
checkStyleLength[
218-
"edges", MatchQ[edges, {$hypergraphPattern..}], Length[edges], OptionValue[HypergraphPlot, options, #]] & /@
204+
checkStyleLength["vertices", Length[vertexList[edges]], OptionValue[HypergraphPlot, options, VertexStyle]];
205+
checkStyleLength["edges", Length[edges], OptionValue[HypergraphPlot, options, #]] & /@
219206
{EdgeStyle, "EdgePolygonStyle"};
220207
);
221208

@@ -247,19 +234,12 @@
247234

248235
checkPlotStyle[style_List] := throw[Failure["invalidPlotStyle", <|"plotStyle" -> style|>]];
249236

250-
(* Single hypergraph *)
251237
declareMessage[General::invalidStyleLength,
252238
"The list of styles `styles` should have the same length `correctLength` as the number of `name`."];
253239

254-
checkStyleLength[name_, False, correctLength_, styles_List] /; Length[styles] =!= correctLength :=
240+
checkStyleLength[name_, correctLength_, styles_List] /; Length[styles] =!= correctLength :=
255241
throw[Failure["invalidStyleLength", <|"styles" -> styles, "name" -> name, "correctLength" -> correctLength|>]];
256242

257-
(* Multiple hypergraphs *)
258-
declareMessage[General::multigraphElementwiseStyle,
259-
"The elementwise style specification `styleSpec` is not supported for lists of hypergraphs."];
260-
261-
checkStyleLength[_, True, _, styles_List] := throw[Failure["multigraphElementwiseStyle", <|"styleSpec" -> styles|>]];
262-
263243
(* Implementation *)
264244

265245
hypergraphPlotImplementation[

Tests/HypergraphPlot.wlt

+2-19
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,8 @@
111111
],
112112

113113
VerificationTest[
114-
graphicsQ /@ HypergraphPlot[{{}}],
115-
{True}
116-
],
117-
118-
testUnevaluated[
119-
HypergraphPlot[{{{}}}],
120-
{HypergraphPlot::invalidEdges}
114+
graphicsQ @ HypergraphPlot[{}],
115+
True
121116
],
122117

123118
testUnevaluated[
@@ -656,18 +651,6 @@
656651
]
657652
],
658653

659-
(* Multiple hypergraphs *)
660-
VerificationTest[
661-
graphicsQ /@ HypergraphPlot[{{{1, 2, 3}, {3, 4, 5}}, {{3, 4, 5}, {5, 6, 7}}, {{5, 6, 7}, {7, 8, 5}}}, ##],
662-
ConstantArray[True, 3]
663-
] & @@@ {
664-
{},
665-
{GraphHighlight -> {3, {3, 4, 5}}},
666-
{VertexSize -> 0.1, "ArrowheadLength" -> 0.2},
667-
{EdgeStyle -> Red},
668-
{VertexCoordinates -> {3 -> {0, 0}, 4 -> {1, 0}}}
669-
},
670-
671654
(* GraphHighlight and style interaction *)
672655

673656
With[{color1 = RGBColor[0.46, 0.51, 0.87], color2 = RGBColor[0.13, 0.64, 0.27]},

0 commit comments

Comments
 (0)