-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from hshoff/harry-boxplot
[boxplot] add @vx/boxplot
- Loading branch information
Showing
19 changed files
with
645 additions
and
272 deletions.
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
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" | ||
] | ||
} | ||
} | ||
} |
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 @@ | ||
include node_modules/react-fatigue-dev/Makefile |
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,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={{ /** */ }}`. |
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,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" | ||
} | ||
} |
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,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> | ||
); | ||
} |
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 @@ | ||
export { default as BoxPlot } from './boxplots/BoxPlot'; |
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,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; | ||
}, {}); | ||
} |
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,6 @@ | ||
export default function callOrValue(maybeFn, data) { | ||
if (typeof maybeFn === 'function') { | ||
return maybeFn(data); | ||
} | ||
return maybeFn; | ||
} |
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
Oops, something went wrong.