Skip to content

Commit

Permalink
fix(website): update sunburst to not crash on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze authored and plouc committed Dec 2, 2020
1 parent 3a6537b commit 952ad50
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 45 deletions.
66 changes: 32 additions & 34 deletions packages/sunburst/src/Sunburst.tsx
Expand Up @@ -7,49 +7,47 @@ import { defaultProps } from './props'
import { useSunburst, useSunburstLayerContext } from './hooks'
import { SvgProps, SunburstLayerId, SunburstLayer } from './types'

const InnerSunburst = <RawDatum,>(props: SvgProps<RawDatum>) => {
const {
data,
id,
value,
valueFormat,

layers = defaultProps.layers as SunburstLayer<RawDatum>[],

colors,
childColor,
const InnerSunburst = <RawDatum,>({
data,
id = defaultProps.id,
value = defaultProps.value,
valueFormat,

margin: partialMargin,
width,
height,
layers = defaultProps.layers as SunburstLayer<RawDatum>[],

cornerRadius,
colors = defaultProps.colors,
childColor = defaultProps.childColor,

borderWidth,
borderColor,
margin: partialMargin,
width,
height,

// slices labels
enableSliceLabels,
sliceLabel,
sliceLabelsSkipAngle,
sliceLabelsTextColor,
cornerRadius = defaultProps.cornerRadius,

defs = [],
fill = [],
borderWidth = defaultProps.borderWidth,
borderColor = defaultProps.borderColor,

role,
// slices labels
enableSliceLabels = defaultProps.enableSliceLabels,
sliceLabel = defaultProps.sliceLabel,
sliceLabelsSkipAngle = defaultProps.sliceLabelsSkipAngle,
sliceLabelsTextColor = defaultProps.sliceLabelsTextColor,

// interactivity
isInteractive,
tooltip,
defs = defaultProps.defs,
fill = defaultProps.fill,

// event handlers
onClick,
onMouseEnter,
onMouseLeave,
onMouseMove,
} = { ...defaultProps, ...props }
role = defaultProps.role,

// interactivity
isInteractive = defaultProps.isInteractive,
tooltip = defaultProps.tooltip,

// event handlers
onClick,
onMouseEnter,
onMouseLeave,
onMouseMove,
}: SvgProps<RawDatum>) => {
const { innerHeight, innerWidth, margin, outerHeight, outerWidth } = useDimensions(
width,
height,
Expand Down
3 changes: 3 additions & 0 deletions packages/sunburst/src/props.ts
Expand Up @@ -27,5 +27,8 @@ export const defaultProps = {
animate: false,
motionConfig: 'gentle',

defs: [],
fill: [],

tooltip: SunburstTooltip,
}
20 changes: 10 additions & 10 deletions website/src/data/components/pie/props.js
Expand Up @@ -22,19 +22,19 @@ const props = [
description: `
Chart data, which must conform to this structure
if using the default \`id\` and \`value\` accessors:
\`\`\`
Array<{
id: string | number,
value: number
}>
\`\`\`
If using a different data structure, you must make sure
to adjust both \`id\` and \`value\`. Meaning you can provide
a completely different data structure as long as \`id\` and \`value\`
return the appropriate values.
Immutability of the data is important as re-computations
depends on it.
`,
Expand Down Expand Up @@ -63,15 +63,15 @@ const props = [
`,
type: 'string | (datum: RawDatum): number',
required: false,
defaultValue: defaults.id,
defaultValue: defaults.value,
},
{
key: 'valueFormat',
group: 'Base',
help: 'Optional formatter for values.',
description: `
The formatted value can then be used for labels & tooltips.
Under the hood, nivo uses [d3-format](https://github.com/d3/d3-format),
please have a look at it for available formats, you can also pass a function
which will receive the raw value and should return the formatted one.
Expand Down Expand Up @@ -481,7 +481,7 @@ const props = [
description: `
You can also use this to insert extra layers
to the chart, the extra layer must be a function.
The layer component which will receive the chart's
context & computed data and must return a valid SVG element
for the \`Pie\` component.
Expand All @@ -494,9 +494,9 @@ const props = [
\`context.restore()\` if you make some global
modifications to the 2d context inside this function
to avoid side effects.
The context passed to layers has the following structure:
\`\`\`
{
dataWithArc: DatumWithArc[],
Expand Down Expand Up @@ -565,13 +565,13 @@ const props = [
A function allowing complete tooltip customisation,
it must return a valid HTML element and will receive
the following props:
\`\`\`
{
datum: PieComputedDatum
}
\`\`\`
You can also customize the style of the tooltip using
the \`theme.tooltip\` object.
`,
Expand Down
6 changes: 5 additions & 1 deletion website/src/data/components/sunburst/mapper.js
Expand Up @@ -13,8 +13,12 @@ import { settingsMapper } from '../../../lib/settings'

const TooltipWrapper = styled.div`
display: grid;
background: #fff;
grid-template-columns: 1fr 1fr;
grid-column-gap: 12px;
font-size: 12px;
border-radius: 2px;
box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.15);
`
const TooltipKey = styled.span`
font-weight: 600;
Expand All @@ -39,7 +43,7 @@ const CustomTooltip = node => {
export default settingsMapper(
{
tooltip: (value, values) => {
if (!values['custom tooltip example']) return null
if (!values['custom tooltip example']) return undefined

return CustomTooltip
},
Expand Down

0 comments on commit 952ad50

Please sign in to comment.