Skip to content

Commit

Permalink
feat(heatmpap): 热力图支持 sizeLegend
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed Oct 17, 2021
1 parent efd30ca commit 3691aac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
40 changes: 29 additions & 11 deletions src/plots/heatmap/adaptor.ts
Expand Up @@ -2,17 +2,7 @@ import { get } from '@antv/util';
import { Params } from '../../core/adaptor';
import { deepAssign, findGeometry } from '../../utils';
import { flow, transformLabel } from '../../utils';
import {
tooltip,
interaction,
animation,
theme,
scale,
annotation,
state,
legend,
pattern,
} from '../../adaptor/common';
import { tooltip, interaction, animation, theme, scale, annotation, state, pattern } from '../../adaptor/common';
import { geometry as geometryAdaptor } from '../../adaptor/geometries/base';
import { getTooltipMapping } from '../../utils/tooltip';
import { HeatmapOptions } from './types';
Expand Down Expand Up @@ -116,6 +106,34 @@ function axis(params: Params<HeatmapOptions>): Params<HeatmapOptions> {
return params;
}

/**
* legend 配置
* @param params
*/
function legend(params: Params<HeatmapOptions>): Params<HeatmapOptions> {
const { chart, options } = params;
const { legend, colorField, sizeField, sizeLegend } = options;

/** legend 不为 false, 则展示图例, 优先展示 color 分类图例 */
const showLegend = legend !== false;

if (colorField) {
chart.legend(colorField, showLegend ? legend : false);
}

// 旧版本: 有 sizeField 就有 sizeLegend. 这里默认继承下 legend 配置
if (sizeField) {
chart.legend(sizeField, sizeLegend === undefined ? legend : sizeLegend);
}

/** 默认没有 sizeField,则隐藏连续图例 */
if (!showLegend && !sizeLegend) {
chart.legend(false);
}

return params;
}

/**
* fixme 后续确认下,数据标签的逻辑为啥和通用的不一致
* 数据标签
Expand Down
8 changes: 6 additions & 2 deletions src/plots/heatmap/types.ts
Expand Up @@ -10,8 +10,6 @@ export interface HeatmapOptions extends Options {
readonly yField: string;
/** 颜色字段,可选 */
readonly colorField?: string;
/** 点大小映射对应的数据字段名,可选 */
readonly sizeField?: string;
/** 热力格子中的形状,可选 */
readonly shape?: string;
/** 热力格子中图形的尺寸比例,可选,只有当 shape 和 sizeField 至少指定一项后才生效 */
Expand All @@ -21,6 +19,12 @@ export interface HeatmapOptions extends Options {
/** 极坐标属性 */
readonly coordinate?: Types.CoordinateOption;

// 图例相关
/** 点大小映射对应的数据字段名,可选 */
readonly sizeField?: string;
/** size 对应的图例 */
readonly sizeLegend?: Options['legend'];

// 样式相关
/** 热力图形样式 */
readonly heatmapStyle?: StyleAttr;
Expand Down

0 comments on commit 3691aac

Please sign in to comment.