Skip to content
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

Control time kept #663

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions nengo_gui/static/components/netgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ Nengo.NetGraph = function(parent, args) {
}
});

Object.defineProperty(this, 'kept_time', {
get: function() {
return Nengo.config.kept_time;
},
set: function(val) {
if (val === this.kept_time) { return; }
Nengo.config.kept_time = val;
sim.time_slider.update_kept_time(val);
}
});

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in Nego.NetGraph? It isn't used by any of the NetGraph components...

// Do networks have transparent backgrounds?
Object.defineProperty(this, 'transparent_nets', {
get: function() {
Expand Down
1 change: 1 addition & 0 deletions nengo_gui/static/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Nengo.Config = function(parent, args) {
define_option("aspect_resize", false);
define_option("zoom_fonts", false);
define_option("font_size", 100);
define_option("kept_time", 4);

// Ace editor options
define_option("hide_editor", false);
Expand Down
27 changes: 27 additions & 0 deletions nengo_gui/static/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ Nengo.Modal.prototype.tabbed_body = function(tabinfo) {
Nengo.Modal.prototype.main_config = function() {
this.clear_body();

// Range on time kept, currently picked arbitrarily
var min_kept_time = 1;
var max_kept_time = 10;

var $form = $('<form class="form-horizontal" id ' +
'="myModalForm"/>').appendTo(this.$body);
$('<div class="form-group" id="config-fontsize-group">' +
Expand All @@ -196,6 +200,21 @@ Nengo.Modal.prototype.main_config = function() {
'<span class="help-block with-errors">As a percentage of' +
' the base size</span>' +
'</div>' +
'<div class="form-group" id="config-kept-time-group">' +
'<label for="kept-time" class="control-label">' +
'Time kept</label>' +
'<div class="input-group col-xs-2">' +
'<input type="number" min="' + min_kept_time +
'" max="' + max_kept_time + '" step="1" ' +
'maxlength="3" class="form-control" id="kept-time"' +
' data-error="' + min_kept_time +
' to ' + max_kept_time + ' seconds"' +
' required>' +
'<span class="input-group-addon">s</span>' +
'</div>' +
'<span class="help-block with-errors">Amount of data to' +
' save on the time slider</span>' +
'</div>' +
'<div class="form-group">' +
'<div class="checkbox">' +
'<label for="zoom-fonts" class="control-label">' +
Expand Down Expand Up @@ -272,6 +291,14 @@ Nengo.Modal.prototype.main_config = function() {
});
$('#config-fontsize').attr('data-my_validator', 'custom');

$('#kept-time').val(Nengo.netgraph.kept_time);
$('#kept-time').bind('keyup input', function () {
var kept_time = parseInt($('#kept-time').val());
if (kept_time >= min_kept_time && kept_time <= max_kept_time) {
Nengo.netgraph.kept_time = kept_time;
}
});

$('#config-backend').change(function () {
sim.set_backend($('#config-backend').val());
});
Expand Down
26 changes: 26 additions & 0 deletions nengo_gui/static/sim_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,32 @@ Nengo.TimeSlider.prototype.reset = function() {
this.sim.div.dispatchEvent(new Event('adjust_time'));
}

Nengo.TimeSlider.prototype.update_kept_time = function(kept_time) {
this.kept_time = kept_time;

/** update the limits on the time axis */
this.kept_scale.domain([this.last_time - this.kept_time, this.last_time]);

var width = this.sim.div.clientWidth - 290;
var height = this.sim.div.clientHeight - 20;
this.kept_scale.range([0, width]);
this.shown_div.style.width = width * this.shown_time / this.kept_time;

// If the shown time window will go off screen, move it on screen
if (this.first_shown_time < this.last_time - this.kept_time) {
this.first_shown_time = this.last_time - this.kept_time;
}

x = this.kept_scale(this.first_shown_time);
Nengo.set_transform(this.shown_div, x, 0);

/** update the time axis display */
this.axis_g.call(this.axis);

/** update any components who need to know the time changed */
this.sim.div.dispatchEvent(new Event('adjust_time'));
}

/**
* Adjust size and location of parts based on overall size
*/
Expand Down
2 changes: 2 additions & 0 deletions nengo_gui/static/top_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Nengo.Toolbar.prototype.config_modal_show = function() {
font_size: Nengo.netgraph.font_size,
aspect_resize: Nengo.netgraph.aspect_resize,
sync_editor: Nengo.ace.auto_update,
kept_time: sim.time_slider.kept_time,
transparent_nets: Nengo.netgraph.transparent_nets};

Nengo.modal.title('Configure Options');
Expand All @@ -134,6 +135,7 @@ Nengo.Toolbar.prototype.config_modal_show = function() {
Nengo.netgraph.zoom_fonts = original["zoom"];
Nengo.netgraph.font_size = original["font_size"];
Nengo.netgraph.transparent_nets = original["transparent_nets"];
Nengo.netgraph.kept_time = original["kept_time"];
Nengo.netgraph.aspect_resize = original["aspect_resize"];
Nengo.ace.auto_update = original["auto_update"];
$('#cancel-button').attr('data-dismiss', 'modal');
Expand Down