Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda