elkjs icon indicating copy to clipboard operation
elkjs copied to clipboard

Support drawing graphs in the `test/examples` directory

Open skieffer opened this issue 1 year ago • 4 comments

I know that elkjs does not officially support the drawing of graphs (just layout), but I wondered if you would like to add a simple script that allows us to see the graphs in the test/examples directory.

I have found this very useful when working on ELK. My workflow is:

  1. Make changes in ELK.
  2. Rebuild elkjs in a sibling directory.
  3. Reload a page from elkjs/test/examples in the browser.
  4. Repeat.

I've written SimpleGraphDrawer.js which draws ELK graphs given in JSON format as SVG. Furthermore, it handles all of the new JSON coordinate modes ~~proposed~~ added in https://github.com/eclipse/elk/pull/1071 .

This PR includes ~~four files~~ five files:

  • SimpleGraphDrawer.js: The drawing class (and a supporting SvgDrawing class).
  • test-browser-draw.html: Same as the existing test-browser.html, except that now we draw the graph.
  • test-browser-draw2.html: Like test-browser-draw.html but with a more interesting graph (namely, the one from here ).
  • test-browser-draw-all-modes.html: Draws a single graph 6 times, with all possible combinations of the new JSON coordinate modes.

EDIT: I've added a fifth file:

  • test-coord-modes.html: Maybe a better demonstrator of the coordinate modes for new users.

skieffer avatar Sep 06 '24 14:09 skieffer

I've added a new file, test-coord-modes.html which is designed to be a helpful demonstrator of the different coordinate modes, for new users. The JS within the file is (hopefully) well-commented, to help users see how to use the modes.

One purpose of including this could be to help head off issues like #332.

Screenshots

There are some introductory notes:

Screenshot 2025-04-08 at 17 18 00

And here's the full table:

Screenshot 2025-04-08 at 17 17 52

skieffer avatar Apr 06 '25 12:04 skieffer

I don' t know if there's any interest in merging this, but, if so, it might be worth discussing which of the five files it adds are really needed. Maybe they are a little redundant at this point.

skieffer avatar Apr 06 '25 12:04 skieffer

I think this would be helpful :+1:

Eddykasp avatar May 21 '25 07:05 Eddykasp

I made a few changes:

  • Now showing the input graph on the test-coord-modes.html page. I think this is very helpful for users to understand what is being drawn.

  • I renamed the class SimpleGraphDrawer --> SimpleElkGraphDrawer. This is a better (more specific) name, describing what the class actually does.

  • I removed the file test-browser-draw-all-modes.html since I think it adds little value beyond what test-coord-modes.html already does.

skieffer avatar May 22 '25 12:05 skieffer