Skip to content

Plot Fit to window in GUI and dv::show #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Tests/ArrayCoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

using std::string;
using std::vector;
/*

TEST(ArrayCore, save_to_disk_2d) {
//! 2-dimensional array
int rows = 10;
Expand Down Expand Up @@ -141,8 +141,8 @@ TEST(ArrayCore, showDefaultSettings) {
bool result = dv::show(values, "testDefaultSettings");
EXPECT_EQ(result, true);
}
*/
TEST(ArrayCore, showHeatMap1) {

TEST(ArrayCore, showHeatMap1_customAspectRatio) {
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
vector<vector<double>> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
auto config = dv::Config();
Expand All @@ -154,6 +154,17 @@ TEST(ArrayCore, showHeatMap1) {
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showHeatMap1_AutoScale) {
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
vector<vector<double>> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
auto config = dv::Config();
config.heatmap.title = "Black & White TEST MATRIX";
config.heatmap.colorSc = dv::config_colorscales::COLORSCALE_GRAYSCALE;
config.heatmap.isAutoScale = true;
bool result = dv::show(values, "showHeatMap_AutoScale", config);
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showSurface) {
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
vector<vector<double>> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
Expand Down
8 changes: 5 additions & 3 deletions array_core/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ struct commonSettings {
xLabel("X"),
yLabel("Y"),
aspectRatioWidth(1),
aspectRatioHeight(1) {}
aspectRatioHeight(1),
isAutoScale(false) {}
virtual ~commonSettings() {}
std::string title;
std::string xLabel;
std::string yLabel;
double aspectRatioWidth;
double aspectRatioHeight;
double aspectRatioWidth; // use it for user scale if isAutoScale = false
double aspectRatioHeight;// use it for user scale if isAutoScale = false
bool isAutoScale; //true - plot fits to browser window, false - square plot
};

struct chartSettings : public commonSettings {
Expand Down
12 changes: 11 additions & 1 deletion array_core/multi_plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,21 @@ void holdOff(const Config& configuration) {
} else {
paramWH = "height";
}
string paramWHsecond;
if (configuration.chart.isAutoScale) {
if (paramWH == "width") {
paramWHsecond = "height";
} else if (paramWH == "height") {
paramWHsecond = "width";
}
} else {
paramWHsecond = paramWH;
}
vector<string> args = {dvs::kPlotlyJsName, allChartBlocks_str, allTracesNames_str,
configuration.chart.title, configuration.chart.xLabel, configuration.chart.yLabel,
dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth),
dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight),
paramWH
paramWH, paramWHsecond
};
string multichartPage = dvs::kHtmlMultiChartModel;
string filled_multichartPage = "";
Expand Down
95 changes: 87 additions & 8 deletions davis_one/davis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ R"(
</head>
<body><div style = "display: flex;
align-items:center;height:100%; width:100%;background:#dddfd4;
justify-content: center;"><div style="%11:99%; aspect-ratio: %9/%10;"
justify-content: center;"><div style="%11:99%; %12:99%; aspect-ratio: %9/%10;"
id="gd"></div></div>
<script>
%1
Expand Down Expand Up @@ -368,7 +368,7 @@ extern const char kHtmlDateTimeModel[] = R"davis_delimeter(
</head>
<body><div style = "display: flex;
align-items:center;height:100%; width:100%;background:#dddfd4;
justify-content: center;"><div style="%6:99%; aspect-ratio: %4/%5;"
justify-content: center;"><div style="%6:99%; %7:99%; aspect-ratio: %4/%5;"
id="gd"></div></div>

<script>
Expand Down Expand Up @@ -413,7 +413,7 @@ extern const char kHtmlMultiChartModel[] = R"davis_delimeter(
</head>
<body><div style = "display: flex;
align-items:center;height:100%; width:100%;background:#dddfd4;
justify-content: center;"><div style="%9:99%; aspect-ratio: %7/%8;"
justify-content: center;"><div style="%9:99%; %10:99%; aspect-ratio: %7/%8;"
id="gd"></div></div>
<script>

Expand Down Expand Up @@ -470,7 +470,7 @@ extern const char kHtmlCloudOfPoints[] = R"davis_delimeter(
</head>
<body><div style = "display: flex;
align-items:center;height:100%; width:100%;background:#dddfd4;
justify-content: center;"><div style="%7:99%; aspect-ratio: %5/%6;"
justify-content: center;"><div style="%7:99%; %8:99%; aspect-ratio: %5/%6;"
id="gd"></div></div>
<script>
var trace = {
Expand Down Expand Up @@ -1023,7 +1023,18 @@ bool createHtmlPageWithPlotlyJS(const std::vector<std::vector<double>>& values,
} else {
paramWH = "height";
}
string paramWHsecond;
if (configuration.heatmap.isAutoScale) {
if (paramWH == "width") {
paramWHsecond = "height";
} else if (paramWH == "height") {
paramWHsecond = "width";
}
} else {
paramWHsecond = paramWH;
}
args[ARG_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
args[ARG_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
break;
}
case dv::VISUALTYPE_SURFACE: {
Expand All @@ -1040,7 +1051,18 @@ bool createHtmlPageWithPlotlyJS(const std::vector<std::vector<double>>& values,
} else {
paramWH = "height";
}
string paramWHsecond;
if (configuration.surf.isAutoScale) {
if (paramWH == "width") {
paramWHsecond = "height";
} else if (paramWH == "height") {
paramWHsecond = "width";
}
} else {
paramWHsecond = paramWH;
}
args[ARG_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
args[ARG_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
break;
}
default:
Expand Down Expand Up @@ -1092,7 +1114,18 @@ bool showLineChartInBrowser(const vector<double>& xValues, const vector<double>&
} else {
paramWH = "height";
}
string paramWHsecond;
if (configuration.chart.isAutoScale) {
if (paramWH == "width") {
paramWHsecond = "height";
} else if (paramWH == "height") {
paramWHsecond = "width";
}
} else {
paramWHsecond = paramWH;
}
args[ARG_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
args[ARG_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
make_string(kHtmlModel, args, page);
string pageName;
mayBeCreateJsWorkingFolder();
Expand Down Expand Up @@ -1196,7 +1229,8 @@ void showMatrixSizesAreNotTheSame(int badRow) {
}

void showDateTimeChart(const string& date_time_values,
const vector<double>& yValues) {
const vector<double>& yValues,
bool isAutoScale) {

string out;
string davis_dir;
Expand Down Expand Up @@ -1230,7 +1264,18 @@ void showDateTimeChart(const string& date_time_values,
}
*/
string paramWH = "height";
string paramWHsecond;
if (isAutoScale) {
if (paramWH == "width") {
paramWHsecond = "height";
} else if (paramWH == "height") {
paramWHsecond = "width";
}
} else {
paramWHsecond = paramWH;
}
args[ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
args[ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
make_string(kHtmlDateTimeModel, args, out);
saveStringToFile(kReportPagePath, out);
openFileBySystem(kReportPagePath);
Expand Down Expand Up @@ -1259,7 +1304,8 @@ void addTraceBlockToGlobal(const vector<double>& xValues, const vector<double>&

void showCloudOfPointsChart(const vector<double>& xValues,
const vector<double>& yValues,
const vector<double>& colorValues) {
const vector<double>& colorValues,
bool isAutoScale) {
string out;
string davis_dir;
#ifdef _WIN32
Expand All @@ -1283,6 +1329,17 @@ void showCloudOfPointsChart(const vector<double>& xValues,
}
*/
string paramWH = "height";
string paramWHsecond;
if (isAutoScale) {
if (paramWH == "width") {
paramWHsecond = "height";
} else if (paramWH == "height") {
paramWHsecond = "width";
}
} else {
paramWHsecond = paramWH;
}
args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
make_string(kHtmlCloudOfPoints, args, out);
saveStringToFile(kCloudPagePath, out);
Expand All @@ -1291,7 +1348,8 @@ void showCloudOfPointsChart(const vector<double>& xValues,

void showCloudOfPointsChartStr(const std::string& xValues,
const vector<double>& yValues,
const vector<double>& colorValues) {
const vector<double>& colorValues,
bool isAutoScale) {
string out;
string davis_dir;
#ifdef _WIN32
Expand All @@ -1315,6 +1373,17 @@ void showCloudOfPointsChartStr(const std::string& xValues,
}
*/
string paramWH = "height";
string paramWHsecond;
if (isAutoScale) {
if (paramWH == "width") {
paramWHsecond = "height";
} else if (paramWH == "height") {
paramWHsecond = "width";
}
} else {
paramWHsecond = paramWH;
}
args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
make_string(kHtmlCloudOfPoints, args, out);
saveStringToFile(kCloudPagePath, out);
Expand Down Expand Up @@ -1363,11 +1432,21 @@ void holdOff(const Config& configuration) {
} else {
paramWH = "height";
}
string paramWHsecond;
if (configuration.chart.isAutoScale) {
if (paramWH == "width") {
paramWHsecond = "height";
} else if (paramWH == "height") {
paramWHsecond = "width";
}
} else {
paramWHsecond = paramWH;
}
vector<string> args = {dvs::kPlotlyJsName, allChartBlocks_str, allTracesNames_str,
configuration.chart.title, configuration.chart.xLabel, configuration.chart.yLabel,
dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth),
dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight),
paramWH
paramWH, paramWHsecond
};
string multichartPage = dvs::kHtmlMultiChartModel;
string filled_multichartPage = "";
Expand Down
24 changes: 17 additions & 7 deletions davis_one/davis.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ struct commonSettings {
xLabel("X"),
yLabel("Y"),
aspectRatioWidth(1),
aspectRatioHeight(1) {}
aspectRatioHeight(1),
isAutoScale(false) {}
virtual ~commonSettings() {}
std::string title;
std::string xLabel;
std::string yLabel;
double aspectRatioWidth;
double aspectRatioHeight;
double aspectRatioWidth; // use it for user scale if isAutoScale = false
double aspectRatioHeight;// use it for user scale if isAutoScale = false
bool isAutoScale; //true - plot fits to browser window, false - square plot
};

struct chartSettings : public commonSettings {
Expand Down Expand Up @@ -127,7 +129,8 @@ enum ARGS_INDEX {
ARG_JS_VER, //%8
ARG_ASPECT_RATIO_WIDTH, //%9
ARG_ASPECT_RATIO_HEIGHT, //%10
ARG_ASPECT_WIDTH_OR_HEIGHT, //11 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
ARG_ASPECT_WIDTH_OR_HEIGHT, //%11 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
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.
// ADD NEW ENUM BEFORE THIS COMMENT
ARGS_SIZE
};
Expand Down Expand Up @@ -155,6 +158,7 @@ enum ARGS_DATE_TIME_PAGE_INDEX {
ARG_DATE_TIME_ASPECT_RATIO_WIDTH, //%4
ARG_DATE_TIME_ASPECT_RATIO_HEIGHT, //%5
ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT, //%6 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
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.

// ADD NEW ENUM BEFORE THIS COMMENT
ARGS_DATE_TIME_PAGE_SIZE
Expand All @@ -171,6 +175,7 @@ enum ARGS_MULTI_CHARTS_PAGE {
ARG_MC_DATE_TIME_ASPECT_RATIO_WIDTH, //%7
ARG_MC_DATE_TIME_ASPECT_RATIO_HEIGHT, //%8
ARG_MC_DATE_ASPECT_WIDTH_OR_HEIGHT, //%9 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
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.

// ADD NEW ENUM BEFORE THIS COMMENT
ARGS_MULTI_CHARTS_PAGE_SIZE
Expand All @@ -184,6 +189,8 @@ enum ARGS_CLOUD_OF_POINTS_PAGE {
ARG_CLOUD_OF_POINTS_ASPECT_RATIO_WIDTH, //%5
ARG_CLOUD_OF_POINTS_ASPECT_RATIO_HEIGHT, //%6
ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT, //7 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
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.

// ADD NEW ENUM BEFORE THIS COMMENT
ARGS_CLOUD_OF_POINTS_PAGE_SIZE
};
Expand Down Expand Up @@ -406,19 +413,22 @@ void showReportFileEmpty();
void showMatrixSizesAreNotTheSame(int badRow);

void showDateTimeChart(const string& date_time_values,
const vector<double>& yValues);
const vector<double>& yValues,
bool isAutoScale);

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

void showCloudOfPointsChart(const vector<double>& xValues,
const vector<double>& yValues,
const vector<double>& colorValues);
const vector<double>& colorValues,
bool isAutoScale);


void showCloudOfPointsChartStr(const string& xValues,
const vector<double>& yValues,
const vector<double>& colorValues);
const vector<double>& colorValues,
bool isAutoScale);


} // namespace dvs end
Expand Down
Loading
Loading