diff --git a/core/core-frontend/src/models/chart/chart-attr.d.ts b/core/core-frontend/src/models/chart/chart-attr.d.ts
index 649cc0429e..746a28ddd6 100644
--- a/core/core-frontend/src/models/chart/chart-attr.d.ts
+++ b/core/core-frontend/src/models/chart/chart-attr.d.ts
@@ -681,6 +681,15 @@ declare interface ChartMiscAttr {
* 显示图例个数
*/
mapLegendNumber: number
+ /**
+ * 自定义区间类型,等间距,自定义
+ */
+ mapLegendRangeType: 'quantize' | 'custom'
+ /**
+ * 自定义区间类型为自定义(custom)时生效
+ * 自定义区间值
+ */
+ mapLegendCustomRange: number[]
/**
* 流向地图配置
*/
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 89d41a8f00..6dd48f5423 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
@@ -15,6 +15,7 @@ import {
import { ElCol, 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'
const { t } = useI18n()
@@ -99,18 +100,114 @@ const init = () => {
if (!state.legendForm.miscForm.hasOwnProperty('mapAutoLegend')) {
state.legendForm.miscForm.mapAutoLegend = true
}
+ if (!state.legendForm.miscForm.hasOwnProperty('mapLegendRangeType')) {
+ state.legendForm.miscForm.mapLegendRangeType = 'quantize'
+ }
+ if (!state.legendForm.miscForm.hasOwnProperty('mapLegendCustomRange')) {
+ state.legendForm.miscForm.mapLegendCustomRange = []
+ }
+ initMapCustomRange()
}
}
}
}
+// 存储地图默认的最大最小值
+const mapLegendDefaultRange = {
+ max: 0,
+ min: 0
+}
+// 缓存原始的区间数据
+let mapLegendCustomRangeCacheList = []
const showProperty = prop => props.propertyInner?.includes(prop)
const mapDefaultRange = args => {
if (args.from === 'map') {
- state.legendForm.miscForm.mapLegendMax = args.data.max
- state.legendForm.miscForm.mapLegendMin = args.data.min
- state.legendForm.miscForm.mapLegendNumber = args.data.legendNumber
+ const rangeCustom = state.legendForm.miscForm.mapLegendRangeType === 'custom'
+ if (!rangeCustom) {
+ state.legendForm.miscForm.mapLegendMax = cloneDeep(args.data.max)
+ state.legendForm.miscForm.mapLegendMin = cloneDeep(args.data.min)
+ }
+ state.legendForm.miscForm.mapLegendNumber = cloneDeep(args.data.legendNumber)
+ mapLegendCustomRangeCacheList = []
+ mapLegendDefaultRange.max = cloneDeep(args.data.max)
+ mapLegendDefaultRange.min = cloneDeep(args.data.min)
+ const customRange = getDynamicColorScale(
+ mapLegendDefaultRange.min,
+ mapLegendDefaultRange.max,
+ args.data.legendNumber
+ )
+ customRange.forEach((item, index) => {
+ if (index === 0) {
+ mapLegendCustomRangeCacheList.push(...item.value)
+ } else {
+ mapLegendCustomRangeCacheList.push(item.value[1])
+ }
+ })
}
}
+const initMapCustomRange = () => {
+ const legendCustom = state.legendForm.miscForm.mapAutoLegend
+ const rangeCustom = state.legendForm.miscForm.mapLegendRangeType === 'custom'
+ const rangeCustomValue = state.legendForm.miscForm.mapLegendCustomRange
+ // 是自定义,并且自定义类型是自定义区间以及rangeCustomValue长度为0时,根据默认最大最小值计算区间值
+ if (legendCustom && rangeCustom && rangeCustomValue.length === 0) {
+ calcMapCustomRange()
+ }
+}
+/**
+ * 计算自定义区间
+ */
+const calcMapCustomRange = () => {
+ const customRange = getDynamicColorScale(
+ mapLegendDefaultRange.min,
+ mapLegendDefaultRange.max,
+ state.legendForm.miscForm.mapLegendNumber
+ )
+ state.legendForm.miscForm.mapLegendCustomRange = []
+ customRange.forEach((item, index) => {
+ if (index === 0) {
+ state.legendForm.miscForm.mapLegendCustomRange.push(...item.value)
+ } else {
+ state.legendForm.miscForm.mapLegendCustomRange.push(item.value[1])
+ }
+ })
+}
+/**
+ * 改变自定义区间类型
+ * @param prop
+ */
+const changeLegendCustomType = (prop?) => {
+ const type = state.legendForm.miscForm.mapLegendRangeType
+ if (type === 'custom') {
+ state.legendForm.miscForm.mapLegendCustomRange = cloneDeep(
+ mapLegendCustomRangeCacheList.slice(0, state.legendForm.miscForm.mapLegendNumber + 1)
+ )
+ } else {
+ state.legendForm.miscForm.mapLegendCustomRange = []
+ }
+ prop ? changeMisc(prop) : ''
+}
+/**
+ * 改变自定义区间个数
+ * @param prop
+ */
+const changeLegendNumber = (prop?) => {
+ if (!state.legendForm.miscForm.mapLegendNumber) {
+ return
+ }
+ calcMapCustomRange()
+ prop ? changeMisc(prop) : ''
+}
+const changeRangeItem = (prop, index) => {
+ console.log(state.legendForm.miscForm.mapLegendCustomRange[index])
+ console.log(mapLegendCustomRangeCacheList[index])
+ if (state.legendForm.miscForm.mapLegendCustomRange[index] === null) {
+ state.legendForm.miscForm.mapLegendCustomRange[index] = cloneDeep(
+ mapLegendCustomRangeCacheList[index]
+ )
+ console.log(state.legendForm.miscForm.mapLegendCustomRange[index])
+ }
+ changeMisc(prop)
+}
onMounted(() => {
init()
})
@@ -194,48 +291,58 @@ onMounted(() => {
class="form-item"
:class="'form-item-' + themes"
:label="t('chart.legend')"
+ prop="miscForm.mapAutoLegend"
>
-