From 21830a0647ccf458b22bc960bef9b54378368eab Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Fri, 17 May 2024 11:11:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9B=BE=E8=A1=A8-=E8=B1=A1=E9=99=90?= =?UTF-8?q?=E5=9B=BE):=20=E6=81=92=E7=BA=BF=E6=94=AF=E6=8C=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=B0=8F=E6=95=B0=E4=BB=A5=E5=8F=8A=E8=B4=9F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/QuadrantSelector.vue | 24 ++++++++++++------ .../js/panel/charts/others/quadrant.ts | 25 +++++-------------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/editor/editor-style/components/QuadrantSelector.vue b/core/core-frontend/src/views/chart/components/editor/editor-style/components/QuadrantSelector.vue index 139861dc0c..d232b27b64 100644 --- a/core/core-frontend/src/views/chart/components/editor/editor-style/components/QuadrantSelector.vue +++ b/core/core-frontend/src/views/chart/components/editor/editor-style/components/QuadrantSelector.vue @@ -33,14 +33,14 @@ const labels = [] const isDashboard = dvMainStore.dvInfo.type === 'dashboard' for (let i = 0; i < 4; i++) { regionStyle.push({ - fill: isDashboard ? '#fdfcfc' : 'rgb(2,4,8,1)', - fillOpacity: 1 + fill: isDashboard ? '#ffffff' : 'rgb(2,4,8,1,1)', + fillOpacity: '1.0' }) labels.push({ content: '', style: { - fill: isDashboard ? 'rgb(2,4,8,1)' : '#fdfcfc', - fillOpacity: 0.5, + fill: isDashboard ? 'rgb(2,4,8,1,1)' : '#ffffff', + fillOpacity: '0.5', fontSize: 14 } }) @@ -108,6 +108,14 @@ const init = () => { if (customAttr.quadrant) { state.quadrantForm = customAttr.quadrant } else { + // 新增图表 + state.quadrantForm = { + ...JSON.parse(JSON.stringify(DEFAULT_QUADRANT_STYLE)), + regionStyle, + labels + } + state.quadrantForm.xBaseline = undefined + state.quadrantForm.yBaseline = undefined changeStyle() } } @@ -188,8 +196,8 @@ onMounted(() => { style="width: 100%" :effect="props.themes" v-model="state.quadrantForm.xBaseline" - :precision="0" - :min="0" + :precision="2" + :step="0.01" size="small" @change="changeStyle()" /> @@ -205,8 +213,8 @@ onMounted(() => { style="width: 100%" :effect="props.themes" v-model="state.quadrantForm.yBaseline" - :precision="0" - :min="0" + :precision="2" + :step="0.01" size="small" @change="changeStyle()" /> diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/others/quadrant.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/others/quadrant.ts index 815c2b4ec6..bac7a3efed 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/others/quadrant.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/others/quadrant.ts @@ -167,30 +167,16 @@ export class Quadrant extends G2PlotChartView { data.push(tmpData) } // x轴基准线 默认值 - const xBaseline = ( - (data.reduce((valueSoFar, currentItem) => { - return Math.max(valueSoFar, currentItem[xFieldObj.name]) - }, 0) + - data.reduce((valueSoFar, currentItem) => { - return Math.min(valueSoFar, currentItem[xFieldObj.name]) - }, Infinity)) / - 2 - ).toFixed() + const xValues = data.map(item => item[xFieldObj.name]) + const xBaseline = ((Math.max(...xValues) + Math.min(...xValues)) / 2).toFixed() // y轴基准线 默认值 - const yBaseline = ( - (data.reduce((valueSoFar, currentItem) => { - return Math.max(valueSoFar, currentItem[yFieldObj.name]) - }, 0) + - data.reduce((valueSoFar, currentItem) => { - return Math.min(valueSoFar, currentItem[yFieldObj.name]) - }, Infinity)) / - 2 - ).toFixed() + const yValues = data.map(item => item[yFieldObj.name]) + const yBaseline = ((Math.max(...yValues) + Math.min(...yValues)) / 2).toFixed() const defaultBaselineQuadrant = { ...chart.customAttr['quadrant'] } // 新建图表 - if (!defaultBaselineQuadrant.xBaseline) { + if (defaultBaselineQuadrant.xBaseline === undefined) { // 默认基准线值 defaultBaselineQuadrant.xBaseline = xBaseline defaultBaselineQuadrant.yBaseline = yBaseline @@ -215,6 +201,7 @@ export class Quadrant extends G2PlotChartView { const newChart = new G2Scatter(container, options) newChart.on('point:click', action) newChart.on('click', () => quadrantDefaultBaseline(defaultBaselineQuadrant)) + newChart.on('afterrender', () => quadrantDefaultBaseline(defaultBaselineQuadrant)) return newChart }