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

Feature request: class shortcodes for connectors #2376

Closed
muteboy opened this issue Feb 25, 2025 · 3 comments
Closed

Feature request: class shortcodes for connectors #2376

muteboy opened this issue Feb 25, 2025 · 3 comments

Comments

@muteboy
Copy link

muteboy commented Feb 25, 2025

I use classes to assign special arrowheads to certain connectors, as described here: https://d2lang.com/tour/connections#arrowheads

For example:

classes: {
  1_to_composition_many: {
    source-arrowhead: 1
    target-arrowhead: * {
      shape: diamond
      style.filled: true
    }
}

and then

box1 -> box2: {class: 1_to_composition_many}

Rather than have to specify the class every time, perhaps I could define the class as usual, then use a shortcode in the connector to assign the class:

classes: {
  1_to_composition_many: {
    shortcode: 1--*<>
    source-arrowhead: 1
    target-arrowhead: * {
      shape: diamond
      style.filled: true
    }
}

and then

box1 1--*<> box2

would assign the class to the connector

@alixander
Copy link
Collaborator

It's a clever idea but I don't like how it'll break without the class being defined.

Would using globs and coding the src/dst names be enough? E.g. any box going to any box has this:

classes: {
  1_to_composition_many: {
    source-arrowhead: 1
    target-arrowhead: * {
      shape: diamond
      style.filled: true
    }
  }
}
(box* -> box*)[*].class: 1_to_composition_many

box1 -> box2

@muteboy
Copy link
Author

muteboy commented Feb 28, 2025

I can understand the concern.
Good idea about the globs. Could I do that based on the connector label?
So all connectors with the label "many to many" are assigned the class "many_to_many"?

@alixander
Copy link
Collaborator

Yes, using filters

https://play.d2lang.com/?script=qlDQtVOo5EoEUUlWCrmJeZW6Jfm6IJqLS0NLCySupaUZrRVrpVDNpaCglpOYlJqDplBBobikMidVr7ikKD871UqhKDWFq5YLEAAA__8%3D&

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants