Skip to content

Commit

Permalink
Merge pull request #89 from hshoff/harry-boxplot
Browse files Browse the repository at this point in the history
[boxplot] add @vx/boxplot
  • Loading branch information
hshoff authored Jul 5, 2017
2 parents ab564ed + 8da24d7 commit 99cc020
Show file tree
Hide file tree
Showing 19 changed files with 645 additions and 272 deletions.
19 changes: 19 additions & 0 deletions packages/vx-boxplot/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"presets": ["es2015", "react", "stage-0"],
"plugins": [],
"env": {
"development": {
"plugins": [
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}]
}],
"transform-runtime",
"transform-decorators-legacy"
]
}
}
}
1 change: 1 addition & 0 deletions packages/vx-boxplot/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include node_modules/react-fatigue-dev/Makefile
9 changes: 9 additions & 0 deletions packages/vx-boxplot/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @vx/boxplot

```
npm install --save @vx/boxplot
```

You can pass in props to target the `min`, `max`, `median`, and `box (interquartile range)` shapes using `minProps`, `maxProps`, `medianProps`, and `boxProps`.

If you are looking to add events over the each boxplot group you can pass in `container={true}` and `containerProps={{ /** */ }}`.
42 changes: 42 additions & 0 deletions packages/vx-boxplot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@vx/boxplot",
"version": "1.0.0",
"description": "vx box plot",
"main": "build/index.js",
"scripts": {
"build": "make build SRC=./src",
"prepublish": "make build SRC=./src",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/hshoff/vx.git"
},
"keywords": ["vx", "react", "d3", "visualizations", "charts"],
"author": "@conglei",
"license": "MIT",
"bugs": {
"url": "https://github.com/hshoff/vx/issues"
},
"homepage": "https://github.com/hshoff/vx#readme",
"dependencies": {
"@vx/group": "0.0.126",
"classnames": "^2.2.5"
},
"devDependencies": {
"babel-jest": "^20.0.3",
"enzyme": "^2.8.2",
"jest": "^20.0.3",
"react-addons-test-utils": "^15.5.1",
"react-fatigue-dev": "github:tj/react-fatigue-dev",
"react-tools": "^0.10.0",
"regenerator-runtime": "^0.10.5",
"react": "^15.0.0 || 15.x"
},
"peerDependencies": {
"react": "^15.0.0 || 15.x"
},
"publishConfig": {
"access": "public"
}
}
137 changes: 137 additions & 0 deletions packages/vx-boxplot/src/boxplots/BoxPlot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import React from 'react';
import classnames from 'classnames';
import { Group } from '@vx/group';
import additionalProps from '../util/additionalProps';

export default function BoxPlot({
left = 0,
className,
data,
max,
min,
firstQuartile,
thirdQuartile,
median,
boxWidth,
fill,
fillOpacity,
stroke,
strokeWidth,
rx = 2,
ry = 2,
medianProps = {},
maxProps = {},
minProps = {},
boxProps = {},
container = false,
containerProps = {},
...restProps
}) {
const centerX = left + boxWidth / 2;
return (
<Group className={classnames('vx-boxplot', className)}>
<line
className="vx-boxplot-max"
x1={centerX - boxWidth / 4}
y1={max}
x2={centerX + boxWidth / 4}
y2={max}
stroke={stroke}
strokeWidth={strokeWidth}
{...additionalProps(maxProps, {
data,
max,
x1: centerX - boxWidth / 4,
x2: centerX + boxWidth / 4
})}
/>
<line
x1={centerX}
y1={max}
x2={centerX}
y2={thirdQuartile}
stroke={stroke}
strokeWidth={strokeWidth}
/>
<rect
x={left}
y={thirdQuartile}
width={boxWidth}
height={firstQuartile - thirdQuartile}
stroke={stroke}
strokeWidth={strokeWidth}
fill={fill}
fillOpacity={fillOpacity}
rx={rx}
ry={ry}
{...additionalProps(boxProps, {
data,
height: firstQuartile - thirdQuartile,
median,
firstQuartile,
thirdQuartile,
min,
max,
x1: left,
x2: left + boxWidth
})}
/>
<line
className="vx-boxplot-median"
x1={left}
y1={median}
x2={left + boxWidth}
y2={median}
stroke={stroke}
strokeWidth={strokeWidth}
{...additionalProps(medianProps, {
data,
median,
x1: left,
x2: left + boxWidth
})}
/>
<line
x1={centerX}
y1={firstQuartile}
x2={centerX}
y2={min}
stroke={stroke}
strokeWidth={strokeWidth}
/>
<line
className="vx-boxplot-min"
x1={centerX - boxWidth / 4}
y1={min}
x2={centerX + boxWidth / 4}
y2={min}
stroke={stroke}
strokeWidth={strokeWidth}
{...additionalProps(minProps, {
data,
min,
x1: centerX - boxWidth / 4,
x2: centerX + boxWidth / 4
})}
/>
{container &&
<rect
x={left}
y={max}
width={boxWidth}
height={min - max}
fillOpacity="0"
{...additionalProps(containerProps, {
data,
x1: left,
x2: left + boxWidth,
median,
max,
min,
thirdQuartile,
firstQuartile
})}
/>}
</Group>
);
}
1 change: 1 addition & 0 deletions packages/vx-boxplot/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as BoxPlot } from './boxplots/BoxPlot';
8 changes: 8 additions & 0 deletions packages/vx-boxplot/src/util/additionalProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import callOrValue from './callOrValue';

export default function additionalProps(restProps, data) {
return Object.keys(restProps).reduce((ret, cur) => {
ret[cur] = callOrValue(restProps[cur], data);
return ret;
}, {});
}
6 changes: 6 additions & 0 deletions packages/vx-boxplot/src/util/callOrValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function callOrValue(maybeFn, data) {
if (typeof maybeFn === 'function') {
return maybeFn(data);
}
return maybeFn;
}
20 changes: 14 additions & 6 deletions packages/vx-demo/components/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export default class Gallery extends React.Component {
<div className="image">
<Dots width={t3[0]} height={t3[1]} />
</div>
<div className="details color-yellow" style={{ zIndex: 1 }}>
<div
className="details color-yellow"
style={{ zIndex: 1 }}
>
<div className="title">Dots</div>
<div className="description">
<pre>{`<Glyph.GlyphCircle />`}</pre>
Expand Down Expand Up @@ -301,7 +304,8 @@ export default class Gallery extends React.Component {
<div className="details" style={{ color: '#8e205f' }}>
<div className="title">Axis</div>
<div className="description">
<pre>{`<Axis.AxisLeft /> + <Axis.AxisBottom />`}</pre>
<pre
>{`<Axis.AxisLeft /> + <Axis.AxisBottom />`}</pre>
</div>
</div>
</div>
Expand Down Expand Up @@ -421,7 +425,8 @@ export default class Gallery extends React.Component {
<div className="details" style={{ color: '#269688' }}>
<div className="title">Trees</div>
<div className="description">
<pre>{`<Hierarchy.Tree /> + <Shape.LinkHorizontal />`}</pre>
<pre
>{`<Hierarchy.Tree /> + <Shape.LinkHorizontal />`}</pre>
</div>
</div>
</div>
Expand Down Expand Up @@ -499,15 +504,18 @@ export default class Gallery extends React.Component {
<div
className="gallery-item"
ref={d => this.nodes.add(d)}
style={{background:"#fd7e14"}}
style={{ background: '#fd7e14' }}
>
<div className="image">
<BoxPlot width={t17[0]} height={t17[1]} />
</div>
<div className="details" style={{ color: '#FFFFFF' }}>
<div
className="details"
style={{ color: '#FFFFFF', zIndex: 1 }}
>
<div className="title">BoxPlot</div>
<div className="description">
<pre>{`<Glyph.GlyphBoxPlot /> `}</pre>
<pre>{`<BoxPlot /> `}</pre>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 99cc020

Please sign in to comment.