Add tooltip and create hugo shortcode
This commit is contained in:
parent
7b9b9bdcd3
commit
2c1f8b45b3
4 changed files with 64 additions and 11 deletions
|
|
@ -1,10 +0,0 @@
|
||||||
:root{
|
|
||||||
--color-empty: #F5F5F5;
|
|
||||||
--color-low: #BDD7EE;
|
|
||||||
--color-mid: #2E86C1;
|
|
||||||
--color-high: #1A5276
|
|
||||||
}
|
|
||||||
|
|
||||||
#heatmap text {
|
|
||||||
font-family: inherit;
|
|
||||||
}
|
|
||||||
|
|
@ -79,7 +79,28 @@ export function render(weeks, counts) {
|
||||||
|
|
||||||
svg.appendChild(rect);
|
svg.appendChild(rect);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
return svg;
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById("heatmap").appendChild(svg);
|
export function setupTooltips(svg) {
|
||||||
|
const tooltip = document.getElementById("tooltip");
|
||||||
|
|
||||||
|
svg.addEventListener("mouseover", (e) => {
|
||||||
|
if (e.target.tagName != "rect") return;
|
||||||
|
const date = e.target.dataset.date;
|
||||||
|
const count = e.target.dataset.count;
|
||||||
|
|
||||||
|
tooltip.textContent = `${date} - ${count} commit${count == 1 ? "" : "s"}`;
|
||||||
|
tooltip.classList.remove("hidden");
|
||||||
|
});
|
||||||
|
|
||||||
|
svg.addEventListener("mousemove", (e) => {
|
||||||
|
tooltip.style.left = e.pageX + 12 + "px";
|
||||||
|
tooltip.style.top = e.pageY - 28 + "px";
|
||||||
|
});
|
||||||
|
|
||||||
|
svg.addEventListener("mouseout", (e) => {
|
||||||
|
if (e.target.tagName === "rect") tooltip.classList.add("hidden");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,9 @@
|
||||||
baseURL = 'https://example.org/'
|
baseURL = 'https://example.org/'
|
||||||
locale = 'en-us'
|
locale = 'en-us'
|
||||||
title = 'My New Hugo Project'
|
title = 'My New Hugo Project'
|
||||||
|
|
||||||
|
[params.heatmap]
|
||||||
|
color_empty = "#F5F5F5"
|
||||||
|
color_low = "#BDD7EE"
|
||||||
|
color_mid = "#2E86C1"
|
||||||
|
color_high = "#1A5276"
|
||||||
|
|
|
||||||
36
layouts/shortcodes/git-heatmap.html
Normal file
36
layouts/shortcodes/git-heatmap.html
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
{{ $js := resources.Get "js/build_heatmap.js" }}
|
||||||
|
{{ $p := .Site.Params.heatmap }}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--color-empty: {{ $p.color_empty }};
|
||||||
|
--color-low: {{ $p.color_low }};
|
||||||
|
--color-mid: {{ $p.color_mid }};
|
||||||
|
--color-high: {{ $p.color_high }};
|
||||||
|
}
|
||||||
|
#heatmap text { font-family: inherit; }
|
||||||
|
#tooltip {
|
||||||
|
position: fixed;
|
||||||
|
background: #333;
|
||||||
|
color: white;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.hidden { display: none; }
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div id="heatmap"></div>
|
||||||
|
<script type="module">
|
||||||
|
import {flattenData, constructWeeks, render, setupTooltips} from "{{ $js.RelPermalink }}"
|
||||||
|
|
||||||
|
const data = await fetch("/activity.json").then((r) => r.json());
|
||||||
|
const counts = flattenData(data);
|
||||||
|
const weeks = constructWeeks();
|
||||||
|
const svg = render(weeks, counts);
|
||||||
|
document.getElementById("heatmap").appendChild(svg);
|
||||||
|
setupTooltips(svg);
|
||||||
|
</script>
|
||||||
|
<div id="tooltip" class="hidden"></div>
|
||||||
|
<div id="legend"></div>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue