You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+98-67Lines changed: 98 additions & 67 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,17 +8,18 @@
8
8
9
9
The Commit Graph package is a React component suite designed to visualize commit graphs in an interactive and informative way. It showcases commit history within a repository with support for infinite scroll loading. See [this post](https://www.dolthub.com/blog/2024-08-07-drawing-a-commit-graph/) for the implementation details.
10
10
11
-
`CommitGraph` is utilized by platforms like [DoltHub](https://www.dolthub.com) to visualize database commit log histories.
11
+
It is used by platforms like [DoltHub](https://www.dolthub.com) to visualize database commit log histories.
12
12
13
13
## Demo
14
14
15
-
The [demo](https://liuliu-dev.github.io/CommitGraph/)features sample commit data and real GitHub repository graphs.
15
+
Explore the [demo](https://liuliu-dev.github.io/CommitGraph/)for sample commit data and real GitHub repository graphs.
16
16
17
17
## Features
18
18
19
-
-**Interactive Commit Graph Visualization:** Render commit history as an interactive graph, offering a clear and detailed view of repository activities.
20
-
-**Infinite Scroll Support:**`CommitGraph.WithInfiniteScroll` enhances the user experience for large commit histories by dynamically loading new content as users scroll.
21
-
-**Customizable Styles:** Extensive styling options for the commit log graph, including node colors, spacing, and more, to seamlessly match your project's design.
19
+
-**Interactive Commit Graph Visualization:** Provides a dynamic visual of commit history with detailed repository activity.
20
+
-**Infinite Scroll Support:**`CommitGraph.WithInfiniteScroll` dynamically loads new content as users scroll through large commit histories.
21
+
-**Customizable Styles:** Easily style the commit log graph, including node colors, spacing, and more.
22
+
-**Diff Stats on Commit Click:** If a `getDiff` function is provided, clicking a commit will display additional file change stats, including additions, deletions, and file modifications.
22
23
23
24
## Installation
24
25
@@ -28,7 +29,7 @@ npm install commit-graph
28
29
29
30
## Quick Start
30
31
31
-
### Using CommitGraph
32
+
### UBasic Usage (without infinite scroll):
32
33
33
34
For a basic implementation without infinite scroll:
34
35
@@ -54,16 +55,29 @@ const MyComponent = () => {
54
55
branchColors: ["#FF0000", "#00FF00", "#0000FF"],
55
56
nodeRadius:2,
56
57
}}
58
+
getDiff={async (base, head) => {
59
+
// Your implementation to fetch diff stats
60
+
return {
61
+
files: [
62
+
{
63
+
filename:"example.txt",
64
+
status:"modified",
65
+
additions:10,
66
+
deletions:2,
67
+
},
68
+
],
69
+
};
70
+
}}
57
71
/>
58
72
);
59
73
};
60
74
61
75
exportdefaultMyComponent;
62
76
```
63
77
64
-
### Using CommitGraph.WithInfiniteScroll
78
+
### Using `CommitGraph.WithInfiniteScroll`
65
79
66
-
For implementations requiring infinite scroll to handle large commit histories:
80
+
For large commit histories requiring infinite scroll:
67
81
68
82
```jsx
69
83
importReactfrom"react";
@@ -89,20 +103,74 @@ export default MyComponent;
89
103
### Common Props for CommitGraph and CommitGraph.WithInfiniteScroll
90
104
91
105
- commits (array): An array of `Commit` objects representing the commit history.
92
-
- branchHeads (array): An array of `Branch` objects representing the branch heads in the commit-graph.
106
+
107
+
- branchHeads (array): An array of `Branch` objects representing the branch heads.
108
+
109
+
- getDiff (function, optional): A function that returns a `Promise` resolving to a [`Diff`](#diff-type) object. Fetches file changes for clicked commits.
110
+
111
+
- currentBranch (string, optional): The name of the current branch.
112
+
113
+
- fullSha (boolean, optional): Displays the full SHA of a commit instead of the shortened SHA.
114
+
115
+
- onCommitClick (function, optional): Function to be called when a commit is clicked, receiving the clicked commit as an argument.
116
+
117
+
- dateFormatFn (function, optional): Formats the commit dates. Accepts a string, number, or Date and returns a formatted string.
// Your commit and branch head data, loadMore function, and hasMore flag
139
+
return (
140
+
<CommitGraph.WithInfiniteScroll
141
+
commits={/* Your commits data */}
142
+
branchHeads={/* Your branch heads data */}
143
+
loadMore={/* Your loadMore function */}
144
+
hasMore={/* hasMore flag */}
145
+
dateFormatFn={customDateTimeFormatFn}
146
+
/>
147
+
);
148
+
};
149
+
150
+
```
151
+
152
+
- graphStyle (object, optional): Customize the graph styling. Example:
153
+
154
+
```typescript
155
+
const graphStyle = {
156
+
commitSpacing: 60,
157
+
branchSpacing: 20,
158
+
nodeRadius: 2,
159
+
branchColors: ["#FF0000", "#00FF00", "#0000FF"],
160
+
};
161
+
```
93
162
94
163
### Additional Props for CommitGraph.WithInfiniteScroll
95
164
96
-
- loadMore (function): Function to load more commits upon reaching the scroll end.
97
-
- hasMore (boolean): Indicates whether more commits are available to load.
165
+
- loadMore (function): Function to load more commits as the user scrolls.
98
166
99
-
## Type Definitions
167
+
- hasMore (boolean): Boolean flag indicating whether more commits are available to load.
100
168
101
-
These type definitions should be used to structure the data passed to the commits and branchHeads props of both CommitGraph and CommitGraph.WithInfiniteScroll components, ensuring proper visualization of commit history and branch information.
169
+
## Type Definitions
102
170
103
171
### `Commit` Type
104
172
105
-
The `Commit` type represents individual commits in the commit history. Each `Commit` object should conform to the following structure:
173
+
Represents individual commits:
106
174
107
175
```typescript
108
176
typeParentCommit= {
@@ -124,11 +192,9 @@ export type Commit = {
124
192
};
125
193
```
126
194
127
-
This type definition includes the commit's SHA, author information, commit message, an array of parent commits, and an optional URL to the commit.
128
-
129
195
### `Branch` Type
130
196
131
-
The `Branch` type defines the structure for branches in the repository, each associated with a particular commit:
197
+
Defines repository branches, each associated with a commit:
132
198
133
199
```typescript
134
200
exporttypeBranch= {
@@ -140,66 +206,31 @@ export type Branch = {
140
206
};
141
207
```
142
208
143
-
Each Branch object should include the branch's name, the SHA of the latest commit on the branch, and an optional link to the branch.
144
-
145
-
### `graphStyle` (object, optional)
209
+
### `Diff` Type
146
210
147
-
An optional object specifying the styling options for the commit-graph. The `graphStyle` object should have the following properties:
148
-
149
-
-`commitSpacing` (number): The vertical spacing between commits.
150
-
-`branchSpacing` (number): The horizontal spacing between branches.
151
-
-`branchColors` (array of strings): An array of colors to be used for different branches. Default: `['#FF0000', '#00FF00', '#0000FF']`.
152
-
-`nodeRadius` (number): The radius of the commit node circles.
153
-
154
-
### `dateFormatFn` (function, optional)
155
-
156
-
An optional function to format commit dates. Takes a Date, number, or string as input and returns a string.
0 commit comments