Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/py_d2/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def __init__(
opacity: Optional[float] = None,
stroke_dash: Optional[int] = None,
three_d: Optional[bool] = None,
font_color: Optional[str] = None,
border_radius: Optional[str] = None,
):
self.stroke = stroke
self.stroke_width = stroke_width
Expand All @@ -27,6 +29,8 @@ def __init__(
self.opacity = opacity
self.stroke_dash = stroke_dash
self.three_d = three_d
self.font_color = font_color
self.border_radius = border_radius

def lines(self) -> List[str]:
styles: List[str] = []
Expand All @@ -52,6 +56,12 @@ def lines(self) -> List[str]:
if self.three_d:
styles.append(f"3d: {stringify_bool(self.three_d)}")

if self.font_color:
styles.append(f"font-color: {self.font_color}")

if self.border_radius:
styles.append(f"border-radius: {self.border_radius}")

if len(styles) == 0:
return []

Expand Down
17 changes: 17 additions & 0 deletions tests/test_py_d2/test_d2_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ def test_d2_style_three_d():
assert str(style) == "style: {\n 3d: true\n}"


def test_d2_style_font_color():
style = D2Style(font_color="red")
assert str(style) == "style: {\n font-color: red\n}"

def test_d2_style_font_color_hex():
style = D2Style(font_color='"#274e13"')
assert str(style) == 'style: {\n font-color: "#274e13"\n}'

def test_d2_style_border_radius():
style = D2Style(border_radius="999")
assert str(style) == "style: {\n border-radius: 999\n}"


def test_d2_style_all():
style = D2Style(
stroke="red",
Expand All @@ -51,6 +64,8 @@ def test_d2_style_all():
opacity=0.5,
stroke_dash=2,
three_d=True,
font_color='"#274e13"',
border_radius='999',
)
assert str(style) == "\n".join(
[
Expand All @@ -62,6 +77,8 @@ def test_d2_style_all():
" opacity: 0.5",
" stroke-dash: 2",
" 3d: true",
" font-color: \"#274e13\"",
" border-radius: 999",
"}",
]
)