From 30ba6a30b2bf93e719ec31c843feaa407566e30b Mon Sep 17 00:00:00 2001 From: vasco Date: Mon, 23 Oct 2023 01:59:52 +0100 Subject: [PATCH] Small interaction improvements --- src/hilbert.js | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/hilbert.js b/src/hilbert.js index 4e63bc0..b157ee0 100644 --- a/src/hilbert.js +++ b/src/hilbert.js @@ -300,21 +300,18 @@ export default Kapsule({ state.hoverD = hoverD; state.rangeTooltip.style('display', 'none'); - if (hoverD) { - if (state.showRangeTooltip) { - state.rangeTooltip.style('display', 'inline'); - - const d = hoverD; - if (state.rangeTooltipContent) { - state.rangeTooltip.html(accessorFn(state.rangeTooltipContent)(d)); - } else { - // default tooltip - const rangeLabel = accessorFn(state.rangeLabel); - const rangeFormatter = d => state.valFormatter(d.start) + (d.length > 1 ? ' - ' + state.valFormatter(d.start + d.length - 1) : ''); - state.rangeTooltip.html(`${rangeLabel(d)}: ${rangeFormatter(d)}`); - } - } + if (hoverD && state.showRangeTooltip) { + const d = hoverD; + const tooltipContent = state.rangeTooltipContent + ? accessorFn(state.rangeTooltipContent)(d) + // default tooltip + : `${accessorFn(state.rangeLabel)(d)}: ${state.valFormatter(d.start) + (d.length > 1 ? ' - ' + state.valFormatter(d.start + d.length - 1) : '')}` + + state.rangeTooltip.html(tooltipContent || ''); + tooltipContent && state.rangeTooltip.style('display', 'inline'); } + + hilbertCanvas.style('cursor', hoverD && state.onRangeClick ? 'pointer' : null); state.onRangeHover && state.onRangeHover(hoverD || null); } } @@ -439,16 +436,13 @@ export default Kapsule({ state.rangeTooltip.style('display', 'none'); if (state.showRangeTooltip) { - state.rangeTooltip.style('display', 'inline'); - - if (state.rangeTooltipContent) { - state.rangeTooltip.html(accessorFn(state.rangeTooltipContent)(d)); - } else { + const tooltipContent = state.rangeTooltipContent + ? accessorFn(state.rangeTooltipContent)(d) // default tooltip - const rangeLabel = accessorFn(state.rangeLabel); - const rangeFormatter = d => state.valFormatter(d.start) + (d.length > 1 ? ' - ' + state.valFormatter(d.start + d.length - 1) : ''); - state.rangeTooltip.html(`${rangeLabel(d)}: ${rangeFormatter(d)}`); - } + : `${accessorFn(state.rangeLabel)(d)}: ${state.valFormatter(d.start) + (d.length > 1 ? ' - ' + state.valFormatter(d.start + d.length - 1) : '')}` + + state.rangeTooltip.html(tooltipContent || ''); + tooltipContent && state.rangeTooltip.style('display', 'inline'); } state.onRangeHover && state.onRangeHover(d);