charts.c

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