Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/bars-disappear-on-zoom #2970

Merged
merged 8 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/soft-moons-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"victory-bar": patch
"victory-core": patch
---

Zoomed bar graph items will no longer be culled from the view when more than 50% of width or height is outside of the clipping parent. Instead they will be clipped once 100% outside"
15 changes: 15 additions & 0 deletions demo/ts/components/victory-zoom-container-demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,21 @@ export default class VictoryZoomContainerDemo extends React.Component<
<VictoryAxis />
<VictoryAxis dependentAxis />
</VictoryChart>

<VictoryChart
containerComponent={<VictoryZoomContainer />}
style={{ parent: parentStyle }}
>
<VictoryBar />
</VictoryChart>

<VictoryChart
containerComponent={<VictoryZoomContainer />}
style={{ parent: parentStyle }}
horizontal
>
<VictoryBar />
</VictoryChart>
</div>
);
}
Expand Down
7 changes: 7 additions & 0 deletions packages/victory-bar/src/helper-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Helpers,
LabelHelpers,
Scale,
VictoryClipContainer,
} from "victory-core";

export const getBarPosition = (props, datum) => {
Expand Down Expand Up @@ -61,6 +62,12 @@ const getCalculatedValues = (props) => {
let data = Data.getData(props);
data = Data.formatDataFromDomain(data, domain, 0);

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

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

Expand Down
15 changes: 13 additions & 2 deletions packages/victory-bar/src/victory-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EventPropTypeInterface,
NumberOrCallback,
StringOrNumberOrCallback,
VictoryClipContainer,
VictoryCommonProps,
VictoryDatableProps,
VictoryMultiLabelableProps,
Expand Down Expand Up @@ -127,7 +128,9 @@ class VictoryBarBase extends React.Component<VictoryBarProps> {
"groupComponent",
"containerComponent",
];

// passed to addEvents.renderData to prevent data props with undefined _x or _y from excluding data from render.
// used when inside of VictoryZoomContainer
static shouldRenderDatum = () => true;
// Overridden in native versions
shouldAnimate() {
return !!this.props.animate;
Expand All @@ -141,7 +144,15 @@ class VictoryBarBase extends React.Component<VictoryBarProps> {
return this.animateComponent(props, animationWhitelist);
}

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

const component = props.standalone
? this.renderContainer(props.containerComponent, children)
Expand Down
2 changes: 1 addition & 1 deletion packages/victory-core/src/victory-util/add-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface EventsMixinClass<TProps> {
): React.ReactElement;
cacheValues<TThis>(this: TThis, obj: Partial<TThis>): void;
getEventState: typeof Events.getEventState;
renderData(props: TProps);
renderData(props: TProps, shouldRenderDatum?: () => boolean);
renderContinuousData(props: TProps);
animateComponent(
props: TProps,
Expand Down
Loading