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

Visualizing LinkedLists in Java #144

Open
mcg10 opened this issue Apr 4, 2022 · 6 comments
Open

Visualizing LinkedLists in Java #144

mcg10 opened this issue Apr 4, 2022 · 6 comments
Projects

Comments

@mcg10
Copy link

mcg10 commented Apr 4, 2022

Screen Shot 2022-04-04 at 10 59 22 AM

I am currently working on setting up the visualizer for myself in Java and am just having a bit of difficulty with cleaning up the visual aspects of it. I am working with this simple ListNode class:

public class ListNode {
    int info;
    ListNode next;
    ListNode(int x){
        info = x;
    }
    ListNode(int x, ListNode node){
        info = x;
        next = node;
    }
}

I would like to view the info field as the label of each node as opposed to the memory address as is currently happening above. If I were working in JS, I would create a const visualize() to adjust the labeling, but I am a bit lost on how to resolve this in Java. What can I do to adjust the JSON that affects the labeling of this? Would I have to add a specific method to my ListNode class, or would it involve adjusting the JSON from a case-to-case basis. Thank you so much for taking the time to read this!

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

hediet commented Apr 5, 2022

I'm quite sure the 20 in ListNode@20 is not the memory address.

Did you check out this example? You can tweak visualize function.

@mcg10
Copy link
Author

mcg10 commented Apr 5, 2022

I'm quite sure the 20 in ListNode@20 is not the memory address.

Did you check out this example? You can tweak visualize function.

Screen Shot 2022-04-05 at 11 04 27 AM

Thanks for the quick response! I did check out the demo yesterday and was still experiencing a similar issue with extraneous elements showing in the visualization. I printed out the results of list.visualize() after appending all 4 elements to the list and got the expected result:

{"nodes":[{"id":"hediet.de/0","label":"list"},{"id":"1"},{"id":"2"},{"id":"3"},{"id":"4"}],"edges":[{"from":"hediet.de/0","to":"1","label":"next"},{"from":"1","to":"2","label":"next"},{"from":"2","to":"3","label":"next"},{"from":"3","to":"4","label":"next"}],"kind":{"graph":true}}

However, I think I'll need to manipulate something in GraphData to prevent the extra fields. Unless you notice any glowering issues with the way I have used the visualizer, I will investigate how the JSON is being sent to the visualization source and see if I can alter anything there.

@hediet
Copy link
Owner

hediet commented Apr 5, 2022

@mcg10
Copy link
Author

mcg10 commented Apr 5, 2022

You cannot just visualize list here, you must enter list.visualize()!

Btw. you can also use the playground: https://hediet.github.io/visualization/?darkTheme=1&state=XQAAAAIvAwAAAAAAAABBKQlHM6T2Wc8XVwEhzaxe6E0Rs2k_lhdt3Y6bGxV4tJypbKTlXRlIXwqQzzLuz6wPqj-1otBEUUwyY-paGyrcHLk0me9_M7oiRIW0BvqAaMpPxOG3LuwH77FPfe_GnG9A0hmiBeh8UYRp_gf-8MxiJI-En74ym3FckGcBU-TDZ_ptakLK7mIXAl7j0WIOePPe4MhV6BqmV44MCEx4xxdutBLvi4fy0BT1afan_6SGGVMN_lQf_90AundefinedQA

Screen Shot 2022-04-05 at 11 36 03 AM

I was using list instead of list.visualize() because it didn't seem to be parsing the JSON correctly. Someone in a previous issue dealt with the same problem specifically in Java but not in Python or C. Thanks for sharing the playground!

@hediet
Copy link
Owner

hediet commented Apr 5, 2022

You are right, this is a regression. Possibly caused by an update of the java extension.

Feel free to debug this extension and file a PR, it should be straight forward.

@mcg10
Copy link
Author

mcg10 commented Apr 5, 2022

Sounds good! I appreciate the sanity check for all of this. I won't be getting to this immediately, but as soon as I resolve it locally, I'll send a PR right away

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

No branches or pull requests

2 participants