Skip to content

Commit 87fd857

Browse files
authored
Plot Fit to window in GUI and dv::show (#147)
1 parent dc31483 commit 87fd857

File tree

11 files changed

+265
-55
lines changed

11 files changed

+265
-55
lines changed

Tests/ArrayCoreTest.cpp

Lines changed: 14 additions & 3 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,8 +141,8 @@ TEST(ArrayCore, showDefaultSettings) {
141141
bool result = dv::show(values, "testDefaultSettings");
142142
EXPECT_EQ(result, true);
143143
}
144-
*/
145-
TEST(ArrayCore, showHeatMap1) {
144+
145+
TEST(ArrayCore, showHeatMap1_customAspectRatio) {
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();
@@ -154,6 +154,17 @@ TEST(ArrayCore, showHeatMap1) {
154154
EXPECT_EQ(result, true);
155155
}
156156

157+
TEST(ArrayCore, showHeatMap1_AutoScale) {
158+
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
159+
vector<vector<double>> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
160+
auto config = dv::Config();
161+
config.heatmap.title = "Black & White TEST MATRIX";
162+
config.heatmap.colorSc = dv::config_colorscales::COLORSCALE_GRAYSCALE;
163+
config.heatmap.isAutoScale = true;
164+
bool result = dv::show(values, "showHeatMap_AutoScale", config);
165+
EXPECT_EQ(result, true);
166+
}
167+
157168
TEST(ArrayCore, showSurface) {
158169
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
159170
vector<vector<double>> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};

array_core/configurator.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ struct commonSettings {
3131
xLabel("X"),
3232
yLabel("Y"),
3333
aspectRatioWidth(1),
34-
aspectRatioHeight(1) {}
34+
aspectRatioHeight(1),
35+
isAutoScale(false) {}
3536
virtual ~commonSettings() {}
3637
std::string title;
3738
std::string xLabel;
3839
std::string yLabel;
39-
double aspectRatioWidth;
40-
double aspectRatioHeight;
40+
double aspectRatioWidth; // use it for user scale if isAutoScale = false
41+
double aspectRatioHeight;// use it for user scale if isAutoScale = false
42+
bool isAutoScale; //true - plot fits to browser window, false - square plot
4143
};
4244

4345
struct chartSettings : public commonSettings {

array_core/multi_plot.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,21 @@ void holdOff(const Config& configuration) {
4545
} else {
4646
paramWH = "height";
4747
}
48+
string paramWHsecond;
49+
if (configuration.chart.isAutoScale) {
50+
if (paramWH == "width") {
51+
paramWHsecond = "height";
52+
} else if (paramWH == "height") {
53+
paramWHsecond = "width";
54+
}
55+
} else {
56+
paramWHsecond = paramWH;
57+
}
4858
vector<string> args = {dvs::kPlotlyJsName, allChartBlocks_str, allTracesNames_str,
4959
configuration.chart.title, configuration.chart.xLabel, configuration.chart.yLabel,
5060
dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth),
5161
dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight),
52-
paramWH
62+
paramWH, paramWHsecond
5363
};
5464
string multichartPage = dvs::kHtmlMultiChartModel;
5565
string filled_multichartPage = "";

davis_one/davis.cpp

Lines changed: 87 additions & 8 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="%11:99%; aspect-ratio: %9/%10;"
45+
justify-content: center;"><div style="%11:99%; %12: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="%6:99%; aspect-ratio: %4/%5;"
371+
justify-content: center;"><div style="%6:99%; %7: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="%9:99%; aspect-ratio: %7/%8;"
416+
justify-content: center;"><div style="%9:99%; %10: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="%7:99%; aspect-ratio: %5/%6;"
473+
justify-content: center;"><div style="%7:99%; %8:99%; aspect-ratio: %5/%6;"
474474
id="gd"></div></div>
475475
<script>
476476
var trace = {
@@ -1023,7 +1023,18 @@ bool createHtmlPageWithPlotlyJS(const std::vector<std::vector<double>>& values,
10231023
} else {
10241024
paramWH = "height";
10251025
}
1026+
string paramWHsecond;
1027+
if (configuration.heatmap.isAutoScale) {
1028+
if (paramWH == "width") {
1029+
paramWHsecond = "height";
1030+
} else if (paramWH == "height") {
1031+
paramWHsecond = "width";
1032+
}
1033+
} else {
1034+
paramWHsecond = paramWH;
1035+
}
10261036
args[ARG_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
1037+
args[ARG_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
10271038
break;
10281039
}
10291040
case dv::VISUALTYPE_SURFACE: {
@@ -1040,7 +1051,18 @@ bool createHtmlPageWithPlotlyJS(const std::vector<std::vector<double>>& values,
10401051
} else {
10411052
paramWH = "height";
10421053
}
1054+
string paramWHsecond;
1055+
if (configuration.surf.isAutoScale) {
1056+
if (paramWH == "width") {
1057+
paramWHsecond = "height";
1058+
} else if (paramWH == "height") {
1059+
paramWHsecond = "width";
1060+
}
1061+
} else {
1062+
paramWHsecond = paramWH;
1063+
}
10431064
args[ARG_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
1065+
args[ARG_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
10441066
break;
10451067
}
10461068
default:
@@ -1092,7 +1114,18 @@ bool showLineChartInBrowser(const vector<double>& xValues, const vector<double>&
10921114
} else {
10931115
paramWH = "height";
10941116
}
1117+
string paramWHsecond;
1118+
if (configuration.chart.isAutoScale) {
1119+
if (paramWH == "width") {
1120+
paramWHsecond = "height";
1121+
} else if (paramWH == "height") {
1122+
paramWHsecond = "width";
1123+
}
1124+
} else {
1125+
paramWHsecond = paramWH;
1126+
}
10951127
args[ARG_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
1128+
args[ARG_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
10961129
make_string(kHtmlModel, args, page);
10971130
string pageName;
10981131
mayBeCreateJsWorkingFolder();
@@ -1196,7 +1229,8 @@ void showMatrixSizesAreNotTheSame(int badRow) {
11961229
}
11971230

11981231
void showDateTimeChart(const string& date_time_values,
1199-
const vector<double>& yValues) {
1232+
const vector<double>& yValues,
1233+
bool isAutoScale) {
12001234

12011235
string out;
12021236
string davis_dir;
@@ -1230,7 +1264,18 @@ void showDateTimeChart(const string& date_time_values,
12301264
}
12311265
*/
12321266
string paramWH = "height";
1267+
string paramWHsecond;
1268+
if (isAutoScale) {
1269+
if (paramWH == "width") {
1270+
paramWHsecond = "height";
1271+
} else if (paramWH == "height") {
1272+
paramWHsecond = "width";
1273+
}
1274+
} else {
1275+
paramWHsecond = paramWH;
1276+
}
12331277
args[ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
1278+
args[ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
12341279
make_string(kHtmlDateTimeModel, args, out);
12351280
saveStringToFile(kReportPagePath, out);
12361281
openFileBySystem(kReportPagePath);
@@ -1259,7 +1304,8 @@ void addTraceBlockToGlobal(const vector<double>& xValues, const vector<double>&
12591304

12601305
void showCloudOfPointsChart(const vector<double>& xValues,
12611306
const vector<double>& yValues,
1262-
const vector<double>& colorValues) {
1307+
const vector<double>& colorValues,
1308+
bool isAutoScale) {
12631309
string out;
12641310
string davis_dir;
12651311
#ifdef _WIN32
@@ -1283,6 +1329,17 @@ void showCloudOfPointsChart(const vector<double>& xValues,
12831329
}
12841330
*/
12851331
string paramWH = "height";
1332+
string paramWHsecond;
1333+
if (isAutoScale) {
1334+
if (paramWH == "width") {
1335+
paramWHsecond = "height";
1336+
} else if (paramWH == "height") {
1337+
paramWHsecond = "width";
1338+
}
1339+
} else {
1340+
paramWHsecond = paramWH;
1341+
}
1342+
args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
12861343
args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
12871344
make_string(kHtmlCloudOfPoints, args, out);
12881345
saveStringToFile(kCloudPagePath, out);
@@ -1291,7 +1348,8 @@ void showCloudOfPointsChart(const vector<double>& xValues,
12911348

12921349
void showCloudOfPointsChartStr(const std::string& xValues,
12931350
const vector<double>& yValues,
1294-
const vector<double>& colorValues) {
1351+
const vector<double>& colorValues,
1352+
bool isAutoScale) {
12951353
string out;
12961354
string davis_dir;
12971355
#ifdef _WIN32
@@ -1315,6 +1373,17 @@ void showCloudOfPointsChartStr(const std::string& xValues,
13151373
}
13161374
*/
13171375
string paramWH = "height";
1376+
string paramWHsecond;
1377+
if (isAutoScale) {
1378+
if (paramWH == "width") {
1379+
paramWHsecond = "height";
1380+
} else if (paramWH == "height") {
1381+
paramWHsecond = "width";
1382+
}
1383+
} else {
1384+
paramWHsecond = paramWH;
1385+
}
1386+
args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
13181387
args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
13191388
make_string(kHtmlCloudOfPoints, args, out);
13201389
saveStringToFile(kCloudPagePath, out);
@@ -1363,11 +1432,21 @@ void holdOff(const Config& configuration) {
13631432
} else {
13641433
paramWH = "height";
13651434
}
1435+
string paramWHsecond;
1436+
if (configuration.chart.isAutoScale) {
1437+
if (paramWH == "width") {
1438+
paramWHsecond = "height";
1439+
} else if (paramWH == "height") {
1440+
paramWHsecond = "width";
1441+
}
1442+
} else {
1443+
paramWHsecond = paramWH;
1444+
}
13661445
vector<string> args = {dvs::kPlotlyJsName, allChartBlocks_str, allTracesNames_str,
13671446
configuration.chart.title, configuration.chart.xLabel, configuration.chart.yLabel,
13681447
dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth),
13691448
dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight),
1370-
paramWH
1449+
paramWH, paramWHsecond
13711450
};
13721451
string multichartPage = dvs::kHtmlMultiChartModel;
13731452
string filled_multichartPage = "";

davis_one/davis.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ struct commonSettings {
5757
xLabel("X"),
5858
yLabel("Y"),
5959
aspectRatioWidth(1),
60-
aspectRatioHeight(1) {}
60+
aspectRatioHeight(1),
61+
isAutoScale(false) {}
6162
virtual ~commonSettings() {}
6263
std::string title;
6364
std::string xLabel;
6465
std::string yLabel;
65-
double aspectRatioWidth;
66-
double aspectRatioHeight;
66+
double aspectRatioWidth; // use it for user scale if isAutoScale = false
67+
double aspectRatioHeight;// use it for user scale if isAutoScale = false
68+
bool isAutoScale; //true - plot fits to browser window, false - square plot
6769
};
6870

6971
struct chartSettings : public commonSettings {
@@ -127,7 +129,8 @@ enum ARGS_INDEX {
127129
ARG_JS_VER, //%8
128130
ARG_ASPECT_RATIO_WIDTH, //%9
129131
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
132+
ARG_ASPECT_WIDTH_OR_HEIGHT, //%11 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
133+
ARG_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%12 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale.
131134
// ADD NEW ENUM BEFORE THIS COMMENT
132135
ARGS_SIZE
133136
};
@@ -155,6 +158,7 @@ enum ARGS_DATE_TIME_PAGE_INDEX {
155158
ARG_DATE_TIME_ASPECT_RATIO_WIDTH, //%4
156159
ARG_DATE_TIME_ASPECT_RATIO_HEIGHT, //%5
157160
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.
158162

159163
// ADD NEW ENUM BEFORE THIS COMMENT
160164
ARGS_DATE_TIME_PAGE_SIZE
@@ -171,6 +175,7 @@ enum ARGS_MULTI_CHARTS_PAGE {
171175
ARG_MC_DATE_TIME_ASPECT_RATIO_WIDTH, //%7
172176
ARG_MC_DATE_TIME_ASPECT_RATIO_HEIGHT, //%8
173177
ARG_MC_DATE_ASPECT_WIDTH_OR_HEIGHT, //%9 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
178+
ARG_MC_DATE_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%10 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale.
174179

175180
// ADD NEW ENUM BEFORE THIS COMMENT
176181
ARGS_MULTI_CHARTS_PAGE_SIZE
@@ -184,6 +189,8 @@ enum ARGS_CLOUD_OF_POINTS_PAGE {
184189
ARG_CLOUD_OF_POINTS_ASPECT_RATIO_WIDTH, //%5
185190
ARG_CLOUD_OF_POINTS_ASPECT_RATIO_HEIGHT, //%6
186191
ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT, //7 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
192+
ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%8 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale.
193+
187194
// ADD NEW ENUM BEFORE THIS COMMENT
188195
ARGS_CLOUD_OF_POINTS_PAGE_SIZE
189196
};
@@ -406,19 +413,22 @@ void showReportFileEmpty();
406413
void showMatrixSizesAreNotTheSame(int badRow);
407414

408415
void showDateTimeChart(const string& date_time_values,
409-
const vector<double>& yValues);
416+
const vector<double>& yValues,
417+
bool isAutoScale);
410418

411419
void addTraceBlockToGlobal(const vector<double>& yValues, const string& traceName);
412420
void addTraceBlockToGlobal(const vector<double>& xValues, const vector<double>& yValues, const string& traceName);
413421

414422
void showCloudOfPointsChart(const vector<double>& xValues,
415423
const vector<double>& yValues,
416-
const vector<double>& colorValues);
424+
const vector<double>& colorValues,
425+
bool isAutoScale);
417426

418427

419428
void showCloudOfPointsChartStr(const string& xValues,
420429
const vector<double>& yValues,
421-
const vector<double>& colorValues);
430+
const vector<double>& colorValues,
431+
bool isAutoScale);
422432

423433

424434
} // namespace dvs end

0 commit comments

Comments
 (0)