d2 icon indicating copy to clipboard operation
d2 copied to clipboard

Adding "resources" section

Open mauroexe opened this issue 1 year ago • 2 comments

Hey Alixander!

I've been doing lots and lots of diagrams and I struggled with something...

When you define your objects, there's no way to keep them invisible and use them later... I came across an idea of creating a section of resources; just like D2 classes but those "resources" could be based on classes too.

To help you understand the idea better, I share you a link to a diagraming tool that a friend of mine found. This tool has a resources section (coincidently LOL).

If you can implement that "resources" behavior, D2 will be strong enough to have no competitors, I have all the faith in your efforts; I wish I had the time to spare helping you coding it.

Imagine if the next scenario could be possible:

FILE: styles.d2

classes: {
  dog: {
    shape: circle
  }
  male: {
    style.fill: brown
    style.fill: brown
    style.font-color:white
  }
  female: {
    style.fill: orange
  }
}

FILE: dogs.d2

resources: {
  dog1: Frido {
    class: [dog; male]
  }
  dog2: Snoopy {
    class: [dog; male]
  }
  dog3: Paulette {
    class: [dog; female]
  }
}

FILE: houses.d2

resources: {
  my-house: {
    label: "Home"
  }
  friends-house: {
    label: "Friend's House"
  }
}

FILE: diagram.d2


...@styles
...@dogs
...@houses

relations: {
  my-house: {
    dog1 -- dog3: "Couple"
  }
  friends-house: {
    dog2
  }
}

The previous example should compile into something like this:

image

It really improves the readability of what really matters: the relations, ¿Don't you think?

¿What do you say, can you implement it sometime in the future?

mauroexe avatar Apr 06 '24 02:04 mauroexe

vars should actually be flexible enough to do this. but needs some compiler work to make it work. good suggestion, thank you

alixander avatar Apr 09 '24 22:04 alixander

Actually vars already can do this. @mauroexe am I missing anything?

Screenshot 2024-07-18 at 4 39 07 PM

https://play.d2lang.com/?script=jJAxa8MwEIV3_4qHCXSyocmmjoWQsdCxZFDsi20464wkNxiT_14sWzEBl3aSdPfep3tXsHaOnMKYAKVU8wVwte5IoWhswZQA9wRoNdOj7wem_NowK1ys3MzfVTE-K4TFKtzqxkfqlX7jitWmmmX3JPnWdhmzHbJaevfwsL4QK6QnaSmNVNuQKd228BiaLw6nqRstpVSvCkfblLLow3IUvkqp3kL68yrdK3wakW74h_ag8KF7Ju9pSz1v4ByDPsfL83w3xlIcE1m2cNN36TsOGeb5d-N0rh-H92ECb6wkwJ_qa7pg3E_GnwAAAP__&sketch=1&

alixander avatar Jul 18 '24 22:07 alixander