Format JS

This commit is contained in:
Claudio Yanes 2022-03-07 18:25:02 +00:00
parent 30a6697c5b
commit 29e2934dc2
3 changed files with 361 additions and 362 deletions

View File

@ -25,7 +25,7 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
}
const data = {
nodes: [...neighbours].map(id => ({id})),
nodes: [...neighbours].map(id => ({ id })),
links: links.filter(l => neighbours.has(l.source) && neighbours.has(l.target)),
}
@ -52,18 +52,18 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
d.fy = d.y;
}
function dragged(event,d) {
function dragged(event, d) {
d.fx = event.x;
d.fy = event.y;
}
function dragended(event,d) {
function dragended(event, d) {
if (!event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}
const noop = () => {}
const noop = () => { }
return d3.drag()
.on("start", enableDrag ? dragstarted : noop)
.on("drag", enableDrag ? dragged : noop)
@ -86,15 +86,15 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
if (enableLegend) {
const legend = [
{"Current": "var(--g-node-active)"},
{"Note": "var(--g-node)"},
{ "Current": "var(--g-node-active)" },
{ "Note": "var(--g-node)" },
...pathColors
]
legend.forEach((legendEntry, i) => {
const key = Object.keys(legendEntry)[0]
const colour = legendEntry[key]
svg.append("circle").attr("cx", -width/2 + 20).attr("cy", height/2 - 30 * (i+1)).attr("r", 6).style("fill", colour)
svg.append("text").attr("x", -width/2 + 40).attr("y", height/2 - 30 * (i+1)).text(key).style("font-size", "15px").attr("alignment-baseline","middle")
svg.append("circle").attr("cx", -width / 2 + 20).attr("cy", height / 2 - 30 * (i + 1)).attr("r", 6).style("fill", colour)
svg.append("text").attr("x", -width / 2 + 40).attr("y", height / 2 - 30 * (i + 1)).text(key).style("font-size", "15px").attr("alignment-baseline", "middle")
})
}
@ -159,7 +159,7 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
.transition()
.duration(200)
.style("opacity", 1)
}).on("mouseleave", function (_,d) {
}).on("mouseleave", function (_, d) {
d3.selectAll(".node")
.transition()
.duration(200)
@ -196,7 +196,7 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
svg.call(d3.zoom()
.extent([[0, 0], [width, height]])
.scaleExtent([0.25, 4])
.on("zoom", ({transform}) => {
.on("zoom", ({ transform }) => {
link.attr("transform", transform);
node.attr("transform", transform);
labels.attr("transform", transform);
@ -217,5 +217,4 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
.attr("x", d => d.x)
.attr("y", d => d.y)
});
}
}

View File

@ -5,13 +5,13 @@ function htmlToElement(html) {
return template.content.firstChild
}
function initPopover(base) {
const baseUrl = base.replace(window.location.origin, "") // is this useless?
function initPopover(baseURL) {
const basePath = baseURL.replace(window.location.origin, "")
document.addEventListener("DOMContentLoaded", () => {
fetchData.then(({content}) => {
fetchData.then(({ content }) => {
const links = [...document.getElementsByClassName("internal-link")]
links.forEach(li => {
const linkDest = content[li.dataset.src.replace(baseUrl, "")]
const linkDest = content[li.dataset.src.replace(basePath, "")]
// const linkDest = content[li.dataset.src]
if (linkDest) {
const popoverElement = `<div class="popover">

View File

@ -58,7 +58,7 @@ const removeMarkdown = (
};
// -----
(async function() {
(async function () {
const contentIndex = new FlexSearch.Document({
cache: true,
charset: "latin:extra",
@ -126,7 +126,7 @@ const removeMarkdown = (
return `${startIndex === 0 ? "" : "..."}${mappedText}${endIndex === splitText.length ? "" : "..."}`
}
const resultToHTML = ({url, title, content, term}) => {
const resultToHTML = ({ url, title, content, term }) => {
const text = removeMarkdown(content)
const resultTitle = highlight(title, term)
const resultText = highlight(text, term)