|
@@ -69,13 +69,14 @@ export default {
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
chartInstance: null,
|
|
chartInstance: null,
|
|
|
- followPhase: false
|
|
|
|
|
|
|
+ followPhase: false,
|
|
|
|
|
+ scaleFactor: 1
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
mounted() {
|
|
mounted() {
|
|
|
|
|
+ this.updateScale();
|
|
|
this.initChart();
|
|
this.initChart();
|
|
|
window.addEventListener('resize', this.handleResize);
|
|
window.addEventListener('resize', this.handleResize);
|
|
|
- // 监听容器尺寸变化,自适应 resize(用 rAF 防抖避免循环)
|
|
|
|
|
this._resizePending = false;
|
|
this._resizePending = false;
|
|
|
this._resizeObserver = new ResizeObserver(() => {
|
|
this._resizeObserver = new ResizeObserver(() => {
|
|
|
if (!this._resizePending) {
|
|
if (!this._resizePending) {
|
|
@@ -116,25 +117,35 @@ export default {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
loading(newVal) {
|
|
loading(newVal) {
|
|
|
- // 当 loading 结束时,确保图表进行一次渲染
|
|
|
|
|
|
|
+ // 当 loading 结束时,销毁旧实例并重建,确保使用正确的容器尺寸
|
|
|
if (!newVal && this.phaseData.length > 0) {
|
|
if (!newVal && this.phaseData.length > 0) {
|
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
|
- if (!this.chartInstance) {
|
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ if (this.chartInstance) {
|
|
|
|
|
+ this.chartInstance.dispose();
|
|
|
|
|
+ this.chartInstance = null;
|
|
|
|
|
+ }
|
|
|
this.initChart();
|
|
this.initChart();
|
|
|
- } else {
|
|
|
|
|
- this.chartInstance.resize();
|
|
|
|
|
- }
|
|
|
|
|
- this.updateChart();
|
|
|
|
|
|
|
+ }, 50);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
handleResize() {
|
|
handleResize() {
|
|
|
|
|
+ this.updateScale();
|
|
|
if (this.chartInstance) {
|
|
if (this.chartInstance) {
|
|
|
this.chartInstance.resize();
|
|
this.chartInstance.resize();
|
|
|
|
|
+ this.updateChart();
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
+ updateScale() {
|
|
|
|
|
+ const el = this.$el;
|
|
|
|
|
+ if (!el) return;
|
|
|
|
|
+ const baseWidth = 600; // 设计基准宽度
|
|
|
|
|
+ this.scaleFactor = Math.max(0.5, el.clientWidth / baseWidth);
|
|
|
|
|
+ el.style.setProperty('--s', this.scaleFactor);
|
|
|
|
|
+ },
|
|
|
|
|
|
|
|
initChart() {
|
|
initChart() {
|
|
|
const chartDom = this.$refs.chartDom;
|
|
const chartDom = this.$refs.chartDom;
|
|
@@ -144,6 +155,12 @@ export default {
|
|
|
if (this.phaseData.length > 0) {
|
|
if (this.phaseData.length > 0) {
|
|
|
this.updateChart();
|
|
this.updateChart();
|
|
|
}
|
|
}
|
|
|
|
|
+ // 延迟一帧 resize,确保 v-show 切换后容器有正确宽度
|
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
|
+ requestAnimationFrame(() => {
|
|
|
|
|
+ this.handleResize();
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
updateChart() {
|
|
updateChart() {
|
|
@@ -152,46 +169,48 @@ export default {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
getChartOption() {
|
|
getChartOption() {
|
|
|
|
|
+ const s = this.scaleFactor;
|
|
|
return {
|
|
return {
|
|
|
- backgroundColor: 'transparent',
|
|
|
|
|
- grid: { left: 10, right: 10, top: 50, bottom: 10, containLabel: false },
|
|
|
|
|
- xAxis: { type: 'value', min: 0, max: this.cycleLength, show: false },
|
|
|
|
|
|
|
+ backgroundColor: 'transparent',
|
|
|
|
|
+ grid: { left: Math.round(10 * s), right: Math.round(10 * s), top: Math.round(50 * s), bottom: Math.round(10 * s), containLabel: false },
|
|
|
|
|
+ xAxis: { type: 'value', min: 0, max: this.cycleLength, show: false },
|
|
|
yAxis: { type: 'category', data: ['Track 0', 'Track 1'], inverse: true, show: false },
|
|
yAxis: { type: 'category', data: ['Track 0', 'Track 1'], inverse: true, show: false },
|
|
|
- series: [
|
|
|
|
|
- {
|
|
|
|
|
- type: 'custom',
|
|
|
|
|
- renderItem: this.renderCustomItem,
|
|
|
|
|
- encode: { x: [1, 2], y: 0 },
|
|
|
|
|
- data: this.phaseData,
|
|
|
|
|
- markLine: {
|
|
|
|
|
- symbol: ['none', 'none'],
|
|
|
|
|
- silent: true,
|
|
|
|
|
- label: {
|
|
|
|
|
- show: true,
|
|
|
|
|
- position: 'start',
|
|
|
|
|
- formatter: `${this.currentTime}/${this.cycleLength}`,
|
|
|
|
|
- color: '#fff',
|
|
|
|
|
- backgroundColor: COLORS.MARK_BLUE,
|
|
|
|
|
- padding: [4, 8],
|
|
|
|
|
- borderRadius: 2,
|
|
|
|
|
- fontSize: 12,
|
|
|
|
|
- fontWeight: 'bold',
|
|
|
|
|
- offset: [0, -2]
|
|
|
|
|
- },
|
|
|
|
|
- lineStyle: { color: COLORS.MARK_BLUE, type: 'solid', width: 2 },
|
|
|
|
|
- data: [ { xAxis: this.currentTime } ]
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ series: [
|
|
|
|
|
+ {
|
|
|
|
|
+ type: 'custom',
|
|
|
|
|
+ renderItem: this.renderCustomItem,
|
|
|
|
|
+ encode: { x: [1, 2], y: 0 },
|
|
|
|
|
+ data: this.phaseData,
|
|
|
|
|
+ markLine: {
|
|
|
|
|
+ symbol: ['none', 'none'],
|
|
|
|
|
+ silent: true,
|
|
|
|
|
+ label: {
|
|
|
|
|
+ show: true,
|
|
|
|
|
+ position: 'start',
|
|
|
|
|
+ formatter: `${this.currentTime}/${this.cycleLength}`,
|
|
|
|
|
+ color: '#fff',
|
|
|
|
|
+ backgroundColor: COLORS.MARK_BLUE,
|
|
|
|
|
+ padding: [Math.round(4 * s), Math.round(8 * s)],
|
|
|
|
|
+ borderRadius: 2,
|
|
|
|
|
+ fontSize: Math.round(10 * s),
|
|
|
|
|
+ fontWeight: 'bold',
|
|
|
|
|
+ offset: [0, -2]
|
|
|
|
|
+ },
|
|
|
|
|
+ lineStyle: { color: COLORS.MARK_BLUE, type: 'solid', width: Math.round(2 * s) },
|
|
|
|
|
+ data: [ { xAxis: this.currentTime } ]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
]
|
|
]
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
renderCustomItem(params, api) {
|
|
renderCustomItem(params, api) {
|
|
|
|
|
+ const s = this.scaleFactor;
|
|
|
const trackIndex = api.value(0);
|
|
const trackIndex = api.value(0);
|
|
|
const start = api.coord([api.value(1), trackIndex]);
|
|
const start = api.coord([api.value(1), trackIndex]);
|
|
|
const end = api.coord([api.value(2), trackIndex]);
|
|
const end = api.coord([api.value(2), trackIndex]);
|
|
|
-
|
|
|
|
|
- const blockHeight = api.size([0, 1])[1];
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const blockHeight = api.size([0, 1])[1];
|
|
|
const yPos = start[1] - blockHeight / 2;
|
|
const yPos = start[1] - blockHeight / 2;
|
|
|
const blockWidth = end[0] - start[0];
|
|
const blockWidth = end[0] - start[0];
|
|
|
const dividerY = (api.coord([0, 1])[1] + api.coord([0, 0])[1]) / 2;
|
|
const dividerY = (api.coord([0, 1])[1] + api.coord([0, 0])[1]) / 2;
|
|
@@ -207,26 +226,27 @@ export default {
|
|
|
else if (type === 'red') fillStyle = COLORS.RED;
|
|
else if (type === 'red') fillStyle = COLORS.RED;
|
|
|
|
|
|
|
|
const rectShape = echarts.graphic.clipRectByRect(
|
|
const rectShape = echarts.graphic.clipRectByRect(
|
|
|
- { x: start[0], y: yPos, width: blockWidth, height: blockHeight },
|
|
|
|
|
|
|
+ { x: start[0], y: yPos, width: blockWidth, height: blockHeight },
|
|
|
{ x: params.coordSys.x, y: params.coordSys.y, width: params.coordSys.width, height: params.coordSys.height }
|
|
{ x: params.coordSys.x, y: params.coordSys.y, width: params.coordSys.width, height: params.coordSys.height }
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (!rectShape) return;
|
|
if (!rectShape) return;
|
|
|
const children = [];
|
|
const children = [];
|
|
|
|
|
|
|
|
// A. 绘制刻度
|
|
// A. 绘制刻度
|
|
|
if (params.dataIndex === 0) {
|
|
if (params.dataIndex === 0) {
|
|
|
- const axisBaseY = params.coordSys.y - 20;
|
|
|
|
|
|
|
+ const axisBaseY = params.coordSys.y - Math.round(20 * s);
|
|
|
[0, 35, 70, 105, 140].forEach(val => {
|
|
[0, 35, 70, 105, 140].forEach(val => {
|
|
|
const x = api.coord([val, 0])[0];
|
|
const x = api.coord([val, 0])[0];
|
|
|
- children.push({ type: 'line', shape: { x1: x, y1: axisBaseY - 5, x2: x, y2: axisBaseY + 5 }, style: { stroke: COLORS.AXIS_LINE, lineWidth: 1.5 } });
|
|
|
|
|
|
|
+ children.push({ type: 'line', shape: { x1: x, y1: axisBaseY - Math.round(5 * s), x2: x, y2: axisBaseY + Math.round(5 * s) }, style: { stroke: COLORS.AXIS_LINE, lineWidth: Math.round(1.5 * s) } });
|
|
|
});
|
|
});
|
|
|
const stages = [ {n:'S1', s:0, e:35}, {n:'S2', s:35, e:70}, {n:'S3', s:70, e:105}, {n:'S4', s:105, e:140} ];
|
|
const stages = [ {n:'S1', s:0, e:35}, {n:'S2', s:35, e:70}, {n:'S3', s:70, e:105}, {n:'S4', s:105, e:140} ];
|
|
|
stages.forEach(st => {
|
|
stages.forEach(st => {
|
|
|
const x1 = api.coord([st.s, 0])[0], x2 = api.coord([st.e, 0])[0], midX = (x1 + x2) / 2;
|
|
const x1 = api.coord([st.s, 0])[0], x2 = api.coord([st.e, 0])[0], midX = (x1 + x2) / 2;
|
|
|
- children.push({ type: 'line', shape: { x1: x1, y1: axisBaseY, x2: midX - 14, y2: axisBaseY }, style: { stroke: COLORS.AXIS_LINE, lineWidth: 1.5 } });
|
|
|
|
|
- children.push({ type: 'line', shape: { x1: midX + 14, y1: axisBaseY, x2: x2, y2: axisBaseY }, style: { stroke: COLORS.AXIS_LINE, lineWidth: 1.5 } });
|
|
|
|
|
- children.push({ type: 'text', style: { text: st.n, x: midX, y: axisBaseY, fill: COLORS.TEXT_LIGHT, fontSize: 13, align: 'center', verticalAlign: 'middle', fontWeight: 'bold' } });
|
|
|
|
|
|
|
+ const textHalf = Math.round(14 * s);
|
|
|
|
|
+ children.push({ type: 'line', shape: { x1: x1, y1: axisBaseY, x2: midX - textHalf, y2: axisBaseY }, style: { stroke: COLORS.AXIS_LINE, lineWidth: Math.round(1.5 * s) } });
|
|
|
|
|
+ children.push({ type: 'line', shape: { x1: midX + textHalf, y1: axisBaseY, x2: x2, y2: axisBaseY }, style: { stroke: COLORS.AXIS_LINE, lineWidth: Math.round(1.5 * s) } });
|
|
|
|
|
+ children.push({ type: 'text', style: { text: st.n, x: midX, y: axisBaseY, fill: COLORS.TEXT_LIGHT, fontSize: Math.round(14 * s), align: 'center', verticalAlign: 'middle', fontWeight: 'bold' } });
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -234,18 +254,20 @@ export default {
|
|
|
children.push({ type: 'rect', shape: rectShape, style: { fill: fillStyle, stroke: 'none' } });
|
|
children.push({ type: 'rect', shape: rectShape, style: { fill: fillStyle, stroke: 'none' } });
|
|
|
|
|
|
|
|
// C. 绘制内部元素
|
|
// C. 绘制内部元素
|
|
|
- if (type === 'green' && blockWidth > 25) {
|
|
|
|
|
- const darkWidth = 32;
|
|
|
|
|
- const midY = yPos + blockHeight / 2;
|
|
|
|
|
|
|
+ const fs = Math.max(0.8, s * 0.9); // 文字/图标用更小的缩放
|
|
|
|
|
+ if (type === 'green' && blockWidth > 20) {
|
|
|
|
|
+ const darkWidth = Math.round(25 * fs);
|
|
|
|
|
+ const midY = yPos + blockHeight / 2;
|
|
|
|
|
|
|
|
children.push({ type: 'rect', shape: { x: start[0], y: yPos, width: darkWidth, height: blockHeight }, style: { fill: COLORS.GREEN_DARK } });
|
|
children.push({ type: 'rect', shape: { x: start[0], y: yPos, width: darkWidth, height: blockHeight }, style: { fill: COLORS.GREEN_DARK } });
|
|
|
- children.push({ type: 'polygon', shape: { points: [ [start[0] + darkWidth, midY - 5], [start[0] + darkWidth, midY + 5], [start[0] + darkWidth + 5, midY] ] }, style: { fill: COLORS.GREEN_DARK } });
|
|
|
|
|
|
|
+ const arrowH = Math.round(4 * fs);
|
|
|
|
|
+ children.push({ type: 'polygon', shape: { points: [ [start[0] + darkWidth, midY - arrowH], [start[0] + darkWidth, midY + arrowH], [start[0] + darkWidth + arrowH, midY] ] }, style: { fill: COLORS.GREEN_DARK } });
|
|
|
|
|
|
|
|
if (iconKey && ICON_PATHS[iconKey]) {
|
|
if (iconKey && ICON_PATHS[iconKey]) {
|
|
|
- const iconSize = 20;
|
|
|
|
|
- const iconX = start[0] + (darkWidth - iconSize) / 2;
|
|
|
|
|
- const iconY = midY - iconSize / 2;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ const iconSize = Math.round(14 * fs);
|
|
|
|
|
+ const iconX = start[0] + (darkWidth - iconSize) / 2;
|
|
|
|
|
+ const iconY = midY - iconSize / 2;
|
|
|
|
|
+
|
|
|
children.push({
|
|
children.push({
|
|
|
type: 'path',
|
|
type: 'path',
|
|
|
shape: { pathData: ICON_PATHS[iconKey], x: iconX, y: iconY, width: iconSize, height: iconSize, layout: 'center' },
|
|
shape: { pathData: ICON_PATHS[iconKey], x: iconX, y: iconY, width: iconSize, height: iconSize, layout: 'center' },
|
|
@@ -253,12 +275,13 @@ export default {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- children.push({ type: 'text', style: { text: `${phaseName}\n${duration}`, x: start[0] + darkWidth + 12, y: midY, fill: COLORS.TEXT_DARK, fontSize: 12, fontFamily: 'Arial', fontWeight: 'bold', align: 'left', verticalAlign: 'middle' } });
|
|
|
|
|
|
|
+ // 文字不受 clipRect 裁剪,独立绘制
|
|
|
|
|
+ children.push({ type: 'text', style: { text: `${phaseName}\n${duration}`, x: start[0] + darkWidth + Math.round(4 * fs), y: midY, fill: COLORS.TEXT_DARK, fontSize: Math.round(12 * fs), fontFamily: 'Arial', fontWeight: 'bold', align: 'left', verticalAlign: 'middle' } });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// D. 分割线
|
|
// D. 分割线
|
|
|
if (trackIndex === 1) {
|
|
if (trackIndex === 1) {
|
|
|
- children.push({ type: 'line', shape: { x1: start[0], y1: dividerY, x2: end[0], y2: dividerY }, style: { stroke: COLORS.DIVIDER_LINE, lineWidth: 1.5 } });
|
|
|
|
|
|
|
+ children.push({ type: 'line', shape: { x1: start[0], y1: dividerY, x2: end[0], y2: dividerY }, style: { stroke: COLORS.DIVIDER_LINE, lineWidth: Math.round(1.5 * s) } });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return { type: 'group', children: children };
|
|
return { type: 'group', children: children };
|
|
@@ -269,41 +292,44 @@ export default {
|
|
|
|
|
|
|
|
<style scoped>
|
|
<style scoped>
|
|
|
.signal-timing-widget {
|
|
.signal-timing-widget {
|
|
|
|
|
+ --s: 1;
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
height: 100%;
|
|
height: 100%;
|
|
|
|
|
+ min-width: 0;
|
|
|
background-color: transparent;
|
|
background-color: transparent;
|
|
|
box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
|
position: relative;
|
|
position: relative;
|
|
|
display: flex;
|
|
display: flex;
|
|
|
flex-direction: column;
|
|
flex-direction: column;
|
|
|
|
|
+ overflow: hidden;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
.header {
|
|
.header {
|
|
|
display: flex;
|
|
display: flex;
|
|
|
justify-content: space-between;
|
|
justify-content: space-between;
|
|
|
align-items: center;
|
|
align-items: center;
|
|
|
- margin-bottom: 25px;
|
|
|
|
|
|
|
+ margin-bottom: calc(var(--s) * 25px);
|
|
|
color: #e0e6f1;
|
|
color: #e0e6f1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-.title-area { font-size: 16px; }
|
|
|
|
|
-.main-title { font-size: 20px; font-weight: bold; margin-right: 10px; }
|
|
|
|
|
-.sub-info { font-size: 14px; opacity: 0.8; }
|
|
|
|
|
|
|
+.title-area { font-size: calc(var(--s) * 16px); }
|
|
|
|
|
+.main-title { font-size: calc(var(--s) * 20px); font-weight: bold; margin-right: calc(var(--s) * 10px); }
|
|
|
|
|
+.sub-info { font-size: calc(var(--s) * 14px); opacity: 0.8; }
|
|
|
|
|
|
|
|
.checkbox-area {
|
|
.checkbox-area {
|
|
|
- font-size: 14px; display: flex; align-items: center;
|
|
|
|
|
|
|
+ font-size: calc(var(--s) * 14px); display: flex; align-items: center;
|
|
|
cursor: pointer; opacity: 0.7; user-select: none;
|
|
cursor: pointer; opacity: 0.7; user-select: none;
|
|
|
}
|
|
}
|
|
|
.checkbox-area:hover { opacity: 1; }
|
|
.checkbox-area:hover { opacity: 1; }
|
|
|
|
|
|
|
|
.checkbox-mock {
|
|
.checkbox-mock {
|
|
|
- width: 14px; height: 14px; border: 1px solid rgba(255, 255, 255, 0.5);
|
|
|
|
|
- margin-right: 6px; border-radius: 2px;
|
|
|
|
|
|
|
+ width: calc(var(--s) * 14px); height: calc(var(--s) * 14px); border: 1px solid rgba(255, 255, 255, 0.5);
|
|
|
|
|
+ margin-right: calc(var(--s) * 6px); border-radius: 2px;
|
|
|
display: flex; align-items: center; justify-content: center;
|
|
display: flex; align-items: center; justify-content: center;
|
|
|
}
|
|
}
|
|
|
.checkbox-mock.is-checked { background-color: #4da8ff; border-color: #4da8ff; }
|
|
.checkbox-mock.is-checked { background-color: #4da8ff; border-color: #4da8ff; }
|
|
|
|
|
|
|
|
-.chart-container { width: 100%; flex: 1; min-height: 120px; }
|
|
|
|
|
|
|
+.chart-container { width: 100%; min-width: 0; flex: 1; min-height: 120px; overflow: hidden; }
|
|
|
|
|
|
|
|
.loading-overlay {
|
|
.loading-overlay {
|
|
|
flex: 1; min-height: 120px; display: flex; align-items: center; justify-content: center;
|
|
flex: 1; min-height: 120px; display: flex; align-items: center; justify-content: center;
|