Skip to content

Commit 52f1a3c

Browse files
etpinardtimelyportfolio
authored andcommitted
incremental progress toward working scrolling legend after resize
2 parents c29e81e + 5deae1b commit 52f1a3c

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

src/components/legend/draw.js

+31-22
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ module.exports = function draw(gd) {
5656
});
5757

5858
var clipPath = fullLayout._topdefs.selectAll('#' + clipId)
59-
.data([0])
60-
.enter().append('clipPath')
59+
.data([0]);
60+
61+
clipPath.enter().append('clipPath')
6162
.attr('id', clipId)
6263
.append('rect');
6364

@@ -210,7 +211,7 @@ module.exports = function draw(gd) {
210211

211212
legend.attr('transform', 'translate(' + lx + ',' + ly + ')');
212213

213-
clipPath.attr({
214+
clipPath.select('rect').attr({
214215
width: opts.width,
215216
height: scrollheight,
216217
x: 0,
@@ -220,49 +221,57 @@ module.exports = function draw(gd) {
220221
legend.call(Drawing.setClipUrl, clipId);
221222

222223
// If scrollbar should be shown.
223-
if(gd.firstRender && opts.height - scrollheight > 0 && !gd._context.staticPlot) {
224+
if(opts.height - scrollheight > 0 && !gd._context.staticPlot) {
225+
224226
bg.attr({
225227
width: opts.width - 2 * opts.borderwidth + constants.scrollBarWidth
226228
});
227229

228230
clipPath.attr({
229231
width: opts.width + constants.scrollBarWidth
230232
});
233+
234+
235+
// Move scrollbar to starting position
236+
scrollBar.call(
237+
Drawing.setRect,
238+
opts.width - (constants.scrollBarWidth + constants.scrollBarMargin),
239+
constants.scrollBarMargin,
240+
constants.scrollBarWidth,
241+
constants.scrollBarHeight
242+
);
243+
244+
legend.on('wheel',null);
231245

232-
legend.node().addEventListener('wheel', function(e) {
246+
legend.on('wheel', function(){
247+
var e = d3.event;
233248
e.preventDefault();
234-
scrollHandler(e.deltaY / 20);
235-
});
249+
scrollHandler(e.deltaY / 20, scrollheight);
250+
})
251+
252+
scrollBar.on('mousedown',null);
236253

237-
scrollBar.node().addEventListener('mousedown', function(e) {
254+
scrollBar.on('mousedown', function(){
255+
var e = d3.event;
238256
e.preventDefault();
239-
257+
240258
function mMove(e) {
241259
if(e.buttons === 1) {
242-
scrollHandler(e.movementY);
260+
scrollHandler(e.movementY, scrollheight);
243261
}
244262
}
245-
263+
246264
function mUp() {
247265
scrollBar.node().removeEventListener('mousemove', mMove);
248266
window.removeEventListener('mouseup', mUp);
249267
}
250-
268+
251269
window.addEventListener('mousemove', mMove);
252270
window.addEventListener('mouseup', mUp);
253271
});
254-
255-
// Move scrollbar to starting position on the first render
256-
scrollBar.call(
257-
Drawing.setRect,
258-
opts.width - (constants.scrollBarWidth + constants.scrollBarMargin),
259-
constants.scrollBarMargin,
260-
constants.scrollBarWidth,
261-
constants.scrollBarHeight
262-
);
263272
}
264273

265-
function scrollHandler(delta) {
274+
function scrollHandler(delta, scrollheight) {
266275

267276
var scrollBarTrack = scrollheight - constants.scrollBarHeight - 2 * constants.scrollBarMargin,
268277
translateY = scrollBox.attr('data-scroll'),

test/image/baselines/gl3d_tet.png

-3.72 KB
Loading

test/image/mocks/gl3d_tet.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@
88
"i":[0, 0, 0, 1],
99
"j":[1, 2, 3, 2],
1010
"k":[2, 3, 1, 3],
11-
"facecolors": [
11+
"facecolor": [
1212
"rgb(0, 0, 0)",
1313
"rgb(255, 0, 0)",
1414
"rgb(0, 255, 0)",
1515
"rgb(0, 0, 255)"
1616
]
1717
}],
1818
"layout": {
19-
"title": "Tetrahedra"
19+
"title": "Tetrahedra",
20+
"scene": {
21+
"camera": {
22+
"eye": {
23+
"x": 1.5,
24+
"y": -1.5,
25+
"z": 0.5
26+
}
27+
}
28+
}
2029
}
2130
}

0 commit comments

Comments
 (0)