Skip to content
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

Use seriesNameFormatter in overflow legends #1652

Merged
merged 1 commit into from
Apr 3, 2024
Merged
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
6 changes: 5 additions & 1 deletion packages/polaris-viz/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- ## Unreleased -->
## Unreleased

### Fixed

- Fixed issue where `<DonutChart />` overflow legends wouldn't use the `seriesNameFormatter`.

## [12.4.0] - 2024-04-03

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export function LegendValues({
lastVisibleIndex={allData.length - hiddenData.length}
setActivatorWidth={() => null}
dimensions={dimensions}
seriesNameFormatter={seriesNameFormatter}
/>
)}
</React.Fragment>
Expand Down
4 changes: 4 additions & 0 deletions packages/polaris-viz/src/components/Legend/Legend.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Fragment} from 'react';
import type {RefObject} from 'react';
import type {LabelFormatter} from '@shopify/polaris-viz-core';
import {DEFAULT_THEME_NAME} from '@shopify/polaris-viz-core';

import {useExternalHideEvents} from '../../hooks';
Expand All @@ -18,6 +19,7 @@ export interface LegendProps {
indexOffset?: number;
truncate?: boolean;
showLegendValues?: boolean;
seriesNameFormatter?: LabelFormatter;
}

export function Legend({
Expand All @@ -30,6 +32,7 @@ export function Legend({
backgroundColor,
truncate = false,
showLegendValues = false,
seriesNameFormatter,
}: LegendProps) {
const {hiddenIndexes} = useExternalHideEvents();

Expand All @@ -54,6 +57,7 @@ export function Legend({
}}
truncate={truncate}
showLegendValues={showLegendValues}
seriesNameFormatter={seriesNameFormatter}
/>
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {LabelFormatter} from '@shopify/polaris-viz-core';
import {
getColorVisionEventAttrs,
getColorVisionStylesForActiveIndex,
Expand Down Expand Up @@ -35,6 +36,7 @@ export interface LegendItemProps extends LegendData {
backgroundColor?: string;
truncate?: boolean;
showLegendValues?: boolean;
seriesNameFormatter?: LabelFormatter;
}

export function LegendItem({
Expand All @@ -52,6 +54,7 @@ export function LegendItem({
backgroundColor,
truncate = false,
showLegendValues = false,
seriesNameFormatter = (value) => `${value}`,
}: LegendItemProps) {
const selectedTheme = useTheme(theme);
const ref = useRef<HTMLButtonElement | null>(null);
Expand Down Expand Up @@ -118,7 +121,7 @@ export function LegendItem({
color: selectedTheme.legend.labelColor,
}}
>
{name}
{seriesNameFormatter(name)}
</span>
{!showLegendValues || value == null ? null : (
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useChartContext,
useTheme,
} from '@shopify/polaris-viz-core';
import type {BoundingRect} from '@shopify/polaris-viz-core';
import type {BoundingRect, LabelFormatter} from '@shopify/polaris-viz-core';

import type {LegendData} from '../../../types';
import {TOOLTIP_BG_OPACITY} from '../../../constants';
Expand All @@ -34,6 +34,7 @@ interface Props {
theme?: string;
lastVisibleIndex?: number;
dimensions?: BoundingRect;
seriesNameFormatter?: LabelFormatter;
}

export const LEGEND_TOOLTIP_ID = 'legend-toolip';
Expand All @@ -48,6 +49,7 @@ export function HiddenLegendTooltip({
lastVisibleIndex = 0,
setActivatorWidth,
dimensions,
seriesNameFormatter,
}: Props) {
const selectedTheme = useTheme();
const {isFirefox} = useBrowserCheck();
Expand Down Expand Up @@ -168,6 +170,7 @@ export function HiddenLegendTooltip({
theme={theme}
indexOffset={lastVisibleIndex}
backgroundColor="transparent"
seriesNameFormatter={seriesNameFormatter}
/>
</div>,
container,
Expand Down
Loading