@@ -102,9 +102,10 @@ export interface DefaultNodeProps {
102102 */
103103export class CustomNodeWidget extends React . Component < DefaultNodeProps > {
104104
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+
108109 element :Object ;
109110 state = {
110111
@@ -127,7 +128,63 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
127128 original : 'https://picsum.photos/id/1019/1000/600/' ,
128129 thumbnail : 'https://picsum.photos/id/1019/250/150/'
129130 } ,
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+ ) ;
131188 } ;
132189
133190 showTooltip ( ) {
@@ -206,8 +263,12 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
206263 * Show/Hide Component's Description Tooltip
207264 */
208265 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 ( ) ;
211272 ReactTooltip . show ( this . element as Element ) ;
212273 }
213274
@@ -234,7 +295,7 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
234295 delete this . props . node . getOptions ( ) . extras [ "tip" ] ;
235296 this . props . node . getOptions ( ) . extras [ "borderColor" ] = "rgb(0,192,255)" ;
236297 }
237-
298+
238299 render ( ) {
239300 if ( this . props . node [ 'extras' ] [ 'type' ] == 'comment' ) {
240301 return (
@@ -301,39 +362,43 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
301362 </ S . Ports >
302363 </ S . Node >
303364 { /** Description Tooltip */ }
304- { this . state . showDescription && < ReactTooltip
365+ { ( this . state . showDescription || this . state . showParamDescriptionList . reduce ( ( prev , cur ) => prev || cur , false ) ) && < ReactTooltip
305366 id = { this . props . node . getOptions ( ) . id }
306367 className = 'description-tooltip'
307368 arrowColor = 'rgb(255, 255, 255)'
308369 clickable
309- afterShow = { ( ) => { this . setState ( { showDescription : true } ) } }
310- afterHide = { ( ) => { this . setState ( { showDescription : false } ) } }
311370 delayHide = { 60000 }
312- delayUpdate = { 5000 }
371+ delayUpdate = { 0 }
313372 getContent = { ( ) =>
314- < div data-no-drag style = { { cursor : 'default' } } >
373+ < div data-no-drag style = { { cursor : 'default' } } ref = { this . tooltipDescriptionRef } >
315374 < button
316375 type = "button"
317376 className = "close"
318377 data-dismiss = "modal"
319378 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+ >
321384 < span aria-hidden = "true" > ×</ span >
322385 </ 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 >
324387 < p className = 'description-title' > Description:</ p >
325- < div
388+ < div
326389 onWheel = { ( e ) => e . stopPropagation ( ) }
327390 className = 'description-container' >
328- < div className = 'markdown-body' dangerouslySetInnerHTML = { this . renderText ( this . state . descriptionStr ) } />
391+ < div className = 'markdown-body' dangerouslySetInnerHTML = { { __html : this . state . descriptionStr } } />
329392 </ div >
330393 </ div > }
331394 overridePosition = { (
332395 { left, top } ,
333396 currentEvent , currentTarget , node , refNode ) => {
397+
334398 const currentNode = this . props . node ;
335399 const nodeDimension = { x : currentNode . width , y : currentNode . height } ;
336400 const nodePosition = { x : currentNode . getX ( ) , y : currentNode . getY ( ) } ;
401+
337402 let newPositionX = nodePosition . x ;
338403 let newPositionY = nodePosition . y ;
339404 let offset = 0 ;
@@ -346,7 +411,7 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
346411
347412 if ( refNode == 'top' ) {
348413 newPositionX = newPositionX - 208 + offset + ( nodeDimension . x / 2 ) ;
349- newPositionY = newPositionY - 220 ;
414+ newPositionY = newPositionY + 66 - this . tooltipDescriptionRef . current . clientHeight ;
350415 }
351416 else if ( refNode == 'bottom' ) {
352417 newPositionX = newPositionX - 208 + offset + ( nodeDimension . x / 2 ) ;
0 commit comments