data instaed of colors

This commit is contained in:
Mahdi Dibaiee
2015-07-26 13:23:28 +04:30
parent bcd52f354a
commit ca572e392e
6 changed files with 69 additions and 38 deletions

View File

@ -1,17 +0,0 @@
let data = new Trie();
data.add('colors');
data.add('coffee');
data.add('codecs');
data.add('boo');
data.add('boloss');
data.add('badass');
data.add('rebecca');
data.add('robots');
data.add('rio');
document.addEventListener('DOMContentLoaded', () => {
draw();
});

View File

@ -3,9 +3,9 @@
</head>
<body>
<script src='../build/libs/d3.js'></script>
<script src='../build/trie.js'></script>
<script src='../build/demo/draw.js'></script>
<script src='../build/demo/colors.js'></script>
<script src='../build/demo/data.js'></script>
</body>

22
demo/data.js Normal file
View File

@ -0,0 +1,22 @@
let data = new Trie();
let json = {
"color": ["red", "rebecca", "blue", "cyan", "pink", "purple",
"teal", "black", "white", "orange", "yellow", "green"],
"name": ["Jack", "James", "Alex", "Adam", "Mahdi", "Josh", "Scott",
"Pat", "Vincent", "Daniel", "Patrick", "Tim"],
"app": ["Atom", "Sublime", "Firefox", "Chrome", "Safari", "Mail",
"Blender", "Sketch", "Slack", "Finder", "Nightly", "Aurora",
"f.lux", "LookUp", "WunderList", "Instagram", "Toggl"]
};
for (let category in json) {
for (let item of json[category]) {
let node = data.add(item);
node.category = category;
}
}
document.addEventListener('DOMContentLoaded', () => {
draw(true);
});

View File

@ -12,7 +12,7 @@ svg.append('g').attr('class', 'lines');
let tree = d3.layout.tree()
.size([WIDTH - MARGIN, HEIGHT - MARGIN]);
function draw() {
function draw(small) {
let nodes = tree.nodes(data.root);
let links = tree.links(nodes);
@ -33,22 +33,22 @@ function draw() {
nodeElements.attr('transform', d => `translate(${d.x}, ${d.y})`)
.style('font-family', 'monospace')
.style('font-size', '11px')
.style('font-size', (small ? '6' : '11') + 'px')
.attr('data-word', d => d.name);
nodesEnter.append('circle');
let circles = nodeElements.selectAll('circle');
circles.attr('r', 25)
circles.attr('r', small ? 15 : 25)
.style('fill', 'rgb(28, 236, 166)')
.style('stroke', 'rgb(17, 172, 144)')
.style('fill', 'rgb(28, 236, 166)')
.style('stroke', 'rgb(17, 172, 144)')
.attr('r', 10)
.attr('r', small ? 5 : 10)
.transition()
.ease(d3.ease('elastic'))
.duration(700)
.attr('r', 25);
.attr('r', small ? 15 : 25);
nodesEnter.append('text');