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
sizing of the link map
zadamfabf24a0659e
diff --git a/src/public/app/widgets/note_map.js b/src/public/app/widgets/note_map.jsindex 586be2c9c8..8fc03283be 100644--- a/src/public/app/widgets/note_map.js+++ b/src/public/app/widgets/note_map.js@@ -171,7 +171,7 @@ export default class NoteMapWidget extends NoteContextAwareWidget {const {x, y} = node;const size = this.noteIdToSizeMap[node.id];- ctx.fillStyle = node.id === this.noteId ? 'red' : color;+ ctx.fillStyle = (this.widgetMode === 'ribbon' && node.id === this.noteId) ? 'red' : color;ctx.beginPath();ctx.arc(x, y, size, 0, 2 * Math.PI, false);ctx.fill();@@ -235,7 +235,7 @@ export default class NoteMapWidget extends NoteContextAwareWidget {async loadNotesAndRelations(mapRootNoteId) {const resp = await server.post(`note-map/${mapRootNoteId}/${this.mapType}`);- this.calculateSizes(resp);+ this.calculateNodeSizes(resp);const links = this.getGroupedLinks(resp.links);@@ -279,18 +279,35 @@ export default class NoteMapWidget extends NoteContextAwareWidget {return Object.values(linksGroupedBySourceTarget);}- calculateSizes(resp) {- const {noteIdToDescendantCountMap} = resp;-+ calculateNodeSizes(resp) {this.noteIdToSizeMap = {};- for (const noteId in noteIdToDescendantCountMap) {- this.noteIdToSizeMap[noteId] = 4;+ if (this.mapType === 'tree') {+ const {noteIdToDescendantCountMap} = resp;++ for (const noteId in noteIdToDescendantCountMap) {+ this.noteIdToSizeMap[noteId] = 4;++ const count = noteIdToDescendantCountMap[noteId];++ if (count > 0) {+ this.noteIdToSizeMap[noteId] += 1 + Math.round(Math.log(count) / Math.log(1.5));+ }+ }+ }+ else if (this.mapType === 'link') {+ const noteIdToLinkCount = {};++ for (const link of resp.links) {+ noteIdToLinkCount[link.targetNoteId] = 1 + (noteIdToLinkCount[link.targetNoteId] || 0);+ }- const count = noteIdToDescendantCountMap[noteId];+ for (const [noteId] of resp.notes) {+ this.noteIdToSizeMap[noteId] = 4;- if (count > 0) {- this.noteIdToSizeMap[noteId] += 1 + Math.round(Math.log(count) / Math.log(1.5));+ if (noteId in noteIdToLinkCount) {+ this.noteIdToSizeMap[noteId] += Math.min(Math.pow(noteIdToLinkCount[noteId], 0.5), 15);+ }}}}diff --git a/src/routes/api/link_map.js b/src/routes/api/note_map.jssimilarity index 60%rename from src/routes/api/link_map.jsrename to src/routes/api/note_map.jsindex 8ef959e201..173ab97c4b 100644--- a/src/routes/api/link_map.js+++ b/src/routes/api/note_map.js@@ -2,83 +2,6 @@const becca = require("../../becca/becca");-function getRelations(noteId) {- const note = becca.getNote(noteId);-- if (!note) {- throw new Error(noteId);- }-- const allRelations = note.getOwnedRelations().concat(note.getTargetRelations());-- return allRelations.filter(rel => {- if (rel.name === 'relationMapLink' || rel.name === 'template') {- return false;- }- else if (rel.name === 'imageLink') {- const parentNote = becca.getNote(rel.noteId);-- return !parentNote.getChildNotes().find(childNote => childNote.noteId === rel.value);- }- else {- return true;- }- });-}--function collectRelations(noteId, relations, depth) {- if (depth === 0) {- return;- }-- for (const relation of getRelations(noteId)) {- if (!relations.has(relation)) {- if (!relation.value) {- continue;- }-- relations.add(relation);-- if (relation.noteId !== noteId) {- collectRelations(relation.noteId, relations, depth - 1);- } else if (relation.value !== noteId) {- collectRelations(relation.value, relations, depth - 1);- }- }- }-}--function getLinkMap(req) {- const {noteId} = req.params;- const {maxDepth} = req.body;-- let relations = new Set();-- collectRelations(noteId, relations, maxDepth);-- relations = Array.from(relations);-- const noteIds = new Set(relations.map(rel => rel.noteId)- .concat(relations.map(rel => rel.targetNoteId))- .concat([noteId]));-- const noteIdToLinkCountMap = {};-- for (const noteId of noteIds) {- noteIdToLinkCountMap[noteId] = getRelations(noteId).length;- }-- return {- noteIdToLinkCountMap,- links: Array.from(relations).map(rel => ({- id: rel.noteId + "-" + rel.name + "-" + rel.value,- sourceNoteId: rel.noteId,- targetNoteId: rel.value,- name: rel.name- }))- };-}-function buildDescendantCountMap() {const noteIdToCountMap = {};@@ -101,7 +24,7 @@ function buildDescendantCountMap() {return noteIdToCountMap;}-function getGlobalLinkMap(req) {+function getLinkMap(req) {const mapRootNote = becca.getNote(req.params.noteId);const noteIds = new Set();@@ -145,7 +68,7 @@ function getGlobalLinkMap(req) {};}-function getGlobalTreeMap(req) {+function getTreeMap(req) {const mapRootNote = becca.getNote(req.params.noteId);const noteIds = new Set();@@ -195,6 +118,5 @@ function getGlobalTreeMap(req) {module.exports = {getLinkMap,- getGlobalLinkMap,- getGlobalTreeMap+ getTreeMap};diff --git a/src/routes/routes.js b/src/routes/routes.jsindex 1d3d918f0c..353990319c 100644--- a/src/routes/routes.js+++ b/src/routes/routes.js@@ -32,7 +32,7 @@ const senderRoute = require('./api/sender');const filesRoute = require('./api/files');const searchRoute = require('./api/search');const specialNotesRoute = require('./api/special_notes.js');-const linkMapRoute = require('./api/link_map');+const noteMapRoute = require('./api/note_map.js');const clipperRoute = require('./api/clipper');const similarNotesRoute = require('./api/similar_notes');const keysRoute = require('./api/keys');@@ -220,9 +220,8 @@ function register(app) {apiRoute(GET, '/api/attributes/names', attributesRoute.getAttributeNames);apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute);- apiRoute(POST, '/api/notes/:noteId/link-map', linkMapRoute.getLinkMap);- apiRoute(POST, '/api/note-map/:noteId/tree', linkMapRoute.getGlobalTreeMap);- apiRoute(POST, '/api/note-map/:noteId/link', linkMapRoute.getGlobalLinkMap);+ apiRoute(POST, '/api/note-map/:noteId/tree', noteMapRoute.getTreeMap);+ apiRoute(POST, '/api/note-map/:noteId/link', noteMapRoute.getLinkMap);apiRoute(GET, '/api/special-notes/inbox/:date', specialNotesRoute.getInboxNote);apiRoute(GET, '/api/special-notes/date/:date', specialNotesRoute.getDateNote);