Skip to content

Commit d1bf982

Browse files
Tabular view code refactoring, dedicated sort function
1 parent 2f2cb21 commit d1bf982

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
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.5.9",
3+
"version": "0.5.10",
44
"description": "Visualizer for iKnow entities",
55
"main": "gulpfile.babel.js",
66
"scripts": {

src/static/index.html

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,19 @@
8989
<table>
9090
<thead>
9191
<tr>
92-
<th>ID</th>
93-
<th>Label</th>
94-
<th>Score</th>
95-
<th>Frequency</th>
96-
<th>Spread</th>
97-
<th>Relation</th>
98-
<th>Parent</th>
92+
<th data-prop="id">ID</th>
93+
<th data-prop="label">Label</th>
94+
<th data-prop="entities.0.score">Score</th>
95+
<th data-prop="entities.0.frequency">Frequency</th>
96+
<th data-prop="entities.0.spread">Spread</th>
97+
<th data-prop="edgeType">Relation</th>
98+
<th data-prop="parent.label">Parent</th>
9999
</tr>
100100
</thead>
101-
<tbody>
101+
<tbody id="tabular-selected">
102+
103+
</tbody>
104+
<tbody id="tabular-others">
102105

103106
</tbody>
104107
</table>

src/static/js/model/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ function preprocess (graph) {
104104
entities: [{
105105
id: -1,
106106
value: getOption("seed"),
107-
[SIZE_CRITERIA]: 10000
107+
[SIZE_CRITERIA]: 9999,
108+
score: 9999,
109+
spread: 0,
110+
frequency: 9999
108111
}]
109112
});
110113
}

src/static/js/selection.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export function updateSelection () {
2020

2121
}
2222

23+
export function getSelection () {
24+
return selection;
25+
}
26+
2327
export function selectAll (node) {
2428
if (!node)
2529
return;

src/static/js/tabular/index.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import { csv } from "./export";
22
import * as model from "../model";
3-
import { onSelectionUpdate, updateSelection } from "../selection";
3+
import { onSelectionUpdate, updateSelection, getSelection } from "../selection";
44

5-
onSelectionUpdate((selection) => {
6-
if (!model.uiState.tabularToggled)
7-
return;
8-
let data = selection.filter(node => node.type === "entity").sort((a, b) =>
9-
a.entities[0].score > b.entities[0].score ? -1 : 1
10-
),
11-
table = document.querySelector("#table table tbody");
5+
let sorting = {
6+
enabled: false,
7+
properties: ["entities", "0", "score"],
8+
order: 1
9+
};
10+
11+
let sorter = (a, b) => {
12+
let i = 0;
13+
while (i < sorting.properties.length && typeof (a = a[sorting.properties[i]]) !== "undefined"
14+
&& typeof (b = b[sorting.properties[i]]) !== "undefined") { console.log(i); ++i }
15+
return a > b ? -sorting.order : a === b ? 0 : sorting.order;
16+
};
17+
18+
function updateSelected () {
19+
let data = getSelection().filter(node => node.type === "entity").sort(sorter),
20+
table = document.querySelector("#tabular-selected");
1221
table.textContent = "";
1322
for (let i = 0; i < data.length; i++) {
1423
let row = table.insertRow(i),
@@ -23,6 +32,16 @@ onSelectionUpdate((selection) => {
2332
c.className = `${ node.edgeType }Item`;
2433
row.insertCell(6).textContent = (node.parent || { label: "root" }).label || "?";
2534
}
35+
}
36+
37+
function updateOthers () {
38+
39+
}
40+
41+
onSelectionUpdate(() => {
42+
if (!model.uiState.tabularToggled)
43+
return;
44+
updateSelected();
2645
});
2746

2847
export function init () {

0 commit comments

Comments
 (0)