-
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
Added ability to change color palettes #574
Open
Seanny123
wants to merge
27
commits into
master
Choose a base branch
from
more-colors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
1d87572
Added basic labels to value plot
Seanny123 8c99b64
added modal to edit labels
Seanny123 5825cd2
Create plots for the input and the output of the SPA Basal Ganglia
Seanny123 f328e9b
Added ability to choose different color palette
Seanny123 4921aa9
added color palette to config
Seanny123 91c57da
fixed legend setting behaviour
Seanny123 b83d12d
expanded palette switching to spa_similarity and bg_plot
Seanny123 74aa0f5
removed left-over ipdb
Seanny123 ded744a
Fixed id and empty labels error for spasimilarity
Seanny123 ed4f79e
Removed redundant variable from bg_plot
Seanny123 a91e6dc
Added basic labels to value plot
Seanny123 fe5caae
added modal to edit labels
Seanny123 a57699d
Create plots for the input and the output of the SPA Basal Ganglia
Seanny123 f64d726
Added ability to choose different color palette
Seanny123 8c06f90
added color palette to config
Seanny123 a7b5978
fixed legend setting behaviour
Seanny123 8683a1e
expanded palette switching to spa_similarity and bg_plot
Seanny123 0e7cef0
removed left-over ipdb
Seanny123 30b4e02
Fixed id and empty labels error for spasimilarity
Seanny123 91e0a31
Removed redundant variable from bg_plot
Seanny123 a913d86
fixed formatting stuff
Seanny123 9137f2a
fix bg plot disapearing problem
Seanny123 7acea6d
Merge branch 'more-colors' of github.com:nengo/nengo_gui into more-co…
Seanny123 89092b0
delete useless fil
Seanny123 3daa7ca
Merge remote-tracking branch 'origin/master' into more-colors
Seanny123 b319286
fixup
Seanny123 59272f3
fixup config
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import struct | ||
|
||
import nengo | ||
import numpy as np | ||
|
||
from nengo_gui.components.value import Value | ||
|
||
|
||
class BGPlot(Value): | ||
"""The server-side system for the SPA Basal Ganglia plot.""" | ||
|
||
# the parameters to be stored in the .cfg file | ||
config_defaults = Value.config_defaults | ||
config_defaults["palette_index"] = 1 | ||
config_defaults["show_legend"] = True | ||
|
||
def __init__(self, obj, **kwargs): | ||
args = kwargs["args"] | ||
super(BGPlot, self).__init__(obj, args["n_lines"]) | ||
|
||
# default legends to show | ||
self.def_legend_labels = args["legend_labels"] | ||
|
||
# the item to connect to | ||
self.probe_target = args["probe_target"] | ||
|
||
self.label = "bg " + self.probe_target | ||
|
||
def attach(self, page, config, uid): | ||
super(Value, self).attach(page, config, uid) | ||
|
||
def add_nengo_objects(self, page): | ||
# create a Node and a Connection so the Node will be given the | ||
# data we want to show while the model is running. | ||
with page.model: | ||
self.node = nengo.Node(self.gather_data, | ||
size_in=self.n_lines) | ||
if self.probe_target == "input": | ||
self.conn = nengo.Connection(self.obj.input, self.node, synapse=0.01) | ||
else: | ||
self.conn = nengo.Connection(self.obj.output, self.node, synapse=0.01) | ||
|
||
def javascript(self): | ||
# generate the javascript that will create the client-side object | ||
info = dict(uid=id(self), label=self.label, | ||
n_lines=self.n_lines, synapse=0) | ||
|
||
if getattr(self.config, "legend_labels") == []: | ||
json = self.javascript_config(info, override={"legend_labels":self.def_legend_labels}) | ||
else: | ||
json = self.javascript_config(info) | ||
return 'new Nengo.Value(main, sim, %s);' % json |
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 |
---|---|---|
|
@@ -82,13 +82,16 @@ def remove_nengo_objects(self, page): | |
""" | ||
pass | ||
|
||
def javascript_config(self, cfg): | ||
def javascript_config(self, cfg, override = {}): | ||
"""Convert the nengo.Config information into javascript. | ||
|
||
This is needed so we can send that config information to the client. | ||
""" | ||
for attr in self.config._clsparams.params: | ||
cfg[attr] = getattr(self.config, attr) | ||
if attr not in override: | ||
cfg[attr] = getattr(self.config, attr) | ||
else: | ||
cfg[attr] = override[attr] | ||
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. See the comment in bgplot.py; I'm pretty sure that this override thing isn't needed at all, since you can just directly put that stuff in the dictionary you're creating and passing in here. |
||
return json.dumps(cfg) | ||
|
||
def code_python(self, uids): | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Generate a color sequence of a given length. | ||
*/ | ||
|
||
/** | ||
* Generate a color sequence of a given length. | ||
* | ||
* Colors are defined using a color blind-friendly palette. | ||
*/ | ||
Nengo.make_colors = function(N) { | ||
// Color blind palette with blue, green, red, magenta, yellow, cyan | ||
var palette = ["#1c73b3", "#039f74", "#d65e00", "#cd79a7", "#f0e542", "#56b4ea"]; | ||
var c = []; | ||
|
||
for (var i = 0; i < N; i++) { | ||
c.push(palette[i % palette.length]); | ||
} | ||
return c; | ||
} | ||
|
||
/** | ||
* Color blind-friendly palette. | ||
*/ | ||
Nengo.default_colors = function() { | ||
// Color blind palette with blue, green, red, magenta, yellow, cyan | ||
var palette = ["#1c73b3", "#039f74", "#d65e00", "#cd79a7", "#f0e542", "#56b4ea"]; | ||
return function(i){ return palette[i%palette.length] }; | ||
} | ||
|
||
/** | ||
* Color palette use by Google for graphics, trends, etc... | ||
*/ | ||
Nengo.google_colors = function() { | ||
var palette = ["#3366cc", "#dc3912", "#ff9900", "#109618", "#990099", "#0099c6", "#dd4477", "#66aa00", "#b82e2e", "#316395", "#994499", "#22aa99", "#aaaa11", "#6633cc", "#e67300", "#8b0707", "#651067", "#329262", "#5574a6", "#3b3eac"]; | ||
return function(i){ return palette[i%palette.length] }; | ||
} | ||
|
||
/** list of valid color choices */ | ||
Nengo.color_choices = [ | ||
["Nengo Color-Blind Friendly (6 colors)", {"func":Nengo.default_colors(), "mod":6}], | ||
["Google (20 colors)", {"func":Nengo.google_colors(), "mod":20}], | ||
["D3.js A (20 colors)", {"func":d3.scale.category20(), "mod":20}], | ||
["D3.js B (20 colors)", {"func":d3.scale.category20b(), "mod":20}], | ||
["D3.js C (20 colors)", {"func":d3.scale.category20c(), "mod":20}] | ||
]; |
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
Oops, something went wrong.
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.
???? Why not just do
and get rid of this whole override thing?
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.
Because the behaviour of
javascript_config
is to override everything with the defaults. It doesn't look to see if the defaults have been set to anything else. Is that it's intended behaviour or should the code be changed?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.
I don't think I understand... all javascript_config does is go through the config entry for the item and just into a json output:
what do you mean by overriding everything with the defaults?
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.
I'll break it down why it over-writes by going through the above code with the example of
legend_labels
being set indict
argument to["A", "B", "C"]
.cfg
is thedict
I've passed in as an argument. The for-loop takes values from the default config, which isself.config._clsparams
and adds it tocfg
. The default config containslegend_labels = []
, so when the for-loop runs, regardless of what the value thatcfg
has forlegend_labels
, it will be over-written by the default config. That is why["A","B","C"]
will be over-written to[]
. Does that make sense now?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.
It's basically equivalent to running this code: