Skip to content

Commit

Permalink
Merge pull request #70 from michiboo/addShape
Browse files Browse the repository at this point in the history
added point shape for markdown
  • Loading branch information
mwcraig committed Mar 25, 2019
2 parents a651636 + ef3c76d commit 83b20d2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions astrowidgets/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ def marker(self):
Marker can be set as follows::
{'type': 'circle', 'color': 'cyan', 'radius': 20}
{'type': 'cross', 'color': 'green', 'radius': 20}
{'type': 'plus', 'color': 'red', 'radius': 20}
"""
return self._marker
Expand All @@ -426,6 +428,14 @@ def marker(self, val):
marker_type = val.pop('type')
if marker_type == 'circle':
self._marker = functools.partial(self.dc.Circle, **val)
elif marker_type == 'plus':
val['type'] = 'point'
val['style'] = 'plus'
self._marker = functools.partial(self.dc.Point, **val)
elif marker_type == 'cross':
val['type'] = 'point'
val['style'] = 'cross'
self._marker = functools.partial(self.dc.Point, **val)
else: # TODO: Implement more shapes
raise NotImplementedError(
'Marker type "{}" not supported'.format(marker_type))
Expand Down
8 changes: 8 additions & 0 deletions astrowidgets/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ def test_add_markers():
skycoord_colname='coord')


def test_set_markers():
image = ImageWidget()
image.marker = {'color': 'yellow', 'radius': 10, 'type': 'cross'}
assert 'cross' in str(image.marker)
assert 'yellow' in str(image.marker)
assert '10' in str(image.marker)


def test_reset_markers():
image = ImageWidget()
# First test: this shouldn't raise any errors
Expand Down
5 changes: 3 additions & 2 deletions example_notebooks/ginga_widget.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@
"w.marker = {'type': 'circle', 'color': 'red', 'radius': 50,\n",
" 'linewidth': 2}\n",
"w.add_markers(markers_table[:2])\n",
"w.marker = {'type': 'circle', 'color': 'cyan', 'radius': 20}\n",
"# You can also change the type of marker to cross or plus\n",
"w.marker = {'type': 'cross', 'color': 'cyan', 'radius': 20}\n",
"w.add_markers(markers_table[2:])"
]
},
Expand Down Expand Up @@ -583,7 +584,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.7.2"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 83b20d2

Please sign in to comment.