private changeLabelMargins()

in src/EnhancedScatterChart.ts [1742:1848]


    private changeLabelMargins(
        doneWithMargins: boolean,
        tickLabelMargins: TickLabelMargins,
        axisLabels: ChartAxesLabels,
        numIterations: number,
        maxIterations: number,
        showY1OnRight: boolean,
        renderXAxis: boolean,
        renderY1Axis: boolean,
        chartHasAxisLabels: boolean,
        changeYAxisSide: boolean = false
    ): { tickLabelMargins: TickLabelMargins, axisLabels: ChartAxesLabels, chartHasAxisLabels: boolean } {
        while (!doneWithMargins && numIterations < maxIterations) {
            numIterations++;

            tickLabelMargins = axis.getTickLabelMargins(
                {
                    width: this.viewportIn.width,
                    height: this.viewport.height
                },
                this.leftRightMarginLimit,
                measureSvgTextWidth,
                measureSvgTextHeight,
                {
                    x: this.xAxisProperties,
                    y1: this.yAxisProperties
                },
                this.bottomMarginLimit,
                EnhancedScatterChart.TextProperties,
                this.isXScrollBarVisible || this.isYScrollBarVisible,
                showY1OnRight,
                renderXAxis,
                renderY1Axis,
                false);

            // We look at the y axes as main and second sides, if the y axis orientation is right so the main side represents the right side
            let maxMainYaxisSide: number = showY1OnRight
                ? tickLabelMargins.yRight
                : tickLabelMargins.yLeft;

            let maxSecondYaxisSide: number = showY1OnRight
                ? tickLabelMargins.yLeft
                : tickLabelMargins.yRight;

            let xMax = tickLabelMargins.xMax;

            maxMainYaxisSide += EnhancedScatterChart.AxisSide;

            if (changeYAxisSide) {
                maxSecondYaxisSide += EnhancedScatterChart.AxisSide;
            }

            if (showY1OnRight && renderY1Axis) {
                maxSecondYaxisSide += EnhancedScatterChart.SecondYAxisSide;
            }

            if (changeYAxisSide && !showY1OnRight && renderY1Axis) {
                maxMainYaxisSide += EnhancedScatterChart.SecondAxisSide;
            }

            xMax += EnhancedScatterChart.XMaxOffset;

            axisLabels = {
                x: this.xAxisProperties.axisLabel,
                y: this.yAxisProperties.axisLabel,
                y2: null
            };

            chartHasAxisLabels = (axisLabels.x != null) || (axisLabels.y != null || axisLabels.y2 != null);

            if (axisLabels.x != null) {
                xMax += EnhancedScatterChart.AdditionalXMaxOffset;
            }

            if (axisLabels.y != null) {
                maxMainYaxisSide += EnhancedScatterChart.SecondAxisSide;
            }

            if (axisLabels.y2 != null) {
                maxSecondYaxisSide += EnhancedScatterChart.SecondAxisSide;
            }

            this.margin.left = showY1OnRight
                ? maxSecondYaxisSide
                : maxMainYaxisSide;

            this.margin.right = showY1OnRight
                ? maxMainYaxisSide
                : maxSecondYaxisSide;

            this.margin.bottom = xMax;

            this.calculateAxes(
                this.data.settings.categoryAxis,
                this.data.settings.valueAxis,
                EnhancedScatterChart.TextProperties
            );

            // the minor padding adjustments could have affected the chosen tick values, which would then need to calculate margins again
            // e.g. [0,2,4,6,8] vs. [0,5,10] the 10 is wider and needs more margin.
            if (this.yAxisProperties.values.length === this.yAxisProperties.values.length) {
                doneWithMargins = !EnhancedScatterChart.DefaultValueOfDoneWithMargins;
            }
        }

        return { tickLabelMargins, axisLabels, chartHasAxisLabels };
    }