diff --git a/!Format + one_header.bat b/!Format + one_header.bat index bdb2f4b..4c09f51 100644 --- a/!Format + one_header.bat +++ b/!Format + one_header.bat @@ -1,2 +1,2 @@ -call auto_format.bat +call format_all.bat call make_one_header.bat \ No newline at end of file diff --git a/ResourceManager/include/ResourceManager/ResourceHandle.h b/ResourceManager/include/ResourceManager/ResourceHandle.h index 7ee2a01..5daf378 100644 --- a/ResourceManager/include/ResourceManager/ResourceHandle.h +++ b/ResourceManager/include/ResourceManager/ResourceHandle.h @@ -1,49 +1,55 @@ -// Copyright (c) 2018 Johnny Borov . Released under MIT License. +// Copyright (c) 2018 Johnny Borov . Released under MIT +// License. #ifndef RM_RESOURCE_HANDLE_H #define RM_RESOURCE_HANDLE_H #include -#include #include +#include -// This exception type is thrown if ResourceHandle constructor gets invalid resource name. -// Compile with -DRM_NO_EXCEPTIONS to disable throwing on invalid resource name. +// This exception type is thrown if ResourceHandle constructor gets invalid +// resource name. Compile with -DRM_NO_EXCEPTIONS to disable throwing on invalid +// resource name. class ResourceNotFound : public std::exception { public: - ResourceNotFound(std::string resource_name) : m_message{"ResourceManager: Resource not found: " + resource_name} {} - virtual const char* what() const noexcept { return m_message.c_str(); } + ResourceNotFound(std::string resource_name) + : m_message{"ResourceManager: Resource not found: " + resource_name} {} + virtual const char *what() const noexcept { return m_message.c_str(); } private: const std::string m_message; }; - -// This class holds a pointer to the beginning of binary data for the requested resource -// and the length/size (in bytes) of this data. (length and size are the same thing). +// This class holds a pointer to the beginning of binary data for the requested +// resource and the length/size (in bytes) of this data. (length and size are +// the same thing). // ------------------------------------------------------------------------------------------- -// If constructor is called with an invalid resource name ResourceNotFound exception is thrown -// Compile with -DRM_NO_EXCEPTIONS to disable throwing on invalid resource name. +// If constructor is called with an invalid resource name ResourceNotFound +// exception is thrown Compile with -DRM_NO_EXCEPTIONS to disable throwing on +// invalid resource name. // ------------------------------------------------------------------------------------------- -// If exceptions are disabled and constructor is called with an invalid resource name -// then the pointer to the data equials nullptr and length/size equals 0. -// In this case you can use isValid() to determine whether construction was successful or not. +// If exceptions are disabled and constructor is called with an invalid resource +// name then the pointer to the data equials nullptr and length/size equals 0. +// In this case you can use isValid() to determine whether construction was +// successful or not. // =========================================================================================== // Avaliable functions: // -- const bool isValid() const noexcept: // # returns true if construction was successful, false otherwise. // # // -- const unsigned char* const data() const noexcept: -// # returns the pointer to the beginning of binary data or nullptr if construction failed. -// # The data is null-terminated in the end. +// # returns the pointer to the beginning of binary data or nullptr if +// construction failed. # The data is null-terminated in the end. // # // -- const char* const c_str() const noexcept: -// # returns the pointer to the beginning of binary data or nullptr if construction failed. -// # The data is null-terminated in the end. +// # returns the pointer to the beginning of binary data or nullptr if +// construction failed. # The data is null-terminated in the end. // # // -- std::string string() const: // # returns std::string based on the binary data with same length as the data. -// # If there are zeroes in the middle of the data string will contain them anyway. +// # If there are zeroes in the middle of the data string will contain them +// anyway. // # // -- const size_t size() const noexcept: // # returns size of the data in bytes or 0 if construction failed. @@ -57,18 +63,28 @@ class ResourceHandle { public: ResourceHandle(std::string resource_name); - const bool isValid() const noexcept { if (m_data_start) return true; else return false; } + const bool isValid() const noexcept { + if (m_data_start) + return true; + else + return false; + } const size_t size() const noexcept { return m_data_len; } const size_t length() const noexcept { return m_data_len; } - const unsigned char* const data() const noexcept { return m_data_start; } + const unsigned char *const data() const noexcept { return m_data_start; } - const char* const c_str() const noexcept { return reinterpret_cast(m_data_start); } - std::string string() const { return std::string(reinterpret_cast(m_data_start), m_data_len); } + const char *const c_str() const noexcept { + return reinterpret_cast(m_data_start); + } + std::string string() const { + return std::string(reinterpret_cast(m_data_start), + m_data_len); + } private: - const unsigned char* m_data_start; + const unsigned char *m_data_start; size_t m_data_len; }; diff --git a/ResourceManager/src/embed_resource.cpp b/ResourceManager/src/embed_resource.cpp index 534939a..d6bb3f7 100644 --- a/ResourceManager/src/embed_resource.cpp +++ b/ResourceManager/src/embed_resource.cpp @@ -1,14 +1,17 @@ -// Copyright (c) 2018 Johnny Borov . Released under MIT License. +// Copyright (c) 2018 Johnny Borov . Released under MIT +// License. #include #include -void generateResourceDataSourceFile(char* resource_name, char* resource_file_name, char* output_file_name); -void generateResourcesConfigSourceFile(char* resource_names_list, char* config_file_name); +void generateResourceDataSourceFile(char *resource_name, + char *resource_file_name, + char *output_file_name); +void generateResourcesConfigSourceFile(char *resource_names_list, + char *config_file_name); std::string modifyFileName(std::string file_name); - -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { // working directory = CMAKE_BINARY_DIR when called from cmake custom command if (std::string(argv[1]) == "-data") { if (argc == 5) @@ -25,19 +28,26 @@ int main(int argc, char* argv[]) { return 0; } - -// generate a cpp file (e.g. resources/res.txt.cpp) containing global extern array of const unsigned char -// of binary data read from the requested input file (CMAKE_SOURCE_DIR/resources/res.txt) plus null-terminator -// in the end of data and a global extern const size_t size of this data in bytes (without null-terminator) -void generateResourceDataSourceFile(char* resource_name, char* resource_file_name, char* output_file_name) { - std::string name{ resource_name }; // e.g. "resources/res.txt" - std::string modified_name = modifyFileName(name); // becomes "resources__slash__res__dot__txt" - - std::ifstream ifs{ resource_file_name, std::ios::binary }; // e.g. reads from CMAKE_SOURCE_DIR/resources/res.txt - std::ofstream ofs{ output_file_name }; // e.g. writes to resources/res.txt.cpp +// generate a cpp file (e.g. resources/res.txt.cpp) containing global extern +// array of const unsigned char of binary data read from the requested input +// file (CMAKE_SOURCE_DIR/resources/res.txt) plus null-terminator in the end of +// data and a global extern const size_t size of this data in bytes (without +// null-terminator) +void generateResourceDataSourceFile(char *resource_name, + char *resource_file_name, + char *output_file_name) { + std::string name{resource_name}; // e.g. "resources/res.txt" + std::string modified_name = + modifyFileName(name); // becomes "resources__slash__res__dot__txt" + + std::ifstream ifs{ + resource_file_name, + std::ios::binary}; // e.g. reads from CMAKE_SOURCE_DIR/resources/res.txt + std::ofstream ofs{output_file_name}; // e.g. writes to resources/res.txt.cpp ofs << "#include \n"; - ofs << "extern const unsigned char _resource_" << modified_name << "_data[] = {\n"; + ofs << "extern const unsigned char _resource_" << modified_name + << "_data[] = {\n"; int line_count = 0; char c; @@ -50,28 +60,31 @@ void generateResourceDataSourceFile(char* resource_name, char* resource_file_nam } } - ofs << "\'\\0\'"; // null-terminator in case data is going to be interprited as a c string + ofs << "\'\\0\'"; // null-terminator in case data is going to be interprited + // as a c string ofs << "};\n"; // -1 excludes null-terminator - ofs << "extern const size_t _resource_" << modified_name << "_len = sizeof(_resource_" << modified_name << "_data) - 1;\n"; + ofs << "extern const size_t _resource_" << modified_name + << "_len = sizeof(_resource_" << modified_name << "_data) - 1;\n"; } - -// generate a cpp file (e.g. __resources__config.cpp) that defines ResourceHandle constructor. -// The defenition contains the hardcoded mapping of original resource names (e.g. "resources/res.txt") -// to their corresponding global extern variables names. Thus it returns a handle which contains pointer to -// the beginning of global extern array of const unsigned char and its size (see -data option description) -void generateResourcesConfigSourceFile(char* resource_names_list, char* config_file_name) { +// generate a cpp file (e.g. __resources__config.cpp) that defines +// ResourceHandle constructor. The defenition contains the hardcoded mapping of +// original resource names (e.g. "resources/res.txt") to their corresponding +// global extern variables names. Thus it returns a handle which contains +// pointer to the beginning of global extern array of const unsigned char and +// its size (see -data option description) +void generateResourcesConfigSourceFile(char *resource_names_list, + char *config_file_name) { std::ofstream ofs(config_file_name); // e.g. writes to __resources__config.cpp - ofs << - "#include \"ResourceManager/ResourceHandle.h\"\n" - "\n" - "ResourceHandle::ResourceHandle(std::string resource_name) {\n" - " "; - + ofs << "#include \"ResourceManager/ResourceHandle.h\"\n" + "\n" + "ResourceHandle::ResourceHandle(std::string resource_name) {\n" + " "; - std::string resource_names{resource_names_list}; // e.g. "res.txt;res2.txt;resources/res.txt" + std::string resource_names{ + resource_names_list}; // e.g. "res.txt;res2.txt;resources/res.txt" size_t length = resource_names.length(); size_t start_pos = 0; do { @@ -83,59 +96,66 @@ void generateResourcesConfigSourceFile(char* resource_names_list, char* config_f std::string name = resource_names.substr(start_pos, end_pos - start_pos); std::string modified_name = modifyFileName(name); - ofs << - "if (resource_name == \"" << name << "\") {\n" - " extern const unsigned char _resource_" << modified_name << "_data[];\n" - " extern const size_t _resource_" << modified_name << "_len;\n" - " m_data_start = _resource_" << modified_name << "_data;\n" - " m_data_len = _resource_" << modified_name << "_len;\n" - " } else "; - - start_pos = end_pos + 1; // e.g. start next read from res2... position in "res.txt;res2.txt;resources/res.txt" + ofs << "if (resource_name == \"" << name + << "\") {\n" + " extern const unsigned char _resource_" + << modified_name + << "_data[];\n" + " extern const size_t _resource_" + << modified_name + << "_len;\n" + " m_data_start = _resource_" + << modified_name + << "_data;\n" + " m_data_len = _resource_" + << modified_name + << "_len;\n" + " } else "; + + start_pos = end_pos + 1; // e.g. start next read from res2... position in + // "res.txt;res2.txt;resources/res.txt" } while (start_pos < length); - - ofs << - "{\n" - "#ifdef RM_NO_EXCEPTIONS\n" - " m_data_start = nullptr;\n" - " m_data_len = 0;\n" - "#else\n" - " throw ResourceNotFound{resource_name};\n" - "#endif\n" - " }\n" - "}\n"; + ofs << "{\n" + "#ifdef RM_NO_EXCEPTIONS\n" + " m_data_start = nullptr;\n" + " m_data_len = 0;\n" + "#else\n" + " throw ResourceNotFound{resource_name};\n" + "#endif\n" + " }\n" + "}\n"; } - // replace symbols that cant be used in c++ identeficator name // e.g. "resources/res.txt" -> "resources__slash__res__dot__txt" std::string modifyFileName(std::string file_name) { size_t search_from_pos = 0; size_t replace_from_pos; - while ((replace_from_pos = file_name.find_first_of(".- /\\", search_from_pos)) != std::string::npos) { - switch (file_name[replace_from_pos]) { - case '.': - file_name.replace(replace_from_pos, 1, "__dot__"); - search_from_pos = replace_from_pos + 7; // shift len(__dot__) = 5 symbols - break; - case '-': - file_name.replace(replace_from_pos, 1, "__dash__"); - search_from_pos = replace_from_pos + 8; - break; - case ' ': - file_name.replace(replace_from_pos, 1, "__space__"); - search_from_pos = replace_from_pos + 9; - break; - case '/': - file_name.replace(replace_from_pos, 1, "__slash__"); - search_from_pos = replace_from_pos + 9; - break; - case '\\': - file_name.replace(replace_from_pos, 1, "__bslash__"); - search_from_pos = replace_from_pos + 10; - break; - } + while ((replace_from_pos = file_name.find_first_of( + ".- /\\", search_from_pos)) != std::string::npos) { + switch (file_name[replace_from_pos]) { + case '.': + file_name.replace(replace_from_pos, 1, "__dot__"); + search_from_pos = replace_from_pos + 7; // shift len(__dot__) = 5 symbols + break; + case '-': + file_name.replace(replace_from_pos, 1, "__dash__"); + search_from_pos = replace_from_pos + 8; + break; + case ' ': + file_name.replace(replace_from_pos, 1, "__space__"); + search_from_pos = replace_from_pos + 9; + break; + case '/': + file_name.replace(replace_from_pos, 1, "__slash__"); + search_from_pos = replace_from_pos + 9; + break; + case '\\': + file_name.replace(replace_from_pos, 1, "__bslash__"); + search_from_pos = replace_from_pos + 10; + break; + } } return file_name; diff --git a/ResourceManager/test/src/test_main.cpp b/ResourceManager/test/src/test_main.cpp index e9562a0..3f1205a 100644 --- a/ResourceManager/test/src/test_main.cpp +++ b/ResourceManager/test/src/test_main.cpp @@ -1,10 +1,12 @@ -// Copyright (c) 2018 Johnny Borov . Released under MIT License. +// Copyright (c) 2018 Johnny Borov . Released under MIT +// License. -#include #include "ResourceManager/ResourceHandle.h" +#include void testInvalidResource() { - ResourceHandle rhdi("i_dont_exist"); // -DRM_NO_EXCEPTIONS to disable throw on invalid recource + ResourceHandle rhdi("i_dont_exist"); // -DRM_NO_EXCEPTIONS to disable throw on + // invalid recource std::cout << "rhdi is valid = " << rhdi.isValid() << '\n'; } @@ -21,7 +23,7 @@ int main() { std::cout << "rh3 size = " << rh3.size() << '\n'; testInvalidResource(); - } catch (const ResourceNotFound& e) { + } catch (const ResourceNotFound &e) { std::cout << e.what() << '\n'; } diff --git a/Tests/ArrayCoreTest.cpp b/Tests/ArrayCoreTest.cpp index 2af84ce..7ecab58 100644 --- a/Tests/ArrayCoreTest.cpp +++ b/Tests/ArrayCoreTest.cpp @@ -1,11 +1,11 @@ -#include "gtest/gtest.h" -#include "plotly_maker/plotly_maker.h" #include "array_core/array_core.h" -#include "common_utils/common_utils.h" #include "array_core/multi_plot.h" +#include "common_utils/common_utils.h" +#include "plotly_maker/plotly_maker.h" +#include "gtest/gtest.h" +#include #include #include -#include #include using std::string; @@ -15,14 +15,15 @@ TEST(ArrayCore, save_to_disk_2d) { //! 2-dimensional array int rows = 10; int cols = 5; - int** vals2d = new int* [rows]; + int **vals2d = new int *[rows]; for (int i = 0; i < rows; ++i) { vals2d[i] = new int[cols]; for (int j = 0; j < cols; ++j) { vals2d[i][j] = i * cols + j; } } - bool result = dv::save(vals2d, rows, cols, "./data/test_saving_save_to_disk_2d.csv"); + bool result = + dv::save(vals2d, rows, cols, "./data/test_saving_save_to_disk_2d.csv"); EXPECT_EQ(result, true); } @@ -30,7 +31,7 @@ TEST(ArrayCore, save_to_disk_pseudo_2d) { //! 1-dimensional array that simulates a 2-dimensional int rows = 10; int cols = 5; - int* vals = new int[rows * cols]; + int *vals = new int[rows * cols]; for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { vals[i * cols + j] = i * cols + j; @@ -39,14 +40,15 @@ TEST(ArrayCore, save_to_disk_pseudo_2d) { dv::configSaveToDisk conf; conf.separatorOfCols = ";"; conf.separatorOfRows = "\n"; - bool result = dv::save(vals, rows, cols, "./data/test_saving_save_to_disk_pseudo_2d.csv", conf); + bool result = dv::save(vals, rows, cols, + "./data/test_saving_save_to_disk_pseudo_2d.csv", conf); EXPECT_EQ(result, true); } TEST(ArrayCore, save_to_disk_1d) { //! 1-dimensional array int size = 10; - int* vals = new int[size]; + int *vals = new int[size]; for (int i = 0; i < size; ++i) { vals[i] = i; } @@ -60,7 +62,8 @@ TEST(ArrayCore, save_to_disk_container1D) { for (size_t i = 0; i < 10; ++i) { vec.emplace_back(i * 1e-10); } - bool result = dv::save(vec, "./data/test_saving_save_to_disk_container1D.csv"); + bool result = + dv::save(vec, "./data/test_saving_save_to_disk_container1D.csv"); EXPECT_EQ(result, true); } @@ -76,7 +79,8 @@ TEST(ArrayCore, save_to_disk_container2D) { } arr2.emplace_back(vec); } - bool result = dv::save(arr2, "./data/test_saving_save_to_disk_container2D.csv"); + bool result = + dv::save(arr2, "./data/test_saving_save_to_disk_container2D.csv"); EXPECT_EQ(result, true); } @@ -90,7 +94,8 @@ TEST(ArrayCore, save_to_disk_XYdata) { for (size_t i = 0; i < 10; ++i) { vecY.emplace_back(i * 3); } - bool result = dv::save(vecX, vecY, "./data/test_saving_save_to_disk_XYdata.csv"); + bool result = + dv::save(vecX, vecY, "./data/test_saving_save_to_disk_XYdata.csv"); EXPECT_EQ(result, true); } @@ -103,7 +108,10 @@ TEST(ArrayCore, universal_1d_conteiner) { TEST(ArrayCore, universal_2d_conteiner) { EXPECT_EQ(dvs::isPlotlyScriptExists(), true); - std::list> template2d = {{30.312345, 40, 98, 76}, {-20.12, 45, 20, 1}, {5, 10, 10, 25}, {45, 23, 90, 2}}; + std::list> template2d = {{30.312345, 40, 98, 76}, + {-20.12, 45, 20, 1}, + {5, 10, 10, 25}, + {45, 23, 90, 2}}; bool result = dv::show(template2d, "testTemplate2d"); EXPECT_EQ(result, true); } @@ -122,7 +130,10 @@ TEST(ArrayCore, stdArray_of_stdArrays) { TEST(ArrayCore, configurator) { EXPECT_EQ(dvs::isPlotlyScriptExists(), true); - vector> values = {{30.312345, 40, 98, 76}, {-20.12, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}}; + vector> values = {{30.312345, 40, 98, 76}, + {-20.12, 45, 20, 1}, + {5, 56, 93, 25}, + {45, 23, 90, 2}}; auto config = dv::Config(); config.heatmap.xLabel = "Столбцы"; config.heatmap.yLabel = "Строки"; @@ -135,14 +146,16 @@ TEST(ArrayCore, configurator) { TEST(ArrayCore, showDefaultSettings) { EXPECT_EQ(dvs::isPlotlyScriptExists(), true); - vector> values = {{30.3, 400, 400, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}}; + vector> values = { + {30.3, 400, 400, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}}; bool result = dv::show(values, "testDefaultSettings"); EXPECT_EQ(result, true); } TEST(ArrayCore, showHeatMap1_customAspectRatio) { EXPECT_EQ(dvs::isPlotlyScriptExists(), true); - vector> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}}; + vector> 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; @@ -154,7 +167,8 @@ TEST(ArrayCore, showHeatMap1_customAspectRatio) { TEST(ArrayCore, showHeatMap1_AutoScale) { EXPECT_EQ(dvs::isPlotlyScriptExists(), true); - vector> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}}; + vector> 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; @@ -166,7 +180,7 @@ TEST(ArrayCore, showHeatMap1_AutoScale) { TEST(ArrayCore, showPseudo2D) { int rows = 5; int cols = 3; - int* vals4 = new int[rows * cols]; + int *vals4 = new int[rows * cols]; for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { vals4[i * cols + j] = i * cols + j; @@ -179,7 +193,7 @@ TEST(ArrayCore, showPseudo2D) { TEST(ArrayCore, showArray2D) { int rows2 = 20; int cols2 = 20; - int** vals5 = new int* [rows2]; + int **vals5 = new int *[rows2]; for (int i = 0; i < rows2; ++i) { vals5[i] = new int[cols2]; for (int j = 0; j < cols2; ++j) { @@ -202,7 +216,8 @@ TEST(ArrayCore, showChart) { 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); + bool result = + dv::show(vals3, sizeof(vals3) / sizeof(vals3[0]), "showChart", config); EXPECT_EQ(result, true); } @@ -231,7 +246,8 @@ TEST(ArrayCore, showChartXYfrom2Containers) { TEST(ArrayCore, readAndShowMatrixFromFile) { EXPECT_EQ(dvs::isPlotlyScriptExists(), true); vector> values; - bool readRes = dvs::readMatrix(values, "./data/2023_07_19-12_59_31_379_Baumer2_text.csv", ';'); + bool readRes = dvs::readMatrix( + values, "./data/2023_07_19-12_59_31_379_Baumer2_text.csv", ';'); EXPECT_EQ(readRes, true); auto config = dv::Config(); config.heatmap.xLabel = "english"; @@ -249,7 +265,8 @@ TEST(ArrayCore, showChartWithNanAndInf) { 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]), "showChartWithNanAndInf", config); + bool result = dv::show(vals3, sizeof(vals3) / sizeof(vals3[0]), + "showChartWithNanAndInf", config); EXPECT_EQ(result, true); } @@ -266,7 +283,7 @@ TEST(ArrayCore, universal_1d_conteinerWithNanAndInf) { TEST(ArrayCore, showPseudo2DWithNanAndInf) { int rows = 5; int cols = 3; - double* vals4 = new double[rows * cols]; + double *vals4 = new double[rows * cols]; for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { vals4[i * cols + j] = 20 + i * cols + j; @@ -306,7 +323,7 @@ TEST(ArrayCore, show3ChartsWithHoldOn) { TEST(ArrayCore, show2ChartsWithHoldOnCustomSettings) { int size = 10; - int* vals = new int[size]; + int *vals = new int[size]; for (int i = 0; i < size; ++i) { vals[i] = i; } @@ -350,7 +367,7 @@ TEST(ArrayCore, testMyltiplyHoldOnOff) { EXPECT_EQ(v1 && v2, true); } -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { ::testing::InitGoogleTest(&argc, argv); std::ignore = RUN_ALL_TESTS(); return 0; diff --git a/Tests/CommonUtilsTest.cpp b/Tests/CommonUtilsTest.cpp index 9b24da5..65473a6 100644 --- a/Tests/CommonUtilsTest.cpp +++ b/Tests/CommonUtilsTest.cpp @@ -13,18 +13,18 @@ using std::vector; vector args{"Apple", "Orange", "Banan", "Pineapple", "Kiwi"}; vector args_big{ - "Yes", // 1 - "No", // 2 - "Ok", // 3 - "Good", // 4 - "Bad", // 5 - "Nice", // 6 - "Ugly", // 7 - "Perfect", // 8 - "Strong", // 9 - "Davis", // 10 - "Cat", // 11 - "Plotly" // 12 + "Yes", // 1 + "No", // 2 + "Ok", // 3 + "Good", // 4 + "Bad", // 5 + "Nice", // 6 + "Ugly", // 7 + "Perfect", // 8 + "Strong", // 9 + "Davis", // 10 + "Cat", // 11 + "Plotly" // 12 }; constexpr char check_test_string_1[] = @@ -47,7 +47,7 @@ constexpr char not_filled_test_string_3[] = // C++ stream interface class TestCout : public std::stringstream { - public: +public: ~TestCout() { std::cout << str() << std::flush; } }; @@ -57,8 +57,7 @@ TEST(CommonUtils, CreateStringFromArgs1) { string out; dvs::make_string(not_filled_test_string_1, args, out); EXPECT_EQ(check_test_string_1, out) << out; - vector neg_args{"Strawbery", "Orange", "Banan", "Pineapple", - "Kiwi"}; + vector neg_args{"Strawbery", "Orange", "Banan", "Pineapple", "Kiwi"}; dvs::make_string(not_filled_test_string_1, neg_args, out); EXPECT_FALSE(check_test_string_1 == out); } @@ -132,7 +131,7 @@ TEST(CommonUtils, RussianFileC) { TEST(CommonUtils, JsDownloadByCurl) { dvs::tryToDownloadJsByCurl(); } -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { ::testing::InitGoogleTest(&argc, argv); std::ignore = RUN_ALL_TESTS(); return 0; diff --git a/Tests/PlotlyLibTest.cpp b/Tests/PlotlyLibTest.cpp index 30c5090..e32f98d 100644 --- a/Tests/PlotlyLibTest.cpp +++ b/Tests/PlotlyLibTest.cpp @@ -1,11 +1,11 @@ -#include "gtest/gtest.h" #include "plotly_maker/plotly_maker.h" +#include "gtest/gtest.h" #include using std::string; - TEST(PlotlyMaker, CreateDefaultHeatMapHtmlPageTest) { - std::vector>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}}; + std::vector> testValues = { + {43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}}; std::string str_page = "test_page"; auto config = dv::Config(); config.typeVisual = dv::VISUALTYPE_HEATMAP; @@ -22,7 +22,8 @@ TEST(PlotlyMaker, CreateDefaultHeatMapHtmlPageTest) { } TEST(PlotlyMaker, ShowGlamourHeatMapHtmlPageTest) { - std::vector>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}}; + std::vector> testValues = { + {43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}}; std::string str_page = "veryGlamourPage"; auto config = dv::Config(); config.heatmap.colorSc = dv::config_colorscales::COLORSCALE_GLAMOUR; @@ -31,7 +32,8 @@ TEST(PlotlyMaker, ShowGlamourHeatMapHtmlPageTest) { } TEST(PlotlyMaker, ShowThermalHeatMapHtmlPageTest) { - std::vector>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}}; + std::vector> testValues = { + {43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}}; std::string str_page = "veryHotPage"; auto config = dv::Config(); config.heatmap.colorSc = dv::config_colorscales::COLORSCALE_THERMAL; @@ -40,7 +42,8 @@ TEST(PlotlyMaker, ShowThermalHeatMapHtmlPageTest) { } TEST(PlotlyMaker, ShowSunnyHeatMapHtmlPageTest) { - std::vector>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}}; + std::vector> testValues = { + {43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}}; std::string str_page = "SunnyPage"; auto config = dv::Config(); config.heatmap.colorSc = dv::config_colorscales::COLORSCALE_SUNNY; @@ -52,7 +55,7 @@ TEST(PlotlyMaker, ShowWarnigJsAbsentPageTest) { dvs::showWarningJsAbsentPage(); } -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { ::testing::InitGoogleTest(&argc, argv); std::ignore = RUN_ALL_TESTS(); return 0; diff --git a/_astylerc b/_astylerc deleted file mode 100644 index 435563f..0000000 --- a/_astylerc +++ /dev/null @@ -1,39 +0,0 @@ -# Chromium Coding Style Options -# https://chromium.googlesource.com/chromium/src/+/master/styleguide/styleguide.md - -# braces and indent -style=google -indent=spaces=2 - -# indentation -indent-switches -indent-continuation=2 -indent-preproc-block -indent-preproc-define -min-conditional-indent=0 -max-continuation-indent=80 - -# padding -pad-oper -pad-header -unpad-paren -align-pointer=type - -# formatting -break-one-line-headers -keep-one-line-blocks -keep-one-line-statements -convert-tabs -#close-templates - -# objective-c -pad-method-prefix -unpad-return-type -unpad-param-type -align-method-colon -pad-method-colon=none - -# files ---suffix=none ---exclude=./ResourceManager ---recursive diff --git a/array_core/array_core.h b/array_core/array_core.h index 71727e7..752a76c 100644 --- a/array_core/array_core.h +++ b/array_core/array_core.h @@ -1,94 +1,127 @@ #ifndef ARRAY_CORE_ARRAY_CORE_H_ #define ARRAY_CORE_ARRAY_CORE_H_ -//#START_GRAB_TO_INCLUDES_LIST -#include +// #START_GRAB_TO_INCLUDES_LIST #include -//#STOP_GRAB_TO_INCLUDES_LIST -#include "plotly_maker/plotly_maker.h" -#include "common_utils/common_utils.h" +#include +// #STOP_GRAB_TO_INCLUDES_LIST #include "common_utils/common_constants.h" +#include "common_utils/common_utils.h" #include "configurator.h" #include "multi_plot.h" - +#include "plotly_maker/plotly_maker.h" namespace dv { -//#START_GRAB_TO_DV_NAMESPACE - +// #START_GRAB_TO_DV_NAMESPACE //! (matrix) 2-dimensional array template -bool show(T** data, uint64_t arrRows, uint64_t arrCols, - const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); +bool show(T **data, uint64_t arrRows, uint64_t arrCols, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); template -bool save(T** data, uint64_t arrRows, uint64_t arrCols, const std::string& filename, - const configSaveToDisk& configuration = configSaveToDisk()); +bool save(T **data, uint64_t arrRows, uint64_t arrCols, + const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); -//! (matrix) 1-dimensional array that simulates a 2-dimensional one (element access [i*cols+j]) +//! (matrix) 1-dimensional array that simulates a 2-dimensional one (element +//! access [i*cols+j]) template -bool show(const T* data, uint64_t arrRows, uint64_t arrCols, - const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); +bool show(const T *data, uint64_t arrRows, uint64_t arrCols, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); template -bool save(const T* data, uint64_t arrRows, uint64_t arrCols, const std::string& filename, - const configSaveToDisk& configuration = configSaveToDisk()); +bool save(const T *data, uint64_t arrRows, uint64_t arrCols, + const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); //! (chart) 1-dimensional array template -bool show(const T* data, uint64_t count, const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); +bool show(const T *data, uint64_t count, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); template -bool save(const T* data, uint64_t count, const std::string& filename, const configSaveToDisk& configuration = configSaveToDisk()); +bool save(const T *data, uint64_t count, const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); //! +(chart) 1-dimensional container -template()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool show(C const& container, const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); - -template()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool save(C const& container, const std::string& filename, const configSaveToDisk& configuration = configSaveToDisk()); - +template < + typename C, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool show(C const &container, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); + +template < + typename C, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool save(C const &container, const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); //! +(chart) Two 1-dimensional container for X-Y plot -template()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool show(C const& containerX, C const& containerY, const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); - -template()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool save(C const& containerX, C const& containerY, const std::string& filename, const configSaveToDisk& configuration = configSaveToDisk()); - +template < + typename C, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool show(C const &containerX, C const &containerY, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); + +template < + typename C, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool save(C const &containerX, C const &containerY, const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); //! (chart / matrix) 2-dimensional container -template()))>::type, - typename T = typename std::decay()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool show(C const& container_of_containers, const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); - -template()))>::type, - typename T = typename std::decay()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool save(C const& container_of_containers, const std::string& filename, const configSaveToDisk& configuration = configSaveToDisk()); - +template < + typename C, + typename E = + typename std::decay()))>::type, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool show(C const &container_of_containers, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); + +template < + typename C, + typename E = + typename std::decay()))>::type, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool save(C const &container_of_containers, const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); // *********************************** // template functions implementations: // *********************************** template -bool show(T** data, uint64_t arrRows, uint64_t arrCols, const std::string& htmlPageName, const Config& configuration) { +bool show(T **data, uint64_t arrRows, uint64_t arrCols, + const std::string &htmlPageName, const Config &configuration) { if (data == nullptr || arrRows == 0 || arrCols == 0) return false; std::vector> vecVecDbl = - dvs::makeVecVecFromRowPtr(data, arrRows, arrCols); + dvs::makeVecVecFromRowPtr(data, arrRows, arrCols); bool res = false; if (configuration.typeVisual == VISUALTYPE_AUTO || @@ -99,20 +132,23 @@ bool show(T** data, uint64_t arrRows, uint64_t arrCols, const std::string& htmlP } template -bool save(T** data, uint64_t arrRows, uint64_t arrCols, const std::string& filename, const configSaveToDisk& configuration) { +bool save(T **data, uint64_t arrRows, uint64_t arrCols, + const std::string &filename, const configSaveToDisk &configuration) { if (data == nullptr || arrRows == 0 || arrCols == 0) return false; std::vector> vecVec = - dvs::makeVecVecFromRowPtr(data, arrRows, arrCols); + dvs::makeVecVecFromRowPtr(data, arrRows, arrCols); bool res = dvs::saveVecVec(vecVec, filename, configuration); return res; } template -bool show(const T* data, uint64_t arrRows, uint64_t arrCols, const std::string& htmlPageName, const Config& configuration) { +bool show(const T *data, uint64_t arrRows, uint64_t arrCols, + const std::string &htmlPageName, const Config &configuration) { if (data == nullptr || arrRows == 0 || arrCols == 0) return false; - std::vector> vecVecDbl = dvs::makeVecVecFromFlat(data, arrRows, arrCols); + std::vector> vecVecDbl = + dvs::makeVecVecFromFlat(data, arrRows, arrCols); bool res = false; if (configuration.typeVisual == VISUALTYPE_AUTO || configuration.typeVisual == VISUALTYPE_HEATMAP) { @@ -122,17 +158,19 @@ bool show(const T* data, uint64_t arrRows, uint64_t arrCols, const std::string& } template -bool save(const T* data, uint64_t arrRows, uint64_t arrCols, const std::string& filename, - const configSaveToDisk& configuration) { +bool save(const T *data, uint64_t arrRows, uint64_t arrCols, + const std::string &filename, const configSaveToDisk &configuration) { if (data == nullptr || arrRows == 0 || arrCols == 0) return false; - std::vector> vecVec = dvs::makeVecVecFromFlat(data, arrRows, arrCols); + std::vector> vecVec = + dvs::makeVecVecFromFlat(data, arrRows, arrCols); bool res = dvs::saveVecVec(vecVec, filename, configuration); return res; } template -bool show(const T* data, uint64_t count, const std::string& htmlPageName, const Config& configuration) { +bool show(const T *data, uint64_t count, const std::string &htmlPageName, + const Config &configuration) { if (data == nullptr || count == 0) return false; std::vector dblRow = dvs::makeVecFrom1D(data, count); @@ -150,7 +188,8 @@ bool show(const T* data, uint64_t count, const std::string& htmlPageName, const } template -bool save(const T* data, uint64_t count, const std::string& filename, const configSaveToDisk& configuration) { +bool save(const T *data, uint64_t count, const std::string &filename, + const configSaveToDisk &configuration) { if (data == nullptr || count == 0) return false; std::vector row = dvs::makeVecFrom1D(data, count); @@ -158,8 +197,9 @@ bool save(const T* data, uint64_t count, const std::string& filename, const conf return res; } -template -bool show(C const& container, const std::string& htmlPageName, const Config& configuration) { +template +bool show(C const &container, const std::string &htmlPageName, + const Config &configuration) { std::vector dblRow = dvs::makeVecFromContainer(container); bool res = false; if (configuration.typeVisual == VISUALTYPE_AUTO || @@ -174,15 +214,17 @@ bool show(C const& container, const std::string& htmlPageName, const Config& con return res; } -template -bool save(C const& container, const std::string& filename, const configSaveToDisk& configuration) { +template +bool save(C const &container, const std::string &filename, + const configSaveToDisk &configuration) { std::vector row = dvs::makeVecFromContainer(container); bool res = dvs::saveVec(row, filename, configuration); return res; } -template -bool show(C const& containerX, C const& containerY, const std::string& htmlPageName, const Config& configuration) { +template +bool show(C const &containerX, C const &containerY, + const std::string &htmlPageName, const Config &configuration) { if (containerX.size() != containerY.size()) { return false; } @@ -191,7 +233,8 @@ bool show(C const& containerX, C const& containerY, const std::string& htmlPageN bool res = false; if (!dvs::isHold) { - res = dvs::showLineChartInBrowser(dblRowX, dblRowY, htmlPageName, configuration); + res = dvs::showLineChartInBrowser(dblRowX, dblRowY, htmlPageName, + configuration); } else { dvs::addTraceBlockToGlobal(dblRowX, dblRowY, htmlPageName); res = true; @@ -199,8 +242,9 @@ bool show(C const& containerX, C const& containerY, const std::string& htmlPageN return res; } -template -bool save(C const& containerX, C const& containerY, const std::string& filename, const configSaveToDisk& configuration) { +template +bool save(C const &containerX, C const &containerY, const std::string &filename, + const configSaveToDisk &configuration) { if (containerX.size() != containerY.size()) { return false; } @@ -215,11 +259,12 @@ bool save(C const& containerX, C const& containerY, const std::string& filename return res; } -template -bool show(C const& container_of_containers, const std::string& htmlPageName, const Config& configuration) { +template +bool show(C const &container_of_containers, const std::string &htmlPageName, + const Config &configuration) { std::vector> vecVecDbl; vecVecDbl.reserve(container_of_containers.size()); - for (const auto& row : container_of_containers) { + for (const auto &row : container_of_containers) { std::vector dblRow = dvs::makeVecFromContainer(row); vecVecDbl.emplace_back(dblRow); } @@ -229,9 +274,12 @@ bool show(C const& container_of_containers, const std::string& htmlPageName, con if (!vecVecDbl.empty()) { size2 = vecVecDbl[0].size(); } - if ((configuration.typeVisual == VISUALTYPE_AUTO || //case when we want to plot graph with X and Y vectors + if ((configuration.typeVisual == + VISUALTYPE_AUTO || // case when we want to plot graph with X and Y + // vectors configuration.typeVisual == VISUALTYPE_CHART) && - (size1 == 2 || size2 == 2)) { // it can be or 2-columns-data or 2-rows-data + (size1 == 2 || + size2 == 2)) { // it can be or 2-columns-data or 2-rows-data std::vector xVals; std::vector yVals; if (size1 == 2) { @@ -245,7 +293,8 @@ bool show(C const& container_of_containers, const std::string& htmlPageName, con } } if (!dvs::isHold) { - res = dvs::showLineChartInBrowser(xVals, yVals, htmlPageName, configuration); + res = dvs::showLineChartInBrowser(xVals, yVals, htmlPageName, + configuration); } else { dvs::addTraceBlockToGlobal(xVals, yVals, htmlPageName); res = true; @@ -257,11 +306,12 @@ bool show(C const& container_of_containers, const std::string& htmlPageName, con return res; } -template -bool save(C const& container_of_containers, const std::string& filename, const configSaveToDisk& configuration) { +template +bool save(C const &container_of_containers, const std::string &filename, + const configSaveToDisk &configuration) { std::vector> vecVec; vecVec.reserve(container_of_containers.size()); - for (const auto& row : container_of_containers) { + for (const auto &row : container_of_containers) { std::vector rowTemp = dvs::makeVecFromContainer(row); vecVec.emplace_back(rowTemp); } @@ -269,7 +319,7 @@ bool save(C const& container_of_containers, const std::string& filename, const c return res; } -//#STOP_GRAB_TO_DV_NAMESPACE +// #STOP_GRAB_TO_DV_NAMESPACE } // end namespace dv -#endif //ARRAY_CORE_ARRAY_CORE_H_ +#endif // ARRAY_CORE_ARRAY_CORE_H_ diff --git a/array_core/configurator.h b/array_core/configurator.h index 8c301b4..9233c01 100644 --- a/array_core/configurator.h +++ b/array_core/configurator.h @@ -3,10 +3,11 @@ #include namespace dv { -//#START_GRAB_TO_DV_NAMESPACE +// #START_GRAB_TO_DV_NAMESPACE enum config_visualizationTypes { - VISUALTYPE_AUTO, //if user not forces some specific type it will be recognized by context + VISUALTYPE_AUTO, // if user not forces some specific type it will be + // recognized by context VISUALTYPE_CHART, VISUALTYPE_HEATMAP }; @@ -24,38 +25,33 @@ enum config_colorscales { COLORSCALE_PORTLAND }; - struct commonSettings { - commonSettings(): - xLabel("X"), - yLabel("Y"), - aspectRatioWidth(1), - aspectRatioHeight(1), - isFitPlotToWindow(false) {} + commonSettings() + : xLabel("X"), yLabel("Y"), aspectRatioWidth(1), aspectRatioHeight(1), + isFitPlotToWindow(false) {} virtual ~commonSettings() {} std::string title; std::string xLabel; std::string yLabel; std::string zLabel; double aspectRatioWidth; // use it for user scale if isFitPlotToWindow = false - double aspectRatioHeight;// use it for user scale if isFitPlotToWindow = false - bool isFitPlotToWindow; //true - plot fits to browser window, false - square plot + double + aspectRatioHeight; // use it for user scale if isFitPlotToWindow = false + bool isFitPlotToWindow; // true - plot fits to browser window, false - square + // plot }; struct chartSettings : public commonSettings { - //currently empty + // currently empty }; struct heatMapSettings : public commonSettings { - heatMapSettings(): - colorSc(config_colorscales::COLORSCALE_DEFAULT) {} + heatMapSettings() : colorSc(config_colorscales::COLORSCALE_DEFAULT) {} config_colorscales colorSc; }; - struct Config { - Config(): - typeVisual(VISUALTYPE_AUTO) {} + Config() : typeVisual(VISUALTYPE_AUTO) {} void reset() { chart = chartSettings(); heatmap = heatMapSettings(); @@ -67,18 +63,14 @@ struct Config { }; struct configSaveToDisk { - configSaveToDisk(): - separatorOfRows("\n"), - separatorOfCols(";"), - isTranspose(false) {} + configSaveToDisk() + : separatorOfRows("\n"), separatorOfCols(";"), isTranspose(false) {} std::string separatorOfRows; std::string separatorOfCols; - bool isTranspose; //rows-cols or cols-rows + bool isTranspose; // rows-cols or cols-rows }; - - -//#STOP_GRAB_TO_DV_NAMESPACE -}// end namespace dv +// #STOP_GRAB_TO_DV_NAMESPACE +} // end namespace dv #endif // CONFIGURATOR_H diff --git a/array_core/multi_plot.cpp b/array_core/multi_plot.cpp index 26e9ce0..a00b741 100644 --- a/array_core/multi_plot.cpp +++ b/array_core/multi_plot.cpp @@ -1,29 +1,27 @@ #include "multi_plot.h" +#include "common_utils/common_constants.h" +#include "common_utils/common_utils.h" #include "plotly_maker/html_parts.h" #include "plotly_maker/plotly_maker.h" -#include "common_utils/common_utils.h" -#include "common_utils/common_constants.h" namespace dvs { -//#START_GRAB_TO_DVS_NAMESPACE +// #START_GRAB_TO_DVS_NAMESPACE bool isHold = false; std::vector allChartBlocks = {}; -//#STOP_GRAB_TO_DVS_NAMESPACE +// #STOP_GRAB_TO_DVS_NAMESPACE } // end namespace dvs - namespace dv { -//#START_GRAB_TO_DV_NAMESPACE +// #START_GRAB_TO_DV_NAMESPACE void holdOn() { dvs::isHold = true; dvs::allChartBlocks.clear(); - } -void holdOff(const Config& configuration) { +void holdOff(const Config &configuration) { dvs::isHold = false; if (dvs::allChartBlocks.empty()) { return; @@ -41,7 +39,8 @@ void holdOff(const Config& configuration) { allChartBlocks_str.append(dvs::allChartBlocks[i]); } std::string paramWH; - if (configuration.chart.aspectRatioWidth > configuration.chart.aspectRatioHeight) { + if (configuration.chart.aspectRatioWidth > + configuration.chart.aspectRatioHeight) { paramWH = "width"; } else { paramWH = "height"; @@ -56,21 +55,21 @@ void holdOff(const Config& configuration) { } else { paramWHsecond = paramWH; } - std::vector 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, - paramWHsecond, - dvs::kHtmlComboboxStyleBlock, - dvs::kHtmlComboboxSelectBlock, - dvs::kHtmlComboboxUpdateFooBlock, - dvs::kHtmlDavisLogoHyperlinkBlock - }; + std::vector 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, + paramWHsecond, + dvs::kHtmlComboboxStyleBlock, + dvs::kHtmlComboboxSelectBlock, + dvs::kHtmlComboboxUpdateFooBlock, + dvs::kHtmlDavisLogoHyperlinkBlock}; std::string multichartPage = dvs::kHtmlMultiChartModel; std::string filled_multichartPage = ""; dvs::make_string(multichartPage, args, filled_multichartPage); @@ -85,7 +84,5 @@ void holdOff(const Config& configuration) { dvs::allChartBlocks.clear(); } - - -//#STOP_GRAB_TO_DV_NAMESPACE +// #STOP_GRAB_TO_DV_NAMESPACE } // end namespace dv diff --git a/array_core/multi_plot.h b/array_core/multi_plot.h index 2fce9a2..8d1514f 100644 --- a/array_core/multi_plot.h +++ b/array_core/multi_plot.h @@ -1,36 +1,32 @@ #ifndef MULTI_PLOT_H #define MULTI_PLOT_H -#include -#include #include "configurator.h" +#include +#include using std::string; using std::vector; namespace dvs { -//#START_GRAB_TO_DVS_NAMESPACE +// #START_GRAB_TO_DVS_NAMESPACE extern bool isHold; extern vector allChartBlocks; -//#STOP_GRAB_TO_DVS_NAMESPACE +// #STOP_GRAB_TO_DVS_NAMESPACE } // end namespace dvs - namespace dv { -//#START_GRAB_TO_DV_NAMESPACE - +// #START_GRAB_TO_DV_NAMESPACE //! it shows, that we want to start accumulate chart graphs for showing //! them all at one html in one axes void holdOn(); //! finish creation of html page with multi pages -void holdOff(const Config& configuration = Config()); - - +void holdOff(const Config &configuration = Config()); -//#STOP_GRAB_TO_DV_NAMESPACE +// #STOP_GRAB_TO_DV_NAMESPACE } // end namespace dv #endif // MULTI_PLOT_H diff --git a/astyle.exe b/astyle.exe deleted file mode 100644 index 2b14d33..0000000 Binary files a/astyle.exe and /dev/null differ diff --git a/auto_format.bat b/auto_format.bat deleted file mode 100644 index 5bc9ed3..0000000 --- a/auto_format.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo off -echo davis code is formatting... -start /B astyle --project ./*.cpp,*.h -ping localhost -n 3 >nul diff --git a/code_style/cpp/README.md b/code_style/cpp/README.md new file mode 100644 index 0000000..93fdf1c --- /dev/null +++ b/code_style/cpp/README.md @@ -0,0 +1,53 @@ +# Правила и утилиты для автоформатирования кода С++ в проектах CodeBase + +## 💅 Настройка и установка ClangFormat в QtCreator + +
+ +1. Включить необходимые модули(Beautifier и ClangFormat), + зайти в "Справка" -> "О модулях" - см. рис. 1. + + Включение модулей + + *Рисунок 1 - включение модулей.* + +2. Появится модуль "Стилизатор", выберите необходимые + параметры (Включить автоформатирование ClangFormat, + выбрать путь к clang-format.exe и file со стилем кода), см. рис. 2, рис. 3. + Файл(.clang-format) со стилем кода не нужно копировать в каждый проект, + clang-format.exe находит его автоматически в корневой директории кодовой базы + (один экземпляр .clang-format используется во всех проектах). + + Стилизатор + + *Рисунок 2 - включение автоформатирования ClangFormat.* + + Путь к clang-format + + *Рисунок 3 - установка автоформатирования ClangFormat.* +
+ + +> [!NOTE] +> Файл .clang-format лежит в корне CodeBase +> https://github.com/RemsensOrganization/CodeBase/blob/main/.clang-format +> При использовании его в своих проектах кладите на уровень самого проекта или +> выше каталогом, вплоть до корня диска. Тогда эти настройки будут использованы для +> всех проектов уровнями ниже + +
+ + +4. Для автоформатирования кода при сохранении файла нужно + включить переопределение файла ClangFormat, см. рис. 4 + и определить комбинацию горячих клавиш для команды FormatFile, см. рис.5. + + Выбор стиля кода + + *Рисунок 4 - выбор стиля кода ClangFormat.* + + Бинд горячей клавиши + + *Рисунок 5 - использование ClangFormat по комбинации горячих клавиш.* + +
diff --git a/code_style/cpp/clang-format.exe b/code_style/cpp/clang-format.exe new file mode 100644 index 0000000..54669e9 Binary files /dev/null and b/code_style/cpp/clang-format.exe differ diff --git a/code_style/cpp/images/image_1.png b/code_style/cpp/images/image_1.png new file mode 100644 index 0000000..a540814 Binary files /dev/null and b/code_style/cpp/images/image_1.png differ diff --git a/code_style/cpp/images/image_2.png b/code_style/cpp/images/image_2.png new file mode 100644 index 0000000..13fea2e Binary files /dev/null and b/code_style/cpp/images/image_2.png differ diff --git a/code_style/cpp/images/image_3.png b/code_style/cpp/images/image_3.png new file mode 100644 index 0000000..cff4224 Binary files /dev/null and b/code_style/cpp/images/image_3.png differ diff --git a/code_style/cpp/images/image_4.png b/code_style/cpp/images/image_4.png new file mode 100644 index 0000000..3b595d4 Binary files /dev/null and b/code_style/cpp/images/image_4.png differ diff --git a/code_style/cpp/images/image_5.png b/code_style/cpp/images/image_5.png new file mode 100644 index 0000000..445918a Binary files /dev/null and b/code_style/cpp/images/image_5.png differ diff --git a/common_utils/common_constants.cpp b/common_utils/common_constants.cpp index 378f7a4..6e2c711 100644 --- a/common_utils/common_constants.cpp +++ b/common_utils/common_constants.cpp @@ -13,4 +13,4 @@ const char kCloudPagePath[] = "./davis_htmls/cloud_of_points.html"; const char kJsUrlToDownolad[] = "https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.32.0/plotly.min.js"; // #STOP_GRAB_TO_DVS_NAMESPACE -} // namespace dvs +} // namespace dvs diff --git a/common_utils/common_constants.h b/common_utils/common_constants.h index cc2eb16..13e3f89 100644 --- a/common_utils/common_constants.h +++ b/common_utils/common_constants.h @@ -13,6 +13,6 @@ extern const char kReportPagePath[]; extern const char kCloudPagePath[]; extern const char kJsUrlToDownolad[]; // #STOP_GRAB_TO_DVS_NAMESPACE -} // namespace dvs +} // namespace dvs -#endif // COMMON_UTILS_COMMON_CONSTANTS_H +#endif // COMMON_UTILS_COMMON_CONSTANTS_H diff --git a/common_utils/common_utils.cpp b/common_utils/common_utils.cpp index 09c2f60..d287142 100644 --- a/common_utils/common_utils.cpp +++ b/common_utils/common_utils.cpp @@ -25,14 +25,14 @@ namespace dvs { using std::string; #ifdef _WIN32 - #include - #include - #define getcwd _getcwd // stupid MSFT "deprecation" warning +#include +#include +#define getcwd _getcwd // stupid MSFT "deprecation" warning #elif __linux__ - #include +#include #endif -bool is_file_exists(const string& file_name) { +bool is_file_exists(const string &file_name) { std::ifstream file(file_name.c_str()); if (!file) { return false; @@ -40,7 +40,7 @@ bool is_file_exists(const string& file_name) { return true; } -void openFileBySystem(const string& file_name) { +void openFileBySystem(const string &file_name) { string command; #ifdef _WIN32 command = "start "; @@ -58,7 +58,7 @@ void openFileBySystem(const string& file_name) { string getCurrentPath() { #if defined(_WIN32) || (__linux__) char buffer[1024]; - char* answer = getcwd(buffer, sizeof(buffer)); + char *answer = getcwd(buffer, sizeof(buffer)); string s_cwd; if (answer) { s_cwd = answer; @@ -84,7 +84,7 @@ void tryToDownloadJsByCurl() { std::system(cmd.c_str()); } -bool saveStringToFile(const string& file_name, const string& data) { +bool saveStringToFile(const string &file_name, const string &data) { std::ofstream out(file_name); if (out.is_open()) { out << data.c_str(); @@ -94,7 +94,7 @@ bool saveStringToFile(const string& file_name, const string& data) { return false; } -void openPlotlyHtml(const string& file_name) { openFileBySystem(file_name); } +void openPlotlyHtml(const string &file_name) { openFileBySystem(file_name); } void sleepMicroSec(unsigned long microsec) { #ifdef _WIN32 @@ -116,7 +116,7 @@ void mayBeCreateJsWorkingFolder() { } } -bool deleteFolder(const char* fname) { +bool deleteFolder(const char *fname) { struct stat sb; if (stat(fname, &sb) == 0) { // rmdir(fname); @@ -126,7 +126,7 @@ bool deleteFolder(const char* fname) { } } -bool get_data_from_file(const string& path, vector& result) { +bool get_data_from_file(const string &path, vector &result) { // TODO different scenarious and sanitizing std::setlocale(LC_ALL, "ru_RU.UTF-8"); if (!is_file_exists(path)) { @@ -148,7 +148,7 @@ bool get_data_from_file(const string& path, vector& result) { return true; } -bool readMatrix(vector>& outMatrix, const std::string& path, +bool readMatrix(vector> &outMatrix, const std::string &path, char dlmtr) { outMatrix.clear(); std::setlocale(LC_ALL, "ru_RU.UTF-8"); @@ -158,7 +158,7 @@ bool readMatrix(vector>& outMatrix, const std::string& path, if (ifs) { while (!ifs.eof()) { std::getline(ifs, str); - if (str.size() == 0) // if exist empty line + if (str.size() == 0) // if exist empty line continue; std::vector parts = split(str, dlmtr); vector doubleLine; @@ -176,7 +176,7 @@ bool readMatrix(vector>& outMatrix, const std::string& path, } } -vector split(const string& target, char c) { +vector split(const string &target, char c) { std::string temp; std::stringstream stringstream{target}; std::vector result; @@ -187,7 +187,7 @@ vector split(const string& target, char c) { return result; } -bool make_string(const string& src, const vector& args, string& out) { +bool make_string(const string &src, const vector &args, string &out) { if (!out.empty()) { out.clear(); } @@ -249,7 +249,7 @@ bool make_string(const string& src, const vector& args, string& out) { return true; } -int find_separator(const std::string& src, char& separator) { +int find_separator(const std::string &src, char &separator) { std::vector ignored_chars = {'+', '-', 'e', 'E', '.', '\r', ','}; std::set unique_chars; bool is_service_char = false; @@ -299,27 +299,25 @@ int find_separator(const std::string& src, char& separator) { return UNDEFINED_BEHAVIOR; } -string removeSpecialCharacters(const string& s) { +string removeSpecialCharacters(const string &s) { string t; for (int i = 0; i < s.length(); i++) { if (s[i] == ' ') { t += '_'; - } else if ((s[i] >= 'a' && s[i] <= 'z') || - (s[i] >= 'A' && s[i] <= 'Z') || - (s[i] >= '0' && s[i] <= '9') || (s[i] == '-') || - (s[i] == '_')) { + } else if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z') || + (s[i] >= '0' && s[i] <= '9') || (s[i] == '-') || (s[i] == '_')) { t += s[i]; } } return t; } -bool is_string_convertable_to_digit(const string& sample) { +bool is_string_convertable_to_digit(const string &sample) { try { std::ignore = std::stod(sample); - } catch (const std::invalid_argument& e) { + } catch (const std::invalid_argument &e) { return false; - } catch (const std::out_of_range& e) { + } catch (const std::out_of_range &e) { return false; } return true; @@ -336,7 +334,7 @@ string nullIfNotFinite(double val) { return plotlyVar; } -string vectorToString(const vector& vec) { +string vectorToString(const vector &vec) { std::ostringstream oss; for (size_t i = 0; i < vec.size(); ++i) { if (i != 0) { @@ -359,7 +357,7 @@ std::string makeUniqueDavisHtmlName() { #if defined(_MSC_VER) localtime_s(&tm, &in_time_t); #else - if (std::tm* p = std::localtime(&in_time_t)) + if (std::tm *p = std::localtime(&in_time_t)) tm = *p; #endif std::ostringstream ss; @@ -370,13 +368,10 @@ std::string makeUniqueDavisHtmlName() { std::string makeUniqueDavisHtmlRelativePath() { string name = makeUniqueDavisHtmlName(); - return std::string("./") - .append(kOutFolderName) - .append(name) - .append(".html"); + return std::string("./").append(kOutFolderName).append(name).append(".html"); } -void transponeMatrix(std::vector>& matrix) { +void transponeMatrix(std::vector> &matrix) { if (matrix.empty()) return; @@ -392,37 +387,37 @@ void transponeMatrix(std::vector>& matrix) { matrix = std::move(transposed); } -vector calculateAverageVector(const vector>& vectors) { +vector calculateAverageVector(const vector> &vectors) { if (vectors.empty()) { throw std::invalid_argument("Input vector of vectors is empty."); } size_t vectorSize = vectors[0].size(); - for (const auto& vec : vectors) { + for (const auto &vec : vectors) { if (vec.size() != vectorSize) { throw std::invalid_argument("All vectors must have the same size."); } } std::vector averageVector(vectorSize, 0.0); - for (const auto& vec : vectors) { + for (const auto &vec : vectors) { for (size_t i = 0; i < vectorSize; ++i) { averageVector[i] += vec[i]; } } - for (double& value : averageVector) { + for (double &value : averageVector) { value /= vectors.size(); } return averageVector; } -vector calculateStandardDeviation(const vector& mean, - const vector>& data) { +vector calculateStandardDeviation(const vector &mean, + const vector> &data) { std::vector stddev(mean.size(), 0.0); int n = data.size(); - for (const auto& vec : data) { + for (const auto &vec : data) { for (size_t i = 0; i < vec.size(); ++i) { double diff = vec[i] - mean[i]; stddev[i] += diff * diff; @@ -434,7 +429,7 @@ vector calculateStandardDeviation(const vector& mean, return stddev; } -std::string reverseString(const std::string& input) { +std::string reverseString(const std::string &input) { std::stringstream ss(input); std::string item; std::vector elements; @@ -456,8 +451,8 @@ std::string reverseString(const std::string& input) { return result; } -vector doubleAndReverse(const vector& input, - const vector& mean) { +vector doubleAndReverse(const vector &input, + const vector &mean) { vector result(input.size(), 0); vector minus_result = input; for (size_t i = 0; i < result.size(); ++i) { @@ -470,4 +465,4 @@ vector doubleAndReverse(const vector& input, } // #STOP_GRAB_TO_DVS_NAMESPACE -}; // namespace dvs +}; // namespace dvs diff --git a/common_utils/common_utils.h b/common_utils/common_utils.h index 531b5bf..ba20cad 100644 --- a/common_utils/common_utils.h +++ b/common_utils/common_utils.h @@ -30,45 +30,45 @@ using std::vector; string getCurrentPath(); -bool is_file_exists(const string& file_name); +bool is_file_exists(const string &file_name); -void openFileBySystem(const string& file_name); +void openFileBySystem(const string &file_name); bool isPlotlyScriptExists(); void tryToDownloadJsByCurl(); -bool saveStringToFile(const string& file_name, const string& data); +bool saveStringToFile(const string &file_name, const string &data); void mayBeCreateJsWorkingFolder(); void sleepMicroSec(unsigned long microsec); -void openPlotlyHtml(const string& file_name); +void openPlotlyHtml(const string &file_name); -bool get_data_from_file(const string& path, vector& result); +bool get_data_from_file(const string &path, vector &result); -vector split(const string& target, char c); +vector split(const string &target, char c); -bool readMatrix(vector>& outMatrix, const string& path, +bool readMatrix(vector> &outMatrix, const string &path, char dlmtr); -bool make_string(const string& src, const vector& args, string& out); +bool make_string(const string &src, const vector &args, string &out); // Now it doesn't work. -bool deleteFolder(const char* fname); +bool deleteFolder(const char *fname); -int find_separator(const std::string& src, char& separator); +int find_separator(const std::string &src, char &separator); //! remove special characters except letters, numbers and '-', '_'. Spaces -> //! '_' -string removeSpecialCharacters(const string& s); +string removeSpecialCharacters(const string &s); //! convert this cases to string "null" for Plotly string nullIfNotFinite(double val); //! convert vec to string, separated by "," -string vectorToString(const vector& vec); +string vectorToString(const vector &vec); //! only name string makeUniqueDavisHtmlName(); @@ -77,8 +77,7 @@ string makeUniqueDavisHtmlName(); string makeUniqueDavisHtmlRelativePath(); //! sometimes std::to_string reurn str with ',' as separator what is wrong -template -string toStringDotSeparator(T data) { +template string toStringDotSeparator(T data) { string str = std::to_string(data); std::replace(str.begin(), str.end(), ',', '.'); return str; @@ -86,7 +85,7 @@ string toStringDotSeparator(T data) { //! save to disk vector data template -bool saveVec(const vector& vec, const string& filename, +bool saveVec(const vector &vec, const string &filename, dv::configSaveToDisk config) { if (vec.size() == 0) { return false; @@ -105,7 +104,7 @@ bool saveVec(const vector& vec, const string& filename, //! save to disk vector> data template -bool saveVecVec(const vector>& vecVec, const string& filename, +bool saveVecVec(const vector> &vecVec, const string &filename, dv::configSaveToDisk config) { if (vecVec.size() == 0) { return false; @@ -124,7 +123,7 @@ bool saveVecVec(const vector>& vecVec, const string& filename, for (int j = 0; j < cols; ++j) { double val = vecVec.at(j).at(i); fout << val; - if (j < cols - 1) { // we dont need sep at row end + if (j < cols - 1) { // we dont need sep at row end fout << config.separatorOfCols; } } @@ -137,7 +136,7 @@ bool saveVecVec(const vector>& vecVec, const string& filename, for (size_t j = 0; j < cols; ++j) { double val = vecVec.at(i).at(j); fout << val; - if (j < cols - 1) { // we dont need sep at row end + if (j < cols - 1) { // we dont need sep at row end fout << config.separatorOfCols; } } @@ -151,16 +150,16 @@ bool saveVecVec(const vector>& vecVec, const string& filename, //! convert any container to std::vector template < typename G, - typename C, // https://devblogs.microsoft.com/oldnewthing/20190619-00/?p=102599 + typename C, // https://devblogs.microsoft.com/oldnewthing/20190619-00/?p=102599 typename T = - typename std::decay()))>::type, + typename std::decay()))>::type, typename Enable = - typename std::enable_if::value>::type > -std::vector makeVecFromContainer(const C& container) { + typename std::enable_if::value>::type> +std::vector makeVecFromContainer(const C &container) { std::vector vec; vec.reserve(static_cast( - std::distance(std::begin(container), std::end(container)))); - for (auto const& v : container) { + std::distance(std::begin(container), std::end(container)))); + for (auto const &v : container) { vec.push_back(static_cast(v)); } return vec; @@ -168,13 +167,12 @@ std::vector makeVecFromContainer(const C& container) { //! convert T** to std::vector template -inline std::vector> makeVecVecFromRowPtr(const T* const* data, - uint64_t rows, -uint64_t cols) { +inline std::vector> +makeVecVecFromRowPtr(const T *const *data, uint64_t rows, uint64_t cols) { std::vector> res; res.reserve(rows); for (uint64_t i = 0; i < rows; ++i) { - const T* rowPtr = data[i]; + const T *rowPtr = data[i]; std::vector row; row.reserve(cols); for (uint64_t j = 0; j < cols; ++j) @@ -186,13 +184,12 @@ uint64_t cols) { //! convert pseudo 2D T* to std::vector template -inline std::vector> makeVecVecFromFlat(const T* data, - uint64_t rows, -uint64_t cols) { +inline std::vector> +makeVecVecFromFlat(const T *data, uint64_t rows, uint64_t cols) { std::vector> res; res.reserve(rows); for (uint64_t i = 0; i < rows; ++i) { - const T* rowPtr = data + i * cols; + const T *rowPtr = data + i * cols; std::vector row; row.reserve(cols); for (uint64_t j = 0; j < cols; ++j) @@ -204,7 +201,7 @@ uint64_t cols) { //! convert pseudo T* to std::vector template -inline std::vector makeVecFrom1D(const T* data, uint64_t count) { +inline std::vector makeVecFrom1D(const T *data, uint64_t count) { std::vector res; res.reserve(static_cast(count)); for (uint64_t i = 0; i < count; ++i) @@ -212,23 +209,23 @@ inline std::vector makeVecFrom1D(const T* data, uint64_t count) { return res; } -bool is_string_convertable_to_digit(const string& sample); +bool is_string_convertable_to_digit(const string &sample); -void transponeMatrix(std::vector>& matrix); +void transponeMatrix(std::vector> &matrix); -vector calculateAverageVector(const vector>& vectors); +vector calculateAverageVector(const vector> &vectors); -vector calculateStandardDeviation(const vector& mean, - const vector>& data); +vector calculateStandardDeviation(const vector &mean, + const vector> &data); -vector doubleAndReverse(const vector& input, - const vector& mean); +vector doubleAndReverse(const vector &input, + const vector &mean); -std::string reverseString(const std::string& input); +std::string reverseString(const std::string &input); template -std::vector> readBinaryFile(const std::string& filePath, -size_t rowLength) { +std::vector> readBinaryFile(const std::string &filePath, + size_t rowLength) { std::ifstream file(filePath, std::ios::binary); if (!file) { throw std::runtime_error("Cannot open file"); @@ -238,7 +235,7 @@ size_t rowLength) { std::vector row(rowLength); while ( - file.read(reinterpret_cast(row.data()), rowLength * sizeof(T))) { + file.read(reinterpret_cast(row.data()), rowLength * sizeof(T))) { data.push_back(row); } @@ -253,6 +250,6 @@ size_t rowLength) { } // #STOP_GRAB_TO_DVS_NAMESPACE -}; // namespace dvs +}; // namespace dvs -#endif // COMMON_UTILS_COMMON_UTILS_H_ +#endif // COMMON_UTILS_COMMON_UTILS_H_ diff --git a/davis.h b/davis.h index 0d8edec..cbe5069 100644 --- a/davis.h +++ b/davis.h @@ -1,11 +1,11 @@ #ifndef DAVIS_H #define DAVIS_H +#include "array_core/configurator.h" +#include "plotly_maker/plotly_maker.h" +#include #include #include -#include -#include "plotly_maker/plotly_maker.h" -#include "array_core/configurator.h" /* namespace { diff --git a/davis_launcher.cpp b/davis_launcher.cpp index 3434ab6..b6d0dd6 100644 --- a/davis_launcher.cpp +++ b/davis_launcher.cpp @@ -1,6 +1,6 @@ #include "davis.h" -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { /* vectorv = {8.0, 8.0, 9, 0, 55}; vector>hm = {{8.0, 8.0, 9, 0, 55}, {5.0, 18.0, 0.9, 50, 15}}; diff --git a/davis_one/davis.cpp b/davis_one/davis.cpp index 12acf02..979716c 100644 --- a/davis_one/davis.cpp +++ b/davis_one/davis.cpp @@ -42,7 +42,7 @@ const char kJsUrlToDownolad[] = } // namespace dvs end namespace dvs { -// *INDENT-OFF* +// clang-format off const char kHtmlModel[] = R"( @@ -779,7 +779,7 @@ const char kAverageErrorDataBlock[] = R"davis_delimeter({ } )davis_delimeter"; -// *INDENT-ON* +// clang-format on } // namespace dvs end @@ -787,14 +787,14 @@ namespace dvs { using std::string; #ifdef _WIN32 - #include - #include - #define getcwd _getcwd // stupid MSFT "deprecation" warning +#include +#include +#define getcwd _getcwd // stupid MSFT "deprecation" warning #elif __linux__ - #include +#include #endif -bool is_file_exists(const string& file_name) { +bool is_file_exists(const string &file_name) { std::ifstream file(file_name.c_str()); if (!file) { return false; @@ -802,7 +802,7 @@ bool is_file_exists(const string& file_name) { return true; } -void openFileBySystem(const string& file_name) { +void openFileBySystem(const string &file_name) { string command; #ifdef _WIN32 command = "start "; @@ -820,7 +820,7 @@ void openFileBySystem(const string& file_name) { string getCurrentPath() { #if defined(_WIN32) || (__linux__) char buffer[1024]; - char* answer = getcwd(buffer, sizeof(buffer)); + char *answer = getcwd(buffer, sizeof(buffer)); string s_cwd; if (answer) { s_cwd = answer; @@ -846,7 +846,7 @@ void tryToDownloadJsByCurl() { std::system(cmd.c_str()); } -bool saveStringToFile(const string& file_name, const string& data) { +bool saveStringToFile(const string &file_name, const string &data) { std::ofstream out(file_name); if (out.is_open()) { out << data.c_str(); @@ -856,7 +856,7 @@ bool saveStringToFile(const string& file_name, const string& data) { return false; } -void openPlotlyHtml(const string& file_name) { openFileBySystem(file_name); } +void openPlotlyHtml(const string &file_name) { openFileBySystem(file_name); } void sleepMicroSec(unsigned long microsec) { #ifdef _WIN32 @@ -878,7 +878,7 @@ void mayBeCreateJsWorkingFolder() { } } -bool deleteFolder(const char* fname) { +bool deleteFolder(const char *fname) { struct stat sb; if (stat(fname, &sb) == 0) { // rmdir(fname); @@ -888,7 +888,7 @@ bool deleteFolder(const char* fname) { } } -bool get_data_from_file(const string& path, vector& result) { +bool get_data_from_file(const string &path, vector &result) { // TODO different scenarious and sanitizing std::setlocale(LC_ALL, "ru_RU.UTF-8"); if (!is_file_exists(path)) { @@ -910,7 +910,7 @@ bool get_data_from_file(const string& path, vector& result) { return true; } -bool readMatrix(vector>& outMatrix, const std::string& path, +bool readMatrix(vector> &outMatrix, const std::string &path, char dlmtr) { outMatrix.clear(); std::setlocale(LC_ALL, "ru_RU.UTF-8"); @@ -920,7 +920,7 @@ bool readMatrix(vector>& outMatrix, const std::string& path, if (ifs) { while (!ifs.eof()) { std::getline(ifs, str); - if (str.size() == 0) // if exist empty line + if (str.size() == 0) // if exist empty line continue; std::vector parts = split(str, dlmtr); vector doubleLine; @@ -938,7 +938,7 @@ bool readMatrix(vector>& outMatrix, const std::string& path, } } -vector split(const string& target, char c) { +vector split(const string &target, char c) { std::string temp; std::stringstream stringstream{target}; std::vector result; @@ -949,7 +949,7 @@ vector split(const string& target, char c) { return result; } -bool make_string(const string& src, const vector& args, string& out) { +bool make_string(const string &src, const vector &args, string &out) { if (!out.empty()) { out.clear(); } @@ -1011,7 +1011,7 @@ bool make_string(const string& src, const vector& args, string& out) { return true; } -int find_separator(const std::string& src, char& separator) { +int find_separator(const std::string &src, char &separator) { std::vector ignored_chars = {'+', '-', 'e', 'E', '.', '\r', ','}; std::set unique_chars; bool is_service_char = false; @@ -1061,27 +1061,25 @@ int find_separator(const std::string& src, char& separator) { return UNDEFINED_BEHAVIOR; } -string removeSpecialCharacters(const string& s) { +string removeSpecialCharacters(const string &s) { string t; for (int i = 0; i < s.length(); i++) { if (s[i] == ' ') { t += '_'; - } else if ((s[i] >= 'a' && s[i] <= 'z') || - (s[i] >= 'A' && s[i] <= 'Z') || - (s[i] >= '0' && s[i] <= '9') || (s[i] == '-') || - (s[i] == '_')) { + } else if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z') || + (s[i] >= '0' && s[i] <= '9') || (s[i] == '-') || (s[i] == '_')) { t += s[i]; } } return t; } -bool is_string_convertable_to_digit(const string& sample) { +bool is_string_convertable_to_digit(const string &sample) { try { std::ignore = std::stod(sample); - } catch (const std::invalid_argument& e) { + } catch (const std::invalid_argument &e) { return false; - } catch (const std::out_of_range& e) { + } catch (const std::out_of_range &e) { return false; } return true; @@ -1098,7 +1096,7 @@ string nullIfNotFinite(double val) { return plotlyVar; } -string vectorToString(const vector& vec) { +string vectorToString(const vector &vec) { std::ostringstream oss; for (size_t i = 0; i < vec.size(); ++i) { if (i != 0) { @@ -1121,7 +1119,7 @@ std::string makeUniqueDavisHtmlName() { #if defined(_MSC_VER) localtime_s(&tm, &in_time_t); #else - if (std::tm* p = std::localtime(&in_time_t)) + if (std::tm *p = std::localtime(&in_time_t)) tm = *p; #endif std::ostringstream ss; @@ -1132,13 +1130,10 @@ std::string makeUniqueDavisHtmlName() { std::string makeUniqueDavisHtmlRelativePath() { string name = makeUniqueDavisHtmlName(); - return std::string("./") - .append(kOutFolderName) - .append(name) - .append(".html"); + return std::string("./").append(kOutFolderName).append(name).append(".html"); } -void transponeMatrix(std::vector>& matrix) { +void transponeMatrix(std::vector> &matrix) { if (matrix.empty()) return; @@ -1154,37 +1149,37 @@ void transponeMatrix(std::vector>& matrix) { matrix = std::move(transposed); } -vector calculateAverageVector(const vector>& vectors) { +vector calculateAverageVector(const vector> &vectors) { if (vectors.empty()) { throw std::invalid_argument("Input vector of vectors is empty."); } size_t vectorSize = vectors[0].size(); - for (const auto& vec : vectors) { + for (const auto &vec : vectors) { if (vec.size() != vectorSize) { throw std::invalid_argument("All vectors must have the same size."); } } std::vector averageVector(vectorSize, 0.0); - for (const auto& vec : vectors) { + for (const auto &vec : vectors) { for (size_t i = 0; i < vectorSize; ++i) { averageVector[i] += vec[i]; } } - for (double& value : averageVector) { + for (double &value : averageVector) { value /= vectors.size(); } return averageVector; } -vector calculateStandardDeviation(const vector& mean, - const vector>& data) { +vector calculateStandardDeviation(const vector &mean, + const vector> &data) { std::vector stddev(mean.size(), 0.0); int n = data.size(); - for (const auto& vec : data) { + for (const auto &vec : data) { for (size_t i = 0; i < vec.size(); ++i) { double diff = vec[i] - mean[i]; stddev[i] += diff * diff; @@ -1196,7 +1191,7 @@ vector calculateStandardDeviation(const vector& mean, return stddev; } -std::string reverseString(const std::string& input) { +std::string reverseString(const std::string &input) { std::stringstream ss(input); std::string item; std::vector elements; @@ -1218,8 +1213,8 @@ std::string reverseString(const std::string& input) { return result; } -vector doubleAndReverse(const vector& input, - const vector& mean) { +vector doubleAndReverse(const vector &input, + const vector &mean) { vector result(input.size(), 0); vector minus_result = input; for (size_t i = 0; i < result.size(); ++i) { @@ -1236,9 +1231,7 @@ vector doubleAndReverse(const vector& input, namespace dvs { - - -bool checkThatSizesAreTheSame(const vector>& values) { +bool checkThatSizesAreTheSame(const vector> &values) { size_t size = 0; if (!values.empty()) { size = values[0].size(); @@ -1253,8 +1246,8 @@ bool checkThatSizesAreTheSame(const vector>& values) { return true; } -bool createStringHeatMapValues(const vector>& values, - string& str_values) { +bool createStringHeatMapValues(const vector> &values, + string &str_values) { if (!checkThatSizesAreTheSame(values)) return false; if (!str_values.empty()) @@ -1278,9 +1271,9 @@ bool createStringHeatMapValues(const vector>& values, return true; } -bool createStringLineChartValues(const vector& xValues, - const vector& yValues, - string& out_str_values) { +bool createStringLineChartValues(const vector &xValues, + const vector &yValues, + string &out_str_values) { if (xValues.size() != yValues.size()) { return false; } @@ -1302,16 +1295,17 @@ bool createStringLineChartValues(const vector& xValues, out_str_values.append(","); } } - out_str_values.append("], mode: 'lines', hovertemplate: 'x:%{x}, y:%{y:.} ' };var data = [trace];"); + out_str_values.append("], mode: 'lines', hovertemplate: 'x:%{x}, y:%{y:.} " + "' };var data = [trace];"); return true; } -bool getMatrixValuesFromString(const string& in_values, - vector>& out_values) { +bool getMatrixValuesFromString(const string &in_values, + vector> &out_values) { istringstream f_lines(in_values); string lines; while (std::getline(f_lines, lines, ';')) { - vectorvals; + vector vals; istringstream f_values(lines); string str_value; while (std::getline(f_values, str_value, ',')) { @@ -1322,9 +1316,8 @@ bool getMatrixValuesFromString(const string& in_values, return true; }; -bool createHtmlPageHeatmap(const std::vector>& values, - string& page, - const dv::Config& configuration) { +bool createHtmlPageHeatmap(const std::vector> &values, + string &page, const dv::Config &configuration) { vector args(ARGS_SIZE, ""); string str_values = ""; if (!checkThatSizesAreTheSame(values)) { @@ -1338,10 +1331,13 @@ bool createHtmlPageHeatmap(const std::vector>& values, args[ARG_TITLE_X] = configuration.heatmap.xLabel; args[ARG_TITLE_Y] = configuration.heatmap.yLabel; args[ARG_TITLE_Z] = configuration.heatmap.zLabel; - args[ARG_ASPECT_RATIO_WIDTH] = dvs::toStringDotSeparator(configuration.heatmap.aspectRatioWidth); - args[ARG_ASPECT_RATIO_HEIGHT] = dvs::toStringDotSeparator(configuration.heatmap.aspectRatioHeight); + 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) { + if (configuration.heatmap.aspectRatioWidth > + configuration.heatmap.aspectRatioHeight) { paramWH = "width"; } else { paramWH = "height"; @@ -1360,50 +1356,52 @@ bool createHtmlPageHeatmap(const std::vector>& values, 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_POINT_LINE_SWITCHER_UPDATE_FOO] = + kHtmlComboboxUpdateSurfaceMatrixFooBlock; args[ARG_DAVIS_LOGO] = kHtmlDavisLogoHyperlinkBlock; dv::config_colorscales clrScale; clrScale = configuration.heatmap.colorSc; switch (clrScale) { - case dv::config_colorscales::COLORSCALE_DEFAULT: - args[ARG_COLOR_MAP] = kColorMapDefaultPart; - break; - case dv::config_colorscales::COLORSCALE_SUNNY: - args[ARG_COLOR_MAP] = kColorMapSunnyPart; - break; - case dv::config_colorscales::COLORSCALE_GLAMOUR: - args[ARG_COLOR_MAP] = kColorMapGlamourPart; - break; - case dv::config_colorscales::COLORSCALE_THERMAL: - args[ARG_COLOR_MAP] = kColorMapThermalPart; - break; - case dv::config_colorscales::COLORSCALE_GRAYSCALE: - args[ARG_COLOR_MAP] = kColorMapGrayscalePart; - break; - case dv::config_colorscales::COLORSCALE_YlGnBu: - args[ARG_COLOR_MAP] = kColorMapYlGnBuPart; - break; - case dv::config_colorscales::COLORSCALE_JET: - args[ARG_COLOR_MAP] = kColorMapJetPart; - break; - case dv::config_colorscales::COLORSCALE_HOT: - args[ARG_COLOR_MAP] = kColorMapHotPart; - break; - case dv::config_colorscales::COLORSCALE_ELECTRIC: - args[ARG_COLOR_MAP] = kColorMapElectricPart; - break; - case dv::config_colorscales::COLORSCALE_PORTLAND: - args[ARG_COLOR_MAP] = kColorMapPortlandPart; - break; + case dv::config_colorscales::COLORSCALE_DEFAULT: + args[ARG_COLOR_MAP] = kColorMapDefaultPart; + break; + case dv::config_colorscales::COLORSCALE_SUNNY: + args[ARG_COLOR_MAP] = kColorMapSunnyPart; + break; + case dv::config_colorscales::COLORSCALE_GLAMOUR: + args[ARG_COLOR_MAP] = kColorMapGlamourPart; + break; + case dv::config_colorscales::COLORSCALE_THERMAL: + args[ARG_COLOR_MAP] = kColorMapThermalPart; + break; + case dv::config_colorscales::COLORSCALE_GRAYSCALE: + args[ARG_COLOR_MAP] = kColorMapGrayscalePart; + break; + case dv::config_colorscales::COLORSCALE_YlGnBu: + args[ARG_COLOR_MAP] = kColorMapYlGnBuPart; + break; + case dv::config_colorscales::COLORSCALE_JET: + args[ARG_COLOR_MAP] = kColorMapJetPart; + break; + case dv::config_colorscales::COLORSCALE_HOT: + args[ARG_COLOR_MAP] = kColorMapHotPart; + break; + case dv::config_colorscales::COLORSCALE_ELECTRIC: + args[ARG_COLOR_MAP] = kColorMapElectricPart; + break; + case dv::config_colorscales::COLORSCALE_PORTLAND: + args[ARG_COLOR_MAP] = kColorMapPortlandPart; + break; } make_string(kHtmlModel, args, page); return true; } -bool showHeatMapInBrowser(const vector>& values, - const string& title, const dv::Config& configuration) { +bool showHeatMapInBrowser(const vector> &values, + const string &title, + const dv::Config &configuration) { string page; if (!createHtmlPageHeatmap(values, page, configuration)) { return false; @@ -1411,37 +1409,42 @@ bool showHeatMapInBrowser(const vector>& values, string pageName; mayBeCreateJsWorkingFolder(); string titleWithoutSpecialChars = dvs::removeSpecialCharacters(title); - pageName.append("./").append(kOutFolderName).append(titleWithoutSpecialChars).append(".html"); + pageName.append("./") + .append(kOutFolderName) + .append(titleWithoutSpecialChars) + .append(".html"); saveStringToFile(pageName, page); if (isPlotlyScriptExists()) { openPlotlyHtml(pageName); } else { showWarningJsAbsentPage(); } - return true;// TODO handle different exceptions + return true; // TODO handle different exceptions } -bool showHeatMapInBrowser(const string& values, - const string& title, const dv::Config& configuration) { - vector>heat_map_values; +bool showHeatMapInBrowser(const string &values, const string &title, + const dv::Config &configuration) { + vector> heat_map_values; getMatrixValuesFromString(values, heat_map_values); showHeatMapInBrowser(heat_map_values, title, configuration); return true; }; -bool showLineChartInBrowser(const vector& values, - const string& title, const dv::Config& configuration) { +bool showLineChartInBrowser(const vector &values, const string &title, + const dv::Config &configuration) { vector x(values.size()); - std::iota(std::begin(x), std::end(x), 0); // Fill with 0, 1, 2... + std::iota(std::begin(x), std::end(x), 0); // Fill with 0, 1, 2... showLineChartInBrowser(x, values, title, configuration); return true; } -bool showLineChartInBrowser(const vector& xValues, const vector& yValues, - const std::string& title, const dv::Config& configuration) { +bool showLineChartInBrowser(const vector &xValues, + const vector &yValues, + const std::string &title, + const dv::Config &configuration) { string page; - vectorargs(ARGS_SIZE, ""); + vector args(ARGS_SIZE, ""); args[ARG_JS_VER] = kPlotlyJsName; string str_values = ""; createStringLineChartValues(xValues, yValues, str_values); @@ -1449,10 +1452,13 @@ bool showLineChartInBrowser(const vector& xValues, const vector& args[ARG_TITLE] = configuration.chart.title; args[ARG_TITLE_X] = configuration.chart.xLabel; args[ARG_TITLE_Y] = configuration.chart.yLabel; - args[ARG_ASPECT_RATIO_WIDTH] = dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth); - args[ARG_ASPECT_RATIO_HEIGHT] = dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight); + args[ARG_ASPECT_RATIO_WIDTH] = + dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth); + args[ARG_ASPECT_RATIO_HEIGHT] = + dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight); string paramWH; - if (configuration.chart.aspectRatioWidth > configuration.chart.aspectRatioHeight) { + if (configuration.chart.aspectRatioWidth > + configuration.chart.aspectRatioHeight) { paramWH = "width"; } else { paramWH = "height"; @@ -1477,7 +1483,10 @@ bool showLineChartInBrowser(const vector& xValues, const vector& string pageName; mayBeCreateJsWorkingFolder(); string titleWithoutSpecialChars = dvs::removeSpecialCharacters(title); - pageName.append("./").append(kOutFolderName).append(titleWithoutSpecialChars).append(".html"); + pageName.append("./") + .append(kOutFolderName) + .append(titleWithoutSpecialChars) + .append(".html"); saveStringToFile(pageName, page); if (isPlotlyScriptExists()) { openPlotlyHtml(pageName); @@ -1487,9 +1496,9 @@ bool showLineChartInBrowser(const vector& xValues, const vector& return true; } -bool showLineChartInBrowser(const string& values, - const string& title, const dv::Config& configuration) { - vectorvals; +bool showLineChartInBrowser(const string &values, const string &title, + const dv::Config &configuration) { + vector vals; istringstream f(values); string s; while (std::getline(f, s, ',')) { @@ -1507,7 +1516,7 @@ void showWarningJsAbsentPage() { #elif __linux__ davis_dir = "/davis_htmls"; #endif - vectorargs {ARGS_WARNING_PAGE_SIZE, ""}; + vector args{ARGS_WARNING_PAGE_SIZE, ""}; args[ARG_WORKING_FOLDER] = getCurrentPath() + davis_dir; args[ARG_JS_VERSION] = kPlotlyJsName; make_string(kWarningJSLibAbsentPage, args, out); @@ -1515,10 +1524,8 @@ void showWarningJsAbsentPage() { openFileBySystem(kWarningPagePath); } - -void showReportPage(const string& title, - const string& svg, - const string& description) { +void showReportPage(const string &title, const string &svg, + const string &description) { string out; string davis_dir; @@ -1527,63 +1534,55 @@ void showReportPage(const string& title, #elif __linux__ davis_dir = "/davis_htmls"; #endif - vectorargs {ARGS_REPORT_PAGE_SIZE, ""}; + vector args{ARGS_REPORT_PAGE_SIZE, ""}; args[ARG_REPORT_TITLE] = title; args[ARG_SVG_ICON] = svg; args[ARG_REPORT_DESCRIPTION] = description; make_string(kNoFileFoundedPage, args, out); saveStringToFile(kReportPagePath, out); openFileBySystem(kReportPagePath); - } - void showReportFileNotFounded() { - showReportPage("Open file error.", - kWarningIcon, + showReportPage("Open file error.", kWarningIcon, "File is not founded. Please, check the path to the file."); } void showReportFileEmpty() { - showReportPage("File is empty.", - kWarningIcon, - "No data to show."); + showReportPage("File is empty.", kWarningIcon, "No data to show."); } - void showMatrixSizesAreNotTheSame(int badRow) { string text; - text.append("Rows have different sizes in matrix. Check the row № ").append(std::to_string(badRow + 1)); - showReportPage("Rows sizes are not the same", - kWarningIcon, - text); + text.append("Rows have different sizes in matrix. Check the row № ") + .append(std::to_string(badRow + 1)); + showReportPage("Rows sizes are not the same", kWarningIcon, text); } -void showDateTimeChart(const string& date_time_values, - const vector& yValues, - bool isFitPlotToWindow) { +void showDateTimeChart(const string &date_time_values, + const vector &yValues, bool isFitPlotToWindow) { string out; - vectorargs {ARGS_DATE_TIME_PAGE_SIZE, ""}; + vector args{ARGS_DATE_TIME_PAGE_SIZE, ""}; args[ARG_JS_NAME] = kPlotlyJsName; - vectorargs_block {ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; + vector args_block{ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; std::string simpleData_yValues = vectorToString(yValues); args_block[ARG_SIMPLE_DATA_X] = date_time_values; args_block[ARG_SIMPLE_DATA_Y] = simpleData_yValues; std::string data_values_block; make_string(kHtmlSimpleDataBlock, args_block, data_values_block); - args[ARG_DATE_TIME_VALUES_BLOCK] = data_values_block; args[ARG_DATE_TIME_ASPECT_RATIO_WIDTH] = "1"; args[ARG_DATE_TIME_ASPECT_RATIO_HEIGHT] = "1"; args[ARG_DATE_TIME_POINT_LINE_SWITCHER_STYLE] = kHtmlComboboxStyleBlock; args[ARG_DATE_TIME_POINT_LINE_SWITCHER_SELECT] = kHtmlComboboxSelectBlock; - args[ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO] = kHtmlComboboxUpdateFooBlock; + args[ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO] = + kHtmlComboboxUpdateFooBlock; string paramWH = "height"; string paramWHsecond; @@ -1603,17 +1602,18 @@ void showDateTimeChart(const string& date_time_values, auto unique_path = dvs::makeUniqueDavisHtmlName(); saveStringToFile(unique_path, out); openFileBySystem(unique_path); - - } -void addTraceBlockToGlobal(const vector& yValues, const string& traceName) { +void addTraceBlockToGlobal(const vector &yValues, + const string &traceName) { vector xValues(yValues.size()); - std::iota(std::begin(xValues), std::end(xValues), 0); // Fill with 0, 1, 2... + std::iota(std::begin(xValues), std::end(xValues), 0); // Fill with 0, 1, 2... addTraceBlockToGlobal(xValues, yValues, traceName); } -void addTraceBlockToGlobal(const vector& xValues, const vector& yValues, const string& traceName) { +void addTraceBlockToGlobal(const vector &xValues, + const vector &yValues, + const string &traceName) { string trace_block = dvs::kHtmlMultiChartBlock; int trace_i = 1 + dvs::allChartBlocks.size(); string str_numTrace = std::to_string(trace_i); @@ -1626,13 +1626,13 @@ void addTraceBlockToGlobal(const vector& xValues, const vector& dvs::allChartBlocks.emplace_back(filled_trace_block); } -void showCloudOfPointsChart(const vector& xValues, - const vector& yValues, - const vector& colorValues, +void showCloudOfPointsChart(const vector &xValues, + const vector &yValues, + const vector &colorValues, bool isFitPlotToWindow) { string out; string davis_dir; - vectorargs {ARGS_CLOUD_OF_POINTS_PAGE_SIZE, ""}; + vector args{ARGS_CLOUD_OF_POINTS_PAGE_SIZE, ""}; args[ARG_JS_COF_NAME] = kPlotlyJsName; args[ARG_X_CLOUD_OF_POINTS] = vectorToString(xValues); args[ARG_Y_CLOUD_OF_POINTS] = vectorToString(yValues); @@ -1651,7 +1651,8 @@ void showCloudOfPointsChart(const vector& xValues, } else { paramWHsecond = paramWH; } - args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond; + args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = + paramWHsecond; args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT] = paramWH; args[ARG_CLOUD_OF_POINTS_DAVIS_LOGO] = kHtmlDavisLogoHyperlinkBlock; make_string(kHtmlCloudOfPoints, args, out); @@ -1660,12 +1661,12 @@ void showCloudOfPointsChart(const vector& xValues, openFileBySystem(unique_file_name); } -void showCloudOfPointsChartStr(const std::string& xValues, - const vector& yValues, - const vector& colorValues, +void showCloudOfPointsChartStr(const std::string &xValues, + const vector &yValues, + const vector &colorValues, bool isFitPlotToWindow) { string out; - vectorargs {ARGS_CLOUD_OF_POINTS_PAGE_SIZE, ""}; + vector args{ARGS_CLOUD_OF_POINTS_PAGE_SIZE, ""}; args[ARG_JS_COF_NAME] = kPlotlyJsName; args[ARG_X_CLOUD_OF_POINTS] = xValues; args[ARG_Y_CLOUD_OF_POINTS] = vectorToString(yValues); @@ -1684,7 +1685,8 @@ void showCloudOfPointsChartStr(const std::string& xValues, } else { paramWHsecond = paramWH; } - args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond; + args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = + paramWHsecond; args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT] = paramWH; args[ARG_CLOUD_OF_POINTS_DAVIS_LOGO] = kHtmlDavisLogoHyperlinkBlock; make_string(kHtmlCloudOfPoints, args, out); @@ -1693,18 +1695,16 @@ void showCloudOfPointsChartStr(const std::string& xValues, openFileBySystem(unique_file_name); } -void showMultiChart(const std::string& date_time_values, - const vector>& yValues, +void showMultiChart(const std::string &date_time_values, + const vector> &yValues, bool isFitPlotToWindow) { string out; - vectorargs {ARGS_DATE_TIME_PAGE_SIZE, ""}; + vector args{ARGS_DATE_TIME_PAGE_SIZE, ""}; args[ARG_JS_NAME] = kPlotlyJsName; - - std::string all_data = ""; for (size_t i = 0; i < yValues.size(); ++i) { - vectorargs_block {ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; + vector args_block{ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; std::string simpleData_yValues = vectorToString(yValues[i]); args_block[ARG_SIMPLE_DATA_X] = date_time_values; args_block[ARG_SIMPLE_DATA_Y] = simpleData_yValues; @@ -1722,33 +1722,34 @@ void showMultiChart(const std::string& date_time_values, auto polygon_date_time = date_time_values; polygon_date_time.append(","); polygon_date_time.append(reversed_date_time_data); - auto polygon_deviation_values = doubleAndReverse(deviation_values, average_values); + auto polygon_deviation_values = + doubleAndReverse(deviation_values, average_values); - vectorargs_block {ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; + vector args_block{ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; std::string simpleData_yValues = vectorToString(deviation_values); args_block[ARG_SIMPLE_DATA_X] = polygon_date_time; args_block[ARG_SIMPLE_DATA_Y] = vectorToString(polygon_deviation_values); std::string average_error_data_values_block; - make_string(kAverageErrorDataBlock, args_block, average_error_data_values_block); + make_string(kAverageErrorDataBlock, args_block, + average_error_data_values_block); std::string average_values_str = vectorToString(average_values); - vectorargs_aver_block {ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; + vector args_aver_block{ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; args_aver_block[ARG_SIMPLE_DATA_X] = date_time_values; args_aver_block[ARG_SIMPLE_DATA_Y] = average_values_str; std::string average_data_values_block; make_string(kHtmlSimpleDataBlock, args_aver_block, average_data_values_block); - auto all_aver_block = average_error_data_values_block; all_aver_block.append(","); all_aver_block.append(average_data_values_block); - args[ARG_DATE_TIME_AVERAGE_VALUES_BLOCK] = all_aver_block; args[ARG_DATE_TIME_POINT_LINE_SWITCHER_STYLE] = kHtmlComboboxStyleBlock; args[ARG_DATE_TIME_POINT_LINE_SWITCHER_SELECT] = kHtmlComboboxSelectBlock; - args[ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO] = kHtmlComboboxUpdateFooBlock; + args[ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO] = + kHtmlComboboxUpdateFooBlock; args[ARG_DATE_TIME_VALUES_BLOCK] = all_data; args[ARG_DATE_TIME_ASPECT_RATIO_WIDTH] = "1"; args[ARG_DATE_TIME_ASPECT_RATIO_HEIGHT] = "1"; @@ -1793,10 +1794,9 @@ namespace dv { void holdOn() { dvs::isHold = true; dvs::allChartBlocks.clear(); - } -void holdOff(const Config& configuration) { +void holdOff(const Config &configuration) { dvs::isHold = false; if (dvs::allChartBlocks.empty()) { return; @@ -1814,7 +1814,8 @@ void holdOff(const Config& configuration) { allChartBlocks_str.append(dvs::allChartBlocks[i]); } std::string paramWH; - if (configuration.chart.aspectRatioWidth > configuration.chart.aspectRatioHeight) { + if (configuration.chart.aspectRatioWidth > + configuration.chart.aspectRatioHeight) { paramWH = "width"; } else { paramWH = "height"; @@ -1829,21 +1830,21 @@ void holdOff(const Config& configuration) { } else { paramWHsecond = paramWH; } - std::vector 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, - paramWHsecond, - dvs::kHtmlComboboxStyleBlock, - dvs::kHtmlComboboxSelectBlock, - dvs::kHtmlComboboxUpdateFooBlock, - dvs::kHtmlDavisLogoHyperlinkBlock - }; + std::vector 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, + paramWHsecond, + dvs::kHtmlComboboxStyleBlock, + dvs::kHtmlComboboxSelectBlock, + dvs::kHtmlComboboxUpdateFooBlock, + dvs::kHtmlDavisLogoHyperlinkBlock}; std::string multichartPage = dvs::kHtmlMultiChartModel; std::string filled_multichartPage = ""; dvs::make_string(multichartPage, args, filled_multichartPage); @@ -1859,6 +1860,4 @@ void holdOff(const Config& configuration) { } - - } // namespace dv end diff --git a/davis_one/davis.h b/davis_one/davis.h index e68e6ae..1424f8b 100644 --- a/davis_one/davis.h +++ b/davis_one/davis.h @@ -39,7 +39,8 @@ extern const char kJsUrlToDownolad[]; namespace dv { enum config_visualizationTypes { - VISUALTYPE_AUTO, //if user not forces some specific type it will be recognized by context + VISUALTYPE_AUTO, // if user not forces some specific type it will be + // recognized by context VISUALTYPE_CHART, VISUALTYPE_HEATMAP }; @@ -57,38 +58,33 @@ enum config_colorscales { COLORSCALE_PORTLAND }; - struct commonSettings { - commonSettings(): - xLabel("X"), - yLabel("Y"), - aspectRatioWidth(1), - aspectRatioHeight(1), - isFitPlotToWindow(false) {} + commonSettings() + : xLabel("X"), yLabel("Y"), aspectRatioWidth(1), aspectRatioHeight(1), + isFitPlotToWindow(false) {} virtual ~commonSettings() {} std::string title; std::string xLabel; std::string yLabel; std::string zLabel; double aspectRatioWidth; // use it for user scale if isFitPlotToWindow = false - double aspectRatioHeight;// use it for user scale if isFitPlotToWindow = false - bool isFitPlotToWindow; //true - plot fits to browser window, false - square plot + double + aspectRatioHeight; // use it for user scale if isFitPlotToWindow = false + bool isFitPlotToWindow; // true - plot fits to browser window, false - square + // plot }; struct chartSettings : public commonSettings { - //currently empty + // currently empty }; struct heatMapSettings : public commonSettings { - heatMapSettings(): - colorSc(config_colorscales::COLORSCALE_DEFAULT) {} + heatMapSettings() : colorSc(config_colorscales::COLORSCALE_DEFAULT) {} config_colorscales colorSc; }; - struct Config { - Config(): - typeVisual(VISUALTYPE_AUTO) {} + Config() : typeVisual(VISUALTYPE_AUTO) {} void reset() { chart = chartSettings(); heatmap = heatMapSettings(); @@ -100,37 +96,36 @@ struct Config { }; struct configSaveToDisk { - configSaveToDisk(): - separatorOfRows("\n"), - separatorOfCols(";"), - isTranspose(false) {} + configSaveToDisk() + : separatorOfRows("\n"), separatorOfCols(";"), isTranspose(false) {} std::string separatorOfRows; std::string separatorOfCols; - bool isTranspose; //rows-cols or cols-rows + bool isTranspose; // rows-cols or cols-rows }; - - } // namespace dv end namespace dvs { enum ARGS_INDEX { - ARG_VALUES, //%1 - ARG_COLOR_MAP, //%2 - ARG_MATRIX_TYPE,//%3 - ARG_TITLE, //%4 - ARG_TITLE_X, //%5 - ARG_TITLE_Y, //%6 - ARG_TITLE_Z, //%7 - ARG_JS_VER, //%8 + ARG_VALUES, //%1 + ARG_COLOR_MAP, //%2 + ARG_MATRIX_TYPE, //%3 + ARG_TITLE, //%4 + ARG_TITLE_X, //%5 + ARG_TITLE_Y, //%6 + ARG_TITLE_Z, //%7 + 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_FOR_AUTOSCALE, //%12 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale. - ARG_POINT_LINE_SWITCHER_STYLE, //%13 - ARG_POINT_LINE_SWITCHER_SELECT, //%14 - ARG_POINT_LINE_SWITCHER_UPDATE_FOO, //%15 - ARG_DAVIS_LOGO, //%16 + 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_FOR_AUTOSCALE, //%12 if value of it is equal to + // ARG_ASPECT_WIDTH_OR_HEIGHT it's + // mean no autoscale. + ARG_POINT_LINE_SWITCHER_STYLE, //%13 + ARG_POINT_LINE_SWITCHER_SELECT, //%14 + ARG_POINT_LINE_SWITCHER_UPDATE_FOO, //%15 + ARG_DAVIS_LOGO, //%16 // ADD NEW ENUM BEFORE THIS COMMENT ARGS_SIZE }; @@ -142,7 +137,6 @@ enum ARGS_WARNING_PAGE_INDEX { ARGS_WARNING_PAGE_SIZE }; - enum ARGS_REPORT_PAGE_INDEX { ARG_REPORT_TITLE, //%1 ARG_SVG_ICON, //%2 @@ -156,16 +150,21 @@ enum ARGS_DATE_TIME_PAGE_INDEX { ARG_DATE_TIME_VALUES_BLOCK, //%2 ARG_DATE_TIME_ASPECT_RATIO_WIDTH, //%3 ARG_DATE_TIME_ASPECT_RATIO_HEIGHT, //%4 - ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT, //%5 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not - ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%6 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale. + ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT, //%5 "width" if ARG_ASPECT_RATIO_WIDTH > + // ARG_ASPECT_RATIO_HEIGHT and "height" + // if not + ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%6 if value of it is + // equal to + // ARG_ASPECT_WIDTH_OR_HEIGHT + // it's mean no autoscale. ARG_DATE_TIME_POINT_LINE_SWITCHER_STYLE, //%7 ARG_DATE_TIME_POINT_LINE_SWITCHER_SELECT, //%8 ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO, //%9 - ARG_DATE_TIME_DAVIS_LOGO, //%10 - ARG_DATE_TIME_AVERAGE_BUTTON_STYLE,//%11 - ARG_DATE_TIME_AVERAGE_BUTTON_DIV,//%12 - ARG_DATE_TIME_AVERAGE_BUTTON_JS,//%13 - ARG_DATE_TIME_AVERAGE_VALUES_BLOCK,//%14 + ARG_DATE_TIME_DAVIS_LOGO, //%10 + ARG_DATE_TIME_AVERAGE_BUTTON_STYLE, //%11 + ARG_DATE_TIME_AVERAGE_BUTTON_DIV, //%12 + ARG_DATE_TIME_AVERAGE_BUTTON_JS, //%13 + ARG_DATE_TIME_AVERAGE_VALUES_BLOCK, //%14 // ADD NEW ENUM BEFORE THIS COMMENT ARGS_DATE_TIME_PAGE_SIZE }; @@ -176,9 +175,16 @@ enum ARGS_CLOUD_OF_POINTS_PAGE { ARG_Y_CLOUD_OF_POINTS, ARG_COLOR_CLOUD_OF_POINTS, 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. + 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. ARG_CLOUD_OF_POINTS_DAVIS_LOGO, //%9 // ADD NEW ENUM BEFORE THIS COMMENT ARGS_CLOUD_OF_POINTS_PAGE_SIZE @@ -190,7 +196,6 @@ enum ARGS_SIMPLE_DATA_BLOCK { ARGS_SIMPLE_DATA_BLOCK_SIZE }; - extern const char kHtmlModel[]; extern const char kColorMapDefaultPart[]; extern const char kColorMapSunnyPart[]; @@ -212,7 +217,6 @@ extern const char kWarningIcon[]; extern const char kHtmlDateTimeModel[]; - extern const char kHtmlMultiChartBlock[]; extern const char kHtmlMultiChartModel[]; extern const char kHtmlCloudOfPoints[]; @@ -247,45 +251,45 @@ using std::vector; string getCurrentPath(); -bool is_file_exists(const string& file_name); +bool is_file_exists(const string &file_name); -void openFileBySystem(const string& file_name); +void openFileBySystem(const string &file_name); bool isPlotlyScriptExists(); void tryToDownloadJsByCurl(); -bool saveStringToFile(const string& file_name, const string& data); +bool saveStringToFile(const string &file_name, const string &data); void mayBeCreateJsWorkingFolder(); void sleepMicroSec(unsigned long microsec); -void openPlotlyHtml(const string& file_name); +void openPlotlyHtml(const string &file_name); -bool get_data_from_file(const string& path, vector& result); +bool get_data_from_file(const string &path, vector &result); -vector split(const string& target, char c); +vector split(const string &target, char c); -bool readMatrix(vector>& outMatrix, const string& path, +bool readMatrix(vector> &outMatrix, const string &path, char dlmtr); -bool make_string(const string& src, const vector& args, string& out); +bool make_string(const string &src, const vector &args, string &out); // Now it doesn't work. -bool deleteFolder(const char* fname); +bool deleteFolder(const char *fname); -int find_separator(const std::string& src, char& separator); +int find_separator(const std::string &src, char &separator); //! remove special characters except letters, numbers and '-', '_'. Spaces -> //! '_' -string removeSpecialCharacters(const string& s); +string removeSpecialCharacters(const string &s); //! convert this cases to string "null" for Plotly string nullIfNotFinite(double val); //! convert vec to string, separated by "," -string vectorToString(const vector& vec); +string vectorToString(const vector &vec); //! only name string makeUniqueDavisHtmlName(); @@ -294,8 +298,7 @@ string makeUniqueDavisHtmlName(); string makeUniqueDavisHtmlRelativePath(); //! sometimes std::to_string reurn str with ',' as separator what is wrong -template -string toStringDotSeparator(T data) { +template string toStringDotSeparator(T data) { string str = std::to_string(data); std::replace(str.begin(), str.end(), ',', '.'); return str; @@ -303,7 +306,7 @@ string toStringDotSeparator(T data) { //! save to disk vector data template -bool saveVec(const vector& vec, const string& filename, +bool saveVec(const vector &vec, const string &filename, dv::configSaveToDisk config) { if (vec.size() == 0) { return false; @@ -322,7 +325,7 @@ bool saveVec(const vector& vec, const string& filename, //! save to disk vector> data template -bool saveVecVec(const vector>& vecVec, const string& filename, +bool saveVecVec(const vector> &vecVec, const string &filename, dv::configSaveToDisk config) { if (vecVec.size() == 0) { return false; @@ -341,7 +344,7 @@ bool saveVecVec(const vector>& vecVec, const string& filename, for (int j = 0; j < cols; ++j) { double val = vecVec.at(j).at(i); fout << val; - if (j < cols - 1) { // we dont need sep at row end + if (j < cols - 1) { // we dont need sep at row end fout << config.separatorOfCols; } } @@ -354,7 +357,7 @@ bool saveVecVec(const vector>& vecVec, const string& filename, for (size_t j = 0; j < cols; ++j) { double val = vecVec.at(i).at(j); fout << val; - if (j < cols - 1) { // we dont need sep at row end + if (j < cols - 1) { // we dont need sep at row end fout << config.separatorOfCols; } } @@ -368,16 +371,16 @@ bool saveVecVec(const vector>& vecVec, const string& filename, //! convert any container to std::vector template < typename G, - typename C, // https://devblogs.microsoft.com/oldnewthing/20190619-00/?p=102599 + typename C, // https://devblogs.microsoft.com/oldnewthing/20190619-00/?p=102599 typename T = - typename std::decay()))>::type, + typename std::decay()))>::type, typename Enable = - typename std::enable_if::value>::type > -std::vector makeVecFromContainer(const C& container) { + typename std::enable_if::value>::type> +std::vector makeVecFromContainer(const C &container) { std::vector vec; vec.reserve(static_cast( - std::distance(std::begin(container), std::end(container)))); - for (auto const& v : container) { + std::distance(std::begin(container), std::end(container)))); + for (auto const &v : container) { vec.push_back(static_cast(v)); } return vec; @@ -385,13 +388,12 @@ std::vector makeVecFromContainer(const C& container) { //! convert T** to std::vector template -inline std::vector> makeVecVecFromRowPtr(const T* const* data, - uint64_t rows, -uint64_t cols) { +inline std::vector> +makeVecVecFromRowPtr(const T *const *data, uint64_t rows, uint64_t cols) { std::vector> res; res.reserve(rows); for (uint64_t i = 0; i < rows; ++i) { - const T* rowPtr = data[i]; + const T *rowPtr = data[i]; std::vector row; row.reserve(cols); for (uint64_t j = 0; j < cols; ++j) @@ -403,13 +405,12 @@ uint64_t cols) { //! convert pseudo 2D T* to std::vector template -inline std::vector> makeVecVecFromFlat(const T* data, - uint64_t rows, -uint64_t cols) { +inline std::vector> +makeVecVecFromFlat(const T *data, uint64_t rows, uint64_t cols) { std::vector> res; res.reserve(rows); for (uint64_t i = 0; i < rows; ++i) { - const T* rowPtr = data + i * cols; + const T *rowPtr = data + i * cols; std::vector row; row.reserve(cols); for (uint64_t j = 0; j < cols; ++j) @@ -421,7 +422,7 @@ uint64_t cols) { //! convert pseudo T* to std::vector template -inline std::vector makeVecFrom1D(const T* data, uint64_t count) { +inline std::vector makeVecFrom1D(const T *data, uint64_t count) { std::vector res; res.reserve(static_cast(count)); for (uint64_t i = 0; i < count; ++i) @@ -429,23 +430,23 @@ inline std::vector makeVecFrom1D(const T* data, uint64_t count) { return res; } -bool is_string_convertable_to_digit(const string& sample); +bool is_string_convertable_to_digit(const string &sample); -void transponeMatrix(std::vector>& matrix); +void transponeMatrix(std::vector> &matrix); -vector calculateAverageVector(const vector>& vectors); +vector calculateAverageVector(const vector> &vectors); -vector calculateStandardDeviation(const vector& mean, - const vector>& data); +vector calculateStandardDeviation(const vector &mean, + const vector> &data); -vector doubleAndReverse(const vector& input, - const vector& mean); +vector doubleAndReverse(const vector &input, + const vector &mean); -std::string reverseString(const std::string& input); +std::string reverseString(const std::string &input); template -std::vector> readBinaryFile(const std::string& filePath, -size_t rowLength) { +std::vector> readBinaryFile(const std::string &filePath, + size_t rowLength) { std::ifstream file(filePath, std::ios::binary); if (!file) { throw std::runtime_error("Cannot open file"); @@ -455,7 +456,7 @@ size_t rowLength) { std::vector row(rowLength); while ( - file.read(reinterpret_cast(row.data()), rowLength * sizeof(T))) { + file.read(reinterpret_cast(row.data()), rowLength * sizeof(T))) { data.push_back(row); } @@ -474,26 +475,30 @@ size_t rowLength) { namespace dvs { +using std::istringstream; using std::string; using std::vector; -using std::istringstream; +bool createHtmlPageHeatmap(const vector> &values, string &page, + const dv::Config &configuration); -bool createHtmlPageHeatmap(const vector>& values, - string& page, - const dv::Config& configuration); +bool showHeatMapInBrowser(const vector> &values, + const string &title, const dv::Config &configuration); +bool showHeatMapInBrowser(const string &values, const string &title, + const dv::Config &configuration); -bool showHeatMapInBrowser(const vector>& values, const string& title, const dv::Config& configuration); -bool showHeatMapInBrowser(const string& values, const string& title, const dv::Config& configuration); - -bool showLineChartInBrowser(const vector& values, const string& title, const dv::Config& configuration); -bool showLineChartInBrowser(const vector& xValues, const vector& yValues, - const string& title, const dv::Config& configuration); -bool showLineChartInBrowser(const string& values, const string& title, const dv::Config& configuration); +bool showLineChartInBrowser(const vector &values, const string &title, + const dv::Config &configuration); +bool showLineChartInBrowser(const vector &xValues, + const vector &yValues, const string &title, + const dv::Config &configuration); +bool showLineChartInBrowser(const string &values, const string &title, + const dv::Config &configuration); void showWarningJsAbsentPage(); -void showReportPage(const string& page, const string& title, const string& svg, const string& description); +void showReportPage(const string &page, const string &title, const string &svg, + const string &description); void showReportFileNotFounded(); @@ -501,26 +506,27 @@ void showReportFileEmpty(); void showMatrixSizesAreNotTheSame(int badRow); -void showDateTimeChart(const string& date_time_values, - const vector& yValues, - bool isFitPlotToWindow); +void showDateTimeChart(const string &date_time_values, + const vector &yValues, bool isFitPlotToWindow); -void addTraceBlockToGlobal(const vector& yValues, const string& traceName); -void addTraceBlockToGlobal(const vector& xValues, const vector& yValues, const string& traceName); +void addTraceBlockToGlobal(const vector &yValues, + const string &traceName); +void addTraceBlockToGlobal(const vector &xValues, + const vector &yValues, + const string &traceName); -void showCloudOfPointsChart(const vector& xValues, - const vector& yValues, - const vector& colorValues, +void showCloudOfPointsChart(const vector &xValues, + const vector &yValues, + const vector &colorValues, bool isFitPlotToWindow); - -void showCloudOfPointsChartStr(const string& xValues, - const vector& yValues, - const vector& colorValues, +void showCloudOfPointsChartStr(const string &xValues, + const vector &yValues, + const vector &colorValues, bool isFitPlotToWindow); -void showMultiChart(const string& date_time_values, - const vector>& yValues, +void showMultiChart(const string &date_time_values, + const vector> &yValues, bool isFitPlotToWindow); @@ -536,95 +542,126 @@ extern vector allChartBlocks; namespace dv { - //! it shows, that we want to start accumulate chart graphs for showing //! them all at one html in one axes void holdOn(); //! finish creation of html page with multi pages -void holdOff(const Config& configuration = Config()); - - +void holdOff(const Config &configuration = Config()); } // namespace dv end namespace dv { - //! (matrix) 2-dimensional array template -bool show(T** data, uint64_t arrRows, uint64_t arrCols, - const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); +bool show(T **data, uint64_t arrRows, uint64_t arrCols, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); template -bool save(T** data, uint64_t arrRows, uint64_t arrCols, const std::string& filename, - const configSaveToDisk& configuration = configSaveToDisk()); +bool save(T **data, uint64_t arrRows, uint64_t arrCols, + const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); -//! (matrix) 1-dimensional array that simulates a 2-dimensional one (element access [i*cols+j]) +//! (matrix) 1-dimensional array that simulates a 2-dimensional one (element +//! access [i*cols+j]) template -bool show(const T* data, uint64_t arrRows, uint64_t arrCols, - const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); +bool show(const T *data, uint64_t arrRows, uint64_t arrCols, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); template -bool save(const T* data, uint64_t arrRows, uint64_t arrCols, const std::string& filename, - const configSaveToDisk& configuration = configSaveToDisk()); +bool save(const T *data, uint64_t arrRows, uint64_t arrCols, + const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); //! (chart) 1-dimensional array template -bool show(const T* data, uint64_t count, const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); +bool show(const T *data, uint64_t count, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); template -bool save(const T* data, uint64_t count, const std::string& filename, const configSaveToDisk& configuration = configSaveToDisk()); +bool save(const T *data, uint64_t count, const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); //! +(chart) 1-dimensional container -template()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool show(C const& container, const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); - -template()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool save(C const& container, const std::string& filename, const configSaveToDisk& configuration = configSaveToDisk()); +template < + typename C, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool show(C const &container, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); +template < + typename C, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool save(C const &container, const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); //! +(chart) Two 1-dimensional container for X-Y plot -template()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool show(C const& containerX, C const& containerY, const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); - -template()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool save(C const& containerX, C const& containerY, const std::string& filename, const configSaveToDisk& configuration = configSaveToDisk()); +template < + typename C, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool show(C const &containerX, C const &containerY, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); +template < + typename C, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool save(C const &containerX, C const &containerY, const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); //! (chart / matrix) 2-dimensional container -template()))>::type, - typename T = typename std::decay()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool show(C const& container_of_containers, const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); - -template()))>::type, - typename T = typename std::decay()))>::type, - typename Enable = typename std::enable_if::value>::type> -bool save(C const& container_of_containers, const std::string& filename, const configSaveToDisk& configuration = configSaveToDisk()); +template < + typename C, + typename E = + typename std::decay()))>::type, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool show(C const &container_of_containers, + const std::string &htmlPageName = dvs::makeUniqueDavisHtmlName(), + const Config &configuration = Config()); +template < + typename C, + typename E = + typename std::decay()))>::type, + typename T = + typename std::decay()))>::type, + typename Enable = + typename std::enable_if::value>::type> +bool save(C const &container_of_containers, const std::string &filename, + const configSaveToDisk &configuration = configSaveToDisk()); // *********************************** // template functions implementations: // *********************************** template -bool show(T** data, uint64_t arrRows, uint64_t arrCols, const std::string& htmlPageName, const Config& configuration) { +bool show(T **data, uint64_t arrRows, uint64_t arrCols, + const std::string &htmlPageName, const Config &configuration) { if (data == nullptr || arrRows == 0 || arrCols == 0) return false; std::vector> vecVecDbl = - dvs::makeVecVecFromRowPtr(data, arrRows, arrCols); + dvs::makeVecVecFromRowPtr(data, arrRows, arrCols); bool res = false; if (configuration.typeVisual == VISUALTYPE_AUTO || @@ -635,20 +672,23 @@ bool show(T** data, uint64_t arrRows, uint64_t arrCols, const std::string& htmlP } template -bool save(T** data, uint64_t arrRows, uint64_t arrCols, const std::string& filename, const configSaveToDisk& configuration) { +bool save(T **data, uint64_t arrRows, uint64_t arrCols, + const std::string &filename, const configSaveToDisk &configuration) { if (data == nullptr || arrRows == 0 || arrCols == 0) return false; std::vector> vecVec = - dvs::makeVecVecFromRowPtr(data, arrRows, arrCols); + dvs::makeVecVecFromRowPtr(data, arrRows, arrCols); bool res = dvs::saveVecVec(vecVec, filename, configuration); return res; } template -bool show(const T* data, uint64_t arrRows, uint64_t arrCols, const std::string& htmlPageName, const Config& configuration) { +bool show(const T *data, uint64_t arrRows, uint64_t arrCols, + const std::string &htmlPageName, const Config &configuration) { if (data == nullptr || arrRows == 0 || arrCols == 0) return false; - std::vector> vecVecDbl = dvs::makeVecVecFromFlat(data, arrRows, arrCols); + std::vector> vecVecDbl = + dvs::makeVecVecFromFlat(data, arrRows, arrCols); bool res = false; if (configuration.typeVisual == VISUALTYPE_AUTO || configuration.typeVisual == VISUALTYPE_HEATMAP) { @@ -658,17 +698,19 @@ bool show(const T* data, uint64_t arrRows, uint64_t arrCols, const std::string& } template -bool save(const T* data, uint64_t arrRows, uint64_t arrCols, const std::string& filename, - const configSaveToDisk& configuration) { +bool save(const T *data, uint64_t arrRows, uint64_t arrCols, + const std::string &filename, const configSaveToDisk &configuration) { if (data == nullptr || arrRows == 0 || arrCols == 0) return false; - std::vector> vecVec = dvs::makeVecVecFromFlat(data, arrRows, arrCols); + std::vector> vecVec = + dvs::makeVecVecFromFlat(data, arrRows, arrCols); bool res = dvs::saveVecVec(vecVec, filename, configuration); return res; } template -bool show(const T* data, uint64_t count, const std::string& htmlPageName, const Config& configuration) { +bool show(const T *data, uint64_t count, const std::string &htmlPageName, + const Config &configuration) { if (data == nullptr || count == 0) return false; std::vector dblRow = dvs::makeVecFrom1D(data, count); @@ -686,7 +728,8 @@ bool show(const T* data, uint64_t count, const std::string& htmlPageName, const } template -bool save(const T* data, uint64_t count, const std::string& filename, const configSaveToDisk& configuration) { +bool save(const T *data, uint64_t count, const std::string &filename, + const configSaveToDisk &configuration) { if (data == nullptr || count == 0) return false; std::vector row = dvs::makeVecFrom1D(data, count); @@ -694,8 +737,9 @@ bool save(const T* data, uint64_t count, const std::string& filename, const conf return res; } -template -bool show(C const& container, const std::string& htmlPageName, const Config& configuration) { +template +bool show(C const &container, const std::string &htmlPageName, + const Config &configuration) { std::vector dblRow = dvs::makeVecFromContainer(container); bool res = false; if (configuration.typeVisual == VISUALTYPE_AUTO || @@ -710,15 +754,17 @@ bool show(C const& container, const std::string& htmlPageName, const Config& con return res; } -template -bool save(C const& container, const std::string& filename, const configSaveToDisk& configuration) { +template +bool save(C const &container, const std::string &filename, + const configSaveToDisk &configuration) { std::vector row = dvs::makeVecFromContainer(container); bool res = dvs::saveVec(row, filename, configuration); return res; } -template -bool show(C const& containerX, C const& containerY, const std::string& htmlPageName, const Config& configuration) { +template +bool show(C const &containerX, C const &containerY, + const std::string &htmlPageName, const Config &configuration) { if (containerX.size() != containerY.size()) { return false; } @@ -727,7 +773,8 @@ bool show(C const& containerX, C const& containerY, const std::string& htmlPageN bool res = false; if (!dvs::isHold) { - res = dvs::showLineChartInBrowser(dblRowX, dblRowY, htmlPageName, configuration); + res = dvs::showLineChartInBrowser(dblRowX, dblRowY, htmlPageName, + configuration); } else { dvs::addTraceBlockToGlobal(dblRowX, dblRowY, htmlPageName); res = true; @@ -735,8 +782,9 @@ bool show(C const& containerX, C const& containerY, const std::string& htmlPageN return res; } -template -bool save(C const& containerX, C const& containerY, const std::string& filename, const configSaveToDisk& configuration) { +template +bool save(C const &containerX, C const &containerY, const std::string &filename, + const configSaveToDisk &configuration) { if (containerX.size() != containerY.size()) { return false; } @@ -751,11 +799,12 @@ bool save(C const& containerX, C const& containerY, const std::string& filename return res; } -template -bool show(C const& container_of_containers, const std::string& htmlPageName, const Config& configuration) { +template +bool show(C const &container_of_containers, const std::string &htmlPageName, + const Config &configuration) { std::vector> vecVecDbl; vecVecDbl.reserve(container_of_containers.size()); - for (const auto& row : container_of_containers) { + for (const auto &row : container_of_containers) { std::vector dblRow = dvs::makeVecFromContainer(row); vecVecDbl.emplace_back(dblRow); } @@ -765,9 +814,12 @@ bool show(C const& container_of_containers, const std::string& htmlPageName, con if (!vecVecDbl.empty()) { size2 = vecVecDbl[0].size(); } - if ((configuration.typeVisual == VISUALTYPE_AUTO || //case when we want to plot graph with X and Y vectors + if ((configuration.typeVisual == + VISUALTYPE_AUTO || // case when we want to plot graph with X and Y + // vectors configuration.typeVisual == VISUALTYPE_CHART) && - (size1 == 2 || size2 == 2)) { // it can be or 2-columns-data or 2-rows-data + (size1 == 2 || + size2 == 2)) { // it can be or 2-columns-data or 2-rows-data std::vector xVals; std::vector yVals; if (size1 == 2) { @@ -781,7 +833,8 @@ bool show(C const& container_of_containers, const std::string& htmlPageName, con } } if (!dvs::isHold) { - res = dvs::showLineChartInBrowser(xVals, yVals, htmlPageName, configuration); + res = dvs::showLineChartInBrowser(xVals, yVals, htmlPageName, + configuration); } else { dvs::addTraceBlockToGlobal(xVals, yVals, htmlPageName); res = true; @@ -793,11 +846,12 @@ bool show(C const& container_of_containers, const std::string& htmlPageName, con return res; } -template -bool save(C const& container_of_containers, const std::string& filename, const configSaveToDisk& configuration) { +template +bool save(C const &container_of_containers, const std::string &filename, + const configSaveToDisk &configuration) { std::vector> vecVec; vecVec.reserve(container_of_containers.size()); - for (const auto& row : container_of_containers) { + for (const auto &row : container_of_containers) { std::vector rowTemp = dvs::makeVecFromContainer(row); vecVec.emplace_back(rowTemp); } diff --git a/format_all.bat b/format_all.bat new file mode 100644 index 0000000..b740c98 --- /dev/null +++ b/format_all.bat @@ -0,0 +1,19 @@ +@echo off +REM === Настройки === +REM Относительный путь к clang-format.exe +set CLANG_FORMAT=%~dp0code_style\cpp\clang-format.exe + +REM Корневая папка проекта (текущая) +set PROJECT_DIR=%cd% + +echo start to format all *.cpp and *.h files in %PROJECT_DIR% ... + +REM Рекурсивный обход всех файлов +for /R "%PROJECT_DIR%" %%f in (*.cpp *.h) do ( + echo format: %%f + "%CLANG_FORMAT%" -i "%%f" +) + +echo all code base formatting process is finished +ping localhost -n 3 >nul + diff --git a/gui/about_window.cpp b/gui/about_window.cpp index 601be4d..aabd435 100644 --- a/gui/about_window.cpp +++ b/gui/about_window.cpp @@ -1,29 +1,27 @@ #include "about_window.h" -#include "ui_about_window.h" -#include "QPushButton" #include "QHBoxLayout" #include "QMouseEvent" +#include "QPushButton" +#include "ui_about_window.h" +#include "version.h" +#include #include #include -#include -#include #include -#include "version.h" - - +#include -About_window::About_window(QWidget* parent) : - QMainWindow(parent), - ui(new Ui::about_window) { +About_window::About_window(QWidget *parent) + : QMainWindow(parent), ui(new Ui::about_window) { ui->setupUi(this); ui->label_version->setText("Version " + QString(FILE_VERSION_STR) + " (x64)"); isMusicPlaying = false; clicks = 1; - this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | + Qt::WindowStaysOnTopHint); ui->label_nearLogo->setOpenExternalLinks(true); ui->label_wiki->setOpenExternalLinks(true); connect(ui->pushButton_copyMail, &QPushButton::pressed, [&]() { - QLabel* label = new QLabel(this); + QLabel *label = new QLabel(this); label->setText("e-mail copied"); QFont font; font.setPointSize(12); @@ -43,44 +41,42 @@ About_window::~About_window() { emit about_window_closed(); } -void About_window::on_pushButton_close_clicked() { - close(); -} +void About_window::on_pushButton_close_clicked() { close(); } -void About_window::mousePressEvent(QMouseEvent* event) { +void About_window::mousePressEvent(QMouseEvent *event) { m_point = event->pos(); } -void About_window::mouseMoveEvent(QMouseEvent* event) { +void About_window::mouseMoveEvent(QMouseEvent *event) { move(event->globalPos() - m_point); - } -bool About_window::eventFilter(QObject* o, QEvent* e) { - if (o == ui->label_DevtoolsDavis && e->type() == QMouseEvent::MouseButtonRelease && !isMusicPlaying) { +bool About_window::eventFilter(QObject *o, QEvent *e) { + if (o == ui->label_DevtoolsDavis && + e->type() == QMouseEvent::MouseButtonRelease && !isMusicPlaying) { qint64 delta_ms = 250; - qint64 elapsed = someTimer.restart(); //someTimer is QElapsedTimer member + qint64 elapsed = someTimer.restart(); // someTimer is QElapsedTimer member if (elapsed < delta_ms) ++clicks; else clicks = 1; qDebug() << clicks; if (4 == clicks) { - QMediaPlayer* player = new QMediaPlayer(this); + QMediaPlayer *player = new QMediaPlayer(this); player->setMedia(QUrl("qrc:/res/davis.mp3")); player->play(); isMusicPlaying = true; - QObject::connect(player, &QMediaPlayer::stateChanged, [ = ](QMediaPlayer::State state) { - if (state == QMediaPlayer::State::StoppedState) - isMusicPlaying = false; - }); + QObject::connect(player, &QMediaPlayer::stateChanged, + [=](QMediaPlayer::State state) { + if (state == QMediaPlayer::State::StoppedState) + isMusicPlaying = false; + }); } } return QObject::eventFilter(o, e); } void About_window::on_pushButton_copyMail_clicked() { - QClipboard* clipboard = QGuiApplication::clipboard(); + QClipboard *clipboard = QGuiApplication::clipboard(); clipboard->setText("devtools.public@gmail.com"); } - diff --git a/gui/about_window.h b/gui/about_window.h index b95761d..31f2aa3 100644 --- a/gui/about_window.h +++ b/gui/about_window.h @@ -1,8 +1,8 @@ #ifndef ABOUT_WINDOW_H #define ABOUT_WINDOW_H -#include #include +#include namespace Ui { class about_window; @@ -11,25 +11,25 @@ class about_window; class About_window : public QMainWindow { Q_OBJECT - signals: +signals: void about_window_closed(); - public: - explicit About_window(QWidget* parent = nullptr); +public: + explicit About_window(QWidget *parent = nullptr); ~About_window(); - protected: - void mousePressEvent(QMouseEvent* event) override; - void mouseMoveEvent(QMouseEvent* event) override; - bool eventFilter(QObject* o, QEvent* e) override; +protected: + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + bool eventFilter(QObject *o, QEvent *e) override; - private slots: +private slots: void on_pushButton_close_clicked(); void on_pushButton_copyMail_clicked(); - private: - Ui::about_window* ui; +private: + Ui::about_window *ui; QPoint m_point; bool isMusicPlaying; uint clicks; diff --git a/gui/animated_button.cpp b/gui/animated_button.cpp index 101b77c..11e8e8c 100644 --- a/gui/animated_button.cpp +++ b/gui/animated_button.cpp @@ -1,30 +1,32 @@ #include "animated_button.h" -#include #include #include +#include -QString buttonStyle( - "QPushButton {" - " background-color: %1;" - " border: none;" - " color:white;" // text color - " text-align: center;" - " font-size: 13px;" - " border-radius: 14px;" - "}" -); - +QString buttonStyle("QPushButton {" + " background-color: %1;" + " border: none;" + " color:white;" // text color + " text-align: center;" + " font-size: 13px;" + " border-radius: 14px;" + "}"); -AnimatedButton::AnimatedButton(const QString& text, QColor startColor, QColor endColor, QWidget* parent) : QPushButton(text, parent) { +AnimatedButton::AnimatedButton(const QString &text, QColor startColor, + QColor endColor, QWidget *parent) + : QPushButton(text, parent) { setStyleSheet(buttonStyle.arg(startColor.name())); m_startColor = startColor; m_endColor = endColor; - connect(this, &QPushButton::pressed, this, &AnimatedButton::animateButtonPress); - connect(this, &QPushButton::released, this, &AnimatedButton::animateButtonRelease); + connect(this, &QPushButton::pressed, this, + &AnimatedButton::animateButtonPress); + connect(this, &QPushButton::released, this, + &AnimatedButton::animateButtonRelease); } -void AnimatedButton::enterEvent(QEvent* event) { - QPropertyAnimation* animation = new QPropertyAnimation(this, "backgroundColor"); +void AnimatedButton::enterEvent(QEvent *event) { + QPropertyAnimation *animation = + new QPropertyAnimation(this, "backgroundColor"); animation->setDuration(250); animation->setStartValue(m_startColor); animation->setEndValue(m_endColor); @@ -33,8 +35,9 @@ void AnimatedButton::enterEvent(QEvent* event) { QPushButton::enterEvent(event); } -void AnimatedButton::leaveEvent(QEvent* event) { - QPropertyAnimation* animation = new QPropertyAnimation(this, "backgroundColor"); +void AnimatedButton::leaveEvent(QEvent *event) { + QPropertyAnimation *animation = + new QPropertyAnimation(this, "backgroundColor"); animation->setDuration(250); animation->setStartValue(m_endColor); animation->setEndValue(m_startColor); @@ -44,28 +47,27 @@ void AnimatedButton::leaveEvent(QEvent* event) { void AnimatedButton::animateButtonPress() { - m_originalGeometry = geometry(); - QPropertyAnimation* animation = new QPropertyAnimation(this, "geometry"); + m_originalGeometry = geometry(); + QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry"); animation->setDuration(100); animation->setStartValue(geometry()); - animation->setEndValue(QRect(m_originalGeometry.x(), m_originalGeometry.y() + 5, - m_originalGeometry.width(), m_originalGeometry.height())); + animation->setEndValue( + QRect(m_originalGeometry.x(), m_originalGeometry.y() + 5, + m_originalGeometry.width(), m_originalGeometry.height())); animation->start(QAbstractAnimation::DeleteWhenStopped); } void AnimatedButton::animateButtonRelease() { - QPropertyAnimation* animation = new QPropertyAnimation(this, "geometry"); + QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry"); animation->setDuration(100); animation->setStartValue(geometry()); animation->setEndValue(m_originalGeometry); animation->start(QAbstractAnimation::DeleteWhenStopped); } -QColor AnimatedButton::backgroundColor() const { - return m_backgroundColor; -} +QColor AnimatedButton::backgroundColor() const { return m_backgroundColor; } -void AnimatedButton::setBackgroundColor(const QColor& color) { +void AnimatedButton::setBackgroundColor(const QColor &color) { m_backgroundColor = color; setStyleSheet(buttonStyle.arg(color.name())); } diff --git a/gui/animated_button.h b/gui/animated_button.h index 12dc296..12ec688 100644 --- a/gui/animated_button.h +++ b/gui/animated_button.h @@ -1,40 +1,39 @@ #ifndef ANIMATED_BUTTON_H #define ANIMATED_BUTTON_H #include -#include -#include -#include #include +#include +#include +#include class AnimatedButton : public QPushButton { Q_OBJECT - Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) + Q_PROPERTY( + QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) - public: - AnimatedButton(const QString& text, QColor startColor, QColor endColor, QWidget* parent = nullptr); +public: + AnimatedButton(const QString &text, QColor startColor, QColor endColor, + QWidget *parent = nullptr); QColor backgroundColor() const; - void setBackgroundColor(const QColor& color); + void setBackgroundColor(const QColor &color); - protected: - void enterEvent(QEvent* event) override; +protected: + void enterEvent(QEvent *event) override; - void leaveEvent(QEvent* event) override; + void leaveEvent(QEvent *event) override; - private slots: +private slots: void animateButtonPress(); void animateButtonRelease(); - private: +private: QColor m_startColor; QColor m_endColor; QColor m_backgroundColor; QRect m_originalGeometry; }; - - - #endif // ANIMATED_BUTTON_H diff --git a/gui/cool_progressbar.cpp b/gui/cool_progressbar.cpp index 48cecc7..04b3629 100644 --- a/gui/cool_progressbar.cpp +++ b/gui/cool_progressbar.cpp @@ -3,31 +3,24 @@ #include #include - -coolProgressBar::coolProgressBar(const QColor& backgroundColor, - const QColor& animatedColor, - int animationTimeMs, - QWidget* parent) { +coolProgressBar::coolProgressBar(const QColor &backgroundColor, + const QColor &animatedColor, + int animationTimeMs, QWidget *parent) { setVisible(false); m_backgroundColor = backgroundColor; m_animatedColor = animatedColor; m_animationTimeMs = animationTimeMs; - QString styleBack( - " background-color: %1;" - " border-radius: 1px;" - " border: none;" - ); + QString styleBack(" background-color: %1;" + " border-radius: 1px;" + " border: none;"); setStyleSheet(styleBack.arg(m_backgroundColor.name())); - - QWidget* movingSquare = new QWidget(this); + QWidget *movingSquare = new QWidget(this); m_movingSquare = movingSquare; - QString styleMoving( - " background-color: %1;" - " border-radius: 1px;" - " border: none;" - ); + QString styleMoving(" background-color: %1;" + " border-radius: 1px;" + " border: none;"); m_movingSquare->setStyleSheet(styleMoving.arg(m_animatedColor.name())); m_animation = new QPropertyAnimation(m_movingSquare, "geometry"); @@ -37,11 +30,9 @@ coolProgressBar::coolProgressBar(const QColor& backgroundColor, void coolProgressBar::startAnimation() { m_animation->setStartValue(QRect(-m_movingSquare->width(), - m_movingSquare->y(), - m_movingSquare->width(), + m_movingSquare->y(), m_movingSquare->width(), m_movingSquare->height())); - m_animation->setEndValue(QRect(width(), - m_movingSquare->y(), + m_animation->setEndValue(QRect(width(), m_movingSquare->y(), m_movingSquare->width(), m_movingSquare->height())); m_animation->setEasingCurve(QEasingCurve::InOutCubic); @@ -54,16 +45,15 @@ void coolProgressBar::stopAnimation() { setVisible(false); } -void coolProgressBar::paintEvent(QPaintEvent* event) { +void coolProgressBar::paintEvent(QPaintEvent *event) { QStyleOption opt; opt.init(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } -void coolProgressBar::showEvent(QShowEvent* event) { +void coolProgressBar::showEvent(QShowEvent *event) { qDebug() << width(); m_movingSquare->setGeometry(0, 0, width() / 2, height()); qDebug() << "blue - " << m_movingSquare->geometry(); } - diff --git a/gui/cool_progressbar.h b/gui/cool_progressbar.h index 88bf4bf..6925175 100644 --- a/gui/cool_progressbar.h +++ b/gui/cool_progressbar.h @@ -2,28 +2,29 @@ #define COOLPROGRESSBAR_H #include -#include #include +#include class coolProgressBar : public QWidget { Q_OBJECT - public: - explicit coolProgressBar(const QColor& backgroundColor, - const QColor& animatedColor, - int animationTimeMs, - QWidget* parent = nullptr); - public slots: +public: + explicit coolProgressBar(const QColor &backgroundColor, + const QColor &animatedColor, int animationTimeMs, + QWidget *parent = nullptr); +public slots: void startAnimation(); void stopAnimation(); - protected: - void paintEvent(QPaintEvent* event) override; - void showEvent(QShowEvent* event) override; - private: + +protected: + void paintEvent(QPaintEvent *event) override; + void showEvent(QShowEvent *event) override; + +private: QColor m_backgroundColor; QColor m_animatedColor; int m_animationTimeMs; - QWidget* m_movingSquare; - QPropertyAnimation* m_animation; + QWidget *m_movingSquare; + QPropertyAnimation *m_animation; }; #endif // COOLPROGRESSBAR_H diff --git a/gui/json_utils.cpp b/gui/json_utils.cpp index a79c3ee..1282326 100644 --- a/gui/json_utils.cpp +++ b/gui/json_utils.cpp @@ -1,19 +1,17 @@ #include "json_utils.h" -#include +#include +#include +#include +#include #include #include +#include #include -#include -#include -#include -#include - namespace jsn { -bool getJsonObjectFromFile(const QString& path, - QJsonObject& object) { +bool getJsonObjectFromFile(const QString &path, QJsonObject &object) { QFile file(path); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "File can't be opened!" << path; @@ -31,8 +29,7 @@ bool getJsonObjectFromFile(const QString& path, return true; } -bool getJsonArrayFromFile(const QString& path, - QJsonArray& object) { +bool getJsonArrayFromFile(const QString &path, QJsonArray &object) { QFile file(path); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "File can't be opened!" << path; @@ -49,8 +46,7 @@ bool getJsonArrayFromFile(const QString& path, return true; } -bool saveJsonObjectToFile(const QString& path, - const QJsonObject& json_object, +bool saveJsonObjectToFile(const QString &path, const QJsonObject &json_object, QJsonDocument::JsonFormat format) { QFile file(path); if (!file.open(QIODevice::WriteOnly)) @@ -64,8 +60,7 @@ bool saveJsonObjectToFile(const QString& path, return true; } -bool saveJsonArrayToFile(const QString& path, - const QJsonArray& json_object, +bool saveJsonArrayToFile(const QString &path, const QJsonArray &json_object, QJsonDocument::JsonFormat format) { QFile file(path); if (!file.open(QIODevice::WriteOnly)) @@ -79,9 +74,10 @@ bool saveJsonArrayToFile(const QString& path, return true; } -QPair isJsonObjectContainsUserKeys(const QJsonObject& user_json_from_file, - const QJsonArray& service_keys, - const QJsonObject& user_stamp_keys) { +QPair +isJsonObjectContainsUserKeys(const QJsonObject &user_json_from_file, + const QJsonArray &service_keys, + const QJsonObject &user_stamp_keys) { if (user_json_from_file.isEmpty()) return {false, QJsonObject()}; @@ -100,7 +96,8 @@ QPair isJsonObjectContainsUserKeys(const QJsonObject& user_js // Check that we have keys for user json for (int i = 0; i < service_keys.size(); ++i) { - auto jarr_custom_keys = user_stamp_keys[service_keys[i].toString()].toArray(); + auto jarr_custom_keys = + user_stamp_keys[service_keys[i].toString()].toArray(); for (int j = 0; j < jarr_custom_keys.size(); ++j) { auto custom_key = jarr_custom_keys[j].toString(); if (user_json_from_file.contains(custom_key)) { @@ -118,9 +115,9 @@ QPair isJsonObjectContainsUserKeys(const QJsonObject& user_js return {true, result_object_with_data}; } -QVector getVectorDoubleFromJsonArray(const QJsonArray& json_array) { +QVector getVectorDoubleFromJsonArray(const QJsonArray &json_array) { QVector vector; - for (const QJsonValue& value : json_array) { + for (const QJsonValue &value : json_array) { if (value.isDouble()) { vector.append(value.toDouble()); } @@ -128,15 +125,16 @@ QVector getVectorDoubleFromJsonArray(const QJsonArray& json_array) { return vector; } -std::vector > getMatrixFromJsonArray(const QJsonArray& json_array) { +std::vector> +getMatrixFromJsonArray(const QJsonArray &json_array) { std::vector> matrix; - for (const QJsonValue& rowValue : json_array) { + for (const QJsonValue &rowValue : json_array) { if (rowValue.isArray()) { QJsonArray rowArray = rowValue.toArray(); std::vector row; - for (const QJsonValue& value : qAsConst(rowArray)) { + for (const QJsonValue &value : qAsConst(rowArray)) { if (value.isDouble()) { row.emplace_back(value.toDouble()); } @@ -149,9 +147,7 @@ std::vector > getMatrixFromJsonArray(const QJsonArray& json_ return matrix; } - -bool getJsonValueFromFile(const QString& path, - QJsonValue& jsonValue) { +bool getJsonValueFromFile(const QString &path, QJsonValue &jsonValue) { QFile file(path); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "File can't be opened!" << path; @@ -175,10 +171,9 @@ bool getJsonValueFromFile(const QString& path, return true; } -QJsonValue getValueByPath(const QJsonValue& obj, - const QStringList& path) { +QJsonValue getValueByPath(const QJsonValue &obj, const QStringList &path) { QJsonValue value = obj; - for (const QString& key : path) { + for (const QString &key : path) { if (value.isObject()) { value = value.toObject().value(key); } else if (value.isArray()) { @@ -196,7 +191,7 @@ QJsonValue getValueByPath(const QJsonValue& obj, return value; } -QVector getStringListFromJsonArray(const QJsonArray& array) { +QVector getStringListFromJsonArray(const QJsonArray &array) { QVector pathes; for (int i = 0; i < array.size(); ++i) { if (array[i].isArray() == false) @@ -210,24 +205,22 @@ QVector getStringListFromJsonArray(const QJsonArray& array) { return pathes; } -void extractAllObjects(const QJsonValue& value, - QJsonArray& result) { +void extractAllObjects(const QJsonValue &value, QJsonArray &result) { if (value.isObject()) { QJsonObject obj = value.toObject(); result.append(obj); - for (const QString& key : obj.keys()) { + for (const QString &key : obj.keys()) { extractAllObjects(obj[key], result); } } else if (value.isArray()) { QJsonArray array = value.toArray(); - for (const QJsonValue& item : array) { + for (const QJsonValue &item : array) { extractAllObjects(item, result); } } } -bool isObjectMatrixToMatrixType(const QStringList& keys, - QJsonObject& object) { +bool isObjectMatrixToMatrixType(const QStringList &keys, QJsonObject &object) { QStringList object_keys = object.keys(); qDebug() << "Проверочные Ключи: " << keys; qDebug() << "Ключи объекта" << object_keys; @@ -239,6 +232,4 @@ bool isObjectMatrixToMatrixType(const QStringList& keys, return true; } - - -} // end jsn namespace +} // namespace jsn diff --git a/gui/json_utils.h b/gui/json_utils.h index b668c0b..4fd8b2f 100644 --- a/gui/json_utils.h +++ b/gui/json_utils.h @@ -1,57 +1,46 @@ #ifndef JSON_UTILS_H #define JSON_UTILS_H -#include "QVector" #include "QJsonDocument" +#include "QVector" class QString; class QJsonArray; class QJsonObject; - namespace jsn { +bool getJsonObjectFromFile(const QString &path, QJsonObject &object); -bool getJsonObjectFromFile(const QString& path, - QJsonObject& object); - -bool getJsonArrayFromFile(const QString& path, - QJsonArray& object); - - -bool getJsonValueFromFile(const QString& path, - QJsonValue& jsonValue); - - -bool saveJsonObjectToFile(const QString& path, - const QJsonObject& json_object, - QJsonDocument::JsonFormat format = QJsonDocument::Indented); - -bool saveJsonArrayToFile(const QString& path, - const QJsonArray& json_object, - QJsonDocument::JsonFormat format = QJsonDocument::Indented); - -QPair isJsonObjectContainsUserKeys(const QJsonObject& path, - const QJsonArray& service_keys, - const QJsonObject& user_stamp_keys - ); +bool getJsonArrayFromFile(const QString &path, QJsonArray &object); -QVector getVectorDoubleFromJsonArray(const QJsonArray& json_array); +bool getJsonValueFromFile(const QString &path, QJsonValue &jsonValue); -std::vector > getMatrixFromJsonArray(const QJsonArray& json_array); +bool saveJsonObjectToFile( + const QString &path, const QJsonObject &json_object, + QJsonDocument::JsonFormat format = QJsonDocument::Indented); +bool saveJsonArrayToFile( + const QString &path, const QJsonArray &json_object, + QJsonDocument::JsonFormat format = QJsonDocument::Indented); -QJsonValue getValueByPath(const QJsonValue& obj, - const QStringList& path); +QPair +isJsonObjectContainsUserKeys(const QJsonObject &path, + const QJsonArray &service_keys, + const QJsonObject &user_stamp_keys); +QVector getVectorDoubleFromJsonArray(const QJsonArray &json_array); -QVector getStringListFromJsonArray(const QJsonArray& array); +std::vector> +getMatrixFromJsonArray(const QJsonArray &json_array); +QJsonValue getValueByPath(const QJsonValue &obj, const QStringList &path); -void extractAllObjects(const QJsonValue& value, QJsonArray& result); +QVector getStringListFromJsonArray(const QJsonArray &array); -bool isObjectMatrixToMatrixType(const QStringList& keys, QJsonObject& object); +void extractAllObjects(const QJsonValue &value, QJsonArray &result); +bool isObjectMatrixToMatrixType(const QStringList &keys, QJsonObject &object); } // end namespace jsn diff --git a/gui/main.cpp b/gui/main.cpp index f6401b3..d8dea16 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -1,45 +1,50 @@ -#include "davis_gui.h" #include "../common_utils/common_constants.h" #include "../common_utils/common_utils.h" -#include "QFile" #include "QDebug" -#include "QUrl" +#include "QFile" #include "QStyleFactory" +#include "QUrl" +#include "davis_gui.h" #include - void applyDark() { qApp->setStyle(QStyleFactory::create("Fusion")); QPalette darkPalette; QColor gray = QColor(230, 230, 230); darkPalette.setColor(QPalette::Window, QColor(53, 53, 53)); darkPalette.setColor(QPalette::WindowText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(127, 127, 127)); + darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, + QColor(127, 127, 127)); darkPalette.setColor(QPalette::Base, QColor(42, 42, 42)); darkPalette.setColor(QPalette::AlternateBase, QColor(66, 66, 66)); darkPalette.setColor(QPalette::ToolTipBase, gray); darkPalette.setColor(QPalette::ToolTipText, gray); darkPalette.setColor(QPalette::Text, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127)); + darkPalette.setColor(QPalette::Disabled, QPalette::Text, + QColor(127, 127, 127)); darkPalette.setColor(QPalette::Dark, QColor(35, 35, 35)); darkPalette.setColor(QPalette::Shadow, QColor(20, 20, 20)); darkPalette.setColor(QPalette::Button, QColor(53, 53, 53)); darkPalette.setColor(QPalette::ButtonText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127)); + darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, + QColor(127, 127, 127)); darkPalette.setColor(QPalette::BrightText, Qt::red); darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); - darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80)); + darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, + QColor(80, 80, 80)); darkPalette.setColor(QPalette::HighlightedText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(127, 127, 127)); + darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, + QColor(127, 127, 127)); qApp->setPalette(darkPalette); }; -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { dvs::mayBeCreateJsWorkingFolder(); if (dvs::isPlotlyScriptExists() == false) { qDebug() << "try to copy file....."; - QFile::copy(":/plotly_maker/" + QString(dvs::kPlotlyJsName), dvs::kPlotlyJsWorkPath); + QFile::copy(":/plotly_maker/" + QString(dvs::kPlotlyJsName), + dvs::kPlotlyJsWorkPath); } else { qDebug() << "js exists..."; } diff --git a/gui/qrc_files_restorer.cpp b/gui/qrc_files_restorer.cpp index 0b2b593..668f271 100644 --- a/gui/qrc_files_restorer.cpp +++ b/gui/qrc_files_restorer.cpp @@ -1,14 +1,14 @@ #include "qrc_files_restorer.h" -#include #include +#include #include -QrcFilesRestorer::QrcFilesRestorer(const QString& path2Qrc) { +QrcFilesRestorer::QrcFilesRestorer(const QString &path2Qrc) { QDir dir(path2Qrc); QStringList files = dir.entryList(); } -void QrcFilesRestorer::restoreFilesFromQrc(const QString& path2Qrc) { +void QrcFilesRestorer::restoreFilesFromQrc(const QString &path2Qrc) { QDir dir(path2Qrc); QStringList files = dir.entryList(); for (int i = 0; i < files.count(); ++i) { @@ -20,5 +20,3 @@ void QrcFilesRestorer::restoreFilesFromQrc(const QString& path2Qrc) { } } } - - diff --git a/gui/qrc_files_restorer.h b/gui/qrc_files_restorer.h index 46262c8..6544c5f 100644 --- a/gui/qrc_files_restorer.h +++ b/gui/qrc_files_restorer.h @@ -1,17 +1,15 @@ #ifndef QRC_FILES_RESTORER_H #define QRC_FILES_RESTORER_H - class QString; //! //! \brief Копирование файлов из исполняемого файла на диск //! class QrcFilesRestorer { - public: - QrcFilesRestorer(const QString& path2Qrc); - static void restoreFilesFromQrc(const QString& path2Qrc); - +public: + QrcFilesRestorer(const QString &path2Qrc); + static void restoreFilesFromQrc(const QString &path2Qrc); }; #endif // QRC_FILES_RESTORER_H diff --git a/main.cpp b/main.cpp index 7a663de..b553a04 100644 --- a/main.cpp +++ b/main.cpp @@ -1,25 +1,23 @@ -#include -#include -#include -#include #include "ResourceManager/ResourceHandle.h" -#include #include "array_core/array_core.h" #include "common_utils/common_constants.h" #include "common_utils/common_utils.h" +#include +#include +#include +#include +#include using std::vector; -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { cxxopts::Options options("davis", "data visualization utility"); - options.add_options() - ("h,help", "davis commands") - ("l,linechart", "linechart values", cxxopts::value()) - ("m,heatmap", "heatmap values", cxxopts::value()) - ("f,file", "path to input file", cxxopts::value()) - ("t,charttype", "chart type", cxxopts::value()) - ; + options.add_options()("h,help", "davis commands")( + "l,linechart", "linechart values", cxxopts::value())( + "m,heatmap", "heatmap values", cxxopts::value())( + "f,file", "path to input file", cxxopts::value())( + "t,charttype", "chart type", cxxopts::value()); auto result = options.parse(argc, argv); if (result.count("help")) { std::cout << options.help() << std::endl; @@ -59,5 +57,3 @@ int main(int argc, char* argv[]) { return EXIT_SUCCESS; } - - diff --git a/plotly_maker/html_parts.cpp b/plotly_maker/html_parts.cpp index 5869e22..b08f507 100644 --- a/plotly_maker/html_parts.cpp +++ b/plotly_maker/html_parts.cpp @@ -2,7 +2,7 @@ namespace dvs { // #START_GRAB_TO_DVS_NAMESPACE -// *INDENT-OFF* +// clang-format off const char kHtmlModel[] = R"( @@ -739,6 +739,6 @@ const char kAverageErrorDataBlock[] = R"davis_delimeter({ } )davis_delimeter"; -// *INDENT-ON* +// clang-format on // #STOP_GRAB_TO_DVS_NAMESPACE } // namespace dvs diff --git a/plotly_maker/html_parts.h b/plotly_maker/html_parts.h index 625f888..7a6307f 100644 --- a/plotly_maker/html_parts.h +++ b/plotly_maker/html_parts.h @@ -2,24 +2,27 @@ #define HTML_PARTS_H namespace dvs { -//#START_GRAB_TO_DVS_NAMESPACE +// #START_GRAB_TO_DVS_NAMESPACE enum ARGS_INDEX { - ARG_VALUES, //%1 - ARG_COLOR_MAP, //%2 - ARG_MATRIX_TYPE,//%3 - ARG_TITLE, //%4 - ARG_TITLE_X, //%5 - ARG_TITLE_Y, //%6 - ARG_TITLE_Z, //%7 - ARG_JS_VER, //%8 + ARG_VALUES, //%1 + ARG_COLOR_MAP, //%2 + ARG_MATRIX_TYPE, //%3 + ARG_TITLE, //%4 + ARG_TITLE_X, //%5 + ARG_TITLE_Y, //%6 + ARG_TITLE_Z, //%7 + 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_FOR_AUTOSCALE, //%12 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale. - ARG_POINT_LINE_SWITCHER_STYLE, //%13 - ARG_POINT_LINE_SWITCHER_SELECT, //%14 - ARG_POINT_LINE_SWITCHER_UPDATE_FOO, //%15 - ARG_DAVIS_LOGO, //%16 + 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_FOR_AUTOSCALE, //%12 if value of it is equal to + // ARG_ASPECT_WIDTH_OR_HEIGHT it's + // mean no autoscale. + ARG_POINT_LINE_SWITCHER_STYLE, //%13 + ARG_POINT_LINE_SWITCHER_SELECT, //%14 + ARG_POINT_LINE_SWITCHER_UPDATE_FOO, //%15 + ARG_DAVIS_LOGO, //%16 // ADD NEW ENUM BEFORE THIS COMMENT ARGS_SIZE }; @@ -31,7 +34,6 @@ enum ARGS_WARNING_PAGE_INDEX { ARGS_WARNING_PAGE_SIZE }; - enum ARGS_REPORT_PAGE_INDEX { ARG_REPORT_TITLE, //%1 ARG_SVG_ICON, //%2 @@ -45,16 +47,21 @@ enum ARGS_DATE_TIME_PAGE_INDEX { ARG_DATE_TIME_VALUES_BLOCK, //%2 ARG_DATE_TIME_ASPECT_RATIO_WIDTH, //%3 ARG_DATE_TIME_ASPECT_RATIO_HEIGHT, //%4 - ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT, //%5 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not - ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%6 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale. + ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT, //%5 "width" if ARG_ASPECT_RATIO_WIDTH > + // ARG_ASPECT_RATIO_HEIGHT and "height" + // if not + ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%6 if value of it is + // equal to + // ARG_ASPECT_WIDTH_OR_HEIGHT + // it's mean no autoscale. ARG_DATE_TIME_POINT_LINE_SWITCHER_STYLE, //%7 ARG_DATE_TIME_POINT_LINE_SWITCHER_SELECT, //%8 ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO, //%9 - ARG_DATE_TIME_DAVIS_LOGO, //%10 - ARG_DATE_TIME_AVERAGE_BUTTON_STYLE,//%11 - ARG_DATE_TIME_AVERAGE_BUTTON_DIV,//%12 - ARG_DATE_TIME_AVERAGE_BUTTON_JS,//%13 - ARG_DATE_TIME_AVERAGE_VALUES_BLOCK,//%14 + ARG_DATE_TIME_DAVIS_LOGO, //%10 + ARG_DATE_TIME_AVERAGE_BUTTON_STYLE, //%11 + ARG_DATE_TIME_AVERAGE_BUTTON_DIV, //%12 + ARG_DATE_TIME_AVERAGE_BUTTON_JS, //%13 + ARG_DATE_TIME_AVERAGE_VALUES_BLOCK, //%14 // ADD NEW ENUM BEFORE THIS COMMENT ARGS_DATE_TIME_PAGE_SIZE }; @@ -65,9 +72,16 @@ enum ARGS_CLOUD_OF_POINTS_PAGE { ARG_Y_CLOUD_OF_POINTS, ARG_COLOR_CLOUD_OF_POINTS, 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. + 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. ARG_CLOUD_OF_POINTS_DAVIS_LOGO, //%9 // ADD NEW ENUM BEFORE THIS COMMENT ARGS_CLOUD_OF_POINTS_PAGE_SIZE @@ -79,7 +93,6 @@ enum ARGS_SIMPLE_DATA_BLOCK { ARGS_SIMPLE_DATA_BLOCK_SIZE }; - extern const char kHtmlModel[]; extern const char kColorMapDefaultPart[]; extern const char kColorMapSunnyPart[]; @@ -101,7 +114,6 @@ extern const char kWarningIcon[]; extern const char kHtmlDateTimeModel[]; - extern const char kHtmlMultiChartBlock[]; extern const char kHtmlMultiChartModel[]; extern const char kHtmlCloudOfPoints[]; @@ -120,7 +132,7 @@ extern const char kAverageButtonStyleBlock[]; extern const char kAverageButtonDivBlock[]; extern const char kAverageButtonJsFooBlock[]; extern const char kAverageErrorDataBlock[]; -//#STOP_GRAB_TO_DVS_NAMESPACE -} +// #STOP_GRAB_TO_DVS_NAMESPACE +} // namespace dvs #endif // HTML_PARTS_H diff --git a/plotly_maker/plotly_maker.cpp b/plotly_maker/plotly_maker.cpp index c154ae6..c2a03fd 100644 --- a/plotly_maker/plotly_maker.cpp +++ b/plotly_maker/plotly_maker.cpp @@ -1,26 +1,22 @@ -//#START_GRAB_TO_INCLUDES_LIST +// #START_GRAB_TO_INCLUDES_LIST +#include #include -#include #include -#include -#include -#include #include -#include -//#STOP_GRAB_TO_INCLUDES_LIST +#include +#include +// #STOP_GRAB_TO_INCLUDES_LIST -#include "html_parts.h" -#include "common_utils/common_utils.h" +#include "array_core/multi_plot.h" #include "common_utils/common_constants.h" +#include "common_utils/common_utils.h" +#include "html_parts.h" #include "plotly_maker.h" -#include "array_core/multi_plot.h" namespace dvs { -//#START_GRAB_TO_DVS_NAMESPACE - +// #START_GRAB_TO_DVS_NAMESPACE - -bool checkThatSizesAreTheSame(const vector>& values) { +bool checkThatSizesAreTheSame(const vector> &values) { size_t size = 0; if (!values.empty()) { size = values[0].size(); @@ -35,8 +31,8 @@ bool checkThatSizesAreTheSame(const vector>& values) { return true; } -bool createStringHeatMapValues(const vector>& values, - string& str_values) { +bool createStringHeatMapValues(const vector> &values, + string &str_values) { if (!checkThatSizesAreTheSame(values)) return false; if (!str_values.empty()) @@ -60,9 +56,9 @@ bool createStringHeatMapValues(const vector>& values, return true; } -bool createStringLineChartValues(const vector& xValues, - const vector& yValues, - string& out_str_values) { +bool createStringLineChartValues(const vector &xValues, + const vector &yValues, + string &out_str_values) { if (xValues.size() != yValues.size()) { return false; } @@ -84,16 +80,17 @@ bool createStringLineChartValues(const vector& xValues, out_str_values.append(","); } } - out_str_values.append("], mode: 'lines', hovertemplate: 'x:%{x}, y:%{y:.} ' };var data = [trace];"); + out_str_values.append("], mode: 'lines', hovertemplate: 'x:%{x}, y:%{y:.} " + "' };var data = [trace];"); return true; } -bool getMatrixValuesFromString(const string& in_values, - vector>& out_values) { +bool getMatrixValuesFromString(const string &in_values, + vector> &out_values) { istringstream f_lines(in_values); string lines; while (std::getline(f_lines, lines, ';')) { - vectorvals; + vector vals; istringstream f_values(lines); string str_value; while (std::getline(f_values, str_value, ',')) { @@ -104,9 +101,8 @@ bool getMatrixValuesFromString(const string& in_values, return true; }; -bool createHtmlPageHeatmap(const std::vector>& values, - string& page, - const dv::Config& configuration) { +bool createHtmlPageHeatmap(const std::vector> &values, + string &page, const dv::Config &configuration) { vector args(ARGS_SIZE, ""); string str_values = ""; if (!checkThatSizesAreTheSame(values)) { @@ -120,10 +116,13 @@ bool createHtmlPageHeatmap(const std::vector>& values, args[ARG_TITLE_X] = configuration.heatmap.xLabel; args[ARG_TITLE_Y] = configuration.heatmap.yLabel; args[ARG_TITLE_Z] = configuration.heatmap.zLabel; - args[ARG_ASPECT_RATIO_WIDTH] = dvs::toStringDotSeparator(configuration.heatmap.aspectRatioWidth); - args[ARG_ASPECT_RATIO_HEIGHT] = dvs::toStringDotSeparator(configuration.heatmap.aspectRatioHeight); + 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) { + if (configuration.heatmap.aspectRatioWidth > + configuration.heatmap.aspectRatioHeight) { paramWH = "width"; } else { paramWH = "height"; @@ -142,50 +141,52 @@ bool createHtmlPageHeatmap(const std::vector>& values, 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_POINT_LINE_SWITCHER_UPDATE_FOO] = + kHtmlComboboxUpdateSurfaceMatrixFooBlock; args[ARG_DAVIS_LOGO] = kHtmlDavisLogoHyperlinkBlock; dv::config_colorscales clrScale; clrScale = configuration.heatmap.colorSc; switch (clrScale) { - case dv::config_colorscales::COLORSCALE_DEFAULT: - args[ARG_COLOR_MAP] = kColorMapDefaultPart; - break; - case dv::config_colorscales::COLORSCALE_SUNNY: - args[ARG_COLOR_MAP] = kColorMapSunnyPart; - break; - case dv::config_colorscales::COLORSCALE_GLAMOUR: - args[ARG_COLOR_MAP] = kColorMapGlamourPart; - break; - case dv::config_colorscales::COLORSCALE_THERMAL: - args[ARG_COLOR_MAP] = kColorMapThermalPart; - break; - case dv::config_colorscales::COLORSCALE_GRAYSCALE: - args[ARG_COLOR_MAP] = kColorMapGrayscalePart; - break; - case dv::config_colorscales::COLORSCALE_YlGnBu: - args[ARG_COLOR_MAP] = kColorMapYlGnBuPart; - break; - case dv::config_colorscales::COLORSCALE_JET: - args[ARG_COLOR_MAP] = kColorMapJetPart; - break; - case dv::config_colorscales::COLORSCALE_HOT: - args[ARG_COLOR_MAP] = kColorMapHotPart; - break; - case dv::config_colorscales::COLORSCALE_ELECTRIC: - args[ARG_COLOR_MAP] = kColorMapElectricPart; - break; - case dv::config_colorscales::COLORSCALE_PORTLAND: - args[ARG_COLOR_MAP] = kColorMapPortlandPart; - break; + case dv::config_colorscales::COLORSCALE_DEFAULT: + args[ARG_COLOR_MAP] = kColorMapDefaultPart; + break; + case dv::config_colorscales::COLORSCALE_SUNNY: + args[ARG_COLOR_MAP] = kColorMapSunnyPart; + break; + case dv::config_colorscales::COLORSCALE_GLAMOUR: + args[ARG_COLOR_MAP] = kColorMapGlamourPart; + break; + case dv::config_colorscales::COLORSCALE_THERMAL: + args[ARG_COLOR_MAP] = kColorMapThermalPart; + break; + case dv::config_colorscales::COLORSCALE_GRAYSCALE: + args[ARG_COLOR_MAP] = kColorMapGrayscalePart; + break; + case dv::config_colorscales::COLORSCALE_YlGnBu: + args[ARG_COLOR_MAP] = kColorMapYlGnBuPart; + break; + case dv::config_colorscales::COLORSCALE_JET: + args[ARG_COLOR_MAP] = kColorMapJetPart; + break; + case dv::config_colorscales::COLORSCALE_HOT: + args[ARG_COLOR_MAP] = kColorMapHotPart; + break; + case dv::config_colorscales::COLORSCALE_ELECTRIC: + args[ARG_COLOR_MAP] = kColorMapElectricPart; + break; + case dv::config_colorscales::COLORSCALE_PORTLAND: + args[ARG_COLOR_MAP] = kColorMapPortlandPart; + break; } make_string(kHtmlModel, args, page); return true; } -bool showHeatMapInBrowser(const vector>& values, - const string& title, const dv::Config& configuration) { +bool showHeatMapInBrowser(const vector> &values, + const string &title, + const dv::Config &configuration) { string page; if (!createHtmlPageHeatmap(values, page, configuration)) { return false; @@ -193,37 +194,42 @@ bool showHeatMapInBrowser(const vector>& values, string pageName; mayBeCreateJsWorkingFolder(); string titleWithoutSpecialChars = dvs::removeSpecialCharacters(title); - pageName.append("./").append(kOutFolderName).append(titleWithoutSpecialChars).append(".html"); + pageName.append("./") + .append(kOutFolderName) + .append(titleWithoutSpecialChars) + .append(".html"); saveStringToFile(pageName, page); if (isPlotlyScriptExists()) { openPlotlyHtml(pageName); } else { showWarningJsAbsentPage(); } - return true;// TODO handle different exceptions + return true; // TODO handle different exceptions } -bool showHeatMapInBrowser(const string& values, - const string& title, const dv::Config& configuration) { - vector>heat_map_values; +bool showHeatMapInBrowser(const string &values, const string &title, + const dv::Config &configuration) { + vector> heat_map_values; getMatrixValuesFromString(values, heat_map_values); showHeatMapInBrowser(heat_map_values, title, configuration); return true; }; -bool showLineChartInBrowser(const vector& values, - const string& title, const dv::Config& configuration) { +bool showLineChartInBrowser(const vector &values, const string &title, + const dv::Config &configuration) { vector x(values.size()); - std::iota(std::begin(x), std::end(x), 0); // Fill with 0, 1, 2... + std::iota(std::begin(x), std::end(x), 0); // Fill with 0, 1, 2... showLineChartInBrowser(x, values, title, configuration); return true; } -bool showLineChartInBrowser(const vector& xValues, const vector& yValues, - const std::string& title, const dv::Config& configuration) { +bool showLineChartInBrowser(const vector &xValues, + const vector &yValues, + const std::string &title, + const dv::Config &configuration) { string page; - vectorargs(ARGS_SIZE, ""); + vector args(ARGS_SIZE, ""); args[ARG_JS_VER] = kPlotlyJsName; string str_values = ""; createStringLineChartValues(xValues, yValues, str_values); @@ -231,10 +237,13 @@ bool showLineChartInBrowser(const vector& xValues, const vector& args[ARG_TITLE] = configuration.chart.title; args[ARG_TITLE_X] = configuration.chart.xLabel; args[ARG_TITLE_Y] = configuration.chart.yLabel; - args[ARG_ASPECT_RATIO_WIDTH] = dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth); - args[ARG_ASPECT_RATIO_HEIGHT] = dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight); + args[ARG_ASPECT_RATIO_WIDTH] = + dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth); + args[ARG_ASPECT_RATIO_HEIGHT] = + dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight); string paramWH; - if (configuration.chart.aspectRatioWidth > configuration.chart.aspectRatioHeight) { + if (configuration.chart.aspectRatioWidth > + configuration.chart.aspectRatioHeight) { paramWH = "width"; } else { paramWH = "height"; @@ -259,7 +268,10 @@ bool showLineChartInBrowser(const vector& xValues, const vector& string pageName; mayBeCreateJsWorkingFolder(); string titleWithoutSpecialChars = dvs::removeSpecialCharacters(title); - pageName.append("./").append(kOutFolderName).append(titleWithoutSpecialChars).append(".html"); + pageName.append("./") + .append(kOutFolderName) + .append(titleWithoutSpecialChars) + .append(".html"); saveStringToFile(pageName, page); if (isPlotlyScriptExists()) { openPlotlyHtml(pageName); @@ -269,9 +281,9 @@ bool showLineChartInBrowser(const vector& xValues, const vector& return true; } -bool showLineChartInBrowser(const string& values, - const string& title, const dv::Config& configuration) { - vectorvals; +bool showLineChartInBrowser(const string &values, const string &title, + const dv::Config &configuration) { + vector vals; istringstream f(values); string s; while (std::getline(f, s, ',')) { @@ -289,7 +301,7 @@ void showWarningJsAbsentPage() { #elif __linux__ davis_dir = "/davis_htmls"; #endif - vectorargs {ARGS_WARNING_PAGE_SIZE, ""}; + vector args{ARGS_WARNING_PAGE_SIZE, ""}; args[ARG_WORKING_FOLDER] = getCurrentPath() + davis_dir; args[ARG_JS_VERSION] = kPlotlyJsName; make_string(kWarningJSLibAbsentPage, args, out); @@ -297,10 +309,8 @@ void showWarningJsAbsentPage() { openFileBySystem(kWarningPagePath); } - -void showReportPage(const string& title, - const string& svg, - const string& description) { +void showReportPage(const string &title, const string &svg, + const string &description) { string out; string davis_dir; @@ -309,63 +319,55 @@ void showReportPage(const string& title, #elif __linux__ davis_dir = "/davis_htmls"; #endif - vectorargs {ARGS_REPORT_PAGE_SIZE, ""}; + vector args{ARGS_REPORT_PAGE_SIZE, ""}; args[ARG_REPORT_TITLE] = title; args[ARG_SVG_ICON] = svg; args[ARG_REPORT_DESCRIPTION] = description; make_string(kNoFileFoundedPage, args, out); saveStringToFile(kReportPagePath, out); openFileBySystem(kReportPagePath); - } - void showReportFileNotFounded() { - showReportPage("Open file error.", - kWarningIcon, + showReportPage("Open file error.", kWarningIcon, "File is not founded. Please, check the path to the file."); } void showReportFileEmpty() { - showReportPage("File is empty.", - kWarningIcon, - "No data to show."); + showReportPage("File is empty.", kWarningIcon, "No data to show."); } - void showMatrixSizesAreNotTheSame(int badRow) { string text; - text.append("Rows have different sizes in matrix. Check the row № ").append(std::to_string(badRow + 1)); - showReportPage("Rows sizes are not the same", - kWarningIcon, - text); + text.append("Rows have different sizes in matrix. Check the row № ") + .append(std::to_string(badRow + 1)); + showReportPage("Rows sizes are not the same", kWarningIcon, text); } -void showDateTimeChart(const string& date_time_values, - const vector& yValues, - bool isFitPlotToWindow) { +void showDateTimeChart(const string &date_time_values, + const vector &yValues, bool isFitPlotToWindow) { string out; - vectorargs {ARGS_DATE_TIME_PAGE_SIZE, ""}; + vector args{ARGS_DATE_TIME_PAGE_SIZE, ""}; args[ARG_JS_NAME] = kPlotlyJsName; - vectorargs_block {ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; + vector args_block{ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; std::string simpleData_yValues = vectorToString(yValues); args_block[ARG_SIMPLE_DATA_X] = date_time_values; args_block[ARG_SIMPLE_DATA_Y] = simpleData_yValues; std::string data_values_block; make_string(kHtmlSimpleDataBlock, args_block, data_values_block); - args[ARG_DATE_TIME_VALUES_BLOCK] = data_values_block; args[ARG_DATE_TIME_ASPECT_RATIO_WIDTH] = "1"; args[ARG_DATE_TIME_ASPECT_RATIO_HEIGHT] = "1"; args[ARG_DATE_TIME_POINT_LINE_SWITCHER_STYLE] = kHtmlComboboxStyleBlock; args[ARG_DATE_TIME_POINT_LINE_SWITCHER_SELECT] = kHtmlComboboxSelectBlock; - args[ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO] = kHtmlComboboxUpdateFooBlock; + args[ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO] = + kHtmlComboboxUpdateFooBlock; string paramWH = "height"; string paramWHsecond; @@ -385,17 +387,18 @@ void showDateTimeChart(const string& date_time_values, auto unique_path = dvs::makeUniqueDavisHtmlName(); saveStringToFile(unique_path, out); openFileBySystem(unique_path); - - } -void addTraceBlockToGlobal(const vector& yValues, const string& traceName) { +void addTraceBlockToGlobal(const vector &yValues, + const string &traceName) { vector xValues(yValues.size()); - std::iota(std::begin(xValues), std::end(xValues), 0); // Fill with 0, 1, 2... + std::iota(std::begin(xValues), std::end(xValues), 0); // Fill with 0, 1, 2... addTraceBlockToGlobal(xValues, yValues, traceName); } -void addTraceBlockToGlobal(const vector& xValues, const vector& yValues, const string& traceName) { +void addTraceBlockToGlobal(const vector &xValues, + const vector &yValues, + const string &traceName) { string trace_block = dvs::kHtmlMultiChartBlock; int trace_i = 1 + dvs::allChartBlocks.size(); string str_numTrace = std::to_string(trace_i); @@ -408,13 +411,13 @@ void addTraceBlockToGlobal(const vector& xValues, const vector& dvs::allChartBlocks.emplace_back(filled_trace_block); } -void showCloudOfPointsChart(const vector& xValues, - const vector& yValues, - const vector& colorValues, +void showCloudOfPointsChart(const vector &xValues, + const vector &yValues, + const vector &colorValues, bool isFitPlotToWindow) { string out; string davis_dir; - vectorargs {ARGS_CLOUD_OF_POINTS_PAGE_SIZE, ""}; + vector args{ARGS_CLOUD_OF_POINTS_PAGE_SIZE, ""}; args[ARG_JS_COF_NAME] = kPlotlyJsName; args[ARG_X_CLOUD_OF_POINTS] = vectorToString(xValues); args[ARG_Y_CLOUD_OF_POINTS] = vectorToString(yValues); @@ -433,7 +436,8 @@ void showCloudOfPointsChart(const vector& xValues, } else { paramWHsecond = paramWH; } - args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond; + args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = + paramWHsecond; args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT] = paramWH; args[ARG_CLOUD_OF_POINTS_DAVIS_LOGO] = kHtmlDavisLogoHyperlinkBlock; make_string(kHtmlCloudOfPoints, args, out); @@ -442,12 +446,12 @@ void showCloudOfPointsChart(const vector& xValues, openFileBySystem(unique_file_name); } -void showCloudOfPointsChartStr(const std::string& xValues, - const vector& yValues, - const vector& colorValues, +void showCloudOfPointsChartStr(const std::string &xValues, + const vector &yValues, + const vector &colorValues, bool isFitPlotToWindow) { string out; - vectorargs {ARGS_CLOUD_OF_POINTS_PAGE_SIZE, ""}; + vector args{ARGS_CLOUD_OF_POINTS_PAGE_SIZE, ""}; args[ARG_JS_COF_NAME] = kPlotlyJsName; args[ARG_X_CLOUD_OF_POINTS] = xValues; args[ARG_Y_CLOUD_OF_POINTS] = vectorToString(yValues); @@ -466,7 +470,8 @@ void showCloudOfPointsChartStr(const std::string& xValues, } else { paramWHsecond = paramWH; } - args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond; + args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = + paramWHsecond; args[ARG_CLOUD_OF_POINTS_ASPECT_WIDTH_OR_HEIGHT] = paramWH; args[ARG_CLOUD_OF_POINTS_DAVIS_LOGO] = kHtmlDavisLogoHyperlinkBlock; make_string(kHtmlCloudOfPoints, args, out); @@ -475,18 +480,16 @@ void showCloudOfPointsChartStr(const std::string& xValues, openFileBySystem(unique_file_name); } -void showMultiChart(const std::string& date_time_values, - const vector>& yValues, +void showMultiChart(const std::string &date_time_values, + const vector> &yValues, bool isFitPlotToWindow) { string out; - vectorargs {ARGS_DATE_TIME_PAGE_SIZE, ""}; + vector args{ARGS_DATE_TIME_PAGE_SIZE, ""}; args[ARG_JS_NAME] = kPlotlyJsName; - - std::string all_data = ""; for (size_t i = 0; i < yValues.size(); ++i) { - vectorargs_block {ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; + vector args_block{ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; std::string simpleData_yValues = vectorToString(yValues[i]); args_block[ARG_SIMPLE_DATA_X] = date_time_values; args_block[ARG_SIMPLE_DATA_Y] = simpleData_yValues; @@ -504,33 +507,34 @@ void showMultiChart(const std::string& date_time_values, auto polygon_date_time = date_time_values; polygon_date_time.append(","); polygon_date_time.append(reversed_date_time_data); - auto polygon_deviation_values = doubleAndReverse(deviation_values, average_values); + auto polygon_deviation_values = + doubleAndReverse(deviation_values, average_values); - vectorargs_block {ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; + vector args_block{ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; std::string simpleData_yValues = vectorToString(deviation_values); args_block[ARG_SIMPLE_DATA_X] = polygon_date_time; args_block[ARG_SIMPLE_DATA_Y] = vectorToString(polygon_deviation_values); std::string average_error_data_values_block; - make_string(kAverageErrorDataBlock, args_block, average_error_data_values_block); + make_string(kAverageErrorDataBlock, args_block, + average_error_data_values_block); std::string average_values_str = vectorToString(average_values); - vectorargs_aver_block {ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; + vector args_aver_block{ARGS_SIMPLE_DATA_BLOCK_SIZE, ""}; args_aver_block[ARG_SIMPLE_DATA_X] = date_time_values; args_aver_block[ARG_SIMPLE_DATA_Y] = average_values_str; std::string average_data_values_block; make_string(kHtmlSimpleDataBlock, args_aver_block, average_data_values_block); - auto all_aver_block = average_error_data_values_block; all_aver_block.append(","); all_aver_block.append(average_data_values_block); - args[ARG_DATE_TIME_AVERAGE_VALUES_BLOCK] = all_aver_block; args[ARG_DATE_TIME_POINT_LINE_SWITCHER_STYLE] = kHtmlComboboxStyleBlock; args[ARG_DATE_TIME_POINT_LINE_SWITCHER_SELECT] = kHtmlComboboxSelectBlock; - args[ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO] = kHtmlComboboxUpdateFooBlock; + args[ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO] = + kHtmlComboboxUpdateFooBlock; args[ARG_DATE_TIME_VALUES_BLOCK] = all_data; args[ARG_DATE_TIME_ASPECT_RATIO_WIDTH] = "1"; args[ARG_DATE_TIME_ASPECT_RATIO_HEIGHT] = "1"; @@ -559,6 +563,5 @@ void showMultiChart(const std::string& date_time_values, openFileBySystem(unique_file_name); } -//#STOP_GRAB_TO_DVS_NAMESPACE +// #STOP_GRAB_TO_DVS_NAMESPACE }; // namespace dvs - diff --git a/plotly_maker/plotly_maker.h b/plotly_maker/plotly_maker.h index a61d5c1..1c24980 100644 --- a/plotly_maker/plotly_maker.h +++ b/plotly_maker/plotly_maker.h @@ -1,37 +1,41 @@ #ifndef PLOTLY_MAKER_PLOTLY_MAKER_H_ #define PLOTLY_MAKER_PLOTLY_MAKER_H_ -//#START_GRAB_TO_INCLUDES_LIST -#include -#include -#include +// #START_GRAB_TO_INCLUDES_LIST #include -//#STOP_GRAB_TO_INCLUDES_LIST +#include +#include +#include +// #STOP_GRAB_TO_INCLUDES_LIST #include "../array_core/configurator.h" namespace dvs { -//#START_GRAB_TO_DVS_NAMESPACE +// #START_GRAB_TO_DVS_NAMESPACE +using std::istringstream; using std::string; using std::vector; -using std::istringstream; - -bool createHtmlPageHeatmap(const vector>& values, - string& page, - const dv::Config& configuration); +bool createHtmlPageHeatmap(const vector> &values, string &page, + const dv::Config &configuration); -bool showHeatMapInBrowser(const vector>& values, const string& title, const dv::Config& configuration); -bool showHeatMapInBrowser(const string& values, const string& title, const dv::Config& configuration); +bool showHeatMapInBrowser(const vector> &values, + const string &title, const dv::Config &configuration); +bool showHeatMapInBrowser(const string &values, const string &title, + const dv::Config &configuration); -bool showLineChartInBrowser(const vector& values, const string& title, const dv::Config& configuration); -bool showLineChartInBrowser(const vector& xValues, const vector& yValues, - const string& title, const dv::Config& configuration); -bool showLineChartInBrowser(const string& values, const string& title, const dv::Config& configuration); +bool showLineChartInBrowser(const vector &values, const string &title, + const dv::Config &configuration); +bool showLineChartInBrowser(const vector &xValues, + const vector &yValues, const string &title, + const dv::Config &configuration); +bool showLineChartInBrowser(const string &values, const string &title, + const dv::Config &configuration); void showWarningJsAbsentPage(); -void showReportPage(const string& page, const string& title, const string& svg, const string& description); +void showReportPage(const string &page, const string &title, const string &svg, + const string &description); void showReportFileNotFounded(); @@ -39,30 +43,30 @@ void showReportFileEmpty(); void showMatrixSizesAreNotTheSame(int badRow); -void showDateTimeChart(const string& date_time_values, - const vector& yValues, - bool isFitPlotToWindow); +void showDateTimeChart(const string &date_time_values, + const vector &yValues, bool isFitPlotToWindow); -void addTraceBlockToGlobal(const vector& yValues, const string& traceName); -void addTraceBlockToGlobal(const vector& xValues, const vector& yValues, const string& traceName); +void addTraceBlockToGlobal(const vector &yValues, + const string &traceName); +void addTraceBlockToGlobal(const vector &xValues, + const vector &yValues, + const string &traceName); -void showCloudOfPointsChart(const vector& xValues, - const vector& yValues, - const vector& colorValues, +void showCloudOfPointsChart(const vector &xValues, + const vector &yValues, + const vector &colorValues, bool isFitPlotToWindow); - -void showCloudOfPointsChartStr(const string& xValues, - const vector& yValues, - const vector& colorValues, +void showCloudOfPointsChartStr(const string &xValues, + const vector &yValues, + const vector &colorValues, bool isFitPlotToWindow); -void showMultiChart(const string& date_time_values, - const vector>& yValues, +void showMultiChart(const string &date_time_values, + const vector> &yValues, bool isFitPlotToWindow); -//#STOP_GRAB_TO_DVS_NAMESPACE +// #STOP_GRAB_TO_DVS_NAMESPACE }; // namespace dvs #endif // PLOTLY_MAKER_PLOTLY_MAKER_H_ -