Skip to content

deleting "surface" in code is done #159

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 1 commit into from
Mar 16, 2025
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
21 changes: 2 additions & 19 deletions Tests/ArrayCoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ TEST(ArrayCore, configurator) {
config.heatmap.title = "Тестовая матрица";
config.heatmap.colorSc = dv::COLORSCALE_YlGnBu;
bool result1 = dv::show(values, "HeatMap", config);
config.typeVisual = dv::VISUALTYPE_SURFACE;
config.surf.title = "This is Surface!!!";
bool result2 = dv::show(values, "Surface", config);
EXPECT_EQ(result1 && result2, true);
EXPECT_EQ(result1, true);
}

TEST(ArrayCore, showDefaultSettings) {
Expand Down Expand Up @@ -165,20 +162,6 @@ TEST(ArrayCore, showHeatMap1_AutoScale) {
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}};
auto config = dv::Config();
config.typeVisual = dv::VISUALTYPE_SURFACE;
config.surf.xLabel = "xLabel from Settings";
config.surf.yLabel = "yLabel from Settings";
config.surf.zLabel = "zLabel from Settings";
config.surf.title = "Title from Settings";
config.surf.colorSc = dv::config_colorscales::COLORSCALE_THERMAL;
bool result = dv::show(values, "showSurface", config);
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showPseudo2D) {
int rows = 5;
int cols = 3;
Expand Down Expand Up @@ -360,7 +343,7 @@ TEST(ArrayCore, testMyltiplyHoldOnOff) {

dv::holdOn();
dv::show(vec1, "titleHoldOn3");
dv::show(vec1, "titleHoldOn4");
dv::show(vec2, "titleHoldOn4");
dv::holdOff();

EXPECT_EQ(v1 && v2, true);
Expand Down
11 changes: 1 addition & 10 deletions Tests/PlotlyLibTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TEST(PlotlyMaker, CreateDefaultHeatMapHtmlPageTest) {
std::string str_page = "test_page";
auto config = dv::Config();
config.typeVisual = dv::VISUALTYPE_HEATMAP;
bool result = dvs::createHtmlPageWithPlotlyJS(testValues, str_page, config, dv::VISUALTYPE_HEATMAP);
bool result = dvs::createHtmlPageHeatmap(testValues, str_page, config);
std::ofstream out("example.html");
if (out.is_open()) {
out << str_page.c_str();
Expand Down Expand Up @@ -48,15 +48,6 @@ TEST(PlotlyMaker, ShowSunnyHeatMapHtmlPageTest) {
EXPECT_EQ(result, true);
}

TEST(PlotlyMaker, ShowThermalSurfaceHtmlPageTest) {
std::vector<std::vector<double>>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}};
std::string str_page = "ThermalSurfacePage";
auto config = dv::Config();
config.heatmap.colorSc = dv::config_colorscales::COLORSCALE_THERMAL;
bool result = dvs::showSurfaceInBrowser(testValues, str_page, config);
EXPECT_EQ(result, true);
}

TEST(PlotlyMaker, ShowWarnigJsAbsentPageTest) {
dvs::showWarningJsAbsentPage();
}
Expand Down
12 changes: 4 additions & 8 deletions array_core/array_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ bool show(T** data, uint64_t arrRows, uint64_t arrCols, const string& htmlPageNa
}
bool res = false;
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_HEATMAP)
configuration.typeVisual == VISUALTYPE_HEATMAP) {
res = dvs::showHeatMapInBrowser(vecVecDbl, htmlPageName, configuration);
else if (configuration.typeVisual == VISUALTYPE_SURFACE)
res = dvs::showSurfaceInBrowser(vecVecDbl, htmlPageName, configuration);
}
return res;
}

Expand All @@ -122,10 +121,9 @@ bool show(const T* data, uint64_t arrRows, uint64_t arrCols, const string& htmlP
}
bool res = false;
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_HEATMAP)
configuration.typeVisual == VISUALTYPE_HEATMAP) {
res = dvs::showHeatMapInBrowser(vecVecDbl, htmlPageName, configuration);
else if (configuration.typeVisual == VISUALTYPE_SURFACE)
res = dvs::showSurfaceInBrowser(vecVecDbl, htmlPageName, configuration);
}
return res;
}

Expand Down Expand Up @@ -260,8 +258,6 @@ bool show(C const& container_of_containers, const string& htmlPageName, const Co
} else if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_HEATMAP) {
res = dvs::showHeatMapInBrowser(vecVecDbl, htmlPageName, configuration);
} else if (configuration.typeVisual == VISUALTYPE_SURFACE) {
res = dvs::showSurfaceInBrowser(vecVecDbl, htmlPageName, configuration);
}
return res;
}
Expand Down
14 changes: 1 addition & 13 deletions array_core/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace dv {
enum config_visualizationTypes {
VISUALTYPE_AUTO, //if user not forces some specific type it will be recognized by context
VISUALTYPE_CHART,
VISUALTYPE_HEATMAP,
VISUALTYPE_SURFACE
VISUALTYPE_HEATMAP
};

enum config_colorscales {
Expand Down Expand Up @@ -52,28 +51,17 @@ struct heatMapSettings : public commonSettings {
config_colorscales colorSc;
};

struct surfaceSettings : public commonSettings {
surfaceSettings():
colorSc(config_colorscales::COLORSCALE_DEFAULT),
zLabel("Z") {}
config_colorscales colorSc;
std::string zLabel;
};


struct Config {
Config():
typeVisual(VISUALTYPE_AUTO) {}
void reset() {
chart = chartSettings();
heatmap = heatMapSettings();
surf = surfaceSettings();
}

chartSettings chart;
heatMapSettings heatmap;
surfaceSettings surf;

config_visualizationTypes typeVisual;
};

Expand Down
167 changes: 48 additions & 119 deletions davis_one/davis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,6 @@ hovertemplate: 'x:%{x} <br>y:%{y} <br>val:%{z:.}<extra></extra>',
colorbar: {
title: ""
}
}];)";

const char kSurfaceTypePart[]=R"(
type: 'surface',
hovertemplate: 'x:%{x} <br>y:%{y} <br>z:%{z:.}<extra></extra>',
colorbar: {
title: ""
}
}];)";

const char kWarningJSLibAbsentPage[] = R"(
Expand Down Expand Up @@ -1306,29 +1298,6 @@ bool createStringLineChartValues(const vector<double>& xValues,
return true;
}



inline bool heatmap_and_surface(const vector<vector<double>>& values,
const string& title,
const dv::Config& configuration,
dv::config_visualizationTypes typeVisual) {
string page;
if (!createHtmlPageWithPlotlyJS(values, page, configuration, typeVisual)) {
return false;
}
string pageName;
mayBeCreateJsWorkingFolder();
string titleWithoutSpecialChars = dvs::removeSpecialCharacters(title);
pageName.append("./").append(kOutFolderName).append(titleWithoutSpecialChars).append(".html");
saveStringToFile(pageName, page);
if (isPlotlyScriptExists()) {
openPlotlyHtml(pageName);
} else {
showWarningJsAbsentPage();
}
return true;// TODO handle different exceptions
};

bool getMatrixValuesFromString(const string& in_values,
vector<vector<double>>& out_values) {
istringstream f_lines(in_values);
Expand All @@ -1345,10 +1314,9 @@ bool getMatrixValuesFromString(const string& in_values,
return true;
};

bool createHtmlPageWithPlotlyJS(const std::vector<std::vector<double>>& values,
string& page,
const dv::Config& configuration,
dv::config_visualizationTypes typeVisual) {
bool createHtmlPageHeatmap(const std::vector<std::vector<double>>& values,
string& page,
const dv::Config& configuration) {
vector<string> args(ARGS_SIZE, "");
string str_values = "";
if (!checkThatSizesAreTheSame(values)) {
Expand All @@ -1357,13 +1325,37 @@ bool createHtmlPageWithPlotlyJS(const std::vector<std::vector<double>>& values,
createStringHeatMapValues(values, str_values);
args[ARG_VALUES] = str_values;
args[ARG_JS_VER] = kPlotlyJsName;
args[ARG_MATRIX_TYPE] = kHeatMapTypePart;
args[ARG_TITLE] = configuration.heatmap.title;
args[ARG_TITLE_X] = configuration.heatmap.xLabel;
args[ARG_TITLE_Y] = configuration.heatmap.yLabel;
args[ARG_ASPECT_RATIO_WIDTH] = dvs::toStringDotSeparator(configuration.heatmap.aspectRatioWidth);
args[ARG_ASPECT_RATIO_HEIGHT] = dvs::toStringDotSeparator(configuration.heatmap.aspectRatioHeight);
string paramWH;
if (configuration.heatmap.aspectRatioWidth > configuration.heatmap.aspectRatioHeight) {
paramWH = "width";
} else {
paramWH = "height";
}
string paramWHsecond;
if (configuration.heatmap.isFitPlotToWindow) {
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;
args[ARG_POINT_LINE_SWITCHER_STYLE] = kHtmlComboboxStyleBlock;
args[ARG_POINT_LINE_SWITCHER_SELECT] = kHtmlComboboxSelectSurfaceMatrixBlock;
args[ARG_POINT_LINE_SWITCHER_UPDATE_FOO] = kHtmlComboboxUpdateSurfaceMatrixFooBlock;
args[ARG_DAVIS_LOGO] = kHtmlDavisLogoHyperlinkBlock;

dv::config_colorscales clrScale;
if (typeVisual == dv::VISUALTYPE_HEATMAP)
clrScale = configuration.heatmap.colorSc;
else if (typeVisual == dv::VISUALTYPE_SURFACE)
clrScale = configuration.surf.colorSc;
else
return false;
clrScale = configuration.heatmap.colorSc;
switch (clrScale) {
case dv::config_colorscales::COLORSCALE_DEFAULT:
args[ARG_COLOR_MAP] = kColorMapDefaultPart;
Expand Down Expand Up @@ -1396,78 +1388,28 @@ bool createHtmlPageWithPlotlyJS(const std::vector<std::vector<double>>& values,
args[ARG_COLOR_MAP] = kColorMapPortlandPart;
break;
}
switch (typeVisual) {
case dv::VISUALTYPE_HEATMAP: {
args[ARG_MATRIX_TYPE] = kHeatMapTypePart;
args[ARG_TITLE] = configuration.heatmap.title;
args[ARG_TITLE_X] = configuration.heatmap.xLabel;
args[ARG_TITLE_Y] = configuration.heatmap.yLabel;
args[ARG_ASPECT_RATIO_WIDTH] = dvs::toStringDotSeparator(configuration.heatmap.aspectRatioWidth);
args[ARG_ASPECT_RATIO_HEIGHT] = dvs::toStringDotSeparator(configuration.heatmap.aspectRatioHeight);
string paramWH;
if (configuration.heatmap.aspectRatioWidth > configuration.heatmap.aspectRatioHeight) {
paramWH = "width";
} else {
paramWH = "height";
}
string paramWHsecond;
if (configuration.heatmap.isFitPlotToWindow) {
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;
args[ARG_POINT_LINE_SWITCHER_STYLE] = kHtmlComboboxStyleBlock;
args[ARG_POINT_LINE_SWITCHER_SELECT] = kHtmlComboboxSelectSurfaceMatrixBlock;
args[ARG_POINT_LINE_SWITCHER_UPDATE_FOO] = kHtmlComboboxUpdateSurfaceMatrixFooBlock;
args[ARG_DAVIS_LOGO] = kHtmlDavisLogoHyperlinkBlock;
break;
}
case dv::VISUALTYPE_SURFACE: {
args[ARG_MATRIX_TYPE] = kSurfaceTypePart;
args[ARG_TITLE] = configuration.surf.title;
args[ARG_TITLE_X] = configuration.surf.xLabel;
args[ARG_TITLE_Y] = configuration.surf.yLabel;
args[ARG_TITLE_Z] = configuration.surf.zLabel;
args[ARG_ASPECT_RATIO_WIDTH] = dvs::toStringDotSeparator(configuration.surf.aspectRatioWidth);
args[ARG_ASPECT_RATIO_HEIGHT] = dvs::toStringDotSeparator(configuration.surf.aspectRatioHeight);
string paramWH;
if (configuration.surf.aspectRatioWidth > configuration.surf.aspectRatioHeight) {
paramWH = "width";
} else {
paramWH = "height";
}
string paramWHsecond;
if (configuration.surf.isFitPlotToWindow) {
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;
args[ARG_DAVIS_LOGO] = kHtmlDavisLogoHyperlinkBlock;
break;
}
default:
break;
}

make_string(kHtmlModel, args, page);
return true;
}

bool showHeatMapInBrowser(const vector<vector<double>>& values,
const string& title, const dv::Config& configuration) {
return heatmap_and_surface(values, title, configuration, dv::VISUALTYPE_HEATMAP);
string page;
if (!createHtmlPageHeatmap(values, page, configuration)) {
return false;
}
string pageName;
mayBeCreateJsWorkingFolder();
string titleWithoutSpecialChars = dvs::removeSpecialCharacters(title);
pageName.append("./").append(kOutFolderName).append(titleWithoutSpecialChars).append(".html");
saveStringToFile(pageName, page);
if (isPlotlyScriptExists()) {
openPlotlyHtml(pageName);
} else {
showWarningJsAbsentPage();
}
return true;// TODO handle different exceptions
}

bool showHeatMapInBrowser(const string& values,
Expand Down Expand Up @@ -1548,19 +1490,6 @@ bool showLineChartInBrowser(const string& values,
return true;
};

bool showSurfaceInBrowser(const vector<vector<double>>& values,
const string& title, const dv::Config& configuration) {
return heatmap_and_surface(values, title, configuration, dv::VISUALTYPE_SURFACE);
}

bool showSurfaceInBrowser(const string& values,
const string& title, const dv::Config& configuration) {
vector<vector<double>>surface_values;
getMatrixValuesFromString(values, surface_values);
showSurfaceInBrowser(surface_values, title, configuration);
return true;
}

void showWarningJsAbsentPage() {
string out;
string davis_dir;
Expand Down
Loading