From 0e3684e137dcee0f64c0a29fe621b6e8281c75e4 Mon Sep 17 00:00:00 2001 From: Arthur Camouseigt Date: Mon, 25 May 2020 14:22:52 +0200 Subject: [PATCH] [matplotlib/modpyplot.cpp] Adding keyword arguments support for bar function bar function can now take into account the following keywords arguments : - color Change-Id: Iefa68cff59986d89c37cfecd7e3750f03c33ca59 --- python/port/mod/matplotlib/pyplot/modpyplot.cpp | 11 ++++++----- python/port/mod/matplotlib/pyplot/modpyplot.h | 2 +- python/port/mod/matplotlib/pyplot/modpyplot_table.c | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/python/port/mod/matplotlib/pyplot/modpyplot.cpp b/python/port/mod/matplotlib/pyplot/modpyplot.cpp index 7685611f0..805edce29 100644 --- a/python/port/mod/matplotlib/pyplot/modpyplot.cpp +++ b/python/port/mod/matplotlib/pyplot/modpyplot.cpp @@ -174,16 +174,14 @@ mp_obj_t modpyplot_axis(size_t n_args, const mp_obj_t *args) { return mp_obj_new_tuple(4, coords); } -/* bar(x, height, width, bottom, color) +/* bar(x, height, width, bottom, KW :color) * 'x', 'height', 'width' and 'bottom' can either be a scalar or an array/tuple of * scalar. * 'width' default value is 0.8 * 'bottom' default value is None * */ -// TODO: accept keyword args? - -mp_obj_t modpyplot_bar(size_t n_args, const mp_obj_t *args) { +mp_obj_t modpyplot_bar(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args) { assert(sPlotStore != nullptr); sPlotStore->setShow(true); mp_obj_t * xItems; @@ -215,7 +213,10 @@ mp_obj_t modpyplot_bar(size_t n_args, const mp_obj_t *args) { bItems[0] = mp_obj_new_float(0.0f); } - KDColor color = colorFromOptionalArgumentAtIndex(n_args, args, 4); + // Setting bar color + mp_map_elem_t * elem = mp_map_lookup(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_color), MP_MAP_LOOKUP); + KDColor color = colorFromKeywordArgument(elem); + for (size_t i=0; i 1 ? i : 0]; mp_obj_t iW = wItems[wLength > 1 ? i : 0]; diff --git a/python/port/mod/matplotlib/pyplot/modpyplot.h b/python/port/mod/matplotlib/pyplot/modpyplot.h index d28e8f4e1..6e5c2f466 100644 --- a/python/port/mod/matplotlib/pyplot/modpyplot.h +++ b/python/port/mod/matplotlib/pyplot/modpyplot.h @@ -6,7 +6,7 @@ void modpyplot_flush_used_heap(); mp_obj_t modpyplot_arrow(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args); 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); +mp_obj_t modpyplot_bar(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args); 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); mp_obj_t modpyplot_plot(size_t n_args, const mp_obj_t *args); diff --git a/python/port/mod/matplotlib/pyplot/modpyplot_table.c b/python/port/mod/matplotlib/pyplot/modpyplot_table.c index 3a398a05c..52dd41364 100644 --- a/python/port/mod/matplotlib/pyplot/modpyplot_table.c +++ b/python/port/mod/matplotlib/pyplot/modpyplot_table.c @@ -3,7 +3,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(modpyplot___init___obj, modpyplot___init__); STATIC MP_DEFINE_CONST_FUN_OBJ_KW(modpyplot_arrow_obj, 4, modpyplot_arrow); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_axis_obj, 0, 1, modpyplot_axis); -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_bar_obj, 2, 5, modpyplot_bar); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(modpyplot_bar_obj, 2, modpyplot_bar); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_grid_obj, 0, 1, modpyplot_grid); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_hist_obj, 1, 3, modpyplot_hist); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_plot_obj, 1, 3, modpyplot_plot);