1
1
import { csv } from "./export" ;
2
2
import * as model from "../model" ;
3
- import { onSelectionUpdate , updateSelection , getSelection , getOthers } from "../selection" ;
3
+ import {
4
+ onSelectionUpdate , updateSelection , getSelection , getOthers , selectAll , deselectAll
5
+ } from "../selection" ;
4
6
5
7
let sorting = {
6
8
properties : [ "entities" , "0" , "score" ] ,
@@ -20,14 +22,28 @@ let sorter = (a, b) => {
20
22
function switchSelected ( ) {
21
23
if ( ! this . element )
22
24
return ;
25
+ this . element . classList . remove ( "highlighted" ) ;
23
26
d3 . select ( this . element ) . classed ( "selected" , this . selected = ! this . selected ) ;
24
27
updateSelection ( ) ;
25
28
}
26
29
27
- function updateSelected ( ) {
28
- let data = getSelection ( ) . filter ( node => node . type === "entity" ) . sort ( sorter ) ,
29
- table = document . querySelector ( "#tabular-selected" ) ;
30
- table . textContent = "" ;
30
+ /**
31
+ * this: node
32
+ */
33
+ function toggleChildrenSelected ( e ) {
34
+ let sel = false ,
35
+ el = e . target || e . srcElement ;
36
+ for ( let o of this . children ) { if ( o . selected ) { sel = true ; break ; } }
37
+ if ( sel )
38
+ deselectAll ( this , false ) ;
39
+ else
40
+ selectAll ( this , false ) ;
41
+ el . className = `icon-${ ! sel ? "filled" : "outline" } ` ;
42
+ this . element . classList . remove ( "highlighted" ) ;
43
+ updateSelection ( ) ;
44
+ }
45
+
46
+ function insertRows ( data , table , selected ) {
31
47
for ( let i = 0 ; i < data . length ; i ++ ) {
32
48
let row = table . insertRow ( i ) ,
33
49
node = data [ i ] ,
@@ -40,34 +56,34 @@ function updateSelected () {
40
56
( c = row . insertCell ( 5 ) ) . textContent = node . edgeType || "" ;
41
57
c . className = `${ node . edgeType } Item` ;
42
58
row . insertCell ( 6 ) . textContent = ( node . parent || { label : "root" } ) . label || "?" ;
43
- let ee = document . createElement ( "i" ) ;
44
- ee . className = "icon-close" ;
59
+ let ee = document . createElement ( "i" ) ,
60
+ ei = document . createElement ( "i" ) ,
61
+ sel = false ,
62
+ cell = row . insertCell ( 7 ) ;
63
+ for ( let o of node . children ) { if ( o . selected ) { sel = true ; break ; } }
64
+ ei . className = `icon-${ sel ? "filled" : "outline" } ` ;
65
+ ei . addEventListener ( "click" , toggleChildrenSelected . bind ( node ) ) ;
66
+ ee . className = `icon-${ selected ? "close" : "add" } ` ;
45
67
ee . addEventListener ( "click" , switchSelected . bind ( node ) ) ;
46
- row . insertCell ( 7 ) . appendChild ( ee ) ;
68
+ cell . appendChild ( ei ) ;
69
+ cell . appendChild ( ee ) ;
70
+ row . addEventListener ( "mouseover" , ( ) => { node . element . classList . add ( "highlighted" ) ; } ) ;
71
+ row . addEventListener ( "mouseout" , ( ) => { node . element . classList . remove ( "highlighted" ) ; } ) ;
47
72
}
48
73
}
49
74
75
+ function updateSelected ( ) {
76
+ let data = getSelection ( ) . filter ( node => node . type === "entity" ) . sort ( sorter ) ,
77
+ table = document . querySelector ( "#tabular-selected" ) ;
78
+ table . textContent = "" ;
79
+ insertRows ( data , table , true ) ;
80
+ }
81
+
50
82
function updateOthers ( ) {
51
83
let data = getOthers ( ) . filter ( node => node . type === "entity" ) . sort ( sorter ) ,
52
84
table = document . querySelector ( "#tabular-others" ) ;
53
85
table . textContent = "" ;
54
- for ( let i = 0 ; i < data . length ; i ++ ) {
55
- let row = table . insertRow ( i ) ,
56
- node = data [ i ] ,
57
- c ;
58
- row . insertCell ( 0 ) . textContent = node . id ;
59
- row . insertCell ( 1 ) . textContent = node . label ;
60
- row . insertCell ( 2 ) . textContent = node . entities [ 0 ] . score ;
61
- row . insertCell ( 3 ) . textContent = node . entities [ 0 ] . frequency ;
62
- row . insertCell ( 4 ) . textContent = node . entities [ 0 ] . spread ;
63
- ( c = row . insertCell ( 5 ) ) . textContent = node . edgeType || "" ;
64
- c . className = `${ node . edgeType } Item` ;
65
- row . insertCell ( 6 ) . textContent = ( node . parent || { label : "root" } ) . label || "?" ;
66
- let ee = document . createElement ( "i" ) ;
67
- ee . className = "icon-add" ;
68
- ee . addEventListener ( "click" , switchSelected . bind ( node ) ) ;
69
- row . insertCell ( 7 ) . appendChild ( ee ) ;
70
- }
86
+ insertRows ( data , table , false ) ;
71
87
}
72
88
73
89
function updateAll ( ) {
0 commit comments