import * as React from "react"; import { ToolTipText } from "./ToolTipText"; import { ToolTipTSpanLabel } from "./ToolTipTSpanLabel"; export type layouts = "horizontal" | "horizontalRows" | "horizontalInline" | "vertical" | "verticalRows"; export interface SingleTooltipProps { readonly origin: [number, number]; readonly yLabel: string; readonly yValue: string; readonly onClick?: (event: React.MouseEvent, details: any) => void; readonly fontFamily?: string; readonly fontSize?: number; readonly fontWeight?: number; readonly labelFill: string; readonly valueFill: string; readonly forChart: number | string; readonly options: any; readonly layout: layouts; readonly withShape: boolean; } export class SingleTooltip extends React.Component { public static defaultProps = { labelFill: "#4682B4", valueFill: "#000000", withShape: false, }; /* * Renders the value next to the label. */ public renderValueNextToLabel() { const { origin, yLabel, yValue, labelFill, valueFill, withShape, fontSize, fontFamily, fontWeight } = this.props; return ( {withShape ? : null} {yLabel}: {yValue} ); } /* * Renders the value beneath the label. */ public renderValueBeneathLabel() { const { origin, yLabel, yValue, labelFill, valueFill, withShape, fontSize, fontFamily, fontWeight } = this.props; return ( {withShape ? : null} {yLabel} {yValue} ); } /* * Renders the value next to the label. * The parent component must have a "text"-element. */ public renderInline() { const { yLabel, yValue, labelFill, valueFill, fontSize, fontFamily, fontWeight } = this.props; return ( {yLabel}:  {yValue}   ); } public render() { const { layout } = this.props; let comp: JSX.Element | null = null; switch (layout) { case "horizontal": comp = this.renderValueNextToLabel(); break; case "horizontalRows": comp = this.renderValueBeneathLabel(); break; case "horizontalInline": comp = this.renderInline(); break; case "vertical": comp = this.renderValueNextToLabel(); break; case "verticalRows": comp = this.renderValueBeneathLabel(); break; default: comp = this.renderValueNextToLabel(); } return comp; } private readonly handleClick = (event: React.MouseEvent) => { const { onClick, forChart, options } = this.props; if (onClick !== undefined) { onClick(event, { chartId: forChart, ...options }); } }; }