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

Bug/stacked groups #1072

Merged
merged 2 commits into from
Aug 2, 2018
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
69 changes: 69 additions & 0 deletions demo/components/debug-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import React from "react";
import { VictoryChart } from "../../packages/victory-chart/src/index";
import { VictoryStack } from "../../packages/victory-stack/src/index";
import { VictoryGroup } from "../../packages/victory-group/src/index";
import { VictoryBar } from "../../packages/victory-bar/src/index";
import { VictoryArea } from "../../packages/victory-area/src/index";
import { VictoryScatter } from "../../packages/victory-scatter/src/index";
import { VictoryPortal } from "../../packages/victory-core/src/index";
import { VictorySelectionContainer } from "../../packages/victory-selection-container/src/index";
import { VictoryVoronoiContainer } from "../../packages/victory-voronoi-container/src/index";

Expand All @@ -20,6 +24,71 @@ class App extends React.Component {
const chartStyle = { parent: { border: "1px solid #ccc", margin: "2%", maxWidth: "40%" } };
return (
<div style={containerStyle}>
<VictoryChart style={chartStyle} >
<VictoryStack colorScale="warm">
<VictoryGroup
data={[
{ x: 1, y: 2 },
{ x: 2, y: 3 },
{ x: 3, y: 5 },
{ x: 4, y: 4 }
]}
>
<VictoryArea/>
<VictoryPortal>
<VictoryScatter
style={{ data: { fill: "black" } }}
/>
</VictoryPortal>
</VictoryGroup>
<VictoryGroup
data={[
{ x: 1, y: 4 },
{ x: 2, y: 3 },
{ x: 3, y: 2 },
{ x: 4, y: 5 }
]}
>
<VictoryArea/>
<VictoryPortal>
<VictoryScatter
style={{ data: { fill: "green" } }}
/>
</VictoryPortal>
</VictoryGroup>
<VictoryGroup
data={[
{ x: 1, y: 3 },
{ x: 2, y: 1 },
{ x: 3, y: 4 },
{ x: 4, y: 2 }
]}
>
<VictoryArea/>
<VictoryPortal>
<VictoryScatter
style={{ data: { fill: "blue" } }}
/>
</VictoryPortal>
</VictoryGroup>
<VictoryGroup
data={[
{ x: 1, y: 3 },
{ x: 2, y: 1 },
{ x: 3, y: 4 },
{ x: 4, y: 2 }
]}
>
<VictoryArea/>
<VictoryPortal>
<VictoryScatter
style={{ data: { fill: "cyan" } }}
/>
</VictoryPortal>
</VictoryGroup>
</VictoryStack>
</VictoryChart>

<VictoryChart style={chartStyle}
containerComponent={
<VictoryVoronoiContainer
Expand Down
12 changes: 7 additions & 5 deletions packages/victory-core/src/victory-util/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export default {
getDataFromChildren(props, childComponents) {
const { polar, startAngle, endAngle, categories, minDomain, maxDomain } = props;
const parentProps = { polar, startAngle, endAngle, categories, minDomain, maxDomain };

let stack = 0;
const iteratee = (child, childName, parent) => {
const role = child.type && child.type.role;
const childProps = assign({}, child.props, parentProps);
Expand All @@ -182,14 +184,14 @@ export default {
} else {
childData = Data.getData(childProps);
}
return childData.map((datum) => assign({ childName }, datum));
stack += 1;
return childData.map((datum) => assign({ stack }, datum));
};

const children = childComponents ?
childComponents.slice(0) : React.Children.toArray(props.children);
const datasets = Helpers.reduceChildren(children, iteratee, props);
childComponents.slice(0) : React.Children.toArray(props.children);
const stacked = children.filter((c) => c.type && c.type.role === "stack").length;
const group = stacked ? "eventKey" : "childName";
const datasets = Helpers.reduceChildren(children, iteratee, props);
const group = stacked ? "eventKey" : "stack";
return values(groupBy(datasets, group));
},

Expand Down