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

erDiagram styling does not seem to work #2673

Open
jiludvik opened this issue Jan 28, 2022 · 16 comments
Open

erDiagram styling does not seem to work #2673

jiludvik opened this issue Jan 28, 2022 · 16 comments
Labels
Graph: Entity Relationship Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request

Comments

@jiludvik
Copy link

jiludvik commented Jan 28, 2022

erDiagrams are supposed to supposed two styling elements: color and stroke but documentation does not provide any examples of how to use these. I've tried to use the following ways to apply styling in mermaide.live:

erDiagram
        CUSTOMER }|..|{ DELIVERY-ADDRESS : has
classDef myclass fill:#f9f
class CUSTOMER myclass
erDiagram
        CUSTOMER }|..|{ DELIVERY-ADDRESS : has
style CUSTOMER fill:#f9f

I would expect that application of fill #f9f changes filling of CUSTOMER pink, but in botj cases the selected data entity remains black with blue edges. Use of indentation in the markdown does not seem to have any effect either.

@github-actions github-actions bot added the Status: Triage Needs to be verified, categorized, etc label Jan 28, 2022
@stefanocrosta
Copy link

stefanocrosta commented Mar 11, 2022

I have also tried all possible ways and did not manage to style the erDiagram individual entities...

@tim-oritain
Copy link

Is it even possible to style erDiagrams? I can't figure out how to do it and the documentation is of no help...

@pcampr
Copy link

pcampr commented Nov 24, 2022

I didn't find any mention of stroke, fill or anything similar in the parser https://github.com/mermaid-js/mermaid/tree/develop/packages/mermaid/src/diagrams/er/parser , so I doubt this is doable now, although the doc clearly says it's possible

@Gregory-Lange
Copy link

It is possible to theme them. If you look at the source for the default themes it gives you the ins to do so. for example setting attributeBackgroundColorOdd will set the background color for odd items.

@pcampr
Copy link

pcampr commented Jan 10, 2023

It is possible to theme them. If you look at the source for the default themes...

Yes, if there is this possibility. If Mermaid is embedded into a product (Notion, GitHub) then there is no such option, we can only edit the source (mermaid markup) of the diagram.

@Gregory-Lange
Copy link

Wrong you make an inline custom theme and it will apply. Using the %%{init: {‘theme’:’base’, ‘themeVariables’:{ XXXXX }} }%% unless the live demo app is doing something that the usual is not.

@pcampr
Copy link

pcampr commented Jan 16, 2023

Wrong you make an inline custom theme and it will apply. Using the %%{init

this thread is about the ability to style each element separately (I guess), so that e.g. CUSTOMER entity can have a different color/fill than DELIVERY-ADDRESS

this init can change only the global style for all entities

@Gordonby
Copy link

Gordonby commented Feb 6, 2023

I really need per entity background fill.
The docs telling me it's possible is the ultimate fu. 😄

@FlorianCassayre
Copy link

It's extremely surprising to me that this diagram type doesn't support such a basic feature. Watching this issue.

@huynhicode
Copy link
Member

huynhicode commented Apr 2, 2023

Thanks, everyone for your input. The documentation for styling ER Diagrams is a bit confusing and we will work on making it clearer.

The two style attributes: fill and color can be used on the following CSS Class Selectors for ER Diagrams:

  • .er.attributeBoxEven
  • .er.attributeBoxOdd
  • .er.entityBox
  • .er.entityLabel
  • .er.relationshipLabel
  • .er.relationshipLabelBox
  • .er.relationshipLine

To apply a fill or stroke to a CSS Class Selector:

.er.entityLabel {
     fill: blue;
}

To apply a fill or stroke to a specific entity:

[id*="entity-CUSTOMER"] .er.entityLabel {
     fill: blue;
}

In the example above, "CUSTOMER" refers to the NAME value of the entity.

Currently, these three CSS Class Selectors require a custom id in your html:

  • .er.attributeBoxEven
  • .er.attributeBoxOdd
  • .er.entityBox
<div id="exampleErDiagram" class="mermaid">
     erDiagram
          ...
</div>
#exampleErDiagram .er.attributeBoxEven {
	fill: forestgreen;
}

(Will look into removing this as a requirement.)

Here is a CodePen example. It's not the prettiest ER Diagram 😅, but hopefully, it gives you a better idea of how to apply styling to ER Diagrams.

ER Diagrams Documentation

Also, a quick reminder to set your theme to base as it is the only modifiable theme (currently).

@pcampr
Copy link

pcampr commented Apr 7, 2023

Thank you. We use mermaid in Notion, where it supports the syntax, but not custom CSS. So to control color and fill, we'd need a support directly in mermaid markup.

@Hatch-Cody
Copy link

Hatch-Cody commented Apr 25, 2023

For anyone left wondering how to apply styles to individual attributes of the erDiagram on the live editor, here is a simple example.

Code:

erDiagram
  CUSTOMER ||--o{ ORDER : places
  CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
  ORDER ||--|{ LINE-ITEM : contains

Config:

{
  "theme": "dark",
  "themeCSS": [
    ".er.relationshipLabel { fill: red; }", 
    ".er.relationshipLabelBox { fill: purple; }", 
    ".er.entityBox { fill: blue; }",
    "[id*=entity-CUSTOMER] .er.entityBox { fill: orange;}"
    ]
}

@shaun-gambardella
Copy link

Thanks, everyone for your input. The documentation for styling ER Diagrams is a bit confusing and we will work on making it clearer.

The two style attributes: fill and color can be used on the following CSS Class Selectors for ER Diagrams:

  • .er.attributeBoxEven
  • .er.attributeBoxOdd
  • .er.entityBox
  • .er.entityLabel
  • .er.relationshipLabel
  • .er.relationshipLabelBox
  • .er.relationshipLine

To apply a fill or stroke to a CSS Class Selector:

.er.entityLabel {
     fill: blue;
}

To apply a fill or stroke to a specific entity:

[id*="entity-CUSTOMER"] .er.entityLabel {
     fill: blue;
}

In the example above, "CUSTOMER" refers to the NAME value of the entity.

Currently, these three CSS Class Selectors require a custom id in your html:

  • .er.attributeBoxEven
  • .er.attributeBoxOdd
  • .er.entityBox
<div id="exampleErDiagram" class="mermaid">
     erDiagram
          ...
</div>
#exampleErDiagram .er.attributeBoxEven {
	fill: forestgreen;
}

(Will look into removing this as a requirement.)

Here is a CodePen example. It's not the prettiest ER Diagram 😅, but hopefully, it gives you a better idea of how to apply styling to ER Diagrams.

ER Diagrams Documentation

Also, a quick reminder to set your theme to base as it is the only modifiable theme (currently).

I use vscode to create my ER diagrams using mermaid. Can you please provide a code example of how to use the css styling rather than in the mermaid live editor?

@AnilRh
Copy link

AnilRh commented Aug 16, 2023

For the Notion users out there here's an example:

%%{init: {"theme": "forest", "themeCSS": ["[id*=entity-SHOES] .er.entityBox { fill: orange;}"]}}%%

erDiagram
  CUSTOMER ||--o{ SHOES : "has many"

@pcampr
Copy link

pcampr commented Aug 16, 2023

@AnilRh thank you, this works nicely in Notion!

@Yokozuna59
Copy link
Member

@AnilRh Thanks for the code, but it's not specific to notion:

%%{init: {"theme": "forest", "themeCSS": ["[id*=entity-SHOES] .er.entityBox { fill: orange;}"]}}%%

erDiagram
  CUSTOMER ||--o{ SHOES : "has many"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Graph: Entity Relationship Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests