Navigation Menu

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

Is it possible to make the diagram shapes clickable? #121

Closed
darrencruse opened this issue Nov 8, 2019 · 8 comments
Closed

Is it possible to make the diagram shapes clickable? #121

darrencruse opened this issue Nov 8, 2019 · 8 comments

Comments

@darrencruse
Copy link

darrencruse commented Nov 8, 2019

We are using nomnoml to generate (display only) ER-diagrams and would like to add some minimal interactivity where the users could click the boxes and see some related help info or possibly navigate to other web pages

There's nothing specifically built into nomnoml for such interactivity right...

But I'm hoping it's still possible but I'm not sure?

e.g. I'm a little new to SVG but I understand it's a DOM underneath and adding onclick handlers is in theory possible right e.g. as described here:
https://stackoverflow.com/questions/2296097/making-an-svg-image-object-clickable-with-onclick-avoiding-absolute-positioning

But I'm imagining to do the above I would use nomnoml to generate my SVG and then separately (old-school-jquery-style) find the rect elements and bind my click handlers to them.

But that would traditionally mean e.g. finding those elements by known ids on them right.

But I see a closed issue here that rejected the idea of having the nomnoml syntax let you assign ids or css class names.

In general am I thinking right or is there a different/better way?

If this is thinking right then is there a way I can find specific nomnoml generated SVG elements without having such "ids" on them?

@skanaar
Copy link
Owner

skanaar commented Nov 8, 2019

The nodes are not entities as such in the SVG files, they are just a collection of shapes.

A plain [node] is just a box but for example [<actor>a stick figure] is a bit more complex, and there is nothing in the SVG that reveals where one node ends and another starts.

Your use case is probably best solved by using some custom keyword like

[Component|
  onclick:http://darrencruse.com/Component.html
]

and then pass the output SVG through a script that replaces that pattern with a clickable link.

@MJonker
Copy link

MJonker commented Dec 3, 2019

@skanaar do you have a hint where we can start this 'parsing' of the SVG ? Should we extend a piece code in this repository ?

@skanaar
Copy link
Owner

skanaar commented Dec 3, 2019

I mean that the SVG output that nomnoml generates can then be parsed in whatever script/tool that you would prefer.

So let nomnoml generate my-diagram.svg.
And then consume that file with a script of your choice. Python, bash, javascript etc. etc.

@skanaar
Copy link
Owner

skanaar commented Sep 14, 2020

v1.1.0 is now published. It attaches the node name to every SVG shape as a data-name attribute.

This snippet is an example of how the data can be extracted in a click event handler.

document.querySelector('svg').onclick = function (e) { console.log(e.target.attributes['data-name']) }

With this, it should be possible to make a clickable diagram. The name-to-link data would have to be stored outside the diagram somewhere, but I think it is a good start.

@42sol-eu
Copy link

Is there a small working example for this?
It seems not to work in my example.

@skanaar
Copy link
Owner

skanaar commented Sep 27, 2020

  1. Open http://www.nomnoml.com/image.svg?source=[first]-%3E[second]
  2. Open the browser console
  3. Enter: document.querySelector('svg').onclick = function (e) { console.log(e.target.attributes['data-name']) }
  4. Click the diagram, you should see output in the console

(tested on Chrome)

You might have an old version in your cache?

@42sol-eu
Copy link

Perfect, that works fine. Now to the integration part...

@skanaar
Copy link
Owner

skanaar commented Apr 11, 2022

Finally nomnoml generates a proper SVG hierarchy with the release of v1.5.0 🎉

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

No branches or pull requests

4 participants