Skip to content

Commit dc31483

Browse files
authored
Aspect ratio (#146)
1 parent 225184c commit dc31483

File tree

10 files changed

+242
-31
lines changed

10 files changed

+242
-31
lines changed

Tests/ArrayCoreTest.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
using std::string;
1212
using std::vector;
13-
13+
/*
1414
TEST(ArrayCore, save_to_disk_2d) {
1515
//! 2-dimensional array
1616
int rows = 10;
@@ -141,13 +141,15 @@ TEST(ArrayCore, showDefaultSettings) {
141141
bool result = dv::show(values, "testDefaultSettings");
142142
EXPECT_EQ(result, true);
143143
}
144-
144+
*/
145145
TEST(ArrayCore, showHeatMap1) {
146146
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
147147
vector<vector<double>> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
148148
auto config = dv::Config();
149149
config.heatmap.title = "Black & White TEST MATRIX";
150150
config.heatmap.colorSc = dv::config_colorscales::COLORSCALE_GRAYSCALE;
151+
config.heatmap.aspectRatioWidth = 2;
152+
config.heatmap.aspectRatioHeight = 3;
151153
bool result = dv::show(values, "showHeatMap_gray", config);
152154
EXPECT_EQ(result, true);
153155
}
@@ -322,18 +324,20 @@ TEST(ArrayCore, show2ChartsWithHoldOnCustomSettings) {
322324
config.chart.title = "Custom title";
323325
config.chart.xLabel = "Custom xLabel";
324326
config.chart.yLabel = "Custom yLabel";
327+
config.chart.aspectRatioHeight = 1;
328+
config.chart.aspectRatioWidth = 3;
325329
dv::holdOff(config);
326330
EXPECT_EQ(v1 && v2, true);
327331
}
328332

329333
TEST(ArrayCore, testMyltiplyHoldOnOff) {
330334

331335
vector<double> vec1 = {1, 2, 3, 4, 5, 6, 7};
332-
vector<double> vec2 = {3, 4, 5, 6, 7};
336+
vector<double> vec2 = {3, 4, 5, 6, 27};
333337

334338
dv::holdOn();
335339
bool v1 = dv::show(vec1, "titleHoldOn1");
336-
bool v2 = dv::show(vec1, "titleHoldOn2");
340+
bool v2 = dv::show(vec2, "titleHoldOn2");
337341
dv::holdOff();
338342

339343
dv::holdOff();

array_core/configurator.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ enum config_colorscales {
2929
struct commonSettings {
3030
commonSettings():
3131
xLabel("X"),
32-
yLabel("Y") {}
32+
yLabel("Y"),
33+
aspectRatioWidth(1),
34+
aspectRatioHeight(1) {}
3335
virtual ~commonSettings() {}
3436
std::string title;
3537
std::string xLabel;
3638
std::string yLabel;
39+
double aspectRatioWidth;
40+
double aspectRatioHeight;
3741
};
3842

3943
struct chartSettings : public commonSettings {

array_core/multi_plot.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,17 @@ void holdOff(const Config& configuration) {
3939
allTracesNames_str.append(filled_trace_name_part);
4040
allChartBlocks_str.append(dvs::allChartBlocks[i]);
4141
}
42+
string paramWH;
43+
if (configuration.chart.aspectRatioWidth > configuration.chart.aspectRatioHeight) {
44+
paramWH = "width";
45+
} else {
46+
paramWH = "height";
47+
}
4248
vector<string> args = {dvs::kPlotlyJsName, allChartBlocks_str, allTracesNames_str,
43-
configuration.chart.title, configuration.chart.xLabel, configuration.chart.yLabel
49+
configuration.chart.title, configuration.chart.xLabel, configuration.chart.yLabel,
50+
dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth),
51+
dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight),
52+
paramWH
4453
};
4554
string multichartPage = dvs::kHtmlMultiChartModel;
4655
string filled_multichartPage = "";

common_utils/common_utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ string vectorToString(const vector<double>& vec);
6969

7070
string makeUniqueDavisHtmlName();
7171

72+
//! sometimes std::to_string reurn str with ',' as separator what is wrong
73+
template <typename T>
74+
string toStringDotSeparator(T data) {
75+
string str = std::to_string(data);
76+
std::replace(str.begin(), str.end(), ',', '.');
77+
return str;
78+
}
79+
7280
//! save to disk vector<T> data
7381
template <typename T>
7482
bool saveVec(const vector<T>& vec, const string& filename, dv::configSaveToDisk config) {

davis_one/davis.cpp

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ R"(
4242
</head>
4343
<body><div style = "display: flex;
4444
align-items:center;height:100%; width:100%;background:#dddfd4;
45-
justify-content: center;"><div style="height:95%; aspect-ratio: 1/1;"
45+
justify-content: center;"><div style="%11:99%; aspect-ratio: %9/%10;"
4646
id="gd"></div></div>
4747
<script>
4848
%1
@@ -368,7 +368,7 @@ extern const char kHtmlDateTimeModel[] = R"davis_delimeter(
368368
</head>
369369
<body><div style = "display: flex;
370370
align-items:center;height:100%; width:100%;background:#dddfd4;
371-
justify-content: center;"><div style="height:95%; aspect-ratio: 1/1;"
371+
justify-content: center;"><div style="%6:99%; aspect-ratio: %4/%5;"
372372
id="gd"></div></div>
373373
374374
<script>
@@ -413,7 +413,7 @@ extern const char kHtmlMultiChartModel[] = R"davis_delimeter(
413413
</head>
414414
<body><div style = "display: flex;
415415
align-items:center;height:100%; width:100%;background:#dddfd4;
416-
justify-content: center;"><div style="height:95%; aspect-ratio: 1/1;"
416+
justify-content: center;"><div style="%9:99%; aspect-ratio: %7/%8;"
417417
id="gd"></div></div>
418418
<script>
419419
@@ -470,7 +470,7 @@ extern const char kHtmlCloudOfPoints[] = R"davis_delimeter(
470470
</head>
471471
<body><div style = "display: flex;
472472
align-items:center;height:100%; width:100%;background:#dddfd4;
473-
justify-content: center;"><div style="height:95%; aspect-ratio: 1/1;"
473+
justify-content: center;"><div style="%7:99%; aspect-ratio: %5/%6;"
474474
id="gd"></div></div>
475475
<script>
476476
var trace = {
@@ -1010,24 +1010,39 @@ bool createHtmlPageWithPlotlyJS(const std::vector<std::vector<double>>& values,
10101010
break;
10111011
}
10121012
switch (typeVisual) {
1013-
case dv::VISUALTYPE_HEATMAP:
1013+
case dv::VISUALTYPE_HEATMAP: {
10141014
args[ARG_MATRIX_TYPE] = kHeatMapTypePart;
10151015
args[ARG_TITLE] = configuration.heatmap.title;
10161016
args[ARG_TITLE_X] = configuration.heatmap.xLabel;
10171017
args[ARG_TITLE_Y] = configuration.heatmap.yLabel;
1018+
args[ARG_ASPECT_RATIO_WIDTH] = dvs::toStringDotSeparator(configuration.heatmap.aspectRatioWidth);
1019+
args[ARG_ASPECT_RATIO_HEIGHT] = dvs::toStringDotSeparator(configuration.heatmap.aspectRatioHeight);
1020+
string paramWH;
1021+
if (configuration.heatmap.aspectRatioWidth > configuration.heatmap.aspectRatioHeight) {
1022+
paramWH = "width";
1023+
} else {
1024+
paramWH = "height";
1025+
}
1026+
args[ARG_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
10181027
break;
1019-
case dv::VISUALTYPE_SURFACE:
1028+
}
1029+
case dv::VISUALTYPE_SURFACE: {
10201030
args[ARG_MATRIX_TYPE] = kSurfaceTypePart;
10211031
args[ARG_TITLE] = configuration.surf.title;
10221032
args[ARG_TITLE_X] = configuration.surf.xLabel;
10231033
args[ARG_TITLE_Y] = configuration.surf.yLabel;
10241034
args[ARG_TITLE_Z] = configuration.surf.zLabel;
1035+
args[ARG_ASPECT_RATIO_WIDTH] = dvs::toStringDotSeparator(configuration.surf.aspectRatioWidth);
1036+
args[ARG_ASPECT_RATIO_HEIGHT] = dvs::toStringDotSeparator(configuration.surf.aspectRatioHeight);
1037+
string paramWH;
1038+
if (configuration.surf.aspectRatioWidth > configuration.surf.aspectRatioHeight) {
1039+
paramWH = "width";
1040+
} else {
1041+
paramWH = "height";
1042+
}
1043+
args[ARG_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
10251044
break;
1026-
case dv::VISUALTYPE_CHART:
1027-
args[ARG_TITLE] = configuration.chart.title;
1028-
args[ARG_TITLE_X] = configuration.chart.xLabel;
1029-
args[ARG_TITLE_Y] = configuration.chart.yLabel;
1030-
break;
1045+
}
10311046
default:
10321047
break;
10331048
}
@@ -1069,6 +1084,15 @@ bool showLineChartInBrowser(const vector<double>& xValues, const vector<double>&
10691084
args[ARG_TITLE] = configuration.chart.title;
10701085
args[ARG_TITLE_X] = configuration.chart.xLabel;
10711086
args[ARG_TITLE_Y] = configuration.chart.yLabel;
1087+
args[ARG_ASPECT_RATIO_WIDTH] = dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth);
1088+
args[ARG_ASPECT_RATIO_HEIGHT] = dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight);
1089+
string paramWH;
1090+
if (configuration.chart.aspectRatioWidth > configuration.chart.aspectRatioHeight) {
1091+
paramWH = "width";
1092+
} else {
1093+
paramWH = "height";
1094+
}
1095+
args[ARG_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
10721096
make_string(kHtmlModel, args, page);
10731097
string pageName;
10741098
mayBeCreateJsWorkingFolder();
@@ -1195,6 +1219,18 @@ void showDateTimeChart(const string& date_time_values,
11951219
}
11961220

11971221
args[ARG_Y_DATE_TIME_VALUES] = values;
1222+
args[ARG_DATE_TIME_ASPECT_RATIO_WIDTH] = "1";
1223+
args[ARG_DATE_TIME_ASPECT_RATIO_HEIGHT] = "1";
1224+
/*
1225+
string paramWH;
1226+
if(configuration.chart.aspectRatioWidth > configuration.chart.aspectRatioHeight){
1227+
paramWH = "width";
1228+
}else{
1229+
paramWH = "height";
1230+
}
1231+
*/
1232+
string paramWH = "height";
1233+
args[ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
11981234
make_string(kHtmlDateTimeModel, args, out);
11991235
saveStringToFile(kReportPagePath, out);
12001236
openFileBySystem(kReportPagePath);
@@ -1236,6 +1272,18 @@ void showCloudOfPointsChart(const vector<double>& xValues,
12361272
args[ARG_X_CLOUD_OF_POINTS] = vectorToString(xValues);
12371273
args[ARG_Y_CLOUD_OF_POINTS] = vectorToString(yValues);
12381274
args[ARG_COLOR_CLOUD_OF_POINTS] = vectorToString(colorValues);
1275+
args[ARG_CLOUD_OF_POINTS_ASPECT_RATIO_WIDTH] = "1";
1276+
args[ARG_CLOUD_OF_POINTS_ASPECT_RATIO_HEIGHT] = "1";
1277+
/*
1278+
string paramWH;
1279+
if(configuration.chart.aspectRatioWidth > configuration.chart.aspectRatioHeight){
1280+
paramWH = "width";
1281+
}else{
1282+
paramWH = "height";
1283+
}
1284+
*/
1285+
string paramWH = "height";
1286+
args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
12391287
make_string(kHtmlCloudOfPoints, args, out);
12401288
saveStringToFile(kCloudPagePath, out);
12411289
openFileBySystem(kCloudPagePath);
@@ -1256,6 +1304,18 @@ void showCloudOfPointsChartStr(const std::string& xValues,
12561304
args[ARG_X_CLOUD_OF_POINTS] = xValues;
12571305
args[ARG_Y_CLOUD_OF_POINTS] = vectorToString(yValues);
12581306
args[ARG_COLOR_CLOUD_OF_POINTS] = vectorToString(colorValues);
1307+
args[ARG_CLOUD_OF_POINTS_ASPECT_RATIO_WIDTH] = "1";
1308+
args[ARG_CLOUD_OF_POINTS_ASPECT_RATIO_HEIGHT] = "1";
1309+
/*
1310+
string paramWH;
1311+
if(configuration.chart.aspectRatioWidth > configuration.chart.aspectRatioHeight){
1312+
paramWH = "width";
1313+
}else{
1314+
paramWH = "height";
1315+
}
1316+
*/
1317+
string paramWH = "height";
1318+
args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
12591319
make_string(kHtmlCloudOfPoints, args, out);
12601320
saveStringToFile(kCloudPagePath, out);
12611321
openFileBySystem(kCloudPagePath);
@@ -1297,8 +1357,17 @@ void holdOff(const Config& configuration) {
12971357
allTracesNames_str.append(filled_trace_name_part);
12981358
allChartBlocks_str.append(dvs::allChartBlocks[i]);
12991359
}
1360+
string paramWH;
1361+
if (configuration.chart.aspectRatioWidth > configuration.chart.aspectRatioHeight) {
1362+
paramWH = "width";
1363+
} else {
1364+
paramWH = "height";
1365+
}
13001366
vector<string> args = {dvs::kPlotlyJsName, allChartBlocks_str, allTracesNames_str,
1301-
configuration.chart.title, configuration.chart.xLabel, configuration.chart.yLabel
1367+
configuration.chart.title, configuration.chart.xLabel, configuration.chart.yLabel,
1368+
dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth),
1369+
dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight),
1370+
paramWH
13021371
};
13031372
string multichartPage = dvs::kHtmlMultiChartModel;
13041373
string filled_multichartPage = "";

davis_one/davis.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ enum config_colorscales {
5555
struct commonSettings {
5656
commonSettings():
5757
xLabel("X"),
58-
yLabel("Y") {}
58+
yLabel("Y"),
59+
aspectRatioWidth(1),
60+
aspectRatioHeight(1) {}
5961
virtual ~commonSettings() {}
6062
std::string title;
6163
std::string xLabel;
6264
std::string yLabel;
65+
double aspectRatioWidth;
66+
double aspectRatioHeight;
6367
};
6468

6569
struct chartSettings : public commonSettings {
@@ -121,6 +125,9 @@ enum ARGS_INDEX {
121125
ARG_TITLE_Y, //%6
122126
ARG_TITLE_Z, //%7
123127
ARG_JS_VER, //%8
128+
ARG_ASPECT_RATIO_WIDTH, //%9
129+
ARG_ASPECT_RATIO_HEIGHT, //%10
130+
ARG_ASPECT_WIDTH_OR_HEIGHT, //11 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
124131
// ADD NEW ENUM BEFORE THIS COMMENT
125132
ARGS_SIZE
126133
};
@@ -145,14 +152,26 @@ enum ARGS_DATE_TIME_PAGE_INDEX {
145152
ARG_JS_NAME, //%1
146153
ARG_DATE_TIME_VALUES, //%2
147154
ARG_Y_DATE_TIME_VALUES, //%3
155+
ARG_DATE_TIME_ASPECT_RATIO_WIDTH, //%4
156+
ARG_DATE_TIME_ASPECT_RATIO_HEIGHT, //%5
157+
ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT, //%6 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
158+
148159
// ADD NEW ENUM BEFORE THIS COMMENT
149160
ARGS_DATE_TIME_PAGE_SIZE
150161
};
151162

163+
// currently don't used
152164
enum ARGS_MULTI_CHARTS_PAGE {
153165
ARG_JS_MC_NAME,
154166
ARG_TRACES_BLOCKS,
155167
ARG_DATA_OF_TRACES,
168+
something1,
169+
something2,
170+
something3,
171+
ARG_MC_DATE_TIME_ASPECT_RATIO_WIDTH, //%7
172+
ARG_MC_DATE_TIME_ASPECT_RATIO_HEIGHT, //%8
173+
ARG_MC_DATE_ASPECT_WIDTH_OR_HEIGHT, //%9 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
174+
156175
// ADD NEW ENUM BEFORE THIS COMMENT
157176
ARGS_MULTI_CHARTS_PAGE_SIZE
158177
};
@@ -162,6 +181,9 @@ enum ARGS_CLOUD_OF_POINTS_PAGE {
162181
ARG_X_CLOUD_OF_POINTS,
163182
ARG_Y_CLOUD_OF_POINTS,
164183
ARG_COLOR_CLOUD_OF_POINTS,
184+
ARG_CLOUD_OF_POINTS_ASPECT_RATIO_WIDTH, //%5
185+
ARG_CLOUD_OF_POINTS_ASPECT_RATIO_HEIGHT, //%6
186+
ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT, //7 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
165187
// ADD NEW ENUM BEFORE THIS COMMENT
166188
ARGS_CLOUD_OF_POINTS_PAGE_SIZE
167189
};
@@ -254,6 +276,14 @@ string vectorToString(const vector<double>& vec);
254276

255277
string makeUniqueDavisHtmlName();
256278

279+
//! sometimes std::to_string reurn str with ',' as separator what is wrong
280+
template <typename T>
281+
string toStringDotSeparator(T data) {
282+
string str = std::to_string(data);
283+
std::replace(str.begin(), str.end(), ',', '.');
284+
return str;
285+
}
286+
257287
//! save to disk vector<T> data
258288
template <typename T>
259289
bool saveVec(const vector<T>& vec, const string& filename, dv::configSaveToDisk config) {

gui/davis_gui.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,17 @@ void DavisGUI::visualizeFiles(const QStringList& file_list) {
889889
}
890890
}
891891
}
892+
double aspectW = 1;
893+
double aspectH = 1;
894+
QString paramWH;
895+
if (aspectW > aspectH) {
896+
paramWH = "width";
897+
} else {
898+
paramWH = "height";
899+
}
892900
QString multichartPage = dvs::kHtmlMultiChartModel;
893-
multichartPage = multichartPage.arg(dvs::kPlotlyJsName, all_chart_blocks, all_traces_names, "", "X", "Y");
901+
multichartPage = multichartPage.arg(dvs::kPlotlyJsName, all_chart_blocks, all_traces_names, "", "X", "Y",
902+
QString::number(aspectW), QString::number(aspectH), paramWH);
894903
qDebug() << multichartPage;
895904
dvs::saveStringToFile(dvs::kReportPagePath, multichartPage.toStdString());
896905
dvs::openFileBySystem(dvs::kReportPagePath);

0 commit comments

Comments
 (0)