Commit 94602774 authored by tom's avatar tom

fix charts tooltip

parent 32857407
...@@ -86,11 +86,19 @@ const ChartTooltip = ({ xScale, yScale, width, height, data, anchorEl, ...props ...@@ -86,11 +86,19 @@ const ChartTooltip = ({ xScale, yScale, width, height, data, anchorEl, ...props
.selectAll('.ChartTooltip__point') .selectAll('.ChartTooltip__point')
.attr('transform', (cur, i) => { .attr('transform', (cur, i) => {
const index = bisectDate(data[i].items, xDate, 1); const index = bisectDate(data[i].items, xDate, 1);
const d0 = data[i].items[index - 1]; const d0 = data[i].items[index - 1] as TimeChartItem | undefined;
const d1 = data[i].items[index]; const d1 = data[i].items[index] as TimeChartItem | undefined;
const d = xDate.getTime() - d0?.date.getTime() > d1?.date.getTime() - xDate.getTime() ? d1 : d0; const d = (() => {
if (!d0) {
if (d.date === undefined && d.value === undefined) { return d1;
}
if (!d1) {
return d0;
}
return xDate.getTime() - d0.date.getTime() > d1.date.getTime() - xDate.getTime() ? d1 : d0;
})();
if (d?.date === undefined && d?.value === undefined) {
// move point out of container // move point out of container
return 'translate(-100,-100)'; return 'translate(-100,-100)';
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment