Skip to content

Commit

Permalink
feat(pie): remove lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc authored and wyze committed Apr 23, 2021
1 parent bf225e7 commit fe4f634
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
3 changes: 1 addition & 2 deletions packages/pie/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 5 additions & 9 deletions packages/pie/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand All @@ -31,11 +30,8 @@ export const useNormalizedData = <RawDatum extends MayHaveLabel>({
}: Pick<CompletePieSvgProps<RawDatum>, 'id' | 'value' | 'valueFormat' | 'colors'> & {
data: RawDatum[]
}): Omit<ComputedDatum<RawDatum>, 'arc' | 'fill'>[] => {
const getId = usePropertyAccessor<RawDatum, string | number>(id)
const getValue = useMemo(
() => (typeof value === 'function' ? value : (d: RawDatum) => get(d, value)),
[value]
)
const getId = usePropertyAccessor<RawDatum, DatumId>(id)
const getValue = usePropertyAccessor<RawDatum, number>(value)
const formatValue = useValueFormatter<number>(valueFormat)

const getColor = useOrdinalColorScale<Omit<ComputedDatum<RawDatum>, 'arc' | 'color' | 'fill'>>(
Expand Down Expand Up @@ -92,7 +88,7 @@ export const usePieArcs = <RawDatum>({
outerRadius: number
padAngle: number
sortByValue: boolean
activeId: null | string | number
activeId: null | DatumId
activeInnerRadiusOffset: number
activeOuterRadiusOffset: number
}): Omit<ComputedDatum<RawDatum>, 'fill'>[] => {
Expand Down Expand Up @@ -187,7 +183,7 @@ export const usePie = <RawDatum>({
radius: number
innerRadius: number
}) => {
const [activeId, setActiveId] = useState<string | number | null>(null)
const [activeId, setActiveId] = useState<DatumId | null>(null)
const dataWithArc = usePieArcs({
data,
startAngle,
Expand Down

0 comments on commit fe4f634

Please sign in to comment.