I would like to update the style of a vertex whenever an asynchronous event fires (ie, change a stop light to green when a car drives up). I found another question similar and created a custom graph view:

final mxGraph graph = new mxGraph() {
   protected mxGraphView createGraphView() {
      mxGraphView graph_view = new mxGraphView(this) {
         public mxCellState createState(Object obj) {
            mxCell cell = (mxCell) obj;
            if (cell.isVertex() && IsCellIWant(cell)) {
               Map<String, Object> styles =
                            new HashMap<String, Object>(graph.getCellStyle(cell));
               styles.put(mxConstants.STYLE_FILLCOLOR, "#FFFFFF");
               return new mxCellState(this, cell, styles);
            }
            return super.createState(cell);
         }
      };
      return graph_view;
   }
};

This causes the vertices to show with the correct fill color the first time the graph is rendered, but I cannot figure out how to get them to be re-rendered once the event triggers.

tl;dr: How do you get a vertex already added to a graph to re-render based on a new style?

asked 12 Oct '12, 12:49

Nescient's gravatar image

Nescient
111
accept rate: 0%


I think I figured it out. I put the following code in a change handler for the event I want (and removed the custom graph view):

Object[] cells = graph.getChildVertices(graph.getDefaultParent());
mxStylesheet style = graph.getStylesheet();
Map<String, Object> vstyle =
                    new HashMap<String, Object>(style.getDefaultVertexStyle());
vstyle.put(mxConstants.STYLE_FILLCOLOR, "#FFFFFF");
for (Object o : cells) {
   mxCell c = (mxCell) o;
   if (IsCellIWant(c)) {
      graph.getView().getState(c).setStyle(vstyle);
   }
}
link

answered 12 Oct '12, 13:21

Nescient's gravatar image

Nescient
111
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×79
×50
×45
×29
×11

Asked: 12 Oct '12, 12:49

Seen: 3,976 times

Last updated: 12 Oct '12, 13:21