diff --git a/core/core-frontend/src/locales/en.ts b/core/core-frontend/src/locales/en.ts index d4f12cbc1e..3c6e08ffbc 100644 --- a/core/core-frontend/src/locales/en.ts +++ b/core/core-frontend/src/locales/en.ts @@ -2075,7 +2075,8 @@ export default { threshold_value: 'Threshold Value', range_num: 'Number of Range', show_range_bg: 'Show Range Background', - last_item: 'Last item' + last_item: 'Last item', + legend_sort: 'Legend sort' }, dataset: { field_value: 'Field Value', diff --git a/core/core-frontend/src/locales/tw.ts b/core/core-frontend/src/locales/tw.ts index da374abeb0..04f9bd18b6 100644 --- a/core/core-frontend/src/locales/tw.ts +++ b/core/core-frontend/src/locales/tw.ts @@ -2018,7 +2018,8 @@ export default { threshold_value: '分界值', range_num: '區間背景個數', show_range_bg: '顯示區間背景', - last_item: '最後一項' + last_item: '最後一項', + legend_sort: '圖例排序' }, dataset: { field_value: '欄位值', diff --git a/core/core-frontend/src/locales/zh-CN.ts b/core/core-frontend/src/locales/zh-CN.ts index dc7e0944a2..abea2125c4 100644 --- a/core/core-frontend/src/locales/zh-CN.ts +++ b/core/core-frontend/src/locales/zh-CN.ts @@ -2024,7 +2024,8 @@ export default { threshold_value: '分界值', range_num: '区间背景个数', show_range_bg: '显示区间背景', - last_item: '最后一项' + last_item: '最后一项', + legend_sort: '图例排序' }, dataset: { field_value: '字段值', @@ -3324,7 +3325,6 @@ export default { template: '模板', category: '分类', all_org: '所有组织', - custom: '自定义', import_template: '导入模板', copy_template: '复用模板', upload_template: '上传模板', diff --git a/core/core-frontend/src/models/chart/chart-style.d.ts b/core/core-frontend/src/models/chart/chart-style.d.ts index d95b48a538..b84823319e 100644 --- a/core/core-frontend/src/models/chart/chart-style.d.ts +++ b/core/core-frontend/src/models/chart/chart-style.d.ts @@ -122,11 +122,22 @@ declare interface ChartLegendStyle { * 字体大小 */ fontSize: number + /** + * 图例大小 + */ size: number /** * 子弹图显示区间背景 */ showRange: true + /** + * 排序方式 + */ + sort: 'none' | 'asc' | 'desc' | 'custom' + /** + * 自定义排序 + */ + customSort: string[] } /** diff --git a/core/core-frontend/src/views/chart/components/editor/drag-item/components/CustomSortEdit.vue b/core/core-frontend/src/views/chart/components/editor/drag-item/components/CustomSortEdit.vue index f1c24ac957..47570e3455 100644 --- a/core/core-frontend/src/views/chart/components/editor/drag-item/components/CustomSortEdit.vue +++ b/core/core-frontend/src/views/chart/components/editor/drag-item/components/CustomSortEdit.vue @@ -24,6 +24,11 @@ const props = defineProps({ fieldType: { type: String, required: true + }, + originSortList: { + type: Array, + default: () => [], + required: false } }) @@ -54,6 +59,17 @@ const init = () => { reqMethod(param) .then(response => { const strArr = response.data + if (props.originSortList?.length) { + const tmp = [] + props.originSortList.forEach(ele => { + const index = strArr.findIndex(item => item === ele) + if (index !== -1) { + tmp.push(strArr[index]) + strArr.splice(index, 1) + } + }) + strArr.unshift(...tmp) + } state.sortList = strArr.map(ele => { return transStr2Obj(ele) }) diff --git a/core/core-frontend/src/views/chart/components/editor/editor-style/components/LegendSelector.vue b/core/core-frontend/src/views/chart/components/editor/editor-style/components/LegendSelector.vue index 5e28b30df5..bcc153968b 100644 --- a/core/core-frontend/src/views/chart/components/editor/editor-style/components/LegendSelector.vue +++ b/core/core-frontend/src/views/chart/components/editor/editor-style/components/LegendSelector.vue @@ -16,6 +16,7 @@ import { ElCol, ElFormItem, ElRow, ElSpace } from 'element-plus-secondary' import { cloneDeep } from 'lodash-es' import { useEmitt } from '@/hooks/web/useEmitt' import { getDynamicColorScale } from '@/views/chart/components/js/util' +import CustomSortEdit from '@/views/chart/components/editor/drag-item/components/CustomSortEdit.vue' const { t } = useI18n() @@ -55,7 +56,9 @@ const state = reactive({ legendForm: { ...JSON.parse(JSON.stringify(DEFAULT_LEGEND_STYLE)), miscForm: JSON.parse(JSON.stringify(DEFAULT_MISC)) as ChartMiscAttr - } + }, + showCustomSort: false, + customSortField: null }) const chartType = computed(() => { @@ -226,6 +229,31 @@ const getMapCustomRange = index => { if (index === state.legendForm.miscForm.mapLegendNumber) return t('chart.max') return '' } +const customSort = [] +const changeLegendSort = sort => { + if (sort === 'custom') { + state.customSortField = cloneDeep(props.chart.xAxisExt?.[0]) + if (!state.customSortField) { + return + } + state.showCustomSort = true + } else { + state.showCustomSort = false + state.legendForm.sort = sort + } + changeLegendStyle('sort') +} +const closeCustomSort = () => { + state.showCustomSort = false +} +const saveCustomSort = () => { + state.showCustomSort = false + state.legendForm.customSort = customSort + changeLegendStyle('customSort') +} +const customSortChange = list => { + customSort.splice(0, customSort.length, ...list) +} onMounted(() => { init() }) @@ -674,7 +702,54 @@ onMounted(() => { + + + + + + + + + + + +