Skip to content

Commit

Permalink
doc change
Browse files Browse the repository at this point in the history
  • Loading branch information
nlkluth committed Nov 12, 2024
1 parent 1f2650d commit b2f0cf8
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 92 deletions.
5 changes: 0 additions & 5 deletions .changeset/forty-shrimps-hug.md

This file was deleted.

22 changes: 0 additions & 22 deletions demo/ts/components/victory-box-plot-demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,28 +272,6 @@ export default class VictoryBoxPlotDemo extends React.Component<
boxWidth={10}
data={this.state.data}
/>
<VictoryChart
style={chartStyle}
minDomain={0}
theme={VictoryTheme.clean}
>
<VictoryBoxPlot
minLabels
minLabelComponent={
<VictoryTooltip
labelTarget="minLabels"
dataTargets={["min", "max", "q1", "q3", "median"]}
/>
}
data={[
{ x: "red", y: [5, 10, 9, 2] },
{ x: "blue", y: [1, 15, 6, 8] },
{ x: "green", y: [3, 5, 6, 9] },
{ x: "yellow", y: [5, 20, 8, 12] },
{ x: "white", y: [2, 11, 12, 13] },
]}
/>
</VictoryChart>
</div>
);
}
Expand Down
42 changes: 16 additions & 26 deletions packages/victory-tooltip/src/victory-tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export interface VictoryTooltipProps
};
constrainToVisibleArea?: boolean;
cornerRadius?: NumberOrCallback;
dataTargets: string[];
events?: any;
height?: number;
horizontal?: boolean;
Expand All @@ -50,7 +49,6 @@ export interface VictoryTooltipProps
flyoutWidth?: NumberOrCallback;
id?: number | string;
index?: number | string;
labelTarget: string;
orientation?: OrientationTypes | ((...args: any[]) => OrientationTypes);
pointerLength?: NumberOrCallback;
pointerOrientation?:
Expand Down Expand Up @@ -106,8 +104,6 @@ export class VictoryTooltip extends React.Component<VictoryTooltipProps> {
labelComponent: <VictoryLabel />,
flyoutComponent: <Flyout />,
groupComponent: <g />,
labelTarget: "labels",
dataTargets: ["data"],
};

static defaultEvents(props: VictoryTooltipProps): {
Expand All @@ -116,35 +112,29 @@ export class VictoryTooltip extends React.Component<VictoryTooltipProps> {
}[] {
const activate = props.activateData
? [
{ target: props.labelTarget, mutation: () => ({ active: true }) },
{ target: "labels", mutation: () => ({ active: true }) },
{ target: "data", mutation: () => ({ active: true }) },
]
: [{ target: props.labelTarget, mutation: () => ({ active: true }) }];
: [{ target: "labels", mutation: () => ({ active: true }) }];
const deactivate = props.activateData
? [
{
target: props.labelTarget,
mutation: () => ({ active: undefined }),
},
{ target: "labels", mutation: () => ({ active: undefined }) },
{ target: "data", mutation: () => ({ active: undefined }) },
]
: [
{
target: props.labelTarget,
mutation: () => ({ active: undefined }),
},
];
return props.dataTargets.map((dataTarget) => ({
target: dataTarget,
eventHandlers: {
onMouseOver: () => activate,
onFocus: () => activate,
onTouchStart: () => activate,
onMouseOut: () => deactivate,
onBlur: () => deactivate,
onTouchEnd: () => deactivate,
: [{ target: "labels", mutation: () => ({ active: undefined }) }];
return [
{
target: "data",
eventHandlers: {
onMouseOver: () => activate,
onFocus: () => activate,
onTouchStart: () => activate,
onMouseOut: () => deactivate,
onBlur: () => deactivate,
onTouchEnd: () => deactivate,
},
},
}));
];
}

id: string | number;
Expand Down
144 changes: 105 additions & 39 deletions website/docs/charts/box-plot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,111 @@ Events can be handled by passing an array of event objects to the `events` prop
</VictoryChart>
```

## Box Plot - Tooltips

Tooltips are not displayed by default on VictoryBoxPlot; to enable tooltips, use a custom events prop to handle interactions.

```jsx live noInline
function App() {
const activate =
(label: string) => () =>
[
{
target: label,
mutation: () => ({
active: true,
}),
},
];

const deactivate =
(label: string) => () =>
[
{
target: label,
mutation: () => ({
active: undefined,
}),
},
];

const dataTypes = [
"min",
"max",
"q1",
"q3",
"median",
];

const events = dataTypes.map(
(dataType) => ({
target: dataType,
eventHandlers: {
onMouseOver: activate(
`${dataType}Labels`,
),
onFocus: activate(
`${dataType}Labels`,
),
onTouchStart: activate(
`${dataType}Labels`,
),
onMouseOut: deactivate(
`${dataType}Labels`,
),
onBlur: deactivate(
`${dataType}Labels`,
),
onTouchEnd: deactivate(
`${dataType}Labels`,
),
},
}),
);

return (
<VictoryBoxPlot
minLabels
maxLabels
q1Labels
q3Labels
medianLabels
events={events}
minLabelComponent={
<VictoryTooltip />
}
maxLabelComponent={
<VictoryTooltip />
}
q1LabelComponent={
<VictoryTooltip />
}
q3LabelComponent={
<VictoryTooltip />
}
medianLabelComponent={
<VictoryTooltip />
}
data={[
{ x: "red", y: [5, 10, 9, 2] },
{ x: "blue", y: [1, 15, 6, 8] },
{ x: "green", y: [3, 5, 6, 9] },
{
x: "yellow",
y: [5, 20, 8, 12],
},
{
x: "white",
y: [2, 11, 12, 13],
},
]}
/>
);
}

render(<App />);
```

## Standalone Rendering

Box Plot charts can be rendered outside a VictoryChart.
Expand Down Expand Up @@ -311,42 +416,3 @@ They can also be embeded in other SVG components by using the `standalone` prop.
/>
</svg>
```

## Box Plot - Tooltips

```jsx live
<VictoryBoxPlot
minLabels
q3Labels
q3LabelComponent={
<VictoryTooltip
labelTarget="q3Labels"
dataTargets={["q3"]}
/>
}
minLabelComponent={
<VictoryTooltip
labelTarget="minLabels"
dataTargets={[
"min",
"max",
"q1",
"median",
]}
/>
}
data={[
{ x: "red", y: [5, 10, 9, 2] },
{ x: "blue", y: [1, 15, 6, 8] },
{ x: "green", y: [3, 5, 6, 9] },
{
x: "yellow",
y: [5, 20, 8, 12],
},
{
x: "white",
y: [2, 11, 12, 13],
},
]}
/>
```

0 comments on commit b2f0cf8

Please sign in to comment.