Commit 83734571 authored by Dorian Goepp's avatar Dorian Goepp

Fix linechart for same field of different topics

There was a bug in the case where the same field was taken frop several topics. The data of each topic would be appended to a single line.
parent 69b2b4e0
......@@ -90,16 +90,17 @@ class RosLineChart extends Component {
* @param {integer} maxPoints mupper limit on the number of data entries for the plot
* @param {Object} message messages from a ROS topic
*/
function process_message(field, maxPoints, message) {
function process_message(curve, maxPoints, message) {
this.setState((state) => {
let new_data = this.state.data;
const field = curve.field;
if (!(field in new_data)) {
new_data[field] = []
}
if (new_data[field].length >= maxPoints) {
new_data[field].shift();
}
new_data[field] = this.state.data[field].concat([{"y": property(field)(message)}])
new_data[curve.topic+field] = this.state.data[field].concat([{"y": property(field)(message)}])
return {
data: new_data,
}
......@@ -111,7 +112,7 @@ class RosLineChart extends Component {
if ('curves' in config) {
config.curves.forEach((curve) => {
const listener = new RosLib.Topic({ros : this.props.ros, name: curve.topic});
listener.subscribe(process_message.bind(this, curve.field, config.maxPoints));
listener.subscribe(process_message.bind(this, curve, config.maxPoints));
this.listeners.push(listener);
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment