diff --git a/core/frontend/src/lang/en.js b/core/frontend/src/lang/en.js index 72a8dc2ce6..69889fad94 100644 --- a/core/frontend/src/lang/en.js +++ b/core/frontend/src/lang/en.js @@ -1051,6 +1051,9 @@ export default { color_technology: 'Technology', color_simple: 'Simple', not_alpha: 'Opacity', + top_n_desc: 'Merge data into other', + top_n_input_1: 'Show Top', + top_n_input_2: ',the rest merged to other', area_border_color: 'Map border', area_base_color: 'Base map', size: 'Size', diff --git a/core/frontend/src/lang/tw.js b/core/frontend/src/lang/tw.js index 505617cab3..4ca73778db 100644 --- a/core/frontend/src/lang/tw.js +++ b/core/frontend/src/lang/tw.js @@ -1051,6 +1051,9 @@ export default { color_technology: '科技', color_simple: '簡潔', not_alpha: '不透明度', + top_n_desc: '合併數據', + top_n_input_1: '顯示 Top', + top_n_input_2: ', 其餘合併至其他', area_border_color: '地圖邊線', area_base_color: '底圖', size: '大小', diff --git a/core/frontend/src/lang/zh.js b/core/frontend/src/lang/zh.js index 251068c9e4..47f81a2485 100644 --- a/core/frontend/src/lang/zh.js +++ b/core/frontend/src/lang/zh.js @@ -1050,6 +1050,9 @@ export default { color_technology: '科技', color_simple: '简洁', not_alpha: '不透明度', + top_n_desc: '合并数据', + top_n_input_1: '显示 Top', + top_n_input_2: ', 其余合并至其他', area_border_color: '地图边线', area_base_color: '底图', size: '大小', diff --git a/core/frontend/src/views/chart/chart/chart.js b/core/frontend/src/views/chart/chart/chart.js index ea570cd586..62f4aa90cc 100644 --- a/core/frontend/src/views/chart/chart/chart.js +++ b/core/frontend/src/views/chart/chart/chart.js @@ -40,7 +40,9 @@ export const DEFAULT_COLOR_CASE = { mapLineGradient: false, mapLineSourceColor: '#146C94', mapLineTargetColor: '#576CBC', - quotaSuffixColor: '#5470c6' + quotaSuffixColor: '#5470c6', + calcTopN: false, + topN: 5, } export const DEFAULT_COLOR_CASE_DARK = { @@ -65,7 +67,9 @@ export const DEFAULT_COLOR_CASE_DARK = { mapLineGradient: false, mapLineSourceColor: '#2F58CD', mapLineTargetColor: '#3795BD', - quotaSuffixColor: '#5470c6' + quotaSuffixColor: '#5470c6', + calcTopN: false, + topN: 5, } export const DEFAULT_SIZE = { barDefault: true, diff --git a/core/frontend/src/views/chart/chart/common/common.js b/core/frontend/src/views/chart/chart/common/common.js index 8666942218..4d718bd783 100644 --- a/core/frontend/src/views/chart/chart/common/common.js +++ b/core/frontend/src/views/chart/chart/common/common.js @@ -3,6 +3,7 @@ import { DEFAULT_XAXIS_STYLE, DEFAULT_YAXIS_EXT_STYLE, DEFAULT_YAXIS_STYLE } fro import { formatterItem, valueFormatter } from '@/views/chart/chart/formatter' import { $success } from '@/utils/message' import i18n from '@/lang' +import { cloneDeep } from 'lodash' export function componentStyle(chart_option, chart) { let xAxisLabelFormatter = null @@ -423,3 +424,29 @@ export const copyString = (content, notify) => { } }) } + +export const configTopN = (data, chart) => { + if (!data?.length) { + return + } + const color = JSON.parse(chart.customAttr).color + if (!color.calcTopN || data.length <= color.topN) { + return + } + data.sort((a, b) => b.value - a.value) + const otherItems = data.splice(color.topN) + const initOtherItem = { + ...cloneDeep(data[0]), + name: i18n.t('datasource.other'), + value: 0, + } + otherItems.reduce((p, n) => { + p.value += n.value ?? 0 + return p + }, initOtherItem) + data.push(initOtherItem) + data.forEach((item, i) => { + const curColor = color.colors[i % color.colors.length] + item.itemStyle.color = hexColorToRGBA(curColor, color.alpha) + }) +} diff --git a/core/frontend/src/views/chart/chart/common/common_antv.js b/core/frontend/src/views/chart/chart/common/common_antv.js index 354129bf9e..010a5a8f1a 100644 --- a/core/frontend/src/views/chart/chart/common/common_antv.js +++ b/core/frontend/src/views/chart/chart/common/common_antv.js @@ -2,6 +2,7 @@ import { hexColorToRGBA } from '@/views/chart/chart/util' import { formatterItem, valueFormatter } from '@/views/chart/chart/formatter' import { DEFAULT_XAXIS_STYLE, DEFAULT_YAXIS_EXT_STYLE, DEFAULT_YAXIS_STYLE } from '@/views/chart/chart/chart' import { equalsAny, includesAny } from '@/utils/StringUtils' +import i18n from '@/lang' export function getPadding(chart) { if (chart.drill) { @@ -1235,3 +1236,25 @@ export const TOOLTIP_TPL = '