Skip to content

Commit

Permalink
Cache jquery calls to reduce overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
drasmuss committed Feb 8, 2016
1 parent b94c9a8 commit 02583f4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
34 changes: 19 additions & 15 deletions nengo_gui/static/components/netgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ Nengo.NetGraph = function(parent, args) {
parent.appendChild(this.svg);
this.parent = parent;

this.old_width = $(this.svg).width();
this.old_height = $(this.svg).height();
this.width = $(this.svg).width();
this.height = $(this.svg).height();

this.tool_height = $(toolbar.toolbar).height();

/** three separate layers, so that expanded networks are at the back,
* then connection lines, and then other items (nodes, ensembles, and
Expand Down Expand Up @@ -203,9 +205,8 @@ Nengo.NetGraph = function(parent, args) {
event.preventDefault();

self.menu.hide_any();
var tool_h = $(toolbar.toolbar).height();
var x = (event.clientX) / $(self.svg).width()
var y = (event.clientY - tool_h) / $(self.svg).height();
var x = (event.clientX) / self.width
var y = (event.clientY - self.tool_height) / self.height;


switch (event.deltaMode) {
Expand Down Expand Up @@ -496,31 +497,31 @@ Nengo.NetGraph.prototype.on_resize = function(event) {
for (var key in this.svg_objects) {
var item = this.svg_objects[key];
if (item.depth == 1) {
var new_width = item.get_width()*
this.old_width/width / this.scale;
var new_height = item.get_height()*
this.old_height/height / this.scale;
var new_width = item.get_width() / this.scale;
var new_height = item.get_height() / this.scale;
item.size = [new_width/(2*width),
new_height/(2*height)]; }
}
}

this.old_width = width;
this.old_height = height;
this.width = width;
this.height = height;
this.mm_width = $(this.minimap).width();
this.mm_height = $(this.minimap).height();

this.redraw();
};


/** return the pixel width of the SVG times the current scale factor */
Nengo.NetGraph.prototype.get_scaled_width = function() {
return $(this.svg).width() * this.scale;
return this.width * this.scale;
}


/** return the pixel height of the SVG times the current scale factor */
Nengo.NetGraph.prototype.get_scaled_height = function() {
return $(this.svg).height() * this.scale;
return this.height * this.scale;
}


Expand Down Expand Up @@ -608,6 +609,9 @@ Nengo.NetGraph.prototype.create_minimap = function () {
this.minimap.appendChild(this.g_conns_mini);
this.minimap.appendChild(this.g_items_mini);

this.mm_width = $(this.minimap).width();
this.mm_height = $(this.minimap).height();

// default display minimap
this.mm_display = true;
this.toggleMiniMap();
Expand Down Expand Up @@ -690,8 +694,8 @@ Nengo.NetGraph.prototype.scaleMiniMap = function () {
* main viewport and scale the viewbox to reflect that. */
Nengo.NetGraph.prototype.scaleMiniMapViewBox = function () {
if (this.mm_display == true) {
var mm_w = $(this.minimap).width();
var mm_h = $(this.minimap).height();
var mm_w = this.mm_width
var mm_h = this.mm_height

var w = mm_w * this.mm_scale;
var h = mm_h * this.mm_scale;
Expand Down
21 changes: 10 additions & 11 deletions nengo_gui/static/components/netgraph_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ Nengo.NetGraphItem = function(ng, info, minimap, mini_item) {
var vertical_resize = event.edges.bottom || event.edges.top;
var horizontal_resize = event.edges.left || event.edges.right;

var screen_offset = $('#netgraph').offset();
var w = pos[0] - event.clientX + screen_offset.left;
var h = pos[1] - event.clientY + screen_offset.top;
var w = pos[0] - event.clientX + this.ng.offsetX;
var h = pos[1] - event.clientY + this.ng.offsetY;

if (event.edges.right) {
w *= -1;
Expand Down Expand Up @@ -752,10 +751,10 @@ Nengo.NetGraphItem.prototype.get_width = function() {
}

if (this.minimap == false) {
var w = $(this.ng.svg).width();
var w = this.ng.width;
var screen_w = this.get_nested_width() * w * this.ng.scale;
} else {
var w = $(this.ng.minimap).width();
var w = this.ng.mm_width;
var screen_w = this.get_nested_width() * w * this.ng.mm_scale;
};

Expand All @@ -774,10 +773,10 @@ Nengo.NetGraphItem.prototype.get_height = function() {
}

if (this.minimap == false) {
var h = $(this.ng.svg).height();
var h = this.ng.height;
var screen_h = this.get_nested_height() * h * this.ng.scale;
} else {
var h = $(this.ng.minimap).height();
var h = this.ng.mm_height;
var screen_h = this.get_nested_height() * h * this.ng.mm_scale;
};

Expand All @@ -802,14 +801,14 @@ Nengo.NetGraphItem.prototype.get_screen_location = function() {
if (this.minimap && !this.ng.mm_display) { return [1, 1]; }

if (this.minimap == false) {
var w = $(this.ng.svg).width() * this.ng.scale;
var h = $(this.ng.svg).height() * this.ng.scale;
var w = this.ng.width * this.ng.scale;
var h = this.ng.height * this.ng.scale;

var offsetX = this.ng.offsetX * w;
var offsetY = this.ng.offsetY * h;
} else {
var mm_w = $(this.ng.minimap).width();
var mm_h = $(this.ng.minimap).height();
var mm_w = this.ng.mm_width;
var mm_h = this.ng.mm_height;

var w = mm_w * this.ng.mm_scale;
var h = mm_h * this.ng.mm_scale;
Expand Down

0 comments on commit 02583f4

Please sign in to comment.