mirror of
https://github.com/dataease/dataease.git
synced 2026-05-16 14:31:00 +08:00
fix(图表): 修复柱条图配置圆角影响条件样式的问题
This commit is contained in:
committed by
jianneng-fit2cloud
parent
91e5ce11aa
commit
c3d6d8a9c7
@@ -19,7 +19,6 @@ import {
|
||||
BAR_EDITOR_PROPERTY_INNER
|
||||
} from '@/views/chart/components/js/panel/charts/bar/common'
|
||||
import {
|
||||
assembleOptionsDataForRoundAngle,
|
||||
configPlotTooltipEvent,
|
||||
configRoundAngle,
|
||||
getLabel,
|
||||
@@ -59,8 +58,7 @@ export class Bar extends G2PlotChartView<ColumnOptions, Column> {
|
||||
yField: 'value',
|
||||
seriesField: 'category',
|
||||
isGroup: true,
|
||||
data: [],
|
||||
rawFields: ['isFirst', 'isLast']
|
||||
data: []
|
||||
}
|
||||
|
||||
axis: AxisType[] = [...BAR_AXIS_TYPE]
|
||||
@@ -90,7 +88,7 @@ export class Bar extends G2PlotChartView<ColumnOptions, Column> {
|
||||
const initOptions: ColumnOptions = {
|
||||
...this.baseOptions,
|
||||
appendPadding: getPadding(chart),
|
||||
data: assembleOptionsDataForRoundAngle(data, isGroup, isStack)
|
||||
data
|
||||
}
|
||||
const options: ColumnOptions = this.setupOptions(chart, initOptions)
|
||||
let newChart = null
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
} from '@/views/chart/components/js/panel/types/impl/g2plot'
|
||||
import type { Bar, BarOptions } from '@antv/g2plot/esm/plots/bar'
|
||||
import {
|
||||
assembleOptionsDataForRoundAngle,
|
||||
configAxisLabelLengthLimit,
|
||||
configPlotTooltipEvent,
|
||||
configRoundAngle,
|
||||
@@ -78,8 +77,7 @@ export class HorizontalBar extends G2PlotChartView<BarOptions, Bar> {
|
||||
xField: 'value',
|
||||
yField: 'field',
|
||||
seriesField: 'category',
|
||||
isGroup: true,
|
||||
rawFields: ['isFirst', 'isLast']
|
||||
isGroup: true
|
||||
}
|
||||
|
||||
async drawChart(drawOptions: G2PlotDrawOptions<Bar>): Promise<Bar> {
|
||||
@@ -94,7 +92,7 @@ export class HorizontalBar extends G2PlotChartView<BarOptions, Bar> {
|
||||
const initOptions: BarOptions = {
|
||||
...this.baseOptions,
|
||||
appendPadding: getPadding(chart),
|
||||
data: assembleOptionsDataForRoundAngle(data, false)
|
||||
data
|
||||
}
|
||||
|
||||
const options = this.setupOptions(chart, initOptions)
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
} from '@/views/chart/components/js/panel/types/impl/g2plot'
|
||||
import type { DualAxes, DualAxesOptions } from '@antv/g2plot/esm/plots/dual-axes'
|
||||
import {
|
||||
assembleOptionsDataForRoundAngle,
|
||||
configRoundAngle,
|
||||
configPlotTooltipEvent,
|
||||
getAnalyse,
|
||||
@@ -124,7 +123,7 @@ export class ColumnLineMix extends G2PlotChartView<DualAxesOptions, DualAxes> {
|
||||
})
|
||||
// options
|
||||
const initOptions: DualAxesOptions = {
|
||||
data: [assembleOptionsDataForRoundAngle(data1, isGroup), data2],
|
||||
data: [data1, data2],
|
||||
xField: 'field',
|
||||
yField: ['value', 'valueExt'], //这里不能设置成一样的
|
||||
appendPadding: getPadding(chart),
|
||||
@@ -135,8 +134,7 @@ export class ColumnLineMix extends G2PlotChartView<DualAxesOptions, DualAxes> {
|
||||
color: [],
|
||||
isGroup: isGroup,
|
||||
isStack: isStack,
|
||||
seriesField: seriesField,
|
||||
rawFields: ['isFirst', 'isLast']
|
||||
seriesField: seriesField
|
||||
},
|
||||
{
|
||||
geometry: data2Type,
|
||||
|
||||
@@ -2449,32 +2449,14 @@ export const configRoundAngle = (chart: Chart, styleName: string, callBack?: (da
|
||||
}
|
||||
}
|
||||
}
|
||||
// 堆叠条形图、百分比条形图第一个和最后一个反转
|
||||
const isStackHorizontalBar = [
|
||||
'bar-stack-horizontal',
|
||||
'percentage-bar-stack-horizontal'
|
||||
].includes(chart.type)
|
||||
// 配置柱条样式
|
||||
const style = datum => {
|
||||
if (isTopRound && datum.isFirst && datum.isLast) {
|
||||
if (isTopRound) {
|
||||
return { radius, ...(callBack ? callBack(datum) : {}) }
|
||||
}
|
||||
if (!isTopRound && datum.isFirst && datum.isLast) {
|
||||
if (!isTopRound) {
|
||||
return { radius: finalRadius, ...(callBack ? callBack(datum) : {}) }
|
||||
}
|
||||
if (isStackHorizontalBar) {
|
||||
if (datum.isLast || (!isTopRound && datum.isFirst)) {
|
||||
return {
|
||||
radius: datum.isFirst ? topRadius : radius,
|
||||
...(callBack ? callBack(datum) : {})
|
||||
}
|
||||
}
|
||||
} else if (datum.isFirst || (!isTopRound && datum.isLast)) {
|
||||
return {
|
||||
radius: datum.isLast ? topRadius : radius,
|
||||
...(callBack ? callBack(datum) : {})
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
[styleName]: style
|
||||
@@ -2486,48 +2468,3 @@ export const configRoundAngle = (chart: Chart, styleName: string, callBack?: (da
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 为圆角组装options.data,
|
||||
* 添加 isFirst 和 isLast 属性
|
||||
* @param data
|
||||
* @param isGroup
|
||||
* @param isStack
|
||||
*/
|
||||
export const assembleOptionsDataForRoundAngle = (
|
||||
data: Record<string, any>[],
|
||||
isGroup: boolean,
|
||||
isStack?: boolean
|
||||
) => {
|
||||
// column数据分组
|
||||
const groupedByField = new Map<string, Record<string, any>[]>()
|
||||
|
||||
data.forEach(item => {
|
||||
let groupField = item.field
|
||||
if (isGroup || isStack) {
|
||||
groupField = `${item.field}-${isStack ? item.group : item.category}`
|
||||
}
|
||||
if (!groupedByField.has(groupField)) {
|
||||
groupedByField.set(groupField, [])
|
||||
}
|
||||
groupedByField.get(groupField)?.push(item)
|
||||
})
|
||||
|
||||
// 遍历每个分组,添加 isFirst 和 isLast 属性
|
||||
groupedByField.forEach(group => {
|
||||
const firstItem = group[0]
|
||||
const lastItem = group[group.length - 1]
|
||||
if (firstItem) firstItem.isFirst = true
|
||||
if (lastItem) lastItem.isLast = true
|
||||
})
|
||||
|
||||
// 按原始数据顺序重新组装
|
||||
return data.map(item => {
|
||||
let groupField = item.field
|
||||
if (isGroup || isStack) {
|
||||
groupField = `${item.field}-${isStack ? item.group : item.category}`
|
||||
}
|
||||
const group = groupedByField.get(groupField)
|
||||
return group && group.length > 0 ? group.shift() : item
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user