diff --git a/core/core-frontend/src/custom-component/v-query/DynamicTimeFiltering.vue b/core/core-frontend/src/custom-component/v-query/DynamicTimeFiltering.vue index 62e53255e5..fd7f7528c7 100644 --- a/core/core-frontend/src/custom-component/v-query/DynamicTimeFiltering.vue +++ b/core/core-frontend/src/custom-component/v-query/DynamicTimeFiltering.vue @@ -6,7 +6,7 @@ import type { ManipulateType } from 'dayjs' import { getThisStart, getThisEnd, getLastStart, getAroundStart } from './time-format-dayjs' interface SelectConfig { intervalType: string - regularOrTrendsValue: Date + regularOrTrendsValue: string | Date | [Date, Date] regularOrTrends: string relativeToCurrent: string timeNum: number diff --git a/core/core-frontend/src/custom-component/v-query/DynamicTimeRangeFiltering.vue b/core/core-frontend/src/custom-component/v-query/DynamicTimeRangeFiltering.vue index c85845b551..5e4f8cb2ea 100644 --- a/core/core-frontend/src/custom-component/v-query/DynamicTimeRangeFiltering.vue +++ b/core/core-frontend/src/custom-component/v-query/DynamicTimeRangeFiltering.vue @@ -6,13 +6,13 @@ import type { ManipulateType } from 'dayjs' import { getAround, getCustomRange, getAroundStart } from './time-format-dayjs' interface SelectConfig { regularOrTrends: string - regularOrTrendsValue: [Date, Date] + regularOrTrendsValue: string | Date | [Date, Date] intervalType: string relativeToCurrentRange: string timeNum: number relativeToCurrentType: ManipulateType around: string - timeGranularity: DatePickType + timeGranularity?: DatePickType timeNumRange: number relativeToCurrentTypeRange: ManipulateType aroundRange: string diff --git a/core/core-frontend/src/custom-component/v-query/RangeFilterTime.vue b/core/core-frontend/src/custom-component/v-query/RangeFilterTime.vue index 163af40690..f215783953 100644 --- a/core/core-frontend/src/custom-component/v-query/RangeFilterTime.vue +++ b/core/core-frontend/src/custom-component/v-query/RangeFilterTime.vue @@ -5,6 +5,27 @@ import { useI18n } from '@/hooks/web/useI18n' import DynamicTime from './DynamicTimeFiltering.vue' import DynamicTimeRange from './DynamicTimeRangeFiltering.vue' import { ManipulateType } from 'dayjs' +import { type DatePickType } from 'element-plus-secondary' + +type OptionItem = { + label: string + value: string +} + +type DynamicConfig = { + regularOrTrends: string + regularOrTrendsValue: string | Date | [Date, Date] + intervalType: string + relativeToCurrent: string + relativeToCurrentRange: string + timeNum: number + relativeToCurrentType: ManipulateType + around: string + timeNumRange: number + relativeToCurrentTypeRange: ManipulateType + aroundRange: string + timeGranularity?: DatePickType +} const props = defineProps({ timeRange: { type: Object as PropType, @@ -25,7 +46,7 @@ const props = defineProps({ }) }, timeGranularityMultiple: { - type: String, + type: String as PropType, default: 'yearrange' } }) @@ -51,7 +72,7 @@ const intervalTypeList = [ ] const regularOrTrendsTitle = computed(() => { - return intervalTypeList.find(ele => ele.value === timeRange.value.intervalType).label + return intervalTypeList.find(ele => ele.value === timeRange.value.intervalType)?.label || '' }) const { timeRange } = toRefs(props) const dynamicTime = computed(() => { @@ -62,6 +83,10 @@ const filterTypeCom = computed(() => { return intervalType === 'timeInterval' ? DynamicTimeRange : DynamicTime }) +const dynamicConfig = computed(() => { + return timeRange.value as unknown as DynamicConfig +}) + const aroundList = [ { label: t('dynamic_time.before'), @@ -98,7 +123,7 @@ const relativeToCurrentTypeListTips = computed(() => { return (relativeToCurrentTypeList.value[relativeToCurrentTypeList.value.length - 1] || {}).label }) const relativeToCurrentList = computed(() => { - let list = [] + let list: OptionItem[] = [] if (!timeRange.value) return list switch (props.timeGranularityMultiple) { case 'yearrange': @@ -188,7 +213,7 @@ const relativeToCurrentList = computed(() => { }) const relativeToCurrentListRange = computed(() => { - let list = [] + let list: OptionItem[] = [] if (!timeRange.value) return list switch (props.timeGranularityMultiple) { case 'yearrange': @@ -265,6 +290,10 @@ const relativeToCurrentListRange = computed(() => { { label: t('common.month_to_yesterday'), value: 'monthToYesterday' + }, + { + label: t('v_query.last_month_full'), + value: 'LastMonthFull' } ] break @@ -465,7 +494,7 @@ watch(
{{ t('template_manage.preview') }}
{ + const value = Number(item?.value) + if (Number.isFinite(value)) { + range.min = Math.min(range.min, value) + range.max = Math.max(range.max, value) + } + return range + }, + { min: Infinity, max: -Infinity } + ) + const tickMethod = (min, max, count = 5) => { + if (min === max) { + return [min] + } + const splitCount = Math.max(1, count) + const step = (max - min) / splitCount + const ticks = [] + for (let i = 0; i <= splitCount; i++) { + ticks.push(min + step * i) + } + return ticks + } + if (axisValue?.auto !== false) { + if (Number.isFinite(dataRange.min) && Number.isFinite(dataRange.max)) { + const dataMin = dataRange.min + const dataMax = dataRange.max + const splitCount = Math.max(1, Number(misc.splitNumber) || 5) + const padding = (dataMax - dataMin || Math.abs(dataMax) || 1) / splitCount + options.scale.y = { + ...options.scale.y, + // G2 的 nice 会同时扩展最小值,这里只固定最小值并给最大值留出一格空间 + nice: false, + domainMin: dataMin, + domainMax: dataMax + padding, + tickCount: splitCount, + tickMethod + } + } + } else { const yScale = { scale: { y: { domainMin: axisValue.min, domainMax: axisValue.max, tickCount: axisValue.splitCount, - tickMethod: (min, max, count) => { - const step = (max - min) / count - const ticks = [] - for (let i = 0; i <= count; i++) { - ticks.push(min + step * i) - } - return ticks - } + tickMethod } } }