-
-
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] Replace path
with circle
for perf improvement
#14518
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
000ff4e
[charts] Replace `path` by `circle` for perf improvement
alexfauquette b2dac66
test impact on benchmark
alexfauquette 08d0945
fix TS
alexfauquette aee551a
scripts
alexfauquette 6e36564
prettier
alexfauquette b0f0c4c
wording
alexfauquette 57340c9
renaming
alexfauquette 2df8e30
docs:api
alexfauquette 7f101dd
Merge remote-tracking branch 'upstream/master' into line-perf
alexfauquette 35899aa
fix import
alexfauquette 344aa44
rsc:build
alexfauquette 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
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
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
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
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,120 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useTheme } from '@mui/material/styles'; | ||
import { animated, useSpring } from '@react-spring/web'; | ||
import { InteractionContext } from '../context/InteractionProvider'; | ||
import { useInteractionItemProps } from '../hooks/useInteractionItemProps'; | ||
import { useItemHighlighted } from '../context'; | ||
import { MarkElementOwnerState, useUtilityClasses } from './markElementClasses'; | ||
import { warnOnce } from '../internals/warning'; | ||
|
||
export type CircleMarkElementProps = Omit<MarkElementOwnerState, 'isFaded' | 'isHighlighted'> & | ||
Omit<React.SVGProps<SVGPathElement>, 'ref' | 'id'> & { | ||
/** | ||
* The shape of the marker. | ||
*/ | ||
shape: 'circle' | 'cross' | 'diamond' | 'square' | 'star' | 'triangle' | 'wye'; | ||
/** | ||
* If `true`, animations are skipped. | ||
* @default false | ||
*/ | ||
skipAnimation?: boolean; | ||
/** | ||
* The index to the element in the series' data array. | ||
*/ | ||
dataIndex: number; | ||
}; | ||
|
||
/** | ||
* The line mark element that only render circle for performance improvement. | ||
* | ||
* Demos: | ||
* | ||
* - [Lines](https://mui.com/x/react-charts/lines/) | ||
* - [Line demonstration](https://mui.com/x/react-charts/line-demo/) | ||
* | ||
* API: | ||
* | ||
* - [CircleMarkElement API](https://mui.com/x/api/charts/circle-mark-element/) | ||
*/ | ||
function CircleMarkElement(props: CircleMarkElementProps) { | ||
const { | ||
x, | ||
y, | ||
id, | ||
classes: innerClasses, | ||
color, | ||
dataIndex, | ||
onClick, | ||
skipAnimation, | ||
shape, | ||
...other | ||
} = props; | ||
|
||
if (shape !== 'circle') { | ||
warnOnce( | ||
[ | ||
`MUI X: The mark element of your line chart have shape "${shape}" which is not supported when using \`perfUpdate=true\`.`, | ||
'Only "circle" are supported with `perfUpdate`.', | ||
].join('\n'), | ||
'error', | ||
); | ||
} | ||
const theme = useTheme(); | ||
const getInteractionItemProps = useInteractionItemProps(); | ||
const { isFaded, isHighlighted } = useItemHighlighted({ | ||
seriesId: id, | ||
}); | ||
const { axis } = React.useContext(InteractionContext); | ||
|
||
const position = useSpring({ to: { x, y }, immediate: skipAnimation }); | ||
const ownerState = { | ||
id, | ||
classes: innerClasses, | ||
isHighlighted: axis.x?.index === dataIndex || isHighlighted, | ||
isFaded, | ||
color, | ||
}; | ||
const classes = useUtilityClasses(ownerState); | ||
|
||
return ( | ||
<animated.circle | ||
{...other} | ||
cx={position.x} | ||
cy={position.y} | ||
r={5} | ||
fill={(theme.vars || theme).palette.background.paper} | ||
stroke={color} | ||
strokeWidth={2} | ||
className={classes.root} | ||
onClick={onClick} | ||
cursor={onClick ? 'pointer' : 'unset'} | ||
{...getInteractionItemProps({ type: 'line', seriesId: id, dataIndex })} | ||
/> | ||
); | ||
} | ||
|
||
CircleMarkElement.propTypes = { | ||
// ----------------------------- Warning -------------------------------- | ||
// | These PropTypes are generated from the TypeScript type definitions | | ||
// | To update them edit the TypeScript types and run "pnpm proptypes" | | ||
// ---------------------------------------------------------------------- | ||
classes: PropTypes.object, | ||
/** | ||
* The index to the element in the series' data array. | ||
*/ | ||
dataIndex: PropTypes.number.isRequired, | ||
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, | ||
/** | ||
* The shape of the marker. | ||
*/ | ||
shape: PropTypes.oneOf(['circle', 'cross', 'diamond', 'square', 'star', 'triangle', 'wye']) | ||
.isRequired, | ||
/** | ||
* If `true`, animations are skipped. | ||
* @default false | ||
*/ | ||
skipAnimation: PropTypes.bool, | ||
} as any; | ||
|
||
export { CircleMarkElement }; |
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
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
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,42 @@ | ||
import composeClasses from '@mui/utils/composeClasses'; | ||
import generateUtilityClass from '@mui/utils/generateUtilityClass'; | ||
import generateUtilityClasses from '@mui/utils/generateUtilityClasses'; | ||
import { SeriesId } from '../models/seriesType/common'; | ||
|
||
export interface MarkElementClasses { | ||
/** Styles applied to the root element. */ | ||
root: string; | ||
/** Styles applied to the root element when highlighted. */ | ||
highlighted: string; | ||
/** Styles applied to the root element when faded. */ | ||
faded: string; | ||
} | ||
|
||
export type MarkElementClassKey = keyof MarkElementClasses; | ||
|
||
export interface MarkElementOwnerState { | ||
id: SeriesId; | ||
color: string; | ||
isFaded: boolean; | ||
isHighlighted: boolean; | ||
classes?: Partial<MarkElementClasses>; | ||
} | ||
|
||
export function getMarkElementUtilityClass(slot: string) { | ||
return generateUtilityClass('MuiMarkElement', slot); | ||
} | ||
|
||
export const markElementClasses: MarkElementClasses = generateUtilityClasses('MuiMarkElement', [ | ||
'root', | ||
'highlighted', | ||
'faded', | ||
]); | ||
|
||
export const useUtilityClasses = (ownerState: MarkElementOwnerState) => { | ||
const { classes, id, isFaded, isHighlighted } = ownerState; | ||
const slots = { | ||
root: ['root', `series-${id}`, isHighlighted && 'highlighted', isFaded && 'faded'], | ||
}; | ||
|
||
return composeClasses(slots, getMarkElementUtilityClass, classes); | ||
}; |
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
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ describe('LineChart', () => { | |
]} | ||
width={500} | ||
height={300} | ||
markPerfUpdate | ||
/>, | ||
); | ||
|
||
|
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.
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.
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.
markPerfUpdate
sounds vague, "update" is a status, so it doesn't fully describe the action I think.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.
What about
experimentalMarkRendering
To say it's planned to be the future default behavior in v8?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.
Yeah, I think that would be great