Skip to content

Commit abbc047

Browse files
committed
cleanup
1 parent bf3b8d8 commit abbc047

1 file changed

Lines changed: 34 additions & 34 deletions

File tree

src/lib/toolbar.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -89,43 +89,12 @@ function makeIconButton(parent, opts) {
8989
const btnNode = btn.node();
9090
const tipNode = tip.node();
9191

92-
function positionTip() {
93-
if (!btnNode || !tipNode) return;
94-
95-
const rect = btnNode.getBoundingClientRect();
96-
const gap = 8;
97-
98-
tipNode.style.left = '0';
99-
tipNode.style.top = '0';
100-
101-
const tipRect = tipNode.getBoundingClientRect();
102-
103-
let left = rect.left + rect.width / 2 - tipRect.width / 2;
104-
let top = rect.bottom + gap;
105-
106-
const padding = 0.5;
107-
108-
if (left < padding) left = padding;
109-
if (left + tipRect.width > window.innerWidth - padding) {
110-
left = window.innerWidth - tipRect.width - padding;
111-
}
112-
113-
if (top + tipRect.height > window.innerHeight - padding) {
114-
top = rect.top - tipRect.height - gap;
115-
}
116-
117-
if (top < padding) top = padding;
118-
119-
tipNode.style.left = `${left/16}rem`;
120-
tipNode.style.top = `${top/16}rem`;
121-
}
122-
12392
function show() {
12493
if (!tipNode) return;
12594
if (!tipNode.matches(':popover-open')) {
12695
tipNode.showPopover();
12796
}
128-
positionTip();
97+
positionTip(btnNode, tipNode);
12998
}
13099

131100
function hide() {
@@ -142,19 +111,50 @@ function makeIconButton(parent, opts) {
142111

143112
d3.select(window).on(`resize.${id}`, () => {
144113
if (tipNode?.matches(':popover-open')) {
145-
positionTip();
114+
positionTip(btnNode, tipNode);
146115
}
147116
});
148117

149118
d3.select(window).on(`scroll.${id}`, () => {
150119
if (tipNode?.matches(':popover-open')) {
151-
positionTip();
120+
positionTip(btnNode, tipNode);
152121
}
153122
});
154123

155124
return { btn, tip };
156125
}
157126

127+
function positionTip(btnNode: any, tipNode: any) {
128+
if (!btnNode || !tipNode) return;
129+
130+
const rect = btnNode.getBoundingClientRect();
131+
const gap = 8;
132+
133+
tipNode.style.left = '0';
134+
tipNode.style.top = '0';
135+
136+
const tipRect = tipNode.getBoundingClientRect();
137+
138+
let left = rect.left + rect.width / 2 - tipRect.width / 2;
139+
let top = rect.bottom + gap;
140+
141+
const padding = 0.5;
142+
143+
if (left < padding) left = padding;
144+
if (left + tipRect.width > window.innerWidth - padding) {
145+
left = window.innerWidth - tipRect.width - padding;
146+
}
147+
148+
if (top + tipRect.height > window.innerHeight - padding) {
149+
top = rect.top - tipRect.height - gap;
150+
}
151+
152+
if (top < padding) top = padding;
153+
154+
tipNode.style.left = `${left/16}rem`;
155+
tipNode.style.top = `${top/16}rem`;
156+
}
157+
158158
function showModalWithData(dataset: any[]): void {
159159

160160
const overlay = d3.select('body')

0 commit comments

Comments
 (0)