5
5
* - graph (clear)
6
6
*/
7
7
8
+ import * as utils from "./../src/utils.js" ;
9
+
8
10
let draw ;
9
11
let width = 100 ;
10
12
let height = 50 ;
@@ -21,18 +23,39 @@ function init(element){
21
23
function vertex_add ( id , label ) {
22
24
console . log ( `view_svg> added node '${ label } '` ) ;
23
25
let group = draw . group ( ) . id ( 'g_' + id ) ;
24
- let text = draw . text ( label ) . id ( 't_' + id ) ;
26
+ let text = draw . text ( label ) . id ( 't_' + id ) . css ( 'pointer-events' , 'none' ) ;
25
27
let vert = draw
26
28
. rect ( width , height )
27
29
. id ( 'vert_' + id )
28
- . attr ( { fill : '#00af06' } ) ;
30
+ . attr ( { fill : '#00af06' } )
31
+ . on ( [ 'click' , 'mouseover' ,
32
+ 'mouseleave' , 'contextmenu' ,
33
+ 'touchstart' , 'touchend' ] , onMouseVertex ) ;
29
34
vert . center ( 0 , 0 ) ;
30
35
group . add ( vert ) ;
31
36
text . center ( 0 , 0 ) ;
32
37
group . add ( text ) ;
33
38
group . center ( 0 , 0 ) ;
34
39
}
35
40
41
+
42
+ function onMouseVertex ( e ) {
43
+ //console.log(`${e.type} on ${e.target.id}`);
44
+ if ( [ 'contextmenu' , 'click' ] . includes ( e . type ) ) {
45
+ e . preventDefault ( ) ;
46
+ e . stopPropagation ( ) ;
47
+ }
48
+ if ( [ 'mouseover' , 'touchstart' ] . includes ( e . type ) ) {
49
+ const id = e . target . id . substr ( 5 , event . target . id . length ) ;
50
+ utils . send ( 'graph_mouse' , { 'type' :'hover' , id :id , start :true } ) ;
51
+ }
52
+ if ( [ 'mouseleave' , 'touchend' ] . includes ( e . type ) ) {
53
+ const id = e . target . id . substr ( 5 , event . target . id . length ) ;
54
+ utils . send ( 'graph_mouse' , { 'type' :'hover' , id :id , start :false } ) ;
55
+ }
56
+ return false ;
57
+ }
58
+
36
59
function vertex_readd ( id , label ) {
37
60
//let group = SVG('#g_'+id);
38
61
var groupd_svg = document . getElementById ( 'g_' + id ) ;
@@ -105,6 +128,18 @@ function graph_clear(){
105
128
}
106
129
}
107
130
131
+ function vertex_highlight ( id , start ) {
132
+ let vertex = SVG ( '#vert_' + id ) ;
133
+ if ( start ) {
134
+ vertex . css ( 'fill' , '#b00f06' ) ;
135
+ }
136
+ else {
137
+ vertex . css ( 'fill' , '#228855' ) ;
138
+ }
139
+ console . log ( `svg> highlight , ${ start } ` ) ;
140
+
141
+ }
142
+
108
143
function onViewVertex ( e ) {
109
144
const d = e . detail ;
110
145
if ( d . type == 'add_before_edge' ) {
@@ -116,6 +151,9 @@ function onViewVertex(e){
116
151
else if ( e . detail . type == "add_after_edge" ) {
117
152
vertex_readd ( d . id , d . label ) ;
118
153
}
154
+ else if ( e . detail . type == "highlight" ) {
155
+ vertex_highlight ( d . id , d . start ) ;
156
+ }
119
157
}
120
158
121
159
function onViewEdge ( e ) {
0 commit comments