This repository was archived by the owner on Jun 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
0.4.0 improvements #53
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5a1da59
[visualizer] Added back topology object to context
nemesifier 845325f
[js] Minor coding style improvements
nemesifier d0a6b68
[js] Removed redundant jquery static file
nemesifier bbdf55c
[history] Simplified topology history
nemesifier 6788e9c
[history] Improved usability and look
nemesifier dafb1d3
[history] Simplified topology history JS logic
nemesifier d7bce53
[history] Added missing jquery ui datepicker icons
nemesifier cf3741f
[history] Renamed topology-switcher.js to topology-history.js
nemesifier e8d0410
[history] Improved history API error messages
nemesifier 06b2a7a
[history] Display error message if no snapshot is found
nemesifier c457142
[history] Move node overlay on bottom right corner
nemesifier 9c7474f
[visualizer] Added {% trans %} tags for english words
nemesifier ce57016
[admin] Removed unused error handling code in visualize.js
nemesifier e7e5555
[tests] Renamed base test classes for consistency
nemesifier 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
38 changes: 16 additions & 22 deletions
38
django_netjsongraph/static/netjsongraph/js/topology-switcher.js
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,32 +1,26 @@ | ||
| $(function() { | ||
| window.initTopologyHistory = function($){ | ||
| $('#dp').datepicker(); | ||
| d = new Date(); | ||
| month = d.getMonth() + 1; | ||
| day = d.getDate(); | ||
| defaultDate = (month < 10 ? '0' : '') + month + '/' + | ||
| (day < 10 ? '0' : '') + day + '/' + | ||
| d.getFullYear(); | ||
| var d = new Date(), | ||
| month = d.getMonth() + 1, | ||
| day = d.getDate(), | ||
| defaultDate = (month < 10 ? '0' : '') + month + '/' + | ||
| (day < 10 ? '0' : '') + day + '/' + d.getFullYear(), | ||
| currentDate = d.getFullYear() + '-' + (month < 10 ? '0' : '') + | ||
| month + '-' + (day < 10 ? '0' : '') + day; | ||
| $('#dp').val(defaultDate); | ||
| currentDate = d.getFullYear() + '-' + | ||
| (month < 10 ? '0' : '') + month + '-' + | ||
| (day < 10 ? '0' : '') + day; | ||
| $('#submit').click(function() { | ||
| queryDate = $('#dp').val(); | ||
| date = queryDate.split('/').reverse(); | ||
| var queryDate = $('#dp').val(), | ||
| date = queryDate.split('/').reverse(), | ||
| graphUrl; | ||
| if(date != []){ | ||
| var x = date[1]; | ||
| date[1] = date[2]; | ||
| date[2] = x; | ||
| } | ||
| date = date.join('-'); | ||
| graphUrl = $('.switcher').attr('graph-url') + '?date=' + date; | ||
| if(currentDate == date){ | ||
| graphUrl = window.location.href; | ||
| } | ||
| body = $('body'); | ||
| $.get(graphUrl, function(html) { | ||
| body.html(html); | ||
| $('#dp').val(queryDate); | ||
| }); | ||
| graphUrl = $('.switcher').attr('data-history-api') + '?date=' + date; | ||
| // load latest data when looking currentDate | ||
| if(currentDate == date){ graphUrl = undefined } | ||
| window.graph = window.loadNetJsonGraph(graphUrl); | ||
| }); | ||
| }); | ||
| }; |
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
8 changes: 8 additions & 0 deletions
8
django_netjsongraph/templates/netjsongraph/netjsongraph-content.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <div id="legend"> | ||
| <p><span class="link up"> </span> link up</p> | ||
| <p><span class="link down"> </span> link down</p> | ||
| </div> | ||
| <div class="switcher" data-history-api="{{ history_url }}"> | ||
| <label for="dp">Date </label><input type="text" id="dp"> | ||
| <button id="submit">Submit</button> | ||
| </div> |
35 changes: 25 additions & 10 deletions
35
django_netjsongraph/templates/netjsongraph/netjsongraph-script.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,27 @@ | ||
| <script> | ||
| var graph = d3.netJsonGraph("{{ api_url }}", { | ||
| linkClassProperty: "status", | ||
| defaultStyle: false, | ||
| labelDy: "-1.5em", | ||
| circleRadius: 7, | ||
| charge: -300, | ||
| gravity: 0.1, | ||
| linkDistance: 70, | ||
| linkStrength: 0.1 | ||
| }); | ||
| // the graph may be loaded elsewhere than body | ||
| window.__njg_el__ = window.__njg_el__ || "body"; | ||
| // loadGraph wrapper is used to reload | ||
| // the graph with data from older snapshots | ||
| window.loadNetJsonGraph = function(url){ | ||
| url = url || "{{ graph_url }}"; | ||
| // destroy HTML elements if present | ||
| d3.select("svg").remove(); | ||
| d3.select(".njg-overlay").remove(); | ||
| d3.select(".njg-metadata").remove(); | ||
| // load graph | ||
| return d3.netJsonGraph(url, { | ||
| el: window.__njg_el__, | ||
| linkClassProperty: "status", | ||
| defaultStyle: false, | ||
| labelDy: "-1.5em", | ||
| circleRadius: 7, | ||
| charge: -300, | ||
| gravity: 0.1, | ||
| linkDistance: 70, | ||
| linkStrength: 0.1 | ||
| }); | ||
| }; | ||
| window.graph = window.loadNetJsonGraph(); | ||
| window.initTopologyHistory(jQuery); | ||
| </script> | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is amazing! Didn't know we could do all these 😮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not optimal because not very easy to read, but a more elegant solution would require more time.
we basically reuse this piece of code to load and reload the graph in frontend, admin and when loading older snapshots, the difference is that in the admin we set
window.__njg_el__to the overlay, and when using snapshots we first fetch the data from the API and then pass the data in the graph directly to the library.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I understand. I really liked how you made it reusable