Skip to content

Commit 8a624eb

Browse files
authored
matrix_as_multichart (#148)
1 parent 87fd857 commit 8a624eb

File tree

10 files changed

+247
-61
lines changed

10 files changed

+247
-61
lines changed

common_utils/common_utils.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,23 @@ string makeUniqueDavisHtmlName() {
350350
return string(dvs::kOutFolderName) + dvs::kAppName + std::to_string(random_number) + ".html";
351351
}
352352

353+
void transponeMatrix(std::vector<std::vector<double> >& matrix) {
354+
355+
if (matrix.empty())
356+
return;
357+
358+
size_t rows = matrix.size();
359+
size_t cols = matrix[0].size();
360+
vector<vector<double>> transposed(cols, vector<double>(rows));
361+
362+
for (size_t i = 0; i < rows; ++i) {
363+
for (size_t j = 0; j < cols; ++j) {
364+
transposed[j][i] = matrix[i][j];
365+
}
366+
}
367+
matrix = std::move(transposed);
368+
}
369+
353370

354371
//#STOP_GRAB_TO_DVS_NAMESPACE
355372
}; // namespace dvs

common_utils/common_utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ vector<G> vecFromTemplate(const C& container) {
158158
bool is_string_convertable_to_digit(const string& sample);
159159

160160

161+
void transponeMatrix(std::vector<std::vector<double>>& matrix);
162+
163+
161164
//#STOP_GRAB_TO_DVS_NAMESPACE
162165
}; // namespace dvs
163166

davis_one/davis.cpp

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -358,27 +358,23 @@ const char kNoFileFoundedPage[] = R"(<!DOCTYPE html>
358358
)";
359359

360360

361-
extern const char kWarningIcon[] = R"davis_delimeter(<svg xmlns="http://www.w3.org/2000/svg" width="50%" height="50%" viewBox="0 0 156.262 144.407"><path d="M-109.166 7.227a2 2 0 0 0-.406.046c-3.195.03-6.176 1.695-7.785 4.483l-31.25 54.127-31.25 54.127h.002c-3.42 5.922 1.017 13.609 7.855 13.61h125.002c6.839-.001 11.277-7.688 7.857-13.61l-31.25-54.127-31.252-54.127c-1.465-2.539-4.079-4.164-6.978-4.45a2 2 0 0 0-.445-.077h-.004a2.006 2.006 0 0 0-.094-.002z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path fill="#fff" d="M-109.165 9.227a7.081 7.081 0 0 0-6.46 3.529l-31.25 54.127-31.25 54.127c-2.674 4.631.777 10.609 6.126 10.61h125.002c5.348-.001 8.8-5.979 6.125-10.61l-31.25-54.127-31.252-54.127a7.079 7.079 0 0 0-5.79-3.53h-.001z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path d="M-109.26 11.225a5.073 5.073 0 0 0-4.632 2.53l-31.25 54.128-31.25 54.127c-1.953 3.381.488 7.609 4.393 7.61h125.002c3.905-.001 6.345-4.229 4.392-7.61l-31.25-54.127-31.252-54.127a5.073 5.073 0 0 0-4.152-2.531z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path fill="#fc0" d="M140.053 125.83H16.209L47.17 72.204l30.961-53.626 30.961 53.626z"/><g transform="translate(.295 2.437) scale(.99073)"><circle cx="78.564" cy="111.117" r="8.817"/><path d="M78.564 42.955a8.817 8.817 0 0 0-8.818 8.816l3.156 37.461a5.662 5.662 0 0 0 11.325 0l3.154-37.46a8.817 8.817 0 0 0-8.817-8.817z"/></g></svg>)davis_delimeter";
361+
const char kWarningIcon[] = R"davis_delimeter(<svg xmlns="http://www.w3.org/2000/svg" width="50%" height="50%" viewBox="0 0 156.262 144.407"><path d="M-109.166 7.227a2 2 0 0 0-.406.046c-3.195.03-6.176 1.695-7.785 4.483l-31.25 54.127-31.25 54.127h.002c-3.42 5.922 1.017 13.609 7.855 13.61h125.002c6.839-.001 11.277-7.688 7.857-13.61l-31.25-54.127-31.252-54.127c-1.465-2.539-4.079-4.164-6.978-4.45a2 2 0 0 0-.445-.077h-.004a2.006 2.006 0 0 0-.094-.002z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path fill="#fff" d="M-109.165 9.227a7.081 7.081 0 0 0-6.46 3.529l-31.25 54.127-31.25 54.127c-2.674 4.631.777 10.609 6.126 10.61h125.002c5.348-.001 8.8-5.979 6.125-10.61l-31.25-54.127-31.252-54.127a7.079 7.079 0 0 0-5.79-3.53h-.001z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path d="M-109.26 11.225a5.073 5.073 0 0 0-4.632 2.53l-31.25 54.128-31.25 54.127c-1.953 3.381.488 7.609 4.393 7.61h125.002c3.905-.001 6.345-4.229 4.392-7.61l-31.25-54.127-31.252-54.127a5.073 5.073 0 0 0-4.152-2.531z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path fill="#fc0" d="M140.053 125.83H16.209L47.17 72.204l30.961-53.626 30.961 53.626z"/><g transform="translate(.295 2.437) scale(.99073)"><circle cx="78.564" cy="111.117" r="8.817"/><path d="M78.564 42.955a8.817 8.817 0 0 0-8.818 8.816l3.156 37.461a5.662 5.662 0 0 0 11.325 0l3.154-37.46a8.817 8.817 0 0 0-8.817-8.817z"/></g></svg>)davis_delimeter";
362362

363363

364364

365-
extern const char kHtmlDateTimeModel[] = R"davis_delimeter(
365+
const char kHtmlDateTimeModel[] = R"davis_delimeter(
366366
<head>
367367
<script src="%1" charset="utf-8"></script>
368368
</head>
369369
<body><div style = "display: flex;
370370
align-items:center;height:100%; width:100%;background:#dddfd4;
371-
justify-content: center;"><div style="%6:99%; %7:99%; aspect-ratio: %4/%5;"
371+
justify-content: center;"><div style="%5:99%; %6:99%; aspect-ratio: %3/%4;"
372372
id="gd"></div></div>
373373
374374
<script>
375375
376376
var data = [
377-
{
378-
x: [%2],
379-
y: [%3],
380-
type: 'scatter'
381-
}
377+
%2
382378
];
383379
384380
var config = {
@@ -395,7 +391,7 @@ Plotly.newPlot('gd', data);
395391

396392

397393

398-
extern const char kHtmlMultiChartBlock[] = R"davis_delimeter(
394+
const char kHtmlMultiChartBlock[] = R"davis_delimeter(
399395
var trace%1 = {
400396
x: [%2],
401397
y: [%3],
@@ -407,7 +403,7 @@ var trace%1 = {
407403

408404

409405

410-
extern const char kHtmlMultiChartModel[] = R"davis_delimeter(
406+
const char kHtmlMultiChartModel[] = R"davis_delimeter(
411407
<head>
412408
<script src="%1" charset="utf-8"></script>
413409
</head>
@@ -463,7 +459,7 @@ Plotly.newPlot('gd', data, layout, config);
463459

464460

465461

466-
extern const char kHtmlCloudOfPoints[] = R"davis_delimeter(
462+
const char kHtmlCloudOfPoints[] = R"davis_delimeter(
467463
468464
<head>
469465
<script src="%1" charset="utf-8"></script>
@@ -501,7 +497,11 @@ Plotly.newPlot('gd', data,layout,config);
501497
502498
)davis_delimeter";
503499

504-
500+
const char kHtmlSimpleDataBlock[]= R"davis_delimeter({
501+
x: [%1],
502+
y: [%2],
503+
type: 'scatter'
504+
})davis_delimeter";
505505

506506

507507
// *INDENT-ON*
@@ -843,6 +843,23 @@ string makeUniqueDavisHtmlName() {
843843
return string(dvs::kOutFolderName) + dvs::kAppName + std::to_string(random_number) + ".html";
844844
}
845845

846+
void transponeMatrix(std::vector<std::vector<double> >& matrix) {
847+
848+
if (matrix.empty())
849+
return;
850+
851+
size_t rows = matrix.size();
852+
size_t cols = matrix[0].size();
853+
vector<vector<double>> transposed(cols, vector<double>(rows));
854+
855+
for (size_t i = 0; i < rows; ++i) {
856+
for (size_t j = 0; j < cols; ++j) {
857+
transposed[j][i] = matrix[i][j];
858+
}
859+
}
860+
matrix = std::move(transposed);
861+
}
862+
846863

847864

848865
} // namespace dvs end
@@ -1241,18 +1258,16 @@ void showDateTimeChart(const string& date_time_values,
12411258
#endif
12421259
vector<string>args {ARGS_DATE_TIME_PAGE_SIZE, ""};
12431260
args[ARG_JS_NAME] = kPlotlyJsName;
1244-
args[ARG_DATE_TIME_VALUES] = date_time_values;
12451261

1246-
std::string values;
1247-
for (size_t i = 0; i < yValues.size(); ++i) {
1248-
std::string value = std::to_string(yValues[i]);
1249-
values.append(value);
1250-
if (i != yValues.size() - 1) {
1251-
values.append(",");
1252-
}
1253-
}
1262+
vector<string>args_block {ARGS_SIMPLE_DATA_BLOCK_SIZE, ""};
1263+
std::string simpleData_yValues = vectorToString(yValues);
1264+
args_block[ARG_SIMPLE_DATA_X] = date_time_values;
1265+
args_block[ARG_SIMPLE_DATA_Y] = simpleData_yValues;
1266+
std::string data_values_block;
1267+
make_string(kHtmlSimpleDataBlock, args_block, data_values_block);
12541268

1255-
args[ARG_Y_DATE_TIME_VALUES] = values;
1269+
1270+
args[ARG_DATE_TIME_VALUES_BLOCK] = data_values_block;
12561271
args[ARG_DATE_TIME_ASPECT_RATIO_WIDTH] = "1";
12571272
args[ARG_DATE_TIME_ASPECT_RATIO_HEIGHT] = "1";
12581273
/*
@@ -1390,6 +1405,57 @@ void showCloudOfPointsChartStr(const std::string& xValues,
13901405
openFileBySystem(kCloudPagePath);
13911406
}
13921407

1408+
void showDateTimeMultichart(const std::string& date_time_values,
1409+
const vector<vector<double>>& yValues,
1410+
bool isAutoScale) {
1411+
string out;
1412+
string davis_dir;
1413+
#ifdef _WIN32
1414+
davis_dir = "\\davis_htmls";
1415+
#elif __linux__
1416+
davis_dir = "/davis_htmls";
1417+
#endif
1418+
vector<string>args {ARGS_DATE_TIME_PAGE_SIZE, ""};
1419+
args[ARG_JS_NAME] = kPlotlyJsName;
1420+
1421+
1422+
std::string all_data = "";
1423+
for (int i = 0; i < yValues.size(); ++i) {
1424+
vector<string>args_block {ARGS_SIMPLE_DATA_BLOCK_SIZE, ""};
1425+
std::string simpleData_yValues = vectorToString(yValues[i]);
1426+
args_block[ARG_SIMPLE_DATA_X] = date_time_values;
1427+
args_block[ARG_SIMPLE_DATA_Y] = simpleData_yValues;
1428+
std::string data_values_block;
1429+
make_string(kHtmlSimpleDataBlock, args_block, data_values_block);
1430+
all_data.append(data_values_block);
1431+
if (i != yValues.size() - 1) {
1432+
all_data.append(",");
1433+
}
1434+
}
1435+
1436+
args[ARG_DATE_TIME_VALUES_BLOCK] = all_data;
1437+
args[ARG_DATE_TIME_ASPECT_RATIO_WIDTH] = "1";
1438+
args[ARG_DATE_TIME_ASPECT_RATIO_HEIGHT] = "1";
1439+
1440+
string paramWH = "height";
1441+
string paramWHsecond;
1442+
if (isAutoScale) {
1443+
if (paramWH == "width") {
1444+
paramWHsecond = "height";
1445+
} else if (paramWH == "height") {
1446+
paramWHsecond = "width";
1447+
}
1448+
} else {
1449+
paramWHsecond = paramWH;
1450+
}
1451+
1452+
args[ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
1453+
args[ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
1454+
make_string(kHtmlDateTimeModel, args, out);
1455+
saveStringToFile(kReportPagePath, out);
1456+
openFileBySystem(kReportPagePath);
1457+
}
1458+
13931459

13941460
} // namespace dvs end
13951461

davis_one/davis.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,12 @@ enum ARGS_REPORT_PAGE_INDEX {
152152
};
153153

154154
enum ARGS_DATE_TIME_PAGE_INDEX {
155-
ARG_JS_NAME, //%1
156-
ARG_DATE_TIME_VALUES, //%2
157-
ARG_Y_DATE_TIME_VALUES, //%3
158-
ARG_DATE_TIME_ASPECT_RATIO_WIDTH, //%4
159-
ARG_DATE_TIME_ASPECT_RATIO_HEIGHT, //%5
160-
ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT, //%6 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
161-
ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%7 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale.
155+
ARG_JS_NAME, //%1
156+
ARG_DATE_TIME_VALUES_BLOCK, //%2
157+
ARG_DATE_TIME_ASPECT_RATIO_WIDTH, //%3
158+
ARG_DATE_TIME_ASPECT_RATIO_HEIGHT, //%4
159+
ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT, //%5 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
160+
ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%6 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale.
162161

163162
// ADD NEW ENUM BEFORE THIS COMMENT
164163
ARGS_DATE_TIME_PAGE_SIZE
@@ -195,6 +194,12 @@ enum ARGS_CLOUD_OF_POINTS_PAGE {
195194
ARGS_CLOUD_OF_POINTS_PAGE_SIZE
196195
};
197196

197+
enum ARGS_SIMPLE_DATA_BLOCK {
198+
ARG_SIMPLE_DATA_X,
199+
ARG_SIMPLE_DATA_Y,
200+
ARGS_SIMPLE_DATA_BLOCK_SIZE
201+
};
202+
198203

199204
extern const char kHtmlModel[];
200205
extern const char kColorMapDefaultPart[];
@@ -223,6 +228,8 @@ extern const char kHtmlMultiChartBlock[];
223228
extern const char kHtmlMultiChartModel[];
224229
extern const char kHtmlCloudOfPoints[];
225230

231+
extern const char kHtmlSimpleDataBlock[];
232+
226233

227234
} // namespace dvs end
228235

@@ -372,6 +379,9 @@ vector<G> vecFromTemplate(const C& container) {
372379
bool is_string_convertable_to_digit(const string& sample);
373380

374381

382+
void transponeMatrix(std::vector<std::vector<double>>& matrix);
383+
384+
375385

376386
} // namespace dvs end
377387

@@ -430,6 +440,10 @@ void showCloudOfPointsChartStr(const string& xValues,
430440
const vector<double>& colorValues,
431441
bool isAutoScale);
432442

443+
void showDateTimeMultichart(const string& date_time_values,
444+
const vector<vector<double>>& yValues,
445+
bool isAutoScale);
446+
433447

434448
} // namespace dvs end
435449

gui/davis_gui.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ bool DavisGUI::checkDateTimeVariant(const QStringList& lines) {
660660
QString dates;
661661
std::vector<double> values;
662662
std::vector<double> force;
663+
std::vector<std::vector<double>> multicharts;
663664

664665
for (int i = 0; i < lines.size(); ++i) {
665666
QString test = lines[i];
@@ -691,9 +692,17 @@ bool DavisGUI::checkDateTimeVariant(const QStringList& lines) {
691692
}
692693

693694

694-
if (values_list.size() < 2 || values_list.size() > 3) {
695+
if (values_list.size() < 2) {
695696
continue;
696697
}
698+
if (values_list.size() > 3) {
699+
std::vector<double> temp(values_list.size() - 1);
700+
for (int j = 1; j < values_list.size(); ++j) {
701+
temp[j - 1] = values_list[j].toDouble();
702+
}
703+
multicharts.push_back(temp);
704+
}
705+
697706
double value = values_list[1].toDouble();
698707
//qDebug() << value;
699708
values.emplace_back(value);
@@ -706,6 +715,13 @@ bool DavisGUI::checkDateTimeVariant(const QStringList& lines) {
706715
}
707716
}
708717
}
718+
719+
if (multicharts.empty() == false) {
720+
dvs::transponeMatrix(multicharts);
721+
dvs::showDateTimeMultichart(dates.toStdString(), multicharts, action_fitPlotToAllWindow->isChecked());
722+
return true;
723+
}
724+
709725
if (values.size() == 0)
710726
return false;
711727
qDebug() << "check sizes: " << lines.size() << values.size();
@@ -918,8 +934,16 @@ void DavisGUI::visualizeFiles(const QStringList& file_list) {
918934
paramWHsecond = paramWH;
919935
}
920936
QString multichartPage = dvs::kHtmlMultiChartModel;
921-
multichartPage = multichartPage.arg(dvs::kPlotlyJsName, all_chart_blocks, all_traces_names, "", "X", "Y",
922-
QString::number(aspectW), QString::number(aspectH), paramWH, paramWHsecond);
937+
multichartPage = multichartPage.arg(dvs::kPlotlyJsName)
938+
.arg(all_chart_blocks)
939+
.arg(all_traces_names)
940+
.arg("")
941+
.arg("X")
942+
.arg("Y")
943+
.arg(QString::number(aspectW))
944+
.arg(QString::number(aspectH))
945+
.arg(paramWH)
946+
.arg(paramWHsecond);
923947
qDebug() << multichartPage;
924948
dvs::saveStringToFile(dvs::kReportPagePath, multichartPage.toStdString());
925949
dvs::openFileBySystem(dvs::kReportPagePath);

gui/davis_gui.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class DavisGUI : public QMainWindow {
6161
void readJsonToPlot(const QString& pathToFile);
6262
bool mayBeShowMatrixToMatrix(QJsonArray& stamps,
6363
QJsonObject& obj);
64+
void matrixAnalyzer(std::vector<std::vector<double>>& matrix,
65+
const bool isRow);
6466
Skins checkSkin();
6567

6668

0 commit comments

Comments
 (0)