mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 06:49:47 +02:00
Merge pull request #4860 from dreathed/bug/4849_center_axis_labels
bug/4849_center_axis_labels
This commit is contained in:
@@ -160,4 +160,70 @@ describe('Quadrant Chart', () => {
|
|||||||
);
|
);
|
||||||
cy.get('svg');
|
cy.get('svg');
|
||||||
});
|
});
|
||||||
|
it('should render x-axis labels in the center, if x-axis has two labels', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
quadrantChart
|
||||||
|
title Reach and engagement of campaigns
|
||||||
|
x-axis Low Reach --> High Reach
|
||||||
|
y-axis Low Engagement
|
||||||
|
quadrant-1 We should expand
|
||||||
|
quadrant-2 Need to promote
|
||||||
|
quadrant-3 Re-evaluate
|
||||||
|
quadrant-4 May be improved
|
||||||
|
Campaign A: [0.3, 0.6]
|
||||||
|
Campaign B: [0.45, 0.23]
|
||||||
|
Campaign C: [0.57, 0.69]
|
||||||
|
Campaign D: [0.78, 0.34]
|
||||||
|
Campaign E: [0.40, 0.34]
|
||||||
|
Campaign F: [0.35, 0.78]
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
cy.get('svg');
|
||||||
|
});
|
||||||
|
it('should render y-axis labels in the center, if y-axis has two labels', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
quadrantChart
|
||||||
|
title Reach and engagement of campaigns
|
||||||
|
x-axis Low Reach
|
||||||
|
y-axis Low Engagement --> High Engagement
|
||||||
|
quadrant-1 We should expand
|
||||||
|
quadrant-2 Need to promote
|
||||||
|
quadrant-3 Re-evaluate
|
||||||
|
quadrant-4 May be improved
|
||||||
|
Campaign A: [0.3, 0.6]
|
||||||
|
Campaign B: [0.45, 0.23]
|
||||||
|
Campaign C: [0.57, 0.69]
|
||||||
|
Campaign D: [0.78, 0.34]
|
||||||
|
Campaign E: [0.40, 0.34]
|
||||||
|
Campaign F: [0.35, 0.78]
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
cy.get('svg');
|
||||||
|
});
|
||||||
|
it('should render both axes labels on the left and bottom, if both axes have only one label', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
quadrantChart
|
||||||
|
title Reach and engagement of campaigns
|
||||||
|
x-axis Reach -->
|
||||||
|
y-axis Engagement -->
|
||||||
|
quadrant-1 We should expand
|
||||||
|
quadrant-2 Need to promote
|
||||||
|
quadrant-3 Re-evaluate
|
||||||
|
quadrant-4 May be improved
|
||||||
|
Campaign A: [0.3, 0.6]
|
||||||
|
Campaign B: [0.45, 0.23]
|
||||||
|
Campaign C: [0.57, 0.69]
|
||||||
|
Campaign D: [0.78, 0.34]
|
||||||
|
Campaign E: [0.40, 0.34]
|
||||||
|
Campaign F: [0.35, 0.78]
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
cy.get('svg');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -283,14 +283,17 @@ export class QuadrantBuilder {
|
|||||||
quadrantTop,
|
quadrantTop,
|
||||||
quadrantWidth,
|
quadrantWidth,
|
||||||
} = quadrantSpace;
|
} = quadrantSpace;
|
||||||
const drawAxisLabelInMiddle = this.data.points.length === 0;
|
|
||||||
|
const drawXAxisLabelsInMiddle = Boolean(this.data.xAxisRightText);
|
||||||
|
const drawYAxisLabelsInMiddle = Boolean(this.data.yAxisTopText);
|
||||||
|
|
||||||
const axisLabels: QuadrantTextType[] = [];
|
const axisLabels: QuadrantTextType[] = [];
|
||||||
|
|
||||||
if (this.data.xAxisLeftText && showXAxis) {
|
if (this.data.xAxisLeftText && showXAxis) {
|
||||||
axisLabels.push({
|
axisLabels.push({
|
||||||
text: this.data.xAxisLeftText,
|
text: this.data.xAxisLeftText,
|
||||||
fill: this.themeConfig.quadrantXAxisTextFill,
|
fill: this.themeConfig.quadrantXAxisTextFill,
|
||||||
x: quadrantLeft + (drawAxisLabelInMiddle ? quadrantHalfWidth / 2 : 0),
|
x: quadrantLeft + (drawXAxisLabelsInMiddle ? quadrantHalfWidth / 2 : 0),
|
||||||
y:
|
y:
|
||||||
xAxisPosition === 'top'
|
xAxisPosition === 'top'
|
||||||
? this.config.xAxisLabelPadding + titleSpace.top
|
? this.config.xAxisLabelPadding + titleSpace.top
|
||||||
@@ -299,7 +302,7 @@ export class QuadrantBuilder {
|
|||||||
quadrantHeight +
|
quadrantHeight +
|
||||||
this.config.quadrantPadding,
|
this.config.quadrantPadding,
|
||||||
fontSize: this.config.xAxisLabelFontSize,
|
fontSize: this.config.xAxisLabelFontSize,
|
||||||
verticalPos: drawAxisLabelInMiddle ? 'center' : 'left',
|
verticalPos: drawXAxisLabelsInMiddle ? 'center' : 'left',
|
||||||
horizontalPos: 'top',
|
horizontalPos: 'top',
|
||||||
rotation: 0,
|
rotation: 0,
|
||||||
});
|
});
|
||||||
@@ -308,7 +311,7 @@ export class QuadrantBuilder {
|
|||||||
axisLabels.push({
|
axisLabels.push({
|
||||||
text: this.data.xAxisRightText,
|
text: this.data.xAxisRightText,
|
||||||
fill: this.themeConfig.quadrantXAxisTextFill,
|
fill: this.themeConfig.quadrantXAxisTextFill,
|
||||||
x: quadrantLeft + quadrantHalfWidth + (drawAxisLabelInMiddle ? quadrantHalfWidth / 2 : 0),
|
x: quadrantLeft + quadrantHalfWidth + (drawXAxisLabelsInMiddle ? quadrantHalfWidth / 2 : 0),
|
||||||
y:
|
y:
|
||||||
xAxisPosition === 'top'
|
xAxisPosition === 'top'
|
||||||
? this.config.xAxisLabelPadding + titleSpace.top
|
? this.config.xAxisLabelPadding + titleSpace.top
|
||||||
@@ -317,7 +320,7 @@ export class QuadrantBuilder {
|
|||||||
quadrantHeight +
|
quadrantHeight +
|
||||||
this.config.quadrantPadding,
|
this.config.quadrantPadding,
|
||||||
fontSize: this.config.xAxisLabelFontSize,
|
fontSize: this.config.xAxisLabelFontSize,
|
||||||
verticalPos: drawAxisLabelInMiddle ? 'center' : 'left',
|
verticalPos: drawXAxisLabelsInMiddle ? 'center' : 'left',
|
||||||
horizontalPos: 'top',
|
horizontalPos: 'top',
|
||||||
rotation: 0,
|
rotation: 0,
|
||||||
});
|
});
|
||||||
@@ -334,9 +337,9 @@ export class QuadrantBuilder {
|
|||||||
quadrantLeft +
|
quadrantLeft +
|
||||||
quadrantWidth +
|
quadrantWidth +
|
||||||
this.config.quadrantPadding,
|
this.config.quadrantPadding,
|
||||||
y: quadrantTop + quadrantHeight - (drawAxisLabelInMiddle ? quadrantHalfHeight / 2 : 0),
|
y: quadrantTop + quadrantHeight - (drawYAxisLabelsInMiddle ? quadrantHalfHeight / 2 : 0),
|
||||||
fontSize: this.config.yAxisLabelFontSize,
|
fontSize: this.config.yAxisLabelFontSize,
|
||||||
verticalPos: drawAxisLabelInMiddle ? 'center' : 'left',
|
verticalPos: drawYAxisLabelsInMiddle ? 'center' : 'left',
|
||||||
horizontalPos: 'top',
|
horizontalPos: 'top',
|
||||||
rotation: -90,
|
rotation: -90,
|
||||||
});
|
});
|
||||||
@@ -352,9 +355,10 @@ export class QuadrantBuilder {
|
|||||||
quadrantLeft +
|
quadrantLeft +
|
||||||
quadrantWidth +
|
quadrantWidth +
|
||||||
this.config.quadrantPadding,
|
this.config.quadrantPadding,
|
||||||
y: quadrantTop + quadrantHalfHeight - (drawAxisLabelInMiddle ? quadrantHalfHeight / 2 : 0),
|
y:
|
||||||
|
quadrantTop + quadrantHalfHeight - (drawYAxisLabelsInMiddle ? quadrantHalfHeight / 2 : 0),
|
||||||
fontSize: this.config.yAxisLabelFontSize,
|
fontSize: this.config.yAxisLabelFontSize,
|
||||||
verticalPos: drawAxisLabelInMiddle ? 'center' : 'left',
|
verticalPos: drawYAxisLabelsInMiddle ? 'center' : 'left',
|
||||||
horizontalPos: 'top',
|
horizontalPos: 'top',
|
||||||
rotation: -90,
|
rotation: -90,
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user