-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2/radar): 自定义 radar tooltip,允许横向对比显示 tooltip (#1337)
* feat(v2/radar): 自定义 radar tooltip,允许横向对比显示 tooltip * refactor(v2/radar): 修改雷达图 cr 建议 * refactor(v2/radar): 修改 cr 建议 * feat(v2/radar): 增加 xy crosshairs 的tooltip demo
- Loading branch information
Showing
8 changed files
with
221 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
const categories = ['销售', '市场营销', '发展', '客户支持', '信息技术', '行政管理']; | ||
/** 预算支出 */ | ||
const data1 = [43000, 19000, 60000, 35000, 17000, 10000]; | ||
/** 实际支出 */ | ||
const data2 = [50000, 39000, 42000, 31000, 26000, 14000]; | ||
|
||
export const SINGLE_DATA = categories.map((d, idx) => ({ name: d, value: data1[idx] })); | ||
export const SERIES_DATA = []; | ||
categories.forEach((d, idx) => { | ||
SERIES_DATA.push({ name: d, value: data1[idx], type: '预算支出' }); | ||
SERIES_DATA.push({ name: d, value: data2[idx], type: '实际支出' }); | ||
}); | ||
export const SINGLE_DATA = [ | ||
{ name: '销售', value: 43000 }, | ||
{ name: '市场营销', value: 19000 }, | ||
{ name: '发展', value: 60000 }, | ||
{ name: '客户支持', value: 35000 }, | ||
{ name: '信息技术', value: 17000 }, | ||
{ name: '行政管理', value: 10000 }, | ||
]; | ||
export const SERIES_DATA = [ | ||
{ name: '销售', value: 43000, type: '预算支出' }, | ||
{ name: '销售', value: 50000, type: '实际支出' }, | ||
{ name: '市场营销', value: 19000, type: '预算支出' }, | ||
{ name: '市场营销', value: 39000, type: '实际支出' }, | ||
{ name: '发展', value: 60000, type: '预算支出' }, | ||
{ name: '发展', value: 42000, type: '实际支出' }, | ||
{ name: '客户支持', value: 35000, type: '预算支出' }, | ||
{ name: '客户支持', value: 31000, type: '实际支出' }, | ||
{ name: '信息技术', value: 17000, type: '预算支出' }, | ||
{ name: '信息技术', value: 26000, type: '实际支出' }, | ||
{ name: '行政管理', value: 10000, type: '预算支出' }, | ||
{ name: '行政管理', value: 14000, type: '实际支出' }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { registerAction, registerInteraction } from '@antv/g2'; | ||
import { RadarTooltipAction } from './radar-tooltip-action'; | ||
|
||
registerAction('radar-tooltip', RadarTooltipAction); | ||
registerInteraction('radar-tooltip', { | ||
start: [{ trigger: 'element:mouseenter', action: 'radar-tooltip:show' }], | ||
end: [{ trigger: 'element:mouseleave', action: 'radar-tooltip:hide' }], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { registerComponentController } from '@antv/g2'; | ||
import { getTooltipItems } from '@antv/g2/lib/util/tooltip'; | ||
import TooltipController from '@antv/g2/lib/chart/controller/tooltip'; | ||
import { Action } from '@antv/g2/lib/interaction'; | ||
import { isNil } from '@antv/util'; | ||
import { Point } from '../../../types'; | ||
|
||
export class RadarTooltipController extends TooltipController { | ||
public get name(): string { | ||
return 'radar-tooltip'; | ||
} | ||
|
||
public getTooltipItems(point: Point) { | ||
const { shared, title: cfgTitle } = this.getTooltipCfg(); | ||
const hintItems = super.getTooltipItems(point); | ||
|
||
if (hintItems.length > 0) { | ||
const geometry = this.view.geometries[0]; | ||
const dataArray = geometry.dataArray; | ||
const title = hintItems[0].name; | ||
const result = []; | ||
dataArray.forEach((mappingData) => { | ||
mappingData.forEach((d) => { | ||
const items = getTooltipItems(d, geometry); | ||
const item = items[0]; | ||
if (!shared && item && item.name === title) { | ||
const displayTitle = isNil(cfgTitle) ? title : cfgTitle; | ||
result.push({ ...item, name: item.title, title: displayTitle }); | ||
} else if (shared && item) { | ||
const displayTitle = isNil(cfgTitle) ? item.name || title : cfgTitle; | ||
result.push({ ...item, name: item.title, title: displayTitle }); | ||
} | ||
}); | ||
}); | ||
|
||
return result; | ||
} | ||
return []; | ||
} | ||
} | ||
registerComponentController('radar-tooltip', RadarTooltipController); | ||
|
||
/** | ||
* 雷达图 tooltip 激活 action | ||
*/ | ||
export class RadarTooltipAction extends Action { | ||
init() { | ||
const { view } = this.context; | ||
view.removeInteraction('tooltip'); | ||
} | ||
|
||
public show() { | ||
const { event } = this.context; | ||
const controller = this.getTooltipController(); | ||
controller.showTooltip({ x: event.x, y: event.y }); | ||
} | ||
|
||
public hide() { | ||
const controller = this.getTooltipController(); | ||
controller.hideTooltip(); | ||
} | ||
|
||
private getTooltipController() { | ||
const { view } = this.context; | ||
return view.getController('radar-tooltip') as TooltipController; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters