-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[charts] Add radar labels #16839
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
[charts] Add radar labels #16839
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e9cec83
Fix dark mode
alexfauquette 2c7b3bd
generalize text placement
alexfauquette 76b3259
plot labels
alexfauquette 64e82a3
scripts
alexfauquette c064310
Merge remote-tracking branch 'upstream/master' into radar-darkmode
alexfauquette ffb1c94
add labelGap
alexfauquette 590049e
standardize the deg2rad and rad2deg
alexfauquette 6c89f34
fix
alexfauquette 6a5ca62
fix
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 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
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,23 @@ | ||
import * as React from 'react'; | ||
import ApiPage from 'docs/src/modules/components/ApiPage'; | ||
import mapApiPageTranslations from 'docs/src/modules/utils/mapApiPageTranslations'; | ||
import jsonPageContent from './radar-metric-labels.json'; | ||
|
||
export default function Page(props) { | ||
const { descriptions, pageContent } = props; | ||
return <ApiPage descriptions={descriptions} pageContent={pageContent} />; | ||
} | ||
|
||
Page.getInitialProps = () => { | ||
const req = require.context( | ||
'docsx/translations/api-docs/charts/radar-metric-labels', | ||
false, | ||
/\.\/radar-metric-labels.*.json$/, | ||
); | ||
const descriptions = mapApiPageTranslations(req); | ||
|
||
return { | ||
descriptions, | ||
pageContent: jsonPageContent, | ||
}; | ||
}; |
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,15 @@ | ||
{ | ||
"props": { "divisions": { "type": { "name": "number" }, "default": "5" } }, | ||
"name": "RadarMetricLabels", | ||
"imports": [ | ||
"import { RadarMetricLabels } from '@mui/x-charts/RadarChart';", | ||
"import { RadarMetricLabels } from '@mui/x-charts';", | ||
"import { RadarMetricLabels } from '@mui/x-charts-pro';" | ||
], | ||
"classes": [], | ||
"muiName": "MuiRadarMetricLabels", | ||
"filename": "/packages/x-charts/src/RadarChart/RadarMetricLabels/RadarMetricLabels.tsx", | ||
"inheritance": null, | ||
"demos": "<ul><li><a href=\"/x/react-charts/radar/\">Charts - Radar 🚧</a></li></ul>", | ||
"cssComponent": false | ||
} |
7 changes: 7 additions & 0 deletions
7
docs/translations/api-docs/charts/radar-metric-labels/radar-metric-labels.json
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,7 @@ | ||
{ | ||
"componentDescription": "", | ||
"propDescriptions": { | ||
"divisions": { "description": "The number of divisions in the radar grid." } | ||
}, | ||
"classDescriptions": {} | ||
} |
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,44 @@ | ||
import { clampAngle } from '../internals/clampAngle'; | ||
import { ChartsTextStyle } from '../internals/getWordsByLines'; | ||
|
||
/** | ||
* Provide the text-anchor based on the angle between the text and the associated element. | ||
* - 0 means the element is on top of the text, 180 bellow, and 90 on the right of the text. | ||
* @param {number} angle The angle between the text and the element. | ||
* @returns | ||
*/ | ||
export function getDefaultTextAnchor(angle: number): ChartsTextStyle['textAnchor'] { | ||
const adjustedAngle = clampAngle(angle); | ||
|
||
if (adjustedAngle <= 30 || adjustedAngle >= 330) { | ||
// +/-30° around 0° | ||
return 'middle'; | ||
} | ||
|
||
if (adjustedAngle <= 210 && adjustedAngle >= 150) { | ||
// +/-30° around 180° | ||
return 'middle'; | ||
} | ||
|
||
if (adjustedAngle <= 180) { | ||
return 'end'; | ||
} | ||
|
||
return 'start'; | ||
} | ||
|
||
export function getDefaultBaseline(angle: number): ChartsTextStyle['dominantBaseline'] { | ||
const adjustedAngle = clampAngle(angle); | ||
|
||
if (adjustedAngle <= 30 || adjustedAngle >= 330) { | ||
// +/-60° around 0° | ||
return 'hanging'; | ||
} | ||
|
||
if (adjustedAngle <= 210 && adjustedAngle >= 150) { | ||
// +/-60° around 180° | ||
return 'auto'; | ||
} | ||
|
||
return 'central'; | ||
} |
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,6 +15,8 @@ export interface MetricConfig { | |||||
max?: number; | ||||||
} | ||||||
|
||||||
export type RadarLabelFormatterContext = { location: 'tick' | 'tooltip' }; | ||||||
|
||||||
export interface RadarConfig { | ||||||
/** | ||||||
* The metrics shown by radar. | ||||||
|
@@ -30,4 +32,11 @@ export interface RadarConfig { | |||||
* @default 0 | ||||||
*/ | ||||||
startAngle?: number; | ||||||
/** | ||||||
* Format metric names according to their placement. | ||||||
* @param {string} name The matric name. | ||||||
* @param {RadarLabelFormatterContext} context Indicate where the label will be used. | ||||||
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.
Suggested change
|
||||||
* @returns {string} The label to display. | ||||||
*/ | ||||||
labelFormatter?: (name: string, context: RadarLabelFormatterContext) => string; | ||||||
} |
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.
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.