Commit 06e82429 authored by leon's avatar leon

feat:normal line use min display count

parent 95565bd4
...@@ -190,23 +190,58 @@ ...@@ -190,23 +190,58 @@
*/ */
switchData(event,count) { switchData(event,count) {
const categories = this.elementData.dataList.datas[this.index].categories const categories = this.elementData.dataList.datas[this.index].categories
// 容错在一个百分点内,认为是滑块滚动 // 容错在拖拽0.5内,认为是滑块滚动
const flag = Math.abs(lastCount - count) <= categories.length / 100 ? true : false const flag = Math.abs(lastCount - count) <= categories.length * 0.5 / 100 ? true : false
if(flag && event.end === 100 && this.index != this.elementData.dataList.datas.length - 1) { if(flag && event.end === 100 && this.index != this.elementData.dataList.datas.length - 1) {
this.index += 1 this.index += 1
this.setChartDatas() this.setChartDatas("next", event)
} }
if(flag && event.start === 0 && this.index != 0) { if(flag && event.start === 0 && this.index != 0) {
this.index -= 1 this.index -= 1
this.setChartDatas() this.setChartDatas("prev", event)
} }
}, },
setChartDatas() { setChartDatas(op, event) {
const categories = this.elementData.dataList.datas[this.index].categories const categories = this.elementData.dataList.datas[this.index].categories
const series = this.elementData.dataList.datas[this.index].series const series = this.elementData.dataList.datas[this.index].series
const dealSeries = this.dealSeriesData(series) const dealSeries = this.dealSeriesData(series)
const count = categories.length * (event.end - event.start) / 100
var flag = false
var start = event.start
var end = event.end
const minCount = 5
// 当整体的数量小于minCount时,全部显示
if(categories <= minCount) {
flag = true
start = 0
end = 100
} else {
// 当切换过来显示的数量小于minCount时,需要更改start和end的值,使显示的数量为最小数量
if(count < minCount) {
// 向后切换
if(op === 'next') {
start = 1
end = parseInt(100 * minCount / categories.length) + start
end = end > 100 ? 100 : end
}
// 向前切换
if(op === 'prev') {
end = 99
start = end - parseInt(100 * minCount / categories.length)
start = start >= 0 ? start : 0
}
flag = true
}
}
if(flag) {
this.$set(this.ec.option, 'dataZoom.start', start)
this.$set(this.ec.option, 'dataZoom.end', end)
}
this.$set(this.ec.option, 'xAxis.data', categories) this.$set(this.ec.option, 'xAxis.data', categories)
this.$set(this.ec.option, 'series', dealSeries) this.$set(this.ec.option, 'series', dealSeries)
this.$set(this.ec.option, 'dataZoom.start', start)
this.$set(this.ec.option, 'dataZoom.end', end)
} }
} }
} }
......
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