diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/map/map.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/map/map.ts index 9b58b75123..b02978581f 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/map/map.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/map/map.ts @@ -218,7 +218,6 @@ export class Map extends L7PlotChartView { content.push(name) } if (label.showQuota) { - valueFormatter areaMap[name] && content.push(valueFormatter(areaMap[name], label.quotaLabelFormatter)) } item.properties['_DE_LABEL_'] = content.join('\n\n') @@ -229,7 +228,7 @@ export class Map extends L7PlotChartView { colors = colors.slice(0, validArea) } if (colors.length) { - options.color.value = colors + options.color['value'] = colors } return options } @@ -244,7 +243,8 @@ export class Map extends L7PlotChartView { this.configLabel, this.configStyle, this.configTooltip, - this.configBasicStyle + this.configBasicStyle, + this.configLegend )(chart, options, extra) } } diff --git a/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts b/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts index 09f8da1e6f..dd1216f852 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts @@ -12,6 +12,15 @@ import { Tooltip } from '@antv/g2plot/esm' import { add } from 'mathjs' import isEmpty from 'lodash-es/isEmpty' import _ from 'lodash' +import type { LegendOptions } from '@antv/l7plot/dist/esm/types/legend' +import { CategoryLegendListItem } from '@antv/l7plot-component/dist/lib/types/legend' +import createDom from '@antv/dom-util/esm/create-dom' +import { + CONTAINER_TPL, + ITEM_TPL, + LIST_CLASS +} from '@antv/l7plot-component/dist/esm/legend/category/constants' +import substitute from '@antv/util/esm/substitute' export function getPadding(chart: Chart): number[] { if (chart.drill) { @@ -772,3 +781,36 @@ export function getTooltipSeriesTotalMap(data: any[]): Record { }) return result } + +export function configL7Legend(): LegendOptions { + return { + customContent: (_: string, items: CategoryLegendListItem[]) => { + const showItems = items?.length > 30 ? items.slice(0, 30) : items + if (showItems?.length) { + const containerDom = createDom(CONTAINER_TPL) as HTMLElement + const listDom = containerDom.getElementsByClassName(LIST_CLASS)[0] as HTMLElement + showItems.forEach(item => { + let value = '-' + if (item.value !== '') { + if (Array.isArray(item.value)) { + item.value.forEach((v, i) => { + item.value[i] = Number.isNaN(v) || v === 'NaN' ? 'NaN' : parseFloat(v).toFixed(0) + }) + value = item.value.join('-') + } else { + const tmp = item.value as string + value = Number.isNaN(tmp) || tmp === 'NaN' ? 'NaN' : parseFloat(tmp).toFixed(0) + } + } + const substituteObj = { ...item, value } + + const domStr = substitute(ITEM_TPL, substituteObj) + const itemDom = createDom(domStr) + listDom.appendChild(itemDom) + }) + return listDom + } + return '' + } + } +} diff --git a/core/core-frontend/src/views/chart/components/js/panel/types/impl/l7plot.ts b/core/core-frontend/src/views/chart/components/js/panel/types/impl/l7plot.ts index 17d99f20d7..c22d32c9ca 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/types/impl/l7plot.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/types/impl/l7plot.ts @@ -4,6 +4,7 @@ import { PlotOptions } from '@antv/l7plot/dist/esm/types/plot' import { Plot as L7Plot } from '@antv/l7plot/dist/esm/core/plot' import { configL7Label, + configL7Legend, configL7Style, configL7Tooltip } from '@/views/chart/components/js/panel/common/common_antv' @@ -13,6 +14,7 @@ import { ChartLibraryType } from '@/views/chart/components/js/panel/types' import { defaultsDeep } from 'lodash-es' +import { ChoroplethOptions } from '@antv/l7plot/dist/esm/plots/choropleth' export interface L7PlotDrawOptions

extends AntVDrawOptions

{ areaId?: string @@ -43,7 +45,11 @@ export abstract class L7PlotChartView< defaultsDeep(options.tooltip, tooltip) return options } - + protected configLegend(_: Chart, options: ChoroplethOptions) { + const legend = configL7Legend() + defaultsDeep(options.legend, legend) + return options + } protected constructor(name: string, defaultData?: any[]) { super(ChartLibraryType.L7_PLOT, name) this.defaultData = defaultData