Skip to content

Commit eef9406

Browse files
Contribution heatmap improvements (#35876)
1. Set a fixed height on the element, preventing the content after the element from shifting on page load. This uses CSS [container query length units](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_containment/Container_queries#container_query_length_units) as I saw no other way because of the non-linear scaling of the element. 2. Move the "total-contributions" text into the existing vue slot, eliminating the need for absolute positioning. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent aaa8033 commit eef9406

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

templates/user/heatmap.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{{if .HeatmapData}}
2+
<div class="activity-heatmap-container">
23
<div id="user-heatmap" class="is-loading"
34
data-heatmap-data="{{JsonUtils.EncodeToString .HeatmapData}}"
45
data-locale-total-contributions="{{ctx.Locale.Tr "heatmap.number_of_contributions_in_the_last_12_months" (ctx.Locale.PrettyNumber .HeatmapTotalContributions)}}"
56
data-locale-no-contributions="{{ctx.Locale.Tr "heatmap.no_contributions"}}"
67
data-locale-more="{{ctx.Locale.Tr "heatmap.more"}}"
78
data-locale-less="{{ctx.Locale.Tr "heatmap.less"}}"
89
></div>
9-
<div class="divider"></div>
10+
</div>
11+
<div class="divider"></div>
1012
{{end}}

web_src/css/features/heatmap.css

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,44 @@
44
position: relative;
55
}
66

7-
/* before the Vue component is mounted, show a loading indicator with dummy size */
8-
/* the ratio is guesswork, see https://github.com/razorness/vue3-calendar-heatmap/issues/26 */
9-
#user-heatmap.is-loading {
10-
aspect-ratio: 5.415; /* the size is about 790 x 145 */
7+
.activity-heatmap-container {
8+
container-type: inline-size;
119
}
12-
.user.profile #user-heatmap.is-loading {
13-
aspect-ratio: 5.645; /* the size is about 953 x 169 */
10+
11+
@container (width > 0) {
12+
#user-heatmap {
13+
/* Set element to fixed height so that it does not resize after load. The calculation is complex
14+
because the element does not scale with a fixed aspect ratio. */
15+
height: calc((100cqw / 5) - (100cqw / 25) + 20px);
16+
}
17+
}
18+
19+
/* Fallback height adjustment above for browsers that don't support container queries */
20+
@supports not (container-type: inline-size) {
21+
/* Before the Vue component is mounted, show a loading indicator with dummy size */
22+
/* The ratio is guesswork for legacy browsers, new browsers use the "@container" approach above */
23+
#user-heatmap.is-loading {
24+
aspect-ratio: 5.4823972051; /* the size is about 816 x 148.84 */
25+
}
26+
.user.profile #user-heatmap.is-loading {
27+
aspect-ratio: 5.6290608387; /* the size is about 953 x 169.3 */
28+
}
1429
}
1530

1631
#user-heatmap text {
1732
fill: currentcolor !important;
1833
}
1934

35+
/* root legend */
36+
#user-heatmap .vch__container > .vch__legend {
37+
display: flex;
38+
font-size: 11px;
39+
justify-content: space-between;
40+
}
41+
2042
/* for the "Less" and "More" legend */
2143
#user-heatmap .vch__legend .vch__legend {
2244
display: flex;
23-
font-size: 11px;
2445
align-items: center;
2546
justify-content: right;
2647
}
@@ -34,25 +55,3 @@
3455
#user-heatmap .vch__day__square:hover {
3556
outline: 1.5px solid var(--color-text);
3657
}
37-
38-
/* move the "? contributions in the last ? months" text from top to bottom */
39-
#user-heatmap .total-contributions {
40-
font-size: 11px;
41-
position: absolute;
42-
bottom: 0;
43-
left: 25px;
44-
}
45-
46-
@media (max-width: 1200px) {
47-
#user-heatmap .total-contributions {
48-
left: 21px;
49-
}
50-
}
51-
52-
@media (max-width: 1000px) {
53-
#user-heatmap .total-contributions {
54-
font-size: 10px;
55-
left: 17px;
56-
bottom: -4px;
57-
}
58-
}

web_src/js/components/ActivityHeatmap.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ function handleDayClick(e: Event & {date: Date}) {
5353
}
5454
</script>
5555
<template>
56-
<div class="total-contributions">
57-
{{ locale.textTotalContributions }}
58-
</div>
5956
<calendar-heatmap
6057
:locale="locale.heatMapLocale"
6158
:no-data-text="locale.noDataText"
@@ -65,5 +62,7 @@ function handleDayClick(e: Event & {date: Date}) {
6562
:range-color="colorRange"
6663
@day-click="handleDayClick($event)"
6764
:tippy-props="{theme: 'tooltip'}"
68-
/>
65+
>
66+
<template #vch__legend-left>{{ locale.textTotalContributions }}</template>
67+
</calendar-heatmap>
6968
</template>

0 commit comments

Comments
 (0)