@akshay-rajput/git-graph-svg 2.0.3 β 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +229 -120
- package/dist/components/GitGraph/GitGraph.d.ts +7 -1
- package/dist/components/GitGraph/util.d.ts +1 -1
- package/dist/git-graph-svg.es.js +950 -0
- package/dist/git-graph-svg.umd.js +14 -0
- package/package.json +37 -6
- package/dist/git-repo-graph.es.js +0 -932
- package/dist/git-repo-graph.umd.js +0 -14
package/README.md
CHANGED
|
@@ -1,33 +1,52 @@
|
|
|
1
1
|
# GitGraphSVG
|
|
2
2
|
|
|
3
|
-
A lightweight, customizable **SVG-based Git commit graph renderer for
|
|
4
|
-
React**.
|
|
3
|
+
A lightweight, customizable **SVG-based Git commit graph renderer for React**.
|
|
5
4
|
|
|
6
|
-
`
|
|
7
|
-
support, automatic lane allocation, and customizable node/edge
|
|
8
|
-
rendering.
|
|
5
|
+
`git-graph-svg` renders a Git-style commit history with branching and merging support, automatic lane allocation, and fully customizable node and edge rendering.
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
Built for **flexibility, performance, and zero dependencies**.
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
---
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
- π¨ Customizable color palette\
|
|
16
|
-
- π§© Render overrides (`renderNode`, `renderEdge`)\
|
|
17
|
-
- π Fully SVG-based (no canvas)\
|
|
18
|
-
- β‘ Lightweight & dependency-free
|
|
11
|
+
# β¨ Features
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
* π Automatic branch lane management
|
|
14
|
+
* π¨ Customizable branch color palettes
|
|
15
|
+
* π§© Fully customizable node and edge rendering
|
|
16
|
+
* π Pure SVG rendering (no canvas)
|
|
17
|
+
* β‘ Lightweight & dependency-free
|
|
18
|
+
* πΏ Supports complex branch & merge histories
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
# π Screenshots
|
|
21
23
|
|
|
22
|
-
## π Screenshots
|
|
23
24
|

|
|
24
25
|
|
|
25
|
-
|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
# π¦ Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install git-graph-svg
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
or
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
yarn add git-graph-svg
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
26
43
|
|
|
27
|
-
|
|
28
|
-
import { GitGraphSVG, CommitItem } from "./GitGraphSVG";
|
|
44
|
+
# π Basic Usage
|
|
29
45
|
|
|
30
|
-
|
|
46
|
+
```tsx
|
|
47
|
+
import { GitGraph, type ICommitItem } from "git-graph-svg";
|
|
48
|
+
|
|
49
|
+
const commits: ICommitItem[] = [
|
|
31
50
|
{
|
|
32
51
|
id: "a1",
|
|
33
52
|
message: "Initial commit",
|
|
@@ -45,77 +64,78 @@ const commits: CommitItem[] = [
|
|
|
45
64
|
];
|
|
46
65
|
|
|
47
66
|
export default function App() {
|
|
48
|
-
return <
|
|
67
|
+
return <GitGraph commits={commits} />;
|
|
49
68
|
}
|
|
50
69
|
```
|
|
51
70
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
## π Data Model
|
|
71
|
+
---
|
|
55
72
|
|
|
56
|
-
|
|
73
|
+
# π Commit Data Model
|
|
57
74
|
|
|
58
|
-
```
|
|
59
|
-
export interface
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
75
|
+
```ts
|
|
76
|
+
export interface ICommitItem {
|
|
77
|
+
id: string;
|
|
78
|
+
message: string;
|
|
79
|
+
author: string;
|
|
80
|
+
date: string;
|
|
81
|
+
parents: string[];
|
|
82
|
+
meta?: any;
|
|
65
83
|
}
|
|
66
84
|
```
|
|
67
85
|
|
|
68
|
-
Each commit
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
Each commit references its parent commit IDs in the `parents` array.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
# βοΈ Component Props
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
interface GitGraphProps {
|
|
94
|
+
commits: ICommitItem[];
|
|
95
|
+
colorPalette?: string[];
|
|
96
|
+
padding?: {
|
|
97
|
+
left: number;
|
|
98
|
+
right: number;
|
|
99
|
+
bottom: number;
|
|
100
|
+
top: number;
|
|
101
|
+
} | number;
|
|
102
|
+
rowHeight?: number;
|
|
103
|
+
laneWidth?: number;
|
|
104
|
+
style?: React.CSSProperties;
|
|
105
|
+
renderNode?: (x: number, y: number, color: string, commit: ICommitItem) => ReactNode;
|
|
106
|
+
renderEdge?: (from: ICommitItem, to: ICommitItem, d: string, color: string) => ReactNode;
|
|
107
|
+
getMergeCurve?: (x1: number, y1: number, x2: number, y2: number) => string;
|
|
108
|
+
getBranchSplitCurve?: (x1: number, y1: number, x2: number, y2: number) => string;
|
|
89
109
|
}
|
|
90
110
|
```
|
|
91
111
|
|
|
92
|
-
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
# π¨ Custom Rendering
|
|
93
115
|
|
|
94
|
-
|
|
116
|
+
The graph engine handles **layout and branch logic**, while you control how nodes and edges are rendered.
|
|
95
117
|
|
|
96
|
-
|
|
118
|
+
---
|
|
97
119
|
|
|
98
|
-
|
|
120
|
+
## Custom Node Rendering
|
|
99
121
|
|
|
100
|
-
```
|
|
101
|
-
<
|
|
122
|
+
```tsx
|
|
123
|
+
<GitGraph
|
|
102
124
|
commits={commits}
|
|
103
|
-
renderNode={(commit) => (
|
|
125
|
+
renderNode={(x, y, color, commit) => (
|
|
104
126
|
<g key={commit.id}>
|
|
127
|
+
<circle cx={x} cy={y} r={3} fill={color} />
|
|
128
|
+
|
|
105
129
|
<circle
|
|
106
|
-
cx={
|
|
107
|
-
cy={
|
|
108
|
-
r={
|
|
109
|
-
fill="
|
|
110
|
-
stroke={
|
|
111
|
-
strokeWidth={
|
|
130
|
+
cx={x}
|
|
131
|
+
cy={y}
|
|
132
|
+
r={6}
|
|
133
|
+
fill="none"
|
|
134
|
+
stroke={color}
|
|
135
|
+
strokeWidth={2}
|
|
112
136
|
/>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
y={commit.cy - 10}
|
|
116
|
-
textAnchor="middle"
|
|
117
|
-
fontSize={10}
|
|
118
|
-
>
|
|
137
|
+
|
|
138
|
+
<text x={x + 20} y={y}>
|
|
119
139
|
{commit.id}
|
|
120
140
|
</text>
|
|
121
141
|
</g>
|
|
@@ -123,88 +143,177 @@ You can override how nodes and edges are rendered.
|
|
|
123
143
|
/>
|
|
124
144
|
```
|
|
125
145
|
|
|
126
|
-
|
|
146
|
+
---
|
|
127
147
|
|
|
128
|
-
|
|
148
|
+
## Custom Edge Rendering
|
|
129
149
|
|
|
130
|
-
```
|
|
131
|
-
<
|
|
150
|
+
```tsx
|
|
151
|
+
<GitGraph
|
|
132
152
|
commits={commits}
|
|
133
|
-
renderEdge={(from, to, path) => (
|
|
153
|
+
renderEdge={(from, to, path, color) => (
|
|
134
154
|
<path
|
|
135
155
|
key={`${from.id}-${to.id}`}
|
|
136
156
|
d={path}
|
|
137
|
-
stroke=
|
|
138
|
-
|
|
157
|
+
stroke={color}
|
|
158
|
+
strokeWidth={2}
|
|
139
159
|
fill="none"
|
|
160
|
+
strokeDasharray="5,5"
|
|
140
161
|
/>
|
|
141
162
|
)}
|
|
142
163
|
/>
|
|
143
164
|
```
|
|
144
165
|
|
|
145
|
-
|
|
166
|
+
---
|
|
146
167
|
|
|
147
|
-
## π¨
|
|
168
|
+
## π¨ Custom Color Palette
|
|
148
169
|
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
|
|
170
|
+
```tsx
|
|
171
|
+
<GitGraph
|
|
172
|
+
commits={commits}
|
|
173
|
+
colorPalette={[
|
|
174
|
+
"#8338ec",
|
|
175
|
+
"#ff006e",
|
|
176
|
+
"#fb5607",
|
|
177
|
+
"#ffbe0b"
|
|
178
|
+
]}
|
|
179
|
+
/>
|
|
180
|
+
```
|
|
152
181
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
182
|
+
If the number of active branches exceeds the palette size, additional colors are generated automatically.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## π§ͺ Example: Multiple Graph Styles
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { useMemo } from "react";
|
|
190
|
+
import { GitGraph, type ICommitItem } from "git-graph-svg";
|
|
191
|
+
import { heavyCommitDataset } from "./type";
|
|
192
|
+
|
|
193
|
+
function App() {
|
|
194
|
+
const commits = useMemo(
|
|
195
|
+
() =>
|
|
196
|
+
heavyCommitDataset.sort(
|
|
197
|
+
(a: any, b: any) =>
|
|
198
|
+
new Date(b.date).getTime() - new Date(a.date).getTime()
|
|
199
|
+
),
|
|
200
|
+
[heavyCommitDataset]
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<div style={{ display: "flex" }}>
|
|
205
|
+
|
|
206
|
+
{/* Graph with custom nodes and dashed edges */}
|
|
207
|
+
<GitGraph
|
|
208
|
+
commits={commits}
|
|
209
|
+
rowHeight={25}
|
|
210
|
+
laneWidth={25}
|
|
211
|
+
renderNode={(x, y, color, commit) => (
|
|
212
|
+
<g key={commit.id}>
|
|
213
|
+
<circle cx={x} cy={y} r={3} fill={color} />
|
|
214
|
+
<circle
|
|
215
|
+
cx={x}
|
|
216
|
+
cy={y}
|
|
217
|
+
r={6}
|
|
218
|
+
fill="none"
|
|
219
|
+
stroke={color}
|
|
220
|
+
strokeWidth={2}
|
|
221
|
+
/>
|
|
222
|
+
<text x={x + 20} y={y}>
|
|
223
|
+
{commit.id}
|
|
224
|
+
</text>
|
|
225
|
+
</g>
|
|
226
|
+
)}
|
|
227
|
+
renderEdge={(from, to, d, color) => (
|
|
228
|
+
<path
|
|
229
|
+
key={`${from.id}-${to.id}`}
|
|
230
|
+
d={d}
|
|
231
|
+
stroke={color}
|
|
232
|
+
strokeWidth={2}
|
|
233
|
+
fill="none"
|
|
234
|
+
strokeDasharray="5,5"
|
|
235
|
+
/>
|
|
236
|
+
)}
|
|
237
|
+
/>
|
|
238
|
+
|
|
239
|
+
{/* Default graph */}
|
|
240
|
+
<GitGraph commits={commits} rowHeight={35} laneWidth={35} />
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
</div>
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export default App;
|
|
160
248
|
```
|
|
161
249
|
|
|
162
|
-
|
|
163
|
-
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
# π Layout Rules
|
|
253
|
+
|
|
254
|
+
| Property | Description |
|
|
255
|
+
| --------- | ----------------------------------- |
|
|
256
|
+
| rowHeight | Vertical spacing between commits |
|
|
257
|
+
| laneWidth | Horizontal spacing between branches |
|
|
258
|
+
| width | `laneCount * laneWidth` |
|
|
259
|
+
| height | `commitCount * rowHeight` |
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
# π Branch & Merge Handling
|
|
264
|
+
|
|
265
|
+
The engine automatically handles:
|
|
266
|
+
|
|
267
|
+
* Branch creation
|
|
268
|
+
* Branch merging
|
|
269
|
+
* Lane reuse when branches end
|
|
270
|
+
* Multiple parent commits
|
|
271
|
+
* Smooth lane transitions
|
|
164
272
|
|
|
165
|
-
|
|
273
|
+
Rendering rules:
|
|
166
274
|
|
|
167
|
-
|
|
275
|
+
* Straight lines when commits stay in the same lane
|
|
276
|
+
* Smooth curves when switching lanes
|
|
277
|
+
* Colors follow branch lineage
|
|
168
278
|
|
|
169
|
-
|
|
170
|
-
- Horizontal spacing = `laneWidth`
|
|
171
|
-
- SVG width = `lanesCount * laneWidth`
|
|
172
|
-
- SVG height = `commits.length * rowHeight`
|
|
279
|
+
---
|
|
173
280
|
|
|
174
|
-
|
|
281
|
+
# π§ Design Philosophy
|
|
175
282
|
|
|
176
|
-
|
|
283
|
+
`git-graph-svg` is designed as a **rendering engine**, not a UI component.
|
|
177
284
|
|
|
178
|
-
|
|
179
|
-
- Smooth BΓ©zier curves are used when switching lanes.
|
|
180
|
-
- Multiple parents are supported.
|
|
181
|
-
- Lane colors are automatically reassigned when branches end.
|
|
285
|
+
It handles:
|
|
182
286
|
|
|
183
|
-
|
|
287
|
+
* commit layout
|
|
288
|
+
* lane allocation
|
|
289
|
+
* edge path generation
|
|
290
|
+
* color management
|
|
184
291
|
|
|
185
|
-
|
|
292
|
+
You control the **visual layer**.
|
|
186
293
|
|
|
187
|
-
|
|
294
|
+
This makes it easy to integrate with:
|
|
188
295
|
|
|
189
|
-
|
|
190
|
-
|
|
296
|
+
* Git visualizers
|
|
297
|
+
* CI/CD dashboards
|
|
298
|
+
* repository browsers
|
|
299
|
+
* build pipeline UIs
|
|
191
300
|
|
|
192
|
-
|
|
301
|
+
---
|
|
193
302
|
|
|
194
|
-
|
|
303
|
+
# π Future Enhancements
|
|
195
304
|
|
|
196
|
-
|
|
305
|
+
Possible upcoming improvements:
|
|
197
306
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
307
|
+
* animations
|
|
308
|
+
* hover tooltips
|
|
309
|
+
* zoom & pan
|
|
310
|
+
* horizontal layout support
|
|
311
|
+
* commit grouping
|
|
312
|
+
* performance optimizations for large repositories
|
|
313
|
+
* interactive branch highlighting
|
|
205
314
|
|
|
206
|
-
|
|
315
|
+
---
|
|
207
316
|
|
|
208
|
-
|
|
317
|
+
# π License
|
|
209
318
|
|
|
210
319
|
MIT
|
|
@@ -10,11 +10,17 @@ export interface ICommitItem {
|
|
|
10
10
|
export interface GitGraphProps {
|
|
11
11
|
commits: ICommitItem[];
|
|
12
12
|
colorPalette?: string[];
|
|
13
|
+
padding?: {
|
|
14
|
+
left: number;
|
|
15
|
+
right: number;
|
|
16
|
+
bottom: number;
|
|
17
|
+
top: number;
|
|
18
|
+
} | number;
|
|
13
19
|
rowHeight?: number;
|
|
14
20
|
laneWidth?: number;
|
|
15
21
|
style?: React.CSSProperties;
|
|
16
22
|
renderNode?: (x: number, y: number, color: string, commit: ICommitItem) => ReactNode;
|
|
17
|
-
renderEdge?: (d: string, color: string) => ReactNode;
|
|
23
|
+
renderEdge?: (from: ICommitItem, to: ICommitItem, d: string, color: string) => ReactNode;
|
|
18
24
|
getMergeCurve?: (x1: number, y1: number, x2: number, y2: number) => string;
|
|
19
25
|
getBranchSplitCurve?: (x1: number, y1: number, x2: number, y2: number) => string;
|
|
20
26
|
}
|
|
@@ -2,7 +2,7 @@ import { ICommitItem } from './GitGraph';
|
|
|
2
2
|
declare const svgUtils: {
|
|
3
3
|
getCurveTop(x1: number, y1: number, x2: number, y2: number): string;
|
|
4
4
|
getCurveBottom(x1: number, y1: number, x2: number, y2: number): string;
|
|
5
|
-
drawFinalPath(d: string, color: string, width
|
|
5
|
+
drawFinalPath(d: string, color: string, width: number | undefined, from: ICommitItem, to: ICommitItem): import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
drawPoint(x: number, y: number, color: string, commit: ICommitItem): import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
};
|
|
8
8
|
export { svgUtils };
|