-
Notifications
You must be signed in to change notification settings - Fork 38
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
Value legend #565
Value legend #565
Changes from 2 commits
2df5ee3
ed0adfc
d345279
232ebfb
7c8d3bb
f0d9ccf
f344be3
fbeff83
2b0e608
08e1279
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,27 @@ Nengo.Value = function(parent, sim, args) { | |
this.on_resize(this.get_screen_width(), this.get_screen_height()); | ||
this.axes2d.axis_y.tickValues([args.min_value, args.max_value]); | ||
this.axes2d.fit_ticks(this); | ||
|
||
this.colors = Nengo.make_colors(6); | ||
this.color_func = function(d, i) {return self.colors[i % 6]}; | ||
this.legend = document.createElement('div'); | ||
this.legend.classList.add('legend'); | ||
this.div.appendChild(this.legend); | ||
|
||
this.legend_labels = args.legend_labels || []; | ||
if(this.legend_labels.length !== this.n_lines){ | ||
// fill up an array with temporary labels | ||
for(i=0; i<this.n_lines; i++){ | ||
if(this.legend_labels[i] === undefined){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not |
||
this.legend_labels[i] = "label_".concat(String(i)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick style question: is there a preference to do |
||
} | ||
} | ||
} | ||
|
||
this.show_legend = args.show_legend || false; | ||
if(this.show_legend === true){ | ||
Nengo.draw_legend(this.legend, this.legend_labels, this.color_func); | ||
} | ||
}; | ||
|
||
Nengo.Value.prototype = Object.create(Nengo.Component.prototype); | ||
|
@@ -129,13 +150,76 @@ Nengo.Value.prototype.generate_menu = function() { | |
var items = []; | ||
items.push(['Set range...', function() {self.set_range();}]); | ||
|
||
if (this.show_legend) { | ||
items.push(['Hide legend', function() {self.set_show_legend(false);}]); | ||
} else { | ||
items.push(['Show legend', function() {self.set_show_legend(true);}]); | ||
} | ||
|
||
// TODO: give the legend it's own context menu | ||
items.push(['Set legend labels', function () {self.set_legend_labels();}]) | ||
|
||
// add the parent's menu items to this | ||
return $.merge(items, Nengo.Component.prototype.generate_menu.call(this)); | ||
}; | ||
|
||
Nengo.Value.prototype.set_show_legend = function(value){ | ||
if (this.show_legend !== value) { | ||
this.show_legend = value; | ||
this.save_layout(); | ||
} | ||
if (this.show_legend === true){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
Nengo.draw_legend(this.legend, this.legend_labels, this.color_func); | ||
} else { | ||
// delete the legend's children | ||
while(this.legend.lastChild){ | ||
this.legend.removeChild(this.legend.lastChild); | ||
} | ||
} | ||
} | ||
|
||
Nengo.Value.prototype.set_legend_labels = function() { | ||
var self = this; | ||
|
||
Nengo.modal.title('Enter comma seperated legend label values'); | ||
Nengo.modal.single_input_body('Legend label', 'New value'); | ||
Nengo.modal.footer('ok_cancel', function(e) { | ||
var label_csv = $('#singleInput').val(); | ||
var modal = $('#myModalForm').data('bs.validator'); | ||
|
||
// No validation to do. | ||
// Blank string mean do nothing | ||
// Long strings okay | ||
// Excissive entries get ignored | ||
// Missing entries get replaced by default value | ||
// Empty entries assumed to be indication to skip modification | ||
// TODO: Allow escaping of commas | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add that TODO as an issue |
||
if ((label_csv !== null) && (label_csv !== '')) { | ||
labels = label_csv.split(','); | ||
|
||
for(i=0; i<self.n_lines; i++){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing |
||
if(labels[i] !== ""){ | ||
self.legend_labels[i] = labels[i]; | ||
} | ||
} | ||
|
||
// redraw the legend with the updated label values | ||
while(self.legend.lastChild){ | ||
self.legend.removeChild(self.legend.lastChild); | ||
} | ||
Nengo.draw_legend(self.legend, self.legend_labels, self.color_func); | ||
} | ||
$('#OK').attr('data-dismiss', 'modal'); | ||
}); | ||
|
||
// TODO: Add button so that a person can easily return to default labels | ||
Nengo.modal.show(); | ||
} | ||
|
||
Nengo.Value.prototype.layout_info = function () { | ||
var info = Nengo.Component.prototype.layout_info.call(this); | ||
info.show_legend = this.show_legend; | ||
info.legend_labels = this.legend_labels; | ||
info.min_value = this.axes2d.scale_y.domain()[0]; | ||
info.max_value = this.axes2d.scale_y.domain()[1]; | ||
return info; | ||
|
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.
missing
var
beforei=0