Skip to content

Commit

Permalink
[html-report] Add panning and wheel zoom for diagram
Browse files Browse the repository at this point in the history
* add Ctrl + wheel zoom in for diagram only instead of whole page
* add panning by mouse left click over the diagram
  • Loading branch information
Ujifman committed Nov 10, 2022
1 parent 35b406f commit b8c4163
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions com.archimatetool.reports/templates/html/js/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,14 @@ $(document).ready(function() {
slider.value = ((parseInt(slider.value)) + step);
setZoom();
}
// Register events wheel on root-panel-body
document.getElementsByClassName("root-panel-body")[0].addEventListener("wheel", (e) => {
// Zooming happens here
if (e.ctrlKey) {
e.preventDefault()
slider.value = ((parseInt(slider.value)) - e.deltaY/10)
setZoom()
}
})
}
});
56 changes: 56 additions & 0 deletions com.archimatetool.reports/templates/html/js/panelBodyScroller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
document.addEventListener('DOMContentLoaded', function () {
const ele = document.getElementsByClassName('root-panel-body')[0];
ele.style.cursor = 'grab';

let pos = { top: 0, left: 0, x: 0, y: 0 };
let isBlockLink = false;

[...ele.getElementsByTagName('area')].forEach((e)=> {
e.addEventListener('click', (e)=>{
if(isBlockLink) e.preventDefault();
});
})

const mouseDownHandler = function (e) {
e.preventDefault();
ele.style.cursor = 'grabbing';
ele.style.userSelect = 'none';

pos = {
left: ele.scrollLeft,
top: ele.scrollTop,
// Get the current mouse position
x: e.clientX,
y: e.clientY,
};

document.addEventListener('mousemove', mouseMoveHandler);
document.addEventListener('mouseup', mouseUpHandler);
};

const mouseMoveHandler = function (e) {
isBlockLink = true;
// How far the mouse has been moved
const dx = e.clientX - pos.x;
const dy = e.clientY - pos.y;

// Scroll the element
ele.scrollTop = pos.top - dy;
ele.scrollLeft = pos.left - dx;
};

const mouseUpHandler = function () {
ele.style.cursor = 'grab';
ele.style.removeProperty('user-select');

document.removeEventListener('mousemove', mouseMoveHandler);
document.removeEventListener('mouseup', mouseUpHandler);

setTimeout(() => {
isBlockLink = false;
}, 100)
};

// Attach the handler
ele.addEventListener('mousedown', mouseDownHandler);
});
1 change: 1 addition & 0 deletions com.archimatetool.reports/templates/st/frame.stg
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ frame(element, map) ::= <<
<link type="text/css" rel="stylesheet" href="../../css/i18n.css">
<script type="text/javascript" src="../../js/frame.js"></script>
<script type="text/javascript" src="../../js/imageMapResizer.min.js"></script>
<script type="text/javascript" src="../../js/panelBodyScroller.js"></script>
</head>

<body>
Expand Down

2 comments on commit b8c4163

@evlibra
Copy link

@evlibra evlibra commented on b8c4163 Jan 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This blocks selection of text in report documentation frames, e.g. for copy-paste. Can the panning by mouse left click be limited to the Diagram window only?

@Phillipus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding this. See #843 (comment)

Please sign in to comment.