visjs / vis-network

:dizzy: Display dynamic, automatically organised, customizable network views.
https://visjs.github.io/vis-network/
Apache License 2.0
3.07k stars 374 forks source link

hover self ref #398

Closed piratuks closed 4 years ago

piratuks commented 4 years ago

Also found that when you try to hover the edge which angle is not Math.PI / 4 then it fails. I found that it is because on however method getDistanceToEdge is called and it executes this._getCircleData(undefined);. Basically passed ctx is undefined which means getSelfRefCoordinates - >if(ctx && typeof node.distanceToBorder === "function"){ returns incorrect data.

So the solution could be to remove case sentence and check under each _distanceToBorder if ctx was provided, basically skip resize(ctx), because in this case it is needed just calculation.

Any thoughs?

Thomaash commented 4 years ago

Hi @piratuks,

could you provide more info about this? Preferably an MWE demonstrating what's wrong. Because I don't see anything broken fiddling with it. Also you changed node shape methods in your PR but talk about edge methods here.

Thanks.

piratuks commented 4 years ago

@Thomaash

    var nodes = new vis.DataSet([
        {
            id: 1,
            label:
                [
                    "I'm an alligator,",
                    "I'm a mama-papa coming for you.",
                    "I'm the space invader,",
                    "I'll be a rock 'n' rollin' bitch for you."
                ].join("\n"),
            x: 0,
            y: 0,
            color: {
                background: "transparent"
            }
        },
        {
            id: 2,
            label:
                [
                    "An edge connected to the same node on both end renders a circle.",
                    "Both from and to arrows point to the same node.",
                    "The radius of the edge can be adjusted using selfReference.size.",
                    "The edge can be positioned using selfReference.angle.",
                    "The part of the edge behind the node can be hidden using selfReference.renderBehindTheNode."].join("\n"),
            widthConstraint: { minimum: 100 }, heightConstraint: { minimum: 100 },
            x: 200,
            y: 200,
            color: {
                background: "transparent"
            }
        },
        {
            id: 3,
            label:
                ["Self reference edge is in the bottom left corner",
                    "with parts rendered behind node"].join("\n"),
            widthConstraint: { minimum: 100 }, heightConstraint: { minimum: 100 },
            x: 400,
            y: 400,
            color: {
                background: "transparent"
            },
            shape: "box"
        },
    ]);

    // create an array with edges
    var edges = new vis.DataSet([
        { from: 1, to: 1, label: "Moonage Daydream" },
        {
            from: 2, to: 2, label: "Testing", arrows: 'to, middle, from',
            selfReference: {
                size: 40,
                angle: Math.PI * 7 / 6,
                renderBehindTheNode: false
            }
        },
        {
            from: 3, to: 3, label: "Testing", arrows: 'to, middle, from',
            selfReference: {
                size: 40,
                angle: Math.PI * 7 / 6,
                renderBehindTheNode: true
            }
        }
    ]);

    // create a network
    var container = document.getElementById("mynetwork");
    var data = {
        nodes: nodes,
        edges: edges
    };
    var options = {
        edges: {
            color: {
                color: "#2B7CE9",
                highlight: "#2B7CE9",
                hover: "#2B7CE9"
            },
            hoverWidth: function (width) { return width + 2; },
            shadow: true
        },
        interaction: {
            hover: true,
        },
    };
    var network = new vis.Network(container, data, options);
piratuks commented 4 years ago

Run the code on current release and try to hover self ref edge this will illustrates issue and this PR pin points it where i missed it on feature PR when i did it.

Thomaash commented 4 years ago

Oh, now I see it. The bounding box of the edge is in a different place.

vis-bot commented 4 years ago

:tada: This issue has been resolved in version 7.3.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: