|
|
@@ -158,7 +158,11 @@ function _makeIntersectionConfig(id, name, { fixedNsGreen, iconMode = 'default'
|
|
|
*/
|
|
|
function _makePhaseData(cycleLength = 140, isTwoRows = true, iconMode = 'default') {
|
|
|
const n = 4; // 4个阶段 (S1-S4)
|
|
|
- const stageTime = Math.floor(cycleLength / n);
|
|
|
+ // 各阶段按比例分配时间,P1/P3较长,P2/P4较短
|
|
|
+ const ratios = [0.3, 0.2, 0.3, 0.2];
|
|
|
+ const stageTimes = ratios.map(r => Math.floor(cycleLength * r));
|
|
|
+ // 把余数补到第一个阶段,确保总和 = cycleLength
|
|
|
+ stageTimes[0] += cycleLength - stageTimes.reduce((a, b) => a + b, 0);
|
|
|
const pd = [];
|
|
|
|
|
|
// ==========================================
|
|
|
@@ -185,20 +189,22 @@ function _makePhaseData(cycleLength = 140, isTwoRows = true, iconMode = 'default
|
|
|
let t = 0;
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
const stageStart = t;
|
|
|
+ const stageTime = stageTimes[i];
|
|
|
const stageEnd = stageStart + stageTime;
|
|
|
const { icon: stageIcon, direction } = phaseConfig[i];
|
|
|
|
|
|
const pushTrackData = (trackIdx, phaseNamePrefix) => {
|
|
|
const icon = stageIcon;
|
|
|
const phaseName = `${phaseNamePrefix}${i + 1}`;
|
|
|
- const g = Math.floor(Math.random() * 11) + 20; // 绿灯 20-30s
|
|
|
- const s = 3; // 闪烁/条纹 3s
|
|
|
- const y = 2; // 黄灯 2s
|
|
|
+ const s = Math.floor(Math.random() * 3) + 3; // 绿闪/条纹 3-5s
|
|
|
+ const y = 3; // 黄灯固定 3s
|
|
|
+ const r = 2; // 全红间隔 2s
|
|
|
+ const g = stageTime - s - y - r; // 绿灯 = 阶段总时长 - 条纹 - 黄灯 - 红灯
|
|
|
|
|
|
let curT = stageStart;
|
|
|
|
|
|
- // 1. 绿灯 (第6个索引项传入组装好的成对 icon 字符串, 第7个索引项标记方向)
|
|
|
- pd.push([trackIdx, curT, curT + g, phaseName, g, 'green', icon, direction]);
|
|
|
+ // 1. 绿灯 (phase[8]存阶段总时长,用于显示)
|
|
|
+ pd.push([trackIdx, curT, curT + g, phaseName, g, 'green', icon, direction, stageTime]);
|
|
|
curT += g;
|
|
|
// 2. 绿闪/条纹
|
|
|
pd.push([trackIdx, curT, curT + s, '', s, 'stripe', null, direction]);
|
|
|
@@ -206,11 +212,8 @@ function _makePhaseData(cycleLength = 140, isTwoRows = true, iconMode = 'default
|
|
|
// 3. 黄灯
|
|
|
pd.push([trackIdx, curT, curT + y, '', y, 'yellow', null, direction]);
|
|
|
curT += y;
|
|
|
- // 4. 红灯补齐 (确保阶段对齐)
|
|
|
- let remainRed = stageEnd - curT;
|
|
|
- if (remainRed > 0) {
|
|
|
- pd.push([trackIdx, curT, stageEnd, '', remainRed, 'red', null, direction]);
|
|
|
- }
|
|
|
+ // 4. 红灯固定
|
|
|
+ pd.push([trackIdx, curT, curT + r, '', r, 'red', null, direction]);
|
|
|
};
|
|
|
|
|
|
pushTrackData(0, 'P'); // 生成第一排 (P1-P4)
|
|
|
@@ -218,7 +221,7 @@ function _makePhaseData(cycleLength = 140, isTwoRows = true, iconMode = 'default
|
|
|
pushTrackData(1, 'P'); // 生成第二排 (P5-P8,由于逻辑相同,名称可根据需要改为 i+5)
|
|
|
}
|
|
|
|
|
|
- t = stageEnd;
|
|
|
+ t = stageEnd;
|
|
|
}
|
|
|
return pd;
|
|
|
}
|