Skip to content

Commit

Permalink
add title for multichart legend
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeryStk committed Nov 22, 2024
1 parent 952b634 commit fe8f783
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 86 deletions.
3 changes: 2 additions & 1 deletion davis_one/davis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
76 changes: 40 additions & 36 deletions gui/davis_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<<matrix_vector.size();

if(x_vector.empty()==false&&y_vector.empty()==false){
dv::show(x_vector.toStdVector(),y_vector.toStdVector(),"JSON TEST");
}else if(x_vector.empty()==true&&y_vector.empty()==false){
dv::show(y_vector.toStdVector(),"JSON TEST");
}else if(x_vector.empty()==false&&y_vector.empty()==true){
dv::show(x_vector.toStdVector(),"JSON TEST");
}
if(matrix_vector.empty() ==false){
dv::show(matrix_vector,"JSON_MATRIX_VECTOR");
}
}else{
qDebug()<<"Check JSON!";
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: " << matrix_vector.size();

if (x_vector.empty() == false && y_vector.empty() == false) {
dv::show(x_vector.toStdVector(), y_vector.toStdVector(), "JSON TEST");
} else if (x_vector.empty() == true && y_vector.empty() == false) {
dv::show(y_vector.toStdVector(), "JSON TEST");
} else if (x_vector.empty() == false && y_vector.empty() == true) {
dv::show(x_vector.toStdVector(), "JSON TEST");
}
if (matrix_vector.empty() == false) {
dv::show(matrix_vector, "JSON_MATRIX_VECTOR");
}
} else {
qDebug() << "Check JSON!";
}

}
Expand Down Expand Up @@ -327,9 +327,12 @@ void DavisGUI::readPlotText(QStringList& str_lines, QString title) {
auto res = dvs::find_separator(str_lines[i].toStdString(), separator);
//qDebug() << "sep result: " << separator << "--->" << 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(), ',', '.');
Expand All @@ -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);
}
}

Expand All @@ -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();
Expand Down Expand Up @@ -617,7 +620,8 @@ void DavisGUI::visualizeFiles(const QStringList& file_list) {
QString trace_block = dvs::kHtmlMultiChartBlock;
if (isFileContainsSingleChart(file_list[i], outX, outY)) {
//qDebug()<<file_list[i].toLocalFile();
all_chart_blocks.append(trace_block.arg(QString::number(i + 1), outX, outY));
QFileInfo fi(file_list[i]);
all_chart_blocks.append(trace_block.arg(QString::number(i + 1), outX, outY, fi.baseName()));
all_traces_names.append(QString(trace_name).arg(i + 1));
if (i < file_list.size() - 1) {
all_traces_names.append(",");
Expand Down Expand Up @@ -669,7 +673,7 @@ void DavisGUI::visualizeFiles(const QStringList& file_list) {
}
file.close();
if (checkDateTimeVariant(str_lines) == false) {
readPlotText(str_lines,info.baseName());
readPlotText(str_lines, info.baseName());
qDebug() << "matrix read MAKER: " << time.elapsed();
};
} else {
Expand Down
92 changes: 45 additions & 47 deletions gui/json_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,72 +86,70 @@ QPair<bool, QJsonObject> 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();
QStringList user_stamp_keys_list = user_stamp_keys.keys();

// 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"<<check_key;
return {false,QJsonObject()};
}
QString check_key = user_stamp_keys_list[i];
if (service_keys.contains(QJsonValue(check_key)) == false) {
qDebug() << "invalid key in the user stamps json" << check_key;
return {false, QJsonObject()};
}
}

// Check that we have keys for user json
for(int i=0;i<service_keys.size();++i){
auto jarr_custom_keys = user_stamp_keys[service_keys[i].toString()].toArray();
for(int j=0;j<jarr_custom_keys.size();++j){
auto custom_key = jarr_custom_keys[j].toString();
if(user_json_from_file.contains(custom_key)){
if(user_json_from_file[custom_key].isArray()){
result_object_with_data.insert(service_keys[i].toString(),
user_json_from_file[custom_key]);
break;
}
}
};
for (int i = 0; i < service_keys.size(); ++i) {
auto jarr_custom_keys = user_stamp_keys[service_keys[i].toString()].toArray();
for (int j = 0; j < jarr_custom_keys.size(); ++j) {
auto custom_key = jarr_custom_keys[j].toString();
if (user_json_from_file.contains(custom_key)) {
if (user_json_from_file[custom_key].isArray()) {
result_object_with_data.insert(service_keys[i].toString(),
user_json_from_file[custom_key]);
break;
}
}
};
}
if(result_object_with_data.isEmpty()){
return {false, result_object_with_data};
}else
return {true, result_object_with_data};
if (result_object_with_data.isEmpty()) {
return {false, result_object_with_data};
} else
return {true, result_object_with_data};
}

QVector<double> getVectorDoubleFromJsonArray(const QJsonArray& json_array)
{
QVector<double> vector;
for (const QJsonValue &value : json_array) {
if (value.isDouble()) {
vector.append(value.toDouble());
}
}
return vector;
QVector<double> getVectorDoubleFromJsonArray(const QJsonArray& json_array) {
QVector<double> vector;
for (const QJsonValue& value : json_array) {
if (value.isDouble()) {
vector.append(value.toDouble());
}
}
return vector;
}

std::vector<std::vector<double> > getMatrixFromJsonArray(const QJsonArray& json_array)
{
std::vector<std::vector<double>> matrix;
std::vector<std::vector<double> > getMatrixFromJsonArray(const QJsonArray& json_array) {
std::vector<std::vector<double>> matrix;

for (const QJsonValue& rowValue : json_array) {
if (rowValue.isArray()) {
QJsonArray rowArray = rowValue.toArray();
std::vector<double> row;
for (const QJsonValue& rowValue : json_array) {
if (rowValue.isArray()) {
QJsonArray rowArray = rowValue.toArray();
std::vector<double> 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;
}


Expand Down
2 changes: 1 addition & 1 deletion gui/json_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool saveJsonArrayToFile(const QString& path,

QPair<bool, QJsonObject> getJsonObjectFromFileIfUserKeysExist(const QString& path,
const QJsonArray& service_keys,
const QJsonObject &user_stamp_keys
const QJsonObject& user_stamp_keys
);

QVector<double> getVectorDoubleFromJsonArray(const QJsonArray& json_array);
Expand Down
3 changes: 2 additions & 1 deletion plotly_maker/html_parts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit fe8f783

Please sign in to comment.