Skip to content

Commit 7609176

Browse files
committed
victory-zoom-container
1 parent b6efcbe commit 7609176

File tree

5 files changed

+261
-21
lines changed

5 files changed

+261
-21
lines changed

demo/ts/components/victory-zoom-container-demo.tsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { VictoryArea } from "victory-area";
99
import { VictoryBar } from "victory-bar";
1010
import { VictoryLine } from "victory-line";
1111
import { VictoryScatter } from "victory-scatter";
12-
import { VictoryZoomContainer } from "victory-zoom-container";
12+
import { VictoryZoomContainerFn as VictoryZoomContainer } from "victory-zoom-container";
13+
// import { VictoryZoomContainer } from "victory-zoom-container";
1314
import { VictoryTooltip } from "victory-tooltip";
1415
import { VictoryLegend } from "victory-legend";
1516
import {
@@ -331,7 +332,9 @@ export default class VictoryZoomContainerDemo extends React.Component<
331332
{
332333
mutation: (props) => {
333334
return {
334-
style: Object.assign({}, props.style, { stroke: "orange" }),
335+
style: Object.assign({}, props.style, {
336+
stroke: "orange",
337+
}),
335338
};
336339
},
337340
},
@@ -417,7 +420,9 @@ export default class VictoryZoomContainerDemo extends React.Component<
417420
target: "data",
418421
mutation: (props) => {
419422
return {
420-
style: Object.assign({}, props.style, { fill: "gold" }),
423+
style: Object.assign({}, props.style, {
424+
fill: "gold",
425+
}),
421426
};
422427
},
423428
},
@@ -426,7 +431,9 @@ export default class VictoryZoomContainerDemo extends React.Component<
426431
target: "data",
427432
mutation: (props) => {
428433
return {
429-
style: Object.assign({}, props.style, { fill: "orange" }),
434+
style: Object.assign({}, props.style, {
435+
fill: "orange",
436+
}),
430437
};
431438
},
432439
},
@@ -435,7 +442,9 @@ export default class VictoryZoomContainerDemo extends React.Component<
435442
target: "data",
436443
mutation: (props) => {
437444
return {
438-
style: Object.assign({}, props.style, { fill: "red" }),
445+
style: Object.assign({}, props.style, {
446+
fill: "red",
447+
}),
439448
};
440449
},
441450
},

packages/victory-core/src/victory-container/victory-container-fn.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const defaultProps = {
5151
};
5252

5353
export const VictoryContainerFn = (initialProps: VictoryContainerProps) => {
54-
const propsWithDefaults = { ...defaultProps, ...initialProps };
54+
const props = { ...defaultProps, ...initialProps };
5555
const {
5656
role,
5757
title,
@@ -69,19 +69,19 @@ export const VictoryContainerFn = (initialProps: VictoryContainerProps) => {
6969
ouiaId,
7070
ouiaSafe,
7171
ouiaType,
72-
} = propsWithDefaults;
72+
} = props;
7373

7474
const containerRef = useRef<HTMLDivElement>(null);
7575

7676
const portalRef = useRef<Portal>(null);
7777

7878
// Generated ID stored in ref because it needs to persist across renders
7979
const generatedId = useRef(uniqueId("victory-container-"));
80-
const containerId = propsWithDefaults.containerId ?? generatedId;
80+
const containerId = props.containerId ?? generatedId;
8181

8282
const getIdForElement = (elName: string) => `${containerId}-${elName}`;
8383

84-
const userProps = UserProps.getSafeUserProps(propsWithDefaults);
84+
const userProps = UserProps.getSafeUserProps(props);
8585

8686
const dimensions = responsive
8787
? { width: "100%", height: "100%" }
@@ -90,24 +90,24 @@ export const VictoryContainerFn = (initialProps: VictoryContainerProps) => {
9090
const viewBox = responsive ? `0 0 ${width} ${height}` : undefined;
9191

9292
const preserveAspectRatio = responsive
93-
? propsWithDefaults.preserveAspectRatio
93+
? props.preserveAspectRatio
9494
: undefined;
9595

9696
const ariaLabelledBy =
97-
[title && getIdForElement("title"), propsWithDefaults["aria-labelledby"]]
97+
[title && getIdForElement("title"), props["aria-labelledby"]]
9898
.filter(Boolean)
9999
.join(" ") || undefined;
100100

101101
const ariaDescribedBy =
102-
[desc && getIdForElement("desc"), propsWithDefaults["aria-describedby"]]
102+
[desc && getIdForElement("desc"), props["aria-describedby"]]
103103
.filter(Boolean)
104104
.join(" ") || undefined;
105105

106106
const handleWheel = (e: WheelEvent) => e.preventDefault();
107107

108108
React.useEffect(() => {
109109
// TODO check that this works
110-
if (!propsWithDefaults.events?.onWheel) return;
110+
if (!props.events?.onWheel) return;
111111

112112
const container = containerRef?.current;
113113
container?.addEventListener("wheel", handleWheel);
@@ -138,7 +138,7 @@ export const VictoryContainerFn = (initialProps: VictoryContainerProps) => {
138138
data-ouia-component-id={ouiaId}
139139
data-ouia-component-type={ouiaType}
140140
data-ouia-safe={ouiaSafe}
141-
ref={mergeRefs([containerRef, propsWithDefaults.containerRef])}
141+
ref={mergeRefs([containerRef, props.containerRef])}
142142
>
143143
<svg
144144
width={width}

packages/victory-selection-container/src/victory-selection-container-fn.tsx

+18-7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ export interface VictorySelectionContainerProps extends VictoryContainerProps {
3131
selectionStyle?: React.CSSProperties;
3232
}
3333

34+
type Handler = (
35+
event: any,
36+
targetProps: any,
37+
eventKey?: any,
38+
context?: any,
39+
) => void;
40+
3441
const defaultProps = {
3542
activateSelectedData: true,
3643
allowSelection: true,
@@ -45,10 +52,10 @@ const defaultProps = {
4552
export const VictorySelectionContainerFn = (
4653
initialProps: VictorySelectionContainerProps,
4754
) => {
48-
const propsWithDefaults = { ...defaultProps, ...initialProps };
55+
const props = { ...defaultProps, ...initialProps };
4956

5057
const { x1, x2, y1, y2, selectionStyle, selectionComponent, children, name } =
51-
propsWithDefaults;
58+
props;
5259
const width = Math.abs(x2 - x1) || 1;
5360
const height = Math.abs(y2 - y1) || 1;
5461
const x = Math.min(x1, x2);
@@ -57,7 +64,7 @@ export const VictorySelectionContainerFn = (
5764
const shouldRenderRect = y1 && y2 && x1 && x2;
5865

5966
return (
60-
<VictoryContainerFn {...propsWithDefaults}>
67+
<VictoryContainerFn {...props}>
6168
{children}
6269

6370
{shouldRenderRect &&
@@ -76,12 +83,16 @@ export const VictorySelectionContainerFn = (
7683
VictorySelectionContainerFn.role = "container";
7784

7885
VictorySelectionContainerFn.defaultEvents = (
79-
props: VictorySelectionContainerProps,
86+
initialProps: VictorySelectionContainerProps,
8087
) => {
88+
const props = { ...defaultProps, ...initialProps };
8189
const createEventHandler =
82-
(handler: (event: any, targetProps: any) => any) =>
83-
(event: any, targetProps: any) =>
84-
props.disable ? {} : handler(event, { ...defaultProps, ...targetProps });
90+
(handler: Handler, disabled?: boolean): Handler =>
91+
// eslint-disable-next-line max-params
92+
(event, targetProps, eventKey, context) =>
93+
disabled || props.disable
94+
? {}
95+
: handler(event, { ...props, ...targetProps }, eventKey, context);
8596

8697
return [
8798
{
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./victory-zoom-container";
2+
export { VictoryZoomContainerFn } from "./victory-zoom-container-fn";
23
export * from "./zoom-helpers";

0 commit comments

Comments
 (0)