/*
     $Revision$
     $Id$

     File:          vis-network-utils.js
     Description:   clientside defaults and functions for vis-network
*/

const visnetwork = {
    defaultOptions: {
        nodes: {
            shape: "box",
            font: {
                color: "#ffffff",
                size: 14
            },
            color: {
                border: "#041260", // var(--aareon-color-1)
                background: "#1770f6", // var(--aareon-color-2)
                highlight: {
                    border: "#041260", // var(--aareon-color-1)
                    background: "#1770f6", // var(--aareon-color-2)
                }
            },
            labelHighlightBold: false
        },
        edges: {
            smooth: {
                type: "cubicBezier",
                forceDirection: "vertical",
                roundness: .4,
            },
            arrows: {},
            font: {
                align: "middle"
            },
            color: {
                color: "#1770f6", // var(--aareon-color-2)
                highlight: "#041260" // var(--aareon-color-1)
            }
        },
        layout: {
            hierarchical: {
                nodeSpacing: 100,
                direction: "UD",
                sortMethod: "directed"
            }
        },
        interaction: {
            tooltipDelay: 0
        },
        physics: {
            enabled: false
        }
    },
    getDefaultOptions: dir => {
        var options = JSON.parse(JSON.stringify(visnetwork.defaultOptions));
        if (dir && dir === "LR") {
            options.edges.smooth.forceDirection = "horizontal";
            options.layout.hierarchical.nodeSpacing = 50;
            options.layout.hierarchical.direction = "LR";
        }
        return options;
    },
    init: network => {
        if (!$(network.body?.container).is(":visible")) {
            network.on("initRedraw", _ => { // Als we hidden geladen zijn (in een subtab bijv.), zijn we niet gecentreerd. Re-fit daarom (alleen dan) 1x
                if ($(network.body.container).is(":visible")) {
                    network.off("initRedraw");
                    network.fit();
                }
            });
        }
    }
}