Skip to content

Commit

Permalink
format codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sto3psl committed Apr 21, 2018
1 parent 860e5d9 commit ae02448
Show file tree
Hide file tree
Showing 337 changed files with 4,127 additions and 5,572 deletions.
12 changes: 4 additions & 8 deletions packages/vx-annotation/src/annotations/LinePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,11 @@ export default function LinePathAnnotation({
labelFontSize = 10,
labelStroke = 'white',
labelStrokeWidth = 3,
labelPaintOrder = 'stroke',
labelPaintOrder = 'stroke'
}) {
const endPoint = points[points.length - 1];
return (
<Group
className='vx-line-path-annotation-group'
top={top}
left={left}
>
<Group className="vx-line-path-annotation-group" top={top} left={left}>
<LinePath
className={cx('vx-line-path-annotation', className)}
data={points}
Expand All @@ -62,7 +58,7 @@ export default function LinePathAnnotation({
stroke={stroke}
strokeWidth={strokeWidth}
/>
{label &&
{label && (
<text
x={endPoint.x}
y={endPoint.y}
Expand All @@ -77,7 +73,7 @@ export default function LinePathAnnotation({
>
{label}
</text>
}
)}
</Group>
);
}
87 changes: 47 additions & 40 deletions packages/vx-annotation/test/LinePathAnnotation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,63 @@ import { LinePathAnnotation } from '../src';

describe('<LinePathAnnotation />', () => {
test('it should be defined', () => {
expect(LinePathAnnotation).toBeDefined()
})
expect(LinePathAnnotation).toBeDefined();
});

test('it should be wrapped with defaults <Group top={0} left={0} />', () => {
const wrapper = shallow(<LinePathAnnotation />)
expect(wrapper.prop('top')).toEqual(0)
expect(wrapper.prop('left')).toEqual(0)
expect(wrapper.is('.vx-line-path-annotation-group')).toBe(true)
})
const wrapper = shallow(<LinePathAnnotation />);
expect(wrapper.prop('top')).toEqual(0);
expect(wrapper.prop('left')).toEqual(0);
expect(wrapper.is('.vx-line-path-annotation-group')).toBe(true);
});

test('it should set <Group top= left= /> wrapper props', () => {
const wrapper = shallow(
<LinePathAnnotation
top={20}
left={300}
/>
);
expect(wrapper.prop('top')).toEqual(20)
expect(wrapper.prop('left')).toEqual(300)
})
const wrapper = shallow(<LinePathAnnotation top={20} left={300} />);
expect(wrapper.prop('top')).toEqual(20);
expect(wrapper.prop('left')).toEqual(300);
});

test('it should contain a <LinePath />', () => {
const wrapper = shallow(<LinePathAnnotation />)
expect(wrapper.find('.vx-line-path-annotation').length).toBe(1)
})
const wrapper = shallow(<LinePathAnnotation />);
expect(wrapper.find('.vx-line-path-annotation').length).toBe(1);
});

test('it should pass props to <LinePath />', () => {
const points = [new Point({x: 0, y: 0})];
const wrapper = shallow(
<LinePathAnnotation
className='test'
points={points}
/>
);
const points = [new Point({ x: 0, y: 0 })];
const wrapper = shallow(<LinePathAnnotation className="test" points={points} />);
const linePath = wrapper.find('.vx-line-path-annotation');
expect(linePath.prop('data')).toBe(points)
expect(linePath.prop('stroke')).toEqual('black')
expect(linePath.prop('strokeWidth')).toEqual(1)
expect(linePath.prop('className')).toEqual('vx-line-path-annotation test')
})
expect(linePath.prop('data')).toBe(points);
expect(linePath.prop('stroke')).toEqual('black');
expect(linePath.prop('strokeWidth')).toEqual(1);
expect(linePath.prop('className')).toEqual('vx-line-path-annotation test');
});

test('it should not render a label if label prop is undefined', () => {
const wrapper = shallow(<LinePathAnnotation />)
expect(wrapper.prop('children').filter(c => !!c).length).toBe(1)
})
const wrapper = shallow(<LinePathAnnotation />);
expect(wrapper.prop('children').filter(c => !!c).length).toBe(1);
});

test('it should render a label if label prop is defined', () => {
const points = [new Point({x: 0, y: 0})];
const wrapper = shallow(<LinePathAnnotation label='test' points={points} />)
expect(wrapper.prop('children').filter(c => !!c).length).toBe(2)
expect(wrapper.contains(<text dx={0} dy={0} fill="black" fontSize={10} paintOrder="stroke" stroke="white" strokeWidth={3} textAnchor="middle" x={0} y={0}>test</text>)).toBe(true)
})
})
const points = [new Point({ x: 0, y: 0 })];
const wrapper = shallow(<LinePathAnnotation label="test" points={points} />);
expect(wrapper.prop('children').filter(c => !!c).length).toBe(2);
expect(
wrapper.contains(
<text
dx={0}
dy={0}
fill="black"
fontSize={10}
paintOrder="stroke"
stroke="white"
strokeWidth={3}
textAnchor="middle"
x={0}
y={0}
>
test
</text>
)
).toBe(true);
});
});
2 changes: 1 addition & 1 deletion packages/vx-annotation/test/enzyme-setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });
Enzyme.configure({ adapter: new Adapter() });
85 changes: 29 additions & 56 deletions packages/vx-axis/src/axis/Axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ const propTypes = {
labelProps: PropTypes.object,
left: PropTypes.number,
numTicks: PropTypes.number,
orientation: PropTypes.oneOf([
ORIENT.top,
ORIENT.right,
ORIENT.bottom,
ORIENT.left,
]),
orientation: PropTypes.oneOf([ORIENT.top, ORIENT.right, ORIENT.bottom, ORIENT.left]),
rangePadding: PropTypes.number,
scale: PropTypes.func.isRequired,
stroke: PropTypes.string,
Expand All @@ -42,7 +37,7 @@ const propTypes = {
tickValues: PropTypes.array,
tickComponent: PropTypes.func,
top: PropTypes.number,
children: PropTypes.func,
children: PropTypes.func
};

export default function Axis({
Expand All @@ -59,7 +54,7 @@ export default function Axis({
textAnchor: 'middle',
fontFamily: 'Arial',
fontSize: 10,
fill: 'black',
fill: 'black'
},
left = 0,
numTicks = 10,
Expand All @@ -75,14 +70,14 @@ export default function Axis({
textAnchor: 'middle',
fontFamily: 'Arial',
fontSize: 10,
fill: 'black',
fill: 'black'
}),
tickLength = 8,
tickStroke = 'black',
tickTransform,
tickValues,
tickComponent,
top = 0,
top = 0
}) {
let values = scale.ticks ? scale.ticks(numTicks) : scale.domain();
if (tickValues) values = tickValues;
Expand All @@ -93,34 +88,27 @@ export default function Axis({
const range0 = range[0] + 0.5 - rangePadding;
const range1 = range[range.length - 1] + 0.5 + rangePadding;

const horizontal =
orientation !== ORIENT.left && orientation !== ORIENT.right;
const horizontal = orientation !== ORIENT.left && orientation !== ORIENT.right;
const isLeft = orientation === ORIENT.left;
const isTop = orientation === ORIENT.top;
const tickSign = isLeft || isTop ? -1 : 1;

const position = (scale.bandwidth ? center : identity)(
scale.copy(),
);
const position = (scale.bandwidth ? center : identity)(scale.copy());

const axisFromPoint = new Point({
x: horizontal ? range0 : 0,
y: horizontal ? 0 : range0,
y: horizontal ? 0 : range0
});
const axisToPoint = new Point({
x: horizontal ? range1 : 0,
y: horizontal ? 0 : range1,
y: horizontal ? 0 : range1
});

let tickLabelFontSize = 10; // track the max tick label size to compute label offset

if (!!children) {
return (
<Group
className={cx('vx-axis', axisClassName)}
top={top}
left={left}
>
<Group className={cx('vx-axis', axisClassName)} top={top} left={left}>
{children({
axisFromPoint,
axisToPoint,
Expand All @@ -135,75 +123,60 @@ export default function Axis({
ticks: values.map((value, index) => {
const from = new Point({
x: horizontal ? position(value) : 0,
y: horizontal ? 0 : position(value),
y: horizontal ? 0 : position(value)
});
const to = new Point({
x: horizontal ? position(value) : tickSign * tickLength,
y: horizontal ? tickLength * tickSign : position(value),
y: horizontal ? tickLength * tickSign : position(value)
});
return {
value,
index,
from,
to,
formattedValue: format(value, index),
formattedValue: format(value, index)
};
}),
})
})}
</Group>
);
}

return (
<Group
className={cx('vx-axis', axisClassName)}
top={top}
left={left}
>
<Group className={cx('vx-axis', axisClassName)} top={top} left={left}>
{values.map((val, index) => {
if (hideZero && val === 0) return null;

const tickFromPoint = new Point({
x: horizontal ? position(val) : 0,
y: horizontal ? 0 : position(val),
y: horizontal ? 0 : position(val)
});
const tickToPoint = new Point({
x: horizontal ? position(val) : tickSign * tickLength,
y: horizontal ? tickLength * tickSign : position(val),
y: horizontal ? tickLength * tickSign : position(val)
});

const tickLabelPropsObj = tickLabelProps(val, index);
tickLabelFontSize = Math.max(
tickLabelFontSize,
tickLabelPropsObj.fontSize || 0,
);
tickLabelFontSize = Math.max(tickLabelFontSize, tickLabelPropsObj.fontSize || 0);

return (
<Group
key={`vx-tick-${val}-${index}`}
className={cx('vx-axis-tick', tickClassName)}
transform={tickTransform}
>
{!hideTicks && (
<Line
from={tickFromPoint}
to={tickToPoint}
stroke={tickStroke}
/>
)}
{tickComponent ? tickComponent({
x: tickToPoint.x,
y: tickToPoint.y + (horizontal && !isTop ? tickLabelFontSize : 0),
formattedValue: format(val, index),
...tickLabelPropsObj
}) : (
{!hideTicks && <Line from={tickFromPoint} to={tickToPoint} stroke={tickStroke} />}
{tickComponent ? (
tickComponent({
x: tickToPoint.x,
y: tickToPoint.y + (horizontal && !isTop ? tickLabelFontSize : 0),
formattedValue: format(val, index),
...tickLabelPropsObj
})
) : (
<Text
x={tickToPoint.x}
y={
tickToPoint.y +
(horizontal && !isTop ? tickLabelFontSize : 0)

}
y={tickToPoint.y + (horizontal && !isTop ? tickLabelFontSize : 0)}
{...tickLabelPropsObj}
>
{format(val, index)}
Expand Down Expand Up @@ -233,7 +206,7 @@ export default function Axis({
orientation,
range,
tickLabelFontSize,
tickLength,
tickLength
})}
{...labelProps}
>
Expand Down
6 changes: 3 additions & 3 deletions packages/vx-axis/src/axis/AxisBottom.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const propTypes = {
tickValues: PropTypes.array,
tickComponent: PropTypes.func,
top: PropTypes.number,
children: PropTypes.func,
children: PropTypes.func
};

export default function AxisBottom({
Expand Down Expand Up @@ -58,14 +58,14 @@ export default function AxisBottom({
fill: 'black',
fontFamily: 'Arial',
fontSize: 10,
textAnchor: 'middle',
textAnchor: 'middle'
}),
tickLength = 8,
tickStroke,
tickTransform,
tickValues,
tickComponent,
top,
top
}) {
return (
<Axis
Expand Down
6 changes: 3 additions & 3 deletions packages/vx-axis/src/axis/AxisLeft.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const propTypes = {
tickValues: PropTypes.array,
tickComponent: PropTypes.func,
top: PropTypes.number,
children: PropTypes.func,
children: PropTypes.func
};

export default function AxisLeft({
Expand Down Expand Up @@ -59,14 +59,14 @@ export default function AxisLeft({
fill: 'black',
fontFamily: 'Arial',
fontSize: 10,
textAnchor: 'end',
textAnchor: 'end'
}),
tickLength = 8,
tickStroke,
tickTransform,
tickValues,
tickComponent,
top,
top
}) {
return (
<Axis
Expand Down
Loading

0 comments on commit ae02448

Please sign in to comment.