Skip to content

Commit 791fffa

Browse files
Design enhancements, CSV data export
1 parent 60a3add commit 791fffa

14 files changed

+171
-38
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iknow-entity-browser",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "Visualizer for iKnow entities",
55
"main": "gulpfile.babel.js",
66
"scripts": {
2.87 KB
Binary file not shown.

src/static/fonts/iknowentitybrowsericons.svg

Lines changed: 14 additions & 0 deletions
Loading
2.87 KB
Binary file not shown.
1.94 KB
Binary file not shown.

src/static/index.html

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,30 @@
1212
<div id="windows">
1313
<svg id="graph"></svg>
1414
<div id="table">
15-
<h1>Selected Nodes</h1>
15+
<i id="tableToggle" class="ui icon-window-list"></i>
1616
<div class="wrapper">
17-
<table>
18-
<thead>
19-
<tr>
20-
<th>ID</th>
21-
<th>Label</th>
22-
<th>Frequency</th>
23-
</tr>
24-
</thead>
25-
<tbody>
17+
<div>
18+
<i id="exportCSV" class="ui icon-page-export-csv"></i>
19+
</div>
20+
<h1>Selected Nodes</h1>
21+
<div class="wrapper">
22+
<table>
23+
<thead>
24+
<tr>
25+
<th>ID</th>
26+
<th>Label</th>
27+
<th>Score</th>
28+
<th>Frequency</th>
29+
<th>Spread</th>
30+
</tr>
31+
</thead>
32+
<tbody>
2633

27-
</tbody>
28-
</table>
34+
</tbody>
35+
</table>
36+
</div>
2937
</div>
3038
</div>
3139
</div>
32-
<div class="uiIconGroup topRight">
33-
<i id="tableToggle" class="ui icon-window-list"></i>
34-
</div>
3540
</body>
3641
</html>

src/static/js/export.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @param {*[][]} dataArray - Table to be exported.
3+
*/
4+
export function csv (dataArray = []) {
5+
6+
console.log(dataArray);
7+
let csvContent = "data:text/csv;charset=utf-8,";
8+
9+
dataArray.forEach((infoArray, index) => {
10+
11+
let dataString = infoArray.join(",");
12+
csvContent += index < dataArray.length ? dataString + "\n" : dataString;
13+
14+
});
15+
16+
let encodedUri = encodeURI(csvContent),
17+
link = document.createElement("a");
18+
19+
link.setAttribute("href", encodedUri);
20+
link.setAttribute("download", "entityGraph.csv");
21+
document.body.appendChild(link);
22+
link.click();
23+
24+
setTimeout(() => link.parentNode.removeChild(link), 10);
25+
26+
}

src/static/js/index.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
import sampleData from "./sample_output2.json";
2+
import { uiState } from "./ui";
3+
import { csv } from "./export";
24

35
var graph = preprocess(sampleData.graph);
46

57
function preprocess (graph) {
6-
graph.nodes.forEach(node => node.radius = 5 + Math.sqrt(node.entities[0].frequency || 25));
8+
graph.nodes.forEach(node => node.radius = 5 + Math.sqrt(node.entities[0].score/4 || 25));
79
return graph;
810
}
911

1012
function updateSelectedNodes () {
11-
let data = graph.nodes.filter(node => !!node.selected),
13+
if (!uiState.tableToggled)
14+
return;
15+
let data = graph.nodes.filter(node => !!node.selected).sort((a, b) =>
16+
a.entities[0].score > b.entities[0].score ? -1 : 1
17+
),
1218
table = document.querySelector("#table table tbody");
1319
table.textContent = "";
1420
for (let i = 0; i < data.length; i++) {
1521
let row = table.insertRow(i),
1622
node = data[i];
1723
row.insertCell(0).textContent = node.id;
1824
row.insertCell(1).textContent = node.label;
19-
row.insertCell(2).textContent = node.entities[0].frequency;
25+
row.insertCell(2).textContent = node.entities[0].score;
26+
row.insertCell(3).textContent = node.entities[0].frequency;
27+
row.insertCell(4).textContent = node.entities[0].spread;
2028
}
2129
}
2230

@@ -91,7 +99,7 @@ window.init = () => {
9199
if (!ctrlKey) {
92100
node.classed("selected", (p) => p.selected = p.previouslySelected = false)
93101
}
94-
d3.select(this).classed("selected", d.selected = !d.previouslySelected);
102+
d3.select(this).classed("selected", d.selected = !d.selected); // (!prevSel)
95103
updateSelectedNodes();
96104
});
97105

@@ -197,10 +205,18 @@ window.init = () => {
197205
}
198206

199207
d3.select("#tableToggle")
200-
.data([{ toggled: false }])
201-
.on("click", (d) => {
202-
d.toggled = !d.toggled;
203-
d3.select("#table").classed("active", d.toggled);
208+
.data([uiState])
209+
.on("click", function (d) {
210+
d.tableToggled = !d.tableToggled;
211+
d3.select(this).classed("toggled", d.tableToggled);
212+
d3.select("#table").classed("active", d.tableToggled);
213+
updateSelectedNodes();
204214
});
205215

216+
d3.select("#exportCSV").on("click", () => {
217+
csv([].slice.call(document.querySelector("#table table").rows).map(row =>
218+
[].slice.call(row.cells).map(cell => cell.textContent)
219+
));
220+
});
221+
206222
};

src/static/js/ui.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export var uiState = {
2+
tableToggled: false
3+
};

src/static/scss/basic.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ table {
2020
}
2121

2222
th {
23-
background-color: rgb(2, 173, 139);
23+
background-color: $colorA;
2424
color: white;
2525
text-shadow: 0 1px 1px black;
2626
}
2727

28+
}
29+
30+
h1, h2, h3, h4, h5, h6 {
31+
margin: 0 0 .3em 0;
2832
}

0 commit comments

Comments
 (0)