refactor(视图): 辅助线数值格式化跟随y轴

This commit is contained in:
junjun 2022-10-11 10:18:21 +08:00
parent c467e26e2a
commit 62fbacf4e3
2 changed files with 24 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import { hexColorToRGBA } from '@/views/chart/chart/util'
import { DEFAULT_YAXIS_EXT_STYLE } from '@/views/chart/chart/chart'
import { DEFAULT_XAXIS_STYLE, DEFAULT_YAXIS_EXT_STYLE, DEFAULT_YAXIS_STYLE } from '@/views/chart/chart/chart'
import { formatterItem, valueFormatter } from '@/views/chart/chart/formatter'
let xAxisLabelFormatter = null
@ -260,7 +260,6 @@ export function seniorCfg(chart_option, chart) {
}
const rgba = hexToRgba(senior.functionCfg.sliderFillBg, 0.2)
chart_option.dataZoom[1].fillerColor = rgba
}
if (senior.functionCfg.sliderTextClolor) {
chart_option.dataZoom[1].textStyle = { color: senior.functionCfg.sliderTextClolor }
@ -285,12 +284,18 @@ export function seniorCfg(chart_option, chart) {
if (senior.assistLine && senior.assistLine.length > 0) {
if (chart_option.series && chart_option.series.length > 0) {
const customStyle = JSON.parse(chart.customStyle)
let xAxis, yAxis
let xAxis, yAxis, axisFormatterCfg
if (customStyle.xAxis) {
xAxis = JSON.parse(JSON.stringify(customStyle.xAxis))
if (chart.type.includes('horizontal')) {
axisFormatterCfg = xAxis.axisLabelFormatter ? xAxis.axisLabelFormatter : DEFAULT_XAXIS_STYLE.axisLabelFormatter
}
}
if (customStyle.yAxis) {
yAxis = JSON.parse(JSON.stringify(customStyle.yAxis))
if (!chart.type.includes('horizontal')) {
axisFormatterCfg = yAxis.axisLabelFormatter ? yAxis.axisLabelFormatter : DEFAULT_YAXIS_STYLE.axisLabelFormatter
}
}
const fixedLines = senior.assistLine.filter(ele => ele.field === '0')
@ -313,7 +318,7 @@ export function seniorCfg(chart_option, chart) {
fontSize: 10,
position: xAxis.position === 'bottom' ? 'insideStartTop' : 'insideEndTop',
formatter: function(param) {
return ele.name + ' : ' + param.value
return ele.name + ' : ' + valueFormatter(param.value, axisFormatterCfg)
}
},
tooltip: {
@ -335,7 +340,7 @@ export function seniorCfg(chart_option, chart) {
fontSize: 10,
position: yAxis.position === 'left' ? 'insideStartTop' : 'insideEndTop',
formatter: function(param) {
return ele.name + ' : ' + param.value
return ele.name + ' : ' + valueFormatter(param.value, axisFormatterCfg)
}
},
tooltip: {

View File

@ -1,5 +1,6 @@
import { hexColorToRGBA } from '@/views/chart/chart/util'
import { formatterItem, valueFormatter } from '@/views/chart/chart/formatter'
import { DEFAULT_XAXIS_STYLE, DEFAULT_YAXIS_STYLE } from '@/views/chart/chart/chart'
export function getPadding(chart) {
if (chart.drill) {
@ -703,14 +704,20 @@ export function getAnalyse(chart) {
senior = JSON.parse(chart.senior)
if (senior.assistLine && senior.assistLine.length > 0) {
const customStyle = JSON.parse(chart.customStyle)
let xAxisPosition, yAxisPosition
let xAxisPosition, yAxisPosition, axisFormatterCfg
if (customStyle.xAxis) {
const a = JSON.parse(JSON.stringify(customStyle.xAxis))
xAxisPosition = transAxisPosition(chart, a)
if (chart.type.includes('horizontal')) {
axisFormatterCfg = a.axisLabelFormatter ? a.axisLabelFormatter : DEFAULT_XAXIS_STYLE.axisLabelFormatter
}
}
if (customStyle.yAxis) {
const a = JSON.parse(JSON.stringify(customStyle.yAxis))
yAxisPosition = transAxisPosition(chart, a)
if (!chart.type.includes('horizontal')) {
axisFormatterCfg = a.axisLabelFormatter ? a.axisLabelFormatter : DEFAULT_YAXIS_STYLE.axisLabelFormatter
}
}
const fixedLines = senior.assistLine.filter(ele => ele.field === '0')
@ -718,11 +725,12 @@ export function getAnalyse(chart) {
const lines = fixedLines.concat(dynamicLines)
lines.forEach(ele => {
const content = ele.name + ' : ' + parseFloat(ele.value)
const value = parseFloat(ele.value)
const content = ele.name + ' : ' + valueFormatter(value, axisFormatterCfg)
assistLine.push({
type: 'line',
start: ['start', parseFloat(ele.value)],
end: ['end', parseFloat(ele.value)],
start: ['start', value],
end: ['end', value],
style: {
stroke: ele.color,
lineDash: getLineDash(ele.lineType)
@ -731,7 +739,7 @@ export function getAnalyse(chart) {
if (!chart.type.includes('horizontal')) {
assistLine.push({
type: 'text',
position: [yAxisPosition === 'left' ? 'start' : 'end', parseFloat(ele.value)],
position: [yAxisPosition === 'left' ? 'start' : 'end', value],
content: content,
offsetY: -2,
offsetX: yAxisPosition === 'left' ? 2 : -10 * (content.length - 2),
@ -744,7 +752,7 @@ export function getAnalyse(chart) {
} else {
assistLine.push({
type: 'text',
position: [xAxisPosition === 'left' ? 'start' : 'end', parseFloat(ele.value)],
position: [xAxisPosition === 'left' ? 'start' : 'end', value],
content: content,
offsetY: xAxisPosition === 'left' ? -2 : -10 * (content.length - 2),
offsetX: 2,