2021-03-17 13:35:15 +08:00
|
|
|
|
import { createSeriesModel, createMarkLineModels, createMartPoint, createMartPointReverse, hexColor } from './util';
|
2020-12-15 11:18:15 +08:00
|
|
|
|
import store from '@/store/index';
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
2021-03-17 13:35:15 +08:00
|
|
|
|
const defaultConfig = {
|
2021-03-30 11:26:25 +08:00
|
|
|
|
/** 最小时间*/
|
|
|
|
|
minTime: 0,
|
|
|
|
|
/** 最大时间*/
|
|
|
|
|
maxTime: 3600 * 24 - 1,
|
|
|
|
|
/** 边缘高度*/
|
|
|
|
|
edge: 600,
|
|
|
|
|
/** 间隔高度*/
|
|
|
|
|
multiple: 1,
|
|
|
|
|
/** 偏移时间*/
|
|
|
|
|
translation: 0
|
|
|
|
|
};
|
2021-03-17 13:35:15 +08:00
|
|
|
|
|
|
|
|
|
class EqualRatioParser {
|
2021-03-30 11:26:25 +08:00
|
|
|
|
constructor() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 加载配置*/
|
|
|
|
|
load(config = defaultConfig) {
|
|
|
|
|
this.config = config;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 解析excel数据转换为Json后台数据*/
|
|
|
|
|
importData(sheet, data) {
|
|
|
|
|
if (this.config &&
|
2021-03-17 13:35:15 +08:00
|
|
|
|
this.config.importData) {
|
2021-04-08 17:55:35 +08:00
|
|
|
|
return this.config.importData(sheet, data);
|
2021-03-30 11:26:25 +08:00
|
|
|
|
} else {
|
|
|
|
|
console.info('no import data function');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 将后台数据解析成图表*/
|
|
|
|
|
convertDataToModels(data, stations, kmRangeMap, lineStyle) {
|
2019-12-26 14:48:11 +08:00
|
|
|
|
var models = [];
|
|
|
|
|
if (data && data.serviceNumberDataList && data.serviceNumberDataList.length) {
|
|
|
|
|
/** 按服务遍历数据*/
|
|
|
|
|
data.serviceNumberDataList.forEach((service) => {
|
|
|
|
|
/** 按车次遍历数据*/
|
|
|
|
|
var opt = { name: '', markPointData: [], data: [] };
|
|
|
|
|
if (service.tripNumberDataList && service.tripNumberDataList.length) {
|
|
|
|
|
service.tripNumberDataList.forEach((train, j) => {
|
|
|
|
|
var pointdata = {};
|
|
|
|
|
var idx = 0;
|
|
|
|
|
var num = 0;
|
|
|
|
|
var lastPoint = null;
|
|
|
|
|
var nextPoint = null;
|
|
|
|
|
|
|
|
|
|
/** 如果车次号为空,不显示名称*/
|
|
|
|
|
if (train.tripNumber) {
|
|
|
|
|
/** 创建标记点名称和坐标*/
|
2020-08-31 13:25:26 +08:00
|
|
|
|
// pointdata.name = `${service.serviceNumber}${train.directionCode}${train.tripNumber}`;
|
|
|
|
|
pointdata.name = `${service.serviceNumber}${train.tripNumber}`;
|
2019-12-26 14:48:11 +08:00
|
|
|
|
pointdata.color = '#000' || lineStyle.color;
|
2020-11-06 11:04:38 +08:00
|
|
|
|
pointdata.directionCode = train.right ? '2' : '1';
|
|
|
|
|
if (!store.state.map.mapConfig.upRight) {
|
|
|
|
|
pointdata.directionCode = train.right ? '1' : '2';
|
|
|
|
|
}
|
2021-03-17 13:35:15 +08:00
|
|
|
|
pointdata.coord = [train.stationTimeList[1].secondTime, this.getCoordYByElem(stations, kmRangeMap, train.stationTimeList[1], pointdata.directionCode, false)];
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
|
|
|
|
/** 给服务对象添加服务名称和标记点*/
|
2021-03-17 13:35:15 +08:00
|
|
|
|
opt.markPointData.push(this.__createMartPoint(pointdata));
|
2019-12-26 14:48:11 +08:00
|
|
|
|
/** 创建服务号名称*/
|
|
|
|
|
opt.name = `${service.serviceNumber}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 计算非折返点车次点坐标集合*/
|
|
|
|
|
train.stationTimeList.forEach((elem, index) => {
|
|
|
|
|
idx = index;
|
2021-03-15 17:32:12 +08:00
|
|
|
|
// if (index == 0 && train.stationTimeList[index].stationCode != train.stationTimeList[index + 1].stationCode ||
|
|
|
|
|
// index == train.stationTimeList.length - 2 && train.stationTimeList[index].secondTime != train.stationTimeList[index + 1].secondTime ||
|
|
|
|
|
// index > 0 && index < train.stationTimeList.length - 1) {
|
2021-03-30 11:26:25 +08:00
|
|
|
|
const aa = `${train.tripNumber}`;
|
|
|
|
|
opt.data.push([elem.secondTime, this.getCoordYByElem(stations, kmRangeMap, elem, pointdata.directionCode, false), elem.stationCode, aa]);
|
2021-03-15 17:32:12 +08:00
|
|
|
|
// }
|
2019-12-26 14:48:11 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/** 计算折返点车次坐标点集合*/
|
|
|
|
|
if (!train.backup && train.reentry && service.tripNumberDataList[j + 1] && service.tripNumberDataList[j + 1].stationTimeList) {
|
2021-03-30 11:26:25 +08:00
|
|
|
|
const currentTimeList = service.tripNumberDataList[j].stationTimeList;
|
|
|
|
|
const nextTimeList = service.tripNumberDataList[j + 1].stationTimeList;
|
|
|
|
|
if (currentTimeList[currentTimeList.length - 1].secondTime != nextTimeList[0].secondTime) {
|
|
|
|
|
lastPoint = train.stationTimeList[train.stationTimeList.length - 1];
|
|
|
|
|
nextPoint = service.tripNumberDataList[j + 1].stationTimeList[0];
|
|
|
|
|
num = this.computedReentryNumber(train.tripNumber);
|
|
|
|
|
const aa = `${train.tripNumber}`;
|
|
|
|
|
opt.data.push([lastPoint.secondTime, this.getCoordYByElem(stations, kmRangeMap, lastPoint, pointdata.directionCode, true, num), lastPoint.stationCode, aa]);
|
|
|
|
|
opt.data.push([nextPoint.secondTime, this.getCoordYByElem(stations, kmRangeMap, nextPoint, pointdata.directionCode, true, num), nextPoint.stationCode, aa]);
|
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 如果是备用车,按车次添加线*/
|
|
|
|
|
if (train.backup) {
|
|
|
|
|
/** 创建一条完成的服务数据*/
|
2021-02-22 10:13:14 +08:00
|
|
|
|
// opt.name += j;
|
|
|
|
|
const length = opt.name.length;
|
|
|
|
|
const optName = parseInt(opt.name) + j;
|
|
|
|
|
opt.name = optName.toString().padStart(length, '0');
|
2021-03-17 13:35:15 +08:00
|
|
|
|
var model = this.__createSeriesModel(opt, Object.assign({ color: hexColor.toCreate() }, lineStyle));
|
2019-12-26 14:48:11 +08:00
|
|
|
|
if (model) {
|
|
|
|
|
models.push(model);
|
|
|
|
|
opt = { name: '', markPointData: [], data: [] };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 不是备用车,按服务添加线
|
|
|
|
|
if (!service.backup) {
|
|
|
|
|
/** 创建一条完成的服务数据*/
|
2021-03-17 13:35:15 +08:00
|
|
|
|
var model = this.__createSeriesModel(opt, Object.assign({ color: hexColor.toCreate() }, lineStyle));
|
2019-12-26 14:48:11 +08:00
|
|
|
|
if (model) {
|
|
|
|
|
models.push(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return models;
|
|
|
|
|
} else {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2021-03-17 13:35:15 +08:00
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
|
|
|
|
/** 更新数据并解析成图表*/
|
2021-03-17 13:35:15 +08:00
|
|
|
|
updateDataToModels(data, stations, kmRangeMap, runPlanData, series, lineStyle) {
|
2019-12-26 14:48:11 +08:00
|
|
|
|
if (data && data.length) {
|
|
|
|
|
data.forEach(elem => {
|
|
|
|
|
/** 判断此条记录的服务号是否存在*/
|
|
|
|
|
if (!runPlanData[elem.serviceNumber]) {
|
|
|
|
|
/** 创建一个新服务号标记*/
|
|
|
|
|
runPlanData[elem.serviceNumber] = {};
|
|
|
|
|
/** 不存在此服务号,则需要创建一条新的line*/
|
2021-03-17 13:35:15 +08:00
|
|
|
|
series.push(this.__createSeriesModel({
|
2019-12-26 14:48:11 +08:00
|
|
|
|
zlevel: 1,
|
|
|
|
|
name: `run${elem.serviceNumber}`,
|
|
|
|
|
data: [],
|
|
|
|
|
markPointData: []
|
|
|
|
|
}, Object.assign({ color: hexColor.toCreate() }, lineStyle)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 添加数据*/
|
|
|
|
|
series.forEach(serie => {
|
|
|
|
|
/** 找到服务号所在图数据的位置*/
|
|
|
|
|
if (serie.name == `run${elem.serviceNumber}`) {
|
|
|
|
|
/** 添加车组号记录标记*/
|
|
|
|
|
if (!runPlanData[elem.serviceNumber][elem.tripNumber]) {
|
|
|
|
|
runPlanData[elem.serviceNumber][elem.tripNumber] = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runPlanData[elem.serviceNumber][elem.tripNumber].push(elem);
|
|
|
|
|
runPlanData[elem.serviceNumber][elem.tripNumber].sort((a, b) => {
|
|
|
|
|
return parseInt(a.secondTime) - parseInt(b.secondTime);
|
|
|
|
|
});
|
2021-01-28 16:12:10 +08:00
|
|
|
|
let directionCode = elem.right ? '2' : '1';
|
|
|
|
|
if (!store.state.map.mapConfig.upRight) {
|
|
|
|
|
directionCode = elem.right ? '1' : '2';
|
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
/** 如果此记录车组号的数据为第一条时,则打上标签*/
|
|
|
|
|
if (runPlanData[elem.serviceNumber][elem.tripNumber].length <= 1) {
|
2020-08-28 11:30:55 +08:00
|
|
|
|
const result = serie.markPoint.data.some(ele => ele.name == `(${elem.groupNumber})${elem.serviceNumber}${elem.tripNumber}`);
|
|
|
|
|
if (!result) {
|
2021-03-17 13:35:15 +08:00
|
|
|
|
serie.markPoint.data.push(this.__createMartPoint({
|
2020-11-06 11:04:38 +08:00
|
|
|
|
directionCode: directionCode,
|
2021-03-17 13:35:15 +08:00
|
|
|
|
coord: [parseInt(elem.secondTime), this.getCoordYByElem(stations, kmRangeMap, elem, false)],
|
2020-08-31 13:25:26 +08:00
|
|
|
|
name: `(${elem.groupNumber})${elem.serviceNumber}${elem.tripNumber}`,
|
2020-08-28 11:30:55 +08:00
|
|
|
|
color: lineStyle.color || '#000'
|
|
|
|
|
}));
|
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 计算折返点*/
|
2021-03-17 13:35:15 +08:00
|
|
|
|
var nextPoint = [parseInt(elem.secondTime), this.getCoordYByElem(stations, kmRangeMap, elem, false), directionCode];
|
2019-12-26 14:48:11 +08:00
|
|
|
|
if (serie.data.length > 0) {
|
|
|
|
|
var lastPoint = serie.data[serie.data.length - 1];
|
|
|
|
|
if (lastPoint[2] !== nextPoint[2]) {
|
|
|
|
|
var num = this.computedReentryNumber(elem.tripNumber);
|
2021-03-17 13:35:15 +08:00
|
|
|
|
serie.data.push([lastPoint[0], this.getValueYByDirectionCode(lastPoint[1], lastPoint[2], num), lastPoint[2]]);
|
|
|
|
|
serie.data.push([nextPoint[0], this.getValueYByDirectionCode(nextPoint[1], lastPoint[2], num), lastPoint[2]]);
|
2019-12-26 14:48:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 添加车组号数据到对应的服务图数据中*/
|
|
|
|
|
serie.data.push(nextPoint);
|
|
|
|
|
|
|
|
|
|
/** 保证原始数据排序*/
|
|
|
|
|
serie.data.sort((a, b) => {
|
|
|
|
|
return parseInt(a[0]) - parseInt(b[0]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return series;
|
2021-03-17 13:35:15 +08:00
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
|
|
|
|
/** 初始化Y轴*/
|
2021-03-17 13:35:15 +08:00
|
|
|
|
initializeAxisY(stations) {
|
|
|
|
|
return this.__createMarkLineModels(stations, (elem) => {
|
2021-03-19 10:10:51 +08:00
|
|
|
|
return this.getEdge() + elem.kmRange * this.getMultiple();
|
2019-12-26 14:48:11 +08:00
|
|
|
|
});
|
2021-03-17 13:35:15 +08:00
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
2021-03-17 13:35:15 +08:00
|
|
|
|
getAxisYValueByStation(station, index) {
|
2021-03-19 10:10:51 +08:00
|
|
|
|
return this.getEdge() + station.kmRange * this.getMultiple();
|
2021-03-17 13:35:15 +08:00
|
|
|
|
}
|
2020-11-19 09:40:03 +08:00
|
|
|
|
|
2019-12-26 14:48:11 +08:00
|
|
|
|
/** 将后台数据转换为试图序列模型*/
|
|
|
|
|
convertStationsToMap(stations) {
|
|
|
|
|
var map = {};
|
|
|
|
|
if (stations && stations.length) {
|
2020-11-19 09:40:03 +08:00
|
|
|
|
stations.forEach((elem, index) => {
|
2021-03-17 13:35:15 +08:00
|
|
|
|
map[`${elem.kmRange}`] = this.getAxisYValueByStation(elem, index);
|
2019-12-26 14:48:11 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return map;
|
2021-03-17 13:35:15 +08:00
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
|
|
|
|
/** 计算y轴最小值*/
|
2021-03-17 13:35:15 +08:00
|
|
|
|
computedAxisYMinValue(stations) {
|
2021-03-19 10:10:51 +08:00
|
|
|
|
return stations[0].kmRange * this.getMultiple();
|
2021-03-17 13:35:15 +08:00
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
|
|
|
|
/** 计算y轴最大值*/
|
2021-03-17 13:35:15 +08:00
|
|
|
|
computedAxisYMaxValue(stations) {
|
2021-03-19 10:10:51 +08:00
|
|
|
|
return stations[stations.length - 1].kmRange * this.getMultiple() + this.getEdge() * 2;
|
2021-03-17 13:35:15 +08:00
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
|
|
|
|
/** 格式化y轴数据*/
|
2021-03-17 13:35:15 +08:00
|
|
|
|
computedFormatAxisY(stations, params) {
|
2020-01-07 14:49:51 +08:00
|
|
|
|
var yText = '0m';
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
|
|
|
|
stations.forEach(elem => {
|
2021-03-19 10:10:51 +08:00
|
|
|
|
if (elem.kmRange < parseInt(params.value) / this.getMultiple() - this.getEdge()) {
|
2020-01-07 14:49:51 +08:00
|
|
|
|
yText = Math.floor(elem.kmRange) + 'm';
|
2019-12-26 14:48:11 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return yText;
|
2021-03-17 13:35:15 +08:00
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
|
|
|
|
/** 根据是否和上一个车次是否相交,计算下一个车次的折返的高度*/
|
|
|
|
|
computedReentryNumber(code) {
|
2020-08-28 14:29:59 +08:00
|
|
|
|
return 1;
|
2021-03-17 13:35:15 +08:00
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
|
|
|
|
/** 根据方向计算y折返偏移量*/
|
2021-03-17 13:35:15 +08:00
|
|
|
|
getValueYByDirectionCode(defaultValue, directionCode, num) {
|
2021-03-30 11:26:25 +08:00
|
|
|
|
const sign = this.getReverse() ? -1 : 1;
|
2019-12-26 14:48:11 +08:00
|
|
|
|
if (directionCode === '1') {
|
2021-03-19 10:52:57 +08:00
|
|
|
|
defaultValue -= sign * this.getEdge() / 2 * num;
|
2019-12-26 14:48:11 +08:00
|
|
|
|
} else if (directionCode === '2') {
|
2021-03-19 10:52:57 +08:00
|
|
|
|
defaultValue += sign * this.getEdge() / 2 * num;
|
2019-12-26 14:48:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 13:35:15 +08:00
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
2019-12-26 14:48:11 +08:00
|
|
|
|
|
|
|
|
|
/** 根据elem计算y值*/
|
2021-03-17 13:35:15 +08:00
|
|
|
|
getCoordYByElem(stations, kmRangeMap, elem, directionCode, isSpecial, num) {
|
|
|
|
|
var defaultValue = 0;
|
2019-12-26 14:48:11 +08:00
|
|
|
|
var station = stations.find(it => { return it.code == elem.stationCode; });
|
|
|
|
|
if (station) {
|
2021-03-17 13:35:15 +08:00
|
|
|
|
defaultValue = kmRangeMap[`${station.kmRange}`];
|
2019-12-26 14:48:11 +08:00
|
|
|
|
if (isSpecial) {
|
2021-03-17 13:35:15 +08:00
|
|
|
|
defaultValue = this.getValueYByDirectionCode(defaultValue, directionCode, num);
|
2019-12-26 14:48:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 13:35:15 +08:00
|
|
|
|
return defaultValue;
|
2019-12-26 14:48:11 +08:00
|
|
|
|
}
|
2021-03-17 13:35:15 +08:00
|
|
|
|
|
2021-03-30 11:26:25 +08:00
|
|
|
|
getMultiple() {
|
|
|
|
|
return this.config.multiple;
|
|
|
|
|
}
|
2021-03-19 10:10:51 +08:00
|
|
|
|
|
2021-03-30 11:26:25 +08:00
|
|
|
|
getTranslation() {
|
|
|
|
|
return this.config.translation;
|
|
|
|
|
}
|
2021-03-19 10:10:51 +08:00
|
|
|
|
|
2021-03-30 11:26:25 +08:00
|
|
|
|
getEdge() {
|
|
|
|
|
return this.config.edge;
|
|
|
|
|
}
|
2021-03-19 10:10:51 +08:00
|
|
|
|
|
2021-03-30 11:26:25 +08:00
|
|
|
|
getReverse() {
|
|
|
|
|
return this.config.reverse;
|
|
|
|
|
}
|
2021-03-19 10:52:57 +08:00
|
|
|
|
|
2021-03-30 11:26:25 +08:00
|
|
|
|
__createMartPoint(...args) {
|
|
|
|
|
return this.config.reverse ? createMartPointReverse(...args) : createMartPoint(...args);
|
|
|
|
|
}
|
2021-03-17 13:35:15 +08:00
|
|
|
|
|
2021-03-30 11:26:25 +08:00
|
|
|
|
__createSeriesModel(...args) {
|
|
|
|
|
return createSeriesModel(...args);
|
|
|
|
|
}
|
2021-03-17 13:35:15 +08:00
|
|
|
|
|
2021-03-30 11:26:25 +08:00
|
|
|
|
__createMarkLineModels(...args) {
|
|
|
|
|
return createMarkLineModels(...args);
|
|
|
|
|
}
|
2021-03-17 13:35:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default EqualRatioParser;
|