constructor()

in web/src/app/pages/graph/architecture-graph/graph/base/base-containers.ts [590:676]


  constructor(public readonly direction: Direction) {
    super(
      document.createElementNS(
        'http://www.w3.org/2000/svg',
        'g',
      ) as SVGGElement,
    );
    this.transform.onOverrideChildrenOffsets = (originalPos) => {
      const offsets = [];
      let changingSideOffset = 0;
      let maxChildSize = 0;
      for (const child of this.transform.children) {
        const childSize = child.calculateSize();
        const childMargin = child.margin;
        switch (this.direction) {
          case Direction.Horizontal:
            offsets.push({
              x: childMargin.left + originalPos.x + changingSideOffset,
              y: originalPos.y + childMargin.top,
            });
            changingSideOffset +=
              childSize.width + childMargin.left + childMargin.right;
            changingSideOffset += this._gap;
            maxChildSize = Math.max(
              maxChildSize,
              childSize.height + childMargin.top + childMargin.bottom,
            );
            break;
          case Direction.Vertical:
            offsets.push({
              y: childMargin.top + originalPos.y + changingSideOffset,
              x: originalPos.x + childMargin.left,
            });
            changingSideOffset +=
              childSize.height + childMargin.top + childMargin.bottom;
            changingSideOffset += this._gap;
            maxChildSize = Math.max(
              maxChildSize,
              childSize.width + childMargin.left + childMargin.right,
            );
            break;
        }
      }
      if (this._expandChildren) {
        for (const child of this.transform.children) {
          switch (this.direction) {
            case Direction.Horizontal:
              child.minSize = { height: maxChildSize, width: 0 };
              break;
            case Direction.Vertical:
              child.minSize = { height: 0, width: maxChildSize };
              break;
          }
        }
      }
      return offsets;
    };
    this.transform.onSvgElementUpdate = () => {
      return;
    };
    this.transform.onCustomContentSizeCalculate = () => {
      const childTransforms = this.transform.children;
      switch (this.direction) {
        case Direction.Horizontal:
          return {
            width:
              childTransforms.reduce((p, c) => p + c.sizeWithMargin.width, 0) +
              this._gap * Math.max(0, childTransforms.length - 1),
            height: childTransforms.reduce(
              (p, c) => Math.max(p, c.sizeWithMargin.height),
              0,
            ),
          };
        case Direction.Vertical:
          return {
            height:
              childTransforms.reduce((p, c) => p + c.sizeWithMargin.height, 0) +
              this._gap * Math.max(0, childTransforms.length - 1),
            width: childTransforms.reduce(
              (p, c) => Math.max(p, c.sizeWithMargin.width),
              0,
            ),
          };
      }
      throw new Error('unreachable');
    };
  }