From 27cc216e23fdb61ce356f00cd711ff48ac145a6c Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Tue, 3 Dec 2024 18:33:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=9D=A2=E7=A7=AF=E5=9B=BE=E6=9C=80=E5=80=BC=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/chart/components/js/extremumUitl.ts | 7 +++++-- .../src/views/chart/components/js/util.ts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/extremumUitl.ts b/core/core-frontend/src/views/chart/components/js/extremumUitl.ts index dfc029bf92..f3efd025f5 100644 --- a/core/core-frontend/src/views/chart/components/js/extremumUitl.ts +++ b/core/core-frontend/src/views/chart/components/js/extremumUitl.ts @@ -1,5 +1,5 @@ import { valueFormatter } from '@/views/chart/components/js/formatter' -import { parseJson } from '@/views/chart/components/js/util' +import { hexToRgba, parseJson } from '@/views/chart/components/js/util' import { isEmpty } from 'lodash-es' export const clearExtremum = chart => { @@ -326,7 +326,10 @@ export const createExtremumPoint = (chart, ev) => { pointElement.style.fontSize = fontSize + 'px' pointElement.style.lineHeight = fontSize + 'px' // 渐变颜色时需要获取最后一个rgba的值作为背景 - const { r, b, g, a } = getRgbaColorLastRgba(point.color) + const color = point.color.startsWith('#') + ? hexToRgba(point.color, basicStyle.alpha / 100) + : getRgbaColorLastRgba(point.color) + const { r, b, g, a } = color pointElement.style.backgroundColor = 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')' pointElement.style.color = isColorLight(point.color) ? '#000' : '#fff' pointElement.children[0]['style'].borderTopColor = diff --git a/core/core-frontend/src/views/chart/components/js/util.ts b/core/core-frontend/src/views/chart/components/js/util.ts index d5ac73c01b..27da58d6dd 100644 --- a/core/core-frontend/src/views/chart/components/js/util.ts +++ b/core/core-frontend/src/views/chart/components/js/util.ts @@ -1142,3 +1142,19 @@ export const measureText = (chart, text, font, type) => { } return 0 } + +/** + * 获取十六进制颜色值 + * @param hex + * @param alpha + */ +export const hexToRgba = (hex, alpha = 1) => { + // 去掉 # 号 + hex = hex.replace('#', '') + // 转换为 RGB 分量 + const r = parseInt(hex.slice(0, 2), 16) + const g = parseInt(hex.slice(2, 4), 16) + const b = parseInt(hex.slice(4, 6), 16) + // 返回 RGBA 格式 + return `rgba(${r}, ${g}, ${b}, ${alpha})` +}