Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 62 additions & 68 deletions array_core/array_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,88 +10,86 @@
#include "configurator.h"
#include "multi_plot.h"


namespace dv {
//#START_GRAB_TO_DV_NAMESPACE

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


//! (matrix) 2-dimensional array
template <typename T>
bool show(T** data, uint64_t arrRows, uint64_t arrCols,
const string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config());
const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config());

template <typename T>
bool save(T** data, uint64_t arrRows, uint64_t arrCols, const string& filename,
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])
template <typename T>
bool show(const T* data, uint64_t arrRows, uint64_t arrCols,
const string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config());
const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config());

template <typename T>
bool save(const T* data, uint64_t arrRows, uint64_t arrCols, const string& filename,
bool save(const T* data, uint64_t arrRows, uint64_t arrCols, const std::string& filename,
const configSaveToDisk& configuration = configSaveToDisk());

//! (chart) 1-dimensional array
template <typename T>
bool show(const T* data, uint64_t count, const 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 <typename T>
bool save(const T* data, uint64_t count, const 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<typename C,
typename T = typename std::decay<decltype(*std::begin(std::declval<C>()))>::type,
typename Enable = typename std::enable_if<std::is_convertible<T, double>::value>::type>
bool show(C const& container, const string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config());
bool show(C const& container, const std::string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config());

template<typename C,
typename T = typename std::decay<decltype(*std::begin(std::declval<C>()))>::type,
typename Enable = typename std::enable_if<std::is_convertible<T, double>::value>::type>
bool save(C const& container, const string& filename, const configSaveToDisk& configuration = configSaveToDisk());
bool save(C const& container, const std::string& filename, const configSaveToDisk& configuration = configSaveToDisk());


//! +(chart) Two 1-dimensional container for X-Y plot
template<typename C,
typename T = typename std::decay<decltype(*std::begin(std::declval<C>()))>::type,
typename Enable = typename std::enable_if<std::is_convertible<T, double>::value>::type>
bool show(C const& containerX, C const& containerY, const string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config());
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<decltype(*std::begin(std::declval<C>()))>::type,
typename Enable = typename std::enable_if<std::is_convertible<T, double>::value>::type>
bool save(C const& containerX, C const& containerY, const string& filename, const configSaveToDisk& configuration = configSaveToDisk());
bool save(C const& containerX, C const& containerY, const std::string& filename, const configSaveToDisk& configuration = configSaveToDisk());


//! (chart / matrix) 2-dimensional container
template<typename C,
typename E = typename std::decay<decltype(*std::begin(std::declval<C>()))>::type,
typename T = typename std::decay<decltype(*std::begin(std::declval<E>()))>::type,
typename Enable = typename std::enable_if<std::is_convertible<T, double>::value>::type>
bool show(C const& container_of_containers, const string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config());
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<decltype(*std::begin(std::declval<C>()))>::type,
typename T = typename std::decay<decltype(*std::begin(std::declval<E>()))>::type,
typename Enable = typename std::enable_if<std::is_convertible<T, double>::value>::type>
bool save(C const& container_of_containers, const string& filename, const configSaveToDisk& configuration = configSaveToDisk());
bool save(C const& container_of_containers, const std::string& filename, const configSaveToDisk& configuration = configSaveToDisk());


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

template <typename T>
bool show(T** data, uint64_t arrRows, uint64_t arrCols, const string& htmlPageName, const Config& configuration) {
vector<vector<double>> vecVecDbl;
vecVecDbl.reserve(arrRows);
for (uint64_t i = 0; i < arrRows; ++i) {
vector<double> dblRow(&data[i][0], &data[i][0] + arrCols);
vecVecDbl.emplace_back(dblRow);
}
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<std::vector<double>> vecVecDbl =
dvs::makeVecVecFromRowPtr<double>(data, arrRows, arrCols);

bool res = false;
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_HEATMAP) {
Expand All @@ -102,24 +100,19 @@ bool show(T** data, uint64_t arrRows, uint64_t arrCols, const string& htmlPageNa

template <typename T>
bool save(T** data, uint64_t arrRows, uint64_t arrCols, const std::string& filename, const configSaveToDisk& configuration) {
vector<vector<T>> vecVec;
vecVec.reserve(arrRows);
for (uint64_t i = 0; i < arrRows; ++i) {
vector<T> row(&data[i][0], &data[i][0] + arrCols);
vecVec.emplace_back(row);
}
if (data == nullptr || arrRows == 0 || arrCols == 0)
return false;
std::vector<std::vector<T>> vecVec =
dvs::makeVecVecFromRowPtr<T>(data, arrRows, arrCols);
bool res = dvs::saveVecVec<T>(vecVec, filename, configuration);
return res;
}

template <typename T>
bool show(const T* data, uint64_t arrRows, uint64_t arrCols, const string& htmlPageName, const Config& configuration) {
vector<vector<double>> vecVecDbl;
vecVecDbl.reserve(arrRows);
for (uint64_t i = 0; i < arrRows; ++i) {
vector<double> dblRow(&data[i * arrCols], &data[i * arrCols] + arrCols);
vecVecDbl.emplace_back(dblRow);
}
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<std::vector<double>> vecVecDbl = dvs::makeVecVecFromFlat<double>(data, arrRows, arrCols);
bool res = false;
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_HEATMAP) {
Expand All @@ -129,21 +122,20 @@ bool show(const T* data, uint64_t arrRows, uint64_t arrCols, const string& htmlP
}

template <typename T>
bool save(const T* data, uint64_t arrRows, uint64_t arrCols, const string& filename,
bool save(const T* data, uint64_t arrRows, uint64_t arrCols, const std::string& filename,
const configSaveToDisk& configuration) {
vector<vector<T>> vecVec;
vecVec.reserve(arrRows);
for (uint64_t i = 0; i < arrRows; ++i) {
vector<T> row(&data[i * arrCols], &data[i * arrCols] + arrCols);
vecVec.emplace_back(row);
}
if (data == nullptr || arrRows == 0 || arrCols == 0)
return false;
std::vector<std::vector<T>> vecVec = dvs::makeVecVecFromFlat<T>(data, arrRows, arrCols);
bool res = dvs::saveVecVec<T>(vecVec, filename, configuration);
return res;
}

template <typename T>
bool show(const T* data, uint64_t count, const string& htmlPageName, const Config& configuration) {
vector<double> dblRow(data, data + count);
bool show(const T* data, uint64_t count, const std::string& htmlPageName, const Config& configuration) {
if (data == nullptr || count == 0)
return false;
std::vector<double> dblRow = dvs::makeVecFrom1D<double>(data, count);
bool res = false;
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_CHART) {
Expand All @@ -158,15 +150,17 @@ bool show(const T* data, uint64_t count, const string& htmlPageName, const Confi
}

template <typename T>
bool save(const T* data, uint64_t count, const string& filename, const configSaveToDisk& configuration) {
vector<T> row(data, data + count);
bool save(const T* data, uint64_t count, const std::string& filename, const configSaveToDisk& configuration) {
if (data == nullptr || count == 0)
return false;
std::vector<T> row = dvs::makeVecFrom1D<T>(data, count);
bool res = dvs::saveVec<T>(row, filename, configuration);
return res;
}

template<typename C, typename T, typename>
bool show(C const& container, const string& htmlPageName, const Config& configuration) {
vector<double> dblRow = dvs::vecFromTemplate<double>(container);
bool show(C const& container, const std::string& htmlPageName, const Config& configuration) {
std::vector<double> dblRow = dvs::makeVecFromContainer<double>(container);
bool res = false;
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_CHART) {
Expand All @@ -181,19 +175,19 @@ bool show(C const& container, const string& htmlPageName, const Config& configur
}

template<typename C, typename T, typename>
bool save(C const& container, const string& filename, const configSaveToDisk& configuration) {
vector<T> row = dvs::vecFromTemplate<T>(container);
bool save(C const& container, const std::string& filename, const configSaveToDisk& configuration) {
std::vector<T> row = dvs::makeVecFromContainer<T>(container);
bool res = dvs::saveVec<T>(row, filename, configuration);
return res;
}

template<typename C, typename T, typename>
bool show(C const& containerX, C const& containerY, const string& htmlPageName, const Config& configuration) {
bool show(C const& containerX, C const& containerY, const std::string& htmlPageName, const Config& configuration) {
if (containerX.size() != containerY.size()) {
return false;
}
vector<double> dblRowX = dvs::vecFromTemplate<double>(containerX);
vector<double> dblRowY = dvs::vecFromTemplate<double>(containerY);
std::vector<double> dblRowX = dvs::makeVecFromContainer<double>(containerX);
std::vector<double> dblRowY = dvs::makeVecFromContainer<double>(containerY);

bool res = false;
if (!dvs::isHold) {
Expand All @@ -206,13 +200,13 @@ bool show(C const& containerX, C const& containerY, const string& htmlPageName,
}

template<typename C, typename T, typename Enable>
bool save(C const& containerX, C const& containerY, const string& filename, const configSaveToDisk& configuration) {
bool save(C const& containerX, C const& containerY, const std::string& filename, const configSaveToDisk& configuration) {
if (containerX.size() != containerY.size()) {
return false;
}
vector<T> rowX = dvs::vecFromTemplate<T>(containerX);
vector<T> rowY = dvs::vecFromTemplate<T>(containerY);
vector<vector<T>> vecVec;
std::vector<T> rowX = dvs::makeVecFromContainer<T>(containerX);
std::vector<T> rowY = dvs::makeVecFromContainer<T>(containerY);
std::vector<std::vector<T>> vecVec;
vecVec.emplace_back(rowX);
vecVec.emplace_back(rowY);
configSaveToDisk newConf = configuration;
Expand All @@ -222,11 +216,11 @@ bool save(C const& containerX, C const& containerY, const string& filename, con
}

template<typename C, typename E, typename T, typename >
bool show(C const& container_of_containers, const string& htmlPageName, const Config& configuration) {
vector<vector<double>> vecVecDbl;
bool show(C const& container_of_containers, const std::string& htmlPageName, const Config& configuration) {
std::vector<std::vector<double>> vecVecDbl;
vecVecDbl.reserve(container_of_containers.size());
for (auto row : container_of_containers) {
vector<double> dblRow = dvs::vecFromTemplate<double>(row);
for (const auto& row : container_of_containers) {
std::vector<double> dblRow = dvs::makeVecFromContainer<double>(row);
vecVecDbl.emplace_back(dblRow);
}
bool res = false;
Expand All @@ -238,14 +232,14 @@ bool show(C const& container_of_containers, const string& htmlPageName, const Co
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
vector<double> xVals;
vector<double> yVals;
std::vector<double> xVals;
std::vector<double> yVals;
if (size1 == 2) {
xVals = vecVecDbl[0];
yVals = vecVecDbl[1];
} else if (size2 == 2) {
xVals.reserve(size1);
for (int i = 0; i < size1; ++i) {
for (size_t i = 0; i < size1; ++i) {
xVals.emplace_back(vecVecDbl[i][0]);
yVals.emplace_back(vecVecDbl[i][1]);
}
Expand All @@ -264,11 +258,11 @@ bool show(C const& container_of_containers, const string& htmlPageName, const Co
}

template<typename C, typename E, typename T, typename Enable>
bool save(C const& container_of_containers, const string& filename, const configSaveToDisk& configuration) {
vector<vector<T>> vecVec;
bool save(C const& container_of_containers, const std::string& filename, const configSaveToDisk& configuration) {
std::vector<std::vector<T>> vecVec;
vecVec.reserve(container_of_containers.size());
for (auto row : container_of_containers) {
vector<T> rowTemp = dvs::vecFromTemplate<T>(row);
for (const auto& row : container_of_containers) {
std::vector<T> rowTemp = dvs::makeVecFromContainer<T>(row);
vecVec.emplace_back(rowTemp);
}
bool res = dvs::saveVecVec<T>(vecVec, filename, configuration);
Expand Down
60 changes: 33 additions & 27 deletions array_core/multi_plot.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "multi_plot.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

bool isHold = false;
vector<string> allChartBlocks = {};
std::vector<std::string> allChartBlocks = {};

//#STOP_GRAB_TO_DVS_NAMESPACE
} // end namespace dvs
Expand All @@ -27,25 +28,25 @@ void holdOff(const Config& configuration) {
if (dvs::allChartBlocks.empty()) {
return;
}
string allTracesNames_str;
string allChartBlocks_str;
const string trace_name_part = "trace";
std::string allTracesNames_str;
std::string allChartBlocks_str;
const std::string trace_name_part = "trace";
for (int i = 0; i < dvs::allChartBlocks.size(); ++i) {
string str_numTrace = std::to_string(i + 1);
string filled_trace_name_part = trace_name_part + str_numTrace;
std::string str_numTrace = std::to_string(i + 1);
std::string filled_trace_name_part = trace_name_part + str_numTrace;
if (i < dvs::allChartBlocks.size() - 1) {
filled_trace_name_part.append(",");
}
allTracesNames_str.append(filled_trace_name_part);
allChartBlocks_str.append(dvs::allChartBlocks[i]);
}
string paramWH;
std::string paramWH;
if (configuration.chart.aspectRatioWidth > configuration.chart.aspectRatioHeight) {
paramWH = "width";
} else {
paramWH = "height";
}
string paramWHsecond;
std::string paramWHsecond;
if (configuration.chart.isFitPlotToWindow) {
if (paramWH == "width") {
paramWHsecond = "height";
Expand All @@ -55,27 +56,32 @@ void holdOff(const Config& configuration) {
} else {
paramWHsecond = paramWH;
}
vector<string> args = {dvs::kPlotlyJsName,
allChartBlocks_str,
allTracesNames_str,
configuration.chart.title,
configuration.chart.xLabel,
configuration.chart.yLabel,
dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth),
dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight),
paramWH,
paramWHsecond,
dvs::kHtmlComboboxStyleBlock,
dvs::kHtmlComboboxSelectBlock,
dvs::kHtmlComboboxUpdateFooBlock,
dvs::kHtmlDavisLogoHyperlinkBlock
};
string multichartPage = dvs::kHtmlMultiChartModel;
string filled_multichartPage = "";
std::vector<std::string> args = {dvs::kPlotlyJsName,
allChartBlocks_str,
allTracesNames_str,
configuration.chart.title,
configuration.chart.xLabel,
configuration.chart.yLabel,
dvs::toStringDotSeparator(configuration.chart.aspectRatioWidth),
dvs::toStringDotSeparator(configuration.chart.aspectRatioHeight),
paramWH,
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);
string htmlFullName = dvs::makeUniqueDavisHtmlRelativePath();
std::string htmlFullName = dvs::makeUniqueDavisHtmlRelativePath();
dvs::mayBeCreateJsWorkingFolder();
dvs::saveStringToFile(htmlFullName, filled_multichartPage);
dvs::openFileBySystem(htmlFullName);
if (dvs::isPlotlyScriptExists()) {
dvs::openPlotlyHtml(htmlFullName);
} else {
dvs::showWarningJsAbsentPage();
}
dvs::allChartBlocks.clear();
}

Expand Down
Loading