From c914a27081032f78ae3058da60db862e17d3ad0a Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Wed, 20 Nov 2024 18:27:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E6=B2=A1=E6=9C=89=E6=A0=B9=E6=8D=AE=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=8C=BA=E9=97=B4=E5=8F=98=E8=89=B2=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20#13327?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/js/panel/charts/map/map.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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 b67ec32794..3f27def1da 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 @@ -334,7 +334,8 @@ export class Map extends L7PlotChartView { } } } - if (!misc.mapAutoLegend && misc.mapLegendRangeType === 'custom') { + // 不是自动图例、自定义图例区间、不是下钻时 + if (!misc.mapAutoLegend && misc.mapLegendRangeType === 'custom' && !chart.drill) { // 获取图例区间数据 const items = [] // 区间数组 @@ -342,10 +343,10 @@ export class Map extends L7PlotChartView { .slice(0, -1) .map((item, index) => [item, misc.mapLegendCustomRange[index + 1]]) ranges.forEach((range, index) => { - const tmpRange = [range[0]?.toFixed(0), range[1]?.toFixed(0)] + const tmpRange = [range[0], range[1]] const colorIndex = index % colors.length // 当区间第一个值小于最小值时,颜色取地图底色 - const isLessThanMin = range[0] < ranges[0][0] + const isLessThanMin = range[0] < ranges[0][0] && range[1] < ranges[0][0] let rangeColor = colors[colorIndex] if (isLessThanMin) { rangeColor = hexColorToRGBA(basicStyle.areaBaseColor, basicStyle.alpha) @@ -361,6 +362,11 @@ export class Map extends L7PlotChartView { } return '' } + options.color['value'] = ({ value }) => { + const item = items.find(item => value >= item.value[0] && value <= item.value[1]) + return item ? item.color : hexColorToRGBA(basicStyle.areaBaseColor, basicStyle.alpha) + } + options.color.scale.domain = [ranges[0][0], ranges[ranges.length - 1][1]] } else { customLegend['customContent'] = (_: string, items: CategoryLegendListItem[]) => { const showItems = items?.length > 30 ? items.slice(0, 30) : items @@ -370,6 +376,12 @@ export class Map extends L7PlotChartView { return '' } } + // 下钻时按照数据值计算图例 + if (chart.drill) { + getMaxAndMinValueByData(options.source.data, 'value', 0, 0, (max, min) => { + options.color.scale.domain = [min, max] + }) + } defaultsDeep(options, { legend: customLegend }) return options }