fix: it should be value
and not name
This commit is contained in:
parent
63a70a4e94
commit
97ec628663
@ -56,7 +56,7 @@ function keyup() {
|
|||||||
|
|
||||||
var category = node.category ? "- " + node.category : '';
|
var category = node.category ? "- " + node.category : '';
|
||||||
|
|
||||||
results.innerHTML += "<li>" + node.name + " " + category + "</li>";
|
results.innerHTML += "<li>" + node.value + " " + category + "</li>";
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_didIteratorError2 = true;
|
_didIteratorError2 = true;
|
||||||
|
@ -47,7 +47,7 @@ input.addEventListener('keydown', function (e) {
|
|||||||
|
|
||||||
if (!current.children.length) return;
|
if (!current.children.length) return;
|
||||||
|
|
||||||
input.value = current.children[0].name;
|
input.value = current.children[0].value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ function keyup() {
|
|||||||
|
|
||||||
var category = node.category ? "- " + node.category : '';
|
var category = node.category ? "- " + node.category : '';
|
||||||
|
|
||||||
results.innerHTML += "<li>" + node.name + " " + category + "</li>";
|
results.innerHTML += "<li>" + node.value + " " + category + "</li>";
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_didIteratorError2 = true;
|
_didIteratorError2 = true;
|
||||||
|
@ -35,7 +35,7 @@ function draw(small) {
|
|||||||
nodeElements.attr('transform', function (d) {
|
nodeElements.attr('transform', function (d) {
|
||||||
return 'translate(' + d.x + ', ' + d.y + ')';
|
return 'translate(' + d.x + ', ' + d.y + ')';
|
||||||
}).style('font-family', 'monospace').style('font-size', (small ? '6' : '11') + 'px').attr('data-word', function (d) {
|
}).style('font-family', 'monospace').style('font-size', (small ? '6' : '11') + 'px').attr('data-word', function (d) {
|
||||||
return d.name;
|
return d.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
nodesEnter.append('circle');
|
nodesEnter.append('circle');
|
||||||
@ -47,6 +47,6 @@ function draw(small) {
|
|||||||
var texts = svg.selectAll('g.node text').data(nodes);
|
var texts = svg.selectAll('g.node text').data(nodes);
|
||||||
|
|
||||||
texts.attr('dy', 5).html(function (d) {
|
texts.attr('dy', 5).html(function (d) {
|
||||||
return '<tspan>' + d.name.split('').join('</tspan><tspan>') + '</tspan>';
|
return '<tspan>' + d.value.split('').join('</tspan><tspan>') + '</tspan>';
|
||||||
}).attr('text-anchor', 'middle').style('fill', 'white');
|
}).attr('text-anchor', 'middle').style('fill', 'white');
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ var Node = function Node(value, parent) {
|
|||||||
|
|
||||||
_classCallCheck(this, Node);
|
_classCallCheck(this, Node);
|
||||||
|
|
||||||
this.name = value;
|
this.value = value;
|
||||||
this.children = [];
|
this.children = [];
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
};
|
};
|
||||||
@ -29,11 +29,11 @@ var Trie = (function () {
|
|||||||
var _loop = function (i, len) {
|
var _loop = function (i, len) {
|
||||||
if (!parent.children) parent.children = [];
|
if (!parent.children) parent.children = [];
|
||||||
var node = parent.children.find(function (child) {
|
var node = parent.children.find(function (child) {
|
||||||
return child.name[i] === value[i];
|
return child.value[i] === value[i];
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
node = new Node(value.slice(0, i + 1), parent.name);
|
node = new Node(value.slice(0, i + 1), parent.value);
|
||||||
parent.children.push(node);
|
parent.children.push(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ var Trie = (function () {
|
|||||||
|
|
||||||
var _loop2 = function (i, len) {
|
var _loop2 = function (i, len) {
|
||||||
parent = parent.children.find(function (child) {
|
parent = parent.children.find(function (child) {
|
||||||
return child.name[i] === value[i];
|
return child.value[i] === value[i];
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!parent) return {
|
if (!parent) return {
|
||||||
|
@ -34,7 +34,7 @@ function draw(small) {
|
|||||||
nodeElements.attr('transform', d => `translate(${d.x}, ${d.y})`)
|
nodeElements.attr('transform', d => `translate(${d.x}, ${d.y})`)
|
||||||
.style('font-family', 'monospace')
|
.style('font-family', 'monospace')
|
||||||
.style('font-size', (small ? '6' : '11') + 'px')
|
.style('font-size', (small ? '6' : '11') + 'px')
|
||||||
.attr('data-word', d => d.name);
|
.attr('data-word', d => d.value);
|
||||||
|
|
||||||
nodesEnter.append('circle');
|
nodesEnter.append('circle');
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ function draw(small) {
|
|||||||
let texts = svg.selectAll('g.node text').data(nodes);
|
let texts = svg.selectAll('g.node text').data(nodes);
|
||||||
|
|
||||||
texts.attr('dy', 5)
|
texts.attr('dy', 5)
|
||||||
.html(d => `<tspan>${d.name.split('').join('</tspan><tspan>')}</tspan>`)
|
.html(d => `<tspan>${d.value.split('').join('</tspan><tspan>')}</tspan>`)
|
||||||
.attr('text-anchor', 'middle')
|
.attr('text-anchor', 'middle')
|
||||||
.style('fill', 'white');
|
.style('fill', 'white');
|
||||||
}
|
}
|
||||||
|
2
src/1.js
2
src/1.js
@ -30,7 +30,7 @@ function keyup() {
|
|||||||
for (let node of nodes.children) {
|
for (let node of nodes.children) {
|
||||||
const category = node.category ? `- ${node.category}` : '';
|
const category = node.category ? `- ${node.category}` : '';
|
||||||
|
|
||||||
results.innerHTML += `<li>${node.name} ${category}</li>`;
|
results.innerHTML += `<li>${node.value} ${category}</li>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
src/2.js
4
src/2.js
@ -28,7 +28,7 @@ input.addEventListener('keydown', e => {
|
|||||||
|
|
||||||
if (!current.children.length) return;
|
if (!current.children.length) return;
|
||||||
|
|
||||||
input.value = current.children[0].name;
|
input.value = current.children[0].value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ function keyup() {
|
|||||||
for (let node of nodes) {
|
for (let node of nodes) {
|
||||||
const category = node.category ? `- ${node.category}` : '';
|
const category = node.category ? `- ${node.category}` : '';
|
||||||
|
|
||||||
results.innerHTML += `<li>${node.name} ${category}</li>`;
|
results.innerHTML += `<li>${node.value} ${category}</li>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class Node {
|
class Node {
|
||||||
constructor(value = '', parent) {
|
constructor(value = '', parent) {
|
||||||
this.name = value;
|
this.value = value;
|
||||||
this.children = [];
|
this.children = [];
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
@ -14,10 +14,10 @@ class Trie {
|
|||||||
add(value, parent = this.root) {
|
add(value, parent = this.root) {
|
||||||
for (let i = 0, len = value.length; i < len; i++) {
|
for (let i = 0, len = value.length; i < len; i++) {
|
||||||
if (!parent.children) parent.children = [];
|
if (!parent.children) parent.children = [];
|
||||||
let node = parent.children.find(child => child.name[i] === value[i]);
|
let node = parent.children.find(child => child.value[i] === value[i]);
|
||||||
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
node = new Node(value.slice(0, i + 1), parent.name);
|
node = new Node(value.slice(0, i + 1), parent.value);
|
||||||
parent.children.push(node);
|
parent.children.push(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ class Trie {
|
|||||||
|
|
||||||
find(value, parent = this.root) {
|
find(value, parent = this.root) {
|
||||||
for (let i = 0, len = value.length; i < len; i++) {
|
for (let i = 0, len = value.length; i < len; i++) {
|
||||||
parent = parent.children.find(child => child.name[i] === value[i]);
|
parent = parent.children.find(child => child.value[i] === value[i]);
|
||||||
|
|
||||||
if (!parent) return null;
|
if (!parent) return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user