|
21 | 21 | class SignalChart(QWidget): |
22 | 22 | """触发信号图表组件""" |
23 | 23 |
|
24 | | - def __init__(self, max_points: int = 1000): |
| 24 | + def __init__(self, max_points: int = 10000): |
25 | 25 | super().__init__() |
26 | 26 | self.max_points = max_points |
27 | 27 | self.device_names = ["IMU_1", "IMU_2", "CAM_1", "CAM_2", "CAM_3", "CAM_4", "LASER", "GPS"] |
@@ -98,8 +98,8 @@ def create_plot_area(self, parent_layout): |
98 | 98 | self.plot_widget.setYRange(-0.5, len(self.device_names) - 0.5) |
99 | 99 | self.plot_widget.getAxis('left').setTicks([[(i, name) for i, name in enumerate(self.device_names)]]) |
100 | 100 |
|
101 | | - # 启用自动范围调整 |
102 | | - self.plot_widget.enableAutoRange(axis='x') |
| 101 | + # 禁用自动范围调整,使用手动控制 |
| 102 | + self.plot_widget.enableAutoRange(axis='x', enable=False) |
103 | 103 |
|
104 | 104 | parent_layout.addWidget(self.plot_widget, 1) |
105 | 105 |
|
@@ -153,39 +153,48 @@ def add_trigger_event(self, event: TriggerEvent): |
153 | 153 | if device_name in event.triggered_devices: |
154 | 154 | # 设备触发,添加数据点 |
155 | 155 | self.signal_data[device_name].append((current_time, i)) |
156 | | - else: |
157 | | - # 设备未触发,添加空数据点(用于保持时间同步) |
158 | | - self.signal_data[device_name].append(None) |
| 156 | + # 注意:不再为未触发的设备添加None值,这样可以避免数据同步问题 |
159 | 157 |
|
160 | 158 | self.update_plot() |
161 | 159 |
|
162 | 160 | def update_plot(self): |
163 | 161 | """更新图表显示""" |
164 | | - current_time = datetime.now().timestamp() |
| 162 | + if not self.time_data: |
| 163 | + return |
| 164 | + |
| 165 | + # 使用数据中的最新时间作为基准,而不是系统当前时间 |
| 166 | + latest_time = max(self.time_data) |
165 | 167 | time_window = self.time_window_spin.value() |
| 168 | + window_start = latest_time - time_window |
| 169 | + |
| 170 | + # 调试信息 - 可以暂时添加来查看数据状态 |
| 171 | + total_time_points = len(self.time_data) |
| 172 | + print(f"Debug: 总时间点数={total_time_points}, 最新时间={latest_time:.3f}, 窗口起始={window_start:.3f}") |
166 | 173 |
|
167 | 174 | for device_name, scatter in self.plot_items.items(): |
168 | 175 | # 获取设备数据 |
169 | 176 | device_data = self.signal_data[device_name] |
170 | 177 |
|
171 | 178 | # 过滤时间窗口内的数据 |
172 | 179 | valid_points = [] |
| 180 | + total_device_points = len(device_data) |
173 | 181 | for point in device_data: |
174 | | - if point is not None: |
175 | | - timestamp, y_value = point |
176 | | - if current_time - timestamp <= time_window: |
177 | | - valid_points.append([timestamp, y_value]) |
| 182 | + timestamp, y_value = point |
| 183 | + if timestamp >= window_start: |
| 184 | + valid_points.append([timestamp, y_value]) |
| 185 | + |
| 186 | + # 调试信息 |
| 187 | + if total_device_points > 0: |
| 188 | + print(f"设备 {device_name}: 总点数={total_device_points}, 窗口内点数={len(valid_points)}") |
178 | 189 |
|
179 | 190 | if valid_points: |
180 | 191 | valid_points = np.array(valid_points) |
181 | 192 | scatter.setData(valid_points[:, 0], valid_points[:, 1]) |
182 | 193 | else: |
183 | 194 | scatter.setData([], []) |
184 | 195 |
|
185 | | - # 更新X轴范围 |
186 | | - if self.time_data: |
187 | | - latest_time = max(self.time_data) |
188 | | - self.plot_widget.setXRange(latest_time - time_window, latest_time) |
| 196 | + # 更新X轴范围 - 使用数据时间基准 |
| 197 | + self.plot_widget.setXRange(window_start, latest_time) |
189 | 198 |
|
190 | 199 | def highlight_device(self, device_name: str): |
191 | 200 | """高亮显示特定设备""" |
|
0 commit comments