Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

fix portal zooming bug #521

Merged
merged 1 commit into from
Sep 29, 2017
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
28 changes: 26 additions & 2 deletions demo/components/victory-zoom-container-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
VictoryChart, VictoryZoomContainer, VictoryArea, VictoryLine,
VictoryAxis, VictoryGroup, VictoryStack, VictoryScatter
} from "../../src/index";
import { VictoryTheme, VictoryClipContainer, VictoryPortal, VictoryLegend } from "victory-core";
import {
VictoryTheme, VictoryClipContainer, VictoryPortal, VictoryLegend, VictoryTooltip
} from "victory-core";

export default class App extends React.Component {
constructor() {
Expand Down Expand Up @@ -56,7 +58,7 @@ export default class App extends React.Component {
}

getData() {
return range(100).map((i) => {
return range(50).map((i) => {
return {
x: i + 20,
y: Math.random()
Expand Down Expand Up @@ -147,6 +149,28 @@ export default class App extends React.Component {
</VictoryPortal>
</VictoryChart>

<VictoryChart style={{ parent: parentStyle }}
animate={{ duration: 1500 }}
domainPadding={{ x: 20, y: 0 }}
containerComponent={
<VictoryZoomContainer
minimumZoom={{ x: 5 }}
dimension="x"
clipContainerComponent={
<VictoryClipContainer clipPadding={{ top: 15, bottom: 15 }}/>
}
/>
}
>
<VictoryScatter
style={{ parent: parentStyle, data: { fill: "orange" } }}
size={15}
data={this.state.data}
labels={(d) => d.x}
labelComponent={<VictoryTooltip/>}
/>
</VictoryChart>

<VictoryChart
style={{ parent: parentStyle }}
containerComponent={<VictoryZoomContainer/>}
Expand Down
36 changes: 14 additions & 22 deletions src/components/containers/victory-zoom-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,22 @@ export const zoomContainerMixin = (base) => class VictoryZoomContainer extends b
const plottableWidth = Math.abs(rangeX[0] - rangeX[1]);
const plottableHeight = Math.abs(rangeY[0] - rangeY[1]);
const radius = Math.max(...rangeY);
const makeGroup = (child, index) => {
return React.cloneElement(clipContainerComponent, {
key: `ZoomClipContainer-${index}`,
clipWidth: plottableWidth,
clipHeight: plottableHeight,
translateX: Math.min(...rangeX),
translateY: Math.min(...rangeY),
children: child,
polar,
origin: polar ? origin : undefined,
radius: polar ? radius : undefined,
...clipContainerComponent.props
});
};
return React.Children.toArray(children).map((child, index) => {
const groupComponent = React.cloneElement(clipContainerComponent, {
clipWidth: plottableWidth,
clipHeight: plottableHeight,
translateX: Math.min(...rangeX),
translateY: Math.min(...rangeY),
polar,
origin: polar ? origin : undefined,
radius: polar ? radius : undefined,
...clipContainerComponent.props
});
return React.Children.toArray(children).map((child) => {
const role = child && child.type && child.type.role;
if (role === "axis" || role === "legend" || role === "label") {
return child;
} else if (role === "portal") {
const group = makeGroup(child.props.children, index);
return React.cloneElement(child, { children: group, key: `ZoomPortal-${index}` });
} else {
return makeGroup(child, index);
return React.cloneElement(child, { groupComponent });
}
});
}
Expand Down Expand Up @@ -170,8 +163,7 @@ export const zoomContainerMixin = (base) => class VictoryZoomContainer extends b
//eslint-disable-next-line max-statements
return childComponents.map((child) => {
const role = child && child.type && child.type.role;
const currentChild = role === "portal" ?
React.Children.toArray(child.props.children)[0] : child;
const currentChild = child;
const { currentDomain, zoomActive, allowZoom } = props;
const originalDomain = defaults({}, props.originalDomain, props.domain);
const zoomDomain = defaults({}, props.zoomDomain, props.domain);
Expand Down Expand Up @@ -205,7 +197,7 @@ export const zoomContainerMixin = (base) => class VictoryZoomContainer extends b
undefined : this.downsampleZoomData(props, currentChild.props, newDomain)
}, currentChild.props)
);
return role === "portal" ? React.cloneElement(child, { children: newChild }) : newChild;
return newChild;
});
}

Expand Down