Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

1.7 KB
Raw Blame
import { Component, Show } from 'solid-js';
import {
  formatHistoryChartTooltipValue,
  getHistoryChartTooltipLayout,
  type HistoryChartHoverPoint,
} from './historyChartModel';

interface HistoryChartTooltipProps {
  hoveredPoint: HistoryChartHoverPoint | null;
  chartWidth: number;
  chartHeight: number;
  unit?: string;
}

export const HistoryChartTooltip: Component<HistoryChartTooltipProps> = (props) => {
  return (
    <svg
      class="pointer-events-none absolute left-0 top-0 overflow-visible"
      width={props.chartWidth}
      height={props.chartHeight}
      viewBox={`0 0 ${props.chartWidth} ${props.chartHeight}`}
      aria-hidden="true"
    >
      <Show when={props.hoveredPoint}>
        {(point) => {
          const layout = () =>
            getHistoryChartTooltipLayout({
              hoveredPoint: point(),
              chartWidth: props.chartWidth,
              chartHeight: props.chartHeight,
            });
          return (
            <foreignObject
              x={layout().x}
              y={layout().y}
              width={layout().width}
              height={layout().height}
              overflow="visible"
            >
              <div
                data-history-chart-tooltip="true"
                class="h-full w-full rounded-sm border border-border bg-surface px-2 py-1 text-xs text-base-content shadow-lg"
              >
                <div class="mb-0.5 text-center font-medium">
                  {new Date(point().timestamp).toLocaleString()}
                </div>
                <div class="text-muted">
                  {formatHistoryChartTooltipValue(point().value, props.unit)}
                </div>
              </div>
            </foreignObject>
          );
        }}
      </Show>
    </svg>
  );
};