Skip to content

Commit c22a748

Browse files
committed
swipe minimap to scroll page
1 parent 1bfc21e commit c22a748

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

css/style.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ svg text {
7979
height:100px;
8080
}
8181

82+
.noselect {
83+
-webkit-touch-callout: none; /* iOS Safari */
84+
-webkit-user-select: none; /* Safari */
85+
-khtml-user-select: none; /* Konqueror HTML */
86+
-moz-user-select: none; /* Firefox */
87+
-ms-user-select: none; /* Internet Explorer/Edge */
88+
user-select: none; /* Non-prefixed version, currently
89+
supported by Chrome and Opera */
90+
}
91+
8292
/* svg classes */
8393
#drawing text, .link--labels text {
8494
pointer-events: none;

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</div>
2323
</div>
2424

25-
<div id="minimap">
25+
<div id="minimap" class="noselect">
2626
<a id="toggle-minimap">hide>></a>
2727
<canvas>
2828
</canvas>

js/GraphLayout.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const GraphLayout = (function() {
7979

8080
d3.select(this.div).append('button')
8181
.text('⤆ reset ⤇')
82+
.attr('class', 'noselect')
8283
.on('click', () => {
8384
this.dx = 0;
8485
this.adjustMargins();

js/minimap.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Minimap = (function() {
1414
word: '#888',
1515
untagged: '#aaa',
1616
selected: 'crimson',
17-
link: 'blue'
17+
link: 'cyan'
1818
}
1919

2020
function update() {
@@ -46,6 +46,7 @@ const Minimap = (function() {
4646

4747
});
4848

49+
// draw links
4950
ctx.globalAlpha = 0.75;
5051
linkObjs.forEach(function(link) {
5152
let minRow = link.rootMinWord.row.idx;
@@ -55,6 +56,7 @@ const Minimap = (function() {
5556

5657
let y = (slots[minRow - 1] || 0) + rows[minRow].maxSlots - link.h;
5758

59+
// choose color
5860
ctx.fillStyle = COLOR.link;
5961

6062
if (!link.isSelected && link.style) {
@@ -71,6 +73,7 @@ const Minimap = (function() {
7173
}
7274
ctx.fillRect(link.linesLeftX[0] * r, y * RECT_HEIGHT + minRow * PADDING, width * r, RECT_HEIGHT);
7375

76+
// draw links spanning multiple rows
7477
if (maxRow > minRow) {
7578
for (let i = minRow + 1; i < maxRow; ++i) {
7679
y = slots[i - 1] + rows[i].maxSlots - link.h;
@@ -82,12 +85,30 @@ const Minimap = (function() {
8285
}
8386
});
8487

88+
// translate canvas contents according to scroll position
8589
dy = (slots[scrollIndex - 1] || 0) * RECT_HEIGHT + scrollIndex * PADDING;
8690
ctx.setTransform( 1, 0, 0, 1, 0, -dy );
8791

8892
window.requestAnimationFrame(update);
8993
}
9094

95+
// drag events
96+
let drag = 0;
97+
let mousedown = false;
98+
function onmousedown(e) {
99+
drag = e.y;
100+
mousedown = true;
101+
}
102+
function onmousemove(e) {
103+
if (mousedown) {
104+
document.body.scrollTop += (e.y - drag) * window.innerHeight / h;
105+
drag = e.y;
106+
}
107+
}
108+
function onmouseup() {
109+
mousedown = false;
110+
}
111+
91112
class Minimap {
92113
constructor() {
93114
if (singleton === false) {
@@ -96,13 +117,20 @@ const Minimap = (function() {
96117
view = document.querySelector('#minimap canvas');
97118
let toggle = document.getElementById('toggle-minimap');
98119

120+
// show / hide minimap
99121
toggle.onclick = function() {
100122
show = !show;
101123
this.style.textAlign = show ? 'left' : 'right';
102124
this.innerHTML = show ? 'hide>>' : '&lt;&lt;minimap';
103125
view.style.visibility = show ? 'visible' : 'hidden';
104126
};
105127

128+
// swipe minimap to scroll page
129+
view.onmousedown = onmousedown;
130+
document.addEventListener('mousemove', onmousemove);
131+
document.addEventListener('mouseup', onmouseup);
132+
document.addEventListener('mouseleave', onmouseup);
133+
106134
h = view.height;
107135
w = view.width;
108136
ctx = view.getContext('2d');

0 commit comments

Comments
 (0)