4 * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 1999, 2000, 2001, 2003 Bernardo Innocenti <bernie@develer.com>
6 * This file is part of DevLib - See devlib/README for information.
9 * \brief Simple charts on top of mware/gfx routines (implementation).
14 * bm = chart_init(0, ymax, N_POINTS_CURVE, ymin);
16 * chart_drawCurve(bm, curve_y, curve_points + 1);
17 * gfx_setViewRect(bm, xmin, ymax, xmax, ymin);
18 * chart_drawDots(bm, samples_x, samples_y, samples_cnt);
24 * \author Bernardo Innocenti <bernie@develer.com>
29 * Revision 1.3 2004/08/11 19:39:12 bernie
30 * Use chart_x_t and chart_y_t for the input dataset.
32 * Revision 1.1 2004/08/04 03:16:30 bernie
33 * Import simple chart drawing code.
38 #include <mware/gfx.h>
41 void chart_init(Bitmap *bm, vcoord_t xmin, vcoord_t ymin, vcoord_t xmax, vcoord_t ymax)
46 gfx_SetClipRect(bm, CHART_BORDERLEFT, CHART_BORDERTOP,
47 bm->width - CHART_BORDERRIGHT - 1, bm->height - CHART_BORDERBOTTOM - 1);
49 gfx_SetViewRect(bm, xmin, ymin, xmax, ymax);
51 //CHECK_WALL(wall_before_raster, WALL_SIZE);
52 //CHECK_WALL(wall_after_raster, WALL_SIZE);
59 void chart_drawAxis(Bitmap *bm)
62 gfx_MoveTo(bm, CHART_BORDERLEFT, 4);
63 gfx_LineTo(bm, CHART_BORDERLEFT, CHART_BORDERTOP + CHART_HEIGHT - 1);
64 gfx_LineTo(bm, CHART_BORDERLEFT + CHART_WIDTH - 5, CHART_BORDERTOP + CHART_HEIGHT - 1);
67 gfx_MoveTo(bm, CHART_BORDERLEFT - 2, 3);
68 gfx_LineTo(bm, CHART_BORDERLEFT + 2, 3);
69 gfx_LineTo(bm, CHART_BORDERLEFT, 0);
70 gfx_LineTo(bm, CHART_BORDERLEFT - 2, 3);
72 /* Draw right arrow */
73 gfx_MoveTo(bm, CHART_BORDERLEFT + CHART_WIDTH - 4, CHART_BORDERTOP + CHART_HEIGHT - 3);
74 gfx_LineTo(bm, CHART_BORDERLEFT + CHART_WIDTH - 4, CHART_BORDERTOP + CHART_HEIGHT + 1);
75 gfx_LineTo(bm, CHART_BORDERLEFT + CHART_WIDTH - 1, CHART_BORDERTOP + CHART_HEIGHT - 1);
76 gfx_LineTo(bm, CHART_BORDERLEFT + CHART_WIDTH - 4, CHART_BORDERTOP + CHART_HEIGHT - 3);
78 //CHECK_WALL(wall_before_raster, WALL_SIZE);
79 //CHECK_WALL(wall_after_raster, WALL_SIZE);
84 * Draw a set of \a curve_cnt connected segments, whose Y coordinates
85 * are identified by the \a curve_y array and X-coordinates are
86 * are evenly spaced by one virtual unit.
88 void chart_drawCurve(Bitmap *bm, const chart_y_t *curve_y, int curve_cnt)
92 gfx_MoveTo(bm, gfx_TransformX(bm, 0), gfx_TransformY(bm, curve_y[0]));
94 for (i = 1; i < curve_cnt; i++)
95 gfx_LineTo(bm, gfx_TransformX(bm, i), gfx_TransformY(bm, curve_y[i]));
97 //CHECK_WALL(wall_before_raster, WALL_SIZE);
98 //CHECK_WALL(wall_after_raster, WALL_SIZE);
103 * Disegna dei dot in corrispondenza delle coppie (dotsx[i];dotsy[i])
104 * Se dotsx e' NULL, i punti vengono disegnati ad intervalli regolari.
106 void chart_drawDots(Bitmap *bm, const chart_x_t *dots_x, const chart_y_t *dots_y, int cnt)
111 for (i = 0; i < cnt; i++)
114 x = gfx_TransformX(bm, dots_x[i]);
116 x = gfx_TransformX(bm, i);
118 y = gfx_TransformY(bm, dots_y[i]);
120 gfx_DrawRect(bm, x - 1, y - 1, x + 1, y + 1);
122 /* Disegna ticks sull'asse X */
123 gfx_DrawLine(bm, x, bm->height - 1, x, CHART_HEIGHT - 1);
126 //CHECK_WALL(wall_before_raster, WALL_SIZE);
127 //CHECK_WALL(wall_after_raster, WALL_SIZE);