Hi.

\n

I was exploring the jgraphX API and I override the "connection" handler to increment a variable that stores the number of edges in the graph.

\n

Here is the code:

\n
graphComponent.getConnectionHandler().addListener(mxEvent.CONNECT, new mxIEventListener() {\n        @Override\n        public void invoke(Object sender, mxEventObject evt) {\n            numEdges++;\n        }\n    });\n
\n

The problem is:\nWhenever I double click the cell(vertex) the variable is incremented because a "self loop" (connection (v1,v1)) is created.

\n

I wonder if there is a way to not allow these "self loops".

\n

Sorry if this is an issue already discussed. I did some research and found no solution.\nAnd sorry for my english. I'm getting better.

asked 31 Jan, 19:06

sverker's gravatar image

sverker
144
accept rate: 0%


Me too had the same problem, since cant find an apt solution, i used a condition check. Hope this helps.

\n
public void invoke(Object sender, mxEventObject event) {\n    mxCell edge = (mxCell) event.getProperty("cell");\n    if(edge.getTarget()!=edge.getSource()){\n        numEdges++;\n    }\n
\n

}

link

answered 01 Feb, 02:24

Saju%20Chithran's gravatar image

Saju Chithran
707
accept rate: 20%

You tried setAllowLoops and it didn't work?

(01 Feb, 02:35) David ♦♦
1

No David,\nstill the CONNECT event gets triggered when i try to rename by clicking.

(01 Feb, 02:41) Saju Chithran

Did you try mxGraph.setAllowLoops(false)?

link

answered 01 Feb, 00:19

Gaudenz's gravatar image

Gaudenz ♦♦
7.4k15
accept rate: 31%

yes I did.

(01 Feb, 03:37) sverker

Thanks, this event will no longer be fired in the next version. We'll add an active flag in mxConnectionHandler to avoid this.

link

answered 01 Feb, 05:29

Gaudenz's gravatar image

Gaudenz ♦♦
7.4k15
accept rate: 31%

It's working very well.

\n

Is there a way to effectively don't allow these self loops?\nI'm using this:

\n
graphComponent.getConnectionHandler().addListener(mxEvent.CONNECT, new mxIEventListener() {\n        @Override\n        public void invoke(Object sender, mxEventObject evt) {\n            mxCell edge = (mxCell) evt.getProperty("cell");\n\n            if (edge.getTarget() != edge.getSource()) {\n                numEdges++;\n            } else {\n                edge.removeEdge(edge, true);               \n            }\n        }\n    });\n
\n

And it's working. But I don't really know what's happening.

\n

Thanks for the help and sorry for my English. I'm getting better.

link

answered 01 Feb, 04:10

sverker's gravatar image

sverker
144
accept rate: 0%

edited 01 Feb, 04:12

mxGraph.setAllowLoops(false) should disable such loops, but there seems to be a bug that still allows them. What are the exact steps to create such a look, just double click?

link

answered 01 Feb, 04:16

Gaudenz's gravatar image

Gaudenz ♦♦
7.4k15
accept rate: 31%

Using this code:

\n
graphComponent.getConnectionHandler().addListener(mxEvent.CONNECT, new mxIEventListener() {\n        @Override\n        public void invoke(Object sender, mxEventObject evt) {\n                numEdges++;\n        }\n    });\n
\n

with:\n graph.setAllowLoops(false);

\n

or (doesn't matter)

\n
graph.setAllowLoops(true);\n
\n

the CONNECT event is gets triggered when I try to rename by clicking.\nIf the double click is in the "border" area, the event isn't triggered (and you can rename without add a new edge). Only happens when you click (to rename) in the middle of the cell and that "connect behavior" (responsible to take the edge to another cell) is triggered.

link

answered 01 Feb, 05:17

sverker's gravatar image

sverker
144
accept rate: 0%

Ok, ty.

\n

One last question:

\n

Is there any way to know how many edges are removed when you remove a vertex?\nI am building an application that needs to get some information from the graph dynamically. And I'm having problems with it.

\n

Again: TY, and sorry for my English.

link

answered 01 Feb, 09:10

sverker's gravatar image

sverker
144
accept rate: 0%

Problem solved. Ty guys.

(01 Feb, 12:08) sverker
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:

×364
×56
×29

Asked: 31 Jan, 19:06

Seen: 177 times

Last updated: 01 Feb, 12:08

powered by BitNami OSQA