mermaid icon indicating copy to clipboard operation
mermaid copied to clipboard

[classDef] Suggestion: extend classDef with default shape

Open mvandermade opened this issue 5 years ago • 19 comments

Is your feature request related to a problem? Please describe. I'm frustrated when I use a class (for example ":::redis" which gives it a red colour) I need to manually shape each node. Example:

graph TD
  classDef redis fill:#FF0000;
  database1[(database1)]:::redis

Describe the solution you'd like To simplify using a syntax where the classDef also contains the shape

graph TD
  classDef [(redis)] fill:#FF0000;
  database1:::redis

Describe alternatives you've considered Copy paste a lot

Additional context image

to:

image

mvandermade avatar Feb 13 '20 19:02 mvandermade

It sounds like you are looking for the class statement:

graph TD
  classDef redis fill:#FF0000;
  database1[(database1)]
  a --> b
  class a,b,database1 redis

With it you can apply a class to a list of nodes as in the example above.

knsv avatar Feb 17 '20 08:02 knsv

The class statement is indeed helpful to know, thanks !

Is there also a way to apply shapes to an array of objects ?

I didn't see a way to do that using classDef.

So I can achieve the following: image

https://mermaid-js.github.io/mermaid-live-editor/#/edit/eyJjb2RlIjoiZ3JhcGggVERcbiAgY2xhc3NEZWYgcmVkaXMgZmlsbDojRkYwMDAwO1xuICBkYXRhYmFzZTFbKGRhdGFiYXNlMSldXG4gIGFbKGEpXVxuICBiWyhiKV1cbiAgYSAtLT4gYlxuICBjbGFzcyBhLGIsZGF0YWJhc2UxIHJlZGlzIiwibWVybWFpZCI6eyJ0aGVtZSI6ImRlZmF1bHQifSwidXBkYXRlRWRpdG9yIjpmYWxzZX0

But then without writing a[(a)] and b[(b)] but only a and b.

It is a minor typing effort, but for managing large graphs (and when combining smaller graphs together in one big graph) it helps a lot.

mvandermade avatar Feb 17 '20 09:02 mvandermade

Being able to specify shape in classDef would be really helpful – it would allow specifying semantic classes of nodes and styling them separately. This would be very useful when aiming for a consistent "language" across multiple diagrams.

sbarzowski avatar Apr 19 '20 12:04 sbarzowski

I have not given this much thought by now, but this could be done by adding a new attribute shape to classDef as well as style which can also be used to apply styles to nodes. But it should use words as a value, not things like shape:[()] but shape:database. What do you think?

GDFaber avatar Apr 19 '20 12:04 GDFaber

IMO words would be a little bit more readable in this context.

sbarzowski avatar Apr 19 '20 13:04 sbarzowski

Yeah I think it is a good way to start! Maybe the bracket notation is more difficult to write in this syntax.

Would this be how to do it ? : Schermafdruk van 2020-04-19 17 22 17

mvandermade avatar Apr 19 '20 15:04 mvandermade

Just like that, but with a separator: classDef redis fill:#FF0000,shape:database The other option would be style database1 fill:#FF0000,shape:database I think it would then be possible to change the default node shape as well by style default fill:#FF0000,shape:database.

GDFaber avatar Apr 19 '20 15:04 GDFaber

As long as we dont use the : character, yes that would work ok. Otherwise it conflicts with the LABEL definition.

That is the problem I have been running into with setting up style support

jgreywolf avatar Apr 19 '20 17:04 jgreywolf

I think using : should be no problem here as it already is part of the style definition, but I'll have an eye on that.

GDFaber avatar Apr 19 '20 17:04 GDFaber

The only drawing program I used (POVRay) also used comma's in their shape definition. http://www.povray.org/documentation/3.7.0/t2_2.html#t2_2_2 "2.2.2.3 Cylinder Object"

Comma separation seems to make sense to me !

mvandermade avatar Apr 19 '20 18:04 mvandermade

@GDFaber FYI, this is at least somewhat related to #1181 which I have started looking at again. Let's sync up :)

jgreywolf avatar Apr 26 '20 13:04 jgreywolf

Please disregard all of my comments above. As I was laying down to go to sleep last might I realized that this is all talking about css class definition for flowcharts... and not the css class definition for Class Diagrams, which is what I had read it as :)

jgreywolf avatar Apr 27 '20 12:04 jgreywolf

Still could be useful to sync up anyways :)

mvandermade avatar Apr 27 '20 13:04 mvandermade

On second thought, I think we should implement this only as an option for the style variant, not for classDef, because as you say class definitions are for CSS while we apply the style definitions directly to the nodes in the flowchart renderer. I think it feels wrong to add this to the class definition for this reason.

GDFaber avatar Apr 27 '20 14:04 GDFaber

Hmmm... how is style different from classDef in this aspect? IIUC both are currently using CSS attributes directly to style a node (style is used inline and classDef is used to define a class).

And from the user's perspective, if it's only available for style t's possible to have one default shape, but it's impossible to define a few kinds of nodes with their shape, color etc. Let's say someone wants to have red Redis databases, blue Postgres databases and yellow circles for web servers in their diagram. It would be nice if they could declare these 3 kinds of nodes somehow and use them semantically

sbarzowski avatar Apr 27 '20 16:04 sbarzowski

FYI: Perhaps also benefiting from this style-def is this discussion: #1227. Instead of creating a new diagram type. I can imagine the styling of a class would also a step in the right direction.

mvandermade avatar May 22 '20 17:05 mvandermade

Hi everyone,

I'm facing the exact same issue reported by @mvandermade 4 years ago.

This ticket describes pretty well my need.

Be able to assign a shape via a class

The ticket is pretty old. I'm curious if there were improvements in the syntax in the last years.

I've read the documentation and I found nothing about it. Did I miss something?

Thanks

ccoVeille avatar Mar 16 '24 13:03 ccoVeille

I agree; having a way to apply a semantic class name to each node, and then have the styling done separately in a classDef, would be really nice. To me, the shape is part of the UI, vs. the underlying structure; the class is part of the structure of the diagram, but, especially in a flowchart where things can get pretty abstract, wanting to change leaf nodes from a rectangle to a circle feels like styling to me.

bkfunk avatar Jun 03 '24 18:06 bkfunk

i would like to use :::KafkaTopic to apply rotated database shape

whsv26 avatar Jul 09 '24 21:07 whsv26