From 83c6f86d26e2959894d91fe48383d224cf8eacf8 Mon Sep 17 00:00:00 2001 From: azivner Date: Tue, 13 Nov 2018 22:05:32 +0100 Subject: [PATCH] re-center button, WIP --- .../services/note_detail_relation_map.js | 23 ++++++++++++++++++- src/views/details/relation_map.ejs | 5 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/public/javascripts/services/note_detail_relation_map.js b/src/public/javascripts/services/note_detail_relation_map.js index d077c2d61..4846b41c3 100644 --- a/src/public/javascripts/services/note_detail_relation_map.js +++ b/src/public/javascripts/services/note_detail_relation_map.js @@ -14,6 +14,7 @@ const $relationMapContainer = $("#relation-map-container"); const $createChildNote = $("#relation-map-create-child-note"); const $zoomInButton = $("#relation-map-zoom-in"); const $zoomOutButton = $("#relation-map-zoom-out"); +const $centerButton = $("#relation-map-center"); let mapData; let jsPlumbInstance; @@ -168,7 +169,7 @@ function initPanZoom() { pzInstance = panzoom($relationMapContainer[0], { maxZoom: 2, - minZoom: 0.1, + minZoom: 0.3, smoothScroll: false, onMouseDown: function(event) { if (clipboard) { @@ -512,6 +513,26 @@ function getMousePosition(evt) { }; } +$centerButton.click(() => { + if (mapData.notes.length === 0) { + return; // nothing to recenter on + } + + let totalX = 0, totalY = 0; + + for (const note of mapData.notes) { + totalX += note.x; + totalY += note.y; + } + + let averageX = totalX / mapData.notes.length; + let averageY = totalY / mapData.notes.length; + + console.log(averageX, averageY); + + //pzInstance.moveTo(averageX, averageY); +}); + $component.on("drop", dropNoteOntoRelationMapHandler); $component.on("dragover", ev => ev.preventDefault()); diff --git a/src/views/details/relation_map.ejs b/src/views/details/relation_map.ejs index 3b4eae97b..22a22e583 100644 --- a/src/views/details/relation_map.ejs +++ b/src/views/details/relation_map.ejs @@ -6,6 +6,11 @@ Create child note + +