Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions projects/js-packages/charts/BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Breaking Changes - PieSemiCircleChart

## Summary

The `label` and `note` props have been removed from `PieSemiCircleChart` in favor of the more flexible composition API using the `children` prop.

## Migration Guide

### Before (Deprecated)
```tsx
<PieSemiCircleChart
data={data}
width={400}
label="Operating Systems"
note="Windows +10%"
/>
```

### After (New API)

**Option 1: Direct Group usage**
```tsx
import { Group } from '@visx/group';
import { Text } from '@visx/text';

<PieSemiCircleChart
data={data}
width={400}
>
<Group>
<Text textAnchor="middle" y={-40} fontSize={16} fontWeight={600}>
Operating Systems
</Text>
<Text textAnchor="middle" y={-20} fontSize={14}>
Windows +10%
</Text>
</Group>
</PieSemiCircleChart>
```

**Option 2: Compound components (more explicit)**
```tsx
import { Group } from '@visx/group';
import { Text } from '@visx/text';

<PieSemiCircleChart
data={data}
width={400}
>
<PieSemiCircleChart.SVG>
<Group>
<Text textAnchor="middle" y={-40} fontSize={16} fontWeight={600}>
Operating Systems
</Text>
<Text textAnchor="middle" y={-20} fontSize={14}>
Windows +10%
</Text>
</Group>
</PieSemiCircleChart.SVG>
</PieSemiCircleChart>
```

## Affected Consumer Files

### WooCommerce Analytics

The following files in the WooCommerce Analytics repository need to be updated:

1. **`/js/src/widgets/payments-by-method/payments-by-method.tsx`** (Lines 41-43)
- Uses: `label="$122K"` and `note="+3%"`
- Action: Convert to composition API

2. **`/js/src/widgets/taxes-by-code/index.tsx`** (Lines 45-47)
- Uses: `label={label}` and `note={info}`
- Action: Convert to composition API

3. **`/js/src/widgets/coupons-widget/coupons-widget.tsx`** (Line 82)
- Uses: `label=""`
- Action: Remove empty label prop

4. **`/next-woocommerce-analytics/packages/widgets/src/shared/semi-circle-chart/semi-circle-chart.tsx`** (Line 93)
- Uses: `label=""`
- Action: Remove empty label prop

### Jetpack Stats

No breaking changes found - PieSemiCircleChart is not currently used in Jetpack Stats.

## Notes

- The `label=""` empty string usage can simply be removed without replacement
- For actual label/note values, use the composition API examples above
- Import `Group` from `@visx/group` and `Text` from `@visx/text` when using the composition API
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Charts: improve pie semi circle chart composition
Comment on lines +1 to +4
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

Removing the label and note props is a breaking API change. Please mark this as a breaking change in the changelog (e.g., Significance: major and/or Type: breaking-change) and include a brief migration note showing how to render labels via children (Group/Text or PieSemiCircleChart.SVG).

Suggested change
Significance: minor
Type: changed
Charts: improve pie semi circle chart composition
Significance: major
Type: breaking-change
Charts: improve pie semi circle chart composition
Breaking change: The `label` and `note` props have been removed from PieSemiCircleChart. To render labels, use children components such as `<Group><Text /></Group>` or render SVG elements directly via `PieSemiCircleChart.SVG`.
Migration note:
Before:
<PieSemiCircleChart label="My Label" note="Some note" ... />
After:
<PieSemiCircleChart ...>
<Group>
<Text>My Label</Text>
<Text>Some note</Text>
</Group>
</PieSemiCircleChart>
// Or use PieSemiCircleChart.SVG for custom SVG rendering.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think the semi-circle chart label and note props are currently being used by any consumers, so I don't think it needs to be a significant/major change in the changelog. I'm open to having my mind changed on this, but at this time I don't think this feedback is necessary.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { localPoint } from '@visx/event';
import { Group } from '@visx/group';
import { Pie } from '@visx/shape';
import { Text } from '@visx/text';
import { useTooltip, useTooltipInPortal } from '@visx/tooltip';
import clsx from 'clsx';
import { useCallback, useContext, useMemo } from 'react';
Expand Down Expand Up @@ -46,18 +45,42 @@ export interface PieSemiCircleChartProps extends BaseChartProps< DataPointPercen
*/
clockwise?: boolean;

/**
* Label text to display above the chart
*/
label?: string;

/**
* Note text to display below the label
*/
note?: string;

/**
* Use the children prop to render additional elements on the chart.
* Supports composition API with PieSemiCircleChart.SVG and PieSemiCircleChart.HTML components.
*
* @example
* // Render title and note using Group and Text (direct approach)
* <PieSemiCircleChart data={data}>
* <Group>
* <Text textAnchor="middle" y={-40} fontSize={16} fontWeight={600}>
* Chart Title
* </Text>
* <Text textAnchor="middle" y={-20} fontSize={14}>
* Subtitle or note
* </Text>
* </Group>
* </PieSemiCircleChart>
*
* @example
* // Using compound components for more explicit control
* <PieSemiCircleChart data={data}>
* <PieSemiCircleChart.SVG>
* <Group>
* <Text textAnchor="middle" y={-40} fontSize={16} fontWeight={600}>
* Chart Title
* </Text>
* <Text textAnchor="middle" y={-20} fontSize={14}>
* Subtitle or note
* </Text>
* </Group>
* </PieSemiCircleChart.SVG>
* <PieSemiCircleChart.HTML>
* <div style={{ textAlign: 'center', marginTop: '1rem' }}>
* Additional HTML content below the chart
* </div>
* </PieSemiCircleChart.HTML>
* </PieSemiCircleChart>
*/
children?: ReactNode;

Expand Down Expand Up @@ -133,8 +156,6 @@ const PieSemiCircleChartInternal: FC< PieSemiCircleChartProps > = ( {
legendItemClassName,
legendShape = 'circle',
legendValueDisplay = 'percentage',
label,
note,
className,
children,
tooltipOffsetX = 0,
Expand Down Expand Up @@ -316,26 +337,6 @@ const PieSemiCircleChartInternal: FC< PieSemiCircleChartProps > = ( {
} }
</Pie>

{ /* Label and note text */ }
<Group>
<Text
textAnchor="middle"
verticalAnchor="start"
y={ -40 } // Position above the chart with space for note
className={ styles.label }
>
{ label }
</Text>
<Text
textAnchor="middle"
verticalAnchor="start"
y={ -20 } // Position between label and chart
className={ styles.note }
>
{ note }
</Text>
</Group>

{ /* Render SVG children from composition API */ }
{ svgChildren }
</Group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,67 @@ Main component for rendering semi-circular pie charts.
| `width` | `number` | `400` | Width of the chart in pixels (height is automatically half of width) |
| `thickness` | `number` | `0.4` | Thickness of the pie segments (0-1, where 1 is full thickness) |
| `clockwise` | `boolean` | `true` | Direction of segment rendering |
| `label` | `string` | - | Text displayed above the chart |
| `note` | `string` | - | Additional text displayed below the label |
| `children` | `ReactNode` | - | Custom content to render. Supports Group elements or PieSemiCircleChart.SVG/HTML compound components |
| `withTooltips` | `boolean` | `false` | Enable interactive tooltips on hover |
| `showLegend` | `boolean` | `false` | Display legend below the chart |
| `legendOrientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | Legend layout direction |
| `legendAlignment` | `'start' \| 'center' \| 'end'` | `'center'` | Legend alignment within its position |
| `legendPosition` | `'top' \| 'bottom'` | `'bottom'` | Legend position (where the legend appears) |
| `legendShape` | `'circle' \| 'rect' \| 'line'` | `'circle'` | Shape of legend indicators |
| `legendValueDisplay` | `'percentage' \| 'value' \| 'valueDisplay' \| 'none'` | `'percentage'` | Type of value to display in legend |
| `legendMaxWidth` | `number` | - | Maximum width for legend items |
| `legendTextOverflow` | `'wrap' \| 'truncate'` | `'wrap'` | How to handle long legend text |
| `legendItemClassName` | `string` | - | Custom CSS class for legend items |
| `className` | `string` | - | Additional CSS class for the container |
| `chartId` | `string` | - | Optional unique identifier (auto-generated if not provided) |
| `tooltipOffsetX` | `number` | `0` | Horizontal offset for tooltip positioning in pixels |
| `tooltipOffsetY` | `number` | `-15` | Vertical offset for tooltip positioning in pixels |

## Compound Components

### PieSemiCircleChart.SVG

Wrapper for SVG elements to be rendered inside the chart (positioned within the semi-circle).

**Usage:**
```jsx
<PieSemiCircleChart data={data}>
<PieSemiCircleChart.SVG>
<Group>
<Text textAnchor="middle" y={-40}>Title</Text>
</Group>
</PieSemiCircleChart.SVG>
</PieSemiCircleChart>
```

### PieSemiCircleChart.HTML

Wrapper for HTML elements to be rendered outside the SVG (below the chart).

**Usage:**
```jsx
<PieSemiCircleChart data={data}>
<PieSemiCircleChart.HTML>
<div>Additional HTML content</div>
</PieSemiCircleChart.HTML>
</PieSemiCircleChart>
```

### PieSemiCircleChart.Legend

Legend component for flexible placement within the composition API.

**Props:**
- All legend-related props from the main component (orientation, alignment, position, shape, etc.)

**Usage:**
```jsx
<PieSemiCircleChart data={data}>
<PieSemiCircleChart.HTML>
<PieSemiCircleChart.Legend orientation="horizontal" />
</PieSemiCircleChart.HTML>
</PieSemiCircleChart>
```

## DataPointPercentage Type

Expand Down
Loading