Skip to content

Commit

Permalink
all work
Browse files Browse the repository at this point in the history
wip

wip

change tests

adding 2d megatemplate

WIP

delete vector implementation

del include

change settings struct

FINISH!

fix lack of surface settings in html

formatting

fixes for Davis-one-hdr

small fix
  • Loading branch information
AntonMrt committed Jun 4, 2024
1 parent cfc9d53 commit 9f626cf
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 160 deletions.
26 changes: 14 additions & 12 deletions Tests/ArrayCoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ TEST(ArrayCore, configurator) {
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
vector<vector<double>> values = {{30.312345, 40, 98, 76}, {-20.12, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
auto config = dv::Config();
dv::commonSettings comS;
comS.xLabel = "Столбцы";
comS.yLabel = "Строки";
comS.title = "Тестовая матрица";
config.common = comS;
config.heatmap.xLabel = "Столбцы";
config.heatmap.yLabel = "Строки";
config.heatmap.title = "Тестовая матрица";
config.heatmap.colorSc = dv::COLORSCALE_GLAMOUR;
bool result1 = dv::show(values, "HeatMap", config);
config.common.typeVisual = dv::VISUALTYPE_SURFACE;
config.common.title = "This is Surface!!!";
config.typeVisual = dv::VISUALTYPE_SURFACE;
config.surf.title = "This is Surface!!!";
bool result2 = dv::show(values, "Surface", config);
EXPECT_EQ(result1 && result2, true);
}
Expand All @@ -50,7 +48,7 @@ TEST(ArrayCore, showHeatMap1) {
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.common.title = "Black & White TEST MATRIX";
config.heatmap.title = "Black & White TEST MATRIX";
config.heatmap.colorSc = dv::config_colorscales::COLORSCALE_GRAYSCALE;
bool result = dv::show(values, "showHeatMap_gray", config);
EXPECT_EQ(result, true);
Expand All @@ -60,7 +58,11 @@ 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.common.typeVisual = dv::VISUALTYPE_SURFACE;
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);
Expand Down Expand Up @@ -102,9 +104,9 @@ TEST(ArrayCore, testChartDefault) {
TEST(ArrayCore, showChart) {
int vals3[] = {2, 6, 4, -34, 56, 33, 2, 15};
auto config = dv::Config();
config.common.title = "Custom title";
config.common.xLabel = "Custom xLabel";
config.common.yLabel = "Custom yLabel";
config.chart.title = "Custom title";
config.chart.xLabel = "Custom xLabel";
config.chart.yLabel = "Custom yLabel";
bool result = dv::show(vals3, sizeof(vals3) / sizeof(vals3[0]), "showChart", config);
EXPECT_EQ(result, true);
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/PlotlyLibTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ TEST(PlotlyMaker, CreateDefaultHeatMapHtmlPageTest) {
std::vector<std::vector<double>>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}};
std::string str_page = "test_page";
auto config = dv::Config();
config.common.typeVisual = dv::VISUALTYPE_HEATMAP;
config.typeVisual = dv::VISUALTYPE_HEATMAP;
bool result = dvs::createHtmlPageWithPlotlyJS(testValues, str_page, config, dv::VISUALTYPE_HEATMAP);
std::ofstream out("example.html");
if (out.is_open()) {
Expand Down
26 changes: 13 additions & 13 deletions array_core/array_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ bool show(T** data, uint64_t arrRows, uint64_t arrCols, const string& htmlPageNa
vecVecDbl.emplace_back(dblRow);
}
bool res = false;
if (configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_AUTO ||
configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_HEATMAP)
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_HEATMAP)
res = dvs::showHeatMapInBrowser(vecVecDbl, htmlPageName, configuration);
else if (configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_SURFACE)
else if (configuration.typeVisual == VISUALTYPE_SURFACE)
res = dvs::showSurfaceInBrowser(vecVecDbl, htmlPageName, configuration);
return res;
}
Expand All @@ -73,10 +73,10 @@ bool show(const T* data, uint64_t arrRows, uint64_t arrCols, const string& htmlP
vecVecDbl.emplace_back(dblRow);
}
bool res = false;
if (configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_AUTO ||
configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_HEATMAP)
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_HEATMAP)
res = dvs::showHeatMapInBrowser(vecVecDbl, htmlPageName, configuration);
else if (configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_SURFACE)
else if (configuration.typeVisual == VISUALTYPE_SURFACE)
res = dvs::showSurfaceInBrowser(vecVecDbl, htmlPageName, configuration);
return res;
}
Expand All @@ -85,8 +85,8 @@ template <typename T>
bool show(const T* data, uint64_t count, const string& htmlPageName, const Config& configuration) {
vector<double> dblRow(data, data + count);
bool res = false;
if (configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_AUTO ||
configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_CHART)
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_CHART)
res = dvs::showLineChartInBrowser(dblRow, htmlPageName, configuration);
return res;
}
Expand All @@ -100,8 +100,8 @@ bool show(C const& container, const string& htmlPageName, const Config& configur
++i;
}
bool res = false;
if (configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_AUTO ||
configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_CHART)
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_CHART)
res = dvs::showLineChartInBrowser(dblRow, htmlPageName, configuration);
return res;
}
Expand All @@ -121,10 +121,10 @@ bool show(C const& container_of_containers, const string& htmlPageName, const Co
}

bool res = false;
if (configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_AUTO ||
configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_HEATMAP) {
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_HEATMAP) {
res = dvs::showHeatMapInBrowser(vecVecDbl, htmlPageName, configuration);
} else if (configuration.common.typeVisual == config_visualizationTypes::VISUALTYPE_SURFACE)
} else if (configuration.typeVisual == VISUALTYPE_SURFACE)
res = dvs::showSurfaceInBrowser(vecVecDbl, htmlPageName, configuration);
return res;
}
Expand Down
26 changes: 15 additions & 11 deletions array_core/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,45 @@ enum config_colorscales {


struct commonSettings {
commonSettings(): typeVisual(config_visualizationTypes::VISUALTYPE_AUTO), xLabel("X"), yLabel("Y") {}
config_visualizationTypes typeVisual;
commonSettings(): xLabel("X_default"),
yLabel("Y_default") {}
virtual ~commonSettings() {}
std::string title;
std::string xLabel;
std::string yLabel;
};

struct chartSettings {

struct chartSettings : public commonSettings {
//currently empty
};

struct heatMapSettings {
struct heatMapSettings : public commonSettings {
heatMapSettings(): colorSc(config_colorscales::COLORSCALE_DEFAULT) {}
config_colorscales colorSc;
};

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

//New
struct Config {
public:
Config(): typeVisual(VISUALTYPE_AUTO) {}
void reset() {
common = commonSettings();
chart = chartSettings();
heatmap = heatMapSettings();
surf = surfaceSettings();
};
commonSettings common;
}

chartSettings chart;
heatMapSettings heatmap;
surfaceSettings surf;

config_visualizationTypes typeVisual;
};

//#STOP_GRAB_TO_DV_NAMESPACE
Expand Down
1 change: 0 additions & 1 deletion davis_files.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
common_utils/common_constants.cpp
common_utils/common_constants.h
array_core/configurator.h
array_core/configurator.cpp
plotly_maker/html_parts.h
plotly_maker/html_parts.cpp
common_utils/common_utils.h
Expand Down
60 changes: 39 additions & 21 deletions davis_one/davis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ const char kPlotlyJsResourcePath[] = "plotly_maker/plotly-2.27.0.min.js";

} // namespace dvs end

namespace dv {
/*
Configurator& config() {
return Configurator::getInstance();
};
*/


} // namespace dv end
namespace dvs {
// *INDENT-OFF*
const char kHtmlModel[] =
Expand Down Expand Up @@ -57,6 +48,17 @@ var layout = {
title: {
text: '%6'
}
},
scene: {
xaxis: {
title: '%5',
},
yaxis: {
title: '%6',
},
zaxis: {
title: '%7',
}
}
};
var config = {
Expand Down Expand Up @@ -123,12 +125,18 @@ Plotly.newPlot('gd', data, layout, config);

const char kHeatMapTypePart[] = R"(
type: 'heatmap',
hovertemplate: 'x:%{x} <br>y:%{y} <br>val:%{z:.}<extra></extra>'
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>'
hovertemplate: 'x:%{x} <br>y:%{y} <br>z:%{z:.}<extra></extra>',
colorbar: {
title: ""
}
}];)";
// *INDENT-ON*

Expand Down Expand Up @@ -468,9 +476,9 @@ bool createHtmlPageWithPlotlyJS(const std::vector<std::vector<double>>& values,
createStringHeatMapValues(values, str_values);
args[ARG_VALUES] = str_values;
dv::config_colorscales clrScale;
if (typeVisual == dv::config_visualizationTypes::VISUALTYPE_HEATMAP)
if (typeVisual == dv::VISUALTYPE_HEATMAP)
clrScale = configuration.heatmap.colorSc;
else if (typeVisual == dv::config_visualizationTypes::VISUALTYPE_SURFACE)
else if (typeVisual == dv::VISUALTYPE_SURFACE)
clrScale = configuration.surf.colorSc;
else
return false;
Expand All @@ -492,18 +500,28 @@ bool createHtmlPageWithPlotlyJS(const std::vector<std::vector<double>>& values,
break;
}
switch (typeVisual) {
case dv::config_visualizationTypes::VISUALTYPE_HEATMAP:
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;
break;
case dv::config_visualizationTypes::VISUALTYPE_SURFACE:
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;
break;
case dv::VISUALTYPE_CHART:
args[ARG_TITLE] = configuration.chart.title;
args[ARG_TITLE_X] = configuration.chart.xLabel;
args[ARG_TITLE_Y] = configuration.chart.yLabel;
break;
default:
break;
}
args[ARG_TITLE] = configuration.common.title;
args[ARG_TITLE_X] = configuration.common.xLabel;
args[ARG_TITLE_Y] = configuration.common.yLabel;

make_string(kHtmlModel, args, page);
return true;
}
Expand All @@ -528,9 +546,9 @@ bool showLineChartInBrowser(const vector<double>& values,
string str_values = "";
createStringLineChartValues(values, str_values);
args[ARG_VALUES] = str_values;
args[ARG_TITLE] = configuration.common.title;
args[ARG_TITLE_X] = configuration.common.xLabel;
args[ARG_TITLE_Y] = configuration.common.yLabel;
args[ARG_TITLE] = configuration.chart.title;
args[ARG_TITLE_X] = configuration.chart.xLabel;
args[ARG_TITLE_Y] = configuration.chart.yLabel;
make_string(kHtmlModel, args, page);
string pageName;
mayBeCreateJsWorkingFolder();
Expand Down
Loading

0 comments on commit 9f626cf

Please sign in to comment.