antvis/G6

Do you want to work on this issue?

You can request for a bounty in order to promote it!

[Bug]: ComboCombined layout crashes when combos.length === 1 #6779

orzechowskid posted onGitHub

Describe the bug / 问题描述

I am attempting to render a graph using the combo-combined layout, and I get an error when the number of combos is exactly 1. outerPositions is never calculated, so outerPositions.nodes.find() does not exist.

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'nodes')
    at chunk-ERQFASD5.js?v=e9fd4546:50194:48
    at Map.forEach (<anonymous>)
    at ComboCombinedLayout.<anonymous> (chunk-ERQFASD5.js?v=e9fd4546:50192:20)
    at Generator.next (<anonymous>)
    at fulfilled (tslib.es6.mjs:118:56)

in combo-combined.js a value for outerPositions is only yield'd when outerLayoutNodes.length !== 1: code:

                if (outerLayoutNodes.length === 1) {
                    outerLayoutNodes[0].data.x = center[0];
                    outerLayoutNodes[0].data.y = center[1];
                }
                else {
                    const outerLayoutGraph = new GraphCore({
                        nodes: outerLayoutNodes,
                        edges: outerLayoutEdges,
                    });
                    const outerLayout = propsOuterLayout || new ForceLayout();
                    // preset the nodes if the outerLayout is a force family layout
                    if (allHaveNoPosition && FORCE_LAYOUT_TYPE_MAP[outerLayout.id]) {
                        const outerLayoutPreset = outerLayoutNodes.length < 100
                            ? new MDSLayout()
                            : new ConcentricLayout();
                        yield outerLayoutPreset.assign(outerLayoutGraph);
                    }
                    const options = Object.assign({ center, kg: 5, preventOverlap: true, animate: false }, (outerLayout.id === 'force'
                        ? {
                            gravity: 1,
                            factor: 4,
                            linkDistance: (edge, source, target) => {
                                const sourceSize = Math.max(...source.data.size) || 32;
                                const targetSize = Math.max(...target.data.size) || 32;
                                return sourceSize / 2 + targetSize / 2 + 200;
                            },
                        }
                        : {}));
-->                 outerPositions = yield executeLayout(outerLayout, outerLayoutGraph, options);
                }

No response

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

layout:

{
        type: "combo-combined",
        innerLayout: new CircularLayout({
          nodeSize: 60,
        }),
        outerLayout: new D3ForceLayout({
        collide: {
            radius: 150,
        },
        link: {
            distance: (edge) =>
                edge.id.startsWith("cross-platform") &&
                    edge.source.platform !== edge.target.platform
                    ? 1000
                    : 350,
        },
        preventOverlap: true,
    })
}

combos:

{
    "combos": [
        {
            "data": {
                "platform": "twitter"
            },
            "id": "e169b6d5-8272-49ed-84f6-f999a45ca797",
            "label": "",
            "collapsed": false,
        }
    ]
}

nodes:

[
        {
            "data": {
                "id": "12c1652e-39d6-4c8d-b6d5-cadfdc429d28",
                "platform": "twitter",
            },
            "combo": "e169b6d5-8272-49ed-84f6-f999a45ca797",
            "id": "12c1652e-39d6-4c8d-b6d5-cadfdc429d28",
        },
        {
            "data": {
                "id": "380f94e9-9156-454f-803b-d52ec2408382",
                "platform": "twitter",
            },
            "combo": "e169b6d5-8272-49ed-84f6-f999a45ca797",
            "id": "380f94e9-9156-454f-803b-d52ec2408382",
        },
        {
            "data": {
                "id": "44c7768f-01da-44cd-af68-01770ddc4a01",
                "platform": "twitter",
            },
            "combo": "e169b6d5-8272-49ed-84f6-f999a45ca797",
            "id": "44c7768f-01da-44cd-af68-01770ddc4a01",
        },
]

Version / 版本

Please select / 请选择

OS / 操作系统

  • macOS
  • Windows
  • Linux
  • Others / 其他

Browser / 浏览器

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

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests