From df8c82e19777b70c8c2cb392e9fffb2893a4f634 Mon Sep 17 00:00:00 2001 From: IanCa Date: Mon, 19 Feb 2024 15:12:44 -0600 Subject: [PATCH] Allow adjust size/color of svg contour in wordcloud --- hed/models/string_util.py | 2 +- hed/tools/visualization/word_cloud_util.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/hed/models/string_util.py b/hed/models/string_util.py index 589758c3..94acf1da 100644 --- a/hed/models/string_util.py +++ b/hed/models/string_util.py @@ -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) diff --git a/hed/tools/visualization/word_cloud_util.py b/hed/tools/visualization/word_cloud_util.py index 1b022577..d33d06e7 100644 --- a/hed/tools/visualization/word_cloud_util.py +++ b/hed/tools/visualization/word_cloud_util.py @@ -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): @@ -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'') + svg_elements.append(f'') return '\n'.join(svg_elements)