Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: packages/charted/lib/charts/behaviors/axis_label_tooltip.dart

Issue 1521693002: Roll Observatory deps (charted -> ^0.3.0) (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // 1 //
2 // Copyright 2014 Google Inc. All rights reserved. 2 // Copyright 2014 Google Inc. All rights reserved.
3 // 3 //
4 // Use of this source code is governed by a BSD-style 4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at 5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd 6 // https://developers.google.com/open-source/licenses/bsd
7 // 7 //
8 8
9 part of charted.charts; 9 part of charted.charts;
10 10
(...skipping 20 matching lines...) Expand all
31 } 31 }
32 32
33 void dispose() { 33 void dispose() {
34 _disposer.dispose(); 34 _disposer.dispose();
35 if (_tooltipRoot != null) _tooltipRoot.remove(); 35 if (_tooltipRoot != null) _tooltipRoot.remove();
36 } 36 }
37 37
38 void _subscribe() { 38 void _subscribe() {
39 var elements = _area.host.querySelectorAll(_AXIS_SELECTOR); 39 var elements = _area.host.querySelectorAll(_AXIS_SELECTOR);
40 _disposer.dispose(); 40 _disposer.dispose();
41 _disposer.addAll( 41 _disposer
42 elements.map((x) => x.onMouseOver.listen(_handleMouseOver))); 42 .addAll(elements.map((x) => x.onMouseOver.listen(_handleMouseOver)));
43 _disposer.addAll( 43 _disposer.addAll(elements.map((x) => x.onMouseOut.listen(_handleMouseOut)));
44 elements.map((x) => x.onMouseOut.listen(_handleMouseOut)));
45 } 44 }
46 45
47 void _handleMouseOver(MouseEvent e) { 46 void _handleMouseOver(MouseEvent e) {
48 Element target = e.target; 47 Element target = e.target;
49 if (!target.dataset.containsKey('detail')) return; 48 if (!target.dataset.containsKey('detail')) return;
50 ensureTooltipRoot(); 49 ensureTooltipRoot();
51 ensureRenderAreaRect(); 50 ensureRenderAreaRect();
52 51
53 _tooltipRoot.text = target.dataset['detail']; 52 _tooltipRoot.text = target.dataset['detail'];
54 var position = computeTooltipPosition( 53 var position = computeTooltipPosition(target.getBoundingClientRect(),
55 target.getBoundingClientRect(), 54 _tooltipRoot.getBoundingClientRect(), _renderAreaRect);
56 _tooltipRoot.getBoundingClientRect(),
57 _renderAreaRect);
58 55
59 _tooltipRoot.style 56 _tooltipRoot.style
60 ..left = '${position.x}px' 57 ..left = '${position.x}px'
61 ..top = '${position.y}px' 58 ..top = '${position.y}px'
62 ..opacity = '1' 59 ..opacity = '1'
63 ..visibility = 'visible'; 60 ..visibility = 'visible';
64 } 61 }
65 62
66 void _handleMouseOut(MouseEvent e) { 63 void _handleMouseOut(MouseEvent e) {
67 Element target = e.target; 64 Element target = e.target;
(...skipping 19 matching lines...) Expand all
87 _area.host.append(_tooltipRoot); 84 _area.host.append(_tooltipRoot);
88 } 85 }
89 } 86 }
90 87
91 void ensureRenderAreaRect() { 88 void ensureRenderAreaRect() {
92 var layout = _area.layout; 89 var layout = _area.layout;
93 _hostAreaRect = _area.host.getBoundingClientRect(); 90 _hostAreaRect = _area.host.getBoundingClientRect();
94 _renderAreaRect = new math.Rectangle( 91 _renderAreaRect = new math.Rectangle(
95 _hostAreaRect.left + layout.chartArea.x + layout.renderArea.x, 92 _hostAreaRect.left + layout.chartArea.x + layout.renderArea.x,
96 _hostAreaRect.top + layout.chartArea.y + layout.renderArea.y, 93 _hostAreaRect.top + layout.chartArea.y + layout.renderArea.y,
97 layout.renderArea.width, layout.renderArea.height); 94 layout.renderArea.width,
95 layout.renderArea.height);
98 } 96 }
99 97
100 /// Computes the ideal tooltip position based on orientation. 98 /// Computes the ideal tooltip position based on orientation.
101 math.Point computeTooltipPosition(math.Rectangle label, 99 math.Point computeTooltipPosition(
102 math.Rectangle tooltip, math.Rectangle renderArea) { 100 math.Rectangle label, math.Rectangle tooltip, math.Rectangle renderArea) {
103 var x = label.left + (label.width - tooltip.width) / 2, 101 var x = label.left + (label.width - tooltip.width) / 2,
104 y = label.top + (label.height - tooltip.height) / 2; 102 y = label.top + (label.height - tooltip.height) / 2;
105 103
106 if (x + tooltip.width > renderArea.right) { 104 if (x + tooltip.width > renderArea.right) {
107 x = renderArea.right - tooltip.width; 105 x = renderArea.right - tooltip.width;
108 } else if (x < renderArea.left) { 106 } else if (x < renderArea.left) {
109 x = renderArea.left; 107 x = renderArea.left;
110 } 108 }
111 109
112 if (y + tooltip.height > renderArea.bottom) { 110 if (y + tooltip.height > renderArea.bottom) {
113 y = renderArea.bottom - tooltip.height; 111 y = renderArea.bottom - tooltip.height;
114 } else if (y < renderArea.top) { 112 } else if (y < renderArea.top) {
115 y = renderArea.top; 113 y = renderArea.top;
116 } 114 }
117 115
118 return new math.Point(x - _hostAreaRect.left, y - _hostAreaRect.top); 116 return new math.Point(x - _hostAreaRect.left, y - _hostAreaRect.top);
119 } 117 }
120 } 118 }
OLDNEW
« no previous file with comments | « packages/async/test/subscription_stream_test.dart ('k') | packages/charted/lib/charts/behaviors/chart_tooltip.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698