Skip to content

Commit f73bf8e

Browse files
committed
Initial prettier run-through of src
1 parent 15c4d35 commit f73bf8e

File tree

9 files changed

+285
-377
lines changed

9 files changed

+285
-377
lines changed

src/Link/index.js

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { svg, select } from 'd3';
55
import './style.css';
66

77
export default class Link extends React.PureComponent {
8-
98
constructor(props) {
109
super(props);
1110
this.state = {
@@ -27,23 +26,27 @@ export default class Link extends React.PureComponent {
2726
const { transitionDuration } = this.props;
2827

2928
select(this.link)
30-
.transition()
31-
.duration(transitionDuration)
32-
.style('opacity', opacity)
33-
.each('end', done);
29+
.transition()
30+
.duration(transitionDuration)
31+
.style('opacity', opacity)
32+
.each('end', done);
3433
}
3534

3635
diagonalPath(linkData, orientation) {
37-
const diagonal = svg.diagonal().projection((d) =>
38-
orientation === 'horizontal' ? [d.y, d.x] : [d.x, d.y]
39-
);
36+
const diagonal = svg
37+
.diagonal()
38+
.projection(
39+
d => (orientation === 'horizontal' ? [d.y, d.x] : [d.x, d.y]),
40+
);
4041
return diagonal(linkData);
4142
}
4243

4344
straightPath(linkData, orientation) {
44-
const straight = svg.line().interpolate('basis')
45-
.x((d) => d.x)
46-
.y((d) => d.y);
45+
const straight = svg
46+
.line()
47+
.interpolate('basis')
48+
.x(d => d.x)
49+
.y(d => d.y);
4750

4851
let data = [
4952
{ x: linkData.source.x, y: linkData.source.y },
@@ -61,9 +64,9 @@ export default class Link extends React.PureComponent {
6164
}
6265

6366
elbowPath(d, orientation) {
64-
return orientation === 'horizontal' ?
65-
`M${d.source.y},${d.source.x}V${d.target.x}H${d.target.y}` :
66-
`M${d.source.x},${d.source.y}V${d.target.y}H${d.target.x}`;
67+
return orientation === 'horizontal'
68+
? `M${d.source.y},${d.source.x}V${d.target.x}H${d.target.y}`
69+
: `M${d.source.x},${d.source.y}V${d.target.y}H${d.target.x}`;
6770
}
6871

6972
drawPath() {
@@ -84,7 +87,9 @@ export default class Link extends React.PureComponent {
8487
const { styles } = this.props;
8588
return (
8689
<path
87-
ref={(l) => { this.link = l; }}
90+
ref={l => {
91+
this.link = l;
92+
}}
8893
style={{ ...this.state.initialStyle, ...styles }}
8994
className="linkBase"
9095
d={this.drawPath()}
@@ -99,15 +104,8 @@ Link.defaultProps = {
99104

100105
Link.propTypes = {
101106
linkData: PropTypes.object.isRequired,
102-
orientation: PropTypes.oneOf([
103-
'horizontal',
104-
'vertical',
105-
]).isRequired,
106-
pathFunc: PropTypes.oneOf([
107-
'diagonal',
108-
'elbow',
109-
'straight',
110-
]).isRequired,
107+
orientation: PropTypes.oneOf(['horizontal', 'vertical']).isRequired,
108+
pathFunc: PropTypes.oneOf(['diagonal', 'elbow', 'straight']).isRequired,
111109
transitionDuration: PropTypes.number.isRequired,
112110
styles: PropTypes.object,
113111
};

src/Link/tests/index.test.js

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ describe('<Link />', () => {
2424
styles: {},
2525
};
2626

27-
2827
jest.spyOn(Link.prototype, 'drawPath');
2928
jest.spyOn(Link.prototype, 'diagonalPath');
3029
jest.spyOn(Link.prototype, 'elbowPath');
@@ -34,45 +33,25 @@ describe('<Link />', () => {
3433
// Clear method spies on prototype after each test
3534
afterEach(() => jest.clearAllMocks());
3635

37-
3836
it('applies the base className', () => {
39-
const renderedComponent = shallow(
40-
<Link {...mockProps} />
41-
);
37+
const renderedComponent = shallow(<Link {...mockProps} />);
4238

4339
expect(renderedComponent.prop('className')).toBe('linkBase');
4440
});
4541

46-
4742
it('applies `props.styles` when defined', () => {
4843
const initialStyle = { opacity: 0 }; // state.initialStyle
4944
const fixture = { ...initialStyle, stroke: '#777', strokeWidth: 2 };
50-
const renderedComponent = shallow(
51-
<Link
52-
{...mockProps}
53-
styles={fixture}
54-
/>
55-
);
45+
const renderedComponent = shallow(<Link {...mockProps} styles={fixture} />);
5646

5747
expect(renderedComponent.prop('style')).toEqual(fixture);
5848
});
5949

60-
6150
it('calls the appropriate path func based on `props.pathFunc`', () => {
62-
const diagonalComponent = shallow(
63-
<Link {...mockProps} />
64-
);
65-
const elbowComponent = shallow(
66-
<Link
67-
{...mockProps}
68-
pathFunc="elbow"
69-
/>
70-
);
51+
const diagonalComponent = shallow(<Link {...mockProps} />);
52+
const elbowComponent = shallow(<Link {...mockProps} pathFunc="elbow" />);
7153
const straightComponent = shallow(
72-
<Link
73-
{...mockProps}
74-
pathFunc="straight"
75-
/>
54+
<Link {...mockProps} pathFunc="straight" />,
7655
);
7756

7857
expect(diagonalComponent.instance().diagonalPath).toHaveBeenCalled();
@@ -81,33 +60,34 @@ describe('<Link />', () => {
8160
expect(Link.prototype.drawPath).toHaveBeenCalledTimes(3);
8261
});
8362

84-
8563
it('returns an appropriate elbowPath according to `props.orientation`', () => {
86-
expect(
87-
Link.prototype.elbowPath(linkData, 'horizontal')
88-
).toBe(`M${linkData.source.y},${linkData.source.x}V${linkData.target.x}H${linkData.target.y}`);
89-
expect(
90-
Link.prototype.elbowPath(linkData, 'vertical')
91-
).toBe(`M${linkData.source.x},${linkData.source.y}V${linkData.target.y}H${linkData.target.x}`);
64+
expect(Link.prototype.elbowPath(linkData, 'horizontal')).toBe(
65+
`M${linkData.source.y},${linkData.source.x}V${linkData.target
66+
.x}H${linkData.target.y}`,
67+
);
68+
expect(Link.prototype.elbowPath(linkData, 'vertical')).toBe(
69+
`M${linkData.source.x},${linkData.source.y}V${linkData.target
70+
.y}H${linkData.target.x}`,
71+
);
9272
});
9373

94-
9574
it('returns an appropriate straightPath according to `props.orientation`', () => {
96-
expect(
97-
Link.prototype.straightPath(linkData, 'horizontal')
98-
).toBe(`M${linkData.source.y},${linkData.source.x}L${linkData.target.y},${linkData.target.x}`);
99-
expect(
100-
Link.prototype.straightPath(linkData, 'vertical')
101-
).toBe(`M${linkData.source.x},${linkData.source.y}L${linkData.target.x},${linkData.target.y}`);
75+
expect(Link.prototype.straightPath(linkData, 'horizontal')).toBe(
76+
`M${linkData.source.y},${linkData.source.x}L${linkData.target
77+
.y},${linkData.target.x}`,
78+
);
79+
expect(Link.prototype.straightPath(linkData, 'vertical')).toBe(
80+
`M${linkData.source.x},${linkData.source.y}L${linkData.target
81+
.x},${linkData.target.y}`,
82+
);
10283
});
10384

104-
10585
it('fades in once it has been mounted', () => {
10686
const fixture = 1;
107-
const renderedComponent = mount(
108-
<Link {...mockProps} />
109-
);
87+
const renderedComponent = mount(<Link {...mockProps} />);
11088

111-
expect(renderedComponent.instance().applyOpacity).toHaveBeenCalledWith(fixture);
89+
expect(renderedComponent.instance().applyOpacity).toHaveBeenCalledWith(
90+
fixture,
91+
);
11292
});
11393
});

src/Node/index.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { select } from 'd3';
66
import './style.css';
77

88
export default class Node extends React.Component {
9-
109
constructor(props) {
1110
super(props);
1211
const { parent } = props.nodeData;
@@ -31,25 +30,28 @@ export default class Node extends React.Component {
3130
}
3231

3332
componentWillUpdate(nextProps) {
34-
const transform = this.setTransformOrientation(nextProps.nodeData.x, nextProps.nodeData.y);
33+
const transform = this.setTransformOrientation(
34+
nextProps.nodeData.x,
35+
nextProps.nodeData.y,
36+
);
3537
this.applyTransform(transform);
3638
}
3739

3840
setTransformOrientation(x, y) {
39-
return this.props.orientation === 'horizontal' ?
40-
`translate(${y},${x})` :
41-
`translate(${x},${y})`;
41+
return this.props.orientation === 'horizontal'
42+
? `translate(${y},${x})`
43+
: `translate(${x},${y})`;
4244
}
4345

4446
applyTransform(transform, opacity = 1, done = () => {}) {
4547
const { transitionDuration } = this.props;
4648

4749
select(this.node)
48-
.transition()
49-
.duration(transitionDuration)
50-
.attr('transform', transform)
51-
.style('opacity', opacity)
52-
.each('end', done);
50+
.transition()
51+
.duration(transitionDuration)
52+
.attr('transform', transform)
53+
.style('opacity', opacity)
54+
.each('end', done);
5355
}
5456

5557
handleClick() {
@@ -67,11 +69,15 @@ export default class Node extends React.Component {
6769

6870
render() {
6971
const { nodeData, styles } = this.props;
70-
const nodeStyle = nodeData._children ? { ...styles.node } : { ...styles.leafNode };
72+
const nodeStyle = nodeData._children
73+
? { ...styles.node }
74+
: { ...styles.leafNode };
7175
return (
7276
<g
7377
id={nodeData.id}
74-
ref={(n) => { this.node = n; }}
78+
ref={n => {
79+
this.node = n;
80+
}}
7581
style={this.state.initialStyle}
7682
className={nodeData._children ? 'nodeBase' : 'leafNodeBase'}
7783
transform={this.state.transform}
@@ -88,25 +94,20 @@ export default class Node extends React.Component {
8894
{this.props.name}
8995
</text>
9096

91-
<circle
92-
r={this.props.circleRadius}
93-
style={nodeStyle.circle}
94-
/>
97+
<circle r={this.props.circleRadius} style={nodeStyle.circle} />
9598

9699
<text
97100
className="nodeAttributesBase"
98101
y="0"
99102
textAnchor={this.props.textAnchor}
100103
style={nodeStyle.attributes}
101104
>
102-
{
103-
this.props.attributes &&
104-
Object.keys(this.props.attributes).map((labelKey) =>
105+
{this.props.attributes &&
106+
Object.keys(this.props.attributes).map(labelKey => (
105107
<tspan x="10" dy="1.2em" key={uuid.v4()}>
106108
{labelKey}: {this.props.attributes[labelKey]}
107109
</tspan>
108-
)
109-
}
110+
))}
110111
</text>
111112
</g>
112113
);
@@ -132,10 +133,7 @@ Node.defaultProps = {
132133

133134
Node.propTypes = {
134135
nodeData: PropTypes.object.isRequired,
135-
orientation: PropTypes.oneOf([
136-
'horizontal',
137-
'vertical',
138-
]).isRequired,
136+
orientation: PropTypes.oneOf(['horizontal', 'vertical']).isRequired,
139137
transitionDuration: PropTypes.number.isRequired,
140138
onClick: PropTypes.func.isRequired,
141139
name: PropTypes.string.isRequired,

0 commit comments

Comments
 (0)