graph update

This commit is contained in:
Garry Ing 2021-04-03 18:32:00 -04:00
parent e88446c8e9
commit 5b60973e4f
No known key found for this signature in database
GPG Key ID: 62E12D2F8C30C493
4 changed files with 50 additions and 26 deletions

View File

@ -4,8 +4,8 @@ layout: default
--- ---
<div class="container tc"> <div class="container tc">
<h1 class="f-6 work-sans-light normal">404</h1> <h1 class="f-6 anthony normal">404</h1>
<p class="f1 normal">Page not found :(</p> <p class="f1 normal anthony">Page not found :(</p>
<p>The requested page could not be found.</p> <p>The requested page could not be found.</p>
</div> </div>

View File

@ -5,7 +5,7 @@
<a class="no-underline f4 dark-green anthony" rel="author" href="{{ "/" | relative_url }}">{{ site.title | escape }}</a> <a class="no-underline f4 dark-green anthony" rel="author" href="{{ "/" | relative_url }}">{{ site.title | escape }}</a>
{%- if titles_size > 0 -%} {%- if titles_size > 0 -%}
<nav class="f7"> <nav class="f7 code">
{%- for path in page_paths -%} {%- for path in page_paths -%}
{%- assign my_page = site.pages | where: "path", path | first -%} {%- assign my_page = site.pages | where: "path", path | first -%}
{%- if my_page.title -%} {%- if my_page.title -%}

View File

@ -2,7 +2,10 @@
layout: default layout: default
--- ---
<h1 class="f-6 work-sans-light normal">Loading a note...</h1> <div class="ma3 anthony">
<h1 class="f-5 normal loading">Loading a note</h1>
<div class="rand-notes f1"></div>
</div>
<script> <script>
window.graphDataIndex = {% include notes_graph.json %} window.graphDataIndex = {% include notes_graph.json %}

View File

@ -117,7 +117,29 @@ document.querySelectorAll('#notes-entry-container a').forEach(setupListeners)
if (typeof window.graphDataIndex !== 'undefined') { if (typeof window.graphDataIndex !== 'undefined') {
const indexNodes = window.graphDataIndex.nodes const indexNodes = window.graphDataIndex.nodes
const randomNode = indexNodes[Math.floor(Math.random() * indexNodes.length)] const randomNode = indexNodes[Math.floor(Math.random() * indexNodes.length)]
let counter = 0
setInterval(() => {
counter += 1
document.querySelector('.loading').innerHTML += '.'
if (counter === 4) {
document.querySelector('.loading').innerHTML = 'Loading a note'
counter = 0
}
}, 500)
setInterval(() => {
const randomNodeLoader = indexNodes[Math.floor(Math.random() * indexNodes.length)]
const randomNodeTemplate = `<p class="ma0">${randomNodeLoader.path}</p>`
document.querySelector('.rand-notes').innerHTML += randomNodeTemplate
if (counter === 3) {
document.querySelector('.rand-notes').innerHTML = ''
}
}, 250)
setTimeout(() => {
window.location = randomNode.path window.location = randomNode.path
}, 1500)
} }
// Notes graph // Notes graph
@ -127,11 +149,10 @@ const d3 = window.d3
if (typeof window.graphData !== 'undefined') { if (typeof window.graphData !== 'undefined') {
const MINIMAL_NODE_SIZE = 10 const MINIMAL_NODE_SIZE = 10
const MAX_NODE_SIZE = 12 const MAX_NODE_SIZE = 12
const ACTIVE_RADIUS_FACTOR = 1.5
const STROKE = 1 const STROKE = 1
const FONT_SIZE = 12 const FONT_SIZE = 12
const TICKS = 200 const TICKS = 200
const FONT_BASELINE = 40 const FONT_BASELINE = 35
const MAX_LABEL_LENGTH = 50 const MAX_LABEL_LENGTH = 50
const nodesData = window.graphData.nodes const nodesData = window.graphData.nodes
@ -221,7 +242,6 @@ if (typeof window.graphData !== 'undefined') {
const svg = d3.select('svg') const svg = d3.select('svg')
const width = Number(svg.attr('width')) const width = Number(svg.attr('width'))
const height = Number(svg.attr('height')) const height = Number(svg.attr('height'))
let zoomLevel = 1
const simulation = d3 const simulation = d3
.forceSimulation(nodesData) .forceSimulation(nodesData)
@ -247,30 +267,21 @@ if (typeof window.graphData !== 'undefined') {
const resize = (event) => { const resize = (event) => {
if (event) { if (event) {
const scale = event.transform const scale = event.transform
zoomLevel = scale.k if (!activeNode.empty()) {
const newX = parseFloat(activeNode.attr('cx')) - scale.x
const newY = parseFloat(activeNode.attr('cy')) - scale.y
g.attr('transform', 'translate(' + (width / 2 - newX) + ',' + (height / 2 - newY) + ')')
} else {
g.attr('transform', scale) g.attr('transform', scale)
} }
}
const zoomOrKeep = (value) => (zoomLevel >= 1 ? value / zoomLevel : value)
const font = Math.max(Math.round(zoomOrKeep(FONT_SIZE)), 1)
text.attr('font-size', (d) => font)
link.attr('stroke-width', zoomOrKeep(STROKE))
node.attr('r', (d) => {
return zoomOrKeep(nodeSize[d.id])
})
svg
.selectAll('circle')
.filter((_d, i, nodes) => d3.select(nodes[i]).attr('active'))
.attr('r', (d) => zoomOrKeep(ACTIVE_RADIUS_FACTOR * nodeSize[d.id]))
} }
const ticked = () => { const ticked = () => {
node.attr('cx', (d) => d.x).attr('cy', (d) => d.y) node.attr('cx', (d) => d.x).attr('cy', (d) => d.y)
text text
.attr('x', (d) => d.x) .attr('x', (d) => d.x)
.attr('y', (d) => d.y - (FONT_BASELINE - nodeSize[d.id]) / zoomLevel) .attr('y', (d) => d.y - (FONT_BASELINE - nodeSize[d.id]))
link link
.attr('d', (d) => { .attr('d', (d) => {
const dx = d.target.x - d.source.x const dx = d.target.x - d.source.x
@ -338,8 +349,18 @@ if (typeof window.graphData !== 'undefined') {
zoomHandler(svg) zoomHandler(svg)
restart() restart()
const activeNode = svg.select('circle[active]')
if (!activeNode.empty()) {
const centerNode = (xx, yy) => {
g.attr('transform', 'translate(' + (width / 2 - xx) + ',' + (height / 2 - yy) + ')')
}
centerNode(activeNode.attr('cx'), activeNode.attr('cy'))
}
function isCurrentPath (notePath) { function isCurrentPath (notePath) {
return window.location.pathname.includes(notePath) return window.location.pathname === notePath
} }
function shorten (str, maxLen, separator = ' ') { function shorten (str, maxLen, separator = ' ') {