-
Notifications
You must be signed in to change notification settings - Fork 3
Basic Visualisation #15
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
Open
danpalmer
wants to merge
69
commits into
master
Choose a base branch
from
visualisation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
04722ad
First pass at state machite visualisation
danpalmer 5929e3c
Merge branch 'master' into visualisation
danpalmer 9f15757
Improve styling
danpalmer 5d1f35e
Merge branch 'master' into visualisation
PeterJCLaw 293b056
Merge branch 'master' into visualisation
PeterJCLaw 83ee7ac
Clarify that this is a collection
PeterJCLaw 698f2f8
Expect this endpoint to exist too
PeterJCLaw 9a531b4
These are collections too
PeterJCLaw 2767516
Merge branch 'master' into visualisation
PeterJCLaw 331a351
Add alternative using Cytoscape
PeterJCLaw b51c976
Don't need to prettify this
PeterJCLaw 28846c7
Drop draw_state_machine
PeterJCLaw ba45628
Simplify the return type
PeterJCLaw 70bfa80
Type signature here
PeterJCLaw a52bc9b
isort
PeterJCLaw ead96ab
Drop redundant inline style
PeterJCLaw 7c83fc8
Fix indentation
PeterJCLaw a712785
Slightly better colours
PeterJCLaw 345837a
Drop more dead code
PeterJCLaw 16e0b18
Merge branch 'master' into visualisation
PeterJCLaw 021f0c4
Template this properly
PeterJCLaw 2c48ba1
Actually template in the state machine name
PeterJCLaw 0335279
Add a smoke test for the visualisation endpoint
PeterJCLaw 284a79f
Explicitly annotate this
PeterJCLaw 2ab8943
We don't need pydot now that we're using cytoscape
PeterJCLaw ed5f4dd
No need to duplicate the id as the name
PeterJCLaw 13cb98f
Make this test pass
PeterJCLaw 8722e5b
Expand these tests to check the result
PeterJCLaw ce5a5da
Rename for clarity
PeterJCLaw f09da3f
Drop unused styling
PeterJCLaw 5a53abc
Just drop this inline; no need to parse it separately
PeterJCLaw 0028822
Drop default values
PeterJCLaw 338ac6a
Drop comments
PeterJCLaw 8c58dd1
Link to relevant docs
PeterJCLaw ce917ee
Add a legend for the node types
PeterJCLaw 5520840
Let the user choose the spacing
PeterJCLaw f76ebcc
Calculate an initial spacing based on the number of nodes
PeterJCLaw 3230375
Fade the control bar some more
PeterJCLaw 63ede8c
Add an instruction
PeterJCLaw 6a2a22a
Simplify this lookup
PeterJCLaw 4849134
Remove unused imports
PeterJCLaw a8eb759
isort
PeterJCLaw 956c59e
Add a zoom slider too
PeterJCLaw 82a75ae
Configure scroll zooming sensitivity instead of providing our own
PeterJCLaw 4dca5d4
Allow an adjustment once layed out
PeterJCLaw aaf1ec8
Fit to the display window
PeterJCLaw 92416b9
Also test the 404 case
PeterJCLaw a2f3e85
Extract fixture for the root path of the repo
PeterJCLaw 11a9e81
Rename for clarity
PeterJCLaw 1171013
Use system fonts
PeterJCLaw 00a0eb3
Indentation
PeterJCLaw f98ad5f
Rename file to clarify rendering
PeterJCLaw fd2c457
Include the template in the manifest
PeterJCLaw db7f349
Simplify this
PeterJCLaw f891b93
Not SVG
PeterJCLaw dcbc51f
Assert the content type
PeterJCLaw 4b9d8c0
Name this type for clarity when used
PeterJCLaw 8c07681
This isn't just HTML any more
PeterJCLaw 4b5d3a7
Switch to the minified version of the library
PeterJCLaw b0b05cb
Subresource integrity the external library
PeterJCLaw 7d4edd2
No need to return false here
PeterJCLaw d5c676d
Explicitly parse the config as JSON
PeterJCLaw b24c25d
Merge branch 'master' into visualisation
PeterJCLaw 0e9e49c
Connect event up in JS rather than inline
PeterJCLaw 23689dc
Fix lints
PeterJCLaw fd59e2f
Update visualisation test for data loading changes on master branch
PeterJCLaw e146e8a
Update cytoscape
PeterJCLaw f717068
Adjust spacing presets to cope with larger workflows
PeterJCLaw 277c214
Add labels for exit conditions to edges between nodes
PeterJCLaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| include version.py | ||
| include routemaster/config/schema.yaml | ||
| include routemaster/config/visualisation.jinja |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <style> | ||
| body { | ||
| font-size: 14px; | ||
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; | ||
| margin: 0; | ||
| } | ||
| #graph-container { | ||
| height: 100%; | ||
| width: 100%; | ||
| position: absolute; | ||
| left: 0; | ||
| top: 3.5em; | ||
| } | ||
| #controls { | ||
| background-color: #f0f0f0; | ||
| margin: 0; | ||
| } | ||
| #controls div { | ||
| display: inline-block; | ||
| padding: 0.5em; | ||
| margin-right: 0.2em; | ||
| } | ||
| .range-input-container { | ||
| top: 0.5em; | ||
| position: relative; | ||
| } | ||
| .muted { | ||
| color: #666666; | ||
| } | ||
| .action { | ||
| background-color: orange; | ||
| } | ||
| .gate { | ||
| background-color: lightBlue; | ||
| } | ||
| </style> | ||
| <title>Visualisation of state machine {{ state_machine_name }}</title> | ||
| </head> | ||
| <body> | ||
| <script type="application/json" id="state-machine-config"> | ||
| {{ state_machine_config|tojson }} | ||
| </script> | ||
| <script | ||
| src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.21.0/cytoscape.min.js" | ||
| integrity="sha512-6NNH8uUbdENB10r5FH/4DZviHTQ44GtZ+c+fwSiWM4GekjajHkYanpH0+jWt3meFll/HHWAcxKLcMpSAXuT/Dg==" | ||
| crossorigin="anonymous" | ||
| referrerpolicy="no-referrer" | ||
| ></script> | ||
| <div id="controls"> | ||
| <div id="legend"> | ||
| <div class="action">action</div> | ||
| <div class="gate">gate</div> | ||
| </div> | ||
| <div> | ||
| <label> | ||
| Spacing: | ||
| <span class="range-input-container"> | ||
| <input id="spacing-factor" type="range" min="1" max="50" step="0.1"> | ||
| </span> | ||
| <span id="spacing-factor-display"></span> | ||
| </label> | ||
| </div> | ||
| <div class="muted">Click and drag to move the graph; scroll to zoom</div> | ||
| </div> | ||
| <div id="graph-container"></div> | ||
| <script> | ||
| function backgroundColourForNodeClass(nodeClass) { | ||
| var style = getComputedStyle(document.querySelector('#legend ' + nodeClass)); | ||
| return style.backgroundColor; | ||
| } | ||
|
|
||
| var layoutOptions = { | ||
| // http://js.cytoscape.org/#layouts/breadthfirst | ||
| name: 'breadthfirst', | ||
| fit: true, | ||
| directed: true, | ||
| padding: 30, | ||
| spacingFactor: 1.35, | ||
| avoidOverlap: false, | ||
| nodeDimensionsIncludeLabels: false, | ||
| maximalAdjustments: 1, | ||
| }; | ||
|
|
||
| function precisionRound(number, precision) { | ||
| var factor = Math.pow(10, precision); | ||
| return Math.round(number * factor) / factor; | ||
| } | ||
|
|
||
| function displaySpacingFactor() { | ||
| document.getElementById('spacing-factor-display').innerHTML = precisionRound(layoutOptions.spacingFactor * 10, 1); | ||
| } | ||
|
|
||
| function parseConfig(elementId) { | ||
| return JSON.parse(document.getElementById(elementId).innerHTML); | ||
| } | ||
|
|
||
| var cy = cytoscape({ | ||
| container: document.getElementById('graph-container'), | ||
|
|
||
| boxSelectionEnabled: false, | ||
| autounselectify: true, | ||
| wheelSensitivity: 0.1, | ||
|
|
||
| style: cytoscape.stylesheet() | ||
| .selector() | ||
| .css({ | ||
| 'font-family': getComputedStyle(document.body).fontFamily, | ||
| }) | ||
| .selector('node') | ||
| .css({ | ||
| 'content': 'data(id)', | ||
| 'text-valign': 'center', | ||
| 'color': 'black', | ||
| }) | ||
| .style({ | ||
| 'shape': 'square', | ||
| 'width': 'label', | ||
| 'height': 'label', | ||
| 'padding': '1em', | ||
| }) | ||
| .selector('edge') | ||
| .css({ | ||
| 'curve-style': 'bezier', | ||
| 'target-arrow-shape': 'triangle', | ||
| 'target-arrow-color': '#ccc', | ||
| 'line-color': '#ccc', | ||
| 'text-wrap': 'wrap', | ||
| 'text-max-width': 80, | ||
| 'width': 1 | ||
| }) | ||
| .style({ | ||
| 'label': 'data(label)', | ||
| }) | ||
| .selector(':selected') | ||
| .css({ | ||
| 'background-color': 'black', | ||
| 'line-color': 'black', | ||
| 'target-arrow-color': 'black', | ||
| 'source-arrow-color': 'black' | ||
| }) | ||
| .selector('.action') | ||
| .css({ | ||
| 'background-color': backgroundColourForNodeClass('.action'), | ||
| }) | ||
| .selector('.gate') | ||
| .css({ | ||
| 'background-color': backgroundColourForNodeClass('.gate'), | ||
| }), | ||
|
|
||
| elements: parseConfig('state-machine-config'), | ||
|
|
||
| layout: layoutOptions | ||
| }); | ||
|
|
||
| function changeSpacing(value) { | ||
| layoutOptions.spacingFactor = value; | ||
| displaySpacingFactor(); | ||
| cy.layout(layoutOptions).run(); | ||
| } | ||
|
|
||
| var initialSpacingFactor = 0.5 + cy.nodes().length * 0.05; | ||
| var spacingFactorElem = document.getElementById('spacing-factor'); | ||
| spacingFactorElem.addEventListener('change', function() { | ||
| changeSpacing(spacingFactorElem.value / 10); | ||
| }) | ||
| spacingFactorElem.value = initialSpacingFactor * 10; | ||
| changeSpacing(initialSpacingFactor); | ||
| </script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.