Skip to content

Commit d5953d4

Browse files
committed
resizable bottom panel
1 parent 562813e commit d5953d4

File tree

4 files changed

+81
-22
lines changed

4 files changed

+81
-22
lines changed

css/style.css

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,28 @@ button {
4040
.node { cursor: pointer; }
4141

4242
#graph {
43-
cursor:move;
43+
cursor:-webkit-grab;
44+
cursor:grab;
4445
width:100%;
4546
height:220px;
4647
border-top: 1px solid #ccc;
4748
background:#fff;
4849
position:fixed;
4950
bottom:0;
5051
left:0;
51-
overflow:hidden;
5252
}
5353

54+
#graph:before {
55+
cursor:ns-resize;
56+
content:'';
57+
width:100%;
58+
height:7px;
59+
margin-top:-3.5px;
60+
position:absolute;
61+
top:0;
62+
left:0;
63+
display:block;
64+
}
5465

5566
/* svg classes */
5667
#drawing text, .link--labels text {

index.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<script src="js/enums.js"></script>
3434
<script src="js/config.js"></script>
3535
<script src="js/parser.js"></script>
36+
<script src="js/Panel.js"></script>
3637
<script src="js/GraphLayout.js"></script>
3738
<script src="js/style.js"></script>
3839
<script src="js/annotate.js"></script>
@@ -41,7 +42,6 @@
4142
<script src="js/utils.js"></script>
4243

4344
<script type="text/javascript">
44-
4545
/* a lot of these global vars should be wrapped eventually */
4646
var draw = SVG('drawing').size(Config.svgWidth, Config.svgHeight);
4747
var rowGroup = draw.group();
@@ -77,8 +77,10 @@
7777
changeSizeOfSVGPanel(window.innerWidth - 16, (rows[rows.length - 1].lineBottom.y() ) + 1);
7878

7979
window.onload = function() {
80-
var Panel = new GraphLayout();
81-
var parser = new Parser();
80+
81+
const panel = new Panel('graph', 'drawing');
82+
const graph = new GraphLayout(panel.el);
83+
const parser = new Parser();
8284

8385
var prevWidth = Config.svgWidth;
8486
function svgResize() {
@@ -95,22 +97,22 @@
9597
}
9698

9799
draw.on('wordSelected', function() {
98-
Panel.graph(getSelectedObjects());
100+
graph.graph(getSelectedObjects());
99101
});
100102

101103
document.querySelector('#graph>button').onclick = function() {
102104
let words = getSelectedObjects();
103105
if (words.length > 0) {
104-
Panel.graph(words);
106+
graph.graph(words);
105107
}
106108
else {
107-
Panel.clear();
109+
graph.clear();
108110
}
109111
};
110112

111113
function changeDataset(index = 1) {
112114
parser.readJson(`./data/data${index}.json`, function() {
113-
Panel.clear();
115+
graph.clear();
114116

115117
// construct word objects and tags from tokens, entities, and triggers
116118
const words = parser.tokens.map((token, i) => new Word(token, i));
@@ -224,13 +226,12 @@
224226
// linkObjs.forEach(link => link.style = styles[link.style]);
225227
drawWords(wordObjs);
226228
drawLinks(linkObjs);
227-
if (Panel.isOpen) { Panel.close(); }
228229
changeSizeOfSVGPanel(window.innerWidth - 16, (rows[rows.length - 1].lineBottom.y() ) + 1);
229230
}
230231

231232
function resize() {
232233
svgResize();
233-
Panel.resize();
234+
graph.resize();
234235
}
235236

236237
document.getElementById('dataset').onchange = function() {

js/GraphLayout.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
class GraphLayout {
2-
constructor() {
3-
this.isOpen = false;
4-
5-
// references to dom elements
6-
this.drawing = document.getElementById('drawing');
7-
this.div = document.getElementById('graph') ||
8-
document.createElement('div');
9-
this.div.id = 'graph';
10-
document.body.appendChild(this.div);
2+
constructor(el) {
3+
// container element
4+
this.div = el;
115

126
// dimensions & properties
137
this.bounds = this.div.getBoundingClientRect();
148

159
// d3 dom references
16-
this.svg = d3.select('#graph').append('svg')
10+
this.svg = d3.select(this.div).append('svg')
1711
.attr('width', this.bounds.width)
1812
.attr('height', this.bounds.height);
1913
this.g = this.svg.append('g');
@@ -32,7 +26,7 @@ class GraphLayout {
3226
.call(d3.drag()
3327
.on('drag', () => {
3428
this.dx += d3.event.dx;
35-
this.dy += d3.event.dy;
29+
// this.dy += d3.event.dy;
3630
this.adjustMargins(this.dx, this.dy);
3731
})
3832
)

js/Panel.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const Panel = (function() {
2+
3+
class Panel {
4+
constructor(el, el2) {
5+
6+
const container = this.el = document.getElementById(el) || document.body;
7+
const above = document.getElementById(el2);
8+
9+
let height = parseInt(window.getComputedStyle(container).height);
10+
container.style.height = height;
11+
12+
let y;
13+
let isResizingPanel = false;
14+
15+
// add listeners
16+
document.addEventListener('mousemove', drag);
17+
document.addEventListener('mouseup', dragend);
18+
document.addEventListener('mouseleave', dragend);
19+
container.addEventListener('mousedown', function(e) {
20+
if (e.offsetY < 3) {
21+
isResizingPanel = true;
22+
y = e.y;
23+
}
24+
});
25+
26+
function drag(e) {
27+
if (isResizingPanel) {
28+
const dy = e.y - y;
29+
y = e.y;
30+
31+
// clamp
32+
let max = window.innerHeight - 30;
33+
let min = 30;
34+
35+
height = Math.min(Math.max(min, height - dy), max);
36+
container.style.height = height;
37+
38+
if (above) {
39+
above.style.marginBottom = height + 10;
40+
}
41+
}
42+
}
43+
44+
function dragend(e) {
45+
isResizingPanel = false;
46+
}
47+
48+
}
49+
}
50+
51+
return Panel;
52+
53+
})();

0 commit comments

Comments
 (0)