@@ -102,9 +102,10 @@ export interface DefaultNodeProps {
102
102
*/
103
103
export class CustomNodeWidget extends React . Component < DefaultNodeProps > {
104
104
105
- generatePort = ( port ) => {
106
- return < CustomPortLabel engine = { this . props . engine } port = { port } key = { port . getID ( ) } node = { this . props . node } /> ;
107
- } ;
105
+ portsNo = this . props . node . getInPorts ( ) . length + this . props . node . getOutPorts ( ) . length ;
106
+
107
+ tooltipDescriptionRef = React . createRef < HTMLDivElement > ( ) ;
108
+
108
109
element :Object ;
109
110
state = {
110
111
@@ -127,7 +128,63 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
127
128
original : 'https://picsum.photos/id/1019/1000/600/' ,
128
129
thumbnail : 'https://picsum.photos/id/1019/250/150/'
129
130
} ,
130
- ]
131
+ ] ,
132
+ showParamDescriptionList : new Array ( this . portsNo ) . fill ( false ) ,
133
+ paramName : ""
134
+ } ;
135
+
136
+ /**
137
+ * creates a particular function for each component so that it can set only it's state
138
+ * @param id
139
+ */
140
+ setShowParamDescription = ( id : number ) => {
141
+ const _setShowParamDescription = ( newShowDescription : boolean ) => {
142
+ this . setState ( {
143
+ showParamDescriptionList : this . state . showParamDescriptionList . map ( ( value , index ) => (
144
+ id === index ? newShowDescription : false
145
+ )
146
+ ) ,
147
+ showDescription : false
148
+ } )
149
+ }
150
+ return _setShowParamDescription ;
151
+ }
152
+
153
+ setDescriptionStr = ( paramName : string ) => {
154
+ const _setDescriptionStr = async ( descriptionStr : string ) => {
155
+ await this . setState ( {
156
+ descriptionStr : descriptionStr ,
157
+ paramName : paramName
158
+ } ) ;
159
+ ReactTooltip . show ( this . element as Element ) ;
160
+ }
161
+ return _setDescriptionStr ;
162
+ }
163
+
164
+ generatePort = ( port , index ) => {
165
+ const argumentDescriptions = this . props . node [ 'extras' ] [ 'argumentDescriptions' ] ;
166
+
167
+ // remove the ☆ from the beginning of the label
168
+ const name = port . getOptions ( ) . label [ 0 ] === "★" ? port . getOptions ( ) . label . slice ( 1 ) : port . getOptions ( ) . label ;
169
+
170
+ const description = argumentDescriptions && ( name in argumentDescriptions ) ? argumentDescriptions [ name ] : "" ;
171
+
172
+ const isOutPort = port . getOptions ( ) . name . includes ( 'parameter-out' ) ;
173
+
174
+ index = isOutPort ? index + this . props . node . getInPorts ( ) . length : index ;
175
+
176
+ return (
177
+ < CustomPortLabel
178
+ engine = { this . props . engine }
179
+ port = { port }
180
+ key = { port . getID ( ) }
181
+ node = { this . props . node }
182
+ showDescription = { this . state . showParamDescriptionList [ index ] }
183
+ setShowDescription = { this . setShowParamDescription ( index ) }
184
+ setDescriptionStr = { this . setDescriptionStr }
185
+ description = { description }
186
+ />
187
+ ) ;
131
188
} ;
132
189
133
190
showTooltip ( ) {
@@ -206,8 +263,12 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
206
263
* Show/Hide Component's Description Tooltip
207
264
*/
208
265
async handleDescription ( ) {
209
- await this . setState ( { showDescription : ! this . state . showDescription } ) ;
210
- this . getDescriptionStr ( ) ;
266
+ await this . setState ( {
267
+ showDescription : ! this . state . showDescription ,
268
+ showParamDescriptionList : new Array ( this . portsNo ) . fill ( false ) ,
269
+ paramName : ""
270
+ } ) ;
271
+ await this . getDescriptionStr ( ) ;
211
272
ReactTooltip . show ( this . element as Element ) ;
212
273
}
213
274
@@ -234,7 +295,7 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
234
295
delete this . props . node . getOptions ( ) . extras [ "tip" ] ;
235
296
this . props . node . getOptions ( ) . extras [ "borderColor" ] = "rgb(0,192,255)" ;
236
297
}
237
-
298
+
238
299
render ( ) {
239
300
if ( this . props . node [ 'extras' ] [ 'type' ] == 'comment' ) {
240
301
return (
@@ -301,39 +362,43 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
301
362
</ S . Ports >
302
363
</ S . Node >
303
364
{ /** Description Tooltip */ }
304
- { this . state . showDescription && < ReactTooltip
365
+ { ( this . state . showDescription || this . state . showParamDescriptionList . reduce ( ( prev , cur ) => prev || cur , false ) ) && < ReactTooltip
305
366
id = { this . props . node . getOptions ( ) . id }
306
367
className = 'description-tooltip'
307
368
arrowColor = 'rgb(255, 255, 255)'
308
369
clickable
309
- afterShow = { ( ) => { this . setState ( { showDescription : true } ) } }
310
- afterHide = { ( ) => { this . setState ( { showDescription : false } ) } }
311
370
delayHide = { 60000 }
312
- delayUpdate = { 5000 }
371
+ delayUpdate = { 0 }
313
372
getContent = { ( ) =>
314
- < div data-no-drag style = { { cursor : 'default' } } >
373
+ < div data-no-drag style = { { cursor : 'default' } } ref = { this . tooltipDescriptionRef } >
315
374
< button
316
375
type = "button"
317
376
className = "close"
318
377
data-dismiss = "modal"
319
378
aria-label = "Close"
320
- onClick = { ( ) => { this . setState ( { showDescription : false } ) ; } } >
379
+ onClick = { ( ) => { this . setState ( {
380
+ showDescription : false ,
381
+ showParamDescriptionList : new Array ( this . portsNo ) . fill ( false )
382
+ } ) ; } }
383
+ >
321
384
< span aria-hidden = "true" > ×</ span >
322
385
</ button >
323
- < S . DescriptionName color = { this . props . node . getOptions ( ) . color } > { this . props . node . getOptions ( ) [ "name" ] } </ S . DescriptionName >
386
+ < S . DescriptionName color = { this . props . node . getOptions ( ) . color } > { this . props . node . getOptions ( ) [ "name" ] + " " + this . state . paramName } </ S . DescriptionName >
324
387
< p className = 'description-title' > Description:</ p >
325
- < div
388
+ < div
326
389
onWheel = { ( e ) => e . stopPropagation ( ) }
327
390
className = 'description-container' >
328
- < div className = 'markdown-body' dangerouslySetInnerHTML = { this . renderText ( this . state . descriptionStr ) } />
391
+ < div className = 'markdown-body' dangerouslySetInnerHTML = { { __html : this . state . descriptionStr } } />
329
392
</ div >
330
393
</ div > }
331
394
overridePosition = { (
332
395
{ left, top } ,
333
396
currentEvent , currentTarget , node , refNode ) => {
397
+
334
398
const currentNode = this . props . node ;
335
399
const nodeDimension = { x : currentNode . width , y : currentNode . height } ;
336
400
const nodePosition = { x : currentNode . getX ( ) , y : currentNode . getY ( ) } ;
401
+
337
402
let newPositionX = nodePosition . x ;
338
403
let newPositionY = nodePosition . y ;
339
404
let offset = 0 ;
@@ -346,7 +411,7 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
346
411
347
412
if ( refNode == 'top' ) {
348
413
newPositionX = newPositionX - 208 + offset + ( nodeDimension . x / 2 ) ;
349
- newPositionY = newPositionY - 220 ;
414
+ newPositionY = newPositionY + 66 - this . tooltipDescriptionRef . current . clientHeight ;
350
415
}
351
416
else if ( refNode == 'bottom' ) {
352
417
newPositionX = newPositionX - 208 + offset + ( nodeDimension . x / 2 ) ;
0 commit comments