Add grids to graph demo and update graph arrows

Add grid lines to graph demo.
Update graph arrows to allow seperate control of positive and negative
axis arrowheads.
This commit is contained in:
Andrew Hannam 2012-12-13 22:33:05 +10:00
parent d503f3a4ac
commit 311c0e7168
3 changed files with 21 additions and 10 deletions

View File

@ -18,9 +18,9 @@ GGraphStyle GraphStyle1 = {
{ GGRAPH_LINE_NONE, 2, Gray }, // line
{ GGRAPH_LINE_SOLID, 0, White }, // x axis
{ GGRAPH_LINE_SOLID, 0, White }, // y axis
{ GGRAPH_LINE_NONE, 0, White, 0 }, // x grid
{ GGRAPH_LINE_NONE, 0, White, 0 }, // y grid
GWIN_GRAPH_STYLE_XAXIS_ARROWS|GWIN_GRAPH_STYLE_YAXIS_ARROWS // flags
{ GGRAPH_LINE_DASH, 5, Gray, 50 }, // x grid
{ GGRAPH_LINE_DOT, 7, Yellow, 50 }, // y grid
GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS // flags
};
GGraphStyle GraphStyle2 = {
@ -28,9 +28,9 @@ GGraphStyle GraphStyle2 = {
{ GGRAPH_LINE_NONE, 2, Gray }, // line
{ GGRAPH_LINE_SOLID, 0, White }, // x axis
{ GGRAPH_LINE_SOLID, 0, White }, // y axis
{ GGRAPH_LINE_NONE, 0, White, 0 }, // x grid
{ GGRAPH_LINE_NONE, 0, White, 0 }, // y grid
GWIN_GRAPH_STYLE_XAXIS_ARROWS|GWIN_GRAPH_STYLE_YAXIS_ARROWS // flags
{ GGRAPH_LINE_DASH, 5, Gray, 50 }, // x grid
{ GGRAPH_LINE_DOT, 7, Yellow, 50 }, // y grid
GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS // flags
};
int main(void) {

View File

@ -80,8 +80,15 @@ typedef struct GGraphStyle_t {
GGraphGridStyle xgrid;
GGraphGridStyle ygrid;
uint16_t flags;
#define GWIN_GRAPH_STYLE_XAXIS_ARROWS 0x0001
#define GWIN_GRAPH_STYLE_YAXIS_ARROWS 0x0002
#define GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS 0x0001
#define GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS 0x0002
#define GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS 0x0004
#define GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS 0x0008
#define GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS)
#define GWIN_GRAPH_STYLE_NEGATIVE_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS)
#define GWIN_GRAPH_STYLE_XAXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS)
#define GWIN_GRAPH_STYLE_YAXIS_ARROWS (GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS)
#define GWIN_GRAPH_STYLE_ALL_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_ARROWS|GWIN_GRAPH_STYLE_YAXIS_ARROWS)
} GGraphStyle;
// A graph window

View File

@ -299,11 +299,13 @@ void gwinGraphDrawAxis(GHandle gh) {
// x axis
lineto(gg, xmin, 0, xmax, 0, &gg->style.xaxis);
if ((gg->style.flags & GWIN_GRAPH_STYLE_XAXIS_ARROWS)) {
if ((gg->style.flags & GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS)) {
if (xmin > 0 || xmin < -(GGRAPH_ARROW_SIZE+1)) {
lineto(gg, xmin, 0, xmin+GGRAPH_ARROW_SIZE, GGRAPH_ARROW_SIZE, &gg->style.xaxis);
lineto(gg, xmin, 0, xmin+GGRAPH_ARROW_SIZE, -GGRAPH_ARROW_SIZE, &gg->style.xaxis);
}
}
if ((gg->style.flags & GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS)) {
if (xmax < 0 || xmax > (GGRAPH_ARROW_SIZE+1)) {
lineto(gg, xmax, 0, xmax-GGRAPH_ARROW_SIZE, GGRAPH_ARROW_SIZE, &gg->style.xaxis);
lineto(gg, xmax, 0, xmax-GGRAPH_ARROW_SIZE, -GGRAPH_ARROW_SIZE, &gg->style.xaxis);
@ -312,11 +314,13 @@ void gwinGraphDrawAxis(GHandle gh) {
// y axis
lineto(gg, 0, ymin, 0, ymax, &gg->style.yaxis);
if ((gg->style.flags & GWIN_GRAPH_STYLE_YAXIS_ARROWS)) {
if ((gg->style.flags & GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS)) {
if (ymin > 0 || ymin < -(GGRAPH_ARROW_SIZE+1)) {
lineto(gg, 0, ymin, GGRAPH_ARROW_SIZE, ymin+GGRAPH_ARROW_SIZE, &gg->style.yaxis);
lineto(gg, 0, ymin, -GGRAPH_ARROW_SIZE, ymin+GGRAPH_ARROW_SIZE, &gg->style.yaxis);
}
}
if ((gg->style.flags & GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS)) {
if (ymax < 0 || ymax > (GGRAPH_ARROW_SIZE+1)) {
lineto(gg, 0, ymax, GGRAPH_ARROW_SIZE, ymax-GGRAPH_ARROW_SIZE, &gg->style.yaxis);
lineto(gg, 0, ymax, -GGRAPH_ARROW_SIZE, ymax-GGRAPH_ARROW_SIZE, &gg->style.yaxis);