-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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] Filter item outside the drawing area for perf #14281
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3109932
[charts] Filter item outside the zoom for performances
alexfauquette 19fcf7c
add tests
alexfauquette f89957c
Use the y-axis label
alexfauquette 91fc922
discard
alexfauquette 85fa15c
fix-searched-text
alexfauquette 0c28f3f
fix value formatter
alexfauquette be25a37
remove failing test
alexfauquette 3fe8d60
Merge remote-tracking branch 'upstream/master' into filter-with-zoom
alexfauquette 33ac420
uncomment
alexfauquette 9b53b87
improve stability and docs
JCQuintas b572b44
try using the exact same test
JCQuintas 80eb078
return to use 70
JCQuintas 758920c
try license inside
JCQuintas b141174
try using globalThis for release info
JCQuintas e0665a8
Revert "try using globalThis for release info"
JCQuintas 88a8f27
decrease amount of points
JCQuintas 0bc5e3d
browser enabled?
JCQuintas 76a4582
Merge commit 'c14c5abd6e27b8edd8f53724d86b4146254e7089' into filter-w…
JCQuintas db09b3d
greatly decrease amount of points
JCQuintas 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
1 change: 1 addition & 0 deletions
1
packages/x-charts-pro/src/ChartContainerPro/ChartContainerPro.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
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ import { BarElement, BarElementSlotProps, BarElementSlots } from './BarElement'; | |
import { AxisDefaultized } from '../models/axis'; | ||
import { BarItemIdentifier } from '../models'; | ||
import getColor from './getColor'; | ||
import { useChartId } from '../hooks'; | ||
import { useChartId, useDrawingArea } from '../hooks'; | ||
import { AnimationData, CompletedBarData, MaskData } from './types'; | ||
import { BarClipPath } from './BarClipPath'; | ||
import { BarLabelItemProps, BarLabelSlotProps, BarLabelSlots } from './BarLabel/BarLabelItem'; | ||
|
@@ -92,6 +92,7 @@ const useAggregatedData = (): { | |
useBarSeries() ?? | ||
({ series: {}, stackingGroups: [], seriesOrder: [] } as SeriesFormatterResult<'bar'>); | ||
const axisData = useCartesianContext(); | ||
const drawingArea = useDrawingArea(); | ||
const chartId = useChartId(); | ||
|
||
const { series, stackingGroups } = seriesData; | ||
|
@@ -102,6 +103,12 @@ const useAggregatedData = (): { | |
const masks: Record<string, MaskData> = {}; | ||
|
||
const data = stackingGroups.flatMap(({ ids: groupIds }, groupIndex) => { | ||
const xMin = drawingArea.left; | ||
const xMax = drawingArea.left + drawingArea.width; | ||
|
||
const yMin = drawingArea.top; | ||
const yMax = drawingArea.top + drawingArea.height; | ||
|
||
return groupIds.flatMap((seriesId) => { | ||
const xAxisId = series[seriesId].xAxisId ?? defaultXAxisId; | ||
const yAxisId = series[seriesId].yAxisId ?? defaultYAxisId; | ||
|
@@ -132,54 +139,69 @@ const useAggregatedData = (): { | |
|
||
const { stackedData } = series[seriesId]; | ||
|
||
return stackedData.map((values, dataIndex: number) => { | ||
const valueCoordinates = values.map((v) => (verticalLayout ? yScale(v)! : xScale(v)!)); | ||
|
||
const minValueCoord = Math.round(Math.min(...valueCoordinates)); | ||
const maxValueCoord = Math.round(Math.max(...valueCoordinates)); | ||
|
||
const stackId = series[seriesId].stack; | ||
|
||
const result = { | ||
seriesId, | ||
dataIndex, | ||
layout: series[seriesId].layout, | ||
x: verticalLayout ? xScale(xAxis[xAxisId].data?.[dataIndex])! + barOffset : minValueCoord, | ||
y: verticalLayout ? minValueCoord : yScale(yAxis[yAxisId].data?.[dataIndex])! + barOffset, | ||
xOrigin: xScale(0)!, | ||
yOrigin: yScale(0)!, | ||
height: verticalLayout ? maxValueCoord - minValueCoord : barWidth, | ||
width: verticalLayout ? barWidth : maxValueCoord - minValueCoord, | ||
color: colorGetter(dataIndex), | ||
value: series[seriesId].data[dataIndex], | ||
maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`, | ||
}; | ||
|
||
if (!masks[result.maskId]) { | ||
masks[result.maskId] = { | ||
id: result.maskId, | ||
width: 0, | ||
height: 0, | ||
hasNegative: false, | ||
hasPositive: false, | ||
layout: result.layout, | ||
return stackedData | ||
.map((values, dataIndex: number) => { | ||
const valueCoordinates = values.map((v) => (verticalLayout ? yScale(v)! : xScale(v)!)); | ||
|
||
const minValueCoord = Math.round(Math.min(...valueCoordinates)); | ||
const maxValueCoord = Math.round(Math.max(...valueCoordinates)); | ||
|
||
const stackId = series[seriesId].stack; | ||
|
||
const result = { | ||
seriesId, | ||
dataIndex, | ||
layout: series[seriesId].layout, | ||
x: verticalLayout | ||
? xScale(xAxis[xAxisId].data?.[dataIndex])! + barOffset | ||
: minValueCoord, | ||
y: verticalLayout | ||
? minValueCoord | ||
: yScale(yAxis[yAxisId].data?.[dataIndex])! + barOffset, | ||
xOrigin: xScale(0)!, | ||
yOrigin: yScale(0)!, | ||
x: 0, | ||
y: 0, | ||
height: verticalLayout ? maxValueCoord - minValueCoord : barWidth, | ||
width: verticalLayout ? barWidth : maxValueCoord - minValueCoord, | ||
color: colorGetter(dataIndex), | ||
value: series[seriesId].data[dataIndex], | ||
maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`, | ||
}; | ||
} | ||
|
||
const mask = masks[result.maskId]; | ||
mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width; | ||
mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height; | ||
mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x); | ||
mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y); | ||
mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0; | ||
mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0; | ||
|
||
return result; | ||
}); | ||
if ( | ||
result.x > xMax || | ||
result.x + result.width < xMin || | ||
result.y > yMax || | ||
result.y + result.height < yMin | ||
) { | ||
return null; | ||
} | ||
Comment on lines
+170
to
+177
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. That, plus the line |
||
|
||
if (!masks[result.maskId]) { | ||
masks[result.maskId] = { | ||
id: result.maskId, | ||
width: 0, | ||
height: 0, | ||
hasNegative: false, | ||
hasPositive: false, | ||
layout: result.layout, | ||
xOrigin: xScale(0)!, | ||
yOrigin: yScale(0)!, | ||
x: 0, | ||
y: 0, | ||
}; | ||
} | ||
|
||
const mask = masks[result.maskId]; | ||
mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width; | ||
mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height; | ||
mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x); | ||
mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y); | ||
mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0; | ||
mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0; | ||
|
||
return result; | ||
}) | ||
.filter((rectangle) => rectangle !== null); | ||
}); | ||
}); | ||
|
||
|
Oops, something went wrong.
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.
Otherwise TS was not understading that pro component have zoom options