-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[charts-pro] Hide values outside minStart and maxEnd in zoom slider #18336
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
Changes from 5 commits
aeb940a
f64c502
e06eee0
a473584
6a8c0a6
a754030
056c4fb
677c11b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,54 @@ | ||
| import { | ||
| AxisId, | ||
| ChartState, | ||
| DefaultedXAxis, | ||
| DefaultedYAxis, | ||
| DefaultizedZoomOptions, | ||
| selectorChartAxisZoomOptionsLookup, | ||
| selectorChartDrawingArea, | ||
| selectorChartRawAxis, | ||
| ZoomData, | ||
| } from '@mui/x-charts/internals'; | ||
| import { ChartDrawingArea } from '@mui/x-charts/hooks'; | ||
|
|
||
| export function calculateZoomFromPoint(state: ChartState<any>, axisId: AxisId, point: DOMPoint) { | ||
| const { left, top, height, width } = selectorChartDrawingArea(state); | ||
| const axis = selectorChartRawAxis(state, axisId); | ||
|
|
||
| if (!axis) { | ||
| return null; | ||
| } | ||
|
|
||
| return calculateZoomFromPointImpl( | ||
| selectorChartDrawingArea(state), | ||
| axis, | ||
| selectorChartAxisZoomOptionsLookup(state, axisId), | ||
| point, | ||
| ); | ||
| } | ||
|
|
||
| export function calculateZoomFromPointImpl( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This separation makes it easier to unit test.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you also consider creating
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think I understood your question. |
||
| drawingArea: ChartDrawingArea, | ||
| axis: Pick<DefaultedXAxis | DefaultedYAxis, 'position' | 'reverse'>, | ||
| zoomOptions: Pick<DefaultizedZoomOptions, 'minStart' | 'maxEnd'>, | ||
| point: Pick<DOMPoint, 'x' | 'y'>, | ||
| ) { | ||
| const { left, top, height, width } = drawingArea; | ||
| const { minStart, maxEnd } = zoomOptions; | ||
|
|
||
| const axisDirection = axis.position === 'right' || axis.position === 'left' ? 'y' : 'x'; | ||
| const range = maxEnd - minStart; | ||
|
|
||
| let pointerZoom: number; | ||
| if (axisDirection === 'x') { | ||
| pointerZoom = ((point.x - left) / width) * 100; | ||
| pointerZoom = ((point.x - left) / width) * range; | ||
| } else { | ||
| pointerZoom = ((top + height - point.y) / height) * 100; | ||
| pointerZoom = ((top + height - point.y) / height) * range; | ||
| } | ||
|
|
||
| if (axis.reverse) { | ||
| pointerZoom = 100 - pointerZoom; | ||
| pointerZoom = maxEnd - pointerZoom; | ||
| } else { | ||
| pointerZoom += minStart; | ||
| } | ||
|
|
||
| return pointerZoom; | ||
|
|
||
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.