|
|
@@ -72,19 +72,42 @@ export default {
|
|
|
phaseData: { type: Array, default: () => [] },
|
|
|
showAxis: { type: Boolean, default: true },
|
|
|
showScanLine: { type: Boolean, default: true },
|
|
|
- showScanLineLabel: { type: Boolean, default: true }
|
|
|
+ showScanLineLabel: { type: Boolean, default: true },
|
|
|
+ autoScan: { type: Boolean, default: false }
|
|
|
},
|
|
|
data() {
|
|
|
- return { scaleFactor: 1 };
|
|
|
+ return { scaleFactor: 1, internalTime: 0 };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ activeTime() {
|
|
|
+ return this.autoScan ? this.internalTime : this.currentTime;
|
|
|
+ }
|
|
|
},
|
|
|
mounted() {
|
|
|
+ this.internalTime = this.currentTime;
|
|
|
this.initChart();
|
|
|
+ if (this.autoScan) this.startAutoScan();
|
|
|
+ },
|
|
|
+ beforeDestroy() {
|
|
|
+ this.stopAutoScan();
|
|
|
},
|
|
|
watch: {
|
|
|
- currentTime() { if (this.$_chart) this.updateChart(); },
|
|
|
+ currentTime(val) {
|
|
|
+ if (!this.autoScan) {
|
|
|
+ if (this.$_chart) this.updateScanLine();
|
|
|
+ } else {
|
|
|
+ this.internalTime = val;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ autoScan(val) {
|
|
|
+ if (val) { this.startAutoScan(); } else { this.stopAutoScan(); }
|
|
|
+ },
|
|
|
+ showScanLine(val) {
|
|
|
+ this.updateChart();
|
|
|
+ if (val && this.autoScan) { this.startAutoScan(); }
|
|
|
+ },
|
|
|
phaseData: { deep: true, handler(newVal) { if (this.$_chart && newVal.length > 0) this.updateChart(); } },
|
|
|
showAxis() { this.updateChart(); },
|
|
|
- showScanLine() { this.updateChart(); },
|
|
|
showScanLineLabel() { this.updateChart(); }
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -93,6 +116,17 @@ export default {
|
|
|
if (!el) return;
|
|
|
this.scaleFactor = Math.max(0.5, el.clientWidth / 600);
|
|
|
},
|
|
|
+ startAutoScan() {
|
|
|
+ this.stopAutoScan();
|
|
|
+ this._scanTimer = setInterval(() => {
|
|
|
+ const max = this.cycleLength || 140;
|
|
|
+ this.internalTime = this.internalTime >= max ? 0 : this.internalTime + 1;
|
|
|
+ if (this.$_chart) this.updateScanLine();
|
|
|
+ }, 1000);
|
|
|
+ },
|
|
|
+ stopAutoScan() {
|
|
|
+ if (this._scanTimer) { clearInterval(this._scanTimer); this._scanTimer = null; }
|
|
|
+ },
|
|
|
initChart() {
|
|
|
const chartDom = this.$refs.chartRef;
|
|
|
if (!chartDom) return;
|
|
|
@@ -105,6 +139,32 @@ export default {
|
|
|
this.updateScale();
|
|
|
this.$_chart.setOption(this.getChartOption(), true);
|
|
|
},
|
|
|
+ updateScanLine() {
|
|
|
+ if (!this.$_chart) return;
|
|
|
+ this.updateScale();
|
|
|
+ const s = this.scaleFactor;
|
|
|
+ const realMaxTime = this.getMaxTime();
|
|
|
+ this.$_chart.setOption({
|
|
|
+ series: [{
|
|
|
+ markLine: !this.showScanLine ? false : {
|
|
|
+ symbol: ['none', 'none'],
|
|
|
+ silent: true,
|
|
|
+ animation: false,
|
|
|
+ label: {
|
|
|
+ show: this.showScanLineLabel,
|
|
|
+ position: 'start',
|
|
|
+ formatter: `${this.activeTime}/${realMaxTime}`,
|
|
|
+ color: '#fff', backgroundColor: COLORS.MARK_BLUE,
|
|
|
+ padding: [Math.round(4 * s), Math.round(8 * s)],
|
|
|
+ borderRadius: 2, fontSize: Math.max(10, Math.round(10 * s)),
|
|
|
+ offset: [0, Math.round(1 * s)]
|
|
|
+ },
|
|
|
+ lineStyle: { color: COLORS.MARK_BLUE, type: 'solid', width: Math.max(1, Math.round(2 * s)), z: 100 },
|
|
|
+ data: [{ xAxis: this.activeTime }]
|
|
|
+ }
|
|
|
+ }]
|
|
|
+ });
|
|
|
+ },
|
|
|
getMaxTime() {
|
|
|
if (!this.phaseData || this.phaseData.length === 0) return this.cycleLength;
|
|
|
const maxDataTime = Math.max(...this.phaseData.map(item => item[2]));
|
|
|
@@ -135,15 +195,16 @@ export default {
|
|
|
markLine: !this.showScanLine ? false : {
|
|
|
symbol: ['none', 'none'],
|
|
|
silent: true,
|
|
|
+ animation: false,
|
|
|
label: {
|
|
|
- show: this.showScanLineLabel,
|
|
|
- position: 'start', formatter: `${this.currentTime}/${realMaxTime}`,
|
|
|
+ show: this.showScanLineLabel,
|
|
|
+ position: 'start', formatter: `${this.activeTime}/${realMaxTime}`,
|
|
|
color: '#fff', backgroundColor: COLORS.MARK_BLUE, padding: [Math.round(4 * s), Math.round(8 * s)],
|
|
|
- borderRadius: 2, fontSize: Math.max(10, Math.round(10 * s)),
|
|
|
- offset: [0, Math.round(1 * s)]
|
|
|
+ borderRadius: 2, fontSize: Math.max(10, Math.round(10 * s)),
|
|
|
+ offset: [0, Math.round(1 * s)]
|
|
|
},
|
|
|
lineStyle: { color: COLORS.MARK_BLUE, type: 'solid', width: Math.max(1, Math.round(2 * s)), z: 100 },
|
|
|
- data: [ { xAxis: this.currentTime } ]
|
|
|
+ data: [ { xAxis: this.activeTime } ]
|
|
|
}
|
|
|
}]
|
|
|
};
|