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 = { const data = {
nodes: [...neighbours].map(id => ({id})), nodes: [...neighbours].map(id => ({ id })),
links: links.filter(l => neighbours.has(l.source) && neighbours.has(l.target)), 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; d.fy = d.y;
} }
function dragged(event,d) { function dragged(event, d) {
d.fx = event.x; d.fx = event.x;
d.fy = event.y; d.fy = event.y;
} }
function dragended(event,d) { function dragended(event, d) {
if (!event.active) simulation.alphaTarget(0); if (!event.active) simulation.alphaTarget(0);
d.fx = null; d.fx = null;
d.fy = null; d.fy = null;
} }
const noop = () => {} const noop = () => { }
return d3.drag() return d3.drag()
.on("start", enableDrag ? dragstarted : noop) .on("start", enableDrag ? dragstarted : noop)
.on("drag", enableDrag ? dragged : noop) .on("drag", enableDrag ? dragged : noop)
@ -86,15 +86,15 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
if (enableLegend) { if (enableLegend) {
const legend = [ const legend = [
{"Current": "var(--g-node-active)"}, { "Current": "var(--g-node-active)" },
{"Note": "var(--g-node)"}, { "Note": "var(--g-node)" },
...pathColors ...pathColors
] ]
legend.forEach((legendEntry, i) => { legend.forEach((legendEntry, i) => {
const key = Object.keys(legendEntry)[0] const key = Object.keys(legendEntry)[0]
const colour = legendEntry[key] 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("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("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() .transition()
.duration(200) .duration(200)
.style("opacity", 1) .style("opacity", 1)
}).on("mouseleave", function (_,d) { }).on("mouseleave", function (_, d) {
d3.selectAll(".node") d3.selectAll(".node")
.transition() .transition()
.duration(200) .duration(200)
@ -196,7 +196,7 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
svg.call(d3.zoom() svg.call(d3.zoom()
.extent([[0, 0], [width, height]]) .extent([[0, 0], [width, height]])
.scaleExtent([0.25, 4]) .scaleExtent([0.25, 4])
.on("zoom", ({transform}) => { .on("zoom", ({ transform }) => {
link.attr("transform", transform); link.attr("transform", transform);
node.attr("transform", transform); node.attr("transform", transform);
labels.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("x", d => d.x)
.attr("y", d => d.y) .attr("y", d => d.y)
}); });
} }

View File

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

View File

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