/* eslint-disable class-methods-use-this */
/* eslint-disable no-plusplus */
/* eslint-disable no-continue */
/* eslint-disable no-param-reassign */
import { Graph } from '@api-client/graph';
import { getObjectBoundingClientRect } from '../../lib/PositionUtils.js';
// 01 - external association
// 10 - association (internal)
// 20 - parent association
// 40 - self association
export var LayoutWeight;
(function (LayoutWeight) {
    LayoutWeight[LayoutWeight["External"] = 1] = "External";
    LayoutWeight[LayoutWeight["Internal"] = 10] = "Internal";
    LayoutWeight[LayoutWeight["Parent"] = 40] = "Parent";
    LayoutWeight[LayoutWeight["Self"] = 80] = "Self";
})(LayoutWeight || (LayoutWeight = {}));
;
/**
 * A helper library that computes positioning of a data model
 * in the visualization workspace.
 */
export class WorkspaceLayout {
    constructor(workspace) {
        this.workspace = workspace;
        this.readPositions = {};
        /**
         * Number of pixels that separate edges horizontally in the layout.
         */
        this.edgeSeparation = 20;
        /**
         * Number of pixels between each rank in the layout.
         */
        this.rankSeparation = 60; // 80
        /**
         * Number of pixels that separate nodes horizontally in the layout.
         */
        this.nodeSeparation = 60; // 80
        /**
         * Graph margin LR
         */
        this.marginX = 40;
        /**
         * Graph margin TB
         */
        this.marginY = 40;
    }
    /**
     * Reads workspace object dimensions
     * @param {string} id Domain id of the object
     * @returns {DOMRect}
     */
    readDimensions(id) {
        if (this.readPositions[id]) {
            return this.readPositions[id];
        }
        const element = this.workspace.querySelector(`[data-key="${id}"]`);
        if (!element) {
            return undefined;
        }
        const rect = getObjectBoundingClientRect(element, this.workspace);
        this.readPositions[id] = rect;
        return rect;
    }
    initGraph() {
        const g = new Graph();
        const { rankDir, align, ranker, acyclicer, edgeSeparation, rankSeparation, nodeSeparation, marginX, marginY } = this;
        g.setGraph({
            edgeSeparation,
            rankSeparation,
            nodeSeparation,
            rankDir,
            align,
            ranker,
            acyclicer,
            marginX,
            marginY,
        });
        // eslint-disable-next-line arrow-body-style
        // g.setDefaultEdgeLabel(() => { return {}; });
        return g;
    }
}
//# sourceMappingURL=WorkspaceLayout.js.map