2021-06-20 13:31:55 +08:00
|
|
|
/**
|
|
|
|
|
* @author 陈劲松
|
|
|
|
|
* @date 2021/6/16
|
|
|
|
|
* @description chart option和一些工具
|
|
|
|
|
*/
|
2021-07-05 22:58:12 +08:00
|
|
|
import { format } from 'echarts'
|
|
|
|
|
import _ from 'lodash'
|
|
|
|
|
|
2021-06-20 13:31:55 +08:00
|
|
|
const line = {
|
|
|
|
|
xAxis: {
|
|
|
|
|
type: 'time'
|
|
|
|
|
},
|
|
|
|
|
yAxis: {
|
|
|
|
|
type: 'value'
|
|
|
|
|
},
|
2021-07-05 22:58:12 +08:00
|
|
|
animation: false,
|
2021-06-20 13:31:55 +08:00
|
|
|
grid: {
|
|
|
|
|
left: 55,
|
|
|
|
|
bottom: 45,
|
|
|
|
|
top: 30
|
|
|
|
|
},
|
|
|
|
|
legend: {
|
|
|
|
|
show: true,
|
|
|
|
|
right: 30,
|
|
|
|
|
top: 'top',
|
|
|
|
|
orient: 'horizontal',
|
|
|
|
|
icon: 'circle',
|
|
|
|
|
itemGap: 20,
|
|
|
|
|
itemWidth: 10,
|
|
|
|
|
textStyle: {
|
|
|
|
|
padding: [0, 0, 0, 5],
|
|
|
|
|
fontSize: 14
|
2021-07-05 22:58:12 +08:00
|
|
|
},
|
|
|
|
|
formatter: tooLongFormatter
|
2021-06-20 13:31:55 +08:00
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
fontSize: 14
|
|
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
2021-06-29 19:45:44 +08:00
|
|
|
name: '',
|
2021-06-20 13:31:55 +08:00
|
|
|
type: 'line',
|
|
|
|
|
smooth: true,
|
|
|
|
|
symbol: 'none',
|
2021-06-29 19:45:44 +08:00
|
|
|
data: []
|
2021-06-20 13:31:55 +08:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2021-07-05 17:40:43 +08:00
|
|
|
const lineWithStatistics = {
|
|
|
|
|
xAxis: {
|
|
|
|
|
type: 'time'
|
|
|
|
|
},
|
2021-07-05 22:58:12 +08:00
|
|
|
animation: false,
|
2021-07-05 17:40:43 +08:00
|
|
|
yAxis: {
|
|
|
|
|
type: 'value'
|
|
|
|
|
},
|
2021-07-05 22:58:12 +08:00
|
|
|
grid: {
|
|
|
|
|
left: 55,
|
|
|
|
|
bottom: 45,
|
|
|
|
|
top: 30
|
|
|
|
|
},
|
2021-07-05 17:40:43 +08:00
|
|
|
legend: {
|
2021-07-05 22:58:12 +08:00
|
|
|
show: false
|
2021-07-05 17:40:43 +08:00
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
fontSize: 14
|
|
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
name: '',
|
|
|
|
|
type: 'line',
|
|
|
|
|
smooth: true,
|
|
|
|
|
symbol: 'none',
|
|
|
|
|
data: []
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2021-06-20 13:31:55 +08:00
|
|
|
const lineStack = {
|
|
|
|
|
xAxis: {
|
|
|
|
|
type: 'time'
|
|
|
|
|
},
|
|
|
|
|
yAxis: {
|
|
|
|
|
type: 'value'
|
|
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
left: 55,
|
|
|
|
|
bottom: 45,
|
|
|
|
|
top: 10,
|
|
|
|
|
right: 180
|
|
|
|
|
},
|
|
|
|
|
legend: {
|
|
|
|
|
show: true,
|
|
|
|
|
right: 30,
|
|
|
|
|
top: 'middle',
|
|
|
|
|
orient: 'vertical',
|
|
|
|
|
icon: 'circle',
|
|
|
|
|
itemGap: 20,
|
|
|
|
|
itemWidth: 10,
|
2021-07-05 22:58:12 +08:00
|
|
|
formatter: tooLongFormatter,
|
2021-06-20 13:31:55 +08:00
|
|
|
textStyle: {
|
|
|
|
|
padding: [0, 0, 0, 5],
|
|
|
|
|
fontSize: 14
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
fontSize: 14
|
|
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
2021-07-05 22:58:12 +08:00
|
|
|
name: '',
|
2021-06-20 13:31:55 +08:00
|
|
|
type: 'line',
|
|
|
|
|
stack: 'value',
|
|
|
|
|
areaStyle: {},
|
|
|
|
|
symbol: 'none',
|
2021-07-05 22:58:12 +08:00
|
|
|
data: []
|
2021-06-20 13:31:55 +08:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2021-06-23 10:41:11 +08:00
|
|
|
const pieWithTable = {
|
|
|
|
|
tooltip: {
|
|
|
|
|
trigger: 'item'
|
|
|
|
|
},
|
2021-07-05 22:58:12 +08:00
|
|
|
animation: false,
|
2021-06-23 10:41:11 +08:00
|
|
|
legend: {
|
|
|
|
|
orient: 'vertical',
|
2021-06-23 15:57:34 +08:00
|
|
|
type: 'plain',
|
2021-07-05 22:58:12 +08:00
|
|
|
left: '60%',
|
|
|
|
|
top: 'middle',
|
2021-06-23 10:41:11 +08:00
|
|
|
icon: 'circle',
|
|
|
|
|
itemWidth: 10, // 设置宽度
|
|
|
|
|
itemHeight: 10, // 设置高度
|
2021-07-05 22:58:12 +08:00
|
|
|
itemGap: 20,
|
|
|
|
|
selectedMode: false,
|
|
|
|
|
formatter: tooLongFormatter
|
2021-06-23 10:41:11 +08:00
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
type: 'pie',
|
2021-06-25 19:11:00 +08:00
|
|
|
radius: ['42%', '70%'],
|
|
|
|
|
center: ['30%', '50%'],
|
|
|
|
|
data: [],
|
2021-07-05 22:58:12 +08:00
|
|
|
label: {
|
|
|
|
|
formatter: '{d}%'
|
|
|
|
|
},
|
2021-06-23 10:41:11 +08:00
|
|
|
emphasis: {
|
|
|
|
|
itemStyle: {
|
|
|
|
|
shadowBlur: 10,
|
|
|
|
|
shadowOffsetX: 0,
|
|
|
|
|
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2021-06-20 13:31:55 +08:00
|
|
|
const typeOptionMappings = [
|
|
|
|
|
{ value: 11, option: line }, // 常规折线图
|
2021-07-05 17:40:43 +08:00
|
|
|
{ value: 12, option: lineWithStatistics }, // 带统计表格的折线图
|
|
|
|
|
{ value: 13, option: lineStack }, // 折线堆叠图
|
2021-07-01 21:39:10 +08:00
|
|
|
{ value: 31, option: pieWithTable } // 常规折线图
|
2021-06-20 13:31:55 +08:00
|
|
|
]
|
|
|
|
|
const typeCategory = {
|
2021-06-24 17:59:51 +08:00
|
|
|
MAP: 'map',
|
2021-06-20 13:31:55 +08:00
|
|
|
TABLE: 'table',
|
|
|
|
|
ECHARTS: 'echarts',
|
|
|
|
|
TITLE: 'title',
|
2021-07-01 21:39:10 +08:00
|
|
|
SINGLE: 'singleValue',
|
|
|
|
|
TABS: 'tabs'
|
2021-06-20 13:31:55 +08:00
|
|
|
}
|
|
|
|
|
export function getTypeCategory (type) {
|
2021-06-24 17:59:51 +08:00
|
|
|
if (isMap(type)) {
|
|
|
|
|
return typeCategory.MAP
|
|
|
|
|
} else if (isEcharts(type)) {
|
2021-06-20 13:31:55 +08:00
|
|
|
return typeCategory.ECHARTS
|
|
|
|
|
} else if (isTable(type)) {
|
|
|
|
|
return typeCategory.TABLE
|
|
|
|
|
} else if (isSingleValue(type)) {
|
|
|
|
|
return typeCategory.SINGLE
|
|
|
|
|
} else if (isTitle(type)) {
|
|
|
|
|
return typeCategory.TITLE
|
2021-07-01 21:39:10 +08:00
|
|
|
} else if (isTabs(type)) {
|
|
|
|
|
return typeCategory.TABS
|
2021-06-20 13:31:55 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* 饼图柱状图等 */
|
|
|
|
|
export function isEcharts (type) {
|
2021-06-24 17:59:51 +08:00
|
|
|
return type >= 11 && type <= 50
|
|
|
|
|
}
|
|
|
|
|
/* 地图 */
|
|
|
|
|
export function isMap (type) {
|
|
|
|
|
return type >= 1 && type <= 10
|
|
|
|
|
}
|
|
|
|
|
/* 连线地图 */
|
|
|
|
|
export function isMapLine (type) {
|
|
|
|
|
return type === 1
|
2021-06-20 13:31:55 +08:00
|
|
|
}
|
|
|
|
|
/* 带统计的折线图 */
|
|
|
|
|
export function isEchartsWithStatistics (type) {
|
|
|
|
|
return type === 12
|
|
|
|
|
}
|
|
|
|
|
/* 单值 */
|
|
|
|
|
export function isSingleValue (type) {
|
|
|
|
|
return type >= 51 && type <= 60
|
|
|
|
|
}
|
|
|
|
|
/* 带折线图的单值 */
|
|
|
|
|
export function isSingleValueWithEcharts (type) {
|
|
|
|
|
return type === 52
|
|
|
|
|
}
|
2021-06-22 21:19:04 +08:00
|
|
|
/* 带Table的饼图 */
|
|
|
|
|
export function isEchartsWithTable (type) {
|
|
|
|
|
return type === 31
|
|
|
|
|
}
|
2021-06-20 13:31:55 +08:00
|
|
|
/* table */
|
|
|
|
|
export function isTable (type) {
|
|
|
|
|
return type >= 61 && type <= 70
|
|
|
|
|
}
|
2021-07-01 21:39:10 +08:00
|
|
|
/* title */
|
2021-06-20 13:31:55 +08:00
|
|
|
export function isTitle (type) {
|
2021-07-01 21:39:10 +08:00
|
|
|
return type === 93
|
|
|
|
|
}
|
|
|
|
|
/* tabs */
|
|
|
|
|
export function isTabs (type) {
|
|
|
|
|
return type === 91
|
2021-06-20 13:31:55 +08:00
|
|
|
}
|
|
|
|
|
export function getOption (type) {
|
|
|
|
|
const mapping = typeOptionMappings.find(m => m.value === type)
|
2021-07-05 22:58:12 +08:00
|
|
|
return mapping && mapping.option ? _.cloneDeep(mapping.option) : null
|
2021-06-20 13:31:55 +08:00
|
|
|
}
|
|
|
|
|
export const layoutConstant = {
|
|
|
|
|
HEADER: 'header',
|
|
|
|
|
FOOTER: 'footer'
|
|
|
|
|
}
|
|
|
|
|
export function getLayout (type) {
|
|
|
|
|
const layout = []
|
|
|
|
|
if (!isSingleValue(type) && !isTitle(type)) {
|
|
|
|
|
layout.push(layoutConstant.HEADER)
|
|
|
|
|
}
|
|
|
|
|
if (type === 12 || type === 31) {
|
|
|
|
|
layout.push(layoutConstant.FOOTER)
|
|
|
|
|
}
|
|
|
|
|
return layout
|
|
|
|
|
}
|
2021-07-05 22:58:12 +08:00
|
|
|
|
|
|
|
|
function tooLongFormatter (name) {
|
|
|
|
|
return format.truncateText(name, 110, '12')
|
|
|
|
|
}
|