diff --git a/packages/mermaid/src/diagrams/quadrant-chart/quadrantBuilder.ts b/packages/mermaid/src/diagrams/quadrant-chart/quadrantBuilder.ts index f3ca3c3a6..5b740b0e0 100644 --- a/packages/mermaid/src/diagrams/quadrant-chart/quadrantBuilder.ts +++ b/packages/mermaid/src/diagrams/quadrant-chart/quadrantBuilder.ts @@ -283,14 +283,14 @@ export class QuadrantBuilder { quadrantTop, quadrantWidth, } = quadrantSpace; - + const drawAxisLabelInMiddle = this.data.points.length === 0; const axisLabels: QuadrantTextType[] = []; if (this.data.xAxisLeftText && showXAxis) { axisLabels.push({ text: this.data.xAxisLeftText, fill: this.themeConfig.quadrantXAxisTextFill, - x: quadrantLeft + quadrantHalfWidth / 2, + x: quadrantLeft + (drawAxisLabelInMiddle ? quadrantHalfWidth / 2 : 0), y: xAxisPosition === 'top' ? this.config.xAxisLabelPadding + titleSpace.top @@ -299,7 +299,7 @@ export class QuadrantBuilder { quadrantHeight + this.config.quadrantPadding, fontSize: this.config.xAxisLabelFontSize, - verticalPos: 'center', + verticalPos: drawAxisLabelInMiddle ? 'center' : 'left', horizontalPos: 'top', rotation: 0, }); @@ -308,7 +308,7 @@ export class QuadrantBuilder { axisLabels.push({ text: this.data.xAxisRightText, fill: this.themeConfig.quadrantXAxisTextFill, - x: quadrantLeft + quadrantHalfWidth + quadrantHalfWidth / 2, + x: quadrantLeft + quadrantHalfWidth + (drawAxisLabelInMiddle ? quadrantHalfWidth / 2 : 0), y: xAxisPosition === 'top' ? this.config.xAxisLabelPadding + titleSpace.top @@ -317,7 +317,7 @@ export class QuadrantBuilder { quadrantHeight + this.config.quadrantPadding, fontSize: this.config.xAxisLabelFontSize, - verticalPos: 'center', + verticalPos: drawAxisLabelInMiddle ? 'center' : 'left', horizontalPos: 'top', rotation: 0, }); @@ -334,9 +334,9 @@ export class QuadrantBuilder { quadrantLeft + quadrantWidth + this.config.quadrantPadding, - y: quadrantTop + quadrantHeight - quadrantHalfHeight / 2, + y: quadrantTop + quadrantHeight - (drawAxisLabelInMiddle ? quadrantHalfHeight / 2 : 0), fontSize: this.config.yAxisLabelFontSize, - verticalPos: 'center', + verticalPos: drawAxisLabelInMiddle ? 'center' : 'left', horizontalPos: 'top', rotation: -90, }); @@ -352,9 +352,9 @@ export class QuadrantBuilder { quadrantLeft + quadrantWidth + this.config.quadrantPadding, - y: quadrantTop + quadrantHalfHeight - quadrantHalfHeight / 2, + y: quadrantTop + quadrantHalfHeight - (drawAxisLabelInMiddle ? quadrantHalfHeight / 2 : 0), fontSize: this.config.yAxisLabelFontSize, - verticalPos: 'center', + verticalPos: drawAxisLabelInMiddle ? 'center' : 'left', horizontalPos: 'top', rotation: -90, });