Skip to content

Commit

Permalink
feat(gauge): 仪表盘增加 tooltip 配置
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed Mar 16, 2022
1 parent e3fbced commit 3ef6de3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
32 changes: 29 additions & 3 deletions src/plots/gauge/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Geometry } from '@antv/g2';
import { isString } from '@antv/util';
import { get, isString } from '@antv/util';
import { interaction, animation, theme, scale, annotation } from '../../adaptor/common';
import { interval } from '../../adaptor/geometries';
import { AXIS_META_CONFIG_KEYS } from '../../constant';
import { Params } from '../../core/adaptor';
import { deepAssign, flow, pick, renderGaugeStatistic } from '../../utils';
import { deepAssign, findViewById, flow, pick, renderGaugeStatistic } from '../../utils';
import { tooltip } from '../scatter/adaptor';
import { RANGE_TYPE, RANGE_VALUE, PERCENT, DEFAULT_COLOR, INDICATEOR_VIEW_ID, RANGE_VIEW_ID } from './constants';
import { GaugeOptions } from './types';
import { getIndicatorData, getRangeData } from './utils';
Expand Down Expand Up @@ -149,6 +150,31 @@ function statistic(params: Params<GaugeOptions>, updated?: boolean): Params<Gaug
return params;
}

/**
* tooltip 配置
*/
function tooltip(params: Params<GaugeOptions>): Params<GaugeOptions> {
const { chart, options } = params;
const { tooltip } = options;

if (tooltip) {
chart.tooltip(
deepAssign(
{
showTitle: false,
customContent: (x: string, data: any[]) => `${get(data, [0, 'data', PERCENT], 0)}`, // 默认显示原始数据
},
tooltip
)
);
} else {
// 默认,不展示 tooltip
chart.tooltip(false);
}

return params;
}

/**
* other 配置
* @param params
Expand All @@ -157,7 +183,6 @@ function other(params: Params<GaugeOptions>): Params<GaugeOptions> {
const { chart } = params;

chart.legend(false);
chart.tooltip(false);

return params;
}
Expand All @@ -180,6 +205,7 @@ export function adaptor(params: Params<GaugeOptions>) {
animation,
geometry,
meta,
tooltip,
statistic,
interaction,
annotation(),
Expand Down
2 changes: 1 addition & 1 deletion src/plots/gauge/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type GaugeRangeData = {
* @title 仪表盘配置类型定义
*/
export interface GaugeOptions
extends Omit<Options, 'data' | 'tooltip' | 'legend' | 'xAxis' | 'yAxis' | 'xField' | 'yField' | 'color'> {
extends Omit<Options, 'data' | 'legend' | 'xAxis' | 'yAxis' | 'xField' | 'yField' | 'color'> {
/**
* @title 指标的比例
* @description 范围0 ~ 1
Expand Down

0 comments on commit 3ef6de3

Please sign in to comment.