Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在jsPlumb中实现平移和缩放_Javascript_Jquery_Jsplumb_Flowchart - Fatal编程技术网

Javascript 在jsPlumb中实现平移和缩放

Javascript 在jsPlumb中实现平移和缩放,javascript,jquery,jsplumb,flowchart,Javascript,Jquery,Jsplumb,Flowchart,我正在从事一个项目,该项目涉及使用*jsPlumb(*社区版)创建流程图。社区版没有内置的平移/缩放功能。该项目不需要付费版本(工具包版)提供的所有功能。因此,在付费版本上投入大笔资金不是一种选择。使用community edition实现平移/缩放有什么行之有效的方法吗?也许您应该看看 这个库提供了HTML元素的缩放选项,因此应该可以做到这一点 也使用jQueryUI/draggable和Dagre 您需要按div包装图表,div将被平移/缩放(在本例中它有“panzoom”类) jQuery

我正在从事一个项目,该项目涉及使用*jsPlumb(*社区版)创建流程图。社区版没有内置的平移/缩放功能。该项目不需要付费版本(工具包版)提供的所有功能。因此,在付费版本上投入大笔资金不是一种选择。使用community edition实现平移/缩放有什么行之有效的方法吗?

也许您应该看看

这个库提供了HTML元素的缩放选项,因此应该可以做到这一点

也使用jQueryUI/draggable和Dagre

您需要按div包装图表,div将被平移/缩放(在本例中它有“panzoom”类)

jQueryUI用于拖动节点,而不是内置的可拖动节点,以补偿平移缩放比例和双偏移问题。在拖动节点时禁用平移并考虑比例因子:

var currentScale = 1;
$container.find(".diagram .item").draggable({
  start: function(e){
    var pz = $container.find(".panzoom");
    currentScale = pz.panzoom("getMatrix")[0];
    $(this).css("cursor","move");
    pz.panzoom("disable");
  },
  drag:function(e,ui){
    ui.position.left = ui.position.left/currentScale;
    ui.position.top = ui.position.top/currentScale;
    if($(this).hasClass("jsplumb-connected"))
    {
      plumb.repaint($(this).attr('id'),ui.position);
    }
  },
  stop: function(e,ui){
    var nodeId = $(this).attr('id');
    if($(this).hasClass("jsplumb-connected"))
    {
      plumb.repaint(nodeId,ui.position);
    }
    $(this).css("cursor","");
    $container.find(".panzoom").panzoom("enable");
  }
});
var currentScale = 1;
$container.find(".diagram .item").draggable({
  start: function(e){
    var pz = $container.find(".panzoom");
    currentScale = pz.panzoom("getMatrix")[0];
    $(this).css("cursor","move");
    pz.panzoom("disable");
  },
  drag:function(e,ui){
    ui.position.left = ui.position.left/currentScale;
    ui.position.top = ui.position.top/currentScale;
    if($(this).hasClass("jsplumb-connected"))
    {
      plumb.repaint($(this).attr('id'),ui.position);
    }
  },
  stop: function(e,ui){
    var nodeId = $(this).attr('id');
    if($(this).hasClass("jsplumb-connected"))
    {
      plumb.repaint(nodeId,ui.position);
    }
    $(this).css("cursor","");
    $container.find(".panzoom").panzoom("enable");
  }
});