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

2.0 idea - mountable JS/SVG graphs #226

Open
kerrizor opened this issue Nov 1, 2016 · 3 comments
Open

2.0 idea - mountable JS/SVG graphs #226

kerrizor opened this issue Nov 1, 2016 · 3 comments
Milestone

Comments

@kerrizor
Copy link
Collaborator

kerrizor commented Nov 1, 2016

WHAT IF.. in addition to a command line artifact generator, we had a development env only route that would generate a clickable JS/SVG graph in the browser?

@kerrizor kerrizor added this to the 2.0 milestone Nov 1, 2016
@scarroll32
Copy link
Contributor

What about outputting in Mermaid markdown format? 🤔

@unchidev
Copy link

unchidev commented Oct 14, 2022

I just thought the same thing myself.
And I made an experimental prototype of it.

image

rails-mermaid-erd
https://github.com/koedame/rails-mermaid_erd

Mermaid is excellent and has already produced something very good as an experience.
As for me, I would be very happy if rails-erd goes in this direction.

@ayuto-takasaki-LITALICO
Copy link

ayuto-takasaki-LITALICO commented May 18, 2023

Thank you very much for implementing support for mermaid notation.
#405

I have tried to use it, but I found one problem. When I use the only option in .erdconfig to limit the models to be output, the relationship line is drawn for models that are not included in the output.

only: Model1,Model2

After some investigation, I found that the problem can be fixed by defining the following method in lib/rails_erd/diagram/mermaid.rb and adding a condition in each_relationship.

      def node_exists?(name)
        # I'm not sure if this is the proper way to judge, but it works as long as you don't use a weird model name.
        graph.include?("\tclass `#{name}`")
      end
      each_relationship do |relationship|
        from, to = relationship.source, relationship.destination
        next unless node_exists?(from) && node_exists?(to)

        graph << "\t`#{from.name}` #{relation_arrow(relationship)} `#{to.name}`"

        from.children.each do |child|
          next unless node_exists?(child)

          graph << "\t`#{child.name}` #{relation_arrow(relationship)} `#{to.name}`"
        end

        to.children.each do |child|
          next unless node_exists?(child)

          graph << "\t`#{from.name}` #{relation_arrow(relationship)} `#{child.name}`"
        end
      end

I'm not sure how to implement the node_exists? method in a cool way, so I'll just leave it as a comment on the issue.

Thanks for maintaining a great gem.

(This text was translated by DeepL)

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

No branches or pull requests

4 participants