From fe8f7838950867aef4065d538ba5ac86bf54a5b2 Mon Sep 17 00:00:00 2001 From: ValeryStk Date: Fri, 22 Nov 2024 16:43:26 +0300 Subject: [PATCH] add title for multichart legend --- davis_one/davis.cpp | 3 +- gui/davis_gui.cpp | 76 +++++++++++++++--------------- gui/json_utils.cpp | 92 ++++++++++++++++++------------------- gui/json_utils.h | 2 +- plotly_maker/html_parts.cpp | 3 +- 5 files changed, 90 insertions(+), 86 deletions(-) diff --git a/davis_one/davis.cpp b/davis_one/davis.cpp index 87ced7d..07d4f91 100644 --- a/davis_one/davis.cpp +++ b/davis_one/davis.cpp @@ -395,7 +395,8 @@ extern const char kHtmlMultiChartBlock[] = R"davis_delimeter( var trace%1 = { x: [%2], y: [%3], - type: 'scatter' + type: 'scatter', + name: '%4' }; )davis_delimeter"; diff --git a/gui/davis_gui.cpp b/gui/davis_gui.cpp index 8b004e8..2ccbf0d 100644 --- a/gui/davis_gui.cpp +++ b/gui/davis_gui.cpp @@ -183,36 +183,36 @@ void DavisGUI::hideElementsDuringResize() { void DavisGUI::readJsonToPlot(const QString& pathToFile) { QJsonObject user_stamp_keys; - if(jsn::getJsonObjectFromFile("user_keys_list.json", user_stamp_keys)==false){ - jsn::getJsonObjectFromFile(":/user_keys_list.json", user_stamp_keys); + if (jsn::getJsonObjectFromFile("user_keys_list.json", user_stamp_keys) == false) { + jsn::getJsonObjectFromFile(":/user_keys_list.json", user_stamp_keys); } auto json_object_result = jsn::getJsonObjectFromFileIfUserKeysExist(pathToFile, - service_json_keys, - user_stamp_keys); + service_json_keys, + user_stamp_keys); if (json_object_result.first) { - QJsonObject result_obj = json_object_result.second; - QJsonArray x_values = result_obj["x_values"].toArray(); - QJsonArray y_values = result_obj["y_values"].toArray(); - QJsonArray matrix_values = result_obj["matrix_values"].toArray(); - - auto x_vector = jsn::getVectorDoubleFromJsonArray(x_values); - auto y_vector = jsn::getVectorDoubleFromJsonArray(y_values); - auto matrix_vector = jsn::getMatrixFromJsonArray(matrix_values); - - qDebug()<<"MATRIX SIZE: "<" << res; - if(dvs::MORE_THAN_ONE_SEPARATOR==res)continue; - if(dvs::MABE_COMMA_MABE_DOT==res)continue; - if(dvs::UNDEFINED_BEHAVIOR==res)continue; + if (dvs::MORE_THAN_ONE_SEPARATOR == res) + continue; + if (dvs::MABE_COMMA_MABE_DOT == res) + continue; + if (dvs::UNDEFINED_BEHAVIOR == res) + continue; bool is_one_value = false; std::replace(str_lines[i].begin(), str_lines[i].end(), ',', '.'); @@ -351,8 +354,8 @@ void DavisGUI::readPlotText(QStringList& str_lines, QString title) { } else { values.emplace_back(std::stod(str_lines[i].toStdString())); } - if(values.empty()==false){ - data.emplace_back(values); + if (values.empty() == false) { + data.emplace_back(values); } } @@ -364,12 +367,12 @@ void DavisGUI::readPlotText(QStringList& str_lines, QString title) { if (data.size() == 2 || data[0].size() == 2) { //chartXY dv::Config config; config.chart.title = title.toStdString(); - dv::show(data, title.toStdString(),config); + dv::show(data, title.toStdString(), config); } else if (data.size() > 1 && data[0].size() > 1) { if (action_heatmap->isChecked()) { dv::Config config; config.heatmap.title = title.toStdString(); - dv::show(data,title.toStdString(),config); + dv::show(data, title.toStdString(), config); } else if (action_surface->isChecked()) { dv::Config config; config.surf.title = title.toStdString(); @@ -617,7 +620,8 @@ void DavisGUI::visualizeFiles(const QStringList& file_list) { QString trace_block = dvs::kHtmlMultiChartBlock; if (isFileContainsSingleChart(file_list[i], outX, outY)) { //qDebug()< getJsonObjectFromFileIfUserKeysExist(const QString& pat QJsonObject result_object_with_data; QJsonObject user_json_from_file; if (getJsonObjectFromFile(path, user_json_from_file) == false) { - qDebug()<<"Open User json object with data error..."; + qDebug() << "Open User json object with data error..."; return {false, QJsonObject()}; }; QStringList user_file_keys_list = user_json_from_file.keys(); @@ -94,64 +94,62 @@ QPair getJsonObjectFromFileIfUserKeysExist(const QString& pat // Check that all user stamp keys are valid for (int i = 0; i < user_stamp_keys_list.size(); ++i) { - QString check_key = user_stamp_keys_list[i]; - if(service_keys.contains(QJsonValue(check_key))==false){ - qDebug()<<"invalid key in the user stamps json"< getVectorDoubleFromJsonArray(const QJsonArray& json_array) -{ - QVector vector; - for (const QJsonValue &value : json_array) { - if (value.isDouble()) { - vector.append(value.toDouble()); - } - } - return vector; +QVector getVectorDoubleFromJsonArray(const QJsonArray& json_array) { + QVector vector; + for (const QJsonValue& value : json_array) { + if (value.isDouble()) { + vector.append(value.toDouble()); + } + } + return vector; } -std::vector > getMatrixFromJsonArray(const QJsonArray& json_array) -{ - std::vector> matrix; +std::vector > getMatrixFromJsonArray(const QJsonArray& json_array) { + std::vector> matrix; - for (const QJsonValue& rowValue : json_array) { - if (rowValue.isArray()) { - QJsonArray rowArray = rowValue.toArray(); - std::vector row; + for (const QJsonValue& rowValue : json_array) { + if (rowValue.isArray()) { + QJsonArray rowArray = rowValue.toArray(); + std::vector row; - for (const QJsonValue& value : qAsConst(rowArray)) { - if (value.isDouble()) { - row.emplace_back(value.toDouble()); - } - } - - matrix.emplace_back(row); - } + for (const QJsonValue& value : qAsConst(rowArray)) { + if (value.isDouble()) { + row.emplace_back(value.toDouble()); } + } + + matrix.emplace_back(row); + } + } - return matrix; + return matrix; } diff --git a/gui/json_utils.h b/gui/json_utils.h index 2382c1b..8956f95 100644 --- a/gui/json_utils.h +++ b/gui/json_utils.h @@ -29,7 +29,7 @@ bool saveJsonArrayToFile(const QString& path, QPair getJsonObjectFromFileIfUserKeysExist(const QString& path, const QJsonArray& service_keys, - const QJsonObject &user_stamp_keys + const QJsonObject& user_stamp_keys ); QVector getVectorDoubleFromJsonArray(const QJsonArray& json_array); diff --git a/plotly_maker/html_parts.cpp b/plotly_maker/html_parts.cpp index 01b5090..b91e0f4 100644 --- a/plotly_maker/html_parts.cpp +++ b/plotly_maker/html_parts.cpp @@ -367,7 +367,8 @@ extern const char kHtmlMultiChartBlock[] = R"davis_delimeter( var trace%1 = { x: [%2], y: [%3], - type: 'scatter' + type: 'scatter', + name: '%4' }; )davis_delimeter";