buildAlternativeAllelesLabels()

in client/client/modules/render/tracks/vcf/internal/renderer/collapsed/variants/variantContainer.js [154:269]


    buildAlternativeAllelesLabels(manager) {
        const alternativeAllelesLabelsRect = {
            global: {
                x: this.container.x,
                y: this.container.y
            },
            rect: {
                x1: -this._variant.allelesDescriptionsWidth / 2
                    - this._config.variant.allele.intersection.horizontalMargin,
                x2: this._variant.allelesDescriptionsWidth / 2
                    + this._config.variant.allele.intersection.horizontalMargin,
                y1: -this._config.variant.height - this._variant.allelesDescriptionsHeight,
                y2: -this._config.variant.height
            }
        };
        const allelesArea = manager.checkArea('default', alternativeAllelesLabelsRect, {translateX: 0, translateY: -1});
        if (!allelesArea.conflicts) {
            manager.submitArea('default', allelesArea);
        } else {
            const white = 0xFFFFFF;
            this._hasTooltip = true;
            const tooltipGraphics = new PIXI.Graphics();
            tooltipGraphics.x = -this._variant.allelesDescriptionsWidth / 2;
            const borderThickness = 1;
            tooltipGraphics
                .lineStyle(borderThickness, 0x000000, 1)
                .beginFill(white, 1)
                .drawRect(
                    borderThickness / 2,
                    borderThickness / 2,
                    this._variant.allelesDescriptionsWidth - borderThickness,
                    this._variant.allelesDescriptionsHeight - borderThickness)
                .endFill();
            this._tooltipContainer = new PIXI.Container();
            this._tooltipContainer.addChild(tooltipGraphics);
        }
        const allelesContainer = allelesArea.conflicts ? this._tooltipContainer : this._container;
        let y = allelesArea.conflicts ? 0 : allelesArea.rect.y1;
        for (let i = 0; i < this._variant.alternativeAllelesInfo.length; i++) {
            if (!this._variant.alternativeAllelesInfo[i].displayText) {
                continue;
            }
            const label = this.labelsManager
                ? this.labelsManager.getLabel(
                    this._variant.alternativeAllelesInfo[i].displayText,
                    this._config.variant.allele.label
                )
                : undefined;
            if (label) {
                label.x = -Math.round(label.width / 2);
                label.y = Math.round(y);
                allelesContainer.addChild(label);
                y += label.height + this._config.variant.allele.margin;
            }
        }
        const line = {
            end: {
                x: (allelesArea.rect.x1 + allelesArea.rect.x2) / 2,
                y: allelesArea.rect.y2
            },
            start: {
                x: 0,
                y: -this._config.variant.height,
            }
        };
        if (allelesArea.conflicts) {
            const tooltipZone = manager.getZoneBoundaries('tooltip', {x: this.container.x, y: this.container.y});
            if (tooltipZone) {
                const tooltipLabel = this.labelsManager
                    ? this.labelsManager.getLabel('...', this._config.variant.allele.detailsTooltipLabel)
                    : undefined;
                if (tooltipLabel) {
                    const tooltipRect = {
                        global: {
                            x: this.container.x,
                            y: this.container.y
                        },
                        rect: {
                            x1: -tooltipLabel.width / 2,
                            x2: tooltipLabel.width / 2,
                            y1: (tooltipZone.y1 + tooltipZone.y2) / 2 - tooltipLabel.height / 2,
                            y2: (tooltipZone.y1 + tooltipZone.y2) / 2 + tooltipLabel.height / 2
                        }
                    };
                    this._tooltipArea = manager.checkArea('tooltip', tooltipRect, {translateX: 1, translateY: 0});
                    if (!this._tooltipArea.conflicts) {
                        manager.submitArea('tooltip', this._tooltipArea);
                        tooltipLabel.x =
                            Math.round((this._tooltipArea.rect.x1 + this._tooltipArea.rect.x2) / 2 - tooltipLabel.width
                                / 2);
                        tooltipLabel.y = Math.round(this._tooltipArea.rect.y2 - tooltipLabel.height);

                        this._container.addChild(tooltipLabel);

                        line.end.x = (this._tooltipArea.rect.x1 + this._tooltipArea.rect.x2) / 2;
                        line.end.y = this._tooltipArea.rect.y2;
                        this._tooltipPosition = new PIXI.Point(tooltipZone.x1, tooltipZone.y1);
                    }
                }
            }
        }
        drawDashLine(
            this.linesGraphics, 2,
            {
                xStart: line.start.x,
                yStart: line.start.y
            },
            {
                xEnd: line.end.x,
                yEnd: line.end.y
            },
            {
                stroke: 0x000000,
                thickness: 1
            });
    }