diff --git a/python/port/mod/matplotlib/modpyplot.cpp b/python/port/mod/matplotlib/modpyplot.cpp index cb572ad08..fb72bd5ca 100644 --- a/python/port/mod/matplotlib/modpyplot.cpp +++ b/python/port/mod/matplotlib/modpyplot.cpp @@ -61,6 +61,12 @@ mp_obj_t modpyplot_axis(mp_obj_t arg) { return mp_obj_new_tuple(4, coords); } +mp_obj_t modpyplot_bar(mp_obj_t x, mp_obj_t height) { + assert(sPlotStore != nullptr); + + +} + mp_obj_t modpyplot_grid(mp_obj_t b) { if (mp_obj_is_type(b, &mp_type_bool)) { sPlotStore->setGridRequested(mp_obj_is_true(b)); diff --git a/python/port/mod/matplotlib/modpyplot.h b/python/port/mod/matplotlib/modpyplot.h index 9652a637a..777ba7684 100644 --- a/python/port/mod/matplotlib/modpyplot.h +++ b/python/port/mod/matplotlib/modpyplot.h @@ -4,6 +4,7 @@ mp_obj_t modpyplot___init__(); void modpyplot_gc_collect(); mp_obj_t modpyplot_axis(mp_obj_t arg); +mp_obj_t modpyplot_bar(mp_obj_t x, mp_obj_t height); mp_obj_t modpyplot_grid(mp_obj_t b); mp_obj_t modpyplot_plot(mp_obj_t x, mp_obj_t y); mp_obj_t modpyplot_scatter(mp_obj_t x, mp_obj_t y); diff --git a/python/port/mod/matplotlib/plot_store.h b/python/port/mod/matplotlib/plot_store.h index 8d16840f1..96e6511f9 100644 --- a/python/port/mod/matplotlib/plot_store.h +++ b/python/port/mod/matplotlib/plot_store.h @@ -79,6 +79,27 @@ public: void addSegment(mp_obj_t xStart, mp_obj_t yStart, mp_obj_t xEnd, mp_obj_t yEnd, KDColor c); Iterable> segments() { return Iterable>(m_segments); } + // Rect + + class Rect { + public: + Rect(mp_obj_t tuple); + float x() const { return m_x; } + float y() const { return m_y; } + float width() const { return m_width; } + float height() const { return m_height; } + KDColor color() const { return m_color; } + private: + float m_x; + float m_y; + float m_width; + float m_height; + KDColor m_color; + }; + + void addRect(mp_obj_t x, mp_obj_t y, mp_obj_t width, mp_obj_t height, KDColor c); + Iterable> rects() { return Iterable>(m_segments); } + // Label class Label { diff --git a/python/port/mod/matplotlib/plot_view.cpp b/python/port/mod/matplotlib/plot_view.cpp index 96aa2465f..3e7ae4f0c 100644 --- a/python/port/mod/matplotlib/plot_view.cpp +++ b/python/port/mod/matplotlib/plot_view.cpp @@ -16,26 +16,49 @@ void PlotView::drawRect(KDContext * ctx, KDRect rect) const { } for (PlotStore::Dot dot : m_store->dots()) { - drawDot(ctx, rect, dot.x(), dot.y(), dot.color()); + traceDot(ctx, rect, dot); } for (PlotStore::Label label : m_store->labels()) { - drawLabel(ctx, rect, - label.x(), label.y(), label.string(), - KDColorBlack, - CurveView::RelativePosition::Before, - CurveView::RelativePosition::None - ); + traceLabel(ctx, rect, label); } for (PlotStore::Segment segment : m_store->segments()) { - drawSegment2( - ctx, rect, - segment.xStart(), segment.yStart(), - segment.xEnd(), segment.yEnd(), - segment.color() - ); + traceSegment(ctx, rect, segment); } } +void PlotView::traceDot(KDContext * ctx, KDRect r, PlotStore::Dot dot) const { + drawDot(ctx, r, dot.x(), dot.y(), dot.color()); +} + +void PlotView::traceSegment(KDContext * ctx, KDRect r, PlotStore::Segment segment) const { + drawSegment2( + ctx, r, + segment.xStart(), segment.yStart(), + segment.xEnd(), segment.yEnd(), + segment.color() + ); +} + +void PlotView::traceRect(KDContext * ctx, KDRect r, PlotStore::Rect rect) const { + KDRect pixelRect( + floatToPixel(Axis::Horizontal, rect.x()), + floatToPixel(Axis::Vertical, rect.y()), + rect.width() / pixelWidth(), + rect.height() / pixelHeight() + ); + ctx->fillRect(pixelRect, rect.color()); +} + +void PlotView::traceLabel(KDContext * ctx, KDRect r, PlotStore::Label label) const { + drawLabel(ctx, r, + label.x(), label.y(), label.string(), + KDColorBlack, + RelativePosition::Before, + RelativePosition::None + ); +} + + } diff --git a/python/port/mod/matplotlib/plot_view.h b/python/port/mod/matplotlib/plot_view.h index 5e01f8ed1..4a804c957 100644 --- a/python/port/mod/matplotlib/plot_view.h +++ b/python/port/mod/matplotlib/plot_view.h @@ -11,6 +11,10 @@ public: PlotView(PlotStore * s) : Shared::LabeledCurveView(s), m_store(s) {} void drawRect(KDContext * ctx, KDRect rect) const override; private: + void traceDot(KDContext * ctx, KDRect r, PlotStore::Dot dot) const; + void traceSegment(KDContext * ctx, KDRect r, PlotStore::Segment segment) const; + void traceRect(KDContext * ctx, KDRect r, PlotStore::Rect rect) const; + void traceLabel(KDContext * ctx, KDRect r, PlotStore::Label label) const; PlotStore * m_store; };