charts.c

Go to the documentation of this file.
00001 
00041 #include "charts.h"
00042 #include <gfx/gfx.h>
00043 
00044 
00045 #ifndef CONFIG_CHART_ARROWS
00046 #define CONFIG_CHART_ARROWS 0
00047 #endif
00048 
00049 
00050 void chart_init(Bitmap *bm, coord_t xmin, coord_t ymin, coord_t xmax, coord_t ymax)
00051 {
00052     /* Clear the chart area */
00053     gfx_rectClear(bm, xmin, ymin, xmax, ymax);
00054 
00055     gfx_setClipRect(bm, xmin + CHART_BORDERLEFT, ymin + CHART_BORDERTOP,
00056         xmax - CHART_BORDERRIGHT, ymax - CHART_BORDERBOTTOM);
00057 
00058     chart_drawAxis(bm);
00059 }
00060 
00061 
00062 void chart_setScale(Bitmap *bm, chart_x_t xmin, chart_y_t ymin, chart_x_t xmax, chart_y_t ymax)
00063 {
00064     gfx_setViewRect(bm, xmin, ymin, xmax, ymax);
00065 }
00066 
00067 
00071 void chart_drawAxis(Bitmap *bm)
00072 {
00073 #if CONFIG_CHART_ARROWS
00074 
00075     /* Draw axis */
00076     gfx_moveTo(bm, bm->cr.xmin, bm->cr.ymin + 4);
00077     gfx_lineTo(bm, bm->cr.xmin, bm->cr.ymax - 1);
00078     gfx_lineTo(bm, bm->cr.xmax - 4 - 1, bm->cr.ymax - 1);
00079 
00080     /* Draw up arrow */
00081     gfx_moveTo(bm, bm->cr.xmin - 2, bm->cr.ymin + 3);
00082     gfx_lineTo(bm, bm->cr.xmin + 2, bm->cr.ymin + 3);
00083     gfx_lineTo(bm, bm->cr.xmin, bm->cr.ymin);
00084     gfx_lineTo(bm, bm->cr.xmin - 2, bm->cr.ymin + 3);
00085 
00086     /* Draw right arrow */
00087     gfx_moveTo(bm, bm->cr.xmax - 4, bm->cr.ymax - 3);
00088     gfx_lineTo(bm, bm->cr.xmax - 4, bm->cr.ymax + 1);
00089     gfx_lineTo(bm, bm->cr.xmax - 1, bm->cr.ymax - 1);
00090     gfx_lineTo(bm, bm->cr.xmax - 4, bm->cr.ymax - 3);
00091 
00092 #else /* CONFIG_CHART_ARROWS */
00093 
00094     /* Draw a box around the chart */
00095     gfx_rectDraw(bm, bm->cr.xmin, bm->cr.ymin, bm->cr.xmax, bm->cr.ymax);
00096 
00097 #endif /* CONFIG_CHART_ARROWS */
00098 
00099     //CHECK_WALL(wall_before_raster, WALL_SIZE);
00100     //CHECK_WALL(wall_after_raster, WALL_SIZE);
00101 }
00102 
00103 
00109 void chart_drawCurve(Bitmap *bm, const chart_y_t *curve_y, int curve_cnt)
00110 {
00111     int i;
00112 
00113     gfx_moveTo(bm, gfx_transformX(bm, 0), gfx_transformY(bm, curve_y[0]));
00114 
00115     for (i = 1; i < curve_cnt; i++)
00116         gfx_lineTo(bm, gfx_transformX(bm, i), gfx_transformY(bm, curve_y[i]));
00117 
00118     //CHECK_WALL(wall_before_raster, WALL_SIZE);
00119     //CHECK_WALL(wall_after_raster, WALL_SIZE);
00120 }
00121 
00122 
00127 void chart_drawDots(Bitmap *bm, const chart_x_t *dots_x, const chart_y_t *dots_y, int cnt)
00128 {
00129     int i;
00130     coord_t x, y;
00131 
00132     for (i = 0; i < cnt; i++)
00133     {
00134         if (dots_x)
00135             x = gfx_transformX(bm, dots_x[i]);
00136         else
00137             x = gfx_transformX(bm, i);
00138 
00139         y = gfx_transformY(bm, dots_y[i]);
00140 
00141         /* Draw tick over the curve */
00142         gfx_rectFill(bm,
00143             x - TICKS_WIDTH / 2, y - TICKS_HEIGHT / 2,
00144             x + (TICKS_WIDTH + 1) / 2, y + (TICKS_HEIGHT + 1) / 2);
00145 
00146         /* Draw vertical line from the curve to the X-axis */
00147         //gfx_drawLine(bm, x, y, x, bm->cr.ymax - 1);
00148     }
00149 
00150     //CHECK_WALL(wall_before_raster, WALL_SIZE);
00151     //CHECK_WALL(wall_after_raster, WALL_SIZE);
00152 }
00153