Skip to content

Commit

Permalink
feat(pie): properly handle possible presence of label on raw datum
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Nov 5, 2020
1 parent f71cd5b commit 840a6cb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/pie/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ import {
SliceLabelData,
} from './types'

interface MayHaveLabel {
label?: string | number
}

/**
* Format data so that we get a consistent data structure.
* It will also add the `formattedValue` and `color` property.
*/
export const useNormalizedData = <RawDatum>({
export const useNormalizedData = <RawDatum extends MayHaveLabel>({
data,
id = defaultProps.id,
value = defaultProps.value,
Expand All @@ -74,7 +78,6 @@ export const useNormalizedData = <RawDatum>({

const normalizedDatum: Omit<ComputedDatum<RawDatum>, 'arc' | 'color' | 'fill'> = {
id: datumId,
// @ts-ignore
label: datum.label || datumId,
value: datumValue,
formattedValue: formatValue(datumValue),
Expand Down

0 comments on commit 840a6cb

Please sign in to comment.