Skip to content

Commit 5b438e8

Browse files
committed
reverse click functionality to improve hover behavior
1 parent c7f1023 commit 5b438e8

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

src/app/components/StateRoute/History.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,11 @@ function History(props: Record<string, unknown>): JSX.Element {
193193
.append('div')
194194
.attr('class', `tooltip`)
195195
.attr('id', `tt-${d.data.index}`)
196-
.style('left', `${event.clientX}px`)
197-
.style('top', `${event.clientY}px`)
196+
.style('left', `${event.clientX - 10}px`)
197+
.style('top', `${event.clientY - 10}px`)
198198
.style('max-height', `25%`)
199199
.style('overflow', `scroll`);
200+
console.log(findDiff(d.data.index));
200201
d3.selectAll('.tooltip').html(findDiff(d.data.index));
201202
}
202203

@@ -211,7 +212,44 @@ function History(props: Record<string, unknown>): JSX.Element {
211212
}
212213
}
213214
})
214-
.attr('transform', (d) => `translate(${d.x},${d.y})`);
215+
.on('mouseenter', function (event, d) {
216+
const [x, y] = d3.pointer(event);
217+
if (d3.selectAll('.tooltip')._groups['0'].length === 0) {
218+
const div = d3
219+
.select('.display:first-child')
220+
.append('div')
221+
.attr('class', `tooltip`)
222+
.attr('id', `tt-${d.data.index}`)
223+
.style('left', `${event.clientX + 0}px`)
224+
.style('top', `${event.clientY + 0}px`)
225+
.style('max-height', `25%`)
226+
.style('overflow', `auto`)
227+
.on('mouseenter', function (event, d) {})
228+
.on('mouseleave', function (event, d) {
229+
d3.selectAll('.tooltip').remove().style('display', 'hidden');
230+
});
231+
232+
d3.selectAll('.tooltip').html(findDiff(d.data.index));
233+
}
234+
})
235+
.on('mouseleave', function (event, d) {
236+
if (event.relatedTarget.id !== `tt-${d.data.index}`) {
237+
d3.selectAll('.tooltip').transition().delay(100).remove();
238+
}
239+
})
240+
241+
.attr('transform', function (d) {
242+
return `translate(${d.x},${d.y})`;
243+
});
244+
245+
const tooltip = d3
246+
.select('.tooltip')
247+
.on('mousemove', function (event, d) {
248+
d3.select('.tooltip').style('opacity', '1');
249+
})
250+
.on('mouseleave', function (event, d) {
251+
d3.selectAll('.tooltip').remove();
252+
});
215253

216254
node
217255
.append('circle')

0 commit comments

Comments
 (0)