Skip to content

Commit 68ac085

Browse files
committed
changing node color and text color
1 parent edf894a commit 68ac085

File tree

2 files changed

+56
-41
lines changed

2 files changed

+56
-41
lines changed

src/components/Sidebar.svelte

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@
1818
</script>
1919

2020
<main>
21-
<h1>See your component structure below!</h1>
22-
{#if componentStructure.length > 0}
23-
<Tree {componentStructure}/>
24-
{/if}
21+
<!-- <div class="background"> -->
22+
<h1>See your component structure below!</h1>
23+
{#if componentStructure.length > 0}
24+
<Tree {componentStructure}/>
25+
{/if}
26+
<!-- </div> -->
2527
</main>
2628

2729
<style>
30+
2831
h1 {
29-
color: red;
32+
color: #e3ae52;
3033
text-align: center;
3134
}
3235
</style>

src/components/Tree.svelte

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,91 @@
11
<script>
2-
import { onMount } from 'svelte';
3-
import * as d3 from 'd3';
2+
import { onMount } from "svelte";
3+
import * as d3 from "d3";
44
55
export let componentStructure;
6+
// let containerHeight = 0;
7+
// let containerWidth = 0;
8+
// document.addEventListener("DOMContentLoaded", () => {
9+
// containerWidth = document.getElementById("tree-container").offsetWidth;
10+
// containerHeight = document.getElementById("tree-container").offsetHeight;
11+
// console.log("container: ", containerWidth);
12+
// });
613
714
onMount(() => {
815
let height = 2000;
916
let width = 2000;
1017
18+
let containerWidth = document.getElementById("tree-container").offsetWidth;
19+
let containerHeight =
20+
document.getElementById("tree-container").offsetHeight;
21+
1122
let window = d3
12-
.select('#tree-container')
13-
.append('svg')
14-
.attr('height', height)
15-
.attr('width', width)
16-
.append('g')
17-
.attr('transform', 'translate(50,50)');
23+
.select("#tree-container")
24+
.append("svg")
25+
.attr("height", containerHeight)
26+
.attr("width", containerWidth)
27+
.append("g")
28+
.attr("transform", "translate(50,50)");
1829
1930
const root = d3.hierarchy(componentStructure[0]);
20-
//const roots = d3.hierarchy(root);
21-
// console.log(componentStructure[0]);
22-
// console.log(root);
2331
2432
// console.log('root test', root.data);
25-
const tree = d3.tree().size([height / 4, width / 4]);
26-
27-
//console.log('hello');
28-
// console.log(componentStructure);
29-
// console.log(componentStructure[0]);
33+
const tree = d3.tree().size([containerHeight / 4, containerWidth / 4]);
3034
3135
const treeDataTransformed = tree(root);
3236
3337
let nodes = treeDataTransformed.descendants();
34-
console.log('nodes', nodes);
35-
//console.log(nodes);
3638
let links = treeDataTransformed.links();
37-
//console.log(links);
3839
3940
let node = window
40-
.selectAll('.node')
41+
.selectAll(".node")
4142
.data(nodes)
4243
.enter()
43-
.append('g')
44-
.attr('class', 'node')
45-
.attr('transform', function (d) {
44+
.append("g")
45+
.attr("class", "node")
46+
.attr("transform", function (d) {
4647
//console.log('d', d);
4748
// console.log(typeof d);
48-
return 'translate(' + d.x + ',' + d.y + ')';
49+
return "translate(" + d.x + "," + d.y + ")";
4950
});
5051
51-
node.append('circle').attr('r', 15).attr('fill', '#ff0000');
52+
node.append("circle").attr("r", 15).attr("fill", "#e3ae52");
5253
5354
// console.log(root);
5455
55-
node.append('text').text(function (d) {
56-
//console.log(d.data.name);
57-
return d.data.name;
58-
});
56+
node
57+
.append("text")
58+
.text(function (d) {
59+
//console.log(d.data.name);
60+
return d.data.name;
61+
})
62+
.style("fill", "antiquewhite")
63+
.attr("dy", "2em") // Move text down
64+
.attr("text-anchor", "middle");
5965
6066
let diagonal = d3
6167
.linkVertical()
6268
.x((d) => d.x)
6369
.y((d) => d.y);
6470
6571
window
66-
.selectAll('.link')
72+
.selectAll(".link")
6773
.data(links)
6874
.enter()
69-
.append('path')
70-
.attr('class', 'link')
71-
.attr('fill', 'none')
72-
.attr('stroke', '#fff')
73-
.attr('stroke-width', 1)
74-
.attr('d', diagonal);
75+
.append("path")
76+
.attr("class", "link")
77+
.attr("fill", "none")
78+
.attr("stroke", "#fff")
79+
.attr("stroke-width", 1)
80+
.attr("d", diagonal);
7581
});
7682
</script>
7783

7884
<div id="tree-container"></div>
7985

86+
<style>
87+
#tree-container {
88+
width: 100%;
89+
height: 100%;
90+
}
91+
</style>

0 commit comments

Comments
 (0)