MCPcopy Create free account
hub / github.com/curiores/SerialAnalyzer / updateChart

Method updateChart

src/Components/SerialChart.js:106–203  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

104 };
105
106 updateChart() {
107 // Only update the chart if the chart object exists
108 if (this.chartRef !== null) {
109
110 // Get the reference to the chart object
111 var chart = this.chartRef.current;
112 if (chart !== null) {
113
114 if (SerialDataObject.data.length !== 0 && !SerialDataObject.pauseFlag) {
115 // Get the size of the data
116 var nel = SerialDataObject.data.length;
117 var nvars = SerialDataObject.data[nel - 1].length;
118
119 // Check if there are enough chart data objects
120 var k = chart.data.datasets.length;
121 while (chart.data.datasets.length < nvars) {
122 // Add a new dataset if its too short
123 chart.data.datasets.push(
124 {
125 label: k + 1,
126 color: plotFontColor,
127 data: [],
128 borderColor: colorList[k % colorList.length],
129 backgroundColor: colorList[k % colorList.length],
130 borderWidth: GlobalSettings.global.lineThickness,
131 },
132 )
133 k = k + 1;
134 }
135 while (chart.data.datasets.length > nvars) {
136 // If there are too many, remove the last one.
137 chart.data.datasets.pop();
138 }
139
140 // Line width
141 for (var i = 0; i < chart.data.datasets.length; i++) {
142 chart.data.datasets[i].borderWidth = GlobalSettings.global.lineThickness;
143 chart.data.datasets[i].pointRadius = GlobalSettings.global.pointRadius;
144 }
145
146 // Update with data from the serial port
147 var tnow = SerialDataObject.timeHistory[SerialDataObject.timeHistory.length - 1];
148 var tvec = (SerialDataObject.timeHistory.map((x) => { return 1.0e-3 * (x - tnow) }));
149
150 var step = 1;
151 for (var k = 0; k < nvars; k++) {
152 if (GlobalSettings.timeSeries.estimateTime) {
153
154 chart.data.datasets[k].data = reformatData(tvec, SerialDataObject.data, k, step);
155 }
156 else {
157 chart.data.datasets[k].data = reformatData(SerialDataObject.dataIdx, SerialDataObject.data, k, step);
158 }
159 }
160 }
161
162 // If the settings include automatic resizing, perform that here
163 autoResize();

Callers 1

componentDidMountMethod · 0.95

Calls 2

reformatDataFunction · 0.90
autoResizeFunction · 0.90

Tested by

no test coverage detected