jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.7k stars 728 forks source link

how to fix the problem of the position when i type in searchbar for a view on the search #718

Closed LBouzac closed 1 year ago

LBouzac commented 1 year ago

editor.translate_to = function(x, y) { var pos_x = x (this.precanvas.clientWidth / (this.precanvas.clientWidth this.zoom)) - (this.precanvas.getBoundingClientRect().x (this.precanvas.clientWidth / (this.precanvas.clientWidth this.zoom))); var pos_y = y (this.precanvas.clientHeight / (this.precanvas.clientHeight this.zoom)) - (this.precanvas.getBoundingClientRect().y (this.precanvas.clientHeight / (this.precanvas.clientHeight this.zoom)));

this.canvas_x = pos_x; this.canvas_y = pos_y; let storedZoom = this.zoom; this.zoom = 1; this.precanvas.style.transform = "translate(" + pos_x + "px, " + pos_y + "px) scale(" + this.zoom + ")"; this.zoom = storedZoom; this.zoom_last_value = 1; this.zoom_refresh(); }

var infonode = '';

$("#search").on('keyup', function(e) { e.preventDefault(); var value = $(this).val().toLowerCase(); $(".drawflow-node").filter(function() { var isFind = $(this).text().toLowerCase().indexOf(value) > -1; if (isFind) { $(this).addClass("isFind"); var idnode = $(this).attr('id').replace('node-', ''); infonode = editor.getNodeFromId(idnode); } else { $(this).removeClass("isFind"); } if (value == '') { infonode = ''; $(this).removeClass("isFind"); } });

if (infonode != '') { console.log('infonode -----'); console.log(infonode.pos_x + ' / ' + infonode.pos_y); editor.translate_to(infonode.pos_x, infonode.pos_y); } });

jerosoler commented 1 year ago

Is it a problem or is it a trick?

LBouzac commented 1 year ago

a problem because the position is not the good when i write in search bar

jerosoler commented 1 year ago

Can you detail your problem more?

What is that search? Where is? You are moving the canvas. Where do you want to move it exactly?

Can you provide an example?

LBouzac commented 1 year ago

image The search bar in yellow find and fix the camera on the box but when i write image the box in border red is not finds in the good positions

jerosoler commented 1 year ago

Have you tried the function here:

I see that it is similar but different

LBouzac commented 1 year ago

same problem i've try it

jerosoler commented 1 year ago

Could it be that it has a column on the left side?

If so, you may need to calculate the width of this column and apply the sum.

LBouzac commented 1 year ago

for the contested menu image

1: I retrieve the x and y positions of the box

2: there is a column on the left

3: so what is the formula with trick 88 to arrive at the result of the capture

jerosoler commented 1 year ago

Tested on the demo:

editor.translate_to = function(x,y){
    this.canvas_x = x;
    this.canvas_y = y;
    let storedZoom = this.zoom;
    this.zoom = 1;
    this.precanvas.style.transform = "translate("+this.canvas_x+"px, "+this.canvas_y+"px) scale("+this.zoom+")";
    this.zoom = storedZoom;
    this.zoom_last_value = 1;
    this.zoom_refresh();
}

const nodeInfo = editor.getNodeFromId(5);

editor.translate_to(-1*nodeInfo.pos_x,-1*nodeInfo.pos_y);

Works with zoom is 1.

image

LBouzac commented 1 year ago

thanks, here is the code search : ` var infonode = ''; var node_x = node_y = 0;

$("#search").on('keyup', function(e) {
  e.preventDefault();
  var value = $(this).val().toLowerCase();
  $(".drawflow-node").filter(function() {
    var isFind = $(this).text().toLowerCase().indexOf(value) > -1;
    if (isFind) {
      $(this).addClass("isFind");
      var idnode = $(this).attr('id').replace('node-', '');
      infonode = editor.getNodeFromId(idnode);
    } else {
      $(this).removeClass("isFind");
    }
    if(value == '') {
      infonode = '';
      $(this).removeClass("isFind");
    }
  });

  if(infonode != '') {
    console.log('infonode -----');
    console.log('infonode possition : '+infonode.pos_x+' / '+ infonode.pos_y);
    editor.translate_to(-1*infonode.pos_x,-1*infonode.pos_y);
  }
});`