@akshay-rajput/git-graph-svg 2.0.4 → 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 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
- `GitGraphSVG` renders a commit history with branching and merging
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
- ## ✨ Features
9
+ ---
13
10
 
14
- - 🔀 Automatic branch lane management\
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
  ![Screenshot](https://raw.githubusercontent.com/notakshayrajput/RepositoryGraph/refs/heads/main/images/examples.png)
24
25
 
25
- ## 🚀 Basic Usage
26
+ ![Screenshot](https://raw.githubusercontent.com/notakshayrajput/RepositoryGraph/refs/heads/main/images/examples1.png)
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
- ``` tsx
28
- import { GitGraphSVG, CommitItem } from "./GitGraphSVG";
44
+ # 🚀 Basic Usage
29
45
 
30
- const commits: CommitItem[] = [
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 <GitGraphSVG commits={commits} />;
67
+ return <GitGraph commits={commits} />;
49
68
  }
50
69
  ```
51
70
 
52
- ------------------------------------------------------------------------
53
-
54
- ## 📘 Data Model
71
+ ---
55
72
 
56
- ### CommitItem
73
+ # 📘 Commit Data Model
57
74
 
58
- ``` ts
59
- export interface CommitItem {
60
- id: string;
61
- message: string;
62
- author: string;
63
- date: string;
64
- parents: string[];
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 must reference its parent commit IDs in the `parents` array.
69
-
70
- ------------------------------------------------------------------------
71
-
72
- ## ⚙️ Props
73
-
74
- ``` ts
75
- export interface GitGraphSVGProps {
76
- commits: CommitItem[];
77
-
78
- rowHeight?: number;
79
- laneWidth?: number;
80
- colorPalette?: string[];
81
-
82
- renderNode?: (commit: _CommitItem) => React.ReactNode;
83
-
84
- renderEdge?: (
85
- from: _CommitItem,
86
- to: _CommitItem,
87
- defaultPath: string
88
- ) => React.ReactNode;
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
- ## 🎨 Custom Rendering
116
+ The graph engine handles **layout and branch logic**, while you control how nodes and edges are rendered.
95
117
 
96
- You can override how nodes and edges are rendered.
118
+ ---
97
119
 
98
- ### Custom Nodes
120
+ ## Custom Node Rendering
99
121
 
100
- ``` tsx
101
- <GitGraphSVG
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={commit.cx}
107
- cy={commit.cy}
108
- r={8}
109
- fill="white"
110
- stroke={commit.color}
111
- strokeWidth={3}
130
+ cx={x}
131
+ cy={y}
132
+ r={6}
133
+ fill="none"
134
+ stroke={color}
135
+ strokeWidth={2}
112
136
  />
113
- <text
114
- x={commit.cx}
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
- ### Custom Edges
148
+ ## Custom Edge Rendering
129
149
 
130
- ``` tsx
131
- <GitGraphSVG
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="black"
138
- strokeDasharray="4 2"
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
- ## 🎨 Default Configuration
168
+ ## 🎨 Custom Color Palette
148
169
 
149
- ``` ts
150
- const LANE_WIDTH = 50;
151
- const NODE_RADIUS = 5;
170
+ ```tsx
171
+ <GitGraph
172
+ commits={commits}
173
+ colorPalette={[
174
+ "#8338ec",
175
+ "#ff006e",
176
+ "#fb5607",
177
+ "#ffbe0b"
178
+ ]}
179
+ />
180
+ ```
152
181
 
153
- const COLOR_PALETTE = [
154
- "#3a86ff",
155
- "#8338ec",
156
- "#ff006e",
157
- "#fb5607",
158
- "#ffbe0b"
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
- If more branches exist than available colors, random colors are
163
- generated automatically.
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
- ## 📏 Layout Rules
275
+ * Straight lines when commits stay in the same lane
276
+ * Smooth curves when switching lanes
277
+ * Colors follow branch lineage
168
278
 
169
- - Vertical spacing = `rowHeight`
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
- ## 🔄 Merge & Branch Handling
283
+ `git-graph-svg` is designed as a **rendering engine**, not a UI component.
177
284
 
178
- - Straight lines are drawn when commits stay in the same lane.
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
- ## 🧠 Design Philosophy
292
+ You control the **visual layer**.
186
293
 
187
- `GitGraphSVG` is designed as a **rendering engine**, not a UI component.
294
+ This makes it easy to integrate with:
188
295
 
189
- It: - Calculates layout - Assigns lanes and colors - Generates edge
190
- paths - Exposes rendering hooks
296
+ * Git visualizers
297
+ * CI/CD dashboards
298
+ * repository browsers
299
+ * build pipeline UIs
191
300
 
192
- You control the visual layer.
301
+ ---
193
302
 
194
- ------------------------------------------------------------------------
303
+ # 🚀 Future Enhancements
195
304
 
196
- ## 🚀 Possible Future Enhancements
305
+ Possible upcoming improvements:
197
306
 
198
- - Animations
199
- - Hover interactions
200
- - Zoom & pan
201
- - Horizontal layout support
202
- - Stepped lane transitions
203
- - Commit grouping
204
- - Performance optimization for large graphs
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
- ## 📜 License
317
+ # 📜 License
209
318
 
210
319
  MIT
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@akshay-rajput/git-graph-svg",
3
+ "description": "Lightweight SVG-based Git commit graph renderer for React with automatic branch layout.",
3
4
  "private": false,
4
- "version": "2.0.4",
5
- "main": "dist/git-repo-graph.umd.js",
6
- "module": "dist/git-repo-graph.es.js",
5
+ "version": "2.0.5",
6
+ "main": "dist/git-graph-svg.umd.js",
7
+ "module": "dist/git-graph-svg.es.js",
7
8
  "types": "dist/index.d.ts",
8
9
  "type": "module",
9
10
  "license": "MIT",
@@ -13,10 +14,29 @@
13
14
  "files": [
14
15
  "dist"
15
16
  ],
17
+ "author": {
18
+ "name": "Akshay Rajput",
19
+ "url": "https://github.com/notakshayrajput"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/notakshayrajput/RepositoryGraph/issues"
23
+ },
16
24
  "peerDependencies": {
17
- "react": "^18.0.0",
18
- "react-dom": "^18.0.0"
25
+ "react": ">=18.0.0",
26
+ "react-dom": ">=18.0.0"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "import": "./dist/git-graph-svg.es.js",
31
+ "require": "./dist/git-graph-svg.umd.js",
32
+ "types": "./dist/index.d.ts"
33
+ }
19
34
  },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/notakshayrajput/RepositoryGraph.git"
38
+ },
39
+ "homepage": "https://github.com/notakshayrajput/RepositoryGraph",
20
40
  "scripts": {
21
41
  "dev": "vite",
22
42
  "build": "tsc -b && vite build",
@@ -41,5 +61,16 @@
41
61
  },
42
62
  "dependencies": {
43
63
  "delaunator": "^5.0.1"
44
- }
64
+ },
65
+ "keywords": [
66
+ "git",
67
+ "git graph",
68
+ "git visualization",
69
+ "react git graph",
70
+ "commit graph",
71
+ "git branch graph",
72
+ "git history visualization",
73
+ "react svg graph"
74
+ ],
75
+ "sideEffects": false
45
76
  }