antvis/G6

[Bug]: 关于combo折叠后的线条长度问题 #6946

yuequan1997 posted onGitHub

Describe the bug / 问题描述

我正在使用g6的antv-dagre布局绘制图形,同时将过长的数据使用combo组合起来方便折叠查看,但是折叠后线条的长度并没发生变化, layout了也是一样 这是为什么? 我该如何修改线条的长度呢?

展开

Image

折叠

Image

源码

<script setup>
import {onMounted, render} from "vue";
import {Circle, Path} from '@antv/g';
import {CircleCombo, ExtensionCategory, Graph, GraphEvent, register} from "@antv/g6";
import {getNodes} from './initNodes.js';
import {getEdges} from "@/initEdges.js";
import {getCombos} from "@/initCombos.js";

const collapse = (x, y, r) => {
  return [
    ['M', x - r, y],
    ['a', r, r, 0, 1, 0, r * 2, 0],
    ['a', r, r, 0, 1, 0, -r * 2, 0],
    ['M', x - r + 4, y],
    ['L', x + r - 4, y],
  ];
};

const expand = (x, y, r) => {
  return [
    ['M', x - r, y],
    ['a', r, r, 0, 1, 0, r * 2, 0],
    ['a', r, r, 0, 1, 0, -r * 2, 0],
    ['M', x - r + 4, y],
    ['L', x - r + 2 * r - 4, y],
    ['M', x - r + r, y - r + 4],
    ['L', x, y + r - 4],
  ];
};


class CircleComboWithExtraButton extends CircleCombo {
  render(attributes, container) {
    attributes.type = "rect";
    super.render(attributes, container);
    this.drawButton(attributes);
  }

  drawButton(attributes) {
    const { collapsed } = attributes;
    const [, height] = this.getKeySize(attributes);
    const btnR = 8;
    const y = height / 2 + btnR;
    const d = collapsed ? expand(0, y, btnR) : collapse(0, y, btnR);

    const hitArea = this.upsert('hit-area', Circle, { cy: y, r: 10, fill: '#fff', cursor: 'pointer' }, this);
    this.upsert('button', Path, { stroke: '#3d81f7', d, cursor: 'pointer' }, hitArea);
  }

  onCreate() {
    this.shapeMap['hit-area'].addEventListener('click', async () => {
      const id = this.id;
      const collapsed = !this.attributes.collapsed;
      const { graph } = this.context;
      if (collapsed) {
        await graph.collapseElement(id);
      }
      else {
        await graph.expandElement(id);
      }
    });
  }


}

register(ExtensionCategory.COMBO, 'circle-combo-with-extra-button', CircleComboWithExtraButton);
onMounted(() => {
  const graph = new Graph({
    container: document.getElementById("container"),
    //renderer: () => new Renderer(),
    animation: false,
    enableOptimize: true,
    data: {
      nodes: getNodes(),
      edges: getEdges(),
      combos: getCombos(),
    },
    autoResize: true,
    layout: [
      {
        type: 'antv-dagre',
        rankdir: 'LR',
        align: 'UL',
        controlPoints: true,
        nodesep: 25,
        ranksep: 35,
        sortByCombo: true,
      },
    ],
    autoFit: 'view',
    combo: {
      type: 'circle-combo-with-extra-button',
    },
    behaviors: ['level-of-detail', 'zoom-canvas', 'drag-canvas',  'optimize-viewport-transform'],
  });


  graph.once(GraphEvent.AFTER_RENDER, () => {
   graph.getComboData()?.forEach(async (combo) => await graph.collapseElement(combo?.id));
  });

  graph.render();


});
</script>

<template>
  <div id="container" style="height: 100vh"></div>
</template>

No response

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

No response

Version / 版本

5.0.44

OS / 操作系统

  • macOS
  • Windows
  • Linux
  • Others / 其他

Browser / 浏览器

  • Chrome
  • Edge
  • Firefox
  • Safari (Limited support / 有限支持)
  • IE (Nonsupport / 不支持)
  • Others / 其他

📝 To help us better understand and address your issue, please provide more information, or use the standard format, otherwise we will not process this issue.

Reference document:


📝 为了帮助我们更好地理解和解决你的问题,请提供更多信息,或者使用规范的格式,否则我们不会处理这个 issue。

参考文档:

posted by github-actions[bot] 25 days ago

⚠️ This issue has been automatically closed due to inactivity.

  • If the issue is still relevant and important to you, feel free to:
    1. Reopen with additional information
    2. Create a new issue with updated context
    3. Reference any related issues or discussions

We close inactive issues to keep our backlog manageable and focused on active issues.

Your contribution makes our project better! 🌟


⚠️ 由于长期无活动,此 issue 已被自动关闭。

  • 如果这个问题对您来说仍然重要,您可以:
    1. 重新打开并提供补充信息
    2. 创建一个新的 issue 并更新相关背景
    3. 关联相关的 issue 或讨论

为了更好地维护项目,我们需要定期清理不活跃的问题。

感谢您为开源添砖加瓦!🌟

posted by github-actions[bot] 18 days ago

Fund this Issue

$0.00
Funded

Pull requests