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

[Java] Not able to visualize Graph in Java #148

Open
Mayank0896 opened this issue Apr 29, 2022 · 4 comments
Open

[Java] Not able to visualize Graph in Java #148

Mayank0896 opened this issue Apr 29, 2022 · 4 comments
Projects

Comments

@Mayank0896
Copy link

Hi Hediet, First of all thanks for making such cool extension and contributing it to the community.
I am trying to visualize a Graph. But I am facing some issues with it. When I am passing Graph as a json as per format shared by you. It is showing json as an object only not a graph.

`JSONObject mainJsonObject = new JSONObject();

    JSONObject typeGraph = new JSONObject();
    typeGraph.put("graph", true);
    mainJsonObject.put("kind", typeGraph);

    int[][] edges = new int[][] { { 0, 1 }, { 0, 4 }, { 1, 4 }, { 1, 3 }, { 4, 3 }, { 1, 2 }, { 3, 2 } };

    JSONArray arrNodes = new JSONArray();
    ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        adj.add(new ArrayList<>());
        JSONObject nodeU = new JSONObject();
        nodeU.put("id", String.valueOf(i));
        nodeU.put("label", String.valueOf(i));
        arrNodes.add(nodeU);
    }

    mainJsonObject.put("nodes", arrNodes);

    for (int i = 0; i < edges.length; ++i) {
        int u = edges[i][0];
        int v = edges[i][1];
        adj.get(u).add(v);
    }

    JSONArray arrEdges = new JSONArray();
    for (int u = 0; u < adj.size(); u++) {
        for (int v : adj.get(u)) {
            // u->v is edge
            JSONObject edgeUV = new JSONObject();
            edgeUV.put("from", String.valueOf(u));
            edgeUV.put("to", String.valueOf(v));
            arrEdges.add(edgeUV);
        }
    }

    mainJsonObject.put("edges", arrEdges);

    // const example1 = {
    // "kind": { "graph": true },
    // "nodes": [
    // { "id": "1", "label": "1" },
    // { "id": "2", "label": "2", "color": "orange" },
    // { "id": "3", "label": "3" }
    // ],
    // "edges": [
    // { "from": "1", "to": "2", "color": "red" },
    // { "from": "1", "to": "3" }
    // ]
    // };
    System.out.println(mainJsonObject);`

mainJsonObject is the json of Graph created from Nested arraylist. But when I am trying to visualize then it is showing it as an object only.
image
Please refer the screenshot. It looks cool though but it is of no use.

I am trying to pass mainJsonObject directly to expression bar.

Json passed by my code is completely valid ( checked on jsonlint) -
{ "nodes": [ { "id": "0", "label": "0" }, { "id": "1", "label": "1" }, { "id": "2", "label": "2" }, { "id": "3", "label": "3" }, { "id": "4", "label": "4" } ], "kind": { "graph": true }, "edges": [ { "from": "0", "to": "1" }, { "from": "0", "to": "4" }, { "from": "1", "to": "4" }, { "from": "1", "to": "3" }, { "from": "1", "to": "2" }, { "from": "3", "to": "2" }, { "from": "4", "to": "3" } ] }

@hediet hediet added this to Triage in Backlog Apr 29, 2022
@hediet
Copy link
Owner

hediet commented Apr 29, 2022

Try mainJsonObject.toString(). The value to visualize must be a (JSON) string!

@Mayank0896
Copy link
Author

I tried mainJsonObject.toString() but visualization is this -
image

@hediet
Copy link
Owner

hediet commented May 2, 2022

Then something changed in the implementation of the Java Debug adapter :(

It should be very easy to fix though. Can you look into it? The source code of this extension has instructions how to build it.

@Mayank0896
Copy link
Author

Hi @hediet , I suppose this extension is build in TypeScript. I have no idea about typescript or javascript. Just a beginner to Java.
So, I can't promise any fix from my side.

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

Successfully merging a pull request may close this issue.

2 participants