mirror of
https://github.com/dataease/dataease.git
synced 2026-06-16 20:42:07 +08:00
fix(图表): 修复部分图表自定义颜色不生效以及配置渐变颜色后,提示框中的指标颜色不显示的问题
This commit is contained in:
@@ -204,7 +204,7 @@ class G2TooltipCarousel {
|
||||
this.restart()
|
||||
lastRect = newRect
|
||||
}
|
||||
}, 200)
|
||||
}, 16)
|
||||
}
|
||||
|
||||
private restart = this.debounce(() => {
|
||||
|
||||
@@ -101,6 +101,13 @@ export class Bar extends G2ChartView<ViewSpec, G2Column> {
|
||||
return
|
||||
}
|
||||
const data = cloneDeep(drawOptions.chart.data?.data)
|
||||
if (this.name === 'bar-group') {
|
||||
if (!chart.xAxisExt[0]) {
|
||||
data.forEach(item => {
|
||||
item[this.intervalOptions.encode.color] = ' '
|
||||
})
|
||||
}
|
||||
}
|
||||
const initOptions: ViewSpec = {
|
||||
type: 'view',
|
||||
data: data,
|
||||
@@ -298,7 +305,7 @@ export class Bar extends G2ChartView<ViewSpec, G2Column> {
|
||||
scale.x.paddingInner = -0.21
|
||||
}
|
||||
if (this.name === 'bar-group') {
|
||||
scale.x.paddingInner = -0.1
|
||||
scale.x.paddingInner = -0.2
|
||||
}
|
||||
const basicStyle = parseJson(chart.customAttr).basicStyle
|
||||
const { radiusColumnBar, columnBarRightAngleRadius } = basicStyle
|
||||
|
||||
@@ -3,7 +3,12 @@ import {
|
||||
BAR_EDITOR_PROPERTY,
|
||||
BAR_EDITOR_PROPERTY_INNER
|
||||
} from '@/views/chart/components/js/panel/charts/g2/bar/common'
|
||||
import { flow, parseJson, setUpGroupSeriesColor } from '@/views/chart/components/js/util'
|
||||
import {
|
||||
flow,
|
||||
hexColorToRGBA,
|
||||
parseJson,
|
||||
setUpGroupSeriesColor
|
||||
} from '@/views/chart/components/js/util'
|
||||
import { StackBar } from '@/views/chart/components/js/panel/charts/g2/bar/stack-bar'
|
||||
import { Chart as G2Column } from '@antv/g2'
|
||||
import { ViewSpec } from '@/views/chart/components/js/panel/charts/g2/bar/barUtil'
|
||||
@@ -11,6 +16,8 @@ import { useI18n } from '@/hooks/web/useI18n'
|
||||
import { G2DrawOptions } from '@/views/chart/components/js/panel/types/impl/g2'
|
||||
import { valueFormatter } from '@/views/chart/components/js/formatter'
|
||||
import { addExtremumText } from '@/views/chart/components/js/extremumUitl'
|
||||
import { setGradientColor } from '@/views/chart/components/js/panel/common/common_antv'
|
||||
import { defaultsDeep } from 'lodash-es'
|
||||
|
||||
const { t } = useI18n()
|
||||
/**
|
||||
@@ -99,6 +106,53 @@ export class GroupBar extends StackBar {
|
||||
return setUpGroupSeriesColor(chart, data)
|
||||
}
|
||||
|
||||
protected configColor(chart: Chart, options: ViewSpec): ViewSpec {
|
||||
const { basicStyle } = parseJson(chart.customAttr)
|
||||
const { seriesColor } = basicStyle
|
||||
if (!seriesColor?.length) {
|
||||
return options
|
||||
}
|
||||
const { xAxis, xAxisExt, yAxis } = chart
|
||||
if (!xAxis?.length || !yAxis?.length) {
|
||||
return options
|
||||
}
|
||||
const relations = []
|
||||
if (xAxisExt?.length) {
|
||||
seriesColor.forEach(item => {
|
||||
let color = hexColorToRGBA(item.color, basicStyle.alpha)
|
||||
if (basicStyle.gradient) {
|
||||
color = setGradientColor(color, true, 270)
|
||||
}
|
||||
relations.push([item.id, color])
|
||||
})
|
||||
} else {
|
||||
const colorMap = seriesColor.reduce((pre, next) => {
|
||||
pre[next.id] = next.color
|
||||
return pre
|
||||
}, {})
|
||||
yAxis.forEach(item => {
|
||||
if (colorMap[item.id]) {
|
||||
let color = hexColorToRGBA(colorMap[item.id], basicStyle.alpha)
|
||||
if (basicStyle.gradient) {
|
||||
color = setGradientColor(color, true, 270)
|
||||
}
|
||||
relations.push([' ', color])
|
||||
}
|
||||
})
|
||||
}
|
||||
if (relations.length) {
|
||||
const scaleOptions = {
|
||||
scale: {
|
||||
color: {
|
||||
relations
|
||||
}
|
||||
}
|
||||
}
|
||||
defaultsDeep(options, scaleOptions)
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
protected setupOptions(chart: Chart, options: ViewSpec): ViewSpec {
|
||||
return flow(
|
||||
this.configTheme,
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
import { valueFormatter } from '@/views/chart/components/js/formatter'
|
||||
import {
|
||||
TOOLTIP_ITEM_TPL,
|
||||
toLinearGradient,
|
||||
TOOLTIP_TITLE_TPL
|
||||
} from '@/views/chart/components/js/panel/common/common_antv'
|
||||
import { defaultsDeep, isEmpty } from 'lodash-es'
|
||||
@@ -96,7 +97,7 @@ export class GroupStackBar extends StackBar {
|
||||
})
|
||||
const itemsHtml = result
|
||||
.map(item => {
|
||||
const marker = item.color
|
||||
const marker = toLinearGradient(item.color)
|
||||
const label = item.name
|
||||
const value = item.value
|
||||
return TOOLTIP_ITEM_TPL.replace('{marker}', marker)
|
||||
|
||||
@@ -3,7 +3,12 @@ import {
|
||||
BAR_EDITOR_PROPERTY,
|
||||
BAR_EDITOR_PROPERTY_INNER
|
||||
} from '@/views/chart/components/js/panel/charts/g2/bar/common'
|
||||
import { flow, hexColorToRGBA, parseJson } from '@/views/chart/components/js/util'
|
||||
import {
|
||||
flow,
|
||||
hexColorToRGBA,
|
||||
parseJson,
|
||||
setUpStackSeriesColor
|
||||
} from '@/views/chart/components/js/util'
|
||||
import { ViewSpec } from '@/views/chart/components/js/panel/charts/g2/bar/barUtil'
|
||||
import { useI18n } from '@/hooks/web/useI18n'
|
||||
import { Bar } from '@/views/chart/components/js/panel/charts/g2/bar/bar'
|
||||
@@ -11,6 +16,7 @@ import { getLineDash, setGradientColor } from '@/views/chart/components/js/panel
|
||||
import { valueFormatter } from '@/views/chart/components/js/formatter'
|
||||
import { Chart } from '@antv/g2'
|
||||
import { DEFAULT_BASIC_STYLE } from '@/views/chart/components/editor/util/chart'
|
||||
import { defaultsDeep } from 'lodash-es'
|
||||
|
||||
const { t } = useI18n()
|
||||
/**
|
||||
@@ -87,7 +93,11 @@ export class HorizontalBar extends Bar {
|
||||
columnWidthRatio
|
||||
}
|
||||
}
|
||||
if (this.name === 'bar-stack-horizontal' || this.name === 'progress-bar') {
|
||||
if (
|
||||
this.name === 'bar-stack-horizontal' ||
|
||||
this.name === 'progress-bar' ||
|
||||
this.name === 'bar-range'
|
||||
) {
|
||||
children[0].scale.x = {
|
||||
type: 'band',
|
||||
paddingInner: 0.01
|
||||
@@ -234,10 +244,62 @@ export class HorizontalBar extends Bar {
|
||||
return false
|
||||
}
|
||||
|
||||
public setupSeriesColor(chart: ChartObj, data?: any[]): ChartBasicStyle['seriesColor'] {
|
||||
return setUpStackSeriesColor(chart, data)
|
||||
}
|
||||
|
||||
protected configColor(chart: Chart, options: ViewSpec): ViewSpec {
|
||||
const { basicStyle } = parseJson(chart.customAttr)
|
||||
const { seriesColor } = basicStyle
|
||||
if (!seriesColor?.length) {
|
||||
return options
|
||||
}
|
||||
const { xAxis, yAxis, extStack } = chart
|
||||
if (!xAxis?.length || !yAxis?.length) {
|
||||
return options
|
||||
}
|
||||
const relations = []
|
||||
if (extStack?.length) {
|
||||
seriesColor.forEach(item => {
|
||||
let color = hexColorToRGBA(item.color, basicStyle.alpha)
|
||||
if (basicStyle.gradient) {
|
||||
color = setGradientColor(color, true)
|
||||
}
|
||||
relations.push([item.id, color])
|
||||
})
|
||||
} else {
|
||||
const colorMap = seriesColor.reduce((pre, next) => {
|
||||
pre[next.id] = next.color
|
||||
return pre
|
||||
}, {})
|
||||
yAxis.forEach(item => {
|
||||
if (colorMap[item.id]) {
|
||||
let color = hexColorToRGBA(colorMap[item.id], basicStyle.alpha)
|
||||
if (basicStyle.gradient) {
|
||||
color = setGradientColor(color, true)
|
||||
}
|
||||
relations.push([item.chartShowName ?? item.name, color])
|
||||
}
|
||||
})
|
||||
}
|
||||
if (relations.length) {
|
||||
const scaleOptions = {
|
||||
scale: {
|
||||
color: {
|
||||
relations
|
||||
}
|
||||
}
|
||||
}
|
||||
defaultsDeep(options, scaleOptions)
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
protected setupOptions(chart: Chart, options: ViewSpec): ViewSpec {
|
||||
return flow(
|
||||
this.configTheme,
|
||||
this.configBasicStyle,
|
||||
this.configColor,
|
||||
this.configLabel,
|
||||
this.configTooltip,
|
||||
this.configLegend,
|
||||
|
||||
@@ -7,10 +7,11 @@ import {
|
||||
} from '@/views/chart/components/js/panel/charts/g2/bar/barUtil'
|
||||
import { GroupStackBar } from '@/views/chart/components/js/panel/charts/g2/bar/group-stack-bar'
|
||||
import {
|
||||
toLinearGradient,
|
||||
TOOLTIP_ITEM_TPL,
|
||||
TOOLTIP_TITLE_TPL
|
||||
} from '@/views/chart/components/js/panel/common/common_antv'
|
||||
import { defaultsDeep, isEmpty } from 'lodash-es'
|
||||
import { isEmpty } from 'lodash-es'
|
||||
|
||||
/**
|
||||
* 百分比堆叠柱状图
|
||||
@@ -113,7 +114,7 @@ export class PercentageStackBar extends GroupStackBar {
|
||||
})
|
||||
const itemsHtml = result
|
||||
.map(item => {
|
||||
const marker = item.color
|
||||
const marker = toLinearGradient(item.color)
|
||||
const label = item.name
|
||||
const value = item.value
|
||||
return TOOLTIP_ITEM_TPL.replace('{marker}', marker)
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from '@/views/chart/components/js/panel/charts/g2/bar/barUtil'
|
||||
import {
|
||||
TOOLTIP_ITEM_TPL,
|
||||
toLinearGradient,
|
||||
TOOLTIP_TITLE_TPL
|
||||
} from '@/views/chart/components/js/panel/common/common_antv'
|
||||
import { isEmpty } from 'lodash-es'
|
||||
@@ -105,7 +106,7 @@ export class PercentageStackBar extends HorizontalStackBar {
|
||||
})
|
||||
const itemsHtml = result
|
||||
.map(item => {
|
||||
const marker = item.color
|
||||
const marker = toLinearGradient(item.color)
|
||||
const label = item.name
|
||||
const value = item.value
|
||||
return TOOLTIP_ITEM_TPL.replace('{marker}', marker)
|
||||
@@ -129,6 +130,7 @@ export class PercentageStackBar extends HorizontalStackBar {
|
||||
return flow(
|
||||
this.configTheme,
|
||||
this.configBasicStyle,
|
||||
this.configColor,
|
||||
this.configLabel,
|
||||
this.configTooltip,
|
||||
this.configLegend,
|
||||
|
||||
@@ -16,6 +16,7 @@ import { useI18n } from '@/hooks/web/useI18n'
|
||||
import {
|
||||
handleChartDashboardHidden,
|
||||
setGradientColor,
|
||||
toLinearGradient,
|
||||
TOOLTIP_ITEM_TPL,
|
||||
TOOLTIP_TITLE_TPL
|
||||
} from '@/views/chart/components/js/panel/common/common_antv'
|
||||
@@ -320,7 +321,7 @@ export class ProgressBar extends HorizontalStackBar {
|
||||
})
|
||||
const itemsHtml = result
|
||||
.map(item => {
|
||||
const marker = item.color
|
||||
const marker = toLinearGradient(item.color)
|
||||
const label = item.name
|
||||
const value = item.value
|
||||
return TOOLTIP_ITEM_TPL.replace(
|
||||
|
||||
@@ -2,7 +2,12 @@ import {
|
||||
BAR_EDITOR_PROPERTY,
|
||||
BAR_EDITOR_PROPERTY_INNER
|
||||
} from '@/views/chart/components/js/panel/charts/g2/bar/common'
|
||||
import { flow, parseJson, setUpStackSeriesColor } from '@/views/chart/components/js/util'
|
||||
import {
|
||||
flow,
|
||||
hexColorToRGBA,
|
||||
parseJson,
|
||||
setUpStackSeriesColor
|
||||
} from '@/views/chart/components/js/util'
|
||||
import { Bar } from '@/views/chart/components/js/panel/charts/g2/bar/bar'
|
||||
import { formatterItem, valueFormatter } from '@/views/chart/components/js/formatter'
|
||||
import { groupBy } from 'lodash'
|
||||
@@ -13,10 +18,12 @@ import {
|
||||
ViewSpec
|
||||
} from '@/views/chart/components/js/panel/charts/g2/bar/barUtil'
|
||||
import {
|
||||
setGradientColor,
|
||||
toLinearGradient,
|
||||
TOOLTIP_ITEM_TPL,
|
||||
TOOLTIP_TITLE_TPL
|
||||
} from '@/views/chart/components/js/panel/common/common_antv'
|
||||
import { isEmpty } from 'lodash-es'
|
||||
import { defaultsDeep, isEmpty } from 'lodash-es'
|
||||
|
||||
/**
|
||||
* 堆叠柱状图
|
||||
@@ -136,7 +143,7 @@ export class StackBar extends Bar {
|
||||
})
|
||||
const itemsHtml = result
|
||||
.map(item => {
|
||||
const marker = item.color
|
||||
const marker = toLinearGradient(item.color)
|
||||
const label = item.name
|
||||
const value = item.value
|
||||
return TOOLTIP_ITEM_TPL.replace('{marker}', marker)
|
||||
@@ -194,6 +201,53 @@ export class StackBar extends Bar {
|
||||
return setUpStackSeriesColor(chart, data)
|
||||
}
|
||||
|
||||
protected configColor(chart: Chart, options: ViewSpec): ViewSpec {
|
||||
const { basicStyle } = parseJson(chart.customAttr)
|
||||
const { seriesColor } = basicStyle
|
||||
if (!seriesColor?.length) {
|
||||
return options
|
||||
}
|
||||
const { xAxis, xAxisExt, yAxis, extStack } = chart
|
||||
if (!xAxis?.length || !yAxis?.length) {
|
||||
return options
|
||||
}
|
||||
const relations = []
|
||||
if (xAxisExt?.length || extStack?.length) {
|
||||
seriesColor.forEach(item => {
|
||||
let color = hexColorToRGBA(item.color, basicStyle.alpha)
|
||||
if (basicStyle.gradient) {
|
||||
color = setGradientColor(color, true, 270)
|
||||
}
|
||||
relations.push([item.id, color])
|
||||
})
|
||||
} else {
|
||||
const colorMap = seriesColor.reduce((pre, next) => {
|
||||
pre[next.id] = next.color
|
||||
return pre
|
||||
}, {})
|
||||
yAxis.forEach(item => {
|
||||
if (colorMap[item.id]) {
|
||||
let color = hexColorToRGBA(colorMap[item.id], basicStyle.alpha)
|
||||
if (basicStyle.gradient) {
|
||||
color = setGradientColor(color, true, 270)
|
||||
}
|
||||
relations.push([item.chartShowName ?? item.name, color])
|
||||
}
|
||||
})
|
||||
}
|
||||
if (relations.length) {
|
||||
const scaleOptions = {
|
||||
scale: {
|
||||
color: {
|
||||
relations
|
||||
}
|
||||
}
|
||||
}
|
||||
defaultsDeep(options, scaleOptions)
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
protected setupOptions(chart: Chart, options: ViewSpec): ViewSpec {
|
||||
return flow(
|
||||
this.configTheme,
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
import { useI18n } from '@/hooks/web/useI18n'
|
||||
import {
|
||||
TOOLTIP_ITEM_TPL,
|
||||
toLinearGradient,
|
||||
TOOLTIP_TITLE_TPL
|
||||
} from '@/views/chart/components/js/panel/common/common_antv'
|
||||
import { valueFormatter } from '@/views/chart/components/js/formatter'
|
||||
@@ -103,7 +104,7 @@ export class HorizontalStackBar extends HorizontalBar {
|
||||
})
|
||||
const itemsHtml = result
|
||||
.map(item => {
|
||||
const marker = item.color
|
||||
const marker = toLinearGradient(item.color)
|
||||
const label = item.name
|
||||
const value = item.value
|
||||
return TOOLTIP_ITEM_TPL.replace('{marker}', marker)
|
||||
@@ -127,6 +128,7 @@ export class HorizontalStackBar extends HorizontalBar {
|
||||
return flow(
|
||||
this.configTheme,
|
||||
this.configBasicStyle,
|
||||
this.configColor,
|
||||
this.configLabel,
|
||||
this.configTooltip,
|
||||
this.configLegend,
|
||||
|
||||
@@ -23,6 +23,7 @@ import { DEFAULT_YAXIS_STYLE } from '@/views/chart/components/editor/util/chart'
|
||||
import {
|
||||
handleChartDashboardHidden,
|
||||
setGradientColor,
|
||||
toLinearGradient,
|
||||
TOOLTIP_ITEM_TPL,
|
||||
TOOLTIP_TITLE_TPL
|
||||
} from '../../../common/common_antv'
|
||||
@@ -598,7 +599,7 @@ export class Area extends G2ChartView {
|
||||
})
|
||||
const itemsHtml = result
|
||||
.map(item => {
|
||||
const marker = item.color
|
||||
const marker = toLinearGradient(item.color)
|
||||
const label = item.name
|
||||
const value = item.value
|
||||
return TOOLTIP_ITEM_TPL.replace('{marker}', marker)
|
||||
@@ -840,7 +841,7 @@ export class StackArea extends Area {
|
||||
})
|
||||
const itemsHtml = result
|
||||
.map(item => {
|
||||
const marker = item.color
|
||||
const marker = toLinearGradient(item.color)
|
||||
const label = item.name
|
||||
const value = item.value
|
||||
return TOOLTIP_ITEM_TPL.replace('{marker}', marker)
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
handleChartDashboardHidden,
|
||||
setGradientColor,
|
||||
toLinearGradient,
|
||||
TOOLTIP_ITEM_TPL,
|
||||
TOOLTIP_TITLE_TPL
|
||||
} from '../../../common/common_antv'
|
||||
@@ -593,7 +594,7 @@ export class GroupLineMix extends G2ChartView {
|
||||
})
|
||||
const itemsHtml = result
|
||||
.map(item => {
|
||||
const marker = item.color
|
||||
const marker = toLinearGradient(item.color)
|
||||
const label = item.name
|
||||
const value = item.value
|
||||
return TOOLTIP_ITEM_TPL.replace('{marker}', marker)
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
import {
|
||||
handleChartDashboardHidden,
|
||||
setGradientColor,
|
||||
toLinearGradient,
|
||||
TOOLTIP_ITEM_TPL,
|
||||
TOOLTIP_TITLE_TPL
|
||||
} from '../../../common/common_antv'
|
||||
@@ -591,7 +592,7 @@ export class StackLineMix extends G2ChartView {
|
||||
})
|
||||
const itemsHtml = result
|
||||
.map(item => {
|
||||
const marker = item.color
|
||||
const marker = toLinearGradient(item.color)
|
||||
const label = item.name
|
||||
const value = item.value
|
||||
return TOOLTIP_ITEM_TPL.replace('{marker}', marker)
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
import {
|
||||
handleChartDashboardHidden,
|
||||
setGradientColor,
|
||||
toLinearGradient,
|
||||
TOOLTIP_ITEM_TPL,
|
||||
TOOLTIP_TITLE_TPL
|
||||
} from '../../../common/common_antv'
|
||||
@@ -443,7 +444,7 @@ export class ColumnLineMix extends G2ChartView {
|
||||
})
|
||||
const itemsHtml = result
|
||||
.map(item => {
|
||||
const marker = item.color
|
||||
const marker = toLinearGradient(item.color)
|
||||
const label = item.name
|
||||
const value = item.value
|
||||
return TOOLTIP_ITEM_TPL.replace('{marker}', marker)
|
||||
|
||||
Reference in New Issue
Block a user