Skip to content

Commit

Permalink
WolframPhysicsProjectStyleData functions (#392)
Browse files Browse the repository at this point in the history
## Changes
* Adds a shorthand syntax to obtain all options used to style manually-constructed graphs.
* All single-vertex/edge-type graphs now have `"Options"` and `"Function"` properties:
  * `"Options"` gives a list of all options that need to be passed to `Graph` or `Graph3D`;
  * `"Function"` gives a function of a form `Graph[#, ...] &`, which restyles a given graph.

## Examples
* Style a manually constructed graph as a rulial graph:
```wl
In[] := WolframPhysicsProjectStyleData["RulialGraph", "Function"][
 Graph[{1 -> 2, 1 -> 3, 3 -> 4, 3 -> 5, 2 -> 5}]]
```
<img width="265" alt="image" src="https://user-images.githubusercontent.com/1479325/89804995-f41a4000-db02-11ea-80f2-61028a5d38ad.png">

* Get a list of options for a `"SpatialGraph3D"`:
```wl
In[] := WolframPhysicsProjectStyleData["SpatialGraph3D", "Options"]
```
<img width="521" alt="image" src="https://user-images.githubusercontent.com/1479325/89805040-07c5a680-db03-11ea-9969-2330a25c9309.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/392)
<!-- Reviewable:end -->
  • Loading branch information
maxitg authored Aug 10, 2020
1 parent 26868c8 commit d40cb49
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
34 changes: 24 additions & 10 deletions Kernel/style.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
PackageScope["$genericLinePlotStyles"]
PackageScope["$genericGraphEdgeStyle"]

combinedOptionsProperties[plotFunction_][options__] := Sequence[
"Options" -> {options},
"Function" -> (plotFunction[#, options] &)
]

$styleNames = KeySort /@ KeySort @ <|
"EvolutionObject" -> <|"Icon" -> $evolutionObjectIcon|>,
"SpatialGraph" -> <|
Expand All @@ -90,14 +95,16 @@
"HighlightStyle" -> $highlightStyle,
"HyperedgeRendering" -> $hyperedgeRendering,
"DefaultImageSize" -> $wolframModelPlotImageSize,
"Background" -> $spatialGraphBackground
"Background" -> $spatialGraphBackground,
combinedOptionsProperties[Graph][VertexStyle -> $vertexStyle, EdgeStyle -> $edgeLineStyle]
|>,
"CausalGraph" -> <|
"VertexStyle" -> $causalGraphVertexStyle,
"InitialVertexStyle" -> $causalGraphInitialVertexStyle,
"FinalVertexStyle" -> $causalGraphFinalVertexStyle,
"EdgeStyle" -> $causalGraphEdgeStyle,
"Background" -> $causalGraphBackground
"Background" -> $causalGraphBackground,
combinedOptionsProperties[Graph][VertexStyle -> $causalGraphVertexStyle, EdgeStyle -> $causalGraphEdgeStyle]
|>,
"ExpressionsEventsGraph" -> <|
"EventVertexStyle" -> $causalGraphVertexStyle,
Expand Down Expand Up @@ -131,18 +138,21 @@

"SpatialGraph3D" -> <|
"VertexStyle" -> $spatialGraph3DVertexStyle,
"EdgeLineStyle" -> $spatialGraph3DEdgeStyle
"EdgeLineStyle" -> $spatialGraph3DEdgeStyle,
combinedOptionsProperties[Graph3D][VertexStyle -> $spatialGraph3DVertexStyle, EdgeStyle -> $spatialGraph3DEdgeStyle]
|>,

(* MultiwaySystem styles *)

"StatesGraph" -> <|
"VertexStyle" -> $statesGraphVertexStyle,
"EdgeStyle" -> $statesGraphEdgeStyle
"EdgeStyle" -> $statesGraphEdgeStyle,
combinedOptionsProperties[Graph][VertexStyle -> $statesGraphVertexStyle, EdgeStyle -> $statesGraphEdgeStyle]
|>,
"StatesGraph3D" -> <|
"VertexStyle" -> $statesGraphVertexStyle, (* same as 2D *)
"EdgeStyle" -> $statesGraph3DEdgeStyle
"EdgeStyle" -> $statesGraph3DEdgeStyle,
combinedOptionsProperties[Graph][VertexStyle -> $statesGraphVertexStyle, EdgeStyle -> $statesGraph3DEdgeStyle]
|>,
"EvolutionCausalGraph" -> <|
"StateVertexStyle" -> $statesGraphVertexStyle,
Expand All @@ -152,24 +162,28 @@
|>,
"BranchialGraph" -> <|
"VertexStyle" -> $statesGraphVertexStyle,
"EdgeStyle" -> $branchialGraphEdgeStyle
"EdgeStyle" -> $branchialGraphEdgeStyle,
combinedOptionsProperties[Graph][VertexStyle -> $statesGraphVertexStyle, EdgeStyle -> $branchialGraphEdgeStyle]
|>,
"RulialGraph" -> <|
"VertexStyle" -> $rulialGraphVertexStyle,
"EdgeStyle" -> $rulialGraphEdgeStyle,
"VertexIconFontColor" -> $rulialGraphVertexIconFontColor,
"VertexIconBackground" -> $rulialGraphVertexIconBackground,
"VertexIconFrameStyle" -> $rulialGraphVertexIconFrameStyle,
"VertexIconFrameMargins" -> $rulialGraphVertexIconFrameMargins
"VertexIconFrameMargins" -> $rulialGraphVertexIconFrameMargins,
combinedOptionsProperties[Graph][VertexStyle -> $rulialGraphVertexStyle, EdgeStyle -> $rulialGraphEdgeStyle]
|>,

(* Generic plots *)

"GenericLinePlot" -> <|
"PlotStyles" -> $genericLinePlotStyles
"PlotStyles" -> $genericLinePlotStyles,
"Options" -> {PlotStyle -> $genericLinePlotStyles}
|>,
"GenericGraph" -> <|
"EdgeStyle" -> $genericGraphEdgeStyle
"EdgeStyle" -> $genericGraphEdgeStyle,
combinedOptionsProperties[Graph][EdgeStyle -> $genericGraphEdgeStyle]
|>
|>;

Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,25 @@ In[] := WolframPhysicsProjectStyleData["CausalGraph"]
This function is useful if one needs to produce "fake" example plots using styles consistent with the Wolfram Physics Project.
For graphs composed of only a single type of vertices and edges, there is a short-hand syntax.
One can get the list of all options that needs to be passed using an `"Options"` property:
```wl
In[] := WolframPhysicsProjectStyleData["SpatialGraph3D", "Options"]
```
<img src="READMEImages/SpatialGraph3DOptions.png" width="625">
Alternatively, one can use the `"Function"` property, which would give a function that takes a graph and produces a
correctly styled graph:
```wl
In[] := WolframPhysicsProjectStyleData["SpatialGraph3D", "Function"][
Graph3D[{1 -> 2, 2 -> 3, 3 -> 1, 3 -> 4, 4 -> 1}]]
```
<img src="READMEImages/FakeStyledSpatialGraph3D.png" width="478">
### Build Data
There are two constants containing information about the build. **`$SetReplaceGitSHA`** is a git SHA of the currently-used version of *SetReplace*:
Expand Down
Binary file added READMEImages/FakeStyledSpatialGraph3D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added READMEImages/SpatialGraph3DOptions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions Tests/WolframPhysicsProjectStyleData.wlt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@
MemberQ[
WolframPhysicsProjectStyleData /@ $WolframPhysicsProjectPlotThemes,
WolframPhysicsProjectStyleData[]]
],

VerificationTest[
Options[
Graph[{1 -> 2, 2 -> 3, 2 -> 4}, WolframPhysicsProjectStyleData["CausalGraph", "Options"]],
{VertexStyle, EdgeStyle}],
Options[
WolframPhysicsProjectStyleData["CausalGraph", "Function"][Graph[{1 -> 2, 2 -> 3, 2 -> 4}]],
{VertexStyle, EdgeStyle}]
]
}]
|>,
Expand Down

0 comments on commit d40cb49

Please sign in to comment.