Skip to content

Simple JavaScript UI to display and create graphs for unit tests #143

Open

Description

@karussell

This bites me very often and I create graphs on paper or via inkscape but viewing, creating or editing them is too costly. Therefor it would be nice to have a simple JavaScript map where I can create a sample graph and the app would export very simplified Java code. The trick is here to export into simple Java code, which is then readable from the JavaScript app back to display it too. Another option would be to export into some JSON which is then easily copy&pastable into a unit test (e.g. via Helper.createGraphFromJson("{some: json}")). But I prefer Java code if it is more compact.

Main purposes

  • visualize graphs in unit tests
  • visualize calculated routes
  • create graphs for unit tests to avoid full or partial OSM import

Requirements

Activity

  1. easbar commented on Nov 18, 2016

    @easbar
    Member

    I made a little in-browser app to draw graphs and display very simple corresponding java code here:
    https://github.com/ammagamma/graphhopper-creator .
    It uses the d3 force simulation (not Leaflet). This makes it possible to draw the graph in a reasonable way even if only the edges (but not the actual node positions) are given. For example you can specify the edges of a graph on the right and quickly see how it looks on the left. It can also be used to create a graph visually and export "source code" that can be copy&pasted to a unit test. There are two buttons that can be used to sync between the graph visualization and the source representation (see the readme file and the instructions displayed inside the app). Because the app does not use Leaflet it does not support real node coordinates, but only shows the graph schematically (with the edge costs being displayed as numbers). There are a few features that would be helpful that I have not yet implemented but probably would make sense:

    • relabelling of nodes in the graph view
    • changing the edge costs in the graph view
    • removing nodes and edges in the graph view
    • displaying paths

    Not sure if this app is exactly what you were looking for, but it was a fun project that I would like to share ;)

  2. devemux86 commented on Nov 18, 2016

    @devemux86
    Contributor

    Are there any screenshots available to understand the concept?

  3. karussell commented on Nov 18, 2016

    @karussell
    MemberAuthor

    Nice & thanks - will have a look!

  4. easbar commented on Nov 19, 2016

    @easbar
    Member

    Here is a screenshot:

    creator

    I guess it is pretty self-explanatory, the arrow buttons at the bottom of the image can be used to synchronize the graph and source view. Right now only source code lines of the form
    graph.edge(0, 3).setDistance(344); are supported.

  5. karussell commented on Nov 19, 2016

    @karussell
    MemberAuthor

    Works really nice and the moving of the graph makes it a bit hard to 'catch' nodes but at the same time also a bit more fun :)

    So far it is not possible to set edge weights, relabel nodes or to remove edges or nodes!

    But due to the bidirectional update at least changing edge weights and removing edges&nodes is easy and simple :)

  6. karussell commented on Nov 19, 2016

    @karussell
    MemberAuthor

    Can we include it in GH? E.g. under core/src/test/javascript and add a bit documentation (prominently) for the developers?

  7. easbar commented on Nov 28, 2016

    @easbar
    Member

    Of course you can include it in GH! If catching the nodes is too hard we could either require some key-press for dragging nodes (e.g. shift+drag) or reduce the velocity of the simulation a bit. I thought it is fun to move the nodes as well and it can be quite useful to disentangle the graph if there are many edges. Yes, the edge weights and node labels can be changed using the source view, it is just not supported by the graph view so far.

  8. karussell commented on Aug 29, 2017

    @karussell
    MemberAuthor
  9. boldtrn commented on Aug 31, 2017

    @boldtrn
    Member

    Another idea would be to draw the graphs as ascii like OSRM does

    This looks very interesting as well. I am not sure if we can also specify more complex situations, like roundabouts or something like this with the ASCII style, but this looks interesting.

  10. karussell commented on Sep 24, 2020

    @karussell
    MemberAuthor
  11. easbar commented on Sep 26, 2020

    @easbar
    Member

    Another idea would be to draw the graphs as ascii like OSRM does:

    Valhalla took this a bit further and even creates some kind of end-to-end tests from ascii:
    https://github.com/valhalla/valhalla/blob/master/test/gurka/README.md

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions