Skip to content

Commit 50e319d

Browse files
authored
fix(toolitp): 修复 limitInPlot属性无法屏蔽一些后出现的状态 (#3792)
Co-authored-by: ai-qing-hai <[email protected]>
1 parent 7ba92fe commit 50e319d

File tree

2 files changed

+90
-4
lines changed

2 files changed

+90
-4
lines changed

src/chart/controller/tooltip.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { deepMix, find, get, isEqual, isFunction, mix, isString, isBoolean, flatten, isArray } from '@antv/util';
22
import { Crosshair, HtmlTooltip, IGroup } from '../../dependents';
33
import { Point, TooltipItem, TooltipOption } from '../../interface';
4-
import { getAngleByPoint, getDistanceToCenter, isPointInCoordinate } from '../../util/coordinate';
4+
import { getAngleByPoint, getDistanceToCenter, isPointInCoordinate, getCoordinateClipCfg } from '../../util/coordinate';
55
import { polarToCartesian } from '../../util/graphics';
66
import { findItemsFromView } from '../../util/tooltip';
77
import { BBox } from '../../util/bbox';
@@ -47,14 +47,14 @@ export default class Tooltip extends Controller<TooltipOption> {
4747
return 'tooltip';
4848
}
4949

50-
public init() {}
50+
public init() { }
5151

5252
private isVisible() {
5353
const option = this.view.getOptions().tooltip;
5454
return option !== false;
5555
}
5656

57-
public render() {}
57+
public render() { }
5858

5959
/**
6060
* Shows tooltip
@@ -342,7 +342,7 @@ export default class Tooltip extends Controller<TooltipOption> {
342342
return [];
343343
}
344344

345-
public layout() {}
345+
public layout() { }
346346

347347
public update() {
348348
if (this.point) {
@@ -439,8 +439,23 @@ export default class Tooltip extends Controller<TooltipOption> {
439439

440440
private renderTooltipMarkers(items, marker) {
441441
const tooltipMarkersGroup = this.getTooltipMarkersGroup();
442+
const rootView = this.view.getRootView();
443+
const { limitInPlot } = rootView;
442444
for (const item of items) {
443445
const { x, y } = item;
446+
447+
// 有裁剪就剪切
448+
if (limitInPlot || tooltipMarkersGroup?.getClip()) {
449+
const { type, attrs } = getCoordinateClipCfg(rootView.getCoordinate());
450+
tooltipMarkersGroup?.setClip({
451+
type,
452+
attrs,
453+
});
454+
} else {
455+
// 清除已有的 clip
456+
tooltipMarkersGroup?.setClip(undefined);
457+
}
458+
444459
const attrs = {
445460
fill: item.color,
446461
symbol: 'circle',

tests/bugs/3079-spec.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Chart } from '../../src/';
2+
import { createDiv } from '../util/dom';
3+
4+
describe('3079', () => {
5+
it('3079', () => {
6+
const data = [
7+
{ month: 'Jan', city: 'Tokyo', temperature: 7 },
8+
{ month: 'Jan', city: 'London', temperature: 3.9 },
9+
{ month: 'Feb', city: 'Tokyo', temperature: 6.9 },
10+
{ month: 'Feb', city: 'London', temperature: 4.2 },
11+
{ month: 'Mar', city: 'Tokyo', temperature: 9.5 },
12+
{ month: 'Mar', city: 'London', temperature: 5.7 },
13+
{ month: 'Apr', city: 'Tokyo', temperature: 14.5 },
14+
{ month: 'Apr', city: 'London', temperature: 8.5 },
15+
{ month: 'May', city: 'Tokyo', temperature: 18.4 },
16+
{ month: 'May', city: 'London', temperature: 11.9 },
17+
{ month: 'Jun', city: 'Tokyo', temperature: 21.5 },
18+
{ month: 'Jun', city: 'London', temperature: 15.2 },
19+
{ month: 'Jul', city: 'Tokyo', temperature: 25.2 },
20+
{ month: 'Jul', city: 'London', temperature: 17 },
21+
{ month: 'Aug', city: 'Tokyo', temperature: 26.5 },
22+
{ month: 'Aug', city: 'London', temperature: 16.6 },
23+
{ month: 'Sep', city: 'Tokyo', temperature: 23.3 },
24+
{ month: 'Sep', city: 'London', temperature: 14.2 },
25+
{ month: 'Oct', city: 'Tokyo', temperature: 18.3 },
26+
{ month: 'Oct', city: 'London', temperature: 10.3 },
27+
{ month: 'Nov', city: 'Tokyo', temperature: 13.9 },
28+
{ month: 'Nov', city: 'London', temperature: 6.6 },
29+
{ month: 'Dec', city: 'Tokyo', temperature: 9.6 },
30+
{ month: 'Dec', city: 'London', temperature: 4.8 },
31+
];
32+
33+
const chart = new Chart({
34+
container: createDiv(),
35+
limitInPlot: true,
36+
height: 500,
37+
width: 500,
38+
});
39+
40+
chart.data(data);
41+
42+
chart.scale({
43+
month: {
44+
range: [0, 1],
45+
},
46+
temperature: {
47+
nice: true,
48+
min: 10,
49+
},
50+
});
51+
52+
chart.tooltip({
53+
showCrosshairs: true,
54+
shared: true,
55+
});
56+
57+
chart.line().position('month*temperature').color('city').shape('smooth');
58+
chart.point().position('month*temperature').color('city').shape('circle');
59+
60+
chart.render();
61+
62+
const point = chart.getXY({ month: 'Nov', city: 'London', temperature: 6.6 });
63+
64+
chart.showTooltip(point);
65+
66+
const tooltipMarkerGroup = chart.foregroundGroup.findAllByName('tooltipMarkersGroup')[0];
67+
68+
expect(chart.limitInPlot).toBe(true);
69+
expect(!!tooltipMarkerGroup.cfg.clipShape).toBe(true);
70+
});
71+
});

0 commit comments

Comments
 (0)