perf: 图表数据规范化

This commit is contained in:
zxc 2024-09-15 12:09:16 +08:00
parent 51ad1a8244
commit 16aaea3310
2 changed files with 25 additions and 3 deletions

View File

@ -80,12 +80,13 @@
<script lang="ts" setup>
import { computed, onMounted, onUnmounted, ref } from 'vue'
import type { ChartData } from '@/types/slides'
import type { ChartData, ChartType } from '@/types/slides'
import { KEYS } from '@/configs/hotkey'
import { pasteCustomClipboardString, pasteExcelClipboardString } from '@/utils/clipboard'
import Button from '@/components/Button.vue'
const props = defineProps<{
type: ChartType
data: ChartData
}>()
@ -177,8 +178,8 @@ const getTableData = () => {
const [col, row] = selectedRange.value
const labels: string[] = []
const legends: string[] = []
const series: number[][] = []
let legends: string[] = []
let series: number[][] = []
//
for (let rowIndex = 1; rowIndex < row; rowIndex++) {
@ -207,6 +208,26 @@ const getTableData = () => {
series.push(seriesItem)
}
//
//
if (props.type === 'scatter') {
if (legends.length > 2) {
legends = legends.slice(0, 2)
series = series.slice(0, 2)
}
if (legends.length < 2) {
legends.push('Y')
series.push(series[0])
}
}
//
if (props.type === 'ring' || props.type === 'pie') {
if (legends.length > 1) {
legends = legends.slice(0, 1)
series = series.slice(0, 1)
}
}
emit('save', { labels, legends, series })
}

View File

@ -105,6 +105,7 @@
:width="640"
>
<ChartDataEditor
:type="handleChartElement.chartType"
:data="handleChartElement.data"
@close="chartDataEditorVisible = false"
@save="value => updateData(value)"