antvis / G6

♾ A Graph Visualization Framework in JavaScript.
https://g6.antv.antgroup.com/
MIT License
11.16k stars 1.33k forks source link

When dragging a node in the brain map, insert a temporary node to show the current inserted position, but it is always stuck and cannot be continued #6509

Open wangtao-bugkiller opened 1 week ago

wangtao-bugkiller commented 1 week ago

Describe the bug / 问题描述

脑图里面拖拽节点的时候,去插入一个临时节点来显示当前插入的位置,总是卡死无法继续

Reproduction link / 重现链接

No response

Steps to Reproduce the Bug or Issue / 重现步骤

let dragNodeOriPos, minDisNode, minDisNodeId, dragRect, insertPos, insertIndex, lastInsertPostion, lastMinDisNode, lastMinDisNodeId, targetIndex, newParentId, newParentNode, targetInsertIndex, targetParentID;

/**

G6 Version / G6 版本

4.x

Operating System / 操作系统

macOS

Browser / 浏览器

Chrome

Additional context / 补充说明

No response

wangtao-bugkiller commented 1 week ago

是想在拖动的过程中实时的更新这个节点将要插入的位置,每次一插入临时节点就卡死了

wangtao-bugkiller commented 1 week ago

image

wangtao-bugkiller commented 1 week ago

const treeLayout = { type: 'mindmap', direction: 'LR', getHeight: node => { const { images, title, id } = node; let textArr = splitTitle(title); let textHeight = textArr.length * 26 + 20; if (images && images?.length > 0) { textArr += 52; }

  return textHeight;
},
getWidth: node => {
  const { depth, images, marks, nodeType, title } = node;
  const textWidth = depth === 0 ? getTextSize(title, 30)[0] : getTextSize(title, 22)[0];
  // 对 marks 进行边界条件检查
  let tagsWidth = getTagListLength(marks);
  const nodeTypeWidth = nodeType === 'CATA' ? 30 : 0;
  const imageLength = images ? images.length * 52 : 0;
  // 确保 textWidth 的值在合理的范围内,以避免潜在的计算错误
  const adjustedTextWidth = textWidth > 800 ? 900 : textWidth;
  const width = Math.max(adjustedTextWidth + tagsWidth + nodeTypeWidth, imageLength);
  return width;
},
getVGap: d => {
  const { children, depth, images } = d;
  if (Array.isArray(images) && images.length > 0) {
    return 40;
  }
  return 20;
},
getHGap: d => {
  const { children, depth } = d;
  if (!depth) {
    return 60;
  }
  const times = {
    0: 10,
    1: 9,
    2: 7,
    3: 6,
  };
  if (children && children.length > 0) {
    return children.length * (times[depth] || 6) + (children.length < 5 ? 40 : 10);
  }

  return 30;
},
getSide: node => {
  return 'right';
},

}; const renderG6 = () => { const grid = new G6.Grid(); const minimap = new G6.Minimap({ size: [150, 150], className: 'g6-minimap', type: 'delegate', hideEdge: true, });

const container = document.getElementById('xmindContainer');
const width = container.getBoundingClientRect().width;
const height = container.getBoundingClientRect().height;
setDivWH({ width, height });
mindMapTree = new G6.TreeGraph({
  container: 'xmindContainer',
  width,
  height,
  // fitView: true,
  fitCenter: true,
  enabledStack: true,
  maxStep: 20,
  // autoRefresh: true,
  // fitViewPadding: [10, 20],
  layout: treeLayout,
  defaultEdge: {
    type: 'cubic-horizontal',
    style: {
      lineWidth: 2,
      stroke: '#CED4D9',
    },
  },
  animate: false,
  animateCfg: {
    duration: 300, // Number,一次动画的时长
  },
  defaultNode: {
    type: 'dice-mind-map-root',
  },
  minZoom: 0.5,
  modes: {
    default: [
      {
        type: 'drag-node',
        enableDelegate: true,
        enableStack: false,
        enableDebounce: true,
        // shouldUpdate: function(e, self) {
        //   return true;
        // },
      },
      {
        type: 'collapse-expand',
        onChange: function onChange(item, collapsed) {
          const data = item.get('model');
          data.collapsed = collapsed;
          return true;
        },
        shouldBegin: (e, self) => {
          return false;
        },
      },
      'wheel-scroll',
      'scroll-canvas',
      'dice-mindmap',
      'dice-mindmap-drag',
      {
        type: 'click-select',
        trigger: 'shift',
        shouldBegin: (e, self) => {
          const actionsList = ['expand', 'collapse', 'deleteTargetTag'];
          const nameList = ['collapse-icon'];
          const status = e.item?._cfg?.states || [];
          const action = e.target?.cfg?.action || '';
          const regex = /previewPic(\d+)/;
          const match = action.match(regex);
          const regexDel = /deletePic(\d+)/;
          const matchDel = action.match(regexDel);
          const name = e.target?.cfg?.name || '';

          if (
            (nameList.includes(name) || match || matchDel || actionsList.includes(action)) &&
            status.includes('selected')
          )
            return false;
          return true;
        },
      },
      {
        type: 'brush-select',
        trigger: 'drag',
        includeEdges: false,
      },
    ],
  },
  plugins: [minimap, grid],
});

mindMapTree.data(dataTransform(xmindData || {}));

mindMapTree.render(); };

wangtao-bugkiller commented 1 week ago

麻烦帮忙看下,拖拽改变节点的顺序,得有一个临时节点在拖拽过程中实时插入图里显示当前插入位置,就像xmind 软件里面拖拽节点的功能那样,我在插入临时节点的时候渲染就卡住了,不知道怎么解决

wangtao-bugkiller commented 4 days ago

麻烦帮忙看一下