Skip to content

Commit

Permalink
Merge branch 'mermaid-js:develop' into chore/shorten-flow-huge-test-case
Browse files Browse the repository at this point in the history
  • Loading branch information
Yokozuna59 authored Sep 22, 2023
2 parents bd86197 + 0534d75 commit ca960c4
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ module.exports = {
'no-unused-vars': 'off',
'cypress/no-async-tests': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/ban-ts-comment': [
'error',
{
Expand Down
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ representative at an online or offline event.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at [email protected]
.
reported to the community leaders responsible for enforcement at <[email protected]>.

All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
Expand Down
66 changes: 66 additions & 0 deletions cypress/integration/rendering/quadrantChart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,70 @@ describe('Quadrant Chart', () => {
);
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');
});
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
"@types/node": "^18.16.0",
"@types/prettier": "^2.7.2",
"@types/rollup-plugin-visualizer": "^4.2.1",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"@vitest/coverage-v8": "^0.34.0",
"@vitest/spy": "^0.34.0",
"@vitest/ui": "^0.34.0",
Expand Down
22 changes: 13 additions & 9 deletions packages/mermaid/src/diagrams/quadrant-chart/quadrantBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,17 @@ export class QuadrantBuilder {
quadrantTop,
quadrantWidth,
} = quadrantSpace;
const drawAxisLabelInMiddle = this.data.points.length === 0;

const drawXAxisLabelsInMiddle = Boolean(this.data.xAxisRightText);
const drawYAxisLabelsInMiddle = Boolean(this.data.yAxisTopText);

const axisLabels: QuadrantTextType[] = [];

if (this.data.xAxisLeftText && showXAxis) {
axisLabels.push({
text: this.data.xAxisLeftText,
fill: this.themeConfig.quadrantXAxisTextFill,
x: quadrantLeft + (drawAxisLabelInMiddle ? quadrantHalfWidth / 2 : 0),
x: quadrantLeft + (drawXAxisLabelsInMiddle ? quadrantHalfWidth / 2 : 0),
y:
xAxisPosition === 'top'
? this.config.xAxisLabelPadding + titleSpace.top
Expand All @@ -299,7 +302,7 @@ export class QuadrantBuilder {
quadrantHeight +
this.config.quadrantPadding,
fontSize: this.config.xAxisLabelFontSize,
verticalPos: drawAxisLabelInMiddle ? 'center' : 'left',
verticalPos: drawXAxisLabelsInMiddle ? 'center' : 'left',
horizontalPos: 'top',
rotation: 0,
});
Expand All @@ -308,7 +311,7 @@ export class QuadrantBuilder {
axisLabels.push({
text: this.data.xAxisRightText,
fill: this.themeConfig.quadrantXAxisTextFill,
x: quadrantLeft + quadrantHalfWidth + (drawAxisLabelInMiddle ? quadrantHalfWidth / 2 : 0),
x: quadrantLeft + quadrantHalfWidth + (drawXAxisLabelsInMiddle ? quadrantHalfWidth / 2 : 0),
y:
xAxisPosition === 'top'
? this.config.xAxisLabelPadding + titleSpace.top
Expand All @@ -317,7 +320,7 @@ export class QuadrantBuilder {
quadrantHeight +
this.config.quadrantPadding,
fontSize: this.config.xAxisLabelFontSize,
verticalPos: drawAxisLabelInMiddle ? 'center' : 'left',
verticalPos: drawXAxisLabelsInMiddle ? 'center' : 'left',
horizontalPos: 'top',
rotation: 0,
});
Expand All @@ -334,9 +337,9 @@ export class QuadrantBuilder {
quadrantLeft +
quadrantWidth +
this.config.quadrantPadding,
y: quadrantTop + quadrantHeight - (drawAxisLabelInMiddle ? quadrantHalfHeight / 2 : 0),
y: quadrantTop + quadrantHeight - (drawYAxisLabelsInMiddle ? quadrantHalfHeight / 2 : 0),
fontSize: this.config.yAxisLabelFontSize,
verticalPos: drawAxisLabelInMiddle ? 'center' : 'left',
verticalPos: drawYAxisLabelsInMiddle ? 'center' : 'left',
horizontalPos: 'top',
rotation: -90,
});
Expand All @@ -352,9 +355,10 @@ export class QuadrantBuilder {
quadrantLeft +
quadrantWidth +
this.config.quadrantPadding,
y: quadrantTop + quadrantHalfHeight - (drawAxisLabelInMiddle ? quadrantHalfHeight / 2 : 0),
y:
quadrantTop + quadrantHalfHeight - (drawYAxisLabelsInMiddle ? quadrantHalfHeight / 2 : 0),
fontSize: this.config.yAxisLabelFontSize,
verticalPos: drawAxisLabelInMiddle ? 'center' : 'left',
verticalPos: drawYAxisLabelsInMiddle ? 'center' : 'left',
horizontalPos: 'top',
rotation: -90,
});
Expand Down
Loading

0 comments on commit ca960c4

Please sign in to comment.