-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: maria-ericsson <maria.chowdhury@ericsson.com>
- Loading branch information
1 parent
91f685f
commit fb31e85
Showing
3 changed files
with
151 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
viewer-prototype/src/browser/trace-viewer/components/utils/tooltip-component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as React from 'react'; | ||
import { Component } from 'react'; | ||
|
||
interface TooltipProps { | ||
tooltip: { [key: string]: string }; | ||
position: { x: number, y: number }; | ||
} | ||
|
||
interface TooltipStates { | ||
style: { top: string, left: string }; | ||
|
||
} | ||
|
||
export class TooltipComponent extends Component<TooltipProps, TooltipStates> { | ||
constructor(props: TooltipProps) { | ||
super(props); | ||
this.state = { style: { top: props.position.y + 'px', left: props.position.x + 'px' } }; | ||
} | ||
|
||
tooltipRef: React.RefObject<HTMLDivElement> = React.createRef(); | ||
|
||
renderTooltip(): React.ReactNode { | ||
const tooltipArray: React.ReactNode[] = []; | ||
if (this.props.tooltip) { | ||
const keys = Object.keys(this.props.tooltip); | ||
keys.forEach(key => { | ||
tooltipArray.push(<p key={key}>{key + ': ' + this.props.tooltip[key]}</p>); | ||
}); | ||
} | ||
else { | ||
console.log('Tooltip null'); | ||
} | ||
return <React.Fragment> | ||
{tooltipArray.map(element => element)} | ||
</React.Fragment>; | ||
} | ||
|
||
render(): React.ReactNode { | ||
return <div id='tooltip-box' ref={this.tooltipRef} style={this.state.style}> | ||
{this.renderTooltip()} | ||
</div>; | ||
} | ||
} |