Skip to content

Commit

Permalink
Different plot settings (#64)
Browse files Browse the repository at this point in the history
* init

* WIP

* WIP

* init

* WIP

* WIP

* WIP

* WIP

some tests in main

* WIP

before start working with Davis Launcher

* different plot settings are implemented

* add colorscale to conctructor
  • Loading branch information
AntonMrt authored Nov 26, 2023
1 parent ebe6a3e commit d4b0d3a
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 140 deletions.
44 changes: 28 additions & 16 deletions Tests/ArrayCoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@
#include <fstream>

using std::string;
using std::vector;

TEST(ArrayCore, showHeatMap1) {
TEST(ArrayCore, showDefaultSettings) {
EXPECT_EQ(davis::isPlotlyScriptExists(), true);
std::vector<std::vector<double>> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
bool result = davis::show(values, "test1");
vector<vector<double>> values = {{30.3, 400, 400, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
bool result = davis::show(values, "testDefaultSettings");
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showHeatMap2) {
// davis::sleepMs(1000);
std::vector<int> vals2 = {2, 6, 4, 34, 56, 33, 2, 1};
bool result = davis::show(vals2, "test2");
TEST(ArrayCore, showHeatMap1) {
EXPECT_EQ(davis::isPlotlyScriptExists(), true);
vector<vector<double>> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
auto settings = davis::createShowSettingsHeatMap(davis::colorscales::GLAMOUR);
bool result = davis::show(values, "showHeatMap1", settings.get());
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showHeatMap3) {
// davis::sleepMs(1000);
int vals3[] = {2, 6, 4, -34, 56, 33, 2, 15};
bool result = davis::show(vals3, sizeof(vals3) / sizeof(vals3[0]), "test3");
TEST(ArrayCore, showSurface1) {
EXPECT_EQ(davis::isPlotlyScriptExists(), true);
vector<vector<double>> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
auto settings = davis::createShowSettingsSurface();
bool result = davis::show(values, "showSurface1", settings.get());
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showHeatMap4) {
// davis::sleepMs(1000);
TEST(ArrayCore, showPseudo2D) {
int rows = 5;
int cols = 3;
int* vals4 = new int[rows * cols];
Expand All @@ -37,12 +39,11 @@ TEST(ArrayCore, showHeatMap4) {
vals4[i * cols + j] = i * cols + j;
}
}
bool result = davis::show(vals4, rows, cols, "test4");
bool result = davis::show(vals4, rows, cols, "showPseudo2D");
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showHeatMap5) {
// davis::sleepMs(1000);
TEST(ArrayCore, showArray2D) {
int rows2 = 20;
int cols2 = 20;
int** vals5 = new int* [rows2];
Expand All @@ -56,6 +57,17 @@ TEST(ArrayCore, showHeatMap5) {
EXPECT_EQ(result, true);
}

TEST(ArrayCore, testChartDefault) {
vector<int> vec = {-5, -3, -1, 0, 2, 4, 8, 15, 16};
bool result = davis::show(vec, "testChartDefault");
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showChart) {
int vals3[] = {2, 6, 4, -34, 56, 33, 2, 15};
bool result = davis::show(vals3, sizeof(vals3) / sizeof(vals3[0]), "showChart");
EXPECT_EQ(result, true);
}

int main(int argc, char* argv[]) {
//std::cout<< std::endl << davis::deleteFolder(davis::saveFolderName) << std::endl;
Expand Down
25 changes: 9 additions & 16 deletions Tests/PlotlyLibTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ using std::string;
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";
davis::showSettings settings = davis::showSettings();
settings.colorscale = davis::colorscales::GLAMOUR;
bool result = davis::createHtmlPageWithPlotlyJS(testValues, str_page, settings);
bool result = davis::createHtmlPageWithPlotlyJS(testValues, str_page, davis::visualizationTypes::HEATMAP, davis::colorscales::GLAMOUR);
std::ofstream out("example.html");
if (out.is_open()) {
out << str_page.c_str();
Expand All @@ -24,37 +22,32 @@ TEST(PlotlyMaker, CreateDefaultHeatMapHtmlPageTest) {
TEST(PlotlyMaker, ShowGlamourHeatMapHtmlPageTest) {
std::vector<std::vector<double>>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}};
std::string str_page = "veryGlamourPage";
davis::showSettings settings = davis::showSettings();
settings.colorscale = davis::colorscales::GLAMOUR;
bool result = davis::showHeatMapInBrowser(testValues, str_page, settings);
auto settings = std::make_unique<davis::ShowSettingsHeatMap>(davis::colorscales::GLAMOUR);
bool result = davis::showHeatMapInBrowser(testValues, str_page, settings.get());
EXPECT_EQ(result, true);
}

TEST(PlotlyMaker, ShowThermalHeatMapHtmlPageTest) {
std::vector<std::vector<double>>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}};
std::string str_page = "veryHotPage";
davis::showSettings settings = davis::showSettings();
settings.colorscale = davis::colorscales::THERMAL;
bool result = davis::showHeatMapInBrowser(testValues, str_page, settings);
auto settings = std::make_unique<davis::ShowSettingsHeatMap>(davis::colorscales::THERMAL);
bool result = davis::showHeatMapInBrowser(testValues, str_page, settings.get());
EXPECT_EQ(result, true);
}

TEST(PlotlyMaker, ShowSunnyHeatMapHtmlPageTest) {
std::vector<std::vector<double>>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}};
std::string str_page = "SunnyPage";
davis::showSettings settings = davis::showSettings();
settings.colorscale = davis::colorscales::SUNNY;
bool result = davis::showHeatMapInBrowser(testValues, str_page, settings);
auto settings = std::make_unique<davis::ShowSettingsHeatMap>(davis::colorscales::SUNNY);
bool result = davis::showHeatMapInBrowser(testValues, str_page, settings.get());
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";
davis::showSettings settings = davis::showSettings();
settings.colorscale = davis::colorscales::THERMAL;
settings.visualType = davis::visualizationTypes::SURFACE;
bool result = davis::showSurfaceInBrowser(testValues, str_page, settings);
auto settings = std::make_unique<davis::ShowSettingsSurface>(davis::colorscales::THERMAL);
bool result = davis::showSurfaceInBrowser(testValues, str_page, settings.get());
EXPECT_EQ(result, true);
}

Expand Down
98 changes: 72 additions & 26 deletions array_core/array_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,80 +16,126 @@ using std::string;
//! two-dimensional vector
template <typename T>
bool show(const vector<vector<T>>& data, const string& title = kAppName,
const showSettings& settings = showSettings());

//! one-dimensional vector
template <typename T>
bool show(const vector<T>& data, const string& title = kAppName,
const showSettings& settings = showSettings());
ShowSettings* settings = nullptr);

//! two-dimensional array
template <typename T>
bool show(T** data, uint64_t arrRows, uint64_t arrCols,
const string& title = kAppName, const showSettings& settings = showSettings());
const string& title = kAppName, ShowSettings* settings = nullptr);

//! a one-dimensional array that simulates a two-dimensional one (element access [i*cols+j])
template <typename T>
bool show(const T* data, uint64_t arrRows, uint64_t arrCols,
const string& title = kAppName, const showSettings& settings = showSettings());
const string& title = kAppName, ShowSettings* settings = nullptr);

//! one-dimensional vector
template <typename T>
bool show(const vector<T>& data, const string& title = kAppName,
ShowSettings* settings = nullptr);

//! one-dimensional array
template <typename T>
bool show(const T* data, uint64_t count, const string& title = kAppName,
const showSettings& settings = showSettings());
ShowSettings* settings = nullptr);

// ***********************************
// template functions implementations:
// ***********************************

template <typename T>
bool show(const vector<vector<T>>& data, const string& title,
const showSettings& settings) {
ShowSettings* settings) {
vector<vector<double>> vecVecDbl;
vecVecDbl.reserve(data.size());
for (vector<T> row : data) {
vector<double> dblRow(row.begin(), row.end());
vecVecDbl.emplace_back(dblRow);
}
return davis::showHeatMapInBrowser(vecVecDbl, title, settings);
}

template <typename T>
bool show(const vector<T>& data, const string& title,
const showSettings& settings) {
vector<double> dblRow(data.begin(), data.end());
return davis::showLineChartInBrowser(dblRow, title, settings);
bool res = false;
std::unique_ptr<ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
if (settings == nullptr) {
settings = new ShowSettingsHeatMap();
smartP.reset(settings);
}
if (settings->getVisualType() == davis::visualizationTypes::HEATMAP)
res = davis::showHeatMapInBrowser(vecVecDbl, title, static_cast<const ShowSettingsHeatMap*>(settings));
else if (settings->getVisualType() == davis::visualizationTypes::SURFACE)
res = davis::showSurfaceInBrowser(vecVecDbl, title, static_cast<const ShowSettingsSurface*>(settings));
return res;
}

template <typename T>
bool show(T** data, uint64_t arrRows, uint64_t arrCols, const string& title,
const showSettings& settings) {
ShowSettings* settings) {
vector<vector<double>> vecVecDbl;
vecVecDbl.reserve(arrRows);
for (int i = 0; i < arrRows; ++i) {
for (uint64_t i = 0; i < arrRows; ++i) {
vector<double> dblRow(&data[i][0], &data[i][0] + arrCols);
vecVecDbl.emplace_back(dblRow);
}
return davis::showHeatMapInBrowser(vecVecDbl, title, settings);
bool res = false;
std::unique_ptr<ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
if (settings == nullptr) {
settings = new ShowSettingsHeatMap();
smartP.reset(settings);
}
if (settings->getVisualType() == davis::visualizationTypes::HEATMAP)
res = davis::showHeatMapInBrowser(vecVecDbl, title, static_cast<const ShowSettingsHeatMap*>(settings));
else if (settings->getVisualType() == davis::visualizationTypes::SURFACE)
res = davis::showSurfaceInBrowser(vecVecDbl, title, static_cast<const ShowSettingsSurface*>(settings));
return res;
}

template <typename T>
bool show(const T* data, uint64_t arrRows, uint64_t arrCols, const string& title,
const showSettings& settings) {
ShowSettings* settings) {
vector<vector<double>> vecVecDbl;
vecVecDbl.reserve(arrRows);
for (int i = 0; i < arrRows; ++i) {
for (uint64_t i = 0; i < arrRows; ++i) {
vector<double> dblRow(&data[i * arrCols], &data[i * arrCols] + arrCols);
vecVecDbl.emplace_back(dblRow);
}
return davis::showHeatMapInBrowser(vecVecDbl, title, settings);
bool res = false;
std::unique_ptr<ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
if (settings == nullptr) {
settings = new ShowSettingsHeatMap();
smartP.reset(settings);
}
if (settings->getVisualType() == davis::visualizationTypes::HEATMAP)
res = davis::showHeatMapInBrowser(vecVecDbl, title, static_cast<const ShowSettingsHeatMap*>(settings));
else if (settings->getVisualType() == davis::visualizationTypes::SURFACE)
res = davis::showSurfaceInBrowser(vecVecDbl, title, static_cast<const ShowSettingsSurface*>(settings));
return res;
}

template <typename T>
bool show(const vector<T>& data, const string& title,
ShowSettings* settings) {
vector<double> dblRow(data.begin(), data.end());
bool res = false;
std::unique_ptr<ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
if (settings == nullptr) {
settings = new ShowSettingsChart();
smartP.reset(settings);
}
if (settings->getVisualType() == davis::visualizationTypes::CHART)
res = davis::showLineChartInBrowser(dblRow, title, static_cast<const ShowSettingsChart*>(settings));
return res;
}

template <typename T>
bool show(const T* data, uint64_t count, const string& title,
const showSettings& settings) {
ShowSettings* settings) {
vector<double> dblRow(data, data + count);
return davis::showLineChartInBrowser(dblRow, title, settings);
bool res = false;
std::unique_ptr<ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
if (settings == nullptr) {
settings = new ShowSettingsChart();
smartP.reset(settings);
}
if (settings->getVisualType() == davis::visualizationTypes::CHART)
res = davis::showLineChartInBrowser(dblRow, title, static_cast<const ShowSettingsChart*>(settings));
return res;
}

} // namespace davis
Expand Down
Binary file added astyle.exe
Binary file not shown.
22 changes: 8 additions & 14 deletions davis.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ void makeStringFromValues(const vector<double> in_values,
}

}
void makeArgs(const davis::showSettings& settings,
void makeArgs(const davis::ShowSettings* settings,
const vector<vector<double>>& values, string& out) {

switch (settings.visualType) {
switch (settings->getVisualType()) {
case davis::visualizationTypes::CHART:
break;
case davis::visualizationTypes::HEATMAP:
Expand Down Expand Up @@ -65,10 +64,10 @@ void makeArgs(const davis::showSettings& settings,
}
}

void makeArgs(const davis::showSettings& settings,
void makeArgs(const davis::ShowSettings* settings,
vector<double>& values, string& out) {

switch (settings.visualType) {
switch (settings->getVisualType()) {
case davis::visualizationTypes::CHART:
out.append(davis);
out.append(command_line_chart);
Expand All @@ -87,25 +86,20 @@ void makeArgs(const davis::showSettings& settings,

namespace dv {

void show(const davis::showSettings& settings,
vector<vector<double>>& values);
void show(const davis::showSettings& settings,
vector<double>& values);
void show(vector<vector<double>>& values, const davis::ShowSettings* settings);
void show(vector<double>& values, const davis::ShowSettings* settings);

void show(const davis::showSettings& settings,
vector<double>& values) {
void show(vector<vector<double>>& values, const davis::ShowSettings* settings) {
string args;
makeArgs(settings, values, args);
runDavisBySystem(args);
}

void show(const davis::showSettings& settings,
vector<vector<double>>& values) {
void show(vector<double>& values, const davis::ShowSettings* settings) {
string args;
makeArgs(settings, values, args);
runDavisBySystem(args);
}

}

#endif // DAVIS_H
16 changes: 9 additions & 7 deletions davis_launcher.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include "davis.h"

int main(int argc, char* argv[]) {
davis::showSettings settings;
settings.visualType = davis::visualizationTypes::CHART;

vector<double>v = {8.0, 8.0, 9, 0, 55};
vector<vector<double>>hm = {{8.0, 8.0, 9, 0, 55}, {5.0, 18.0, 0.9, 50, 15}};
dv::show(settings, v);
settings.visualType = davis::visualizationTypes::HEATMAP;
dv::show(settings, hm);
settings.visualType = davis::visualizationTypes::SURFACE;
dv::show(settings, hm);
auto settings1 = davis::createShowSettingsChart();
auto settings2 = davis::createShowSettingsHeatMap();
auto settings3 = davis::createShowSettingsSurface();
dv::show(v, settings1.get());

dv::show(hm, settings2.get());

dv::show(hm, settings3.get());
return EXIT_SUCCESS;
}
Loading

0 comments on commit d4b0d3a

Please sign in to comment.