Skip to content

Commit 894a507

Browse files
committed
added some comments, returned a new data obect instead of mutating, and added a horizontal demo
1 parent bcf00de commit 894a507

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,14 @@ export default class VictoryZoomContainerDemo extends React.Component<
557557
>
558558
<VictoryBar />
559559
</VictoryChart>
560+
561+
<VictoryChart
562+
containerComponent={<VictoryZoomContainer />}
563+
style={{ parent: parentStyle }}
564+
horizontal
565+
>
566+
<VictoryBar />
567+
</VictoryChart>
560568
</div>
561569
);
562570
}

packages/victory-bar/src/helper-methods.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@ const getCalculatedValues = (props) => {
6262
let data = Data.getData(props);
6363
data = Data.formatDataFromDomain(data, domain, 0);
6464

65+
// when inside a zoom container, reset the _x and _y properties of each datum to the original
66+
// x and y property values so they will not be clipped. See https://github.com/FormidableLabs/victory/pull/2970
6567
if (props.groupComponent.type === VictoryClipContainer) {
66-
data = data.map((datum) => {
67-
datum._x = datum.x;
68-
datum._y = datum.y;
69-
return datum;
70-
});
68+
data = data.map((datum) => ({ ...datum, _x: datum.x, _y: datum.y }));
7169
}
7270

7371
return { style, data, scale, domain, origin };

packages/victory-bar/src/victory-bar.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export type VictoryBarAlignmentType = "start" | "middle" | "end";
3939

4040
export interface VictoryBarProps
4141
extends VictoryCommonProps,
42-
VictoryDatableProps,
43-
VictoryMultiLabelableProps {
42+
VictoryDatableProps,
43+
VictoryMultiLabelableProps {
4444
alignment?: VictoryBarAlignmentType;
4545
barRatio?: number;
4646
barWidth?: NumberOrCallback;
@@ -145,6 +145,9 @@ class VictoryBarBase extends React.Component<VictoryBarProps> {
145145
}
146146

147147
let children;
148+
// when inside a zoom container (the only place VictoryClipContainer is used), all data
149+
// should be renderable so bars won't dissappear before they've fully exited the container's bounds
150+
// see https://github.com/FormidableLabs/victory/pull/2970
148151
if (props.groupComponent.type === VictoryClipContainer) {
149152
children = this.renderData(props, VictoryBarBase.shouldRenderDatum);
150153
} else {

0 commit comments

Comments
 (0)