@@ -21,58 +21,54 @@ class Tooltip {
21
21
22
22
dom.Element tooltipElem;
23
23
24
- Tooltip (dom.Element this .element, dom.Node this .node,
25
- Scope this .scope) {
26
-
27
- element.onMouseEnter.listen ((event) {
28
- _createTemplate ();
29
- });
30
-
31
- element.onMouseLeave.listen ((event) {
32
- _destroyTemplate ();
33
- });
24
+ Tooltip (this .element, this .node, this .scope) {
25
+ element
26
+ ..onMouseEnter.listen ((_) => _createTemplate ())
27
+ ..onMouseLeave.listen ((_) => _destroyTemplate ());
34
28
}
35
29
36
30
_createTemplate () {
37
31
assert (displayModel != null );
38
32
39
33
tooltipElem = new dom.DivElement ();
40
34
41
- dom.ImageElement imgElem = new dom.ImageElement ();
42
- imgElem. width = displayModel.imgWidth;
43
- imgElem .src = displayModel.imgUrl;
35
+ dom.ImageElement imgElem = new dom.ImageElement ()
36
+ .. width = displayModel.imgWidth
37
+ . .src = displayModel.imgUrl;
44
38
tooltipElem.append (imgElem);
45
39
46
40
if (displayModel.text != null ) {
47
- dom.DivElement textSpan = new dom.DivElement ();
48
- textSpan. appendText (displayModel.text);
49
- textSpan. style.color = "white" ;
50
- textSpan. style.fontSize = "smaller" ;
51
- textSpan .style.paddingBottom = "5px" ;
41
+ dom.DivElement textSpan = new dom.DivElement ()
42
+ .. appendText (displayModel.text)
43
+ .. style.color = "white"
44
+ .. style.fontSize = "smaller"
45
+ . .style.paddingBottom = "5px" ;
52
46
53
47
tooltipElem.append (textSpan);
54
48
}
55
49
56
- tooltipElem.style.padding = "5px" ;
57
- tooltipElem.style.paddingBottom = "0px" ;
58
- tooltipElem.style.backgroundColor = "black" ;
59
- tooltipElem.style.borderRadius = "5px" ;
60
- tooltipElem.style.width = "${displayModel .imgWidth .toString ()}px" ;
50
+ tooltipElem.style
51
+ ..padding = "5px"
52
+ ..paddingBottom = "0px"
53
+ ..backgroundColor = "black"
54
+ ..borderRadius = "5px"
55
+ ..width = "${displayModel .imgWidth .toString ()}px" ;
61
56
62
57
// find the coordinates of the parent DOM element
63
58
Rectangle bounds = element.getBoundingClientRect ();
64
59
int left = (bounds.left + dom.window.pageXOffset).toInt ();
65
60
int top = (bounds.top + dom.window.pageYOffset).toInt ();
66
- int width = ( bounds.width) .toInt ();
67
- int height = ( bounds.height) .toInt ();
61
+ int width = bounds.width.toInt ();
62
+ int height = bounds.height.toInt ();
68
63
69
64
// position the tooltip.
70
65
// Figure out where the containing element sits in the window.
71
66
int tooltipLeft = left + width + 10 ;
72
67
int tooltipTop = top - height;
73
- tooltipElem.style.position = "absolute" ;
74
- tooltipElem.style.top = "${tooltipTop }px" ;
75
- tooltipElem.style.left = "${tooltipLeft }px" ;
68
+ tooltipElem.style
69
+ ..position = "absolute"
70
+ ..top = "${top - height }px"
71
+ ..left = "${left + width + 10 }px" ;
76
72
77
73
// Add the tooltip to the document body. We add it here because
78
74
// we need to position it absolutely, without reference to its
@@ -90,6 +86,5 @@ class TooltipModel {
90
86
String text;
91
87
int imgWidth;
92
88
93
- TooltipModel (String this .imgUrl, String this .text,
94
- int this .imgWidth);
89
+ TooltipModel (this .imgUrl, this .text, this .imgWidth);
95
90
}
0 commit comments