This commit is contained in:
joylink_cuiweidong 2021-05-10 13:50:55 +08:00
commit d0ce678ca0
6 changed files with 538 additions and 23 deletions

View File

@ -2,7 +2,7 @@ import { prefixTime, convertSheetToList } from '../parser/util';
export default { export default {
/** 运行图解析方式*/ /** 运行图解析方式*/
type: 'Distance', type: 'InversionDistance',
/** 边缘高度*/ /** 边缘高度*/
edge: 3, edge: 3,

View File

@ -0,0 +1,292 @@
import { createMartPoint, createMartPointReverse, createSeriesModel, createInversionMarkLineModels, hexColor } from './util';
import store from '@/store/index';
const defaultConfig = {
/** 边缘高度*/
edge: 3,
/** 间隔高度*/
multiple: 3,
/** 偏移时间*/
translation: 60 * 60 * 2
};
class EqualDistanceParser {
constructor() {
}
/** 加载配置*/
load(config = defaultConfig) {
this.config = config;
this.multiple = config.multiple;
this.translation = config.translation;
this.edge = config.edge;
return this;
}
/** 解析excel数据转换为Json后台数据*/
importData(sheet, data) {
if (this.config &&
this.config.importData) {
this.config.importData(sheet, data);
} else {
console.info('no import data function');
}
}
/** 将后台数据解析成图表*/
convertDataToModels(data, stations, kmRangeMap, lineStyle) {
var models = [];
if (data && data.serviceNumberDataList && data.serviceNumberDataList.length) {
/** 按服务遍历数据*/
data.serviceNumberDataList.forEach((service) => {
/** 按车次遍历数据*/
var isBackup = true;
var opt = { name: '', markPointData: [], data: [] };
if (service.tripNumberDataList && service.tripNumberDataList.length) {
service.tripNumberDataList.forEach((train, j) => {
var pointdata = {};
var idx = 0;
var lastPoint = null;
var nextPoint = null;
/** 创建标记点名称和坐标*/
// pointdata.name = `${service.serviceNumber}${train.directionCode}${train.tripNumber}`;
pointdata.name = `${service.serviceNumber}${train.tripNumber}`;
pointdata.color = '#000' || lineStyle.color;
pointdata.directionCode = train.right ? '2' : '1';
if (!store.state.map.mapConfig.upRight) {
pointdata.directionCode = train.right ? '1' : '2';
}
pointdata.coord = [this.getCoordXByElem(stations, kmRangeMap, train.stationTimeList[0], pointdata.directionCode, false), train.stationTimeList[0].secondTime];
/** 给服务对象添加服务名称和标记点*/
opt.name = '' + service.serviceNumber;
opt.markPointData.push(this.__createMartPoint(pointdata));
/** 计算非折返点车次点坐标集合*/
train.stationTimeList.forEach((elem, index) => {
idx = index;
// ${train.directionCode}
const aa = `${train.tripNumber}`;
opt.data.push([this.getCoordXByElem(stations, kmRangeMap, elem, pointdata.directionCode, false), elem.secondTime, elem.stationCode, aa]);
});
/** 计算折返点车次坐标点集合*/
if (!train.backup && train.reentry && service.tripNumberDataList[j + 1] && service.tripNumberDataList[j + 1].stationTimeList) {
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[idx];
nextPoint = service.tripNumberDataList[j + 1].stationTimeList[0];
// ${train.directionCode}
const aa = `${train.tripNumber}`;
opt.data.push([this.getCoordXByElem(stations, kmRangeMap, lastPoint, pointdata.directionCode, true), lastPoint.secondTime, lastPoint.stationCode, aa, '折返轨']);
opt.data.push([this.getCoordXByElem(stations, kmRangeMap, lastPoint, pointdata.directionCode, true), nextPoint.secondTime, lastPoint.stationCode, aa, '折返轨']);
}
}
/** 如果是备用车,按车次添加线*/
if (train.backup) {
/** 创建一条完成的服务数据*/
// opt.name += j;
const length = opt.name.length;
const optName = parseInt(opt.name) + j;
opt.name = optName.toString().padStart(length, '0');
var model = this.__createSeriesModel(opt, Object.assign({ color: '#000' }, lineStyle));
if (model) {
models.push(model);
opt = { name: '', markPointData: [], data: [] };
}
}
isBackup = train.backup;
});
// 不是备用车,按服务添加线
if (!isBackup) {
/** 创建一条完成的服务数据*/
var model = this.__createSeriesModel(opt, Object.assign({ color: '#000' }, lineStyle));
if (model) {
models.push(model);
}
}
}
});
return models;
} else {
return [];
}
}
/** 更新数据并解析成图表*/
updateDataToModels(data, stations, kmRangeMap, runPlanData, series, lineStyle) {
if (data && data.length) {
data.forEach(elem => {
/** 判断此条记录的服务号是否存在*/
if (!runPlanData[elem.serviceNumber]) {
/** 创建一个新服务号标记*/
runPlanData[elem.serviceNumber] = {};
/** 不存在此服务号则需要创建一条新的line*/
series.push(this.__createSeriesModel({
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);
});
let directionCode = elem.right ? '2' : '1';
if (!store.state.map.mapConfig.upRight) {
directionCode = elem.right ? '1' : '2';
}
/** 如果此记录车组号的数据为第一条时,则打上标签*/
if (runPlanData[elem.serviceNumber][elem.tripNumber].length <= 1) {
const result = serie.markPoint.data.some(ele => ele.name == `(${elem.groupNumber})${elem.serviceNumber}${elem.tripNumber}`);
if (!result) {
serie.markPoint.data.push(this.__createMartPoint({
directionCode: directionCode,
coord: [this.getCoordXByElem(stations, kmRangeMap, elem), parseInt(elem.secondTime)],
name: `(${elem.groupNumber})${elem.serviceNumber}${elem.tripNumber}`,
color: lineStyle.color || '#000'
}));
}
}
/** 计算折返点*/
var nextPoint = [this.getCoordXByElem(stations, kmRangeMap, elem), parseInt(elem.secondTime), directionCode];
if (serie.data.length > 0) {
var lastPoint = serie.data[serie.data.length - 1];
if (lastPoint[2] !== nextPoint[2]) {
serie.data.push([this.getValueXByDirectionCode(lastPoint[0], lastPoint[2]), lastPoint[1], lastPoint[2]]);
serie.data.push([this.getValueXByDirectionCode(nextPoint[0], lastPoint[2]), nextPoint[1], lastPoint[2]]);
}
}
/** 添加车组号数据到对应的服务图数据中*/
serie.data.push(nextPoint);
/** 保证原始数据排序*/
// serie.data.sort((a, b) => {
// return parseInt(a[1]) - parseInt(b[1]);
// });
}
});
});
}
return series;
}
getAxisXValueByStation(station, index) {
return this.getEdge() + index * this.getMultiple();
}
/** 将后台数据转换为试图序列模型*/
convertStationsToMap(stations) {
var map = {};
if (stations && stations.length) {
stations.forEach((elem, index) => {
map[`${elem.kmRange}`] = this.getAxisXValueByStation(elem, index);
});
}
return map;
}
/** 初始化X轴*/
initializeAxisX(stations) {
return this.__createMarkLineModels(stations, (elem, index) => {
return this.getEdge() + index * this.getMultiple();
});
}
/** 计算X轴最小值*/
computedAxisXMinValue(stations) {
return 0;
}
/** 计算X轴最大值*/
computedAxisXMaxValue(stations) {
return this.getEdge() * 2 + (stations.length - 1) * this.getMultiple();
}
/** 格式化y轴数据*/
computedFormatAxisY(stations, params) {
var yText = '0m';
var index = Math.floor((parseInt(params.value) - this.getEdge()) / this.getMultiple());
if (index >= 0 && index < stations.length) {
yText = Math.floor(stations[index].kmRange) + 'm';
}
return yText;
}
/** 根据方向计算x折返偏移量*/
getValueXByDirectionCode(defaultValue, directionCode) {
const sign = this.getReverse() ? -1 : 1;
if (directionCode === '1') {
defaultValue -= sign * this.getEdge() / 2;
} else if (directionCode === '2') {
defaultValue += sign * this.getEdge() / 2;
}
return defaultValue;
}
/** 根据elem计算X值*/
getCoordXByElem(stations, kmRangeMap, elem, directionCode, isSpecial) {
var defaultValue = 0;
var station = stations.find(it => { return it.code == elem.stationCode; });
if (station) {
defaultValue = kmRangeMap[`${station.kmRange}`];
if (isSpecial) {
defaultValue = this.getValueXByDirectionCode(defaultValue, directionCode);
}
}
return defaultValue;
}
getMultiple() {
return this.config.multiple;
}
getTranslation() {
return this.config.translation;
}
getEdge() {
return this.config.edge;
}
getReverse() {
return this.config.reverse;
}
__createMartPoint(...args) {
return this.config.reverse ? createMartPointReverse(...args) : createMartPoint(...args);
}
__createSeriesModel(...args) {
return createSeriesModel(...args);
}
__createMarkLineModels(...args) {
return createInversionMarkLineModels(...args);
}
}
export default EqualDistanceParser;

View File

@ -1,14 +1,16 @@
import AUSToolParser from './AUSToolParser'; import AUSToolParser from './AUSToolParser';
import EqualDistanceParser from './EqualDistanceParser'; import EqualDistanceParser from './EqualDistanceParser';
import EqualRatioParser from './EqualRatioParser'; import EqualRatioParser from './EqualRatioParser';
import InversionEqualDistanceParser from './InversionEqualDistanceParser';
class PlanParser { class PlanParser {
constructor() { constructor() {
this.parserMap = { this.parserMap = {
AUS: new AUSToolParser(), AUS: new AUSToolParser(),
Distance: new EqualDistanceParser(), Distance: new EqualDistanceParser(),
Ratio: new EqualRatioParser() Ratio: new EqualRatioParser(),
} InversionDistance: new InversionEqualDistanceParser()
};
} }
load(config) { load(config) {
@ -16,4 +18,4 @@ class PlanParser {
} }
} }
export default new PlanParser() export default new PlanParser();

View File

@ -95,6 +95,40 @@ export function createMarkLineModels(stations, computedAxisY, opt = {}) {
} }
return markLineModel; return markLineModel;
} }
/** 创建标记横线*/
export function createInversionMarkLineModels(stations, computedAxisY, opt = {}) {
const markLineModel = {};
if (stations && stations.length) {
markLineModel.type = 'line';
markLineModel.name = 'markline';
markLineModel.markLine = {};
markLineModel.markLine.silent = true;
markLineModel.markLine.data = [];
markLineModel.markLine.lineStyle = { color: '#B0C4DE', width: 0.5 };
markLineModel.markLine.symbol = 'none';
markLineModel.elements = [];
Object.assign(markLineModel, opt);
stations.forEach((elem, index) => {
markLineModel.markLine.data.push(
{
label: {
show: true,
position: 'start',
formatter: elem.name,
color: 'black'
},
lineStyle: {
type: 'solid',
width: 0.5,
opacity: 0.5
},
xAxis: computedAxisY(elem, index)
}
);
});
}
return markLineModel;
}
/** 创建不会重复颜色的内部对象*/ /** 创建不会重复颜色的内部对象*/
export const hexColor = { export const hexColor = {

View File

@ -255,7 +255,11 @@ export default {
const stations = this.$store.state.runPlan.stations; const stations = this.$store.state.runPlan.stations;
const planData = this.$store.state.runPlan.planData; const planData = this.$store.state.runPlan.planData;
this.kmRangeMap = this.PlanParser.convertStationsToMap(stations); this.kmRangeMap = this.PlanParser.convertStationsToMap(stations);
if (this.$route.query.lineCode === '07') {
this.pushModels(this.staticSeries, [this.PlanParser.initializeAxisX(stations)]);
} else {
this.pushModels(this.staticSeries, [this.PlanParser.initializeAxisY(stations)]); this.pushModels(this.staticSeries, [this.PlanParser.initializeAxisY(stations)]);
}
this.staticSeries = this.pushModels(this.staticSeries, this.PlanParser.convertDataToModels(planData, stations, this.kmRangeMap, { color: '#000', width: 0.5 })); this.staticSeries = this.pushModels(this.staticSeries, this.PlanParser.convertDataToModels(planData, stations, this.kmRangeMap, { color: '#000', width: 0.5 }));
this.staticSeries.forEach(item => { this.staticSeries.forEach(item => {
this.seriesMap[item.name] = item; this.seriesMap[item.name] = item;
@ -361,6 +365,89 @@ export default {
] ]
}; };
const hebXAxis = {
type: 'value',
splitLine: {
show: false
},
axisTick: {
show: false
},
axisLine: {
onZero: false,
lineStyle: {
width: 2,
color: '#d14a61'
}
},
axisLabel: {
interval: 'auto',
formatter: this.yAxisLableFormat
},
axisPointer: {
xAxisIndex: 'all',
label: {
formatter: this.yAxisPointFormat,
backgroundColor: 'rgb(0,100,0,0.5)',
color: 'white'
}
},
min: 0,
max: 0
};
const hebYAxis = [
{
type: 'category',
boundaryGap: false,
data: [],
axisLine: {
onZero: false,
lineStyle: {
width: 2,
color: '#d14a61'
}
},
axisLabel: {
formatter: this.xAxisLableFormat,
textStyle: {
color: '#333'
}
},
axisPointer: {
snap: true,
label: {
formatter: this.xAxisPointFormat,
backgroundColor: 'rgb(255,0,0,0.5)',
color: 'white'
}
}
}
];
const hebDataZoom = [
{
type: 'inside',
yAxisIndex: 0
},
{
fiterMode: 'filter',
handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
handleSize: '80%',
yAxisIndex: 0,
handleStyle: {
color: '#fff',
shadowBlur: 3,
shadowColor: 'rgba(0, 0, 0, 0.6)',
shadowOffsetX: 2,
shadowOffsetY: 2
},
left: '20px'
}
];
if (this.$route.query.lineCode === '07') {
option.xAxis = hebXAxis;
option.yAxis = hebYAxis;
option.dataZoom = hebDataZoom;
}
await this.xAxisInit(option); await this.xAxisInit(option);
await this.yAxisInit(option); await this.yAxisInit(option);
await this.loadInitChart(option); await this.loadInitChart(option);
@ -419,7 +506,11 @@ export default {
const startValue = 3600 * 6; const startValue = 3600 * 6;
const offsetTime = 3600 * 1; const offsetTime = 3600 * 1;
if (this.$route.query.lineCode === '07') {
option.yAxis[0].data = list;
} else {
option.xAxis[0].data = list; option.xAxis[0].data = list;
}
if (!option.dataZoom[0].startValue) { if (!option.dataZoom[0].startValue) {
option.dataZoom[0].startValue = option.dataZoom[1].startValue = startValue - offsetTime; option.dataZoom[0].startValue = option.dataZoom[1].startValue = startValue - offsetTime;
} }
@ -429,9 +520,12 @@ export default {
} }
}, },
yAxisInit(option) { yAxisInit(option) {
if (Object.keys(this.PlanParser).length) { if (Object.keys(this.PlanParser).length && this.$route.query.lineCode !== '07') {
option.yAxis[0].min = this.PlanParser.computedAxisYMinValue(this.stations); option.yAxis.min = this.PlanParser.computedAxisYMinValue(this.stations);
option.yAxis[0].max = this.PlanParser.computedAxisYMaxValue(this.stations); option.yAxis.max = this.PlanParser.computedAxisYMaxValue(this.stations);
} else if (Object.keys(this.PlanParser).length && this.$route.query.lineCode === '07') {
option.xAxis.min = this.PlanParser.computedAxisXMinValue(this.stations);
option.xAxis.max = this.PlanParser.computedAxisXMaxValue(this.stations);
} }
}, },
axisTooltip(param) { axisTooltip(param) {

View File

@ -194,7 +194,11 @@ export default {
const stations = this.$store.state.runPlan.stations; const stations = this.$store.state.runPlan.stations;
const planData = this.$store.state.runPlan.planData; const planData = this.$store.state.runPlan.planData;
this.kmRangeMap = this.PlanParser.convertStationsToMap(stations); this.kmRangeMap = this.PlanParser.convertStationsToMap(stations);
if (this.$route.query.lineCode === '07') {
series = this.pushModels(series, [this.PlanParser.initializeAxisX(stations)]);
} else {
series = this.pushModels(series, [this.PlanParser.initializeAxisY(stations)]); series = this.pushModels(series, [this.PlanParser.initializeAxisY(stations)]);
}
series = this.pushModels(series, this.PlanParser.convertDataToModels(planData, stations, this.kmRangeMap, { color: '#000', width: 0.5 })); series = this.pushModels(series, this.PlanParser.convertDataToModels(planData, stations, this.kmRangeMap, { color: '#000', width: 0.5 }));
await this.loadInitData(series); await this.loadInitData(series);
await this.analyticalServiceNumber(this.$store.state.runPlan.editData); await this.analyticalServiceNumber(this.$store.state.runPlan.editData);
@ -304,6 +308,89 @@ export default {
} }
] ]
}; };
const hebXAxis = {
type: 'value',
splitLine: {
show: false
},
axisTick: {
show: false
},
axisLine: {
onZero: false,
lineStyle: {
width: 2,
color: '#d14a61'
}
},
axisLabel: {
interval: 'auto',
formatter: this.yAxisLableFormat
},
axisPointer: {
xAxisIndex: 'all',
label: {
formatter: this.yAxisPointFormat,
backgroundColor: 'rgb(0,100,0,0.5)',
color: 'white'
}
},
min: 0,
max: 0
};
const hebYAxis = [
{
type: 'category',
boundaryGap: false,
data: [],
axisLine: {
onZero: false,
lineStyle: {
width: 2,
color: '#d14a61'
}
},
axisLabel: {
formatter: this.xAxisLableFormat,
textStyle: {
color: '#333'
}
},
axisPointer: {
snap: true,
label: {
formatter: this.xAxisPointFormat,
backgroundColor: 'rgb(255,0,0,0.5)',
color: 'white'
}
}
}
];
const hebDataZoom = [
{
type: 'inside',
yAxisIndex: 0
},
{
fiterMode: 'filter',
handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
handleSize: '80%',
yAxisIndex: 0,
handleStyle: {
color: '#fff',
shadowBlur: 3,
shadowColor: 'rgba(0, 0, 0, 0.6)',
shadowOffsetX: 2,
shadowOffsetY: 2
},
left: '20px'
}
];
if (this.$route.query.lineCode === '07') {
option.xAxis = hebXAxis;
option.yAxis = hebYAxis;
option.dataZoom = hebDataZoom;
}
await this.xAxisInit(option); await this.xAxisInit(option);
await this.yAxisInit(option); await this.yAxisInit(option);
await this.loadInitChart(series, option); await this.loadInitChart(series, option);
@ -378,8 +465,11 @@ export default {
const startValue = 3600 * 6; const startValue = 3600 * 6;
const offsetTime = 3600 * 1; const offsetTime = 3600 * 1;
if (this.$route.query.lineCode === '07') {
option.yAxis[0].data = list;
} else {
option.xAxis[0].data = list; option.xAxis[0].data = list;
}
if (!option.dataZoom[0].startValue) { if (!option.dataZoom[0].startValue) {
option.dataZoom[0].startValue = option.dataZoom[1].startValue = startValue - offsetTime; option.dataZoom[0].startValue = option.dataZoom[1].startValue = startValue - offsetTime;
} }
@ -389,9 +479,12 @@ export default {
} }
}, },
yAxisInit(option) { yAxisInit(option) {
if (Object.keys(this.PlanParser).length) { if (Object.keys(this.PlanParser).length && this.$route.query.lineCode !== '07') {
option.yAxis.min = this.PlanParser.computedAxisYMinValue(this.stations); option.yAxis.min = this.PlanParser.computedAxisYMinValue(this.stations);
option.yAxis.max = this.PlanParser.computedAxisYMaxValue(this.stations); option.yAxis.max = this.PlanParser.computedAxisYMaxValue(this.stations);
} else if (Object.keys(this.PlanParser).length && this.$route.query.lineCode === '07') {
option.xAxis.min = this.PlanParser.computedAxisXMinValue(this.stations);
option.xAxis.max = this.PlanParser.computedAxisXMaxValue(this.stations);
} }
}, },
axisTooltip(param) { axisTooltip(param) {