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

RFC: Consistency and Control #383

Merged
merged 20 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
25efe09
[glyph][breaking] rm additionalProps, add children as fn
hshoff Oct 14, 2018
126e2c0
[shape][breaking][1 of 2] rm additionalProps, add children as fn
hshoff Oct 15, 2018
4691e9d
[shape][breaking][2 of 2] rm additionalProps, add children as fn
hshoff Oct 18, 2018
3611c5a
[geo][breaking] rm additionalProps, add children as fn
hshoff Oct 19, 2018
77c560c
[heatmap][breaking] rm additionalProps, add children as fn
hshoff Oct 22, 2018
15e4878
[stats][breaking] rm additionalProps, add children as fn
hshoff Oct 22, 2018
7b2874a
[boxplot][breaking] rm additionalProps, add children as fn
hshoff Oct 22, 2018
e5efed5
[voronoi][breaking] rm additionalProps, add children as fn
hshoff Oct 22, 2018
51e9baf
[shape] rm additionalProps reference from readme
hshoff Oct 22, 2018
7261ee8
[legend][breaking] rm additionalProps, add children as fn
hshoff Oct 22, 2018
9c642be
[demo][breaking] start updating tiles to new apis
hshoff Oct 22, 2018
2328ca4
[demo][breaking] continue updating tiles to new apis
hshoff Oct 26, 2018
33bf8b4
[demo][breaking] continue updating tiles to new apis
hshoff Nov 6, 2018
46ad07c
[demo][breaking] finish updating tiles to new apis
hshoff Nov 18, 2018
c29688c
[shape] default Line fill to transparent
hshoff Nov 18, 2018
328c4ec
[shape] allow <AreaClosed /> to work with x,y,yScale
hshoff Nov 18, 2018
43a93d8
[shape] BarGroup + BarStack call children fn with array not object
hshoff Nov 18, 2018
1056bd9
[demo] gallery move barstack + bargroup next to each other
hshoff Nov 18, 2018
1597078
[demo] add gallery back to show
hshoff Nov 18, 2018
d3f1736
[demo] give threshold tile unique id
hshoff Nov 18, 2018
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
29 changes: 22 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"scripts": {
"test": "lerna bootstrap && lerna exec npm run test",
"docs": "node ./scripts/docs/index.js",
"prepare-release":
"git checkout master && git pull --rebase origin master && npm run docs && lerna updated",
"prepare-release": "git checkout master && git pull --rebase origin master && npm run docs && lerna updated",
"release": "npm run prepare-release && lerna publish --exact",
"lint": "eslint \"packages/**/*.js\" --config \"./.eslintrc\"",
"lint:fix": "eslint \"packages/**/*.js\" --config \"./.eslintrc\" --fix",
Expand All @@ -22,16 +21,32 @@
"singleQuote": true
},
"lint-staged": {
"*.js": ["prettier-eslint --write", "git add"]
"*.js": [
"prettier-eslint --write",
"git add"
]
},
"jest": {
"projects": ["<rootDir>/packages/*"],
"projects": [
"<rootDir>/packages/*"
],
"collectCoverage": true,
"coverageDirectory": "<rootDir>/coverage",
"coveragePathIgnorePatterns": ["/node_modules/"],
"coverageReporters": ["text", "lcov"]
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageReporters": [
"text",
"lcov"
]
},
"keywords": ["react", "d3", "visualization", "vx", "charts"],
"keywords": [
"react",
"d3",
"visualization",
"vx",
"charts"
],
"author": "@hshoff",
"license": "MIT",
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/vx-boxplot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"homepage": "https://github.com/hshoff/vx#readme",
"dependencies": {
"@vx/group": "0.0.170",
"classnames": "^2.2.5"
"classnames": "^2.2.5",
"prop-types": "^15.5.10"
},
"devDependencies": {
"babel-cli": "^6.26.0",
Expand Down
237 changes: 166 additions & 71 deletions packages/vx-boxplot/src/boxplots/BoxPlot.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
import React from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { Group } from '@vx/group';
import additionalProps from '../util/additionalProps';

function verticalToHorizontal({ x1, x2, y1, y2 }) {
return {
x1: y1,
x2: y2,
y1: x1,
y2: x2
};
}

BoxPlot.propTypes = {
left: PropTypes.number,
top: PropTypes.number,
className: PropTypes.string,
max: PropTypes.number,
min: PropTypes.number,
firstQuartile: PropTypes.number,
thirdQuartile: PropTypes.number,
median: PropTypes.number,
boxWidth: PropTypes.number,
fill: PropTypes.string,
fillOpacity: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
stroke: PropTypes.string,
strokeWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
rx: PropTypes.number,
ry: PropTypes.number,
valueScale: PropTypes.func,
outliers: PropTypes.array,
horizontal: PropTypes.bool,
medianProps: PropTypes.object,
maxProps: PropTypes.object,
minProps: PropTypes.object,
boxProps: PropTypes.object,
outlierProps: PropTypes.object,
container: PropTypes.bool,
containerProps: PropTypes.object,
children: PropTypes.func
};

export default function BoxPlot({
left = 0,
top = 0,
className,
data,
max,
min,
firstQuartile,
Expand All @@ -19,118 +57,175 @@ export default function BoxPlot({
strokeWidth,
rx = 2,
ry = 2,
valueScale,
outliers = [],
horizontal,
medianProps = {},
maxProps = {},
minProps = {},
boxProps = {},
outlierProps = {},
container = false,
containerProps = {},
...restProps
children
}) {
const centerX = left + boxWidth / 2;
const offset = horizontal ? top : left;
const center = offset + boxWidth / 2;
const valueRange = valueScale.range();

const boxplot = {
valueRange,
center,
offset,
boxWidth,
max: {
x1: center - boxWidth / 4,
x2: center + boxWidth / 4,
y1: valueScale(max),
y2: valueScale(max)
},
maxToThird: {
x1: center,
x2: center,
y1: valueScale(max),
y2: valueScale(thirdQuartile)
},
median: {
x1: offset,
x2: offset + boxWidth,
y1: valueScale(median),
y2: valueScale(median)
},
minToFirst: {
x1: center,
x2: center,
y1: valueScale(firstQuartile),
y2: valueScale(min)
},
min: {
x1: center - boxWidth / 4,
x2: center + boxWidth / 4,
y1: valueScale(min),
y2: valueScale(min)
},
box: {
x1: offset,
x2: boxWidth,
y1: valueScale(thirdQuartile),
y2: Math.abs(valueScale(thirdQuartile) - valueScale(firstQuartile))
},
container: {
x1: offset,
x2: boxWidth,
y1: Math.min(...valueRange),
y2: Math.abs(valueRange[0] - valueRange[1])
}
};

if (horizontal) {
boxplot.max = verticalToHorizontal(boxplot.max);
boxplot.maxToThird = verticalToHorizontal(boxplot.maxToThird);
boxplot.box = verticalToHorizontal(boxplot.box);
boxplot.box.y1 = valueScale(firstQuartile);
boxplot.median = verticalToHorizontal(boxplot.median);
boxplot.minToFirst = verticalToHorizontal(boxplot.minToFirst);
boxplot.min = verticalToHorizontal(boxplot.min);
boxplot.container = verticalToHorizontal(boxplot.container);
boxplot.container.y1 = Math.min(...valueRange);
}

if (children) return children(boxplot);

return (
<Group className={classnames('vx-boxplot', className)}>
{outliers.map((d, i) => {
const cx = horizontal ? valueScale(d) : center;
const cy = horizontal ? center : valueScale(d);
return (
<circle
key={`vx-boxplot-outlier-${i}`}
className="vx-boxplot-outlier"
cx={cx}
cy={cy}
r={4}
stroke={stroke}
strokeWidth={strokeWidth}
fill={fill}
fillOpacity={fillOpacity}
{...outlierProps}
/>
);
})}
<line
className="vx-boxplot-max"
x1={centerX - boxWidth / 4}
y1={max}
x2={centerX + boxWidth / 4}
y2={max}
x1={boxplot.max.x1}
y1={boxplot.max.y1}
x2={boxplot.max.x2}
y2={boxplot.max.y2}
stroke={stroke}
strokeWidth={strokeWidth}
{...additionalProps(maxProps, {
data,
max,
x1: centerX - boxWidth / 4,
x2: centerX + boxWidth / 4
})}
{...maxProps}
/>
<line
x1={centerX}
y1={max}
x2={centerX}
y2={thirdQuartile}
className="vx-boxplot-max-to-third"
x1={boxplot.maxToThird.x1}
y1={boxplot.maxToThird.y1}
x2={boxplot.maxToThird.x2}
y2={boxplot.maxToThird.y2}
stroke={stroke}
strokeWidth={strokeWidth}
/>
<rect
x={left}
y={thirdQuartile}
width={boxWidth}
height={firstQuartile - thirdQuartile}
className="vx-boxplot-box"
x={boxplot.box.x1}
y={boxplot.box.y1}
width={boxplot.box.x2}
height={boxplot.box.y2}
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
})}
{...boxProps}
/>
<line
className="vx-boxplot-median"
x1={left}
y1={median}
x2={left + boxWidth}
y2={median}
x1={boxplot.median.x1}
y1={boxplot.median.y1}
x2={boxplot.median.x2}
y2={boxplot.median.y2}
stroke={stroke}
strokeWidth={strokeWidth}
{...additionalProps(medianProps, {
data,
median,
x1: left,
x2: left + boxWidth
})}
{...medianProps}
/>
<line
x1={centerX}
y1={firstQuartile}
x2={centerX}
y2={min}
className="vx-boxplot-min-to-first"
x1={boxplot.minToFirst.x1}
y1={boxplot.minToFirst.y1}
x2={boxplot.minToFirst.x2}
y2={boxplot.minToFirst.y2}
stroke={stroke}
strokeWidth={strokeWidth}
/>
<line
className="vx-boxplot-min"
x1={centerX - boxWidth / 4}
y1={min}
x2={centerX + boxWidth / 4}
y2={min}
x1={boxplot.min.x1}
y1={boxplot.min.y1}
x2={boxplot.min.x2}
y2={boxplot.min.y2}
stroke={stroke}
strokeWidth={strokeWidth}
{...additionalProps(minProps, {
data,
min,
x1: centerX - boxWidth / 4,
x2: centerX + boxWidth / 4
})}
{...minProps}
/>
{container && (
<rect
x={left}
y={max}
width={boxWidth}
height={min - max}
x={boxplot.container.x1}
y={boxplot.container.y1}
width={boxplot.container.x2}
height={boxplot.container.y2}
fillOpacity="0"
{...additionalProps(containerProps, {
data,
x1: left,
x2: left + boxWidth,
median,
max,
min,
thirdQuartile,
firstQuartile
})}
{...containerProps}
/>
)}
</Group>
Expand Down
1 change: 1 addition & 0 deletions packages/vx-boxplot/src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as BoxPlot } from './boxplots/BoxPlot';
export { default as computeStats } from './util/computeStats';
8 changes: 0 additions & 8 deletions packages/vx-boxplot/src/util/additionalProps.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/vx-boxplot/src/util/callOrValue.js

This file was deleted.

Loading