mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[matplotlib] Modified isEmpty method for showing axis
Added a condition for being considered empty.
Allows axis("on") or axis((0,1,2,3)) to display something with show()
This behavior is the same as the python module
Change-Id: If5f3b07c280ee9ead2bc23d23cbbb4f01da7eae5
This commit is contained in:
@@ -96,6 +96,7 @@ void modpyplot_flush_used_heap() {
|
||||
mp_obj_t modpyplot_arrow(size_t n_args, const mp_obj_t *args) {
|
||||
assert(n_args >= 4);
|
||||
assert(sPlotStore != nullptr);
|
||||
sPlotStore->setShow(true);
|
||||
mp_obj_t arrowWidth = mp_obj_new_float(0.003); // Default value
|
||||
if (n_args >= 5) {
|
||||
arrowWidth = args[4];
|
||||
@@ -114,7 +115,7 @@ mp_obj_t modpyplot_arrow(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
mp_obj_t modpyplot_axis(size_t n_args, const mp_obj_t *args) {
|
||||
assert(sPlotStore != nullptr);
|
||||
|
||||
sPlotStore->setShow(true);
|
||||
if (n_args == 1) {
|
||||
mp_obj_t arg = args[0];
|
||||
if (mp_obj_is_str(arg)) {
|
||||
@@ -168,7 +169,7 @@ mp_obj_t modpyplot_axis(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
mp_obj_t modpyplot_bar(size_t n_args, const mp_obj_t *args) {
|
||||
assert(sPlotStore != nullptr);
|
||||
|
||||
sPlotStore->setShow(true);
|
||||
mp_obj_t * xItems;
|
||||
mp_obj_t * hItems;
|
||||
mp_obj_t * wItems;
|
||||
@@ -223,7 +224,7 @@ mp_obj_t modpyplot_bar(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
mp_obj_t modpyplot_grid(size_t n_args, const mp_obj_t *args) {
|
||||
assert(sPlotStore != nullptr);
|
||||
|
||||
sPlotStore->setShow(true);
|
||||
if (n_args == 0) {
|
||||
// Toggle the grid visibility
|
||||
sPlotStore->setGridRequested(!sPlotStore->gridRequested());
|
||||
@@ -242,7 +243,7 @@ mp_obj_t modpyplot_grid(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
mp_obj_t modpyplot_hist(size_t n_args, const mp_obj_t *args) {
|
||||
assert(sPlotStore != nullptr);
|
||||
|
||||
sPlotStore->setShow(true);
|
||||
// Sort data to easily get the minimal and maximal value and count bin sizes
|
||||
mp_obj_t * xItems;
|
||||
size_t xLength = extractArgument(args[0], &xItems);
|
||||
@@ -326,7 +327,7 @@ mp_obj_t modpyplot_hist(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
mp_obj_t modpyplot_scatter(size_t n_args, const mp_obj_t *args) {
|
||||
assert(sPlotStore != nullptr);
|
||||
|
||||
sPlotStore->setShow(true);
|
||||
mp_obj_t * xItems, * yItems;
|
||||
assert(n_args >= 2);
|
||||
size_t length = extractArgumentsAndCheckEqualSize(args[0], args[1], &xItems, &yItems);
|
||||
@@ -345,7 +346,7 @@ mp_obj_t modpyplot_scatter(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
mp_obj_t modpyplot_plot(size_t n_args, const mp_obj_t *args) {
|
||||
assert(sPlotStore != nullptr);
|
||||
|
||||
sPlotStore->setShow(true);
|
||||
mp_obj_t * xItems, * yItems;
|
||||
size_t length;
|
||||
if (n_args == 1) {
|
||||
@@ -371,7 +372,7 @@ mp_obj_t modpyplot_plot(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
mp_obj_t modpyplot_text(mp_obj_t x, mp_obj_t y, mp_obj_t s) {
|
||||
assert(sPlotStore != nullptr);
|
||||
|
||||
sPlotStore->setShow(true);
|
||||
// Input parameter validation
|
||||
mp_obj_get_float(x);
|
||||
mp_obj_get_float(y);
|
||||
@@ -383,10 +384,11 @@ mp_obj_t modpyplot_text(mp_obj_t x, mp_obj_t y, mp_obj_t s) {
|
||||
}
|
||||
|
||||
mp_obj_t modpyplot_show() {
|
||||
if (sPlotStore->isEmpty()) {
|
||||
if (!sPlotStore->show()) {
|
||||
return mp_const_none;
|
||||
}
|
||||
MicroPython::ExecutionEnvironment * env = MicroPython::ExecutionEnvironment::currentExecutionEnvironment();
|
||||
env->displayViewController(sPlotController);
|
||||
sPlotStore->setShow(false);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ namespace Matplotlib {
|
||||
PlotStore::PlotStore() : Shared::InteractiveCurveViewRange(),
|
||||
m_axesRequested(true),
|
||||
m_axesAuto(true),
|
||||
m_gridRequested(false)
|
||||
m_gridRequested(false),
|
||||
m_show(false)
|
||||
{
|
||||
flush();
|
||||
}
|
||||
@@ -21,10 +22,6 @@ void PlotStore::flush() {
|
||||
m_gridRequested = false;
|
||||
}
|
||||
|
||||
bool PlotStore::isEmpty() {
|
||||
return MP_OBJ_SMALL_INT_VALUE(mp_obj_len(m_dots)) == 0 && MP_OBJ_SMALL_INT_VALUE(mp_obj_len(m_segments)) == 0 && MP_OBJ_SMALL_INT_VALUE(mp_obj_len(m_rects)) == 0 && MP_OBJ_SMALL_INT_VALUE(mp_obj_len(m_labels)) == 0;
|
||||
}
|
||||
|
||||
// Iterators
|
||||
|
||||
template <class T>
|
||||
|
||||
@@ -13,7 +13,6 @@ class PlotStore : public Shared::InteractiveCurveViewRange {
|
||||
public:
|
||||
PlotStore();
|
||||
void flush();
|
||||
bool isEmpty();
|
||||
|
||||
// Iterators
|
||||
|
||||
@@ -123,6 +122,8 @@ public:
|
||||
void setAxesRequested(bool b) { m_axesRequested = b; }
|
||||
bool axesRequested() const { return m_axesRequested; }
|
||||
void setAxesAuto(bool b) { m_axesAuto = b; }
|
||||
void setShow(bool b) { m_show = b; }
|
||||
bool show() { return m_show; }
|
||||
void initRange();
|
||||
|
||||
void setGridRequested(bool b) { m_gridRequested = b; }
|
||||
@@ -135,6 +136,7 @@ private:
|
||||
bool m_axesRequested;
|
||||
bool m_axesAuto;
|
||||
bool m_gridRequested;
|
||||
bool m_show;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user