Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection properties / styles #22

Open
smheidrich opened this issue Sep 15, 2024 · 0 comments
Open

Connection properties / styles #22

smheidrich opened this issue Sep 15, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@smheidrich
Copy link

smheidrich commented Sep 15, 2024

Description

D2 supports properties like style for connections, same as it does for shapes (cf. e.g. the font color example). But py-d2 only seems to support them for shapes, with no constructor parameters available to set them for connections.

It would be nice if D2 supported style and other arbitrary properties for connections with a similar API as for shapes.

Why

Potential use cases are styling connection labels in different colors or text sizes, which can be useful for many applications in which connections model something important (such as transitions between states of a state machine).

Alternatives

The only workarounds I'm aware of if someone needs this feature are to either write code to output D2 connections themselves or to hack support for properties like styles into their own subclass of py-d2's D2Connection class like so:

class CustomD2Connection(D2Connection):
  style: D2Style

  def __init__(self, *args, **kwargs):
    if "style" in kwargs:
      self.style = kwargs.pop("style")
    else:
      self.style = None
    super().__init__(*args, **kwargs)

  def lines(self) -> list[str]:
    lines = super().lines()
    if self.style is not None:
      lines[0] = f"{lines[0]} {{"
      lines.extend(self.style.lines())
      lines.append("}")
    return lines

But it would be better if this was supported by py-d2 directly.

@smheidrich smheidrich added the enhancement New feature or request label Sep 15, 2024
@smheidrich smheidrich changed the title Connection properties Connection properties / styles Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant