Skip to content

Commit

Permalink
fix(tooltip): support NaN data in transpose
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Mar 27, 2023
1 parent 46aa416 commit 28f8cad
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div
xmlns="http://www.w3.org/1999/xhtml"
class="tooltip"
style="pointer-events: none; position: absolute; visibility: visible; z-index: 8; transition: visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1), left 0.4s cubic-bezier(0.23, 1, 0.32, 1), top 0.4s cubic-bezier(0.23, 1, 0.32, 1); background-color: rgba(255, 255, 255, 0.96); box-shadow: 0 6px 12px 0 rgba(0, 0, 0, 0.12); border-radius: 4px; color: rgba(0, 0, 0, 0.65); font-size: 12px; line-height: 20px; padding: 12px; min-width: 120px; max-width: 360px; font-family: Roboto-Regular; left: 110px; top: 75px;"
>
<div
class="tooltip-title"
style="color: rgba(0, 0, 0, 0.45); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
Thu Sep 27 2007 08:00:00 GMT+0800 (中国标准时间)
</div>
<ul
class="tooltip-list"
style="margin: 0px; list-style-type: none; padding: 0px;"
>
<li
class="tooltip-list-item"
data-index="0"
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;"
>
<span
class="tooltip-list-item-name"
style="display: flex; align-items: center; max-width: 216px;"
>
<span
class="tooltip-list-item-marker"
style="background: black; width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;"
/>
<span
class="tooltip-list-item-name-label"
title="close"
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
close
</span>
</span>
<span
class="tooltip-list-item-value"
title="153.47"
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
153.47
</span>
</li>
</ul>
</div>;
42 changes: 42 additions & 0 deletions __tests__/plots/tooltip/aapl-area-missing-data-transpose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { G2Spec } from '../../../src';
import { seriesTooltipSteps } from './utils';

export function aaplAreaMissingDataTranspose(): G2Spec {
return {
width: 800,
type: 'area',
coordinate: { transform: [{ type: 'transpose' }] },
data: {
type: 'fetch',
value: 'data/aapl.csv',
transform: [
{
type: 'map',
callback: (d) => ({
...d,
close: d.date.getUTCMonth() <= 3 ? NaN : d.close,
}),
},
],
},
encode: {
x: 'date',
y: 'close',
},
scale: {
x: { type: 'time' },
},
style: {
connect: true,
connectFill: 'grey',
connectFillOpacity: 0.15,
},
tooltip: {
// title: '',
},
};
}

aaplAreaMissingDataTranspose.maxError = 125;

aaplAreaMissingDataTranspose.steps = seriesTooltipSteps([100, 88]);
1 change: 1 addition & 0 deletions __tests__/plots/tooltip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ export { scoreByItemAreaRadar } from './score-by-item-area-radar';
export { profitIntervalLegendFilterOrdinal } from './profit-interval-legend-filter-ordinal';
export { aaplLineSliderFilter } from './appl-line-slider-filter';
export { aaplLineAreaBasicSample } from './aapl-line-area-basic-sample';
export { aaplAreaMissingDataTranspose } from './aapl-area-missing-data-transpose';
2 changes: 1 addition & 1 deletion src/interaction/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export function seriesTooltip(
selectedSeriesElements.push(element);
const d = seriesData(element, index);
const { x, y } = d;
const p = coordinate.map([x + offsetX, y]);
const p = coordinate.map([(x || 0) + offsetX, y || 0]);
selectedSeriesData.push([d, p] as const);
}
}
Expand Down

0 comments on commit 28f8cad

Please sign in to comment.