Skip to content

Commit

Permalink
add showing and hiding dailynote
Browse files Browse the repository at this point in the history
  • Loading branch information
shenjinglei committed Jan 14, 2024
1 parent 22521a8 commit 6f0fdd8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/dock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { Display, initRawGraph, setGraphType, setSourceNode, } from "./graph";
import { Display, initRawGraph, isDailynote, setGraphType, setIsDailynote, setSourceNode, } from "./graph";
import { i18n, plugin, rawGraph } from "./utils";
import { adaptHotkey, fetchSyncPost, getFrontend } from "siyuan";

Expand All @@ -16,6 +16,7 @@ export function initDock() {
${i18n.pluginName}
</div>
<span class="fn__flex-1 fn__space"></span>
<span id="graph_enhance_dailynote" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${i18n.dockBtnHideDN}"><svg id="graph_enhance_dailynote_icon"><use xlink:href="#iconCalendar"></use></svg></span>
<span id="graph_enhance_path" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${i18n.dockBtnPath}"><svg><use xlink:href="#iconCode"></use></svg></span>
<span id="graph_enhance_global" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${i18n.dockBtnGlobal}"><svg><use xlink:href="#iconLanguage"></use></svg></span>
<span id="graph_enhance_neighbor" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${i18n.dockBtnNeighbor}"><svg><use xlink:href="#iconWorkspace"></use></svg></span>
Expand Down Expand Up @@ -44,6 +45,20 @@ export function initDock() {
init() {
this.element.innerHTML = dockHtml;

document.getElementById("graph_enhance_dailynote")!.onclick = async () => {
if (isDailynote) {
setIsDailynote(false);
document.getElementById("graph_enhance_dailynote")?.setAttribute("aria-label", i18n.dockBtnShowDN);
document.getElementById("graph_enhance_dailynote_icon")?.setAttribute("style", "fill: RoyalBlue;");
} else {
setIsDailynote(true);
document.getElementById("graph_enhance_dailynote")?.setAttribute("aria-label", i18n.dockBtnHideDN);
document.getElementById("graph_enhance_dailynote_icon")?.setAttribute("style", "fill: #5f6368;");
}

Display();
};

document.getElementById("graph_enhance_refresh")!.onclick = async () => {
await refreashGraph();

Expand Down
7 changes: 7 additions & 0 deletions src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ function insertEdge2(cur: QueueItem, _rawGraph: dagre.graphlib.Graph<any>, _proc
}
}

export let isDailynote = true;
export function setIsDailynote(_isDailynote: boolean) {
isDailynote = _isDailynote;
}

function searchUp2(cur: QueueItem, q: QueueItem[], _rawGraph: dagre.graphlib.Graph<any>, _processedGraph: dagre.graphlib.Graph<any>, penetrate = 0) {
const curNodeValue = _processedGraph.node(cur.id);
if (curNodeValue.state & 2) return; // search is already done
Expand All @@ -330,6 +335,7 @@ function searchUp2(cur: QueueItem, q: QueueItem[], _rawGraph: dagre.graphlib.Gra

_rawGraph.inEdges(cur.id)
?.filter(e => _processedGraph.node(e.v)?.state !== 3)
.filter(e => isDailynote || !/^\d{4}-\d{2}-\d{2}$/.test(_rawGraph.node(e.v).label))
.filter(e => penetrate || cur.count === 0 || _rawGraph.edge(e.v, e.w)?.state !== "broken")
.forEach(x => q.push({
id: x.v,
Expand All @@ -350,6 +356,7 @@ function searchDown2(cur: QueueItem, q: QueueItem[], _rawGraph: dagre.graphlib.G

_rawGraph.outEdges(cur.id)
?.filter(e => _processedGraph.node(e.w)?.state !== 3)
.filter(e => isDailynote || !/^\d{4}-\d{2}-\d{2}$/.test(_rawGraph.node(e.w).label))
.filter(e => penetrate || cur.count === 0 || _rawGraph.edge(e.v, e.w)?.state !== "broken")
.forEach(e => q.push({
id: e.w,
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@
"tailThresholdTitle": "Long Tail Graph Threshold",
"tailThresholdDescription": "Comma separated, for example: 1,2",

"dockBtnPath": "Path Graph"
"dockBtnPath": "Path Graph",
"dockBtnShowDN": "Show DailyNote",
"dockBtnHideDN": "Hide DailyNote"
}
4 changes: 3 additions & 1 deletion src/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@
"tailThresholdTitle": "长尾图阈值",
"tailThresholdDescription": "最小值与最大值用英文逗号隔开,如:1,2",

"dockBtnPath": "路径图"
"dockBtnPath": "路径图",
"dockBtnShowDN": "显示 DailyNote",
"dockBtnHideDN": "隐藏 DailyNote"
}

0 comments on commit 6f0fdd8

Please sign in to comment.