Skip to content

Commit e7e61c8

Browse files
committed
add links to minimap
1 parent 7f674f1 commit e7e61c8

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

js/minimap.js

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,73 @@ const Minimap = (function() {
77
let h;
88
let w;
99

10-
const ROW_HEIGHT = 15;
10+
const RECT_HEIGHT = 3;
11+
const PADDING = 3;
1112
const COLOR = {
1213
word: '#888',
1314
untagged: '#aaa',
1415
selected: 'crimson',
1516
link: 'blue'
1617
}
1718

18-
wordColor = '#888';
19-
20-
2119
function update() {
2220
const ROW_WIDTH = Config.svgWidth;
2321
const r = w / ROW_WIDTH;
2422

2523
ctx.clearRect(0,0,w,h);
26-
24+
ctx.globalAlpha = 1;
25+
26+
// draw word
27+
let slots = [];
2728
rows.forEach(function(row, i) {
29+
slots[i] = (slots[i - 1] || 0) + row.maxSlots + 1;
30+
2831
row.words.forEach(function(word) {
32+
// choose color
2933
ctx.fillStyle = word.tag ? COLOR.word : COLOR.untagged;
3034
if (word.isSelected) {
3135
ctx.fillStyle = COLOR.selected;
3236
}
33-
ctx.fillRect(word.leftX * r, i * ROW_HEIGHT * 1.3, word.underneathRect.width() * r, ROW_HEIGHT);
37+
38+
// add word rectangle
39+
ctx.fillRect(word.underneathRect.x() * r, (slots[i] - 1) * RECT_HEIGHT + i * PADDING, word.underneathRect.width() * r,RECT_HEIGHT + PADDING / 3);
3440
});
41+
3542
});
3643

44+
ctx.globalAlpha = 0.75;
3745
linkObjs.forEach(function(link) {
3846
let minRow = link.rootMinWord.row.idx;
3947
let maxRow = link.rootMaxWord.row.idx;
4048

41-
let width = maxRow > minRow ? ROW_WIDTH : link.linesRightX[0] - link.linesLeftX[0];
49+
let width = maxRow > minRow ? ROW_WIDTH : link.linesRightX[link.linesRightX.length - 1] - link.linesLeftX[0];
4250

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);
51+
let y = (slots[minRow - 1] || 0) + rows[minRow].maxSlots - link.h;
52+
53+
ctx.fillStyle = COLOR.link;
54+
55+
if (!link.isSelected && link.style) {
56+
if (link.style.stroke instanceof LinearGradient) {
57+
let x = (maxRow > minRow) ? 0 : link.linesLeftX[0];
58+
let gradient = ctx.createLinearGradient(x * r,0,width * r,0);
59+
gradient.addColorStop(0, link.style.stroke.c1);
60+
gradient.addColorStop(1, link.style.stroke.c2);
61+
ctx.fillStyle = gradient;
62+
}
63+
else {
64+
ctx.fillStyle = link.style.stroke;
65+
}
66+
}
67+
ctx.fillRect(link.linesLeftX[0] * r, y * RECT_HEIGHT + minRow * PADDING, width * r, RECT_HEIGHT);
4568

4669
if (maxRow > minRow) {
4770
for (let i = minRow + 1; i < maxRow; ++i) {
48-
ctx.fillRect(0, i * ROW_HEIGHT * 1.3, ROW_WIDTH * r, ROW_HEIGHT * 0.2);
71+
y = slots[i - 1] + rows[i].maxSlots - link.h;
72+
ctx.fillRect(0, y * RECT_HEIGHT + i * PADDING, width * r, RECT_HEIGHT);
4973
}
50-
ctx.fillRect(0, maxRow * ROW_HEIGHT * 1.3, link.linesRightX[link.linesRightX.length - 1] * r, ROW_HEIGHT * 0.2);
74+
75+
y = slots[maxRow - 1] + rows[maxRow].maxSlots - link.h;
76+
ctx.fillRect(0, y * RECT_HEIGHT + maxRow * PADDING, link.linesRightX[link.linesRightX.length - 1] * r, RECT_HEIGHT);
5177
}
5278
});
5379

@@ -69,8 +95,8 @@ const Minimap = (function() {
6995
view.style.visibility = show ? 'visible' : 'hidden';
7096
};
7197

72-
h = view.getBoundingClientRect().height;
73-
w = view.getBoundingClientRect().width * 3;
98+
h = view.height;
99+
w = view.width;
74100
ctx = view.getContext('2d');
75101
update();
76102
}

0 commit comments

Comments
 (0)