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 6 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"
7 changes: 7 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,13 @@ export default class VictoryZoomContainerDemo extends React.Component<
<VictoryAxis />
<VictoryAxis dependentAxis />
</VictoryChart>

<VictoryChart
containerComponent={<VictoryZoomContainer />}
style={{ parent: parentStyle }}
>
<VictoryBar />
</VictoryChart>
</div>
);
}
Expand Down
9 changes: 9 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,14 @@ const getCalculatedValues = (props) => {
let data = Data.getData(props);
data = Data.formatDataFromDomain(data, domain, 0);

if (props.groupComponent.type === VictoryClipContainer) {
data = data.map((datum) => {
nstolpe marked this conversation as resolved.
Show resolved Hide resolved
datum._x = datum.x;
datum._y = datum.y;
return datum;
});
}

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

Expand Down
12 changes: 10 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,12 @@ class VictoryBarBase extends React.Component<VictoryBarProps> {
return this.animateComponent(props, animationWhitelist);
}

const children = this.renderData(props);
let children;
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