forked from github/dataease
feat(视图): AntV 堆叠柱状图按照指标整体排序 #5872
This commit is contained in:
parent
899e8b16d4
commit
1b7c662642
@ -14,7 +14,7 @@ import {
|
|||||||
configPlotTooltipEvent,
|
configPlotTooltipEvent,
|
||||||
configAxisLabelLengthLimit
|
configAxisLabelLengthLimit
|
||||||
} from '@/views/chart/chart/common/common_antv'
|
} from '@/views/chart/chart/common/common_antv'
|
||||||
import { antVCustomColor, getColors, handleEmptyDataStrategy, hexColorToRGBA } from '@/views/chart/chart/util'
|
import { antVCustomColor, getColors, handleEmptyDataStrategy, hexColorToRGBA, handleStackSort } from '@/views/chart/chart/util'
|
||||||
import { cloneDeep, find } from 'lodash-es'
|
import { cloneDeep, find } from 'lodash-es'
|
||||||
|
|
||||||
export function baseBarOptionAntV(container, chart, action, isGroup, isStack) {
|
export function baseBarOptionAntV(container, chart, action, isGroup, isStack) {
|
||||||
@ -131,6 +131,8 @@ export function baseBarOptionAntV(container, chart, action, isGroup, isStack) {
|
|||||||
}
|
}
|
||||||
handleEmptyDataStrategy(emptyDataStrategy, chart, data, options)
|
handleEmptyDataStrategy(emptyDataStrategy, chart, data, options)
|
||||||
}
|
}
|
||||||
|
// 处理堆叠排序
|
||||||
|
handleStackSort(chart, data)
|
||||||
|
|
||||||
// 开始渲染
|
// 开始渲染
|
||||||
const plot = new Column(container, options)
|
const plot = new Column(container, options)
|
||||||
@ -240,6 +242,8 @@ export function hBaseBarOptionAntV(container, chart, action, isGroup, isStack) {
|
|||||||
return setGradientColor(ele, customAttr.color.gradient)
|
return setGradientColor(ele, customAttr.color.gradient)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// 处理堆叠排序
|
||||||
|
handleStackSort(chart, data)
|
||||||
// 处理空值
|
// 处理空值
|
||||||
if (chart.senior) {
|
if (chart.senior) {
|
||||||
let emptyDataStrategy = JSON.parse(chart.senior)?.functionCfg?.emptyDataStrategy
|
let emptyDataStrategy = JSON.parse(chart.senior)?.functionCfg?.emptyDataStrategy
|
||||||
|
@ -3967,3 +3967,29 @@ export function adjustPosition(targetDom, parentDom, clickPosition, offset, init
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function handleStackSort(chart, data) {
|
||||||
|
if (!data?.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!chart.type.includes('stack') ||
|
||||||
|
chart.type.includes('group')) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const { xaxis, yaxis, extStack } = chart
|
||||||
|
const xAxis = JSON.parse(xaxis)
|
||||||
|
const yAxis = JSON.parse(yaxis)
|
||||||
|
const stack = JSON.parse(extStack)
|
||||||
|
if (!(stack.length && xAxis.length && yAxis.length) ||
|
||||||
|
yAxis[0].sort === 'none' ||
|
||||||
|
!xAxis.every(i => i.sort === 'none')) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const result = data.reduce((p, n, i) => {
|
||||||
|
p[n.field] = (p[n.field] || 0) + (n.value ?? 0)
|
||||||
|
return p
|
||||||
|
}, {})
|
||||||
|
data.sort((p, n) => {
|
||||||
|
return yAxis[0].sort === 'asc' ? result[p.field] - result[n.field] : result[n.field] - result[p.field]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user