From da10ce527b418fc70182c66f91c2fa02b916665b Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Fri, 28 Jun 2024 14:09:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8-=E7=AC=A6=E5=8F=B7?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE):=20=E4=BF=AE=E5=A4=8D=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/panel/charts/map/symbolic-map.ts | 94 +++++++++++++------ 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/map/symbolic-map.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/map/symbolic-map.ts index 7e697da7a5..0a2cc9e517 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/map/symbolic-map.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/map/symbolic-map.ts @@ -60,7 +60,6 @@ export class SymbolicMap extends L7ChartView { async drawChart(drawOption: L7DrawConfig) { const { chart, container, action } = drawOption const xAxis = deepCopy(chart.xAxis) - const xAxisExt = deepCopy(chart.xAxisExt) let basicStyle let miscStyle if (chart.customAttr) { @@ -86,7 +85,7 @@ export class SymbolicMap extends L7ChartView { scene.once('loaded', () => { mapRendered(container) }) - if (xAxis?.length < 2 || xAxisExt?.length < 1) { + if (xAxis?.length < 2) { return new L7Wrapper(scene, undefined) } const configList: L7Config[] = [] @@ -100,16 +99,37 @@ export class SymbolicMap extends L7ChartView { this.configZoomButton(chart, scene) symbolicLayer.on('click', ev => { const data = ev.feature + const dimensionList = [] + const quotaList = [] + chart.data.fields.forEach((item, index) => { + Object.keys(data).forEach(key => { + if (key.startsWith('f_') && item.dataeaseName === key) { + if (index === 0) { + dimensionList.push({ + id: item.id, + dataeaseName: item.dataeaseName, + value: data[key] + }) + } else { + quotaList.push({ + id: item.id, + dataeaseName: item.dataeaseName, + value: data[key] + }) + } + } + }) + }) action({ x: ev.x, y: ev.y, data: { data: { ...data, - dimensionList: chart.data.data.filter(item => item.field === ev.feature.field)?.[0] - ?.dimensionList, - quotaList: chart.data.data.filter(item => item.field === ev.feature.field)?.[0] - ?.quotaList + value: quotaList[0].value, + name: dimensionList[0].id, + dimensionList: dimensionList, + quotaList: quotaList } } }) @@ -127,26 +147,30 @@ export class SymbolicMap extends L7ChartView { const extBubble = deepCopy(chart.extBubble) const { mapSymbolOpacity, mapSymbolSize, mapSymbol, mapSymbolStrokeWidth, colors, alpha } = deepCopy(basicStyle) - const c = [] - colors.forEach(ele => { - c.push(hexColorToRGBA(ele, alpha)) - }) + const colorsWithAlpha = colors.map(color => hexColorToRGBA(color, alpha)) + let colorIndex = 0 + // 存储已分配的颜色 + const colorAssignments = new Map() const sizeKey = extBubble.length > 0 ? extBubble[0].dataeaseName : '' const data = chart.data?.tableRow - ? chart.data?.tableRow.map((item, index) => ({ - ...item, - color: c[index % c.length], - size: item[sizeKey] ? item[sizeKey] : mapSymbolSize, - field: - item[xAxis[0].dataeaseName] + - '000\n' + - item[xAxis[1].dataeaseName] + - '000\n' + - item[xAxisExt[0].dataeaseName], - name: item[xAxisExt[0].dataeaseName] - })) + ? chart.data.tableRow.map(item => { + // 颜色标识 + const identifier = item[xAxisExt[0]?.dataeaseName] + // 检查该标识是否已有颜色分配,如果没有则分配 + let color = colorAssignments.get(identifier) + if (!color) { + color = colorsWithAlpha[colorIndex++ % colorsWithAlpha.length] + // 记录分配的颜色 + colorAssignments.set(identifier, color) + } + return { + ...item, + color, + size: item[sizeKey] ?? mapSymbolSize, + name: identifier + } + }) : [] - const color = xAxisExt && xAxisExt.length > 0 ? 'color' : c[0] const pointLayer = new PointLayer() .source(data, { parser: { @@ -156,17 +180,24 @@ export class SymbolicMap extends L7ChartView { } }) .shape(mapSymbol) - .color(color) - .style({ + .active(true) + if (xAxisExt[0]?.dataeaseName) { + pointLayer.color(xAxisExt[0]?.dataeaseName, colorsWithAlpha) + pointLayer.style({ stroke: { field: 'color' }, strokeWidth: mapSymbolStrokeWidth, - opacity: { - field: (mapSymbolOpacity / 100) * 10 - } + opacity: mapSymbolOpacity / 10 }) - .active(true) + } else { + pointLayer.color(colorsWithAlpha[0]) + pointLayer.style({ + stroke: colorsWithAlpha[0], + strokeWidth: mapSymbolStrokeWidth, + opacity: mapSymbolOpacity / 10 + }) + } if (sizeKey) { pointLayer.size('size', [4, 30]) } else { @@ -329,11 +360,12 @@ export class SymbolicMap extends L7ChartView { setupDefaultOptions(chart: ChartObj): ChartObj { chart.customAttr.label = { ...chart.customAttr.label, - show: false + show: true } chart.customAttr.basicStyle = { ...chart.customAttr.basicStyle, - mapSymbolOpacity: 5 + mapSymbolOpacity: 5, + mapStyle: 'normal' } return chart }