Skip to content

Commit

Permalink
add color - default white to text display
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Jan 17, 2024
1 parent 8a92245 commit e5120fd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions dcm/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,11 @@ def add_donut_segment(
)

def add_text_to_donut_segment(
self, segment: DonutSegment, text: str, direction: str = "horizontal"
self,
segment: DonutSegment,
text: str,
direction: str = "horizontal",
color: str = "white"
) -> None:
"""
Add text to a donut segment with various direction options.
Expand All @@ -456,6 +460,8 @@ def add_text_to_donut_segment(
text (str): The text content to be added.
direction (str): The direction in which the text should be drawn.
Options are "horizontal", "angled", or "curved".
color (str): The color of the text. Default is "white".
"""
# Common calculations
mid_angle = (segment.start_angle + segment.end_angle) / 2
Expand All @@ -478,7 +484,7 @@ def add_text_to_donut_segment(
# Add text element
escaped_text = html.escape(text)
text_element = (
f'<text x="{text_x}" y="{text_y}" fill="black" '
f'<text x="{text_x}" y="{text_y}" fill="{color}" '
f'font-family="{self.config.font}" '
f'font-size="{self.config.font_size}" '
f'text-anchor="{text_anchor}" '
Expand Down Expand Up @@ -508,7 +514,7 @@ def add_text_to_donut_segment(

# Add text along the path
text_path_element = (
f'<text fill="black" font-family="{self.config.font}" font-size="{self.config.font_size}">'
f'<text fill="{color}" font-family="{self.config.font}" font-size="{self.config.font_size}">'
f'<textPath xlink:href="#{path_id}" startOffset="50%" text-anchor="middle">{html.escape(text)}</textPath>'
f"</text>"
)
Expand Down

0 comments on commit e5120fd

Please sign in to comment.