-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[charts-pro] Add a borderRadius
property to FunnelChart
#17660
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7c21f66
initial work
JCQuintas 1684bf1
logic
JCQuintas 9db8c25
rename
JCQuintas df94cbb
improve docs
JCQuintas 81e03b7
changes yolo
JCQuintas 032abd7
doesnt work
JCQuintas 678c2a5
Revert "doesnt work"
JCQuintas c9bc9a9
Revert "changes yolo"
JCQuintas aea349b
simplify
JCQuintas abfe1e0
docs and scripts
JCQuintas 29203eb
Merge branch 'master' into funnel-border-radius
JCQuintas bb32b28
close the bump path
JCQuintas 5e824f0
Move border radius to series
JCQuintas fb25b9c
scripts
JCQuintas cc85c34
Merge branch 'master' into funnel-border-radius
JCQuintas d849488
Update docs/data/charts/funnel/funnel.md
JCQuintas a0c7527
docs suggestions
JCQuintas 80dfa12
scripts
JCQuintas 51d7c27
Merge branch 'master' into funnel-border-radius
JCQuintas 91d126c
linear curve alignment
JCQuintas fe4ffb2
invert second slope
JCQuintas 485a6e6
Merge branch 'master' into funnel-border-radius
JCQuintas 35fd033
default to 8 px border radius
JCQuintas bfab8a6
suggestions
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
This file contains hidden or 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,29 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import { Unstable_FunnelChart as FunnelChart } from '@mui/x-charts-pro/FunnelChart'; | ||
|
||
export default function FunnelBorderRadius() { | ||
return ( | ||
<Box sx={{ width: '100%', maxWidth: 400 }}> | ||
<FunnelChart | ||
series={[ | ||
{ | ||
data: [{ value: 200 }, { value: 180 }, { value: 90 }, { value: 50 }], | ||
borderRadius: 10, | ||
}, | ||
]} | ||
height={300} | ||
/> | ||
<FunnelChart | ||
series={[ | ||
{ | ||
data: [{ value: 200 }, { value: 180 }, { value: 90 }, { value: 50 }], | ||
borderRadius: 10, | ||
}, | ||
]} | ||
height={300} | ||
gap={10} | ||
/> | ||
</Box> | ||
); | ||
} |
This file contains hidden or 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,29 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import { Unstable_FunnelChart as FunnelChart } from '@mui/x-charts-pro/FunnelChart'; | ||
|
||
export default function FunnelBorderRadius() { | ||
return ( | ||
<Box sx={{ width: '100%', maxWidth: 400 }}> | ||
<FunnelChart | ||
series={[ | ||
{ | ||
data: [{ value: 200 }, { value: 180 }, { value: 90 }, { value: 50 }], | ||
borderRadius: 10, | ||
}, | ||
]} | ||
height={300} | ||
/> | ||
<FunnelChart | ||
series={[ | ||
{ | ||
data: [{ value: 200 }, { value: 180 }, { value: 90 }, { value: 50 }], | ||
borderRadius: 10, | ||
}, | ||
]} | ||
height={300} | ||
gap={10} | ||
/> | ||
</Box> | ||
); | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
49 changes: 49 additions & 0 deletions
49
packages/x-charts-pro/src/FunnelChart/curves/borderRadiusPolygon.ts
This file contains hidden or 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,49 @@ | ||
import { Point } from './curve.types'; | ||
|
||
const distance = (p1: Point, p2: Point) => Math.sqrt((p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2); | ||
const lerp = (a: number, b: number, x: number) => a + (b - a) * x; | ||
const lerp2D = (p1: Point, p2: Point, t: number) => ({ | ||
x: lerp(p1.x, p2.x, t), | ||
y: lerp(p1.y, p2.y, t), | ||
}); | ||
|
||
/** | ||
* Draws a polygon with rounded corners | ||
* @param {CanvasRenderingContext2D} ctx The canvas context | ||
* @param {Array} points A list of `{x, y}` points | ||
* @radius {number} how much to round the corners | ||
JCQuintas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
export function borderRadiusPolygon( | ||
ctx: CanvasRenderingContext2D, | ||
points: Point[], | ||
radius: number | number[], | ||
): void { | ||
const numPoints = points.length; | ||
|
||
radius = Array.isArray(radius) ? radius : Array(numPoints).fill(radius); | ||
|
||
const corners: Point[][] = []; | ||
for (let i = 0; i < numPoints; i += 1) { | ||
const lastPoint = points[i]; | ||
const thisPoint = points[(i + 1) % numPoints]; | ||
const nextPoint = points[(i + 2) % numPoints]; | ||
|
||
const lastEdgeLength = distance(lastPoint, thisPoint); | ||
const lastOffsetDistance = Math.min(lastEdgeLength / 2, radius[i] ?? 0); | ||
const start = lerp2D(thisPoint, lastPoint, lastOffsetDistance / lastEdgeLength); | ||
|
||
const nextEdgeLength = distance(nextPoint, thisPoint); | ||
const nextOffsetDistance = Math.min(nextEdgeLength / 2, radius[i] ?? 0); | ||
const end = lerp2D(thisPoint, nextPoint, nextOffsetDistance / nextEdgeLength); | ||
|
||
corners.push([start, thisPoint, end]); | ||
} | ||
|
||
ctx.moveTo(corners[0][0].x, corners[0][0].y); | ||
for (const [start, ctrl, end] of corners) { | ||
ctx.lineTo(start.x, start.y); | ||
ctx.quadraticCurveTo(ctrl.x, ctrl.y, end.x, end.y); | ||
} | ||
|
||
ctx.closePath(); | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.