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

Use classes instead of inline style for easy styling #24

Closed
totty90 opened this issue Dec 2, 2014 · 6 comments
Closed

Use classes instead of inline style for easy styling #24

totty90 opened this issue Dec 2, 2014 · 6 comments
Labels
Status: Approved Is ready to be worked on

Comments

@totty90
Copy link

totty90 commented Dec 2, 2014

Would be nice to do:

.box {
    fill: #E1F0FF;
    stroke: #138BFF;
}

Or there is an easier way?

@knsv
Copy link
Collaborator

knsv commented Dec 2, 2014

I had some idea of being able to paste the svg code and save it as an svg for use in en external program. Maybe you can use the class definiton and the default class for the styling.

@knsv knsv added the styling label Dec 5, 2014
@bjowes
Copy link
Contributor

bjowes commented Dec 13, 2014

It seems to be allowed within the SVG standard to specify CSS classes inside the SVG. One example:
http://blogs.msdn.com/b/ie/archive/2011/10/27/best-practices-for-getting-started-with-svg.aspx

That way it should still fulfill the "copy&paste" scenario. I will look into if the d3 and dagre-d3 supports inserting a CSS header into the SVG.

@knsv
Copy link
Collaborator

knsv commented Dec 13, 2014

Sounds great! Good luck.

I think the goal should be that one can take the svg code generated by mermaid, save it to a file and be able to open in svg editor of choice.

Good luck!

@knsv knsv added the Status: Approved Is ready to be worked on label Dec 13, 2014
@bjowes
Copy link
Contributor

bjowes commented Dec 13, 2014

Got it working! Have a look at my fork for a working example, I made the test page web_style.html for this purpose. This impact the syntax in the following ways:
style - is still used for inline styling of nodes
class - is used to assign a class to a node (nodes may have multiple classes)
classDef - is unused at the moment. Considering to push the styles from classDefs to the common style section for the SVG, but that is next step.
Once the graph is generated, the script will now check through all stylesheets and copy those that affect anything within the SVG into the SVG style section. The default styling (previously class default) is added at the top of the SVG style section.
What do you think of this approach?

I noticed that for the odd shape and the diamond, inline styles were set on the shape. Those were removed.
Also added a generated SVG file to the test folder, to simplify checking how well it carries the styles. The common styles work fine, but the text doesn't due to foreignObject - and it doesn't like
either. I'll create a separate issue on that.

@knsv
Copy link
Collaborator

knsv commented Dec 14, 2014

This looks really good!

By fetching the styles you will know that the svg will look the same outside the browser context. I think we need to support the classDef statement needs to be included as well. That should be fairly easy as we get those from the parser. This for not breaking backwards compatability but we can deprecate the statement and remove it later.

Looking forward to the pull request.

@knsv
Copy link
Collaborator

knsv commented Dec 15, 2014

Included in release 0.2.16

@knsv knsv closed this as completed Dec 15, 2014
knsv pushed a commit that referenced this issue Aug 5, 2020
merge from mermaid-js:develop
knsv pushed a commit that referenced this issue Aug 4, 2021
Bumps [eslint](https://github.com/eslint/eslint) from 7.30.0 to 7.31.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](eslint/eslint@v7.30.0...v7.31.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Approved Is ready to be worked on
Projects
None yet
Development

No branches or pull requests

3 participants