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

Commit

Permalink
Merge pull request #557 from FormidableLabs/feature/victory-boxplot
Browse files Browse the repository at this point in the history
VictoryBoxPlot
  • Loading branch information
boygirl authored Mar 27, 2018
2 parents 75cbb14 + 6358e0f commit acbe7a0
Show file tree
Hide file tree
Showing 9 changed files with 1,289 additions and 3,216 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
.LSOverride
Icon

### VSCode ###
.vscode

# Thumbnails
._*

Expand Down
3 changes: 3 additions & 0 deletions demo/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ChartDemo from "./components/victory-chart-demo";
import LineDemo from "./components/victory-line-demo";
import ScatterDemo from "./components/victory-scatter-demo";
import ErrorBarDemo from "./components/victory-errorbar-demo";
import BoxplotDemo from "./components/victory-boxplot-demo";
import CandlestickDemo from "./components/victory-candlestick-demo";
import EventsDemo from "./components/events-demo";
import GroupDemo from "./components/group-demo";
Expand Down Expand Up @@ -63,6 +64,7 @@ class App extends React.Component {
case "/scatter": Child = ScatterDemo; break;
case "/errorbar": Child = ErrorBarDemo; break;
case "/candlestick": Child = CandlestickDemo; break;
case "/boxplot": Child = BoxplotDemo; break;
case "/events": Child = EventsDemo; break;
case "/group": Child = GroupDemo; break;
case "/voronoi": Child = VoronoiDemo; break;
Expand Down Expand Up @@ -98,6 +100,7 @@ class App extends React.Component {
<li><a href="#/scatter">Victory Scatter Demo</a></li>
<li><a href="#/errorbar">Victory Error Bar Demo</a></li>
<li><a href="#/candlestick">Victory Candlestick Demo</a></li>
<li><a href="#/boxplot">Victory Boxplot Demo</a></li>
<li><a href="#/events">Events Demo</a></li>
<li><a href="#/group">Group Demo</a></li>
<li><a href="#/voronoi">Victory Voronoi Demo</a></li>
Expand Down
181 changes: 181 additions & 0 deletions demo/components/victory-boxplot-demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*global window:false */
/*eslint-disable no-magic-numbers */
import React from "react";
import VictoryChart from "../../src/components/victory-chart/victory-chart";
import VictoryBoxPlot from "../../src/components/victory-boxplot/victory-boxplot";
import { range, random } from "lodash";

export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
data: this.getData()
};
}

componentDidMount() {
/* eslint-disable react/no-did-mount-set-state */
this.setStateInterval = window.setInterval(() => {
this.setState({
data: this.getData()
});
}, 3000);
}

componentWillUnmount() {
window.clearInterval(this.setStateInterval);
}

getData() {
return range(5).map((i) => {
return {
x: i,
y: range(20).map(() => random(1, 100))
};
});
}

render() {
const containerStyle = {
display: "flex",
flexDirection: "row",
flexWrap: "wrap",
alignItems: "center",
justifyContent: "center"
};

const chartStyle = { parent: { border: "1px solid #ccc", margin: "2%", maxWidth: "40%" } };

return (
<div className="demo" style={containerStyle}>
<VictoryChart style={chartStyle}>
<VictoryBoxPlot
data={[{ x: 1, y: 10 }, { x: 1, y: 7 }, { x: 1, y: 3 }, { x: 1, y: 5 }]}
/>
</VictoryChart>
<VictoryChart style={chartStyle} domain={{ x: [0, 3], y: [0, 20] }}>
<VictoryBoxPlot
boxWidth={20}
labels
data={[{ x: 1, y: [5, 10, 9, 2] }, { x: 2, y: [1, 15, 6, 8] }]}
style={{
min: { stroke: "black", strokeWidth: 2 },
max: { stroke: "black", strokeWidth: 2 },
q1: { fill: "#FF530D", fillOpacity: "0.5" },
q3: { fill: "#2bbee0", fillOpacity: "0.5" },
median: { stroke: "#fff", strokeWidth: "4" },
minLabels: { fill: "green", padding: 10 },
maxLabels: { fill: "orange", padding: 10 },
q1Labels: { padding: 10 },
q3Labels: { padding: 10 },
medianLabels: { padding: 10 }
}}
/>
</VictoryChart>

<VictoryChart style={chartStyle} domain={{ x: [0, 20], y: [0, 3] }}>
<VictoryBoxPlot
minLabels maxLabels
whiskerWidth={50}
data={[{ y: 1, x: [5, 10, 9, 2] }, { y: 2, x: [1, 15, 6, 8] }]}
boxWidth={20}
horizontal
labelOrientation={"top"}
events={[{
target: "q1",
eventHandlers: {
onClick: () => {
return [
{
target: "q1Labels",
mutation: () => ({ text: "LABEL!" })
}
];
}
}
}]}
style={{
min: { stroke: "black", strokeWidth: 2 },
max: { stroke: "black", strokeWidth: 2 },
q1: { fill: "#FF530D", fillOpacity: 0.5 },
q3: { fill: "#2bbee0", fillOpacity: 0.5 },
median: { stroke: "#fff", strokeWidth: 2 },
minLabels: { fill: "green", padding: 10 },
maxLabels: { fill: "orange", padding: 10 }
}}
/>
</VictoryChart>

<VictoryChart style={chartStyle} scale={{ y: "time" }} domainPadding={50}>
<VictoryBoxPlot
minLabels maxLabels
boxWidth={10}
data={[
{ y: new Date(1980, 1, 1), x: [5, 10, 9, 2] },
{ y: new Date(1990, 1, 1), x: [1, 15, 6, 8] },
{ y: new Date(2000, 1, 1), x: [3, 5, 6, 9] },
{ y: new Date(2010, 1, 1), x: [5, 20, 8, 12] },
{ y: new Date(2020, 1, 1), x: [2, 11, 12, 13] }
]}
horizontal
/>
</VictoryChart>
<VictoryChart style={chartStyle} domainPadding={50}>
<VictoryBoxPlot
minLabels maxLabels
boxWidth={10}
data={[
{ x: "red", y: [5, 10, 9, 2] },
{ x: "blue", y: [1, 15, 6, 8] },
{ x: "green", y: [3, 5, 6, 9] },
{ x: "yellow", y: [5, 20, 8, 12] },
{ x: "white", y: [2, 11, 12, 13] }
]}
/>
</VictoryChart>
<VictoryChart style={chartStyle} domainPadding={50}>
<VictoryBoxPlot
minLabels maxLabels
boxWidth={10}
data={[
{ x: 1, y: 5 },
{ x: 1, y: 10 },
{ x: 1, y: 8 },
{ x: 2, y: 1 },
{ x: 2, y: 15 },
{ x: 2, y: 7 },
{ x: 3, y: 3 },
{ x: 3, y: 8 },
{ x: 3, y: 5 }
]}
/>
</VictoryChart>
<VictoryChart style={chartStyle} domainPadding={50}>
<VictoryBoxPlot
labels
boxWidth={10}
horizontal
y="type"
data={[
{ type: 1, min: 1, max: 18, median: 8, q1: 5, q3: 15 },
{ type: 2, min: 4, max: 20, median: 10, q1: 7, q3: 15 },
{ type: 3, min: 3, max: 12, median: 6, q1: 5, q3: 10 }
]}
/>
</VictoryChart>
<VictoryChart animate style={chartStyle} domainPadding={50}>
<VictoryBoxPlot
boxWidth={10}
data={this.state.data}
/>
</VictoryChart>
<VictoryBoxPlot
animate
style={chartStyle}
boxWidth={10}
data={this.state.data}
/>
</div>
);
}
}
Loading

0 comments on commit acbe7a0

Please sign in to comment.