From 03a257d44799b3fc5a0dd8ea929c4786e34cc8d9 Mon Sep 17 00:00:00 2001 From: junjun Date: Mon, 9 May 2022 10:21:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BE=85=E5=8A=A9=E7=BA=BF=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=98=BE=E7=A4=BA=E5=90=8D=E7=A7=B0=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E8=B7=9F=E9=9A=8F=E5=9D=90=E6=A0=87=E8=BD=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/chart/chart/common/common.js | 18 +++++- .../views/chart/chart/common/common_antv.js | 55 ++++++++++++++----- 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/frontend/src/views/chart/chart/common/common.js b/frontend/src/views/chart/chart/common/common.js index 632f6aeff4..12257a909c 100644 --- a/frontend/src/views/chart/chart/common/common.js +++ b/frontend/src/views/chart/chart/common/common.js @@ -209,6 +209,14 @@ export function seniorCfg(chart_option, chart) { symbol: 'none', data: [] } + const customStyle = JSON.parse(chart.customStyle) + let xAxis, yAxis + if (customStyle.xAxis) { + xAxis = JSON.parse(JSON.stringify(customStyle.xAxis)) + } + if (customStyle.yAxis) { + yAxis = JSON.parse(JSON.stringify(customStyle.yAxis)) + } senior.assistLine.forEach(ele => { if (chart.type.includes('horizontal')) { chart_option.series[0].markLine.data.push({ @@ -223,7 +231,10 @@ export function seniorCfg(chart_option, chart) { show: true, color: ele.color, fontSize: 10, - position: 'insideStartTop' + position: xAxis.position === 'bottom' ? 'insideStartTop' : 'insideEndTop', + formatter: function(param) { + return ele.name + ' : ' + param.value + } }, tooltip: { show: false @@ -242,7 +253,10 @@ export function seniorCfg(chart_option, chart) { show: true, color: ele.color, fontSize: 10, - position: 'insideStartTop' + position: yAxis.position === 'left' ? 'insideStartTop' : 'insideEndTop', + formatter: function(param) { + return ele.name + ' : ' + param.value + } }, tooltip: { show: false diff --git a/frontend/src/views/chart/chart/common/common_antv.js b/frontend/src/views/chart/chart/common/common_antv.js index d23b76fdb1..731d87c1d6 100644 --- a/frontend/src/views/chart/chart/common/common_antv.js +++ b/frontend/src/views/chart/chart/common/common_antv.js @@ -421,9 +421,9 @@ function transAxisPosition(chart, axis) { if (chart.type.includes('horizontal')) { switch (axis.position) { case 'top': - return 'right' - case 'bottom': return 'left' + case 'bottom': + return 'right' case 'left': return 'bottom' case 'right': @@ -459,7 +459,18 @@ export function getAnalyse(chart) { if (chart.senior && chart.type && (chart.type.includes('bar') || chart.type.includes('line') || chart.type.includes('mix'))) { senior = JSON.parse(chart.senior) if (senior.assistLine && senior.assistLine.length > 0) { + const customStyle = JSON.parse(chart.customStyle) + let xAxisPosition, yAxisPosition + if (customStyle.xAxis) { + const a = JSON.parse(JSON.stringify(customStyle.xAxis)) + xAxisPosition = transAxisPosition(chart, a) + } + if (customStyle.yAxis) { + const a = JSON.parse(JSON.stringify(customStyle.yAxis)) + yAxisPosition = transAxisPosition(chart, a) + } senior.assistLine.forEach(ele => { + const content = ele.name + ' : ' + parseFloat(ele.value) assistLine.push({ type: 'line', start: ['start', parseFloat(ele.value)], @@ -469,18 +480,34 @@ export function getAnalyse(chart) { lineDash: getLineDash(ele.lineType) } }) - assistLine.push({ - type: 'text', - position: ['start', parseFloat(ele.value)], - content: parseFloat(ele.value), - offsetY: -2, - offsetX: 2, - style: { - textBaseline: 'bottom', - fill: ele.color, - fontSize: 10 - } - }) + if (!chart.type.includes('horizontal')) { + assistLine.push({ + type: 'text', + position: [yAxisPosition === 'left' ? 'start' : 'end', parseFloat(ele.value)], + content: content, + offsetY: -2, + offsetX: yAxisPosition === 'left' ? 2 : -10 * (content.length - 2), + style: { + textBaseline: 'bottom', + fill: ele.color, + fontSize: 10 + } + }) + } else { + assistLine.push({ + type: 'text', + position: [xAxisPosition === 'left' ? 'start' : 'end', parseFloat(ele.value)], + content: content, + offsetY: xAxisPosition === 'left' ? -2 : -10 * (content.length - 2), + offsetX: 2, + rotate: Math.PI / 2, + style: { + textBaseline: 'bottom', + fill: ele.color, + fontSize: 10 + } + }) + } }) } }