From 39f064451b195c4d228dced39698dadfd0612034 Mon Sep 17 00:00:00 2001 From: plouc Date: Mon, 14 Dec 2020 09:21:54 +0900 Subject: [PATCH] feat(pie): rename slices to arcs --- packages/arcs/src/ArcShape.tsx | 21 +++++++++++++-------- packages/arcs/src/ArcsLayer.tsx | 2 +- packages/arcs/src/types.ts | 2 ++ packages/pie/src/{Slices.tsx => Arcs.tsx} | 6 +++--- packages/pie/src/Pie.tsx | 12 ++++++------ packages/pie/src/props.ts | 2 +- packages/pie/src/types.ts | 2 +- 7 files changed, 27 insertions(+), 20 deletions(-) rename packages/pie/src/{Slices.tsx => Arcs.tsx} (96%) diff --git a/packages/arcs/src/ArcShape.tsx b/packages/arcs/src/ArcShape.tsx index 17089f2c2..c7e70e3ba 100644 --- a/packages/arcs/src/ArcShape.tsx +++ b/packages/arcs/src/ArcShape.tsx @@ -8,7 +8,7 @@ export type ArcMouseHandler = ( ) => void export interface ArcShapeProps { - data: Datum + datum: Datum style: { opacity: SpringValue color: SpringValue @@ -29,27 +29,32 @@ export interface ArcShapeProps { * regular values to support animations. */ export const ArcShape = ({ - data, + datum, style, onClick, onMouseEnter, onMouseMove, onMouseLeave, }: ArcShapeProps) => { - const handleClick = useCallback(event => onClick?.(data, event), [onClick, data]) + const handleClick = useCallback(event => onClick?.(datum, event), [onClick, datum]) - const handleMouseEnter = useCallback(event => onMouseEnter?.(data, event), [onMouseEnter, data]) + const handleMouseEnter = useCallback(event => onMouseEnter?.(datum, event), [ + onMouseEnter, + datum, + ]) - const handleMouseMove = useCallback(event => onMouseMove?.(data, event), [onMouseMove, data]) + const handleMouseMove = useCallback(event => onMouseMove?.(datum, event), [onMouseMove, datum]) - const handleMouseLeave = useCallback(event => onMouseLeave?.(data, event), [onMouseLeave, data]) + const handleMouseLeave = useCallback(event => onMouseLeave?.(datum, event), [ + onMouseLeave, + datum, + ]) return ( ({ {transition((transitionProps, datum) => { return createElement(Arc, { key: datum.id, - data: datum, + datum, style: { ...transitionProps, borderWidth, diff --git a/packages/arcs/src/types.ts b/packages/arcs/src/types.ts index 27a4d8821..8269210bd 100644 --- a/packages/arcs/src/types.ts +++ b/packages/arcs/src/types.ts @@ -23,6 +23,8 @@ export interface DatumWithArc { export interface DatumWithArcAndColor extends DatumWithArc { color: string + // when using patterns/gradients + fill?: string } export type ArcGenerator = D3Arc diff --git a/packages/pie/src/Slices.tsx b/packages/pie/src/Arcs.tsx similarity index 96% rename from packages/pie/src/Slices.tsx rename to packages/pie/src/Arcs.tsx index 70be372fb..c8b2a0d2c 100644 --- a/packages/pie/src/Slices.tsx +++ b/packages/pie/src/Arcs.tsx @@ -3,7 +3,7 @@ import { ArcGenerator, ArcsLayer } from '@nivo/arcs' import { useTooltip } from '@nivo/tooltip' import { ComputedDatum, CompletePieSvgProps } from './types' -interface SlicesProps { +interface ArcsProps { center: [number, number] data: ComputedDatum[] arcGenerator: ArcGenerator @@ -19,7 +19,7 @@ interface SlicesProps { transitionMode: CompletePieSvgProps['transitionMode'] } -export const Slices = ({ +export const Arcs = ({ center, data, arcGenerator, @@ -33,7 +33,7 @@ export const Slices = ({ setActiveId, tooltip, transitionMode, -}: SlicesProps) => { +}: ArcsProps) => { const { showTooltipFromEvent, hideTooltip } = useTooltip() const handleClick = useMemo(() => { diff --git a/packages/pie/src/Pie.tsx b/packages/pie/src/Pie.tsx index 47689e684..224b64df1 100644 --- a/packages/pie/src/Pie.tsx +++ b/packages/pie/src/Pie.tsx @@ -13,7 +13,7 @@ import PieLegends from './PieLegends' import { useNormalizedData, usePieFromBox, usePieLayerContext } from './hooks' import { ComputedDatum, PieLayer, PieSvgProps, PieLayerId } from './types' import { defaultProps } from './props' -import { Slices } from './Slices' +import { Arcs } from './Arcs' const InnerPie = ({ data, @@ -119,16 +119,16 @@ const InnerPie = ({ const boundDefs = bindDefs(defs, dataWithArc, fill) const layerById: Record = { - slices: null, + arcs: null, radialLabels: null, sliceLabels: null, legends: null, } - if (layers.includes('slices')) { - layerById.slices = ( - - key="slices" + if (layers.includes('arcs')) { + layerById.arcs = ( + + key="arcs" center={[centerX, centerY]} data={dataWithArc} arcGenerator={arcGenerator} diff --git a/packages/pie/src/props.ts b/packages/pie/src/props.ts index 752ba95ea..09827502f 100644 --- a/packages/pie/src/props.ts +++ b/packages/pie/src/props.ts @@ -10,7 +10,7 @@ export const defaultProps = { padAngle: 0, cornerRadius: 0, - layers: ['radialLabels', 'slices', 'sliceLabels', 'legends'], + layers: ['radialLabels', 'arcs', 'sliceLabels', 'legends'], // layout startAngle: 0, diff --git a/packages/pie/src/types.ts b/packages/pie/src/types.ts index 9827b42d5..53876895f 100644 --- a/packages/pie/src/types.ts +++ b/packages/pie/src/types.ts @@ -58,7 +58,7 @@ export type MouseEventHandler = ( event: React.MouseEvent ) => void -export type PieLayerId = 'radialLabels' | 'slices' | 'sliceLabels' | 'legends' +export type PieLayerId = 'radialLabels' | 'arcs' | 'sliceLabels' | 'legends' export interface PieCustomLayerProps { dataWithArc: ComputedDatum[]