src/TooltipContainer.js
/**
 * Show and place the input.
 * @param {string} type - 'reaction_label', 'node_label', or 'gene_label'
 * @param {Object} d - D3 data for DOM element
 */
Show and place the input.
Show and place the input .
function show (type, d) {
  this.cancelHideTooltip()
  if (_.contains([ 'reaction_label', 'node_label', 'gene_label' ], type)) {
    const tooltipSize = (this.tooltipRef !== null && this.tooltipRef.getSize)
    ? this.tooltipRef.getSize()
    : { width: 270, height: 100 }
    this.currentTooltip = { type, id: d[type.replace('_label', '_id')] }
    const windowTranslate = this.zoom_container.window_translate
    const windowScale = this.zoom_container.window_scale
    const mapSize = this.map !== null ? this.map.get_size() : { width: 1000, height: 1000 }
    const offset = {x: 0, y: 0}
    const rightEdge = windowScale * d.label_x + windowTranslate.x + tooltipSize.width
    const bottomEdge = windowScale * d.label_y + windowTranslate.y + tooltipSize.height
    if (mapSize.width < 500) {
      if (rightEdge > mapSize.width) {
        offset.x = -(rightEdge - mapSize.width) / windowScale
      }
      if (bottomEdge > mapSize.height - 74) {
        offset.y = -(bottomEdge - mapSize.height + 77) / windowScale
      }
    } else {
      if (windowScale * d.label_x + windowTranslate.x + 0.5 * tooltipSize.width > mapSize.width) {
        offset.x = -tooltipSize.width / windowScale
      } else if (rightEdge > mapSize.width) {
        offset.x = -(rightEdge - mapSize.width) / windowScale
      }
      if (windowScale * d.label_y + windowTranslate.y + 0.5 * tooltipSize.height > mapSize.height - 45) {
        offset.y = -(tooltipSize.height) / windowScale
      } else if (bottomEdge > mapSize.height - 45) {
        offset.y = -(bottomEdge - mapSize.height + 47) / windowScale
      }
    }
    const coords = { x: d.label_x + offset.x, y: d.label_y + 10 + offset.y }
    this.placed_div.place(coords)
    const data = {
      biggId: d.bigg_id,
      name: d.name,
      loc: coords,
      data: d.data_string,
      type: type.replace('_label', '').replace('node', 'metabolite')
    }
    this.callback_manager.run('setState', null, data)
  } else {
    throw new Error('Tooltip not supported for object type ' + type)
  }
}
function show ( type , d ) { this . cancelHideTooltip ( ) if ( _ . contains ( [ 'reaction_label' , 'node_label' , 'gene_label' ] , type ) ) { const tooltipSize = ( this . tooltipRef !== null && this . tooltipRef . getSize ) ? this . tooltipRef . getSize ( ) : { width : 270 , height : 100 } this . currentTooltip = { type , id : d [ type . replace ( '_label' , '_id' ) ] } const windowTranslate = this . zoom_container . window_translate const windowScale = this . zoom_container . window_scale const mapSize = this . map !== null ? this . map . get_size ( ) : { width : 1000 , height : 1000 } const offset = { x : 0 , y : 0 } const rightEdge = windowScale * d . label_x + windowTranslate . x + tooltipSize . width const bottomEdge = windowScale * d . label_y + windowTranslate . y + tooltipSize . height if ( mapSize . width < 500 ) { if ( rightEdge > mapSize . width ) { offset . x = - ( rightEdge - mapSize . width ) / windowScale } if ( bottomEdge > mapSize . height - 74 ) { offset . y = - ( bottomEdge - mapSize . height + 77 ) / windowScale } } else { if ( windowScale * d . label_x + windowTranslate . x + 0.5 * tooltipSize . width > mapSize . width ) { offset . x = - tooltipSize . width / windowScale } else if ( rightEdge > mapSize . width ) { offset . x = - ( rightEdge - mapSize . width ) / windowScale } if ( windowScale * d . label_y + windowTranslate . y + 0.5 * tooltipSize . height > mapSize . height - 45 ) { offset . y = - ( tooltipSize . height ) / windowScale } else if ( bottomEdge > mapSize . height - 45 ) { offset . y = - ( bottomEdge - mapSize . height + 47 ) / windowScale } } const coords = { x : d . label_x + offset . x , y : d . label_y + 10 + offset . y } this . placed_div . place ( coords ) const data = { biggId : d . bigg_id , name : d . name , loc : coords , data : d . data_string , type : type . replace ( '_label' , '' ) . replace ( 'node' , 'metabolite' ) } this . callback_manager . run ( 'setState' , null , data ) } else { throw new Error ( 'Tooltip not supported for object type ' + type ) } }
Show and place the input.
Show and place the input .
// get rid of a lingering delayed hide // Use a default height if the ref hasn't been connected yet