Skip to content

Commit 7f674f1

Browse files
committed
set up minimap class
1 parent cfa2c0f commit 7f674f1

File tree

4 files changed

+128
-22
lines changed

4 files changed

+128
-22
lines changed

css/style.css

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ svg text {
2929
margin-bottom: 210px;
3030
}
3131

32-
button {
33-
position:absolute;
34-
background:white;
35-
border:none;
36-
outline:none;
37-
cursor:pointer;
38-
}
39-
40-
.node { cursor: pointer; }
41-
.link, .link--dashed {
42-
fill: none;
43-
stroke: #999;
44-
}
45-
.link--dashed {
46-
stroke-dasharray: 2,2;
47-
}
48-
4932
#graph {
5033
cursor:-webkit-grab;
5134
cursor:grab;
@@ -70,11 +53,42 @@ button {
7053
display:block;
7154
}
7255

56+
#toggle-minimap {
57+
display:block;
58+
cursor:pointer;
59+
}
60+
#minimap {
61+
pointer-events:none;
62+
position:fixed;
63+
z-index:100;
64+
top:40px;
65+
right:0;
66+
}
67+
#minimap * {
68+
pointer-events: all;
69+
}
70+
71+
#minimap canvas {
72+
background:rgba(200,200,200,0.5);
73+
margin-top:5px;
74+
width:100px;
75+
height:100px;
76+
}
77+
7378
/* svg classes */
7479
#drawing text, .link--labels text {
7580
pointer-events: none;
7681
}
7782

83+
.node { cursor: pointer; }
84+
.link, .link--dashed {
85+
fill: none;
86+
stroke: #999;
87+
}
88+
.link--dashed {
89+
stroke-dasharray: 2,2;
90+
}
91+
7892
.row--0, .link--label {
7993
fill: #f6f6f6;
8094
}

index.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
<option>paragraph</option>
1616
<option>passage</option>
1717
</select>
18+
19+
<div id="collapse" style="display:inline; float:right;">
20+
<button>[</button>
21+
<button>]</button>
22+
</div>
23+
</div>
24+
25+
<div id="minimap">
26+
<a id="toggle-minimap">hide>></a>
27+
<canvas>
28+
</canvas>
1829
</div>
1930

2031
<div id="drawing">
@@ -42,6 +53,7 @@
4253
<script src="js/render.js"></script>
4354
<script src="js/interact.js"></script>
4455
<script src="js/utils.js"></script>
56+
<script src="js/minimap.js"></script>
4557

4658
<script type="text/javascript">
4759
/* a lot of these global vars should be wrapped eventually */
@@ -68,8 +80,6 @@
6880
// 1. create Words and Links objects (in utils.js) */
6981
var wordObjs = createTestWords(4, 10, 10);
7082

71-
//var linkObjs = createTestLinks(3,3,3);
72-
//var linkObjs = createTestLinks(1,0,0);
7383
var linkObjs = createTestMultiLinks(1);
7484

7585
drawWords(wordObjs);
@@ -79,6 +89,8 @@
7989

8090
window.onload = function() {
8191

92+
const minimap = new Minimap();
93+
8294
const panel = new Panel('graph', 'drawing');
8395
const graph = new GraphLayout(panel.el);
8496
panel.onresize = graph.resize.bind(graph);

js/GraphLayout.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ const GraphLayout = (function() {
195195
node.y += dy;
196196
});
197197

198-
console.log('----- range',d3.extent(this.data[index].root.descendants(), d => d.x));
198+
/* console.log('----- range',d3.extent(this.data[index].root.descendants(), d => d.x));
199199
console.log('graft range',d3.extent(root.descendants(), d => d.x));
200200
console.log(data.anchor.x, dx);
201-
201+
*/
202202
// -------- in progress
203203
// test case : Pos_reg --> graft "outside"
204204
// test case : Promotes --> graft "inside"
@@ -324,7 +324,6 @@ const GraphLayout = (function() {
324324
function handleNodeClick(d) {
325325
unhoverNode(d);
326326
let word = this.words.splice(i, 1, d.node)[0];
327-
console.log('click', d, word);
328327
if (this.words.indexOf(word) < 0) {
329328
word.toggleHighlight(false);
330329
}

js/minimap.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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>>' : '&lt;&lt;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

Comments
 (0)