-
Notifications
You must be signed in to change notification settings - Fork 363
/
6-custom-renders.stories.tsx
303 lines (279 loc) 路 8.75 KB
/
6-custom-renders.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import * as React from "react";
import { storiesOf } from "@storybook/react";
import {
createGitgraph,
CommitOptions,
BranchOptions,
TagOptions,
Mode,
Orientation,
TemplateName,
templateExtend,
} from "@gitgraph/js";
import {
GraphContainer,
createFixedHashGenerator,
createSvg,
createG,
createPath,
createText,
createForeignObject,
} from "../helpers";
const withoutBranchLabels = templateExtend(TemplateName.Metro, {
branch: { label: { display: false } },
});
const renderSax: CommitOptions["renderDot"] = (commit) =>
createSvg({
height: 30,
width: 30,
viewBox: "0 0 71.84 75.33",
children: [
createG({
fill: commit.style.dot.color || "",
stroke: "white",
strokeWidth: 2,
children: [
createPath({
d:
"M68.91,35.38c4.08-1.15,3.81-3-.22-3.75-3.1-.7-18.24-5.75-20.71-6.74-2.15-1-4.67-.12-1,3.4,4,3.53,1.36,8.13,2.79,13.47C50.6,44.89,52.06,49,56,55.62c2.09,3.48,1.39,6.58-1.42,6.82-1.25.28-3.39-1.33-3.33-3.82h0L44.68,43.79c1.79-1.1,2.68-3,2-4.65s-2.5-2.29-4.46-1.93l-1.92-4.36a3.79,3.79,0,0,0,1.59-4.34c-.62-1.53-2.44-2.27-4.37-2L36,22.91c1.65-1.12,2.46-3,1.83-4.52a3.85,3.85,0,0,0-4.37-1.95c-.76-1.68-2.95-6.89-4.89-10.73C26.45,1.3,20.61-2,16.47,1.36c-5.09,4.24-1.46,9-6.86,12.92l2.05,5.35a18.58,18.58,0,0,0,2.54-2.12c1.93-2.14,3.28-6.46,3.28-6.46s1-4,2.2-.57c1.48,3.15,16.59,47.14,16.59,47.14a1,1,0,0,0,0,.11c.37,1.48,5.13,19,19.78,17.52,4.38-.52,6-1.1,9.14-3.83,3.49-2.71,5.75-6.08,5.91-12.62.12-4.67-6.22-12.62-5.81-17S66.71,36,68.91,35.38Z",
}),
createPath({
d:
"M2.25,14.53A28.46,28.46,0,0,1,0,17.28s3,4.75,9.58,3a47.72,47.72,0,0,0-1.43-5A10.94,10.94,0,0,1,2.25,14.53Z",
}),
],
}),
],
});
const renderLongMessage: CommitOptions["renderMessage"] = (commit) => {
return createG({
translate: { x: 0, y: commit.style.dot.size },
children: [
createText({
fill: commit.style.dot.color,
content: `${commit.hashAbbrev} - ${commit.subject}`,
}),
createForeignObject({
width: 600,
translate: { x: 10, y: 0 },
content: `
My money's in that office, right? If she start giving me some
bullshit about it ain't there, and we got to go someplace else and
get it, I'm gonna shoot you in the head then and there. Then I'm
gonna shoot that bitch in the kneecaps, find out where my goddamn
money is. She gonna tell me too. Hey, look at me when I'm talking
to you, motherfucker. You listen: we go in there, and that nigga
Winston or anybody else is in there, you the first motherfucker to
get shot. You understand?
`,
}),
],
});
};
storiesOf("gitgraph-js/6. Custom renders", module)
.add("with render dot", () => (
<GraphContainer>
{(graphContainer) => {
const renderDot: CommitOptions["renderDot"] = (commit) =>
renderSax(commit);
const gitgraph = createGitgraph(graphContainer, {
generateCommitHash: createFixedHashGenerator(),
});
gitgraph
.commit({ subject: "Initial commit" })
.commit({ subject: "Another commit" })
.commit({
subject: "Do something crazy",
renderDot,
});
gitgraph
.branch("dev")
.commit({
subject: "Oh my god",
renderDot,
})
.commit({
subject: "This is a saxo!",
renderDot,
});
}}
</GraphContainer>
))
.add("with render tooltip", () => (
<GraphContainer>
{(graphContainer) => {
const renderTooltip: CommitOptions["renderTooltip"] = (commit) => {
const commitSize = commit.style.dot.size * 2;
return createG({
translate: { x: commitSize + 10, y: commitSize / 2 },
children: [
renderSax(commit),
createText({
translate: { x: 40, y: 15 },
fill: commit.style.dot.color,
content: `${commit.hashAbbrev} - ${commit.subject}`,
}),
],
});
};
const gitgraph = createGitgraph(graphContainer, {
generateCommitHash: createFixedHashGenerator(),
mode: Mode.Compact,
template: withoutBranchLabels,
});
gitgraph
.commit({ subject: "Initial commit" })
.commit({ subject: "Another commit" })
.commit({
subject: "Do something crazy",
renderTooltip,
});
gitgraph
.branch("dev")
.commit({
subject: "Oh my god",
renderTooltip,
})
.commit({
subject: "This is a saxo!",
renderTooltip,
});
}}
</GraphContainer>
))
.add("with render message", () => (
<GraphContainer>
{(graphContainer) => {
const renderMessage: CommitOptions["renderMessage"] = (commit) => {
return createText({
translate: { x: 0, y: commit.style.dot.size },
fill: commit.style.dot.color,
content: `${commit.hashAbbrev} - ${commit.subject}`,
});
};
const gitgraph = createGitgraph(graphContainer, {
generateCommitHash: createFixedHashGenerator(),
});
gitgraph
.commit({ subject: "Initial commit" })
.commit({ subject: "Another commit" })
.commit({
subject: "Do something crazy",
renderMessage,
});
gitgraph
.branch("dev")
.commit({
subject: "Oh my god",
renderMessage,
})
.commit({
subject: "This is a saxo!",
renderMessage,
});
}}
</GraphContainer>
))
.add("with render message (long)", () => (
<GraphContainer>
{(graphContainer) => {
const gitgraph = createGitgraph(graphContainer, {
generateCommitHash: createFixedHashGenerator(),
});
gitgraph
.commit({ subject: "Initial commit" })
.commit({ subject: "Another commit" })
.commit({
subject: "Do something crazy",
renderMessage: renderLongMessage,
});
gitgraph
.branch("dev")
.commit({
subject: "Oh my god",
})
.commit({
subject: "This is a saxo!",
});
}}
</GraphContainer>
))
.add("with render message (long & reverse orientation)", () => (
<GraphContainer>
{(graphContainer) => {
const gitgraph = createGitgraph(graphContainer, {
generateCommitHash: createFixedHashGenerator(),
orientation: Orientation.VerticalReverse,
});
gitgraph
.commit({ subject: "Initial commit" })
.commit({ subject: "Another commit" })
.commit({
subject: "Do something crazy",
renderMessage: renderLongMessage,
});
gitgraph
.branch("dev")
.commit({
subject: "Oh my god",
})
.commit({
subject: "This is a saxo!",
});
}}
</GraphContainer>
))
.add("with render branch label", () => {
const renderLabel: BranchOptions["renderLabel"] = (branch) => {
return createText({
content: `馃幏 ${branch.name}`,
fill: branch.style.label.color,
font: branch.style.label.font,
translate: {
x: 0,
y: 20,
},
rotate: -15,
});
};
return (
<GraphContainer>
{(graphContainer) => {
const gitgraph = createGitgraph(graphContainer, {
generateCommitHash: createFixedHashGenerator(),
});
gitgraph
.branch({ name: "master", renderLabel })
.commit("Initial commit")
.commit("Another commit")
.commit("Do something crazy");
gitgraph
.branch({ name: "dev", renderLabel })
.commit("Oh my god")
.commit("Last commit of the branch");
}}
</GraphContainer>
);
})
.add("with render tag", () => {
const renderTag: TagOptions["render"] = (name, style) => {
return createText({
content: `馃幏 ${name}`,
font: style.font,
fill: style.bgColor,
});
};
return (
<GraphContainer>
{(graphContainer) => {
const gitgraph = createGitgraph(graphContainer, {
generateCommitHash: createFixedHashGenerator(),
});
gitgraph
.branch("master")
.commit("Initial commit")
.tag({ name: "v1.0", render: renderTag });
}}
</GraphContainer>
);
});