@@ -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>>' : '<<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