Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

491
Visualizações
MxGraph JavaScript: How to calculate edge length?

I am looking for a way to calculate the length of the edges in one graph. As an example this image: The connecting edge contains three parts, (a,b and c) I have no idea how to retrieve this information that I can sum up the distances of a + b + c.

On a more complexe graph I want to calculate the length for each edge. There I would loop through all models of the graph, check with .isEdge if it is an edge and then calculate the length of each edge.

let cells = graph.getModel().cells;
            
for(let key in cells){
    let mxCell = cells[key];
    if(mxCell.isEdge())
        {
            calcLength(mxCell)
        } }

calcLength() is the function I need. This one should return the length of the edge.

I used the helloPorts example from jGraph.

Thanks in advance!!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Back again,

together with a friend we found the solution. The information is stored under the graphView in the state as the length.

graphView.getState(mxCell).length

This is part of the mxCell object. If you are looking for the Euclidian length of an edge, this is stored under terminalDistance.

graphView.getState(edge).terminalDistance

The code would look like this to access it:

                let cells = graph.getModel().cells;
                let graphView = graph.getView();
                
                
                // The getModel needs to be triggered before the loop otherwise the the mxCell state is undefined
                graph.getModel().endUpdate();
                
                for(let key in cells){
                    let mxCell = cells[key];
                    if(mxCell.isEdge())
                    {
                        let state = graphView.getState(mxCell).length;
                    }
                    
                }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda