-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[charts] Fix tooltip with horizontal layout #14337
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
251 changes: 251 additions & 0 deletions
251
packages/x-charts/src/ChartsTooltip/contentDIsplayed.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
import * as React from 'react'; | ||
import { expect } from 'chai'; | ||
import { createRenderer, fireEvent } from '@mui/internal-test-utils'; | ||
import { BarChart } from '@mui/x-charts/BarChart'; | ||
import { firePointerEvent } from '../tests/firePointerEvent'; | ||
|
||
const config = { | ||
dataset: [ | ||
{ x: 'A', v1: 4, v2: 2 }, | ||
{ x: 'B', v1: 1, v2: 1 }, | ||
], | ||
margin: { top: 0, left: 0, bottom: 0, right: 0 }, | ||
width: 400, | ||
height: 400, | ||
}; | ||
|
||
// Plot as follow to simplify click position | ||
// | ||
// | X | ||
// | X | ||
// | X X | ||
// | X X X X | ||
// ---A---B- | ||
|
||
const isJSDOM = /jsdom/.test(window.navigator.userAgent); | ||
|
||
describe('ChartsTooltip', () => { | ||
const { render } = createRenderer(); | ||
|
||
describe('axis trigger', () => { | ||
it('should show right values with vertical layout', function test() { | ||
if (isJSDOM) { | ||
// can't do Pointer event with JSDom https://github.com/jsdom/jsdom/issues/2527 | ||
this.skip(); | ||
} | ||
|
||
render( | ||
<div | ||
style={{ | ||
margin: -8, // Removes the body default margins | ||
width: 400, | ||
height: 400, | ||
}} | ||
> | ||
<BarChart | ||
{...config} | ||
series={[ | ||
{ dataKey: 'v1', id: 's1', label: 'S1' }, | ||
{ dataKey: 'v2', id: 's2', label: 'S2' }, | ||
]} | ||
xAxis={[{ scaleType: 'band', dataKey: 'x' }]} | ||
/> | ||
</div>, | ||
); | ||
const svg = document.querySelector<HTMLElement>('svg')!; | ||
|
||
firePointerEvent(svg, 'pointermove', { | ||
clientX: 198, | ||
clientY: 60, | ||
}); | ||
|
||
let cells = document.querySelectorAll<HTMLElement>('.MuiChartsTooltip-root td'); | ||
expect([...cells].map((cell) => cell.textContent)).to.deep.equal([ | ||
// Header | ||
'A', | ||
// First row | ||
'', // mark | ||
'S1', // label | ||
'4', // value | ||
// Second row | ||
'', | ||
'S2', | ||
'2', | ||
]); | ||
|
||
firePointerEvent(svg, 'pointermove', { | ||
clientX: 201, | ||
clientY: 60, | ||
}); | ||
|
||
cells = document.querySelectorAll<HTMLElement>('.MuiChartsTooltip-root td'); | ||
expect([...cells].map((cell) => cell.textContent)).to.deep.equal([ | ||
// Header | ||
'B', | ||
// First row | ||
'', | ||
'S1', | ||
'1', | ||
// Second row | ||
'', | ||
'S2', | ||
'1', | ||
]); | ||
}); | ||
|
||
it('should show right values with horizontal layout', function test() { | ||
if (isJSDOM) { | ||
// can't do Pointer event with JSDom https://github.com/jsdom/jsdom/issues/2527 | ||
this.skip(); | ||
} | ||
|
||
render( | ||
<div | ||
style={{ | ||
margin: -8, // Removes the body default margins | ||
width: 400, | ||
height: 400, | ||
}} | ||
> | ||
<BarChart | ||
{...config} | ||
layout="horizontal" | ||
series={[ | ||
{ dataKey: 'v1', id: 's1', label: 'S1' }, | ||
{ dataKey: 'v2', id: 's2', label: 'S2' }, | ||
]} | ||
yAxis={[{ scaleType: 'band', dataKey: 'x' }]} | ||
/> | ||
</div>, | ||
); | ||
const svg = document.querySelector<HTMLElement>('svg')!; | ||
|
||
firePointerEvent(svg, 'pointermove', { | ||
clientX: 150, | ||
clientY: 60, | ||
}); | ||
|
||
let cells = document.querySelectorAll<HTMLElement>('.MuiChartsTooltip-root td'); | ||
expect([...cells].map((cell) => cell.textContent)).to.deep.equal([ | ||
// Header | ||
'A', | ||
// First row | ||
'', | ||
'S1', | ||
'4', | ||
// Second row | ||
'', | ||
'S2', | ||
'2', | ||
]); | ||
|
||
firePointerEvent(svg, 'pointermove', { | ||
clientX: 150, | ||
clientY: 220, | ||
}); | ||
|
||
cells = document.querySelectorAll<HTMLElement>('.MuiChartsTooltip-root td'); | ||
expect([...cells].map((cell) => cell.textContent)).to.deep.equal([ | ||
// Header | ||
'B', | ||
// First row | ||
'', | ||
'S1', | ||
'1', | ||
// Second row | ||
'', | ||
'S2', | ||
'1', | ||
]); | ||
}); | ||
}); | ||
|
||
describe('item trigger', () => { | ||
it('should show right values with vertical layout', function test() { | ||
if (isJSDOM) { | ||
// can't do Pointer event with JSDom https://github.com/jsdom/jsdom/issues/2527 | ||
this.skip(); | ||
} | ||
|
||
render( | ||
<div | ||
style={{ | ||
margin: -8, // Removes the body default margins | ||
width: 400, | ||
height: 400, | ||
}} | ||
> | ||
<BarChart | ||
{...config} | ||
series={[ | ||
{ dataKey: 'v1', id: 's1', label: 'S1' }, | ||
{ dataKey: 'v2', id: 's2', label: 'S2' }, | ||
]} | ||
xAxis={[{ scaleType: 'band', dataKey: 'x' }]} | ||
tooltip={{ trigger: 'item' }} | ||
/> | ||
</div>, | ||
); | ||
const svg = document.querySelector<HTMLElement>('svg')!; | ||
const rectangles = document.querySelectorAll<HTMLElement>('rect'); | ||
|
||
fireEvent.pointerEnter(rectangles[0]); | ||
|
||
firePointerEvent(svg, 'pointermove', { | ||
clientX: 150, | ||
clientY: 60, | ||
}); // Only to set the tooltip position | ||
|
||
let cells = document.querySelectorAll<HTMLElement>('.MuiChartsTooltip-root td'); | ||
expect([...cells].map((cell) => cell.textContent)).to.deep.equal(['', 'S1', '4']); | ||
|
||
fireEvent.pointerEnter(rectangles[3]); | ||
cells = document.querySelectorAll<HTMLElement>('.MuiChartsTooltip-root td'); | ||
expect([...cells].map((cell) => cell.textContent)).to.deep.equal(['', 'S2', '1']); | ||
}); | ||
|
||
it('should show right values with horizontal layout', function test() { | ||
if (isJSDOM) { | ||
// can't do Pointer event with JSDom https://github.com/jsdom/jsdom/issues/2527 | ||
this.skip(); | ||
} | ||
|
||
render( | ||
<div | ||
style={{ | ||
margin: -8, // Removes the body default margins | ||
width: 400, | ||
height: 400, | ||
}} | ||
> | ||
<BarChart | ||
{...config} | ||
series={[ | ||
{ dataKey: 'v1', id: 's1', label: 'S1' }, | ||
{ dataKey: 'v2', id: 's2', label: 'S2' }, | ||
]} | ||
layout="horizontal" | ||
yAxis={[{ scaleType: 'band', dataKey: 'x' }]} | ||
tooltip={{ trigger: 'item' }} | ||
/> | ||
</div>, | ||
); | ||
const svg = document.querySelector<HTMLElement>('svg')!; | ||
const rectangles = document.querySelectorAll<HTMLElement>('rect'); | ||
|
||
fireEvent.pointerEnter(rectangles[0]); | ||
|
||
firePointerEvent(svg, 'pointermove', { | ||
clientX: 150, | ||
clientY: 60, | ||
}); // Only to set the tooltip position | ||
|
||
let cells = document.querySelectorAll<HTMLElement>('.MuiChartsTooltip-root td'); | ||
expect([...cells].map((cell) => cell.textContent)).to.deep.equal(['', 'S1', '4']); | ||
|
||
fireEvent.pointerEnter(rectangles[3]); | ||
cells = document.querySelectorAll<HTMLElement>('.MuiChartsTooltip-root td'); | ||
expect([...cells].map((cell) => cell.textContent)).to.deep.equal(['', 'S2', '1']); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file name has weird capitalisation 😅