提交 03a257d4 authored 作者: junjun's avatar junjun

feat: 辅助线增加显示名称同时位置跟随坐标轴

上级 3cb51ed9
...@@ -209,6 +209,14 @@ export function seniorCfg(chart_option, chart) { ...@@ -209,6 +209,14 @@ export function seniorCfg(chart_option, chart) {
symbol: 'none', symbol: 'none',
data: [] 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 => { senior.assistLine.forEach(ele => {
if (chart.type.includes('horizontal')) { if (chart.type.includes('horizontal')) {
chart_option.series[0].markLine.data.push({ chart_option.series[0].markLine.data.push({
...@@ -223,7 +231,10 @@ export function seniorCfg(chart_option, chart) { ...@@ -223,7 +231,10 @@ export function seniorCfg(chart_option, chart) {
show: true, show: true,
color: ele.color, color: ele.color,
fontSize: 10, fontSize: 10,
position: 'insideStartTop' position: xAxis.position === 'bottom' ? 'insideStartTop' : 'insideEndTop',
formatter: function(param) {
return ele.name + ' : ' + param.value
}
}, },
tooltip: { tooltip: {
show: false show: false
...@@ -242,7 +253,10 @@ export function seniorCfg(chart_option, chart) { ...@@ -242,7 +253,10 @@ export function seniorCfg(chart_option, chart) {
show: true, show: true,
color: ele.color, color: ele.color,
fontSize: 10, fontSize: 10,
position: 'insideStartTop' position: yAxis.position === 'left' ? 'insideStartTop' : 'insideEndTop',
formatter: function(param) {
return ele.name + ' : ' + param.value
}
}, },
tooltip: { tooltip: {
show: false show: false
......
...@@ -421,9 +421,9 @@ function transAxisPosition(chart, axis) { ...@@ -421,9 +421,9 @@ function transAxisPosition(chart, axis) {
if (chart.type.includes('horizontal')) { if (chart.type.includes('horizontal')) {
switch (axis.position) { switch (axis.position) {
case 'top': case 'top':
return 'right'
case 'bottom':
return 'left' return 'left'
case 'bottom':
return 'right'
case 'left': case 'left':
return 'bottom' return 'bottom'
case 'right': case 'right':
...@@ -459,7 +459,18 @@ export function getAnalyse(chart) { ...@@ -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'))) { if (chart.senior && chart.type && (chart.type.includes('bar') || chart.type.includes('line') || chart.type.includes('mix'))) {
senior = JSON.parse(chart.senior) senior = JSON.parse(chart.senior)
if (senior.assistLine && senior.assistLine.length > 0) { 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 => { senior.assistLine.forEach(ele => {
const content = ele.name + ' : ' + parseFloat(ele.value)
assistLine.push({ assistLine.push({
type: 'line', type: 'line',
start: ['start', parseFloat(ele.value)], start: ['start', parseFloat(ele.value)],
...@@ -469,18 +480,34 @@ export function getAnalyse(chart) { ...@@ -469,18 +480,34 @@ export function getAnalyse(chart) {
lineDash: getLineDash(ele.lineType) lineDash: getLineDash(ele.lineType)
} }
}) })
assistLine.push({ if (!chart.type.includes('horizontal')) {
type: 'text', assistLine.push({
position: ['start', parseFloat(ele.value)], type: 'text',
content: parseFloat(ele.value), position: [yAxisPosition === 'left' ? 'start' : 'end', parseFloat(ele.value)],
offsetY: -2, content: content,
offsetX: 2, offsetY: -2,
style: { offsetX: yAxisPosition === 'left' ? 2 : -10 * (content.length - 2),
textBaseline: 'bottom', style: {
fill: ele.color, textBaseline: 'bottom',
fontSize: 10 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
}
})
}
}) })
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论