diff --git a/src/lib/aqdiagram/0BUILD b/src/lib/aqdiagram/0BUILD index 04ba4b8..b96f728 100644 --- a/src/lib/aqdiagram/0BUILD +++ b/src/lib/aqdiagram/0BUILD @@ -65,6 +65,7 @@ $(gwenhywfar_libs) $(cairo_libs) $(zlib_libs) + -lm diff --git a/src/lib/aqdiagram/graph/0BUILD b/src/lib/aqdiagram/graph/0BUILD index 569a50b..b619857 100644 --- a/src/lib/aqdiagram/graph/0BUILD +++ b/src/lib/aqdiagram/graph/0BUILD @@ -97,7 +97,6 @@ $(local/typefiles) graph.c - g_setup.c w_graph.c w_xaxis.c w_yaxis.c diff --git a/src/lib/aqdiagram/graph/axis.t2d b/src/lib/aqdiagram/graph/axis.t2d index 39dc1b4..0d9cf05 100644 --- a/src/lib/aqdiagram/graph/axis.t2d +++ b/src/lib/aqdiagram/graph/axis.t2d @@ -19,6 +19,8 @@
aqdiagram/aqdg_api.h
aqdiagram/graph/tick.h
+
gwenhywfar/buffer.h
+
math.h
@@ -45,6 +47,89 @@ } \n + + + + + $(api) void $(struct_prefix)_GenLog10Ticks($(struct_type) *st); + + + + + + void $(struct_prefix)_GenLog10Ticks($(struct_type) *st) \n + { \n + double absMaxValue; \n + double v; \n + double vRun; \n + double startValue; \n + GWEN_BUFFER *dbuf; \n + \n + absMaxValue=abs(st->minValue); \n + v=abs(st->maxValue); \n + absMaxValue=(v>absMaxValue)?v:absMaxValue; \n + \n + dbuf=GWEN_Buffer_new(0, 64, 0, 1); \n + v=pow(10, floor(log10(absMaxValue))); \n + \n + startValue=v*10.0; \n + if ((st->minValue)<startValue) \n + startValue=-startValue; \n + \n + /* add ticks for next higher log10 (e.g. "1000.0" for maxValue="365") */ \n + vRun=startValue; \n + while(vRun<=(st->maxValue)) { \n + if (vRun>=(st->minValue)) { \n + if (!$(struct_prefix)_HasTickValue(st, vRun)) { \n + GWEN_Buffer_AppendArgs(dbuf, "%.*f", st->precision, vRun); \n + $(struct_prefix)_AddNewTick(st, GWEN_Buffer_GetStart(dbuf), vRun, 0, 0); \n + GWEN_Buffer_Reset(dbuf); \n + } \n + } \n + vRun+=v; \n + } \n + \n + vRun=startValue; \n + v/=10.0; \n + while(vRun<=(st->maxValue)) { \n + if (vRun>=(st->minValue)) { \n + if (!$(struct_prefix)_HasTickValue(st, vRun)) { \n + GWEN_Buffer_AppendArgs(dbuf, "%.*f", st->precision, vRun); \n + $(struct_prefix)_AddNewTick(st, GWEN_Buffer_GetStart(dbuf), vRun, 1, 0); \n + GWEN_Buffer_Reset(dbuf); \n + } \n + } \n + vRun+=v; \n + } \n + GWEN_Buffer_free(dbuf); \n + } \n + + + + + + + $(api) int $(struct_prefix)_HasTickValue(const $(struct_type) *st, double v); + + + + + + int $(struct_prefix)_HasTickValue(const $(struct_type) *st, double v) \n + { \n + const AQDG_GRAPH_TICK *tick; \n + \n + tick=AQDG_Graph_Tick_List_First(st->tickList); \n + while(tick) { \n + if (AQDG_Graph_Tick_GetValue(tick)==v) \n + return 1; \n + tick=AQDG_Graph_Tick_List_Next(tick); \n + } \n + return 0; \n + } \n + + + diff --git a/src/lib/aqdiagram/graph/graph.h b/src/lib/aqdiagram/graph/graph.h index e543176..befe11e 100644 --- a/src/lib/aqdiagram/graph/graph.h +++ b/src/lib/aqdiagram/graph/graph.h @@ -47,25 +47,25 @@ typedef struct AQDG_GRAPH AQDG_GRAPH; -AQDG_GRAPH *AQDG_Graph_new(void); -void AQDG_Graph_free(AQDG_GRAPH *g); +AQDG_API AQDG_GRAPH *AQDG_Graph_new(void); +AQDG_API void AQDG_Graph_free(AQDG_GRAPH *g); -const char *AQDG_Graph_GetTitle(const AQDG_GRAPH *g); -void AQDG_Graph_SetTitle(AQDG_GRAPH *g, const char *s); +AQDG_API const char *AQDG_Graph_GetTitle(const AQDG_GRAPH *g); +AQDG_API void AQDG_Graph_SetTitle(AQDG_GRAPH *g, const char *s); -const char *AQDG_Graph_GetSubTitle(const AQDG_GRAPH *g); -void AQDG_Graph_SetSubTitle(AQDG_GRAPH *g, const char *s); +AQDG_API const char *AQDG_Graph_GetSubTitle(const AQDG_GRAPH *g); +AQDG_API void AQDG_Graph_SetSubTitle(AQDG_GRAPH *g, const char *s); -AQDG_GRAPH_AXIS *AQDG_Graph_GetAxisByIndex(const AQDG_GRAPH *g, int idx); -int AQDG_Graph_SetAxis(AQDG_GRAPH *g, int idx, AQDG_GRAPH_AXIS *ax); +AQDG_API AQDG_GRAPH_AXIS *AQDG_Graph_GetAxisByIndex(const AQDG_GRAPH *g, int idx); +AQDG_API int AQDG_Graph_SetAxis(AQDG_GRAPH *g, int idx, AQDG_GRAPH_AXIS *ax); -AQDG_GRAPH_SUBGRAPH_LIST *AQDG_Graph_GetSubGraphList(const AQDG_GRAPH *g); -void AQDG_Graph_AddSubGraph(AQDG_GRAPH *g, AQDG_GRAPH_SUBGRAPH *sg); +AQDG_API AQDG_GRAPH_SUBGRAPH_LIST *AQDG_Graph_GetSubGraphList(const AQDG_GRAPH *g); +AQDG_API void AQDG_Graph_AddSubGraph(AQDG_GRAPH *g, AQDG_GRAPH_SUBGRAPH *sg); -AQDG_DRAW_CONTEXT *AQDG_Graph_GetDrawContext(const AQDG_GRAPH *g); -void AQDG_Graph_SetDrawContext(AQDG_GRAPH *g, AQDG_DRAW_CONTEXT *dc); +AQDG_API AQDG_DRAW_CONTEXT *AQDG_Graph_GetDrawContext(const AQDG_GRAPH *g); +AQDG_API void AQDG_Graph_SetDrawContext(AQDG_GRAPH *g, AQDG_DRAW_CONTEXT *dc); #endif diff --git a/src/lib/aqdiagram/graph/w_graph.h b/src/lib/aqdiagram/graph/w_graph.h index 8ff089b..7cb34a2 100644 --- a/src/lib/aqdiagram/graph/w_graph.h +++ b/src/lib/aqdiagram/graph/w_graph.h @@ -81,21 +81,21 @@ enum { -AQDG_OBJECT *AQDG_GraphWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_DRAW_CONTEXT *drawContext, AQDG_GRAPH *graph); +AQDG_API AQDG_OBJECT *AQDG_GraphWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_DRAW_CONTEXT *drawContext, AQDG_GRAPH *graph); -AQDG_GRAPH *AQDG_GraphWidget_GetGraph(const AQDG_OBJECT *o); +AQDG_API AQDG_GRAPH *AQDG_GraphWidget_GetGraph(const AQDG_OBJECT *o); -int AQDG_GraphWidget_GetPen(const AQDG_OBJECT *o, int idx); -void AQDG_GraphWidget_SetPen(AQDG_OBJECT *o, int idx, int penId); +AQDG_API int AQDG_GraphWidget_GetPen(const AQDG_OBJECT *o, int idx); +AQDG_API void AQDG_GraphWidget_SetPen(AQDG_OBJECT *o, int idx, int penId); -int AQDG_GraphWidget_GetFont(const AQDG_OBJECT *o, int idx); -void AQDG_GraphWidget_SetFont(AQDG_OBJECT *o, int idx, int fontId); +AQDG_API int AQDG_GraphWidget_GetFont(const AQDG_OBJECT *o, int idx); +AQDG_API void AQDG_GraphWidget_SetFont(AQDG_OBJECT *o, int idx, int fontId); -int AQDG_GraphWidget_CreatePenFromDb(AQDG_OBJECT *o, GWEN_DB_NODE *db, const char *name, uint32_t defColor, int defWidth, int defDash); -int AQDG_GraphWidget_CreateFontFromDb(AQDG_OBJECT *o, GWEN_DB_NODE *db, const char *name, int defaultFontSize); -uint32_t AQDG_GraphWidget_GetStandardCurveColor(int idx, uint32_t defCol); +AQDG_API int AQDG_GraphWidget_CreatePenFromDb(AQDG_OBJECT *o, GWEN_DB_NODE *db, const char *name, uint32_t defColor, int defWidth, int defDash); +AQDG_API int AQDG_GraphWidget_CreateFontFromDb(AQDG_OBJECT *o, GWEN_DB_NODE *db, const char *name, int defaultFontSize); +AQDG_API uint32_t AQDG_GraphWidget_GetStandardCurveColor(int idx, uint32_t defCol); #endif diff --git a/src/lib/aqdiagram/graph/w_viewport.h b/src/lib/aqdiagram/graph/w_viewport.h index d935c62..53ad39e 100644 --- a/src/lib/aqdiagram/graph/w_viewport.h +++ b/src/lib/aqdiagram/graph/w_viewport.h @@ -12,7 +12,7 @@ #include -AQDG_OBJECT *AQDG_ViewportWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_OBJECT *graphObject); +AQDG_API AQDG_OBJECT *AQDG_ViewportWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_OBJECT *graphObject); diff --git a/src/lib/aqdiagram/graph/w_xaxis.h b/src/lib/aqdiagram/graph/w_xaxis.h index 22b7958..6c4fea8 100644 --- a/src/lib/aqdiagram/graph/w_xaxis.h +++ b/src/lib/aqdiagram/graph/w_xaxis.h @@ -12,7 +12,7 @@ #include -AQDG_OBJECT *AQDG_XAxisWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_OBJECT *graphObject, int axisIndex); +AQDG_API AQDG_OBJECT *AQDG_XAxisWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_OBJECT *graphObject, int axisIndex); diff --git a/src/lib/aqdiagram/graph/w_yaxis.h b/src/lib/aqdiagram/graph/w_yaxis.h index b5d6210..04c55a1 100644 --- a/src/lib/aqdiagram/graph/w_yaxis.h +++ b/src/lib/aqdiagram/graph/w_yaxis.h @@ -12,7 +12,7 @@ #include -AQDG_OBJECT *AQDG_YAxisWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_OBJECT *graphObject, int axisIndex); +AQDG_API AQDG_OBJECT *AQDG_YAxisWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_OBJECT *graphObject, int axisIndex); diff --git a/src/lib/aqdiagram/libtest.c b/src/lib/aqdiagram/libtest.c index 165190b..380663e 100644 --- a/src/lib/aqdiagram/libtest.c +++ b/src/lib/aqdiagram/libtest.c @@ -17,6 +17,9 @@ #include #include #include +#include +#include +#include #include #include @@ -33,6 +36,10 @@ +static void _dumpTicks(const AQDG_GRAPH_TICK_LIST *tickList); + + + int test1(int argc, char **argv) { AQDG_DRAW_CONTEXT *dc; @@ -115,6 +122,67 @@ int test1(int argc, char **argv) +int test2(int argc, char **argv) +{ + AQDG_GRAPH *g; + AQDG_GRAPH_AXIS *xAxis; + AQDG_GRAPH_AXIS *yAxis; + + g=AQDG_Graph_new(); + AQDG_Graph_SetTitle(g, "Test Graph"); + AQDG_Graph_SetSubTitle(g, "Test Data"); + + xAxis=AQDG_Graph_Axis_new(); + AQDG_Graph_Axis_SetLabel(xAxis, "Label X"); + AQDG_Graph_Axis_SetMinValue(xAxis, -5.0); + AQDG_Graph_Axis_SetMaxValue(xAxis, 117.0); + AQDG_Graph_Axis_SetPrecision(xAxis, 0); + AQDG_Graph_SetAxis(g, AQDG_GRAPH_AXISPOS_BOTTOM, xAxis); + fprintf(stderr, "Generating ticks for X-axis\n"); + AQDG_Graph_Axis_GenLog10Ticks(xAxis); + fprintf(stderr, "Ticks for X-Axis (%f - %f)\n", + AQDG_Graph_Axis_GetMinValue(xAxis), + AQDG_Graph_Axis_GetMaxValue(xAxis)); + _dumpTicks(AQDG_Graph_Axis_GetTickList(xAxis)); + + yAxis=AQDG_Graph_Axis_new(); + AQDG_Graph_Axis_SetLabel(yAxis, "Label Y"); + AQDG_Graph_Axis_SetMinValue(yAxis, -27.0); + AQDG_Graph_Axis_SetMaxValue(yAxis, 1235.0); + AQDG_Graph_Axis_SetPrecision(yAxis, 2); + fprintf(stderr, "Generating ticks for Y-axis\n"); + AQDG_Graph_Axis_GenLog10Ticks(yAxis); + fprintf(stderr, "Ticks for Y-Axis (%f - %f)\n", + AQDG_Graph_Axis_GetMinValue(yAxis), + AQDG_Graph_Axis_GetMaxValue(yAxis)); + _dumpTicks(AQDG_Graph_Axis_GetTickList(yAxis)); + + AQDG_Graph_SetAxis(g, AQDG_GRAPH_AXISPOS_LEFT, yAxis); + + return 0; +} + + + +void _dumpTicks(const AQDG_GRAPH_TICK_LIST *tickList) +{ + const AQDG_GRAPH_TICK *tick; + + fprintf(stderr, "Ticks:\n"); + tick=AQDG_Graph_Tick_List_First(tickList); + while(tick) { + fprintf(stderr, + "- %f (\"%s\") [%d]\n", + AQDG_Graph_Tick_GetValue(tick), + AQDG_Graph_Tick_GetLabel(tick), + AQDG_Graph_Tick_GetLevel(tick)); + tick=AQDG_Graph_Tick_List_Next(tick); + } +} + + + + int modTest(int argc, char **argv) { int rv; @@ -158,7 +226,8 @@ int main(int argc, char **argv) GWEN_Logger_SetLevel(AQDG_LOGDOMAIN, GWEN_LoggerLevel_Info); GWEN_Logger_SetLevel(NULL, GWEN_LoggerLevel_Info); - rv=test1(argc, argv); + /*rv=test1(argc, argv);*/ + rv=test2(argc, argv); if (rv!=0){ DBG_ERROR(NULL, "here (%d)", rv);