Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
note map refactoring
zadame4ba7d65e82b
diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.jsindex 39c0c712ea..f7ca88c1d3 100644--- a/src/public/app/entities/note_short.js+++ b/src/public/app/entities/note_short.js@@ -14,7 +14,8 @@ const NOTE_TYPE_ICONS = {"render": "bx bx-extension","search": "bx bx-file-find","relation-map": "bx bx-map-alt",- "book": "bx bx-book"+ "book": "bx bx-book",+ "note-map": "bx bx-map-alt"};/**diff --git a/src/public/app/layouts/desktop_layout.js b/src/public/app/layouts/desktop_layout.jsindex 02cba88959..bbb7db954c 100644--- a/src/public/app/layouts/desktop_layout.js+++ b/src/public/app/layouts/desktop_layout.js@@ -72,8 +72,8 @@ export default class DesktopLayout {.command("jumpToNote")).child(new OpenNoteButtonWidget().icon("bx-map-alt")- .title("Global link map")- .targetNote('globallinkmap'))+ .title("Global note map")+ .targetNote('globalnotemap')).child(new ButtonWidget().icon("bx-history").title("Show recent changes")diff --git a/src/public/app/services/tree_context_menu.js b/src/public/app/services/tree_context_menu.jsindex 456b636c35..05ef111b35 100644--- a/src/public/app/services/tree_context_menu.js+++ b/src/public/app/services/tree_context_menu.js@@ -30,6 +30,7 @@ class TreeContextMenu {{ title: "Code", command: command, type: "code", uiIcon: "code" },{ title: "Saved search", command: command, type: "search", uiIcon: "file-find" },{ title: "Relation Map", command: command, type: "relation-map", uiIcon: "map-alt" },+ { title: "Note Map", command: command, type: "note-map", uiIcon: "map-alt" },{ title: "Render HTML note", command: command, type: "render", uiIcon: "extension" },{ title: "Book", command: command, type: "book", uiIcon: "book" }];diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.jsindex a0e5019d3e..3e50dd4abc 100644--- a/src/public/app/widgets/note_detail.js+++ b/src/public/app/widgets/note_detail.js@@ -20,7 +20,7 @@ import ReadOnlyTextTypeWidget from "./type_widgets/read_only_text.js";import ReadOnlyCodeTypeWidget from "./type_widgets/read_only_code.js";import NoneTypeWidget from "./type_widgets/none.js";import attributeService from "../services/attributes.js";-import GlobalLinkMapTypeWidget from "./type_widgets/global_link_map.js";+import NoteMapTypeWidget from "./type_widgets/note_map.js";const TPL = `<div class="note-detail">@@ -47,7 +47,7 @@ const typeWidgetClasses = {'relation-map': RelationMapTypeWidget,'protected-session': ProtectedSessionTypeWidget,'book': BookTypeWidget,- 'globallinkmap': GlobalLinkMapTypeWidget+ 'note-map': NoteMapTypeWidget};export default class NoteDetailWidget extends NoteContextAwareWidget {@@ -173,10 +173,6 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {type = 'editable-code';}- if (type === 'special') {- type = note.noteId;- }-if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) {type = 'protected-session';}diff --git a/src/public/app/widgets/type_widgets/global_link_map.js b/src/public/app/widgets/type_widgets/note_map.jssimilarity index 90%rename from src/public/app/widgets/type_widgets/global_link_map.jsrename to src/public/app/widgets/type_widgets/note_map.jsindex 39b0adbb7e..a746d0d7e9 100644--- a/src/public/app/widgets/type_widgets/global_link_map.js+++ b/src/public/app/widgets/type_widgets/note_map.js@@ -3,13 +3,13 @@ import libraryLoader from "../../services/library_loader.js";import server from "../../services/server.js";import attributeService from "../../services/attributes.js";-const TPL = `<div class="note-detail-global-link-map note-detail-printable" style="position: relative;">+const TPL = `<div class="note-detail-note-map note-detail-printable" style="position: relative;"><style>- .type-special .note-detail, .note-detail-global-link-map {+ .type-special .note-detail, .note-detail-note-map {height: 100%;}- .map-switcher {+ .map-type-switcher {position: absolute;top: 10px;right: 10px;@@ -17,30 +17,30 @@ const TPL = `<div class="note-detail-global-link-map note-detail-printable" stylz-index: 1000;}- .map-switcher .bx {+ .map-type-switcher .bx {font-size: x-large;}</style>- <div class="btn-group btn-group-sm map-switcher" role="group">+ <div class="btn-group btn-group-sm map-type-switcher" role="group"><button type="button" class="btn btn-secondary" title="Link Map" data-type="link"><span class="bx bx-network-chart"></span></button><button type="button" class="btn btn-secondary" title="Tree map" data-type="tree"><span class="bx bx-sitemap"></span></button></div>- <div class="link-map-container"></div>+ <div class="note-map-container"></div></div>`;-export default class GlobalLinkMapTypeWidget extends TypeWidget {- static getType() { return "globallinkmap"; }+export default class NoteMapTypeWidget extends TypeWidget {+ static getType() { return "note-map"; }doRender() {this.$widget = $(TPL);- this.$container = this.$widget.find(".link-map-container");+ this.$container = this.$widget.find(".note-map-container");window.addEventListener('resize', () => this.setFullHeight(), false);- this.$widget.find(".map-switcher button").on("click", async e => {+ this.$widget.find(".map-type-switcher button").on("click", async e => {const type = $(e.target).closest("button").attr("data-type");await attributeService.setLabel(this.noteId, 'mapType', type);@@ -59,7 +59,7 @@ export default class GlobalLinkMapTypeWidget extends TypeWidget {const height = $(window).height() - top;const width = this.$widget.width();- this.$widget.find('.link-map-container')+ this.$widget.find('.note-map-container').css("height", height).css("width", this.$widget.width());@@ -83,7 +83,6 @@ export default class GlobalLinkMapTypeWidget extends TypeWidget {.onZoom(zoom => this.setZoomLevel(zoom.k)).d3AlphaDecay(0.01).d3VelocityDecay(0.08)- .nodeRelSize(node => this.noteIdToSizeMap[node.id]).nodeCanvasObject((node, ctx) => this.paintNode(node, this.stringToColor(node.type), ctx)).nodePointerAreaPaint((node, ctx) => this.paintNode(node, this.stringToColor(node.type), ctx)).nodeLabel(node => node.name)@@ -91,7 +90,7 @@ export default class GlobalLinkMapTypeWidget extends TypeWidget {.nodePointerAreaPaint((node, color, ctx) => {ctx.fillStyle = color;ctx.beginPath();- ctx.arc(node.x, node.y, 5, 0, 2 * Math.PI, false);+ ctx.arc(node.x, node.y, this.noteIdToSizeMap[node.id], 0, 2 * Math.PI, false);ctx.fill();}).linkLabel(l => `${l.source.name} - <strong>${l.name}</strong> - ${l.target.name}`)@@ -106,7 +105,7 @@ export default class GlobalLinkMapTypeWidget extends TypeWidget {// .dagMode("radialout").onNodeClick(node => this.nodeClicked(node));- this.graph.d3Force('link').distance(5);+ this.graph.d3Force('link').distance(40);//this.graph.d3Force('center').strength(0.01);//@@ -115,7 +114,9 @@ export default class GlobalLinkMapTypeWidget extends TypeWidget {this.graph.d3Force('charge').distanceMax(1000);- this.renderData(await this.loadNotesAndRelations());+ const data = await this.loadNotesAndRelations();++ this.renderData(data);}stringToColor(str) {@@ -215,7 +216,7 @@ export default class GlobalLinkMapTypeWidget extends TypeWidget {ctx.restore();}- async loadNotesAndRelations(noteId, maxDepth) {+ async loadNotesAndRelations() {this.linkIdToLinkMap = {};this.noteIdToLinkCountMap = {};@@ -291,7 +292,7 @@ export default class GlobalLinkMapTypeWidget extends TypeWidget {this.graph.graphData(data);if (zoomToFit && data.nodes.length > 1) {- setTimeout(() => this.graph.zoomToFit(400, zoomPadding), 3000);+ setTimeout(() => this.graph.zoomToFit(400, zoomPadding), 1000);}}diff --git a/src/routes/api/link_map.js b/src/routes/api/link_map.jsindex 183b5e2842..9352a14992 100644--- a/src/routes/api/link_map.js+++ b/src/routes/api/link_map.js@@ -148,7 +148,7 @@ function getGlobalTreeMap() {const noteIds = new Set();const notes = Object.values(becca.notes)- .filter(note => !note.isArchived)+ .filter(note => !note.isArchived && !note.hasLabel('excludeFromTreeMap')).map(note => [note.noteId,note.isContentAvailable() ? note.title : '[protected]',diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex a6ddffa021..a409cd6f68 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -268,7 +268,7 @@ class ConsistencyChecks {SELECT noteId, typeFROM notesWHERE isDeleted = 0- AND type NOT IN ('text', 'code', 'render', 'file', 'image', 'search', 'relation-map', 'book', 'special')`,+ AND type NOT IN ('text', 'code', 'render', 'file', 'image', 'search', 'relation-map', 'book', 'note-map')`,({noteId, type}) => {if (this.autoFix) {const note = becca.getNote(noteId);diff --git a/src/services/special_notes.js b/src/services/special_notes.jsindex 5887539f09..ef69d813a2 100644--- a/src/services/special_notes.js+++ b/src/services/special_notes.js@@ -82,13 +82,13 @@ function getSinglesNoteRoot() {}function getGlobalLinkMapNote() {- let globalLinkMapNote = becca.getNote('globallinkmap');+ let globalLinkMapNote = becca.getNote('globalnotemap');if (!globalLinkMapNote) {globalLinkMapNote = noteService.createNewNote({- noteId: 'globallinkmap',- title: 'Global Link Map',- type: 'special',+ noteId: 'globalnotemap',+ title: 'Global Note Map',+ type: 'note-map',content: '',parentNoteId: getSinglesNoteRoot().noteId}).note;