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

Class SerialChart

src/Components/SerialChart.js:96–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94 The chart is updated using references every refreshRate milliseconds.
95*/
96export default class SerialChart extends React.Component {
97
98 constructor(props) {
99 super(props)
100 // This chart reference is needed to update the charts
101 this.divRef = React.createRef();
102 this.chartRef = React.createRef();
103 this.labelRef = React.createRef();
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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected