Skip to content

Commit b5991a5

Browse files
authored
Improve visualization performance (substantially) (#109)
* fix: moved image generation to avoid severe performance issues * fix: moved button finding code before data handling * fix: fixed leftover invalid variable naming
1 parent de92627 commit b5991a5

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

netbox_topology_views/static/netbox_topology_views/js/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox_topology_views/static_dev/js/home.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,24 @@ function iniPlotboxIndex() {
7878
csrftoken = getCookie('csrftoken');
7979
container = document.getElementById('visgraph');
8080
htmlElement = document.getElementsByTagName("html")[0];
81-
handleLoadData();
8281
downloadButton = document.getElementById('btnDownloadImage');
82+
handleLoadData();
8383
btnFullView = document.getElementById('btnFullView');
8484
coord_save_checkbox = document.getElementById('id_save_coords');
8585
}, false);
8686
}
8787

88+
function performGraphDownload() {
89+
var tempDownloadLink = document.createElement('a');
90+
var generatedImageUrl = canvas.toDataURL(MIME_TYPE);
91+
92+
tempDownloadLink.href = generatedImageUrl;
93+
tempDownloadLink.download = "topology";
94+
document.body.appendChild(tempDownloadLink);
95+
tempDownloadLink.click();
96+
document.body.removeChild(tempDownloadLink);
97+
}
98+
8899
function handleLoadData() {
89100
if (topology_data !== null) {
90101

@@ -103,11 +114,7 @@ function handleLoadData() {
103114
graph.fit();
104115
canvas = document.getElementById('visgraph').getElementsByTagName('canvas')[0];
105116

106-
graph.on('afterDrawing', function () {
107-
var image = canvas.toDataURL(MIME_TYPE);
108-
downloadButton.href = image;
109-
downloadButton.download = "topology";
110-
});
117+
downloadButton.onclick = function(e) { performGraphDownload(); return false; };
111118

112119
graph.on("dragEnd", function (params) {
113120
dragged = this.getPositions(params.nodes);

netbox_topology_views/templates/netbox_topology_views/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<div class="controls">
1717
<div class="control-group">
1818
{% block extra_controls %}{% endblock %}
19-
<a id="btnDownloadImage" class="btn btn-sm btn-info">
19+
<a id="btnDownloadImage" class="btn btn-sm btn-info" href="#">
2020
<i class="mdi mdi-download"></i>
2121
Download
2222
</a>

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)