I am trying to make a cell invisible when a user clicks on it. I have modified the code in overlays.html as follows :

 graph.addListener(mxEvent.CLICK, function(sender, evt)
            {
                var cell = evt.getProperty('cell');
                console.log(cell.getValue());
                console.log(cell.getId());
                if (cell != null)
                {
                    cell.setVisible(false);
                }
            });

But, it is not working. The cell is still visible. What am I doing wrong?

asked 06 Feb '12, 19:05

punithsn's gravatar image

punithsn
1248
accept rate: 41%

edited 04 Dec '12, 04:41

David's gravatar image

David
4.9k21831


Use the model, ie. graph.getModel().setVisible(cell, false) for the repaint to work.

link

answered 06 Feb '12, 22:07

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

Thanks Gaudenz.

(06 Feb '12, 22:24) punithsn

Don't know what was changed, but I am not able to call method setVisible from graph.getModel()

I tried this, but I am not able to make just one cell invisible. When I remove comment then whole graph is invisible.

Any help will be appreciated.

graph.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getClickCount() == 2) { // Get Cell under Mousepointer

    int x = e.getX(), y = e.getY();
    DefaultGraphCell cell = (DefaultGraphCell) graph.getFirstCellForLocation(x, y);

    if (cell != null) {            
       graph.getGraphLayoutCache().setVisible(cell, false);
       //graph.setVisible(false);
       graph.repaint();
    }
  }
}

});

link

answered 04 Dec '12, 02:32

nosman's gravatar image

nosman
11
accept rate: 0%

edited 04 Dec '12, 02:33

You are using JGraph 5, the answer above is for JGraphX (6). They are completely different codebases.

(04 Dec '12, 02:50) David
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:

×228
×66
×29
×11
×2

Asked: 06 Feb '12, 19:05

Seen: 2,492 times

Last updated: 04 Dec '12, 04:41