()
| 197 | }; |
| 198 | |
| 199 | updateChart(){ |
| 200 | if(this.chartRef !== null ){ |
| 201 | // Get the reference to the chart object |
| 202 | var chart = this.chartRef.current; |
| 203 | |
| 204 | if(chart !== null ){ |
| 205 | if(SerialDataObject.data.length !== 0 && !SerialDataObject.pauseFlag){ |
| 206 | // Get the size of the data |
| 207 | var nel = SerialDataObject.data.length; |
| 208 | var nvars = SerialDataObject.data[nel-1].length; |
| 209 | |
| 210 | // Check if there are enough chart data objects |
| 211 | var k = chart.data.datasets.length; |
| 212 | while(chart.data.datasets.length < nvars ){ |
| 213 | // Add a new dataset if its too short |
| 214 | chart.data.datasets.push( |
| 215 | { |
| 216 | label: (k+1) , |
| 217 | color: plotFontColor, |
| 218 | data: [], |
| 219 | borderColor: colorList[k % colorList.length], |
| 220 | backgroundColor: colorList[k % colorList.length], |
| 221 | borderWidth: GlobalSettings.global.lineThickness, |
| 222 | }, |
| 223 | ) |
| 224 | k = k + 1; |
| 225 | } |
| 226 | while(chart.data.datasets.length > nvars ){ |
| 227 | // If there are too many, remove the last one. |
| 228 | chart.data.datasets.pop(); |
| 229 | } |
| 230 | |
| 231 | // Line width |
| 232 | for (var i = 0; i < chart.data.datasets.length; i++){ |
| 233 | chart.data.datasets[i].borderWidth = GlobalSettings.global.lineThickness; |
| 234 | chart.data.datasets[i].pointRadius = GlobalSettings.global.pointRadius; |
| 235 | } |
| 236 | |
| 237 | // Compute the sample rate |
| 238 | var sampleRate = SerialDataObject.sampleRate; |
| 239 | if(GlobalSettings.spectrum.useFixedSampleRate){ |
| 240 | sampleRate = GlobalSettings.spectrum.sampleRate; |
| 241 | } |
| 242 | else{ |
| 243 | GlobalSettings.spectrum.sampleRate = sampleRate; |
| 244 | } |
| 245 | |
| 246 | // Update with data from the serial port |
| 247 | var magMax = 0; |
| 248 | var magMin = 0; |
| 249 | for(var k = 0; k < nvars; k++){ |
| 250 | var s = createSpectrum(SerialDataObject.dataIdx,SerialDataObject.data,k,sampleRate); |
| 251 | if(k===0){ |
| 252 | magMax = Math.max(...s.mag); |
| 253 | magMin = Math.min(...s.mag); |
| 254 | } |
| 255 | else{ |
| 256 | magMax = Math.max(magMax,Math.max(...s.mag)); |
no test coverage detected