Skip to content

Commit 5520bde

Browse files
committed
Improve the position and size of the annotation popover
This tries to fit it onto the window rather than letting it be vertically partially hidden. If it is too large, some components can be scaled to fit.
1 parent 85707e6 commit 5520bde

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

histomicsui/web_client/stylesheets/popover/annotationPopover.styl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
pointer-events none
44
margin-left 15px
55
z-index 1000
6+
--arrow-offset .001px
67

78
.h-annotation-popover
89
position absolute
@@ -14,28 +15,29 @@
1415
border-radius 3px
1516
border 1px solid #000
1617
box-shadow 0 5px 10px rgba(0, 0, 0, 0.5)
18+
--arrow-size 13px
1719

1820
&:before
1921
content ""
2022
border-color transparent #000 transparent transparent
2123
border-style solid
22-
border-width 13px
24+
border-width var(--arrow-size)
2325
height 0
2426
width 0
2527
position absolute
26-
left -26px
27-
top calc(50% - 13px)
28+
left calc(-2 * var(--arrow-size))
29+
top calc(50% - var(--arrow-size) + var(--arrow-offset))
2830

2931
&:after
3032
content ""
3133
border-color transparent #fff transparent transparent
3234
border-style solid
33-
border-width 13px
35+
border-width var(--arrow-size)
3436
height 0
3537
width 0
3638
position absolute
37-
left -25px
38-
top calc(50% - 13px)
39+
left calc(-2 * var(--arrow-size) + 1px)
40+
top calc(50% - var(--arrow-size) + var(--arrow-offset))
3941

4042
> :not(.h-annotation-name)
4143
padding 0 20px

histomicsui/web_client/templates/popover/annotationPopover.pug

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@
4646
td #{value}
4747
- var add = elementAdditionalValues(element, annotation)
4848
if add
49-
| !{add}
49+
.additionalData
50+
| !{add}

histomicsui/web_client/views/popover/AnnotationPopover.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,19 @@ var AnnotationPopover = View.extend({
121121
if (!this._visible()) {
122122
this._hide();
123123
}
124-
this._height = this.$('.h-annotation-popover').height();
124+
this.$('.h-annotation-popover .additionalData').css('font-size', '');
125+
this._height = this.$('.h-annotation-popover').outerHeight(true);
126+
if (this._height > window.innerHeight) {
127+
this.$('.h-annotation-popover .additionalData').css('font-size', '90%');
128+
let delta = (this._height - this.$('.h-annotation-popover').outerHeight(true)) / 10;
129+
if (delta > 0) {
130+
let scale = 100 - (this._height - window.innerHeight) / delta;
131+
if (scale > 10 && scale < 100) {
132+
this.$('.h-annotation-popover .additionalData').css('font-size', `${scale}%`);
133+
}
134+
}
135+
this._height = this.$('.h-annotation-popover').outerHeight(true);
136+
}
125137
this._position();
126138
return this;
127139
},
@@ -275,10 +287,13 @@ var AnnotationPopover = View.extend({
275287
} else {
276288
evt = this._lastPositionEvt;
277289
}
278-
if (evt && this._visible()) {
290+
if (evt && this._visible() && this._height) {
291+
let idealPos = evt.pageY - this._height / 2;
292+
let pos = Math.max(0, Math.min(window.innerHeight - this._height, idealPos));
279293
this.$el.css({
280294
left: evt.pageX + 5,
281-
top: evt.pageY - this._height / 2
295+
top: pos,
296+
'--arrow-offset': (idealPos - pos) + 'px'
282297
});
283298
}
284299
},

0 commit comments

Comments
 (0)