diff --git a/src/plots/heatmap/adaptor.ts b/src/plots/heatmap/adaptor.ts index 100d30dffa..59952795f2 100644 --- a/src/plots/heatmap/adaptor.ts +++ b/src/plots/heatmap/adaptor.ts @@ -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'; @@ -116,6 +106,34 @@ function axis(params: Params): Params { return params; } +/** + * legend 配置 + * @param params + */ +function legend(params: Params): Params { + 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 后续确认下,数据标签的逻辑为啥和通用的不一致 * 数据标签 diff --git a/src/plots/heatmap/types.ts b/src/plots/heatmap/types.ts index f4c399c616..24d680e5da 100644 --- a/src/plots/heatmap/types.ts +++ b/src/plots/heatmap/types.ts @@ -10,8 +10,6 @@ export interface HeatmapOptions extends Options { readonly yField: string; /** 颜色字段,可选 */ readonly colorField?: string; - /** 点大小映射对应的数据字段名,可选 */ - readonly sizeField?: string; /** 热力格子中的形状,可选 */ readonly shape?: string; /** 热力格子中图形的尺寸比例,可选,只有当 shape 和 sizeField 至少指定一项后才生效 */ @@ -21,6 +19,12 @@ export interface HeatmapOptions extends Options { /** 极坐标属性 */ readonly coordinate?: Types.CoordinateOption; + // 图例相关 + /** 点大小映射对应的数据字段名,可选 */ + readonly sizeField?: string; + /** size 对应的图例 */ + readonly sizeLegend?: Options['legend']; + // 样式相关 /** 热力图形样式 */ readonly heatmapStyle?: StyleAttr;