Skip to content

Commit 165ad15

Browse files
committed
fixed index numbering issue and test failing issue
1 parent e446a4a commit 165ad15

File tree

5 files changed

+85
-315
lines changed

5 files changed

+85
-315
lines changed

src/app/__tests__/mainReducer.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ describe('mainReducer testing', () => {
2323
intervalId: 87,
2424
playing: true,
2525
index: 3,
26-
hierarchy: null, // should be a linked list with four nodes
27-
currLocation: null // should point to the last node in hierarchy
26+
hierarchy: null, // should be a linked list with four nodes
27+
currLocation: null, // should point to the last node in hierarchy
2828
},
2929
75: {
3030
snapshots: [1, 2, 3, 4],

src/app/components/Chart.jsx

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/* eslint-disable eqeqeq */
2+
/* eslint-disable react/prop-types */
3+
/* eslint-disable no-mixed-operators */
4+
/* eslint-disable prefer-template */
5+
/* eslint-disable no-return-assign */
6+
/* eslint-disable prefer-arrow-callback */
7+
/* eslint-disable func-names */
18
/* eslint-disable no-underscore-dangle */
29
/* eslint-disable no-param-reassign */
310
/* eslint-disable no-use-before-define */
@@ -15,6 +22,7 @@ class Chart extends Component {
1522
this.maked3Tree = this.maked3Tree.bind(this);
1623
this.removed3Tree = this.removed3Tree.bind(this);
1724
}
25+
1826
componentDidMount() {
1927
const { hierarchy } = this.props;
2028
root = JSON.parse(JSON.stringify(hierarchy));
@@ -45,115 +53,121 @@ class Chart extends Component {
4553
const width = 600 - margin.right - margin.left;
4654
const height = 700 - margin.top - margin.bottom;
4755

48-
let chartContainer = d3.select(this.chartRef.current)
56+
const chartContainer = d3.select(this.chartRef.current)
4957
.append('svg') // chartContainer is now pointing to svg
5058
.attr('width', width)
5159
.attr('height', height);
5260

53-
let g = chartContainer.append("g")
61+
const g = chartContainer.append('g')
5462
// this is changing where the graph is located physically
55-
.attr("transform", `translate(${width / 2 + 4}, ${height / 2 + 2})`);
63+
.attr('transform', `translate(${width / 2 + 4}, ${height / 2 + 2})`);
5664

57-
// if we consider the container for our radial node graph as a box encapsulating, half of this container width is essentially the radius of our radial node graph
58-
let radius = width / 2;
65+
// if we consider the container for our radial node graph as a box encapsulating
66+
// half of this container width is essentially the radius of our radial node graph
67+
const radius = width / 2;
5968

60-
// d3.hierarchy constructs a root node from the specified hierarchical data (our object titled dataset), which must be an object representing the root node
61-
let hierarchy = d3.hierarchy(root);
69+
// d3.hierarchy constructs a root node from the specified hierarchical data
70+
// (our object titled dataset), which must be an object representing the root node
71+
const hierarchy = d3.hierarchy(root);
6272

63-
let tree = d3.tree()
73+
const tree = d3.tree()
6474
// this assigns width of tree to be 2pi
6575
.size([2 * Math.PI, radius / 1.3])
66-
.separation(function (a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth });
76+
.separation(function (a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth; });
6777

68-
let d3root = tree(hierarchy);
78+
const d3root = tree(hierarchy);
6979

7080
g.selectAll('.link')
71-
// root.links() gets an array of all the links, where each element is an object containing a source property, which represents the link's source node, and a target property, which represents the link's target node.
81+
// root.links() gets an array of all the links,
82+
// where each element is an object containing a
83+
// source property, which represents the link's source node,
84+
// and a target property, which represents the link's target node.
7285
.data(d3root.links())
7386
.enter()
7487
.append('path')
7588
.attr('class', 'link')
76-
.attr("d", d3.linkRadial()
89+
.attr('d', d3.linkRadial()
7790
.angle(d => d.x)
7891
.radius(d => d.y));
7992

80-
let node = g.selectAll(".node")
93+
const node = g.selectAll('.node')
8194
// root.descendants gets an array of of all nodes
8295
.data(d3root.descendants())
8396
.enter()
84-
.append("g")
97+
.append('g')
8598
// assigning class to the node based on whether node has children or not
86-
.attr("class", function (d) {
87-
return "node" + (d.children ? " node--internal" : " node--leaf")
99+
.attr('class', function (d) {
100+
return 'node' + (d.children ? ' node--internal' : ' node--leaf');
88101
})
89-
.attr("transform", function (d) {
90-
return "translate(" + reinfeldTidierAlgo(d.x, d.y) + ")";
102+
.attr('transform', function (d) {
103+
return 'translate(' + reinfeldTidierAlgo(d.x, d.y) + ')';
91104
});
92105

93-
node.append("circle")
94-
.attr("r", 10)
106+
node.append('circle')
107+
.attr('r', 10);
108+
109+
// creating a d3.tip method where the html has a function that returns
110+
// the data we passed into tip.show from line 120
111+
const tip = d3Tip()
112+
.attr('class', 'd3-tip')
113+
.html(function (d) { return 'State: ' + d; });
95114

96-
//creating a d3.tip method where the html has a function that returns the data we passed into tip.show from line 120
97-
let tip = d3Tip()
98-
.attr("class", "d3-tip")
99-
.html(function (d) { return "State: " + d; })
100-
101-
//invoking tooltip for nodes
102-
node.call(tip)
115+
// invoking tooltip for nodes
116+
node.call(tip);
103117

104118
node
105-
.append("text")
119+
.append('text')
106120
// adjusts the y coordinates for the node text
107-
.attr("dy", "0.35em")
108-
.attr("x", function (d) {
121+
.attr('dy', '0.35em')
122+
.attr('x', function (d) {
109123
// this positions how far the text is from leaf nodes (ones without children)
110-
// negative number before the colon moves the text of rightside nodes, positive number moves the text for the leftside nodes
124+
// negative number before the colon moves the text of rightside nodes,
125+
// positive number moves the text for the leftside nodes
111126
return d.x < Math.PI === !d.children ? -4 : 5;
112127
})
113-
.attr("text-anchor", function (d) { return d.x < Math.PI === !d.children ? "start" : "end"; })
128+
.attr('text-anchor', function (d) { return d.x < Math.PI === !d.children ? 'start' : 'end'; })
114129
// this arranges the angle of the text
115-
.attr("transform", function (d) { return "rotate(" + (d.x < Math.PI ? d.x - Math.PI / 2 : d.x + Math.PI / 2) * 1 / Math.PI + ")"; })
130+
.attr('transform', function (d) { return 'rotate(' + (d.x < Math.PI ? d.x - Math.PI / 2 : d.x + Math.PI / 2) * 1 / Math.PI + ')'; })
116131
.text(function (d) {
117132
return d.data.index;
118133
});
119-
120-
// allows svg to be dragged around
134+
135+
// allows svg to be dragged around
121136
node.call(d3.drag()
122-
.on("start", dragstarted)
123-
.on("drag", dragged)
124-
.on("end", dragended));
137+
.on('start', dragstarted)
138+
.on('drag', dragged)
139+
.on('end', dragended));
125140

126141
chartContainer.call(d3.zoom()
127142
.extent([[0, 0], [width, height]])
128143
.scaleExtent([1, 8])
129-
.on("zoom", zoomed));
144+
.on('zoom', zoomed));
130145

131146
function dragstarted() {
132147
d3.select(this).raise();
133-
g.attr("cursor", "grabbing");
148+
g.attr('cursor', 'grabbing');
134149
}
135150

136151
function dragged(d) {
137-
d3.select(this).attr("dx", d.x = d3.event.x).attr("dy", d.y = d3.event.y);
152+
d3.select(this).attr('dx', d.x = d3.event.x).attr('dy', d.y = d3.event.y);
138153
}
139154

140155
function dragended() {
141-
g.attr("cursor", "grab");
156+
g.attr('cursor', 'grab');
142157
}
143158

144159
function zoomed() {
145-
g.attr("transform", d3.event.transform);
160+
g.attr('transform', d3.event.transform);
146161
}
147-
148-
//applying tooltip on mouseover and removes it when mouse cursor moves away
162+
163+
// applying tooltip on mouseover and removes it when mouse cursor moves away
149164
node
150165
.on('mouseover', function (d) {
151166
// without JSON.stringify, data will display as object Object
152167
// console.log('d.data --> ', JSON.stringify(d.data))
153-
let displayedState;
154-
tip.show(JSON.stringify(d.data.stateSnapshot.children[0].state), this)
168+
tip.show(JSON.stringify(d.data.stateSnapshot.children[0].state), this);
155169
})
156-
.on('mouseout', tip.hide)
170+
.on('mouseout', tip.hide);
157171

158172
function reinfeldTidierAlgo(x, y) {
159173
return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];

0 commit comments

Comments
 (0)