Commit 130b70ef authored by leon's avatar leon

feat: charts support x y double axis

parent 6c97a118
...@@ -71,11 +71,8 @@ ...@@ -71,11 +71,8 @@
let options = { let options = {
...this.elementInfo.option, ...this.elementInfo.option,
tooltip: {}, tooltip: {},
xAxis: this.$u.common.dealAxisFormatter(this.elementInfo.option.xAxis), yAxis: that.$u.common.dealXAxis({...this.elementInfo.option.yAxis}, this.dealSeriesData(series)),
yAxis: { xAxis: that.$u.common.dealYAxis({...this.elementInfo.option.xAxis}),
...this.$u.common.dealAxisFormatter(this.elementInfo.option.yAxis),
data: this.dealSeriesData(series).categories
},
dataZoom: this.elementInfo.dataZoom && this.elementInfo.dataZoom.show ? [{...this.elementInfo.dataZoom,...DATAZOOM_DEFAULT}] : [{show: false}], dataZoom: this.elementInfo.dataZoom && this.elementInfo.dataZoom.show ? [{...this.elementInfo.dataZoom,...DATAZOOM_DEFAULT}] : [{show: false}],
series: { series: {
id: 'associate', id: 'associate',
......
...@@ -51,11 +51,8 @@ export default { ...@@ -51,11 +51,8 @@ export default {
const that = this const that = this
that.ec.option = { that.ec.option = {
...that.elementInfo.option, ...that.elementInfo.option,
xAxis: that.$u.common.dealAxisFormatter(that.elementInfo.option.xAxis), yAxis: that.$u.common.dealXAxis({...that.elementInfo.option.yAxis}, that.elementData.dataList),
yAxis: { xAxis: that.$u.common.dealYAxis({...that.elementInfo.option.xAxis}),
...that.$u.common.dealAxisFormatter(that.elementInfo.option.yAxis),
data: categories
},
tooltip: that.$u.common.dealTooltip(that.elementInfo.option.tooltip), tooltip: that.$u.common.dealTooltip(that.elementInfo.option.tooltip),
dataZoom: dataZoom:
that.elementInfo.dataZoom && that.elementInfo.dataZoom.show that.elementInfo.dataZoom && that.elementInfo.dataZoom.show
...@@ -222,8 +219,8 @@ export default { ...@@ -222,8 +219,8 @@ export default {
} }
} }
return { return {
...item, ...config,
...config ...item
} }
}) })
return newData return newData
......
...@@ -48,23 +48,10 @@ ...@@ -48,23 +48,10 @@
canvas.setChart(chart) canvas.setChart(chart)
const {categories, series} = this.elementData.dataList const {categories, series} = this.elementData.dataList
const that = this const that = this
let yAxis = [
that.$u.common.dealAxisFormatter({ ...that.elementInfo.option.yAxis, type: 'value' }),
that.$u.common.dealAxisFormatter({ ...that.elementInfo.option.yAxis, type: 'value' })
]
if (that.elementInfo.option.yAxis.showDouble) {
yAxis = [
that.$u.common.dealAxisFormatter({ ...that.elementInfo.option.yAxis, type: 'value' }),
that.$u.common.dealAxisFormatter({ ...that.elementInfo.option.yAxis, ...that.elementInfo.option.yAxis.second, type: 'value' })
]
}
that.ec.option = { that.ec.option = {
...that.elementInfo.option, ...that.elementInfo.option,
xAxis: { xAxis: that.$u.common.dealXAxis({...that.elementInfo.option.xAxis}, that.elementData.dataList),
...that.$u.common.dealAxisFormatter(that.elementInfo.option.xAxis), yAxis: that.$u.common.dealYAxis({...that.elementInfo.option.yAxis, type: 'value'}),
data: categories
},
yAxis: yAxis,
tooltip: that.$u.common.dealTooltip(that.elementInfo.option.tooltip), tooltip: that.$u.common.dealTooltip(that.elementInfo.option.tooltip),
toolbox: { toolbox: {
...that.elementInfo.option.toolbox, ...that.elementInfo.option.toolbox,
...@@ -180,18 +167,14 @@ ...@@ -180,18 +167,14 @@
} }
} else if (item.type === 'line') { } else if (item.type === 'line') {
config = { config = {
yAxisIndex: 1,
...config, ...config,
...that.elementInfo.option.line, ...that.elementInfo.option.line,
...itemStyle ...itemStyle
} }
} }
return { return { ...config, ...item}
...item, })
...config return that.$u.common.dealAxisIndex(newData, that.elementInfo)
}
})
return newData
}, },
/** /**
* 响应dataZoom的滑动事件 * 响应dataZoom的滑动事件
......
...@@ -43,20 +43,10 @@ ...@@ -43,20 +43,10 @@
canvas.setChart(chart) canvas.setChart(chart)
const { categories, series } = this.elementData.dataList const { categories, series } = this.elementData.dataList
const that = this const that = this
var yAxis = that.$u.common.dealAxisFormatter({...that.elementInfo.option.yAxis})
if (yAxis.showDouble) {
yAxis = [
that.$u.common.dealAxisFormatter({ ...that.elementInfo.option.yAxis}),
that.$u.common.dealAxisFormatter({ ...that.elementInfo.option.yAxis, ...that.elementInfo.option.yAxis.second })
]
}
that.ec.option = { that.ec.option = {
...that.elementInfo.option, ...that.elementInfo.option,
xAxis: { xAxis: that.$u.common.dealXAxis({...that.elementInfo.option.xAxis}, that.elementData.dataList),
...that.$u.common.dealAxisFormatter(that.elementInfo.option.xAxis), yAxis: that.$u.common.dealYAxis({...that.elementInfo.option.yAxis}),
data: categories
},
yAxis: yAxis,
tooltip: that.$u.common.dealTooltip(that.elementInfo.option.tooltip), tooltip: that.$u.common.dealTooltip(that.elementInfo.option.tooltip),
toolbox: { toolbox: {
...that.elementInfo.option.toolbox, ...that.elementInfo.option.toolbox,
...@@ -157,16 +147,9 @@ ...@@ -157,16 +147,9 @@
} }
} }
} }
if (that.elementInfo.option.yAxis.showDouble) { return { ...config, ...item}
const yAxisIndex = data.length - 1 === index ? 1 : 0 })
return { ...item, ...config, yAxisIndex: yAxisIndex} return that.$u.common.dealAxisIndex(newData, that.elementInfo)
}
return {
...item,
...config
}
})
return newData
}, },
/** /**
* 响应dataZoom的滑动事件 * 响应dataZoom的滑动事件
......
...@@ -42,20 +42,10 @@ ...@@ -42,20 +42,10 @@
canvas.setChart(chart) canvas.setChart(chart)
const { categories = [], series = [] } = this.elementData.dataList const { categories = [], series = [] } = this.elementData.dataList
const that = this const that = this
var yAxis = that.$u.common.dealAxisFormatter({...that.elementInfo.option.yAxis})
if (yAxis.showDouble) {
yAxis = [
that.$u.common.dealAxisFormatter({ ...that.elementInfo.option.yAxis}),
that.$u.common.dealAxisFormatter({ ...that.elementInfo.option.yAxis, ...that.elementInfo.option.yAxis.second})
]
}
that.ec.option = { that.ec.option = {
...that.elementInfo.option, ...that.elementInfo.option,
xAxis: { xAxis: that.$u.common.dealXAxis({...that.elementInfo.option.xAxis}, that.elementData.dataList),
...that.$u.common.dealAxisFormatter(that.elementInfo.option.xAxis), yAxis: that.$u.common.dealYAxis({...that.elementInfo.option.yAxis}),
data: categories
},
yAxis: yAxis,
tooltip: that.$u.common.dealTooltip(that.elementInfo.option.tooltip), tooltip: that.$u.common.dealTooltip(that.elementInfo.option.tooltip),
toolbox: { toolbox: {
...that.elementInfo.option.toolbox, ...that.elementInfo.option.toolbox,
...@@ -158,16 +148,9 @@ ...@@ -158,16 +148,9 @@
}, },
} }
} }
if (that.elementInfo.option.yAxis.showDouble) { return { ...config, ...item}
const yAxisIndex = data.length - 1 === index ? 1 : 0 })
return { ...item, ...config, yAxisIndex: yAxisIndex} return that.$u.common.dealAxisIndex(newData, that.elementInfo)
}
return {
...item,
...config
}
})
return newData
}, },
/** /**
* 响应dataZoom的滑动事件 * 响应dataZoom的滑动事件
......
...@@ -240,30 +240,33 @@ const install = (Vue, vm) => { ...@@ -240,30 +240,33 @@ const install = (Vue, vm) => {
const dealTooltip = (tooltip) => { const dealTooltip = (tooltip) => {
if (!tooltip) { if (!tooltip) {
return return
} }
tooltip = { tooltip = {
...tooltip, ...tooltip,
position(point, params, dom, rect, size) { position(point, params, dom, rect, size) {
let x = point[0]; let x = point[0];
let y = point[1]; let y = point[1];
const { contentSize, viewSize } = size; const {
const maxX = viewSize[0] - contentSize[0]; contentSize,
if (x > maxX) { viewSize
x -= contentSize[0]; } = size;
} const maxX = viewSize[0] - contentSize[0];
const maxY = viewSize[1] - contentSize[1]; if (x > maxX) {
if (y > maxY) { x -= contentSize[0];
y -= contentSize[1]; }
} const maxY = viewSize[1] - contentSize[1];
if(y < 0) { if (y > maxY) {
y = 0 y -= contentSize[1];
} }
return [x, y]; if (y < 0) {
} y = 0
} }
return [x, y];
}
}
if (tooltip.formatter && tooltip.formatter.length) { if (tooltip.formatter && tooltip.formatter.length) {
return { return {
...tooltip, ...tooltip,
formatter: (val) => { formatter: (val) => {
return converFunction(tooltip.formatter, val) return converFunction(tooltip.formatter, val)
}, },
...@@ -275,6 +278,69 @@ const install = (Vue, vm) => { ...@@ -275,6 +278,69 @@ const install = (Vue, vm) => {
trigger: "axis" trigger: "axis"
} }
} }
/**
*
* @param axis 表单的yAxis设置
*/
const dealYAxis = (axis) => {
if (!axis) {
return
}
if (axis.showDouble) {
return [
dealAxisFormatter({
...axis
}),
dealAxisFormatter({
...axis,
...axis.second
})
]
}
return dealAxisFormatter({
...axis
})
}
/**
*
* @param axis 表单的xAxis设置
*/
const dealXAxis = (axis, dataList) => {
if (!axis) {
return
}
if (!dataList) {
return
}
const categories = dataList.categories
if (axis.showDouble) {
let data = categories
if (dataList.secondCategories) {
data = dataList.secondCategories
}
return [{
...dealAxisFormatter({
...axis
}),
data: categories
},
{
...dealAxisFormatter({
...axis,
...axis.second
}),
data: data
}
]
}
return {
...dealAxisFormatter({
...axis
}),
data: categories
}
}
/** /**
* *
...@@ -296,27 +362,65 @@ const install = (Vue, vm) => { ...@@ -296,27 +362,65 @@ const install = (Vue, vm) => {
} }
} }
return axis return axis
} }
/** const dealAxisIndex = (datas, elementInfo) => {
* 图层关系关联 子组件获取到folderId const yShowDouble = elementInfo.option.yAxis.showDouble
* @param {elements} let yflag = false
*/ const xShowDouble = elementInfo.option.xAxis.showDouble
const elementFolderId = (elements) => { let xflag = false
elements.forEach(element => { const newData = datas.map((item, index) => {
if (element.type === 'folder') { let yAxisIndex = 0
element.child.data.forEach(item => { if (yShowDouble) {
const index = elements.findIndex(ele => ele.id === item) if (item.yAxisIndex) {
if(index != -1) { yAxisIndex = item.yAxisIndex
elements[index].folderId = element.id yflag = true
elements[index].isChild = true }
// 打开双轴的情况下,没有设置yAxisIndex的,默认数组最后的用右轴
} if (datas.length > 1 && datas.length - 1 === index && !yflag) {
}) yAxisIndex = 1
} }
}) }
return elements let xAxisIndex = 0
} if (xShowDouble) {
if (item.xAxisIndex) {
xAxisIndex = item.xAxisIndex
xflag = true
}
// 打开双轴的情况下,没有设置xAxisIndex的,默认数组最后的用顶轴
if (datas.length > 1 && datas.length - 1 === index && !xflag) {
xAxisIndex = 1
}
}
return {
...item,
yAxisIndex: yAxisIndex,
xAxisIndex: xAxisIndex
}
})
return newData
}
/**
* 图层关系关联 子组件获取到folderId
* @param {elements}
*/
const elementFolderId = (elements) => {
elements.forEach(element => {
if (element.type === 'folder') {
element.child.data.forEach(item => {
const index = elements.findIndex(ele => ele.id === item)
if (index != -1) {
elements[index].folderId = element.id
elements[index].isChild = true
}
})
}
})
return elements
}
vm.$u.common = { vm.$u.common = {
converFunction, converFunction,
...@@ -328,8 +432,10 @@ const install = (Vue, vm) => { ...@@ -328,8 +432,10 @@ const install = (Vue, vm) => {
chunk, chunk,
getQueryFromString, getQueryFromString,
filterRequestParams, filterRequestParams,
dealTooltip, dealTooltip,
dealAxisFormatter, dealXAxis,
dealYAxis,
dealAxisIndex,
elementFolderId elementFolderId
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment