@dreamcatcher-tech/commit-graph

中文文档
2.2.9发布于 2024/09/27MITTypeScriptESM + CJS近 30 天下载 1.9万

一个可视化承诺图的反射组件.

中文使用文档
文档目录18 节
  1. 概览
  2. 演示
  3. 特征
  4. 安装
  5. 快速启动
  6. 使用提交图形
  7. 使用 Co通Graph 。 无限滚动
  8. 道具
  9. Communication Graph 和 Communication Graph 的通用道具 。 无限滚动
  10. CommitGraph 的附加道具 。 无限滚动
  11. 类型定义
  12. Commit 类型
  13. Branch 类型
  14. graphStyle (对象,可选)
  15. dateFormatFn (职能,可选)
  16. currentBranch (弦,可选)
  17. fullSha (boolean,可选)
  18. 故事书

提交图表

readme-header

License

概览

Contition Graph 包是一个 React 组件套件,旨在以互动和信息化的方式可视化承诺图. 它展示一个存储器内的历史,支持无限地加载卷轴。 见 这个员额 详细执行情况.

CommitGraph 用于平台,如 多尔特湖 可视化数据库输入日志历史.

演示

这个 演示 特性样本输入数据和真实的 GitHub 寄存器图表.

特征

  • 交互式提交图形可视化 : Render将历史作为互动图来承诺,对存储处的活动提供了清晰而详细的视角.
  • 无限滚动支持 : CommitGraph.WithInfiniteScroll 通过在用户滚动时动态地加载新内容来增强大型承诺历史的用户经验.
  • 自定义样式 : 用于承诺日志图的广泛样式选项,包括节点颜色,间隔等,以无缝匹配项目的设计.

安装

npm install commit-graph

快速启动

使用提交图形

对于没有无限卷轴的基本执行:

import React from "react";
import { CommitGraph } from "commit-graph";

const MyComponent = () => {
  const commits = [
    // Commits data according to the new Commit type
  ];
  const branchHeads = [
    // Branch heads data according to the new Branch type
  ];

  return (
    <CommitGraph
      commits={commits}
      branchHeads={branchHeads}
      graphStyle={{
        commitSpacing: 50,
        branchSpacing: 20,
        branchColors: ["#FF0000", "#00FF00", "#0000FF"],
        nodeRadius: 2,
      }}
    />
  );
};

export default MyComponent;

使用 Co通Graph 。 无限滚动

对于需要无限卷轴处理大型承诺历史的执行:

import React from "react";
import { CommitGraph } from "commit-graph";

const MyComponent = () => {
  // Your commit and branch head data, loadMore function, and hasMore flag
  return (
    <CommitGraph.WithInfiniteScroll
      commits={/* Your commits data */}
      branchHeads={/* Your branch heads data */}
      loadMore={/* Your loadMore function */}
      hasMore={/* hasMore flag */}
    />
  );
};

export default MyComponent;

道具

Communication Graph 和 Communication Graph 的通用道具 。 无限滚动

  • 执行(阵列):数组 Commit 代表承诺历史的天体.
  • 分支头 (阵列): 一组 Branch 在承诺图中代表分支头的物体.

CommitGraph 的附加道具 。 无限滚动

  • 加载更多(函数):在到达滚动端时加载更多任务的函数 .
  • has More (boolean) : 说明是否有更多的承诺可以加载 .

类型定义

这些类型定义应当用于构建传递给CommitGraph和CommitGraph两个指令和分支标题道具的数据. 用"无限滚动"组件,确保承诺历史和分支信息的适当可视化.

Commit 类型

这个 Commit 类型代表个人在犯罪历史中犯罪。 每个 Commit 对象应符合下列结构:

type ParentCommit = {
  sha: string;
};

export type Commit = {
  sha: string;
  commit: {
    author: {
      name: string; // The name of the commit author
      date: string | number | Date; // The date of the commit
      email?: string; // The email of the commit author (optional)
    };
    message: string; // The commit message
  };
  parents: ParentCommit[]; // An array of parent commits
  html_url?: string; // The URL to view the commit (optional)
};

此类型定义包括承诺的SHA,作者信息,承诺消息,父方承诺的数组,以及承诺的可选URL.

Branch 类型

这个 Branch 类型定义寄存器中分支的结构,每个分支与特定承诺相关:

export type Branch = {
  name: string; // The name of the branch
  commit: {
    sha: string; // The SHA of the latest commit on the branch
  };
  link?: string; // A URL to the branch on GitHub (optional)
};

每个分行对象应包括分行名称,分行最新承诺的SHA,以及与分行的可选链接.

graphStyle (对象,可选)

指定执行图的样式选项的可选对象。 这个 graphStyle 对象应具有以下属性:

  • commitSpacing (数目):承诺之间的垂直间隔.
  • branchSpacing (数字):分枝之间的水平间隔.
  • branchColors (串行数): 用于不同分支的颜色阵列。 默认 : ['#FF0000', '#00FF00', '#0000FF']。 。 。 .
  • nodeRadius (数字):承诺节点圈的半径.

dateFormatFn (职能,可选)

格式化输入日期的可选函数 。 以日期、数字或字符串作为输入并返回字符串.

dateFormatFn?: (d: string | number | Date) => string;

示例:

const customDateTimeFormatFn = (d: string | number | Date): string => {
  return new Date(d).toLocaleString('en-US', {
      year: 'numeric',
      month: 'short',
      day: 'numeric',
      hour: '2-digit',
      minute: '2-digit',
      second: '2-digit',
  });
};

const MyComponent = () => {
  // Your commit and branch head data, loadMore function, and hasMore flag
  return (
    <CommitGraph.WithInfiniteScroll
      commits={/* Your commits data */}
      branchHeads={/* Your branch heads data */}
      loadMore={/* Your loadMore function */}
      hasMore={/* hasMore flag */}
      dateFormatFn={customDateTimeFormatFn}
    />
  );
};

currentBranch (弦,可选)

现分行名.

fullSha (boolean,可选)

而非默认缩短了SHA,显示承诺的全部SHA.

故事书

通过运行故事本来探索“提交图”组件及其特性:

npm run storybook

版本与发布记录

@dreamcatcher-tech/commit-graph 共发布 6 个版本,首次发布于 2024/09/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.2.9latest2024/09/272 年前
2.2.82024/09/272 年前
2.2.72024/09/252 年前
2.2.62024/09/202 年前
2.2.52024/09/202 年前
2.2.42024/09/182 年前

关于 @dreamcatcher-tech/commit-graph 的常见问题

@dreamcatcher-tech/commit-graph 是什么?

一个可视化承诺图的反射组件.

如何安装 @dreamcatcher-tech/commit-graph?

在项目目录运行 npm install @dreamcatcher-tech/commit-graph,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0)、react-dom(>=18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dreamcatcher-tech/commit-graph 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dreamcatcher-tech/commit-graph 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dreamcatcher-tech/commit-graph 可以商用吗?

@dreamcatcher-tech/commit-graph 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dreamcatcher-tech/commit-graph 的下载量有多少?

根据 npm 官方下载统计,@dreamcatcher-tech/commit-graph 在 2026/10/13 – 2026/11/11 这 30 天内被下载 19,308 次,日均约 644 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dreamcatcher-tech/commit-graph 还在维护吗?

最新版本 2.2.9 发布于 2024/09/27(2 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/09/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。