-
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
Merged
Merged
Value legend #565
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2df5ee3
Added basic labels to value plot
Seanny123 ed0adfc
added modal to edit labels
Seanny123 d345279
fix terry comments
Seanny123 232ebfb
quick comment update
Seanny123 7c8d3bb
brought up to date with master
Seanny123 f0d9ccf
fix modal error
Seanny123 f344be3
fixed label persistence
Seanny123 fbeff83
fixed changing dimensions
Seanny123 2b0e608
FIXUP: remove console.log
Seanny123 08e1279
fixed hiding and showing labels
Seanny123 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 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 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 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 |
---|---|---|
|
@@ -114,6 +114,26 @@ 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 || []; | ||
console.log(this.legend_labels); | ||
if (this.legend_labels.length !== this.n_lines) { | ||
// fill up the array with temporary labels | ||
for (var i=this.legend_labels.length; i<this.n_lines; i++) { | ||
this.legend_labels[i] = "label_" + 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. Could the defaults be "0, 1, 2, ..." rather than "label_0, label_1, label_2, ..."? |
||
} | ||
} | ||
|
||
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); | ||
|
@@ -231,13 +251,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) { | ||
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. | ||
// Empty entries assumed to be indication to skip modification | ||
// Long strings okay | ||
// Excissive entries get ignored | ||
// 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 (var i=0; i<self.n_lines; i++) { | ||
if (labels[i] !== "" && labels[i] !== undefined) { | ||
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); | ||
self.save_layout(); | ||
} | ||
$('#OK').attr('data-dismiss', 'modal'); | ||
}); | ||
|
||
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; | ||
|
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.
extraneous console.log