From fe4f63422da855064829cd5f3ad506d585dfc082 Mon Sep 17 00:00:00 2001 From: plouc Date: Wed, 16 Dec 2020 21:00:23 +0900 Subject: [PATCH] feat(pie): remove lodash --- packages/pie/package.json | 3 +-- packages/pie/src/hooks.ts | 14 +++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/pie/package.json b/packages/pie/package.json index 3e0be3f05..9d8998dda 100644 --- a/packages/pie/package.json +++ b/packages/pie/package.json @@ -33,8 +33,7 @@ "@nivo/colors": "0.67.0", "@nivo/legends": "0.67.0", "@nivo/tooltip": "0.67.0", - "d3-shape": "^1.3.5", - "lodash": "^4.17.11" + "d3-shape": "^1.3.5" }, "devDependencies": { "@nivo/core": "0.67.0", diff --git a/packages/pie/src/hooks.ts b/packages/pie/src/hooks.ts index 0b13d95fd..65d02d358 100644 --- a/packages/pie/src/hooks.ts +++ b/packages/pie/src/hooks.ts @@ -1,5 +1,4 @@ import { useMemo, useState } from 'react' -import { get } from 'lodash' import { pie as d3Pie } from 'd3-shape' import { ArcGenerator, useArcGenerator, computeArcBoundingBox } from '@nivo/arcs' import { @@ -10,7 +9,7 @@ import { } from '@nivo/core' import { OrdinalColorScaleConfig, useOrdinalColorScale } from '@nivo/colors' import { defaultProps } from './props' -import { CompletePieSvgProps, ComputedDatum, PieArc, PieCustomLayerProps } from './types' +import { CompletePieSvgProps, ComputedDatum, DatumId, PieArc, PieCustomLayerProps } from './types' interface MayHaveLabel { label?: string | number @@ -31,11 +30,8 @@ export const useNormalizedData = ({ }: Pick, 'id' | 'value' | 'valueFormat' | 'colors'> & { data: RawDatum[] }): Omit, 'arc' | 'fill'>[] => { - const getId = usePropertyAccessor(id) - const getValue = useMemo( - () => (typeof value === 'function' ? value : (d: RawDatum) => get(d, value)), - [value] - ) + const getId = usePropertyAccessor(id) + const getValue = usePropertyAccessor(value) const formatValue = useValueFormatter(valueFormat) const getColor = useOrdinalColorScale, 'arc' | 'color' | 'fill'>>( @@ -92,7 +88,7 @@ export const usePieArcs = ({ outerRadius: number padAngle: number sortByValue: boolean - activeId: null | string | number + activeId: null | DatumId activeInnerRadiusOffset: number activeOuterRadiusOffset: number }): Omit, 'fill'>[] => { @@ -187,7 +183,7 @@ export const usePie = ({ radius: number innerRadius: number }) => { - const [activeId, setActiveId] = useState(null) + const [activeId, setActiveId] = useState(null) const dataWithArc = usePieArcs({ data, startAngle,