Skip to content

Commit a12e83a

Browse files
authored
Merge pull request #135 from open-source-labs/d3-implementation
got rid of d3-tip
2 parents ccff073 + 72e7ad9 commit a12e83a

File tree

7 files changed

+63
-33
lines changed

7 files changed

+63
-33
lines changed

.eslintrc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"root": true,
44
"plugins": ["jest", "react"],
55
"rules": {
6-
"arrow-parens": [2, "as-needed"]
6+
"arrow-parens": [2, "as-needed"],
7+
"import/no-unresolved": "off",
8+
"import/extensions": "off"
79
},
810
"env": {
911
"es6": true,
@@ -22,8 +24,5 @@
2224
},
2325
"ecmaVersion": 2018,
2426
"sourceType": "module"
25-
},
26-
"settings": {
27-
"import/no-unresolved": "off"
2827
}
2928
}

src/app/__tests__/action.test.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/jsx-props-no-spreading */
12
import React from 'react';
23
import { configure, shallow } from 'enzyme';
34
import Adapter from 'enzyme-adapter-react-16';

src/app/__tests__/dropdown.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/jsx-props-no-spreading */
12
/* eslint-disable react/jsx-filename-extension */
23
import React from 'react';
34
import { configure, shallow } from 'enzyme';

src/app/components/Chart.jsx

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import React, { Component } from 'react';
1313
// import PropTypes from 'prop-types';
1414
import * as d3 from 'd3';
15-
import d3Tip from 'd3-tip';
15+
// import d3Tip from 'd3-tip';
1616

1717
let root = {};
1818
class Chart extends Component {
@@ -78,10 +78,10 @@ class Chart extends Component {
7878
const d3root = tree(hierarchy);
7979

8080
g.selectAll('.link')
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.
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.
8585
.data(d3root.links())
8686
.enter()
8787
.append('path')
@@ -104,21 +104,36 @@ class Chart extends Component {
104104
});
105105

106106
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; });
114-
115-
// invoking tooltip for nodes
116-
node.call(tip);
117-
107+
.attr('r', 10)
108+
.on('mouseover', function (d) {
109+
d3.select(this)
110+
.transition(100)
111+
.duration(20)
112+
.attr('r', 20);
113+
114+
tooltipDiv.transition()
115+
.duration(200)
116+
.style('opacity', 0.9);
117+
118+
tooltipDiv.html(JSON.stringify(d.data.stateSnapshot.children[0].state), this)
119+
.style('left', (d3.event.pageX) + 'px')
120+
.style('top', (d3.event.pageY - 28) + 'px');
121+
})
122+
// eslint-disable-next-line no-unused-vars
123+
.on('mouseout', function (d) {
124+
d3.select(this)
125+
.transition()
126+
.duration(200)
127+
.attr('r', 12);
128+
129+
tooltipDiv.transition()
130+
.duration(500)
131+
.style('opacity', 0);
132+
});
118133
node
119134
.append('text')
120135
// adjusts the y coordinates for the node text
121-
.attr('dy', '0.35em')
136+
.attr('dy', '-1.5em')
122137
.attr('x', function (d) {
123138
// this positions how far the text is from leaf nodes (ones without children)
124139
// negative number before the colon moves the text of rightside nodes,
@@ -160,14 +175,12 @@ class Chart extends Component {
160175
g.attr('transform', d3.event.transform);
161176
}
162177

178+
// define the div for the tooltip
179+
const tooltipDiv = d3.select('body').append('div')
180+
.attr('class', 'tooltip')
181+
.style('opacity', 0);
182+
163183
// applying tooltip on mouseover and removes it when mouse cursor moves away
164-
node
165-
.on('mouseover', function (d) {
166-
// without JSON.stringify, data will display as object Object
167-
// console.log('d.data --> ', JSON.stringify(d.data))
168-
tip.show(JSON.stringify(d.data.stateSnapshot.children[0].state), this);
169-
})
170-
.on('mouseout', tip.hide);
171184

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

src/app/components/MainSlider.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/jsx-props-no-spreading */
12
/* eslint-disable react/prop-types */
23

34
import React from 'react';

src/app/styles/components/d3graph.css

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,22 @@ body {
4343
stroke-width: 5px;
4444
}
4545

46-
.d3-tip {
46+
div.tooltip {
47+
position: absolute;
48+
text-align: center;
49+
display: inline;
50+
max-width: 250px;
51+
overflow-wrap: break-word;
52+
padding: 6px;
53+
color: #320a5c;
54+
font-size: 12px;
55+
font-family: "Overpass Mono", monospace;
56+
background: #9cf4df;
57+
border-radius: 8px;
58+
pointer-events: none;
59+
}
60+
61+
/* .d3-tip {
4762
line-height: 1;
4863
padding: 6px;
4964
background: #9cf4df;
@@ -53,7 +68,7 @@ body {
5368
max-width: 400px;
5469
overflow-wrap: break-word;
5570
font-family: "Overpass Mono", monospace;
56-
}
71+
} */
5772

5873
/* Creates a small triangle extender for the tooltip
5974
.d3-tip:after {
@@ -68,8 +83,8 @@ body {
6883
} */
6984

7085
/* Style northward tooltips specifically */
71-
.d3-tip.n:after {
86+
/* .d3-tip.n:after {
7287
margin: -2px 0 0 0;
7388
top: 100%;
7489
left: 0;
75-
}
90+
} */

src/extension/build/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Reactime",
3-
"version": "3.0",
3+
"version": "3.1",
44
"devtools_page": "devtools.html",
55
"description": "A Chrome extension that helps debug state in React applications by memorizing the state of components with every render.",
66
"manifest_version": 2,

0 commit comments

Comments
 (0)