Skip to content

Commit

Permalink
Merge pull request #863 from IanCa/develop
Browse files Browse the repository at this point in the history
Allow adjust size/color of svg contour in wordcloud
  • Loading branch information
VisLab authored Feb 19, 2024
2 parents 8f5e93d + df8c82e commit 82ede45
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hed/models/string_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def gather_descriptions(hed_string):
description(str): The concatenated values of all description tags.
Side effect:
The input HedString has its Definition tags removed.
The input HedString has its description tags removed.
"""
desc_tags = hed_string.find_tags("description", recursive=True, include_groups=0)
Expand Down
9 changes: 5 additions & 4 deletions hed/tools/visualization/word_cloud_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def generate_contour_svg(wc, width, height):
contour = _get_contour_mask(wc, width, height)
if contour is None:
return ""
return _numpy_to_svg(contour)
return _numpy_to_svg(contour, radius=wc.contour_width, color=wc.contour_color)


def _get_contour_mask(wc, width, height):
Expand Down Expand Up @@ -91,19 +91,20 @@ def _draw_contour(wc, img: Image):
WordCloud._draw_contour = _draw_contour


def _numpy_to_svg(contour):
def _numpy_to_svg(contour, radius=1, color="black"):
""" Convert a numpy array to SVG.
Parameters:
contour (np.Array): Image to be converted.
radius (float): The radius of the contour to draw.
color(string): the color to draw it as, e.g. "red"
Returns:
str: The SVG representation.
"""
svg_elements = []
points = np.array(contour.nonzero()).T
for y, x in points:
svg_elements.append(f'<circle cx="{x}" cy="{y}" r="1" stroke="black" fill="black" />')
svg_elements.append(f'<circle cx="{x}" cy="{y}" r="{radius}" stroke="{color}" fill="{color}" />')

return '\n'.join(svg_elements)

Expand Down

0 comments on commit 82ede45

Please sign in to comment.