-
Notifications
You must be signed in to change notification settings - Fork 524
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
Add demo for box plot, clean up label prop defs for box plot #1508
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
/*global window:false */ | ||
/*eslint-disable no-magic-numbers */ | ||
import React from "react"; | ||
import { VictoryChart } from "@packages/victory-chart/src/index"; | ||
import { VictoryBoxPlot } from "@packages/victory-box-plot/src/index"; | ||
import { VictoryTheme } from "@packages/victory-core/src/index"; | ||
import { range, random } from "lodash"; | ||
|
||
interface VictoryBoxPlotDemoState { | ||
data: { | ||
x: number; | ||
y: number[]; | ||
}[]; | ||
} | ||
|
||
export default class VictoryBoxPlotDemo extends React.Component<any, VictoryBoxPlotDemoState> { | ||
setStateInterval?: number = undefined; | ||
|
||
constructor(props: any) { | ||
super(props); | ||
this.state = { | ||
data: this.getData() | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
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: React.CSSProperties = { | ||
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} minDomain={0} theme={VictoryTheme.material}> | ||
<VictoryBoxPlot | ||
minLabels | ||
maxLabels | ||
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}> | ||
<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 horizontal style={chartStyle} domain={{ y: [0, 20], x: [0, 3] }}> | ||
<VictoryBoxPlot | ||
minLabels | ||
maxLabels | ||
q1Labels={({ datum }) => `x: ${datum.x}`} | ||
whiskerWidth={50} | ||
data={[{ x: 1, y: [5, 10, 9, 2] }, { x: 2, y: [1, 15, 6, 8] }]} | ||
boxWidth={20} | ||
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} horizontal domainPadding={50}> | ||
<VictoryBoxPlot | ||
minLabels | ||
maxLabels | ||
boxWidth={10} | ||
data={[ | ||
{ x: new Date(1980, 1, 1), y: [5, 10, 9, 2] }, | ||
{ x: new Date(1990, 1, 1), y: [1, 15, 6, 8] }, | ||
{ x: new Date(2000, 1, 1), y: [3, 5, 6, 9] }, | ||
{ x: new Date(2010, 1, 1), y: [5, 20, 8, 12] }, | ||
{ x: new Date(2020, 1, 1), y: [2, 11, 12, 13] } | ||
]} | ||
/> | ||
</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 | ||
x="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 } | ||
]} | ||
labelOrientation={{ | ||
q1: "top", | ||
q3: "top", | ||
min: "bottom", | ||
max: "bottom", | ||
median: "bottom" | ||
}} | ||
/> | ||
</VictoryChart> | ||
<VictoryChart horizontal animate style={chartStyle} domainPadding={50}> | ||
<VictoryBoxPlot boxWidth={10} data={this.state.data} /> | ||
</VictoryChart> | ||
<VictoryBoxPlot animate style={chartStyle} boxWidth={10} data={this.state.data} /> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure about this... should we be enforcing strings and numbers rather than any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
victory-core
exposes aStringOrNumberOrCallback
type that would be useful here rather than the plain function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, actually I guess it's a bit different for
VictoryBoxPlot
, but you might be able to borrow some of the ideas from https://github.com/FormidableLabs/victory/blob/master/packages/victory-core/src/index.d.ts#L109There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yes, let's use
string | number
instead of any