1+ const Minimap = ( function ( ) {
2+
3+ let show = true ;
4+ let singleton = false ;
5+ let view ;
6+ let ctx ;
7+ let h ;
8+ let w ;
9+
10+ const ROW_HEIGHT = 15 ;
11+ const COLOR = {
12+ word : '#888' ,
13+ untagged : '#aaa' ,
14+ selected : 'crimson' ,
15+ link : 'blue'
16+ }
17+
18+ wordColor = '#888' ;
19+
20+
21+ function update ( ) {
22+ const ROW_WIDTH = Config . svgWidth ;
23+ const r = w / ROW_WIDTH ;
24+
25+ ctx . clearRect ( 0 , 0 , w , h ) ;
26+
27+ rows . forEach ( function ( row , i ) {
28+ row . words . forEach ( function ( word ) {
29+ ctx . fillStyle = word . tag ? COLOR . word : COLOR . untagged ;
30+ if ( word . isSelected ) {
31+ ctx . fillStyle = COLOR . selected ;
32+ }
33+ ctx . fillRect ( word . leftX * r , i * ROW_HEIGHT * 1.3 , word . underneathRect . width ( ) * r , ROW_HEIGHT ) ;
34+ } ) ;
35+ } ) ;
36+
37+ linkObjs . forEach ( function ( link ) {
38+ let minRow = link . rootMinWord . row . idx ;
39+ let maxRow = link . rootMaxWord . row . idx ;
40+
41+ let width = maxRow > minRow ? ROW_WIDTH : link . linesRightX [ 0 ] - link . linesLeftX [ 0 ] ;
42+
43+ ctx . fillStyle = link . isSelected ? COLOR . selected : COLOR . link ;
44+ ctx . fillRect ( link . linesLeftX [ 0 ] * r , minRow * ROW_HEIGHT * 1.3 , width * r , ROW_HEIGHT * 0.2 ) ;
45+
46+ if ( maxRow > minRow ) {
47+ for ( let i = minRow + 1 ; i < maxRow ; ++ i ) {
48+ ctx . fillRect ( 0 , i * ROW_HEIGHT * 1.3 , ROW_WIDTH * r , ROW_HEIGHT * 0.2 ) ;
49+ }
50+ ctx . fillRect ( 0 , maxRow * ROW_HEIGHT * 1.3 , link . linesRightX [ link . linesRightX . length - 1 ] * r , ROW_HEIGHT * 0.2 ) ;
51+ }
52+ } ) ;
53+
54+ window . requestAnimationFrame ( update ) ;
55+ }
56+
57+ class Minimap {
58+ constructor ( ) {
59+ if ( singleton === false ) {
60+ singleton = true ;
61+
62+ view = document . querySelector ( '#minimap canvas' ) ;
63+ let toggle = document . getElementById ( 'toggle-minimap' ) ;
64+
65+ toggle . onclick = function ( ) {
66+ show = ! show ;
67+ this . style . textAlign = show ? 'left' : 'right' ;
68+ this . innerHTML = show ? 'hide>>' : '<<minimap' ;
69+ view . style . visibility = show ? 'visible' : 'hidden' ;
70+ } ;
71+
72+ h = view . getBoundingClientRect ( ) . height ;
73+ w = view . getBoundingClientRect ( ) . width * 3 ;
74+ ctx = view . getContext ( '2d' ) ;
75+ update ( ) ;
76+ }
77+ }
78+ }
79+
80+ return Minimap ;
81+ } ) ( ) ;
0 commit comments