Skip to content

Tooltips

Most components emit hover data through an onhoverinfo callback. The library includes a Tooltip component that renders this data as a floating panel.

HoverInfo

ts
import type { HoverInfo, InfoItem } from '@molbiohive/hatchlings';
FieldTypeDescription
titlestringTooltip heading (e.g. feature name)
itemsInfoItem[]Rows of label/value pairs
position{ x: number; y: number }Viewport coordinates for positioning

InfoItem

FieldTypeDescription
labelstringLeft-aligned label text
valuestring | numberRight-aligned value
unitstring?Optional unit suffix (e.g. 'bp', '°C')
colorstring?Optional CSS color for the value

Tooltip Component

Tooltip renders a HoverInfo object as a themed floating panel with viewport clamping.

Props

PropTypeDefaultDescription
visiblebooleanfalseShow/hide the tooltip
xnumber0Viewport X position
ynumber0Viewport Y position
titlestringHeading text
itemsInfoItem[][]Data rows
childrenSnippetCustom content (Svelte snippet)

Styling

The tooltip uses CSS custom properties for theming:

VariableDescription
--hatch-tooltip-bgBackground color
--hatch-tooltip-borderBorder color
--hatch-tooltip-textTitle and value text color
--hatch-tooltip-labelLabel text color

Basic Usage

Wire onhoverinfo to state, pass state to Tooltip:

svelte
<script>
  import { PlasmidViewer, Tooltip } from '@molbiohive/hatchlings';
  import type { HoverInfo } from '@molbiohive/hatchlings';

  let hoverInfo: HoverInfo | null = $state(null);
</script>

<PlasmidViewer {data} width={500} height={500} onhoverinfo={(info) => hoverInfo = info} />

<Tooltip
  visible={!!hoverInfo}
  x={hoverInfo?.position.x ?? 0}
  y={hoverInfo?.position.y ?? 0}
  title={hoverInfo?.title}
  items={hoverInfo?.items ?? []}
/>

Source Tracking Pattern

When multiple components share one tooltip, use source tracking to prevent one component from clearing another's tooltip:

svelte
<script>
  import { PlasmidViewer, GelViewer, Tooltip } from '@molbiohive/hatchlings';
  import type { HoverInfo } from '@molbiohive/hatchlings';

  let hoverInfo: HoverInfo | null = $state(null);
  let hoverSource: string | null = $state(null);

  function hoverHandler(source: string) {
    return (info: HoverInfo | null) => {
      if (info) {
        hoverSource = source;
        hoverInfo = info;
      } else if (hoverSource === source) {
        hoverSource = null;
        hoverInfo = null;
      }
    };
  }
</script>

<PlasmidViewer {plasmidData} onhoverinfo={hoverHandler('plasmid')} />
<GelViewer {gelData} onhoverinfo={hoverHandler('gel')} />

<Tooltip
  visible={!!hoverInfo}
  x={hoverInfo?.position.x ?? 0}
  y={hoverInfo?.position.y ?? 0}
  title={hoverInfo?.title}
  items={hoverInfo?.items ?? []}
/>

Only the component that set the hover can clear it — so moving from one component to another doesn't briefly flash the tooltip off.

Custom Tooltip Content

Use the children snippet for custom rendering:

svelte
<Tooltip visible={!!hoverInfo} x={hoverInfo?.position.x ?? 0} y={hoverInfo?.position.y ?? 0}>
  {#snippet children()}
    <div class="my-custom-content">
      <strong>{hoverInfo.title}</strong>
      <p>{hoverInfo.items[0]?.value}</p>
    </div>
  {/snippet}
</Tooltip>

Components with onhoverinfo

ComponentHover targets
PlasmidViewerParts and cut sites
SequenceViewerPositions, features, cut sites
GelViewerBands and lanes
TraceViewerBase calls and quality scores
MultiTraceViewerBase calls and peaks
CloningStrategyViewerCloning nodes and actions
CloningHistoryViewerTree nodes
Most chart componentsData points and series