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

Adds style to node serialization. #317

Merged
merged 2 commits into from Oct 11, 2019
Merged

Conversation

jmilloy
Copy link
Collaborator

@jmilloy jmilloy commented Oct 1, 2019

The Style serialization itself is updated so that the definition will be empty for the default style, which allows the node definition to omit the style when it is not necessary.

>>> style = Style()
>>> style.definition
OrderedDict()

>>> style=Style(name="test")
>>> style.definition
OrderedDict([('name', 'test')])

>>> node = Node()
>>> node.definition
OrderedDict([('Node', OrderedDict([('node', 'core.node.Node')]))])

>>> node = Node(style=Style(name="test"))
OrderedDict([('Node', OrderedDict([('node', 'core.node.Node'), ('style', OrderedDict([('name', 'test')]))]))])

In order to do that, I modified the Style cmap handling, so that colormap is string trait (that can be None) and cmap is a property that either uses colormap, enumeration_colors, or a default:

>>> style = Style()
>>> style.colormap # None
>>> style.cmap
<matplotlib.colors.ListedColormap object at 0x7ff855b7c9e8>
>>> style.cmap.name
'viridis'

>>> style = Style(colormap="hot")
>>> style.colormap
'hot'
>>> style.cmap
<matplotlib.colors.LinearSegmentedColormap object at 0x7ff855aa54a8>
>>> style.cmap.name
'hot`

>>> style = Style(enumeration_colors=('c', 'k'))
>>> style.colormap # None
>>> style.cmap
<matplotlib.colors.ListedColormap object at 0x7ff876eb8908>
>>> style.cmap.name
'from_list'

>>> style = Style(colormap="hot", enumeration_colors=('c', 'k'))
...
TypeError: Style can have a colormap or enumeration_colors, but not both

…pdated so that the definition will be empty for the default style, which allows the node definition to omit the style when it is not necessary.
@jmilloy jmilloy self-assigned this Oct 1, 2019
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 90.619% when pulling 9cea677 on feature/node-serialization into 279eab9 on develop.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 90.619% when pulling 9cea677 on feature/node-serialization into 279eab9 on develop.

@mpu-creare mpu-creare merged commit d5bd613 into develop Oct 11, 2019
@mpu-creare mpu-creare deleted the feature/node-serialization branch October 11, 2019 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants