diff --git a/main.js b/main.js index 124631f..2691587 100644 --- a/main.js +++ b/main.js @@ -6882,11 +6882,12 @@ var DEFAULT_NETWORK_SETTINGS = { var MyItemView = class extends import_obsidian.ItemView { constructor(leaf) { super(leaf); + this.connectionType = "block"; // Add a flag to track hover state this.nodeLinkCount = {}; - // Define nodeLinkCount outside of the function - this.mainNodeId = "-1"; - this.scoreThreshold = 0.8; + // Define no + this.centralNodeId = "-1"; + this.significanceScoreThreshold = 0.8; this.settingsInstantiated = false; this.nodeSize = 3; this.linkThickness = 0.3; @@ -6950,23 +6951,30 @@ var MyItemView = class extends import_obsidian.ItemView { nodes = []; links = []; connections = []; + this.minScore = 1; + this.maxScore = 0; if (!this.currentNoteKey) return; - const note = smartNotes[this.currentNoteKey]; - const noteConnections = note.find_connections().filter((connection) => connection.score >= this.scoreThreshold); - if (note.key && note.key.trim() !== "" && !nodes.some((node2) => node2.id === note.key)) { + this.centralNote = smartNotes[this.currentNoteKey]; + const noteConnections = this.centralNote.find_connections().filter( + (connection) => connection.score >= this.significanceScoreThreshold + ); + console.log("central note: ", this.centralNote); + console.log("note connections: ", this.centralNote.find_connections()); + if (this.centralNote.key && this.centralNote.key.trim() !== "" && !nodes.some((node2) => node2.id === this.centralNote.key)) { nodes.push({ - id: note.key, - name: note.key, + id: this.centralNote.key, + name: this.centralNote.key, group: "note", x: Math.random() * 1e3, y: Math.random() * 1e3, fx: null, fy: null }); + this.centralNode = nodes[0]; } - const blockConnections = noteConnections.filter((connection) => connection.__proto__.constructor.name === "SmartBlock"); - blockConnections.forEach((connection, index2) => { + const filteredConnections = noteConnections.filter((connection) => connection.__proto__.constructor.name === (this.connectionType === "block" ? "SmartBlock" : "SmartNote")); + filteredConnections.forEach((connection, index2) => { if (connection && connection.data && connection.data.key && connection.data.key.trim() !== "") { const connectionId = connection.data.key; if (!nodes.some((node2) => node2.id === connectionId)) { @@ -6981,13 +6989,13 @@ var MyItemView = class extends import_obsidian.ItemView { }); } links.push({ - source: note.key, + source: this.centralNote.key, target: connectionId, value: connection.score || 0 // Ensure score is defined }); connections.push({ - source: note.key, + source: this.centralNote.key, target: connectionId, score: connection.score || 0 // Ensure score is defined @@ -7019,8 +7027,6 @@ var MyItemView = class extends import_obsidian.ItemView { updateLabelOpacity(event.transform.k); })); const svgGroup = svg.append("g"); - let mainNodeTemp = nodes.find((node2) => node2.id === this.mainNodeId); - const mainNode = mainNodeTemp; const updateLabelOpacity = (zoomLevel) => { const maxOpacity = 1; const minOpacity = 0; @@ -7038,9 +7044,9 @@ var MyItemView = class extends import_obsidian.ItemView { svgGroup.selectAll(".label").transition().duration(300).attr("opacity", newOpacity); }; const customCenterForce = (alpha) => { - if (mainNode) { - mainNode.x += (width / 2 - mainNode.x) * this.centerForce * alpha; - mainNode.y += (height / 2 - mainNode.y) * this.centerForce * alpha; + if (that.centralNode) { + that.centralNode.x += (width / 2 - that.centralNode.x) * this.centerForce * alpha; + that.centralNode.y += (height / 2 - that.centralNode.y) * this.centerForce * alpha; } }; const customCenterForce2 = (nodeId, centerX, centerY) => { @@ -7056,7 +7062,7 @@ var MyItemView = class extends import_obsidian.ItemView { function inverseNormalize(value) { return 1 - (value - that.minScore) / (that.maxScore - that.minScore); } - const simulation = simulation_default().force("center", null).force("charge", manyBody_default().strength(-DEFAULT_NETWORK_SETTINGS.repelForce)).force("link", link_default().id((d) => d.id).distance((d) => 50 + inverseNormalize(d.score) * 100).strength(1)).force("x", x_default2(width / 2).strength(this.centerForce)).force("y", y_default2(height / 2).strength(this.centerForce)).force("collide", collide_default().radius(DEFAULT_NETWORK_SETTINGS.nodeSize + 3).strength(0.7)).force("customCenter", customCenterForce2(this.mainNodeId, width / 2, height / 2)); + const simulation = simulation_default().force("center", null).force("charge", manyBody_default().strength(-DEFAULT_NETWORK_SETTINGS.repelForce)).force("link", link_default().id((d) => d.id).distance((d) => 50 + inverseNormalize(d.score) * 100).strength(1)).force("x", x_default2(width / 2).strength(this.centerForce)).force("y", y_default2(height / 2).strength(this.centerForce)).force("collide", collide_default().radius(DEFAULT_NETWORK_SETTINGS.nodeSize + 3).strength(0.7)).force("customCenter", customCenterForce2(this.centralNodeId, width / 2, height / 2)); updateConnections(); let link = svgGroup.append("g").attr("class", "links").selectAll("line").data(links).enter().append("line").attr("stroke", "blue").attr("stroke-width", 2).attr("stroke-opacity", 1); let node = svgGroup.append("g").attr("class", "nodes").selectAll("circle").data(nodes).enter().append("circle").attr("r", 20).attr("fill", "blue").call(drag_default().on("start", (event, d) => { @@ -7102,10 +7108,10 @@ var MyItemView = class extends import_obsidian.ItemView { }; const updateVisualization = (newScoreThreshold) => { if (newScoreThreshold !== void 0) { - this.scoreThreshold = newScoreThreshold; + this.significanceScoreThreshold = newScoreThreshold; } updateConnections(); - const filteredConnections = connections.filter((connection) => connection.score >= this.scoreThreshold); + const filteredConnections = connections.filter((connection) => connection.score >= this.significanceScoreThreshold); let visibleNodes = /* @__PURE__ */ new Set(); filteredConnections.forEach((connection) => { visibleNodes.add(connection.source); @@ -7121,12 +7127,6 @@ var MyItemView = class extends import_obsidian.ItemView { } }).filter(Boolean); console.log("Visible Nodes:", nodesData); - const updateForces = () => { - simulation.alpha(0.3).restart(); - setTimeout(() => { - simulation.alphaTarget(0).stop(); - }, 2e3); - }; validatedLinks = filteredConnections.filter((link2) => { const sourceNode = nodesData.find((node2) => node2.id === link2.source); const targetNode = nodesData.find((node2) => node2.id === link2.target); @@ -7146,16 +7146,21 @@ var MyItemView = class extends import_obsidian.ItemView { console.warn("No nodes or links to display after filtering. Aborting update."); return; } - this.mainNodeId = Object.keys(this.nodeLinkCount).reduce((a2, b) => this.nodeLinkCount[a2] > this.nodeLinkCount[b] ? a2 : b); + this.centralNodeId = Object.keys(this.nodeLinkCount).reduce((a2, b) => this.nodeLinkCount[a2] > this.nodeLinkCount[b] ? a2 : b); const mainNodeSize = maxNodeSize; const otherNodeSize = minNodeSize; - const mainNodeTemp2 = nodesData.find((node2) => node2.id === this.mainNodeId); - if (mainNodeTemp2) { - mainNodeTemp2.fx = width / 2; - mainNodeTemp2.fy = height / 2; + if (this.centralNode) { + this.centralNode.fx = width / 2; + this.centralNode.fy = height / 2; } + const updateForces = () => { + simulation.alpha(0.3).restart(); + setTimeout(() => { + simulation.alphaTarget(0).stop(); + }, 2e3); + }; nodeSelection = svgGroup.select("g.nodes").selectAll("circle").data(nodesData, (d) => d.id).join( - (enter) => enter.append("circle").attr("class", "node").attr("r", (d) => d.id === this.mainNodeId ? this.nodeSize + 2 : this.nodeSize).attr("fill", (d) => d.group === "note" ? "#7c8594" : "#926ec9").attr("stroke", (d) => d.group === "note" ? "#7c8594" : "#926ec9").attr("stroke-width", 0.3).attr("opacity", 1).attr("cursor", "pointer").call( + (enter) => enter.append("circle").attr("class", "node").attr("r", (d) => d.id === this.centralNodeId ? this.nodeSize + 2 : this.nodeSize).attr("fill", (d) => d.group === "note" ? "#7c8594" : "#926ec9").attr("stroke", (d) => d.group === "note" ? "#7c8594" : "#926ec9").attr("stroke-width", 0.3).attr("opacity", 1).attr("cursor", "pointer").call( drag_default().on("start", (event, d) => { if (!event.active) simulation.alphaTarget(0.3).restart(); @@ -7169,7 +7174,7 @@ var MyItemView = class extends import_obsidian.ItemView { simulation.alphaTarget(0); }) ).on("mouseover", function(event, d) { - if (d.id !== that.mainNodeId) { + if (d.id !== that.centralNodeId) { select_default2(this).transition().duration(500).attr("fill", "#d46ebe"); } select_default2(this).attr("stroke", "#fff"); @@ -7185,7 +7190,7 @@ var MyItemView = class extends import_obsidian.ItemView { linktext: d.id }); }).on("mouseout", function(event, d) { - if (d.id !== that.mainNodeId) { + if (d.id !== that.centralNodeId) { select_default2(this).transition().duration(500).attr("fill", "#926ec9"); } select_default2(this).attr("stroke", "transparent"); @@ -7193,7 +7198,7 @@ var MyItemView = class extends import_obsidian.ItemView { svgGroup.select(`text[data-id='${d.id}']`).transition().duration(250).attr("y", d.y); that.isHovering = false; }), - (update) => update.attr("r", (d) => d.id === this.mainNodeId ? mainNodeSize : otherNodeSize).attr("fill", (d) => d.group === "note" ? "#7c8594" : "#926ec9").attr("stroke", (d) => d.group === "note" ? "#7c8594" : "#926ec9").attr("opacity", 1).attr("stroke-width", 0.3), + (update) => update.attr("r", (d) => d.id === this.centralNodeId ? mainNodeSize : otherNodeSize).attr("fill", (d) => d.group === "note" ? "#7c8594" : "#926ec9").attr("stroke", (d) => d.group === "note" ? "#7c8594" : "#926ec9").attr("opacity", 1).attr("stroke-width", 0.3), (exit) => exit.remove() ); linkSelection = svgGroup.select("g.links").selectAll("line").data(validatedLinks, (d) => `${d.source}-${d.target}`).join( @@ -7238,12 +7243,12 @@ var MyItemView = class extends import_obsidian.ItemView { updateLabelOpacity(transform(svg.node()).k); }); const highlightNode = (node2) => { - nodeSelection.transition().duration(500).attr("fill", (d) => d.id !== this.mainNodeId && (d.id === node2.id || validatedLinks.some((link2) => link2.source === node2 && link2.target === d || link2.target === node2 && link2.source === d)) ? "#d46ebe" : d.id === this.mainNodeId ? "#7c8594" : "#926ec9").attr("opacity", (d) => d.id === node2.id || validatedLinks.some((link2) => link2.source === node2 && link2.target === d || link2.target === node2 && link2.source === d) ? 1 : 0.1); + nodeSelection.transition().duration(500).attr("fill", (d) => d.id !== this.centralNodeId && (d.id === node2.id || validatedLinks.some((link2) => link2.source === node2 && link2.target === d || link2.target === node2 && link2.source === d)) ? "#d46ebe" : d.id === this.centralNodeId ? "#7c8594" : "#926ec9").attr("opacity", (d) => d.id === node2.id || validatedLinks.some((link2) => link2.source === node2 && link2.target === d || link2.target === node2 && link2.source === d) ? 1 : 0.1); linkSelection.transition().duration(500).attr("opacity", (d) => d.source === node2 || d.target === node2 ? 1 : 0.1); labelSelection.transition().duration(500).attr("opacity", (d) => d.id === node2.id || validatedLinks.some((link2) => link2.source === node2 && link2.target === d || link2.target === node2 && link2.source === d) ? 1 : 0.1); }; const unhighlightNode = () => { - nodeSelection.transition().duration(500).attr("fill", (d) => d.id !== this.mainNodeId ? "#926ec9" : "#7b8493").attr("opacity", 1); + nodeSelection.transition().duration(500).attr("fill", (d) => d.id !== this.centralNodeId ? "#926ec9" : "#7b8493").attr("opacity", 1); linkSelection.transition().duration(500).attr("opacity", 1); labelSelection.transition().duration(500).attr("opacity", 1); }; @@ -7286,8 +7291,19 @@ var MyItemView = class extends import_obsidian.ItemView { Filters