Skip to content

Commit 3c63141

Browse files
committed
Render text onto route trace container
1 parent dcbbc87 commit 3c63141

3 files changed

Lines changed: 43 additions & 18 deletions

File tree

app/charts/route-trace.jsx

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import * as d3 from 'd3';
22

3+
let text = [{
4+
t: 'reverseproxy',
5+
}, {
6+
t: 'books',
7+
}, {
8+
t: 'orders',
9+
}, {
10+
t: 'customers'
11+
}]
312
class RouteTrace {
413
containerEl;
514
props;
615
svg;
7-
16+
17+
// creating D3 container for the nodes
818
constructor(containerEl, props) {
919
this.containerEl = containerEl;
1020
this.props = props;
@@ -17,11 +27,15 @@ class RouteTrace {
1727
this.updateDatapoints();
1828
}
1929

30+
2031
updateDatapoints = () => {
2132
const { svg, props: { data, width, height } } = this;
2233
console.log('data: ', data)
2334
console.log('nodes: ', data[0])
2435
console.log('links: ', data[1])
36+
37+
console.log('1st data point: ', data[0][0])
38+
console.log('4th data point: ', data[0][3])
2539

2640

2741
var simulation = d3.forceSimulation(data[0])
@@ -30,18 +44,32 @@ class RouteTrace {
3044
.force('center', d3.forceCenter(width / 2, height / 2))
3145

3246
const node = svg
33-
.selectAll("circle")
34-
.data(data[0])
35-
.enter()
36-
.append("circle")
47+
.selectAll("circle")
48+
.data(data[0])
49+
.enter()
50+
.append("circle")
51+
52+
// node.select('circle').data(stuff).append("circle").select('text')
53+
// .text(function(d) { return d.id });
54+
55+
const circleAttributes = node
3756
.attr("r", 20)
38-
.attr('cx', () => Math.random() * width)
39-
.attr('cy', () => Math.random() * height)
57+
// .attr('cx', 200)
58+
// .attr('cy', 200)
4059
.style("fill", "#00eda0")
41-
.on('mouseup', (d, i, nodes) => this.setActiveDatapoint(d, nodes[i]));
60+
.on('mouseup', (d, i, nodes) => this.setActiveDatapoint(d, nodes[i]))
61+
62+
const text = svg.selectAll("text")
63+
.data(data[0]).enter().append("text")
64+
65+
const labels = text
66+
.attr("x", d => d.x)
67+
.attr("y", d => d.y)
68+
.attr("dx", 12)
69+
.attr("dy",".35em")
70+
.text(d => d.id);
71+
4272

43-
node.append("title")
44-
.text(function(d) { return d.id; });
4573

4674
const link = svg
4775
.selectAll("line")
@@ -57,7 +85,6 @@ class RouteTrace {
5785
simulation.force('link')
5886
.links(link);
5987

60-
6188
function ticked() {
6289
link
6390
.attr("x1", function(d) { return d.source.x; })
@@ -69,7 +96,6 @@ class RouteTrace {
6996
.attr("cx", function(d) { return d.x; })
7097
.attr("cy", function(d) { return d.y; });
7198
}
72-
7399
}
74100

75101
setActiveDatapoint = (d, node) => {

app/containers/GraphsContainer.jsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const GraphsContainer = (props) => {
1717
const { service } = props;
1818
const initialData = {
1919
nodes: [
20-
{ id1: 'reverse-proxy' },
21-
{ id2: 'books' },
22-
{ id3: 'customers' },
23-
{ id4: 'orders' },
20+
{ id: 'reverse-proxy' },
21+
{ id: 'books' },
22+
{ id: 'customers' },
23+
{ id: 'orders' },
2424
],
2525
links: [
2626
{ source: 'reverse-proxy', target: 'books' },
@@ -60,7 +60,6 @@ const GraphsContainer = (props) => {
6060
return (
6161
<div className="graphsGrid">
6262
<div className='routes'>
63-
<div>{active}</div>
6463
<div ref={canvas} />
6564
</div>
6665
<SpeedChart service={service} />

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@babel/preset-react"
1818
],
1919
"plugins": [
20-
"@babel/plugin-proposal-class-properties"
20+
"@babel/plugin-proposal-class-properties"
2121
]
2222
},
2323
"keywords": [],

0 commit comments

Comments
 (0)