Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 25, 2025

Adds comprehensive documentation for the useLegend hook and the @mui/x-charts/hooks package that was missing from the charts documentation.

What's New

Complete Hooks Package Documentation

  • hooks.md: Overview of all available hooks organized by category (Series, Legend, Layout/positioning)
  • use-legend.md: Dedicated useLegend hook documentation with full API reference
  • use-series.md: Documentation for series-related hooks (useSeries, useBarSeries, useLineSeries, etc.)
  • use-drawing-area.md: Documentation for useDrawingArea hook for layout and positioning
  • use-scale.md: Documentation for scale hooks (useXScale, useYScale) for coordinate transformations

Interactive Demo Components

Created working examples for all documented hooks:

  • UseLegend.tsx - Custom legend implementation
  • UseSeries.tsx - Series data access
  • UseDrawingArea.tsx - Chart layout utilities
  • UseScale.tsx - Coordinate transformation
  • UseBarSeries.tsx - Bar chart specific data

The documentation includes context requirements, usage patterns, and practical examples for building custom chart components.

Fixes #18238.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@mui-bot
Copy link

mui-bot commented Aug 25, 2025

Deploy preview: https://deploy-preview-19334--material-ui-x.netlify.app/

Updated pages:

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against e327878

@Copilot Copilot AI changed the title [WIP] [charts] Document useLegend [charts] Document useLegend hook and @mui/x-charts/hooks package Aug 25, 2025
Copilot finished work on behalf of JCQuintas August 25, 2025 15:38
@Copilot Copilot AI requested a review from JCQuintas August 25, 2025 15:38
@JCQuintas JCQuintas requested a review from Copilot August 26, 2025 19:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive documentation for the useLegend hook and introduces a complete hooks documentation section for the @mui/x-charts/hooks package. The documentation was previously missing, addressing user feedback about the lack of documentation for the useLegend hook and the hooks package.

  • Creates a dedicated hooks documentation section with overview and individual hook pages
  • Documents the useLegend hook with API reference, usage examples, and TypeScript support
  • Adds documentation for other key hooks including useSeries, useDrawingArea, and useScale

Reviewed Changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
docs/data/pages.ts Adds hooks navigation structure to the charts documentation
docs/pages/x/react-charts/hooks/*.js Creates documentation pages for individual hooks
docs/data/charts/hooks/*.md Comprehensive documentation content for hooks with usage examples
docs/data/charts/hooks/*.js/.tsx Interactive demos showing practical hook usage
packages/x-charts/src/hooks/useDrawingArea.ts Adds JSDoc comments to ChartDrawingArea type properties
packages/x-charts/src/hooks/useAxis.ts Adds TypeScript generics to useXAxis and useYAxis functions
Comments suppressed due to low confidence (1)

docs/data/charts/hooks/UseScale.js:37

  • The CSS color() function with the from keyword is not widely supported in browsers. Consider using a more compatible approach like rgba() or a hex color with opacity.
              fill="red"

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@JCQuintas
Copy link
Member

@copilot update the pr description

Copy link
Contributor Author

Copilot AI commented Aug 26, 2025

@copilot update the pr description

Updated the PR description to accurately reflect the current state of changes. Also restored the missing LegendItemParams export in aab4e3e.

Copilot finished work on behalf of JCQuintas August 26, 2025 20:21
@Copilot Copilot AI requested a review from JCQuintas August 26, 2025 20:21
Copy link
Member

@alexfauquette alexfauquette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other all structure looks good. I would prefer to move it at the end of the navigation menu

image

Some table could be replaced by custom component filled by docs:api script. But the infra is not yet available so this can be a good way to move forward

Comment on lines +27 to +34
| Property | Type | Description |
| :------- | :------- | :----------------------------------------------------------------- |
| `left` | `number` | The gap between the left border of the SVG and the drawing area. |
| `right` | `number` | The gap between the right border of the SVG and the drawing area. |
| `top` | `number` | The gap between the top border of the SVG and the drawing area. |
| `bottom` | `number` | The gap between the bottom border of the SVG and the drawing area. |
| `width` | `number` | The width of the drawing area. |
| `height` | `number` | The height of the drawing area. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think a table is the more appropriate structure. Maybe a bullet point, and a sentence to say they are all number

Copy link
Member

@alexfauquette alexfauquette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good starting point for more documentation.

Just added small improvement suggestions


<p class="description">Access raw series data for all chart types.</p>

The `useXxxSeries` hook provides access to specific series data for a particular chart type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we always use useSeries to be consistent? Otherwise sometimes we use useSeries and some other times we use useXxxSeries

Suggested change
The `useXxxSeries` hook provides access to specific series data for a particular chart type.
The `useSeries` hook provides access to specific series data for a particular chart type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it is meant to be all the specific hooks.

useBarSeries
useLineSeries
useScatterSeries
usePieSeries
useRadarSeries
useHeatmapSeries
useFunnelSeries

when I use it alone, it means the exact useSeries which is also a hook. I needed to differentiate them, though I'm open to suggestion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions: useXSeries, use*Series, use[ChartType]Series, "series hooks"

export function useYAxis(axisId?: AxisId) {
export function useYAxis<T extends keyof AxisScaleConfig>(
axisId?: AxisId,
): ComputedAxis<T, any, ChartsYAxisProps> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't it also return undefined?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, but it would only happen if the provided id doesn't exist.

Not sure how to fix this though, since the previous type didn't correctly account for undefined, so adding undefined would be a breaking change.

@JCQuintas JCQuintas enabled auto-merge (squash) September 17, 2025 16:35
@JCQuintas JCQuintas merged commit 344d4bf into master Sep 17, 2025
23 checks passed
@JCQuintas JCQuintas deleted the copilot/fix-18238 branch September 17, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: charts Changes related to the charts. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[charts] Document useLegend

6 participants