@@ -73,7 +73,60 @@ class Word {
7373 }
7474
7575 draw ( ) {
76- drawWord ( this ) ;
76+ let g = this . svg = draw . group ( ) . addClass ( 'word' ) ;
77+
78+ this . underneathRect = g . rect ( this . ww , this . wh )
79+ . x ( this . wx )
80+ . y ( this . wy )
81+ . addClass ( 'word--underneath' ) ;
82+
83+ var textwh = getTextWidthAndHeight ( this . val , texts . wordText . style ) ;
84+
85+ this . text = g . text ( this . val )
86+ . y ( this . wy + Config . textPaddingY * 2 - texts . wordText . descent )
87+ . x ( this . wx + ( this . ww / 2 ) - ( textwh . w / 2 ) )
88+ . font ( texts . wordText . style ) ;
89+
90+ this . bbox = this . underneathRect . bbox ( ) ;
91+ this . leftX = this . underneathRect . bbox ( ) . x ;
92+ this . rightX = this . underneathRect . bbox ( ) . x + this . underneathRect . bbox ( ) . w ;
93+ this . percPos = ( this . leftX - Config . edgePadding ) / ( Config . svgWidth - Config . edgePadding * 2 ) ;
94+
95+ if ( this . tag != null ) {
96+ var textwh = getTextWidthAndHeight ( this . tag , texts . tagText . style ) ;
97+ var tagXPos = this . twx + ( this . ww / 2 ) - ( textwh . w / 2 ) ;
98+
99+ //add in tag text, if the word has an associated tag
100+ this . tagtext = g . text ( this . tag )
101+ . y ( this . wy + Config . textPaddingY / 2 - texts . wordText . descent )
102+ . x ( tagXPos )
103+ . font ( texts . tagText . style ) ;
104+
105+ this . leftHandle = g . rect ( Config . handleW , Config . handleH )
106+ . x ( this . wx )
107+ . y ( this . wy + ( this . wh / 2 ) - ( Config . handleH / 2 ) )
108+ . addClass ( 'word--handle' ) ;
109+
110+ this . rightHandle = g . rect ( Config . handleW , Config . handleH )
111+ . x ( this . wx + this . ww - ( Config . handleW ) )
112+ . y ( this . wy + ( this . wh / 2 ) - ( Config . handleH / 2 ) )
113+ . addClass ( 'word--handle' ) ;
114+
115+ //set up mouse interactions
116+ setUpLeftHandleDraggable ( this ) ;
117+ setUpRightHandleDraggable ( this ) ;
118+ }
119+
120+ setUpWordDraggable ( this ) ;
121+
122+ this . underneathRect . dblclick ( ( ) => {
123+ this . toggleHighlight ( ) ;
124+ draw . fire ( 'wordSelected' , { arbitrary : this } ) ;
125+ } ) ;
126+
127+ this . underneathRect . click ( ( ) => {
128+ draw . fire ( 'wordClicked' , { arbitrary : this } ) ;
129+ } )
77130 }
78131
79132 get minWidth ( ) { //min width is the maximum of: the word text, the tag text, or the size of the two handles + a little bit
0 commit comments