-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathc-ramp.vue
311 lines (287 loc) · 9.25 KB
/
c-ramp.vue
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
304
305
306
307
308
309
310
311
<template lang="pug">
.ramp
template(v-if="tframe === 'commit'")
.ramp-padding(
v-bind:style="optimiseTimeline ? {width: `${100 - optimisedPadding * 2}%`, left: `${optimisedPadding}%`} : ''"
)
template(v-for="(slice, j) in user.commits")
template(v-for="(commit, k) in slice.commitResults")
a.ramp__slice(
draggable="false",
v-on:click="rampClick",
v-bind:href="getLink(commit)", target="_blank",
v-bind:title="getContributionMessageByCommit(slice, commit)",
v-bind:class="`ramp__slice--color${getRampColor(commit, slice)}`,\
!isBrokenLink(getLink(commit)) ? '' : 'broken-link'",
v-bind:style="{\
zIndex: user.commits.length - j,\
borderLeftWidth: `${getWidth(commit)}em`,\
right: `${((getSlicePos(slice.date)\
+ (getCommitPos(k, slice.commitResults.length))) * 100)}%`\
}"
)
template(v-else)
a(v-bind:href="getReportLink()", target="_blank")
.ramp__slice(
draggable="false",
v-for="(slice, j) in user.commits",
v-bind:title="getContributionMessage(slice)",
v-on:click="openTabZoom(user, slice, $event)",
v-bind:class="`ramp__slice--color${getSliceColor(slice)}`",
v-bind:style="{\
zIndex: user.commits.length - j,\
borderLeftWidth: `${getWidth(slice)}em`,\
right: `${(getSlicePos(tframe === 'day' ? slice.date : slice.endDate) * 100)}%` \
}"
)
.date-indicators(v-if="optimiseTimeline")
span {{optimisedMinimumDate}}
span {{optimisedMaximumDate}}
</template>
<script lang='ts'>
import { defineComponent, PropType } from 'vue';
import brokenLinkDisabler from '../mixin/brokenLinkMixin';
import { Commit, CommitResult, User } from '../types/types';
export default defineComponent({
name: 'c-ramp',
mixins: [brokenLinkDisabler],
props: {
groupby: {
type: String,
default: 'groupByRepos',
},
user: {
type: Object as PropType<User>,
required: true,
},
tframe: {
type: String,
default: 'commit',
},
avgsize: {
type: [Number, String],
required: true,
},
sdate: {
type: String,
required: true,
},
udate: {
type: String,
required: true,
},
mergegroup: {
type: Boolean,
default: false,
},
fromramp: {
type: Boolean,
default: false,
},
filtersearch: {
type: String,
default: '',
},
isWidgetMode: {
type: Boolean,
default: false,
},
optimiseTimeline: {
type: Boolean,
default: false,
},
optimisedMinimumDate: {
type: String,
default: '',
},
optimisedMaximumDate: {
type: String,
default: '',
},
},
data(): {
rampSize: number,
optimisedPadding: number,
} {
return {
rampSize: 0.01 as number,
optimisedPadding: 3, // as % of total timeline,
};
},
computed: {
mergeCommitRampSize(): number {
return this.rampSize * 20;
},
deletesContributionRampSize(): number {
return this.rampSize * 20;
},
},
methods: {
getLink(commit: CommitResult): string | undefined {
return window.getCommitLink(commit.repoId, commit.hash);
},
getContributions(commit: CommitResult | Commit): number {
return commit.insertions + commit.deletions;
},
isDeletesContribution(commit: CommitResult | Commit): boolean {
return commit.insertions === 0 && commit.deletions > 0;
},
getWidth(slice: CommitResult | Commit): number {
// Check if slice contains 'isMergeCommit' attribute
if ('isMergeCommit' in slice && slice.isMergeCommit) {
return this.mergeCommitRampSize;
}
if (this.getContributions(slice) === 0) {
return 0;
}
if (this.isDeletesContribution(slice)) {
return this.deletesContributionRampSize;
}
// '+' unary operator here attempts to convert this.avgsize to number, if it is not already one
const newSize = 100 * (slice.insertions / +this.avgsize);
return Math.max(newSize * this.rampSize, 0.5);
},
getContributionMessageByCommit(slice: Commit, commit: CommitResult): string {
return `[${slice.date}] ${commit.messageTitle}: +${commit.insertions} -${commit.deletions} lines `;
},
getContributionMessage(slice: Commit): string {
let title = this.tframe === 'day'
? `[${slice.date}] Daily `
: `[${slice.date} till ${slice.endDate}] Weekly `;
title += `contribution: +${slice.insertions} -${slice.deletions} lines`;
return title;
},
openTabZoom(user: User, slice: Commit, evt: MouseEvent): void {
// prevent opening of zoom tab when cmd/ctrl click
if (window.isMacintosh ? evt.metaKey : evt.ctrlKey) {
return;
}
const zoomUser = { ...user };
// Calculate total commit result insertion and deletion for the daily/weekly commit selected
zoomUser.commits = user.dailyCommits.map(
(dailyCommit) => ({
insertions: dailyCommit.commitResults.reduce((acc, currCommitResult) => acc + currCommitResult.insertions, 0),
deletions: dailyCommit.commitResults.reduce((acc, currCommitResult) => acc + currCommitResult.deletions, 0),
...dailyCommit,
commitResults: dailyCommit.commitResults.map((commitResult) => ({ ...commitResult, isOpen: true })),
}),
) as Array<Commit>;
const info = {
zRepo: user.repoName,
zAuthor: user.name,
zFilterGroup: this.groupby,
zTimeFrame: 'commit',
zAvgCommitSize: slice.insertions,
zUser: zoomUser,
zLocation: window.getRepoLink(user.repoId),
zSince: slice.date,
zUntil: this.tframe === 'day' ? slice.date : slice.endDate,
zIsMerged: this.mergegroup,
zFromRamp: true,
zFilterSearch: this.filtersearch,
};
window.deactivateAllOverlays();
this.$store.commit('updateTabZoomInfo', info);
},
// position for commit granularity
getCommitPos(i: number, total: number): number {
const totalTime = this.optimiseTimeline
? this.getTotalForPos(this.optimisedMinimumDate, this.optimisedMaximumDate)
: this.getTotalForPos(this.sdate, this.udate);
return (((total - i - 1) * window.DAY_IN_MS) / total)
/ (totalTime + window.DAY_IN_MS);
},
// position for day granularity
getSlicePos(date: string): number {
const toDate = this.optimiseTimeline ? this.optimisedMaximumDate : this.udate;
const total = this.optimiseTimeline
? this.getTotalForPos(this.optimisedMinimumDate, this.optimisedMaximumDate)
: this.getTotalForPos(this.sdate, this.udate);
return (new Date(toDate).valueOf() - new Date(date).valueOf()) / (total + window.DAY_IN_MS);
},
// get duration in miliseconds between 2 date
getTotalForPos(sinceDate: string, untilDate: string): number {
return new Date(untilDate).valueOf() - new Date(sinceDate).valueOf();
},
getRampColor(commit: CommitResult, slice: Commit): number | '-deletes' {
if (this.isDeletesContribution(commit)) {
return '-deletes';
}
return this.getSliceColor(slice);
},
getSliceColor(slice: Commit): number | '-deletes' {
if (this.isDeletesContribution(slice)) {
return '-deletes';
}
const timeMs = this.fromramp
? (new Date(this.sdate)).getTime()
: (new Date(slice.date)).getTime();
return (timeMs / window.DAY_IN_MS) % 5;
},
// Prevent browser from switching to new tab when clicking ramp
rampClick(evt: MouseEvent): void {
const isKeyPressed = window.isMacintosh ? evt.metaKey : evt.ctrlKey;
if (isKeyPressed) {
evt.preventDefault();
}
},
getReportLink(): string | undefined {
if (this.isWidgetMode) {
const url = window.location.href;
const regexToRemoveWidget = /([?&])((chartIndex|chartGroupIndex)=\d+)/g;
return url.replace(regexToRemoveWidget, '');
}
return undefined;
},
},
});
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
@import '../styles/_colors.scss';
/* Ramp */
.ramp {
$height: 3rem;
background-color: mui-color('blue', '50');
font-size: 100%;
height: $height;
overflow: hidden;
position: relative;
&__slice {
border-left-color: rgba(0, 0, 0, 0);
border-left-style: solid;
display: block;
height: 0;
position: absolute;
width: 0;
&--color0 {
border-bottom: $height rgba(mui-color('orange'), .5) solid;
}
&--color1 {
border-bottom: $height rgba(mui-color('light-blue'), .5) solid;
}
&--color2 {
border-bottom: $height rgba(mui-color('green'), .5) solid;
}
&--color3 {
border-bottom: $height rgba(mui-color('indigo'), .5) solid;
}
&--color4 {
border-bottom: $height rgba(mui-color('pink'), .5) solid;
}
&--color-deletes {
border-bottom: $height rgba(mui-color('red'), .7) solid;
}
}
}
.ramp-padding {
height: 100%;
position: relative;
}
.date-indicators {
color: mui-color('grey', '700');
display: flex;
justify-content: space-between;
padding-top: 1px;
}
</style>