1

I made a graph using java and i want to customize the style of it. Is there any easy way? By adding style to them? Here is a part of the code that i used: Its getting some data from a json file that are filled to some Hashmaps.

public mxGraphComponent createGlobalOverview(String Filename) {
            mxGraph graph = new mxGraph();
            Object parent = graph.getDefaultParent();

            graph.getModel().beginUpdate();
            try {
                  Object vRoot = graph.insertVertex(parent, null, Filename, 0, 0, 100, 50);
                  int fmsCounter = 0;

                  for (Object i : blueprint.keySet()) {
                      getDependencies(i.toString());
                      if (blueprint.get(i).equals("FMS")) {
                          if (dependsList.get(fmsCounter).equals("null")) {
                              Object rootFMS = graph.insertVertex(parent, null, getTitle(i.toString()), 0, 0, 200, 50);
                              graph.insertEdge(parent, null, "rootFMS", vRoot, rootFMS);
                              System.out.println(blueprint.size());
                              createGraph(graph, parent, rootFMS, i, blueprint.size());
                            }
                        }
                    }
                    graph.setCellsEditable(false);
                    graph.setCellsMovable(false);
                    graph.setCellsResizable(false);
                    graph.setCellsSelectable(false);
                    graph.setEnabled(false);
                    mxIGraphLayout layout = new mxHierarchicalLayout(graph);
                    layout.execute(parent);

              } finally {
                    graph.getModel().endUpdate();
                }
                graph.getView().setScale(0.9);
                mxGraphComponent graphComponent = new mxGraphComponent(graph);
                graphComponent.setConnectable(false);
                return graphComponent;
 }
Piazzi
  • 2,490
  • 3
  • 11
  • 25
Aris
  • 984
  • 8
  • 22
  • you're using the grapheditor example? – Piazzi Apr 05 '19 at 14:56
  • I dont know what this grapheditor example is, but i already created my graph, and now i want to change the style on some of the vertex – Aris Apr 08 '19 at 07:51
  • It's the most used inteface from mxgraph, https://jgraph.github.io/mxgraph/javascript/examples/grapheditor/www/index.html . – Piazzi Apr 08 '19 at 11:27
  • Thanks @LucasPiazzi for your reply but i am creating the graph through java. Is that going to help? – Aris Apr 08 '19 at 11:48
  • Well, i'm used to the grapheditor example, i dont' know if my code will work in your case, could you share us some the function that you used to create the graph? – Piazzi Apr 08 '19 at 11:52
  • Here is a part of a code i updated the post – Aris Apr 08 '19 at 12:07

1 Answers1

0

You could use the mxStyleChange() API Documentation

mxStyleChange​(mxGraphModel graph, java.lang.Object cell, java.lang.String style)   

To know more about the layouts, you shoud take a look here, this will help you defining the style. The shapes might be useful as well:

The API documentation is extensive, you should always take a look there. Hope this helps you

Piazzi
  • 2,490
  • 3
  • 11
  • 25
  • Thank you very much Lucas, you helped me a lot , i will see the Documantation. – Aris Apr 08 '19 at 12:44
  • Glad i could help, mxgraph can be tough sometimes, but the API documentation should be enough to solve your problems. Please consider accepting this answer if it helped in anyway, so more people can find this later. Good luck on your project! – Piazzi Apr 08 '19 at 12:50