mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-22 17:56:43 +02:00
@@ -441,114 +441,114 @@ describe('XY Chart', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render data labels within the bar in the horizontal xy-chart', () => {
|
it('should render data labels within each bar in the horizontal xy-chart', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
---
|
---
|
||||||
config:
|
config:
|
||||||
xyChart:
|
xyChart:
|
||||||
showDataLabel: true
|
showDataLabel: true
|
||||||
chartOrientation: horizontal
|
chartOrientation: horizontal
|
||||||
---
|
---
|
||||||
xychart-beta
|
xychart-beta
|
||||||
title "Sales Revenue"
|
title "Sales Revenue"
|
||||||
x-axis Months [jan,b,c]
|
x-axis Months [jan,b,c]
|
||||||
y-axis "Revenue (in $)" 4000 --> 12000
|
y-axis "Revenue (in $)" 4000 --> 12000
|
||||||
bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000, 3000, 2000, 500, 2000, 3000,11000 ,5000,6000]
|
bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000, 3000, 2000, 500, 2000, 3000, 11000, 5000, 6000]
|
||||||
`,
|
`,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
let textProps, barProps;
|
cy.get('g.bar-plot-0').within(() => {
|
||||||
|
cy.get('rect').each(($rect, index) => {
|
||||||
cy.get('text')
|
// Extract bar properties
|
||||||
.contains('5000')
|
const barProps = {
|
||||||
.then(($el) => {
|
x: parseFloat($rect.attr('x')),
|
||||||
const bbox = $el[0].getBBox();
|
y: parseFloat($rect.attr('y')),
|
||||||
textProps = {
|
width: parseFloat($rect.attr('width')),
|
||||||
x: bbox.x,
|
height: parseFloat($rect.attr('height')),
|
||||||
y: bbox.y,
|
|
||||||
width: bbox.width,
|
|
||||||
height: bbox.height,
|
|
||||||
};
|
};
|
||||||
console.log('textProps', textProps);
|
|
||||||
});
|
|
||||||
|
|
||||||
cy.get('g.bar-plot-0')
|
// Get the text element corresponding to this bar by index.
|
||||||
.find('rect')
|
cy.get('text')
|
||||||
.first()
|
.eq(index)
|
||||||
.then((rect) => {
|
.then(($text) => {
|
||||||
barProps = {
|
const bbox = $text[0].getBBox();
|
||||||
x: parseFloat(rect.attr('x')),
|
const textProps = {
|
||||||
y: parseFloat(rect.attr('y')),
|
x: bbox.x,
|
||||||
width: parseFloat(rect.attr('width')),
|
y: bbox.y,
|
||||||
height: parseFloat(rect.attr('height')),
|
width: bbox.width,
|
||||||
};
|
height: bbox.height,
|
||||||
console.log('barProps', barProps);
|
};
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// Ensure that both textProps and barProps are defined before the assertion
|
|
||||||
expect(textProps.x).to.be.greaterThan(barProps.x);
|
|
||||||
expect(textProps.x + textProps.width).to.be.lessThan(barProps.x + barProps.width);
|
|
||||||
|
|
||||||
expect(textProps.y).to.be.greaterThan(barProps.y);
|
// Verify that the text label is positioned within the boundaries of the bar.
|
||||||
expect(textProps.y + textProps.height).to.be.lessThan(barProps.y + barProps.height);
|
expect(textProps.x).to.be.greaterThan(barProps.x);
|
||||||
expect(textProps.y + textProps.height / 2).to.be.closeTo(
|
expect(textProps.x + textProps.width).to.be.lessThan(barProps.x + barProps.width);
|
||||||
barProps.y + barProps.height / 2,
|
|
||||||
1
|
expect(textProps.y).to.be.greaterThan(barProps.y);
|
||||||
);
|
expect(textProps.y + textProps.height).to.be.lessThan(barProps.y + barProps.height);
|
||||||
|
expect(textProps.y + textProps.height / 2).to.be.closeTo(
|
||||||
|
barProps.y + barProps.height / 2,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render data labels within the bar in the horizontal xy-chart', () => {
|
it('should render data labels within each bar in the vertical xy-chart', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
---
|
---
|
||||||
config:
|
config:
|
||||||
xyChart:
|
xyChart:
|
||||||
showDataLabel: true
|
showDataLabel: true
|
||||||
---
|
---
|
||||||
xychart-beta
|
xychart-beta
|
||||||
title "Sales Revenue"
|
title "Sales Revenue"
|
||||||
x-axis Months [jan,b,c]
|
x-axis Months [jan,b,c]
|
||||||
y-axis "Revenue (in $)" 4000 --> 12000
|
y-axis "Revenue (in $)" 4000 --> 12000
|
||||||
bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000, 3000, 2000, 500, 2000, 3000,11000 ,5000,6000]
|
bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000, 3000, 2000, 500, 2000, 3000, 11000, 5000, 6000]
|
||||||
`,
|
`,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
let textProps, barProps;
|
|
||||||
cy.get('text')
|
|
||||||
.contains('5000')
|
|
||||||
.then(($el) => {
|
|
||||||
const bbox = $el[0].getBBox();
|
|
||||||
textProps = {
|
|
||||||
x: bbox.x,
|
|
||||||
y: bbox.y,
|
|
||||||
width: bbox.width,
|
|
||||||
height: bbox.height,
|
|
||||||
};
|
|
||||||
console.log('textProps', textProps);
|
|
||||||
});
|
|
||||||
cy.get('g.bar-plot-0')
|
|
||||||
.find('rect')
|
|
||||||
.first()
|
|
||||||
.then((rect) => {
|
|
||||||
barProps = {
|
|
||||||
x: parseFloat(rect.attr('x')),
|
|
||||||
y: parseFloat(rect.attr('y')),
|
|
||||||
width: parseFloat(rect.attr('width')),
|
|
||||||
height: parseFloat(rect.attr('height')),
|
|
||||||
};
|
|
||||||
console.log('barProps', barProps);
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// Ensure that both textProps and barProps are defined before the assertion
|
|
||||||
expect(textProps.x).to.be.greaterThan(barProps.x);
|
|
||||||
expect(textProps.x + textProps.width).to.be.lessThan(barProps.x + barProps.width);
|
|
||||||
expect(textProps.x + textProps.width / 2).to.be.closeTo(barProps.x + barProps.width / 2, 1);
|
|
||||||
|
|
||||||
expect(textProps.y).to.be.greaterThan(barProps.y);
|
cy.get('g.bar-plot-0').within(() => {
|
||||||
expect(textProps.y + textProps.height).to.be.lessThan(barProps.y + barProps.height);
|
cy.get('rect').each(($rect, index) => {
|
||||||
|
// Extract bar properties
|
||||||
|
const barProps = {
|
||||||
|
x: parseFloat($rect.attr('x')),
|
||||||
|
y: parseFloat($rect.attr('y')),
|
||||||
|
width: parseFloat($rect.attr('width')),
|
||||||
|
height: parseFloat($rect.attr('height')),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the text element corresponding to this bar by index.
|
||||||
|
cy.get('text')
|
||||||
|
.eq(index)
|
||||||
|
.then(($text) => {
|
||||||
|
const bbox = $text[0].getBBox();
|
||||||
|
const textProps = {
|
||||||
|
x: bbox.x,
|
||||||
|
y: bbox.y,
|
||||||
|
width: bbox.width,
|
||||||
|
height: bbox.height,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Verify that the text label is positioned within the boundaries of the bar.
|
||||||
|
expect(textProps.x).to.be.greaterThan(barProps.x);
|
||||||
|
expect(textProps.x + textProps.width).to.be.lessThan(barProps.x + barProps.width);
|
||||||
|
|
||||||
|
// Check horizontal alignment (within tolerance)
|
||||||
|
expect(textProps.x + textProps.width / 2).to.be.closeTo(
|
||||||
|
barProps.x + barProps.width / 2,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(textProps.y).to.be.greaterThan(barProps.y);
|
||||||
|
expect(textProps.y + textProps.height).to.be.lessThan(barProps.y + barProps.height);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user