开发预览 更新于 2026-05-10

LatencyHeatmap 延迟热力图

二维矩阵热力图,绿→黄→红 OKLCH 色相 lerp。

基础用法

数据通过 props 传入,纯 SVG 渲染,无第三方图表库依赖。 配色取自 --viz-1..8 token,色盲友好。

背景 视口
SunMonTueWedThuFriSat0h4h8h12h16h20h
src/App.vue
<script setup lang="ts">
import { CfLatencyHeatmap } from '@chufix-design/vue';
function row(day: number) {
  return Array.from({ length: 24 }, (_, hour) => 80 + ((day * 47 + hour * 31) % 320));
}
const data = Array.from({ length: 7 }, (_, day) => row(day));
const rowLabels = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
const colLabels = Array.from({ length: 24 }, (_, i) => i % 4 === 0 ? `${i}h` : '');
</script>
<template>
  <CfLatencyHeatmap :data="data" :row-labels="rowLabels" :col-labels="colLabels" />
</template>
<script setup>
import { CfLatencyHeatmap } from '@chufix-design/vue';
function row(day) {
  return Array.from({ length: 24 }, (_, hour) => 80 + ((day * 47 + hour * 31) % 320));
}
const data = Array.from({ length: 7 }, (_, day) => row(day));
const rowLabels = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
const colLabels = Array.from({ length: 24 }, (_, i) => i % 4 === 0 ? `${i}h` : '');
</script>
<template>
  <CfLatencyHeatmap :data="data" :row-labels="rowLabels" :col-labels="colLabels" />
</template>
import { CfLatencyHeatmap } from '@chufix-design/react';

export default function Demo() {
  function row(day: number) {
    return Array.from({ length: 24 }, (_, hour) => 80 + ((day * 47 + hour * 31) % 320));
  }
  const data = Array.from({ length: 7 }, (_, day) => row(day));
  const rowLabels = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
  const colLabels = Array.from({ length: 24 }, (_, i) => i % 4 === 0 ? `${i}h` : '');
  return (
    <>
      <CfLatencyHeatmap data={data} rowLabels={rowLabels} colLabels={colLabels} />
    </>
  );
}
import { CfLatencyHeatmap } from '@chufix-design/react';

export default function Demo() {
  function row(day) {
    return Array.from({ length: 24 }, (_, hour) => 80 + ((day * 47 + hour * 31) % 320));
  }
  const data = Array.from({ length: 7 }, (_, day) => row(day));
  const rowLabels = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
  const colLabels = Array.from({ length: 24 }, (_, i) => i % 4 === 0 ? `${i}h` : '');
  return (
    <>
      <CfLatencyHeatmap data={data} rowLabels={rowLabels} colLabels={colLabels} />
    </>
  );
}

一周 × 24 小时

行 = 周一到周日,列 = 小时。颜色映射到 oklch(70% 0.16 H) 中 H 从 152(绿)→ 78(黄)→ 22(红)。

背景 视口
MonTueWedThuFriSatSun0h4h8h12h16h20h
src/App.vue
<script setup lang="ts">
import { CfLatencyHeatmap } from '@chufix-design/vue';
function row(peakHour: number) {
  return Array.from({ length: 24 }, (_, h) => {
    const dist = Math.abs(h - peakHour);
    return 80 + (24 - dist) * 12 + ((h * 17 + peakHour * 11) % 60);
  });
}
const data = [row(15), row(15), row(15), row(16), row(15), row(13), row(13)];
const rowLabels = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
const colLabels = Array.from({ length: 24 }, (_, i) => i % 4 === 0 ? `${i}h` : '');
</script>
<template>
  <CfLatencyHeatmap :data="data" :row-labels="rowLabels" :col-labels="colLabels" :height="220" />
</template>
<script setup>
import { CfLatencyHeatmap } from '@chufix-design/vue';
function row(peakHour) {
  return Array.from({ length: 24 }, (_, h) => {
    const dist = Math.abs(h - peakHour);
    return 80 + (24 - dist) * 12 + ((h * 17 + peakHour * 11) % 60);
  });
}
const data = [row(15), row(15), row(15), row(16), row(15), row(13), row(13)];
const rowLabels = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
const colLabels = Array.from({ length: 24 }, (_, i) => i % 4 === 0 ? `${i}h` : '');
</script>
<template>
  <CfLatencyHeatmap :data="data" :row-labels="rowLabels" :col-labels="colLabels" :height="220" />
</template>
import { CfLatencyHeatmap } from '@chufix-design/react';

export default function Demo() {
  function row(peakHour: number) {
    return Array.from({ length: 24 }, (_, h) => {
      const dist = Math.abs(h - peakHour);
      return 80 + (24 - dist) * 12 + ((h * 17 + peakHour * 11) % 60);
    });
  }
  const data = [row(15), row(15), row(15), row(16), row(15), row(13), row(13)];
  const rowLabels = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
  const colLabels = Array.from({ length: 24 }, (_, i) => i % 4 === 0 ? `${i}h` : '');
  return (
    <>
      <CfLatencyHeatmap data={data} rowLabels={rowLabels} colLabels={colLabels} height={220} />
    </>
  );
}
import { CfLatencyHeatmap } from '@chufix-design/react';

export default function Demo() {
  function row(peakHour) {
    return Array.from({ length: 24 }, (_, h) => {
      const dist = Math.abs(h - peakHour);
      return 80 + (24 - dist) * 12 + ((h * 17 + peakHour * 11) % 60);
    });
  }
  const data = [row(15), row(15), row(15), row(16), row(15), row(13), row(13)];
  const rowLabels = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
  const colLabels = Array.from({ length: 24 }, (_, i) => i % 4 === 0 ? `${i}h` : '');
  return (
    <>
      <CfLatencyHeatmap data={data} rowLabels={rowLabels} colLabels={colLabels} height={220} />
    </>
  );
}

API

属性类型默认值说明
datanumber[][]rows × cols 数值矩阵
rowLabels / colLabelsstring[]
min / maxnumber自动颜色映射区间
widthnumber480SVG 宽度
heightnumber240SVG 高度
ariaLabelstring透传给根 <svg>aria-label

Events

Vue 事件React 回调载荷类型说明
item-enteronItemEnterLatencyHeatmapInteractionPayload鼠标进入某格时触发
item-leaveonItemLeaveLatencyHeatmapInteractionPayload鼠标离开某格时触发

类型

interface LatencyHeatmapInteractionPayload {
  row: number;
  col: number;
  value: number;
  rowLabel?: string;
  colLabel?: string;
  nativeEvent?: PointerEvent;
}

反馈与讨论

LatencyHeatmap 延迟热力图 的讨论

0
0 / 600
正在加载评论...