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

235
Visualizações
MxGraph: Can't Search and Focus on cells

I've been trying to make a simple input element to search for id's and focus on specific vertexes, as shown below:

Screen before Searching

And the code seems to be working with this simple method:

function searchForNode() {
    const id = document.getElementById("input-search-id").value;
    const { vertex } = findById(id);

    const point = new mxPoint(-(vertex.geometry.x), -(vertex.geometry.y));
    graph.view.translate = point;
}

The problem starts after the first search, where my top left screen focuses on the desired vertex but from there on I'm enabled to scroll up or left.

Screen after Searching

Also, if I scroll before searching for anything, it seems that my graph.view.translate doesn't update to my current position, so, when I search for a vertex it focuses on a different location instead of the expected vertex.

Is there any method from MxGraph Library that I'm missing? I've tried graph.getView().setTranslate(translate) and graph.panGraph(translate) but the behaviour is the same.

Thank you in advance

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

0

So, I found a solution for this problem but not in the most convenient way.

For what I understood, the native scrollbars and the mxGraph panning are different approaches to the display movement, when you scroll you aren't necessarily updating your mxGraph position but when you pan with the mxGraph library you are dragging all the cells along the screen, instead of "scrolling" to them.

I disabled the mxGraph panning option and simply used the javascript native method scrollTo, as show below, I hope it helps.

function searchForNode() {
  const inputValue = document.getElementById("input-search-id").value;
  const { vertex } = flowMap.findNodeByIdOrName(inputValue);
  if( !vertex ) return null;
  
  window.scrollTo({
    top: vertex.geometry.y - MARGIN_TO_CENTER,
    left: vertex.geometry.x - MARGIN_TO_CENTER,
    behavior: 'smooth'
  });
}

*The flowMap.findNodeByIdOrName on the last image and the findById(id) on the question post are my own methods to search on my array of vertexes.

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