Docs
⚙️ ⏐ Utils
Tooltips

Tooltips

Tooltips in REAVIZ provide additional information about data points when users hover over them.

Types supported by reaviz:

  • TooltipArea - Used for positioning tooltips based on position calculations of data. Ideal for multi-series charts (bar/line/area), time series data, and charts with difficult-to-hit points (small bar chart lines).
  • Tooltip - Used for simple positioning relative to an element. Ideal for most charts.

Where to use:

TooltipArea:

  • Multi-series charts (bar/line/area)
  • Time series data (line/area)
  • Small bar chart lines with difficult-to-hit points

Tooltip:

  • Simple positioning relative to an element
  • Ideal for most chart types

Tooltip Area Example

The Sonar Chart is a good example of a custom tooltip area:

<StackedBarSeries
  type="stackedDiverging"
  tooltip={
    <TooltipArea
      tooltip={
        <ChartTooltip
          followCursor={true}
          modifiers={{
            offset: '5px, 5px'
          }}
          content={(data, color) => (
            <TooltipTemplate
              color={color}
              value={{
                x: formatValue(data.x),
                y: `${formatValue(Math.abs(data.data[0].y))}`
              }}
            />
          )}
        />
      }
    />
  }
/>

In the example above, the component recieves a custom TooltipArea where it overrides the tooltip property passing its own content.

API

TooltipArea (opens in a new tab)

PropDescriptionDefault
placementPopperjs placement.
Placement
heightChart height. Set internally.
number
widthChart width. Set internally.
number
xScaleChart D3 XScale. Set internally.
any
yScaleChart D3 YScale. Set internally.
any
disabledWhether the tooltip is disabled or not.
boolean
colorColor setter.
any
dataChart internal data type.
ChartInternalDataShape[]
childrenChild elements to be contained by.
any
isRadialWhether the area is radial or not.
boolean
false
isContinousWhether the area is continous or not (e.g. line and area charts are continous, bar charts are not).
boolean
true
innerRadiusInner-radius to set the positioning by. Set internally.
number
outerRadiusOuter-radius to set the positioning by. Set internally.
number
tooltipTooltip element.
ReactElement<ChartTooltipProps, FC<Partial<ChartTooltipProps>>>
<ChartTooltip />
inverseWhether to inverse the data or not.
boolean
true
onValueEnterWhen pointer entered mouse area.
(event: TooltipAreaEvent) => void
() => undefined
onValueLeaveWhen pointer left mouse area.
() => void
() => undefined
isHorizontalWhether the layout is horizontal or not.
boolean
startAngleStart angle for the first value.
number
0
endAngleEnd angle for the last value.
number
2 * Math.PI
refAllows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs}
LegacyRef<any>
key
Key

ChartTooltip Example

The Calendar Heatmap is a good example of chart tooltip:

<HeatmapCell
  tooltip={
    <ChartTooltip
      content={d =>
        `${formatValue(d.data.metadata.date)}${formatValue(
          d.data.value
        )}`
      }
    />
  }
/>

In this example above, the component overrides the tooltip to format the date for a Calendar format.

API

ChartTooltip (opens in a new tab)

PropDescriptionDefault
contentContent for the tooltip.
any
<TooltipTemplate />
valueTooltip data value.
any
colorColor scheme to apply.
any
dataComplete dataset.
any
followCursorWhether the tooltip should move with the cursor or not.
boolean
childrenContent to wrap.
ReactNode
closeOnClickClose on any click.
boolean
closeOnBodyClickClose when the body is clicked.
boolean
closeOnEscapeClose when escape key is triggered.
boolean
referenceReference of the tooltip to align to.
any
placementfloating-ui placement.
Placement
enterDelayDelay before showing tooltip.
number
leaveDelayDelay before closing tooltip.
number
modifiersfloating-ui modifiers.
Modifiers
visibleExternal setter for visibility.
boolean
classNameAdditional CSS classnames.
string
triggerClassNameCSS Classname for the tooltip container ( ie. the thing that the tooltip is bound to ).
string
triggerHow the tooltip will be triggered.
TriggerTypes | TriggerTypes[]
disabledWhether the tooltip is disabled.
boolean
pointerEventsAdd pointer events or not. Usually not for tooltips.
string
isPopoverDifferentiator for popovers to be handled separate from tooltips
boolean
onOpenTooltip was opened.
() => void
onCloseTooltip was closed.
() => void
themeTheme for the tooltip.
TooltipTheme

Custom Tooltips

You can also override tooltips and handle them yourself manually. Below is an example of overriding the onMouseEnter and onMouseLeave in the VennDiagram component to handle displaying what would be in the tooltip in a custom panel below the chart.

const Venn = () => {
  const [active, setActive] = useState<any | null>(null);
 
  return (
    <>
      <VennDiagram
        type="starEuler"
        data={data}
        height={275}
        series={
          <VennSeries
            arc={
              <VennArc
                onMouseEnter={({ value }) => {
                  setActive(`${value.sets.join(' & ')} - ${value.size.toLocaleString()}`);
                }}
                onMouseLeave={() => setActive(null)}
              />
            }
          />
        }
      />
      {active !== null && (
        <p>{active}</p>
      )}
    </>
  );
};