From 0b453ae5346304826faef59f138fa652958e7e41 Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Sun, 9 Feb 2020 15:02:25 +0100 Subject: [PATCH] preliminary change to support #244 (#247) --- plotter_gui/transforms/custom_function.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plotter_gui/transforms/custom_function.cpp b/plotter_gui/transforms/custom_function.cpp index 2c1b3170b..c0c6a1a9a 100644 --- a/plotter_gui/transforms/custom_function.cpp +++ b/plotter_gui/transforms/custom_function.cpp @@ -152,7 +152,22 @@ PlotData::Point CustomFunction::calculatePoint(QJSValue& calcFct, { throw std::runtime_error("JS Engine : " + jsData.toString().toStdString()); } - new_point.y = jsData.toNumber(); + + if( jsData.isArray() ) + { + const int length = jsData.property("length").toInt(); + if( length == 2 ) + { + new_point.x = jsData.property(0).toNumber(); + new_point.y = jsData.property(1).toNumber(); + } + else{ + throw std::runtime_error("JS Engine : if you return an array, the size must be 2 (time/value pair)"); + } + } + else{ + new_point.y = jsData.toNumber(); + } return new_point; }