From 8e439807db13c213bdec2b3bd47c718e7118c9c0 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 16 Jun 2024 19:31:43 +0200 Subject: [PATCH] started working on new graph module. --- src/lib/aqdiagram/graph/0BUILD | 55 +- src/lib/aqdiagram/graph/Makefile.am | 131 ---- src/lib/aqdiagram/graph/axis.t2d | 123 ++++ src/lib/aqdiagram/graph/curve.t2d | 150 +++++ .../graph/{datapair.xml => datapair.t2d} | 2 +- src/lib/aqdiagram/graph/dataset.xml | 195 ------ src/lib/aqdiagram/graph/dataset_fns.c | 453 ------------- src/lib/aqdiagram/graph/dataset_fns.h | 65 -- src/lib/aqdiagram/graph/draw.c | 559 ---------------- src/lib/aqdiagram/graph/graph.c | 467 ++++++-------- src/lib/aqdiagram/graph/graph.h | 144 ++++- src/lib/aqdiagram/graph/graph_p.h | 97 +-- src/lib/aqdiagram/graph/layout.c | 310 --------- src/lib/aqdiagram/graph/o_graph.c | 414 ++++++++++++ src/lib/aqdiagram/graph/o_graph.h | 102 +++ src/lib/aqdiagram/graph/o_graph_p.h | 43 ++ src/lib/aqdiagram/graph/o_xaxis.c | 65 ++ src/lib/aqdiagram/graph/{draw.h => o_xaxis.h} | 12 +- .../aqdiagram/graph/{layout.h => o_xaxis_p.h} | 15 +- src/lib/aqdiagram/graph/settings.xml | 259 -------- src/lib/aqdiagram/graph/settings_font.xml | 79 --- src/lib/aqdiagram/graph/settings_pen.xml | 86 --- src/lib/aqdiagram/graph/setup.c | 516 --------------- src/lib/aqdiagram/graph/setup.h | 20 - src/lib/aqdiagram/graph/subgraph.t2d | 137 ++++ src/lib/aqdiagram/graph/subgraph.xml | 89 --- .../aqdiagram/graph/{tick.xml => tick.t2d} | 9 - src/lib/aqdiagram/graph/tick_fns.c | 607 ------------------ src/lib/aqdiagram/graph/tick_fns.h | 39 -- 29 files changed, 1400 insertions(+), 3843 deletions(-) delete mode 100644 src/lib/aqdiagram/graph/Makefile.am create mode 100644 src/lib/aqdiagram/graph/axis.t2d create mode 100644 src/lib/aqdiagram/graph/curve.t2d rename src/lib/aqdiagram/graph/{datapair.xml => datapair.t2d} (96%) delete mode 100644 src/lib/aqdiagram/graph/dataset.xml delete mode 100644 src/lib/aqdiagram/graph/dataset_fns.c delete mode 100644 src/lib/aqdiagram/graph/dataset_fns.h delete mode 100644 src/lib/aqdiagram/graph/draw.c delete mode 100644 src/lib/aqdiagram/graph/layout.c create mode 100644 src/lib/aqdiagram/graph/o_graph.c create mode 100644 src/lib/aqdiagram/graph/o_graph.h create mode 100644 src/lib/aqdiagram/graph/o_graph_p.h create mode 100644 src/lib/aqdiagram/graph/o_xaxis.c rename src/lib/aqdiagram/graph/{draw.h => o_xaxis.h} (57%) rename src/lib/aqdiagram/graph/{layout.h => o_xaxis_p.h} (55%) delete mode 100644 src/lib/aqdiagram/graph/settings.xml delete mode 100644 src/lib/aqdiagram/graph/settings_font.xml delete mode 100644 src/lib/aqdiagram/graph/settings_pen.xml delete mode 100644 src/lib/aqdiagram/graph/setup.c delete mode 100644 src/lib/aqdiagram/graph/setup.h create mode 100644 src/lib/aqdiagram/graph/subgraph.t2d delete mode 100644 src/lib/aqdiagram/graph/subgraph.xml rename src/lib/aqdiagram/graph/{tick.xml => tick.t2d} (77%) delete mode 100644 src/lib/aqdiagram/graph/tick_fns.c delete mode 100644 src/lib/aqdiagram/graph/tick_fns.h diff --git a/src/lib/aqdiagram/graph/0BUILD b/src/lib/aqdiagram/graph/0BUILD index bf62f1c..69cdeae 100644 --- a/src/lib/aqdiagram/graph/0BUILD +++ b/src/lib/aqdiagram/graph/0BUILD @@ -33,44 +33,36 @@ - datapair.xml - dataset.xml - tick.xml - subgraph.xml - settings_pen.xml - settings_font.xml - settings.xml + datapair.t2d + subgraph.t2d + tick.t2d + axis.t2d + curve.t2d datapair.c - dataset.c - tick.c subgraph.c - settings_pen.c - settings_font.c - settings.c + tick.c + axis.c + curve.c datapair.h - dataset.h - tick.h subgraph.h - settings_pen.h - settings_font.h - settings.h + tick.h + axis.h + curve.h datapair_p.h - dataset_p.h - tick_p.h subgraph_p.h - settings_pen_p.h - settings_font_p.h - settings_p.h + tick_p.h + axis_p.h + curve_p.h @@ -86,40 +78,29 @@ graph.h - draw.h - layout.h - setup.h + o_graph.h graph_p.h + o_graph_p.h $(local/typefiles) graph.c - draw.c - layout.c - setup.c + g_setup.c + o_graph.c - aqdg_graph_datapair.tm2 aqdg_graph_datapair_list.tm2 aqdg_graph_datapair_list2.tm2 - aqdg_graph_dataset.tm2 aqdg_graph_dataset_list.tm2 aqdg_graph_dataset_list2.tm2 - aqdg_graph_tick.tm2 aqdg_graph_tick_list.tm2 aqdg_graph_tick_list2.tm2 - aqdg_graph_subgraph.tm2 aqdg_graph_subgraph_list.tm2 aqdg_graph_subgraph_list2.tm2 - aqdg_graph_settings_pen.tm2 aqdg_graph_settings_pen_list.tm2 aqdg_graph_settings_pen_list2.tm2 - aqdg_graph_settings_font.tm2 aqdg_graph_settings_font_list.tm2 aqdg_graph_settings_font_list2.tm2 - aqdg_graph_settings.tm2 aqdg_graph_settings_list.tm2 aqdg_graph_settings_list2.tm2 - dataset_fns.c dataset_fns.h - tick_fns.c tick_fns.h diff --git a/src/lib/aqdiagram/graph/Makefile.am b/src/lib/aqdiagram/graph/Makefile.am deleted file mode 100644 index 8d0f2cf..0000000 --- a/src/lib/aqdiagram/graph/Makefile.am +++ /dev/null @@ -1,131 +0,0 @@ -AM_CPPFLAGS=$(gwenhywfar_includes) -I$(srcdir)/.. -I$(builddir)/.. -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib -AM_CFLAGS=$(visibility_cflags) - -DEFS+=\ - -DBUILDING_AQDIAGRAM \ - -DLOCALEDIR=\"@aqdiagram_locale_searchdir@\" \ - -DAQDIAGRAM_DATA_DIR=\"$(aqdiagram_data_searchdir)\" - -noinst_LTLIBRARIES=libaqdg_graph.la - - -typefiles=\ - datapair.xml \ - dataset.xml \ - tick.xml \ - subgraph.xml \ - settings_pen.xml \ - settings_font.xml \ - settings.xml - - - -# typedef files generated by typemaker2 -typedatadir=$(datadir)/aqfinance/typemaker2/c -dist_typedata_DATA=\ - aqdg_graph_datapair.tm2 aqdg_graph_datapair_list.tm2 aqdg_graph_datapair_list2.tm2 \ - aqdg_graph_dataset.tm2 aqdg_graph_dataset_list.tm2 aqdg_graph_dataset_list2.tm2 \ - aqdg_graph_tick.tm2 aqdg_graph_tick_list.tm2 aqdg_graph_tick_list2.tm2 \ - aqdg_graph_subgraph.tm2 aqdg_graph_subgraph_list.tm2 aqdg_graph_subgraph_list2.tm2 \ - aqdg_graph_settings_pen.tm2 aqdg_graph_settings_pen_list.tm2 aqdg_graph_settings_pen_list2.tm2 \ - aqdg_graph_settings_font.tm2 aqdg_graph_settings_font_list.tm2 aqdg_graph_settings_font_list2.tm2 \ - aqdg_graph_settings.tm2 aqdg_graph_settings_list.tm2 aqdg_graph_settings_list2.tm2 - - - -built_sources= \ - datapair.c \ - dataset.c \ - tick.c \ - subgraph.c \ - settings_pen.c \ - settings_font.c \ - settings.c - - -build_headers_priv= \ - datapair_p.h \ - dataset_p.h \ - tick_p.h \ - subgraph_p.h \ - settings_pen_p.h \ - settings_font_p.h \ - settings_p.h - - -build_headers_pub= \ - datapair.h \ - dataset.h \ - tick.h \ - subgraph.h \ - settings_pen.h \ - settings_font.h \ - settings.h - - - -build_headers=$(build_headers_priv) $(build_headers_pub) - -libaqdg_graph_la_SOURCES=$(built_sources) \ - graph.c - - -libaqdg_graph_la_LIBADD=$(CAIRO_LIBS) - - -iheaderdir=${includedir}/aqfinance/graphs -iheader_HEADERS=$(build_headers_pub) \ - graph.h - - -noinst_HEADERS=$(build_headers_priv) \ - graph_p.h - - -EXTRA_DIST=$(typefiles) \ - dataset_fns.dataset_fns.h \ - tick_fns.c tick_fns.h - - - - -build_sources: $(built_sources) - list='$(SUBDIRS)'; for d in $$list; do \ - $(MAKE) -C $$d build_sources; \ - done ; - -clean_build_files: - rm -f $(built_sources) $(build_headers) - -format_build_files: - for f in $(built_sources) $(build_headers); do \ - astyle -s2 --min-conditional-indent=0 --indent-labels --pad=oper -a --suffix=none $$f; \ - done - - -#%.c: %.xml -# typemaker2 -I $(top_srcdir)/src/lib/typemaker2/c -I $(srcdir) -I $(AQDATABASE_TYPEMAKERDIR)/c --destfolder="$(srcdir)" -D AE_API $< - -#%.h: %.xml -# typemaker2 -I $(top_srcdir)/src/lib/typemaker2/c -I $(srcdir) -I $(AQDATABASE_TYPEMAKERDIR)/c --destfolder="$(srcdir)" -D AE_API $< - - -#SUFFIXES = .xml .c - - -typefiles: $(typefiles) typedefs - $(typemaker2_exe) -I $(top_srcdir)/src/lib/typemaker2/c -I $(gwenhywfar_dir)/share/gwenhywfar/typemaker2/c -I $(srcdir) -I $(AQDATABASE_TYPEMAKERDIR)/c --destfolder="$(srcdir)" -D AQDG_API $(typefiles) - -typedefs: $(typefiles) - $(typemaker2_exe) --defs-only -I $(top_srcdir)/src/lib/typemaker2/c -I $(gwenhywfar_dir)/share/gwenhywfar/typemaker2/c -I $(srcdir) -I $(AQDATABASE_TYPEMAKERDIR)/c --destfolder="$(srcdir)" -D AQDG_API $(typefiles) - - -sources: - for f in $(libaqdg_graph_la_SOURCES) $(built_sources); do \ - echo $(subdir)/$$f >>$(top_srcdir)/i18nsources; \ - done - for d in $(SUBDIRS); do \ - $(MAKE) -C $$d sources; \ - done - - diff --git a/src/lib/aqdiagram/graph/axis.t2d b/src/lib/aqdiagram/graph/axis.t2d new file mode 100644 index 0000000..d417e70 --- /dev/null +++ b/src/lib/aqdiagram/graph/axis.t2d @@ -0,0 +1,123 @@ + + + + + + This class describes data axis. + + + AQDG_GRAPH_AXIS + AQDG_Graph_Axis + axis + + + with_db + with_xml + with_list1 + + + +
aqdiagram/aqdg_api.h
+
aqdiagram/graph/tick.h
+
+ +
+ + + + + + + + + + + + + + + NULL + NULL + public + own + const dup + const + + + + NULL + NULL + public + own + const dup + const + + + + 0 + 0 + public + + + + 0 + 0 + public + + + + 0 + 0 + public + + + + 0.0 + 0.0 + public + + + + 0.0 + 0.0 + public + + + + 0.0 + 0.0 + public + + + + 0.0 + 0.0 + public + + + + 0 + 0 + with_flags + public + + + + + NULL + AQDG_Graph_Tick_List_new() + public + own + nodup + none + + + + + + + +
+ +
+ diff --git a/src/lib/aqdiagram/graph/curve.t2d b/src/lib/aqdiagram/graph/curve.t2d new file mode 100644 index 0000000..2885058 --- /dev/null +++ b/src/lib/aqdiagram/graph/curve.t2d @@ -0,0 +1,150 @@ + + + + + + This class describes curve. + + + AQDG_GRAPH_CURVE + AQDG_Graph_Curve + curve + + + with_db + with_xml + with_list1 + + + +
aqdiagram/aqdg_api.h
+
aqdiagram/graph/datapair.h
+
+ + + + + + $(api) void $(struct_prefix)_CalcMinMaxValues($(struct_type) *st); + + + + + + void $(struct_prefix)_CalcMinMaxValues($(struct_type) *st) \n + { \n + if (st && st->dataPairs) { \n + double minX; \n + double maxX; \n + double maxY; \n + double minY; \n + int isFirst=1; \n + const AQDG_GRAPH_DATAPAIR *dp; \n + \n + dp=AQDG_Graph_DataPair_List_First(st->dataPairs); \n + while(dp) { \n + double tx; \n + double ty; \n + \n + tx=AQDG_Graph_DataPair_GetValueX(dp); \n + ty=AQDG_Graph_DataPair_GetValueY(dp); \n + \n + if (isFirst) { \n + minX=maxX=tx; \n + minY=maxY=ty; \n + isFirst=0; \n + } \n + else { \n + minX=(tx<minX)?tx:minX; \n + maxX=(tx>maxX)?tx:maxX; \n + minY=(ty<minY)?ty:minY; \n + maxY=(ty>maxY)?ty:maxY; \n + } \n + dp=AQDG_Graph_DataPair_List_Next(dp); \n + } \n + \n + st->minValueX=minX; \n + st->maxValueX=maxX; \n + st->minValueY=minY; \n + st->maxValueY=maxY; \n + } \n + } \n + + + + + + + +
+ + + + + 0 + 0 + public + + + + NULL + NULL + public + own + const dup + const + + + + 0 + 0 + public + + + + 0 + 0 + with_flags + public + + + + + 0.0 + 0.0 + public + + + + 0.0 + 0.0 + public + + + + 0.0 + 0.0 + public + + + + 0.0 + 0.0 + public + + + + NULL + AQDG_Graph_DataPair_List_new() + public + own + nodup + none + + + + +
+ +
+ diff --git a/src/lib/aqdiagram/graph/datapair.xml b/src/lib/aqdiagram/graph/datapair.t2d similarity index 96% rename from src/lib/aqdiagram/graph/datapair.xml rename to src/lib/aqdiagram/graph/datapair.t2d index 8b7f9fe..f589d82 100644 --- a/src/lib/aqdiagram/graph/datapair.xml +++ b/src/lib/aqdiagram/graph/datapair.t2d @@ -40,7 +40,7 @@ sortbymember - + 0 0 public diff --git a/src/lib/aqdiagram/graph/dataset.xml b/src/lib/aqdiagram/graph/dataset.xml deleted file mode 100644 index e869a4e..0000000 --- a/src/lib/aqdiagram/graph/dataset.xml +++ /dev/null @@ -1,195 +0,0 @@ - - - - - - - - AQDG_GRAPH_DATASET - AQDG_Graph_DataSet - dataset - - - with_db - with_xml - with_list1 - with_list2 - with_refcount - - - -
aqdiagram/aqdg_api.h
-
aqdiagram/graph/datapair.h
-
aqdiagram/graph/tick.h
-
aqdiagram/graph/subgraph.h
- -
dataset_fns.h
-
dataset_fns.c
-
- -
- - - - - - - integer type - - - - floating point type (double precision) - - - - date type - - - - - - - - - - - NULL - NULL - public - own - const dup - const - - - - NULL - NULL - public - own - const dup - const - - - - NULL - AQDG_Graph_DataPair_List_new() - public - own - nodup - none - - - - NULL - AQDG_Graph_SubGraph_List_new() - public - own - nodup - none - - - - - - 0 - 0 - public - - - - 0 - 0 - public - - - - 0.0 - 0.0 - public - - - - 0.0 - 0.0 - public - - - - NULL - NULL - public - own - const dup - const - - - - NULL - AQDG_Graph_Tick_List_new() - public - own - nodup - none - - - - - - - 0 - 0 - public - - - - 0 - 0 - public - - - - 0.0 - 0.0 - public - - - - 0.0 - 0.0 - public - - - - NULL - NULL - public - own - const dup - const - - - - NULL - AQDG_Graph_Tick_List_new() - public - own - nodup - none - - - - - - 0 - 0 - with_flags - public - - - - - -
- -
- diff --git a/src/lib/aqdiagram/graph/dataset_fns.c b/src/lib/aqdiagram/graph/dataset_fns.c deleted file mode 100644 index 5e93202..0000000 --- a/src/lib/aqdiagram/graph/dataset_fns.c +++ /dev/null @@ -1,453 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqDiagram. - * AqDiagram (c) by 2020 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - - - - -void AQDG_Graph_DataSet_AdjustXRange(AQDG_GRAPH_DATASET *ds) -{ - assert(ds); - if (ds->dataPairList) { - AQDG_GRAPH_DATAPAIR *dp; - - dp=AQDG_Graph_DataPair_List_First(ds->dataPairList); - if (dp) { - double minVal; - double maxVal; - - minVal=AQDG_Graph_DataPair_GetValueX(dp); - maxVal=minVal; - - dp=AQDG_Graph_DataPair_List_Next(dp); - while (dp) { - double v; - - v=AQDG_Graph_DataPair_GetValueX(dp); - if (vmaxVal) - maxVal=v; - - dp=AQDG_Graph_DataPair_List_Next(dp); - } - - ds->minValueX=minVal; - ds->maxValueX=maxVal; - } - } -} - - - -void AQDG_Graph_DataSet_AdjustYRange(AQDG_GRAPH_DATASET *ds) -{ - assert(ds); - if (ds->dataPairList) { - AQDG_GRAPH_DATAPAIR *dp; - - dp=AQDG_Graph_DataPair_List_First(ds->dataPairList); - if (dp) { - double minVal; - double maxVal; - - minVal=AQDG_Graph_DataPair_GetValueY(dp); - maxVal=minVal; - - dp=AQDG_Graph_DataPair_List_Next(dp); - while (dp) { - double v; - - v=AQDG_Graph_DataPair_GetValueY(dp); - if (vmaxVal) - maxVal=v; - - dp=AQDG_Graph_DataPair_List_Next(dp); - } - - ds->minValueY=minVal; - ds->maxValueY=maxVal; - } - } -} - - - - -void AQDG_Graph_DataSet_AddTicks(AQDG_GRAPH_DATASET *ds) -{ - if (ds->xTickList) - AQDG_Graph_Tick_AddTicks(ds->xTickList, ds->dataTypeX, ds->minValueX, ds->maxValueX, ds->precisionX); - if (ds->yTickList) - AQDG_Graph_Tick_AddTicks(ds->yTickList, ds->dataTypeY, ds->minValueY, ds->maxValueY, ds->precisionY); -} - - - -void AQDG_Graph_DataSet_AddSubGraph(AQDG_GRAPH_DATASET *ds, const char *label, - int level, int graphType, int dataMode, int colour, int lineWidth, int dashType) -{ - AQDG_GRAPH_SUBGRAPH *sg; - - if (ds->subGraphList==NULL) - ds->subGraphList=AQDG_Graph_SubGraph_List_new(); - - sg=AQDG_Graph_SubGraph_new(); - AQDG_Graph_SubGraph_SetLabel(sg, label); - AQDG_Graph_SubGraph_SetLevel(sg, level); - AQDG_Graph_SubGraph_SetGraphType(sg, graphType); - AQDG_Graph_SubGraph_SetColour(sg, colour); - AQDG_Graph_SubGraph_SetLineWidth(sg, lineWidth); - AQDG_Graph_SubGraph_SetDashType(sg, dashType); - - AQDG_Graph_SubGraph_List_Add(sg, ds->subGraphList); -} - - - -AQDG_GRAPH_SUBGRAPH *AQDG_Graph_DataSet_GetSubGraphByLevel(AQDG_GRAPH_DATASET *ds, int level) -{ - if (ds->subGraphList) - return AQDG_Graph_SubGraph_List_GetByLevel(ds->subGraphList, level); - - return NULL; -} - - - -void AQDG_Graph_DataSet_AddDataPair(AQDG_GRAPH_DATASET *ds, AQDG_GRAPH_DATAPAIR *dp) -{ - assert(ds); - if (ds->dataPairList==NULL) - ds->dataPairList=AQDG_Graph_DataPair_List_new(); - AQDG_Graph_DataPair_List_Add(dp, ds->dataPairList); -} - - - -void AQDG_Graph_DataSet_SortDataPairsByX(AQDG_GRAPH_DATASET *ds, int ascending) -{ - assert(ds); - if (ds->dataPairList) - AQDG_Graph_DataPair_List_SortByValueX(ds->dataPairList, ascending); -} - - - -void AQDG_Graph_DataSet_SortDataPairsByY(AQDG_GRAPH_DATASET *ds, int ascending) -{ - assert(ds); - if (ds->dataPairList) - AQDG_Graph_DataPair_List_SortByValueY(ds->dataPairList, ascending); -} - - - -void AQDG_Graph_DataSet_AccumulateDataPairs(AQDG_GRAPH_DATASET *ds, int level) -{ - assert(ds); - if (ds->dataPairList) { - AQDG_GRAPH_DATAPAIR *dp; - double totalSum=0.0; - - dp=AQDG_Graph_DataPair_List_First(ds->dataPairList); - while (dp) { - if (AQDG_Graph_DataPair_GetLevel(dp)==level) { - double v; - - v=AQDG_Graph_DataPair_GetValueY(dp); - totalSum+=v; - AQDG_Graph_DataPair_SetValueY(dp, totalSum); - } - dp=AQDG_Graph_DataPair_List_Next(dp); - } - } -} - - - -void AQDG_Graph_DataSet_AverageDataPairs(AQDG_GRAPH_DATASET *ds, int level) -{ - assert(ds); - if (ds->dataPairList) { - AQDG_GRAPH_DATAPAIR *dp; - double totalSum=0.0; - int cnt=0; - - dp=AQDG_Graph_DataPair_List_First(ds->dataPairList); - while (dp) { - if (AQDG_Graph_DataPair_GetLevel(dp)==level) { - double v; - - v=AQDG_Graph_DataPair_GetValueY(dp); - totalSum+=v; - cnt++; - } - - dp=AQDG_Graph_DataPair_List_Next(dp); - } - - if (cnt) { - double average; - - average=totalSum/((double)cnt); - dp=AQDG_Graph_DataPair_List_First(ds->dataPairList); - while (dp) { - if (AQDG_Graph_DataPair_GetLevel(dp)==level) { - AQDG_Graph_DataPair_SetValueY(dp, average); - } - dp=AQDG_Graph_DataPair_List_Next(dp); - } - } - } -} - - - -void AQDG_Graph_DataSet_FloatingAverageDataPairs(AQDG_GRAPH_DATASET *ds, int level, int num) -{ - assert(ds); - if (ds->dataPairList) { - AQDG_GRAPH_DATAPAIR *dp; - double lastValues[num]; - int cnt=0; - int idx=0; - - dp=AQDG_Graph_DataPair_List_First(ds->dataPairList); - while (dp) { - if (AQDG_Graph_DataPair_GetLevel(dp)==level) { - double v; - int i; - - v=AQDG_Graph_DataPair_GetValueY(dp); - if (idx>=num) - idx=0; - lastValues[idx]=v; - idx++; - cnt++; - - if (cntdataPairList) { - const AQDG_GRAPH_DATAPAIR *dp; - double sumOfDists=0.0; - double lastValue=0.0; - int cnt=0; - - dp=AQDG_Graph_DataPair_List_First(ds->dataPairList); - while (dp) { - if (AQDG_Graph_DataPair_GetLevel(dp)==level) { - double d; - - d=AQDG_Graph_DataPair_GetValueX(dp); - if (cnt) - sumOfDists+=abs(d-lastValue); - lastValue=d; - cnt++; - } - dp=AQDG_Graph_DataPair_List_Next(dp); - } - - if (cnt>1) { - *pResult=sumOfDists/((double)(cnt-1)); - return 0; - } - else - return 1; - } - else { - return GWEN_ERROR_NO_DATA; - } -} - - - -int AQDG_Graph_DataSet_GetAverageValueDistY(const AQDG_GRAPH_DATASET *ds, int level, double *pResult) -{ - if (ds->dataPairList) { - const AQDG_GRAPH_DATAPAIR *dp; - double sumOfDists=0.0; - double lastValue=0.0; - int cnt=0; - - dp=AQDG_Graph_DataPair_List_First(ds->dataPairList); - while (dp) { - if (AQDG_Graph_DataPair_GetLevel(dp)==level) { - double d; - - d=AQDG_Graph_DataPair_GetValueY(dp); - if (cnt) - sumOfDists+=abs(d-lastValue); - lastValue=d; - cnt++; - } - dp=AQDG_Graph_DataPair_List_Next(dp); - } - - if (cnt>1) { - *pResult=sumOfDists/((double)(cnt-1)); - return 0; - } - else - return 1; - } - else { - return GWEN_ERROR_NO_DATA; - } -} - - - -int AQDG_Graph_DataSet_GetMinValueDistX(const AQDG_GRAPH_DATASET *ds, int level, double *pResult) -{ - if (ds->dataPairList) { - const AQDG_GRAPH_DATAPAIR *dp; - double minDist=0.0; - double lastValue=0.0; - int cnt=0; - - dp=AQDG_Graph_DataPair_List_First(ds->dataPairList); - while (dp) { - if (AQDG_Graph_DataPair_GetLevel(dp)==level) { - double d; - - d=AQDG_Graph_DataPair_GetValueX(dp); - if (cnt) { - double dist; - - dist=abs(d-lastValue); - if (cnt>1) { - if (dist1) { - *pResult=minDist; - return 0; - } - else - return 1; - } - else { - return GWEN_ERROR_NO_DATA; - } -} - - - -int AQDG_Graph_DataSet_GetMinValueDistY(const AQDG_GRAPH_DATASET *ds, int level, double *pResult) -{ - if (ds->dataPairList) { - const AQDG_GRAPH_DATAPAIR *dp; - double minDist=0.0; - double lastValue=0.0; - int cnt=0; - - dp=AQDG_Graph_DataPair_List_First(ds->dataPairList); - while (dp) { - if (AQDG_Graph_DataPair_GetLevel(dp)==level) { - double d; - - d=AQDG_Graph_DataPair_GetValueY(dp); - if (cnt) { - double dist; - - dist=abs(d-lastValue); - if (dist1) { - *pResult=minDist; - return 0; - } - else - return 1; - } - else { - return GWEN_ERROR_NO_DATA; - } -} - - - -void AQDG_Graph_DataSet_KeepFirstNValues(AQDG_GRAPH_DATASET *ds, int n) -{ - assert(ds); - if (ds->dataPairList) { - AQDG_GRAPH_DATAPAIR *dp; - int i=0; - - dp=AQDG_Graph_DataPair_List_First(ds->dataPairList); - while (dp) { - dp=AQDG_Graph_DataPair_List_Next(dp); - i++; - if (i>=n) - break; - } - - if (dp && i>=n) { - while (dp) { - AQDG_GRAPH_DATAPAIR *dpNext; - - /* remove remaining entries */ - dpNext=AQDG_Graph_DataPair_List_Next(dp); - AQDG_Graph_DataPair_List_Del(dp); - AQDG_Graph_DataPair_free(dp); - dp=dpNext; - } - } - } -} - - - - diff --git a/src/lib/aqdiagram/graph/dataset_fns.h b/src/lib/aqdiagram/graph/dataset_fns.h deleted file mode 100644 index 910e6b5..0000000 --- a/src/lib/aqdiagram/graph/dataset_fns.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqDiagram. - * AqDiagram (c) by 2020 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - - -#ifndef AQDG_GRAPH_DATASET_FNS_H -#define AQDG_GRAPH_DATASET_FNS_H - -#ifdef __cplusplus -extern "C" { -#endif - - -AQDG_API double AQDG_Graph_DataSet_GetRoundedMaxVal(double val); - -/** - * Calculates minValueX and maxValueX from the dataset. - */ -AQDG_API void AQDG_Graph_DataSet_AdjustXRange(AQDG_GRAPH_DATASET *ds); - -/** - * Calculates minValueY and maxValueY from the dataset. - */ -AQDG_API void AQDG_Graph_DataSet_AdjustYRange(AQDG_GRAPH_DATASET *ds); - - -AQDG_API void AQDG_Graph_DataSet_AddTicks(AQDG_GRAPH_DATASET *ds); - -AQDG_API void AQDG_Graph_DataSet_AddSubGraph(AQDG_GRAPH_DATASET *ds, const char *label, - int level, int graphType, int dataMode, int colour, int lineWidth, int dashType); - -AQDG_API AQDG_GRAPH_SUBGRAPH *AQDG_Graph_DataSet_GetSubGraphByLevel(AQDG_GRAPH_DATASET *ds, int level); - -AQDG_API void AQDG_Graph_DataSet_AddDataPair(AQDG_GRAPH_DATASET *ds, AQDG_GRAPH_DATAPAIR *dp); - -AQDG_API int AQDG_Graph_DataSet_GetAverageValueDistX(const AQDG_GRAPH_DATASET *ds, int level, double *pResult); -AQDG_API int AQDG_Graph_DataSet_GetAverageValueDistY(const AQDG_GRAPH_DATASET *ds, int level, double *pResult); - -AQDG_API int AQDG_Graph_DataSet_GetMinValueDistX(const AQDG_GRAPH_DATASET *ds, int level, double *pResult); -AQDG_API int AQDG_Graph_DataSet_GetMinValueDistY(const AQDG_GRAPH_DATASET *ds, int level, double *pResult); - - -AQDG_API void AQDG_Graph_DataSet_SortDataPairsByX(AQDG_GRAPH_DATASET *ds, int ascending); -AQDG_API void AQDG_Graph_DataSet_SortDataPairsByY(AQDG_GRAPH_DATASET *ds, int ascending); - -AQDG_API void AQDG_Graph_DataSet_AccumulateDataPairs(AQDG_GRAPH_DATASET *ds, int level); -AQDG_API void AQDG_Graph_DataSet_AverageDataPairs(AQDG_GRAPH_DATASET *ds, int level); -AQDG_API void AQDG_Graph_DataSet_FloatingAverageDataPairs(AQDG_GRAPH_DATASET *ds, int level, int num); - -AQDG_API void AQDG_Graph_DataSet_KeepFirstNValues(AQDG_GRAPH_DATASET *ds, int n); - - -#ifdef __cplusplus -} -#endif - - - -#endif - - diff --git a/src/lib/aqdiagram/graph/draw.c b/src/lib/aqdiagram/graph/draw.c deleted file mode 100644 index 09afc9c..0000000 --- a/src/lib/aqdiagram/graph/draw.c +++ /dev/null @@ -1,559 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqFinance. - * AqFinance (c) by 2011 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqdiagram/graph/draw.h" -#include "aqdiagram/graph/dataset_fns.h" -#include "graph_p.h" - -#include - - -#define MAX_TICK_LEVELS 5 - -#define MIN_DIST_FOR_TICKS 5 -#define MIN_DIST_FOR_GRIDS 5 - - -#define TICKDRAWFLAGS_MARKS 0x01 -#define TICKDRAWFLAGS_GRIDS 0x02 -#define TICKDRAWFLAGS_LABELS 0x04 - - - -static void _drawXAxis(AQDG_GRAPH *gr); -static void _drawYAxis(AQDG_GRAPH *gr); -static void _drawTitleIfSet(const AQDG_GRAPH *gr); -static void _drawSubTitleIfSet(const AQDG_GRAPH *gr); - -static void _drawXTicks(AQDG_GRAPH *gr); -static void _drawYTicks(AQDG_GRAPH *gr); - -static int _isPositionFree(int m1, int m2, const uint8_t *pMask, int maxLen); -static void _reservePosition(int m1, int m2, uint8_t *pMask, int maxLen); - -static void _probablyDrawGridLineForXTick(const AQDG_GRAPH *gr, int x, uint8_t tickDrawFlags); -static void _probablyDrawMarkForXTick(const AQDG_GRAPH *gr, int x, int y, uint8_t tickDrawFlags, int level); - -/*static int _getMaxTickLabelWidthForLevel(const AQDG_GRAPH *gr, const AQDG_GRAPH_TICK_LIST *tl, int level);*/ -static int _calcDistBetweenFirstTwoTicksOfLevel(const AQDG_GRAPH *gr, const AQDG_GRAPH_TICK_LIST *tl, int level); - - - -void AQDG_Graph_DrawFramework(AQDG_GRAPH *gr) -{ - /* draw background */ - AQDG_Draw_Context_DrawFilledRect(gr->drawContext, gr->penBackground, - 0, 0, gr->width, gr->height); - - /* draw graph area */ - AQDG_Draw_Context_DrawFilledRect(gr->drawContext, gr->penGraphBackground, - gr->graphAreaPosX, gr->graphAreaPosY, - gr->graphAreaWidth, gr->graphAreaHeight); - - _drawXAxis(gr); - _drawYAxis(gr); - _drawTitleIfSet(gr); - _drawSubTitleIfSet(gr); -} - - - -void _drawXAxis(AQDG_GRAPH *gr) -{ - const char *s; - - /* ticks, axis, label */ - _drawXTicks(gr); - AQDG_Draw_Context_DrawLine(gr->drawContext, gr->penAxis, - gr->graphAreaPosX, gr->xAxisPosY, - gr->graphAreaPosX+gr->graphAreaWidth, gr->xAxisPosY); - s=AQDG_Graph_DataSet_GetLabelX(gr->dataSet); - if (s && *s) - AQDG_Draw_Context_DrawText(gr->drawContext, gr->penAxisLabel, gr->fontAxisLabel, AQDG_Direction_Horizontal, - gr->xAxisLabelPosX, gr->xAxisLabelPosY, s); -} - - - -void _drawYAxis(AQDG_GRAPH *gr) -{ - const char *s; - - /* ticks, axis, label */ - _drawYTicks(gr); - AQDG_Draw_Context_DrawLine(gr->drawContext, gr->penAxis, - gr->yAxisPosX, gr->graphAreaPosY, - gr->yAxisPosX, gr->graphAreaPosY+gr->graphAreaHeight); - s=AQDG_Graph_DataSet_GetLabelY(gr->dataSet); - if (s && *s) - AQDG_Draw_Context_DrawText(gr->drawContext, gr->penAxisLabel, gr->fontAxisLabel, AQDG_Direction_Horizontal, - gr->yAxisLabelPosX, gr->yAxisLabelPosY, s); -} - - - -void _drawTitleIfSet(const AQDG_GRAPH *gr) -{ - const char *s; - - s=AQDG_Graph_DataSet_GetTitle(gr->dataSet); - if (s && *s) - AQDG_Draw_Context_DrawText(gr->drawContext, gr->penTitle, gr->fontTitle, AQDG_Direction_Horizontal, - gr->titlePosX, gr->titlePosY, s); -} - - - -void _drawSubTitleIfSet(const AQDG_GRAPH *gr) -{ - const char *s; - - s=AQDG_Graph_DataSet_GetSubTitle(gr->dataSet); - if (s && *s) - AQDG_Draw_Context_DrawText(gr->drawContext, gr->penSubTitle, gr->fontSubTitle, AQDG_Direction_Horizontal, - gr->subTitlePosX, gr->subTitlePosY, s); -} - - - -void _drawXTicks(AQDG_GRAPH *gr) -{ - AQDG_GRAPH_TICK_LIST *tl; - - tl=AQDG_Graph_DataSet_GetXTickList(gr->dataSet); - if (tl) { - AQDG_GRAPH_TICK *t; - uint8_t *pMask; - int level; - - /* reset */ - pMask=(uint8_t *) malloc(gr->graphAreaWidth); - assert(pMask); - memset(pMask, 0, gr->graphAreaWidth); - - /* handle each level */ - for (level=1; levelgraphAreaWidth; - if (dist>MIN_DIST_FOR_TICKS) - tickDrawFlags|=TICKDRAWFLAGS_MARKS; - if (dist>MIN_DIST_FOR_GRIDS) - tickDrawFlags|=TICKDRAWFLAGS_GRIDS; - -#if 0 - if (dist>maxWidth+SMALL_BORDER) { - tickDrawFlags|=TICKDRAWFLAGS_LABELS; - } - else if ((dist*2)>maxWidth+SMALL_BORDER) { - tickDrawFlags|=TICKDRAWFLAGS_LABELS; - every=2; - } - else if ((dist*4)>maxWidth+SMALL_BORDER) { - tickDrawFlags|=TICKDRAWFLAGS_LABELS; - every=4; - } -#else - tickDrawFlags|=TICKDRAWFLAGS_LABELS; -#endif - - /* now draw according to flags */ - if (tickDrawFlags) { - double minVal; - double maxVal; - int tickIntervalCnt=every; - - minVal=AQDG_Graph_DataSet_GetMinValueX(gr->dataSet); - maxVal=AQDG_Graph_DataSet_GetMaxValueX(gr->dataSet); - t=AQDG_Graph_Tick_List_First(tl); - while (t) { - if (AQDG_Graph_Tick_GetLevel(t)==level) { - double v; - - tickIntervalCnt--; - v=AQDG_Graph_Tick_GetValue(t); - if (v>=minVal && v<=maxVal) { - int x, y; - - x=gr->graphOriginX + (v * gr->graphFactorX); - y=gr->xAxisPosY; - - _probablyDrawGridLineForXTick(gr, x, tickDrawFlags); - _probablyDrawMarkForXTick(gr, x, y, tickDrawFlags, level); - - if (tickDrawFlags & TICKDRAWFLAGS_LABELS) { - const char *s; - - /* draw label */ - if (tickIntervalCnt<1) { - s=AQDG_Graph_Tick_GetLabel(t); - if (s && *s) { - int i; - - i=AQDG_Draw_Context_GetTextWidth(gr->drawContext, gr->penAxisLabel, s); - if (i>=0) { - if ((x+(i/2) < (gr->graphAreaPosX+gr->graphAreaWidth)) && - (x-(i/2) > gr->graphAreaPosX)) { - int m1, m2; - - m1=x-(i/2)-gr->graphAreaPosX; - m2=x+(i/2)-gr->graphAreaPosX; - if (_isPositionFree(m1, m2, pMask, gr->graphAreaWidth)) { - _reservePosition(m1, m2, pMask, gr->graphAreaWidth); - AQDG_Draw_Context_DrawText(gr->drawContext, gr->penAxisLabel, gr->fontTickLabel, AQDG_Direction_Horizontal, - x-(i/2), gr->xTickLabelPosY, s); - } - } - } - } - tickIntervalCnt=every; - } - } /* if labels to be drawn */ - } /* if value within limits */ - } - t=AQDG_Graph_Tick_List_Next(t); - } /* while t */ - } /* if tickDrawFlags */ - - - } /* for level */ - - free(pMask); - } /* if tl */ -} - - -int _isPositionFree(int m1, int m2, const uint8_t *pMask, int maxLen) -{ - int j; - - for (j=m1; j=maxLen) - return 0; - if (pMask[j]!=0) - return 0; - } - - return 1; -} - - - -void _reservePosition(int m1, int m2, uint8_t *pMask, int maxLen) -{ - int j; - - m1-=SMALL_BORDER/2; - m2+=SMALL_BORDER/2; - - if (m1<0) - m1=0; - if (m2>=maxLen) - m2=maxLen-1; - for (j=m1; jflags & AQDG_GRAPH_FLAGS_WITH_GRID) - AQDG_Draw_Context_DrawLine(gr->drawContext, gr->penGrid, x, gr->graphAreaPosY, x, gr->graphAreaPosY+gr->graphAreaHeight); - } -} - - - -void _probablyDrawMarkForXTick(const AQDG_GRAPH *gr, int x, int y, uint8_t tickDrawFlags, int level) -{ - if (tickDrawFlags & TICKDRAWFLAGS_MARKS) { - int w; - - switch (level) { - case 1: - w=9; - break; - case 2: - w=5; - break; - default: - case 3: - w=1; - break; - } - - /* draw tick mark */ - AQDG_Draw_Context_DrawLine(gr->drawContext, gr->penAxis, x, y-w, x, y+w); - } -} - - - -#if 0 -int _getMaxTickLabelWidthForLevel(const AQDG_GRAPH *gr, const AQDG_GRAPH_TICK_LIST *tl, int level) -{ - AQDG_GRAPH_TICK *t; - int maxWidth=0; - - /* determine width of labels for this level */ - t=AQDG_Graph_Tick_List_First(tl); - while (t) { - if (AQDG_Graph_Tick_GetLevel(t)==level) { - const char *s; - - s=AQDG_Graph_Tick_GetLabel(t); - if (s && *s) { - int i; - - //DBG_ERROR(0, "X-Level %d: [%s] = %f", level, s, AQDG_Graph_Tick_GetValue(t)); - i=AQDG_Draw_Context_GetTextWidth(gr->drawContext, gr->fontTickLabel, s); - if (i<0) { - DBG_ERROR(0, "Invalid text width (%d)", i); - } - else { - if (i>maxWidth) - maxWidth=i; - } - } - else { - DBG_ERROR(0, "X-Level %d: No tick label", level); - } - } - t=AQDG_Graph_Tick_List_Next(t); - } - - return maxWidth; -} -#endif - - - -int _calcDistBetweenFirstTwoTicksOfLevel(const AQDG_GRAPH *gr, const AQDG_GRAPH_TICK_LIST *tl, int level) -{ - const AQDG_GRAPH_TICK *t; - - t=AQDG_Graph_Tick_List_First(tl); - while (t && AQDG_Graph_Tick_GetLevel(t)!=level) - t=AQDG_Graph_Tick_List_Next(t); - if (t) { - const AQDG_GRAPH_TICK *tick1=t; - - t=AQDG_Graph_Tick_List_Next(t); - while (t && AQDG_Graph_Tick_GetLevel(t)!=level) - t=AQDG_Graph_Tick_List_Next(t); - if (t) { - const AQDG_GRAPH_TICK *tick2=t; - double v1, v2; - int dist; - - v1=AQDG_Graph_Tick_GetValue(tick1); - v2=AQDG_Graph_Tick_GetValue(tick2); - dist=(int)((v2-v1)*gr->graphFactorX); - return dist; - } - } - - return 0; -} - - - -void _drawYTicks(AQDG_GRAPH *gr) -{ - AQDG_GRAPH_TICK_LIST *tl; - - tl=AQDG_Graph_DataSet_GetYTickList(gr->dataSet); - if (tl) { - AQDG_GRAPH_TICK *t; - uint8_t *pMask; - int level; - - /* reset */ - pMask=(uint8_t *) malloc(gr->graphAreaHeight); - assert(pMask); - memset(pMask, 0, gr->graphAreaHeight); - - /* handle each level */ - for (level=1; leveldrawContext, gr->fontTickLabel, s); - if (i<0) { - DBG_ERROR(0, "Invalid text width (%d)", i); - } - else { - if (i>maxHeight) - maxHeight=i; - } - } - else { - DBG_ERROR(0, "No tick label"); - } - } - t=AQDG_Graph_Tick_List_Next(t); - } - - - /* get 1st and 2nd entry for the current level and check width */ - { - int first=1; - int hasSecond=0; - double lastValue; - - t=AQDG_Graph_Tick_List_First(tl); - while (t) { - if (AQDG_Graph_Tick_GetLevel(t)==level) { - double v; - - v=AQDG_Graph_Tick_GetValue(t); - if (first) { - lastValue=v; - first=0; - } - else { - int dist; - - dist=(int)((v-lastValue)*gr->graphFactorY); - if (dist>MIN_DIST_FOR_TICKS) - tickDrawFlags|=TICKDRAWFLAGS_MARKS; - if (dist>MIN_DIST_FOR_GRIDS) - tickDrawFlags|=TICKDRAWFLAGS_GRIDS; - if (dist>maxHeight+5) - tickDrawFlags|=TICKDRAWFLAGS_LABELS; - DBG_ERROR(0, "Y-Level %d: dist=%d (flags=%02x)", level, dist, tickDrawFlags); - hasSecond=1; - break; - } - } - - t=AQDG_Graph_Tick_List_Next(t); - } - - if (!first && !hasSecond) { - int dist; - - dist=gr->graphAreaHeight; - if (dist>MIN_DIST_FOR_TICKS) - tickDrawFlags|=TICKDRAWFLAGS_MARKS; - if (dist>MIN_DIST_FOR_GRIDS) - tickDrawFlags|=TICKDRAWFLAGS_GRIDS; - if (dist>maxHeight+2) - tickDrawFlags|=TICKDRAWFLAGS_LABELS; - } - } - - /* now draw according to flags */ - if (tickDrawFlags) { - double minVal; - double maxVal; - - minVal=AQDG_Graph_DataSet_GetMinValueY(gr->dataSet); - maxVal=AQDG_Graph_DataSet_GetMaxValueY(gr->dataSet); - t=AQDG_Graph_Tick_List_First(tl); - while (t) { - double v; - - v=AQDG_Graph_Tick_GetValue(t); - if (AQDG_Graph_Tick_GetLevel(t)==level) { - if (v>=minVal && v<=maxVal) { - int x, y; - int w; - - x=gr->yAxisPosX; - y=gr->graphOriginY - (v * gr->graphFactorY); - - /* draw grid line */ - if (tickDrawFlags & TICKDRAWFLAGS_GRIDS) { - if (gr->flags & AQDG_GRAPH_FLAGS_WITH_GRID) - AQDG_Draw_Context_DrawLine(gr->drawContext, gr->penGrid, gr->graphAreaPosX, y, gr->graphAreaPosX+gr->graphAreaWidth, y); - } - - if (tickDrawFlags & TICKDRAWFLAGS_MARKS) { - switch (level) { - case 1: - w=9; - break; - case 2: - w=5; - break; - default: - case 3: - w=1; - break; - } - - /* draw tick mark */ - AQDG_Draw_Context_DrawLine(gr->drawContext, gr->penAxis, x-w, y, x+w, y); - } - - if (tickDrawFlags & TICKDRAWFLAGS_LABELS) { - const char *s; - - /* draw label */ - s=AQDG_Graph_Tick_GetLabel(t); - if (s && *s) { - int i; - - i=AQDG_Draw_Context_GetTextHeight(gr->drawContext, gr->penAxisLabel, s); - if (i>=0) { - if ((y+(i/2) < (gr->graphAreaPosY+gr->graphAreaHeight)) && (y-(i/2)>= gr->graphAreaPosY)) { - int m1, m2; - - m1=y-(i/2)-gr->graphAreaPosY; - m2=y+(i/2)-gr->graphAreaPosY; - - if (_isPositionFree(m1, m2, pMask, gr->graphAreaHeight)) { - _reservePosition(m1, m2, pMask, gr->graphAreaHeight); - AQDG_Draw_Context_DrawText(gr->drawContext, gr->penAxisLabel, gr->fontTickLabel, AQDG_Direction_Horizontal, - gr->yTickLabelPosX, y-(i/2), s); - } - } - } - } - } /* if labels to be drawn */ - } /* if value within limits */ - } - t=AQDG_Graph_Tick_List_Next(t); - } /* while t */ - } /* if tickDrawFlags */ - - - } /* for level */ - - free(pMask); - } /* if tl */ -} - - - - diff --git a/src/lib/aqdiagram/graph/graph.c b/src/lib/aqdiagram/graph/graph.c index e5847d7..2a7d424 100644 --- a/src/lib/aqdiagram/graph/graph.c +++ b/src/lib/aqdiagram/graph/graph.c @@ -1,6 +1,6 @@ /**************************************************************************** * This file is part of the project AqDiagram. - * AqDiagram (c) by 2020 Martin Preuss, all rights reserved. + * AqDiagram (c) by 2024 Martin Preuss, all rights reserved. * * The license for this file can be found in the file COPYING which you * should have received along with this file. @@ -10,308 +10,253 @@ # include #endif -#include "graph_p.h" -#include "aqdiagram/graph/draw.h" -#include "aqdiagram/graph/layout.h" -#include "aqdiagram/graph/setup.h" +#include "./graph_p.h" + +#include #include -GWEN_LIST_FUNCTIONS(AQDG_GRAPH, AQDG_Graph) -GWEN_LIST2_FUNCTIONS(AQDG_GRAPH, AQDG_Graph) + +static uint32_t _curveColors[]={ + AQDG_GRAPH_COL_LIME, + AQDG_GRAPH_COL_BLUE, + AQDG_GRAPH_COL_CYAN, + AQDG_GRAPH_COL_MAGENTA, + AQDG_GRAPH_COL_GREEN, + AQDG_GRAPH_COL_TURQUOISE, + AQDG_GRAPH_COL_DEEPPINK, + AQDG_GRAPH_COL_NAVY +}; -void AQDG_Graph_DrawDataAsBars(AQDG_GRAPH *gr, int level, int penId); -void AQDG_Graph_DrawDataAsLine(AQDG_GRAPH *gr, int level, int penId); + +static void _presetPens(AQDG_GRAPH *g); +static void _presetFonts(AQDG_GRAPH *g); +static void _releasePens(AQDG_GRAPH *g); +static void _releaseFonts(AQDG_GRAPH *g); -AQDG_GRAPH *AQDG_Graph_new(AQDG_GRAPH_DATASET *ds, AQDG_DRAW_CONTEXT *drawContext, int width, int height) + +AQDG_GRAPH *AQDG_Graph_new(void) { - AQDG_GRAPH *gr; + AQDG_GRAPH *g; - GWEN_NEW_OBJECT(AQDG_GRAPH, gr); - GWEN_LIST_INIT(AQDG_GRAPH, gr) + GWEN_NEW_OBJECT(AQDG_GRAPH, g); - gr->dataSet=ds; - gr->drawContext=drawContext; - gr->width=width; - gr->height=height; + _presetPens(g); + _presetFonts(g); + g->subGraphList=AQDG_Graph_SubGraph_List_new(); - return gr; + return g; } -void AQDG_Graph_free(AQDG_GRAPH *gr) +void AQDG_Graph_free(AQDG_GRAPH *g) { - if (gr) { - GWEN_LIST_FINI(AQDG_GRAPH, gr) - AQDG_Draw_Context_free(gr->drawContext); - GWEN_FREE_OBJECT(gr); - } -} + if (g) { + int i; - - -void AQDG_Graph_DrawDataAsLine(AQDG_GRAPH *gr, int level, int penId) -{ - AQDG_GRAPH_DATAPAIR_LIST *dpl; - - dpl=AQDG_Graph_DataSet_GetDataPairList(gr->dataSet); - if (dpl) { - AQDG_GRAPH_DATAPAIR *dp; - double minValX; - double maxValX; - double minValY; - double maxValY; - int lastX; - int lastY; - int first=1; - - minValX=AQDG_Graph_DataSet_GetMinValueX(gr->dataSet); - maxValX=AQDG_Graph_DataSet_GetMaxValueX(gr->dataSet); - minValY=AQDG_Graph_DataSet_GetMinValueY(gr->dataSet); - maxValY=AQDG_Graph_DataSet_GetMaxValueY(gr->dataSet); - dp=AQDG_Graph_DataPair_List_First(dpl); - while (dp) { - if (AQDG_Graph_DataPair_GetLevel(dp)==level) { - double vX; - double vY; - int x, y; - - vX=AQDG_Graph_DataPair_GetValueX(dp); - vY=AQDG_Graph_DataPair_GetValueY(dp); - - if (vXmaxValX) - vX=maxValX; - - if (vYmaxValY) - vY=maxValY; - - x=gr->graphOriginX + (vX * gr->graphFactorX); - y=gr->graphOriginY - (vY * gr->graphFactorY); - - /* draw a small star */ - AQDG_Draw_Context_DrawLine(gr->drawContext, penId, x-3, y-3, x+3, y+3); - AQDG_Draw_Context_DrawLine(gr->drawContext, penId, x-3, y+3, x+3, y-3); - AQDG_Draw_Context_DrawLine(gr->drawContext, penId, x, y-3, x, y+3); - AQDG_Draw_Context_DrawLine(gr->drawContext, penId, x-3, y, x+3, y); - - if (!first) - AQDG_Draw_Context_DrawLine(gr->drawContext, penId, lastX, lastY, x, y); - else - first=0; - - lastX=x; - lastY=y; - } - - dp=AQDG_Graph_DataPair_List_Next(dp); + _releaseFonts(g); + _releasePens(g); + for (i=0; iaxisArray[i]); + g->axisArray[i]=NULL; } - + AQDG_Graph_SubGraph_List_free(g->subGraphList); + g->subGraphList=NULL; + GWEN_FREE_OBJECT(g); } } -void AQDG_Graph_DrawDataAsBars(AQDG_GRAPH *gr, int level, int penId) +void _presetPens(AQDG_GRAPH *g) { - AQDG_GRAPH_DATAPAIR_LIST *dpl; - double dataWidth; - int barWidth; - int rv; + if (g) { + int i; - rv=AQDG_Graph_DataSet_GetMinValueDistX(gr->dataSet, level, &dataWidth); - if (rv<0) { - DBG_INFO(AQDG_LOGDOMAIN, "here (%d)", rv); - return; + for (i=0; ipenArray[i]=-1; + } } - else if (rv==1) { - /* use full width */ - barWidth=(gr->graphAreaWidth)-10; +} + + + +void _presetFonts(AQDG_GRAPH *g) +{ + if (g) { + int i; + + for (i=0; ifontArray[i]=-1; + } } +} + + + +void _releasePens(AQDG_GRAPH *g) +{ + if (g) { + int i; + + for (i=0; idrawContext, g->penArray[i]); + g->penArray[i]=-1; + } + } +} + + + +void _releaseFonts(AQDG_GRAPH *g) +{ + if (g) { + int i; + + for (i=0; idrawContext, g->fontArray[i]); + g->fontArray[i]=-1; + } + } +} + + + +const char *AQDG_Graph_GetTitle(const AQDG_GRAPH *g) +{ + return g?g->title:NULL; +} + + + +void AQDG_Graph_SetTitle(AQDG_GRAPH *g, const char *s) +{ + if (g) { + free(g->title); + g->title=s?strdup(s):NULL; + } +} + + + +const char *AQDG_Graph_GetSubTitle(const AQDG_GRAPH *g) +{ + return g?g->subTitle:NULL; +} + + + +void AQDG_Graph_SetSubTitle(AQDG_GRAPH *g, const char *s) +{ + if (g) { + free(g->subTitle); + g->subTitle=s?strdup(s):NULL; + } +} + + + +AQDG_DRAW_CONTEXT *AQDG_Graph_GetDrawContext(const AQDG_GRAPH *g) +{ + return g?g->drawContext:NULL; +} + + + +void AQDG_Graph_SetDrawContext(AQDG_GRAPH *g, AQDG_DRAW_CONTEXT *dc) +{ + if (g) + g->drawContext=dc; +} + + + +AQDG_GRAPH_AXIS *AQDG_Graph_GetAxisByIndex(const AQDG_GRAPH *g, int idx) +{ + return (g && idxaxisArray[idx]):NULL; +} + + + +int AQDG_Graph_SetAxis(AQDG_GRAPH *g, int idx, AQDG_GRAPH_AXIS *ax) +{ + if (g && idxaxisArray[idx]) + AQDG_Graph_Axis_free(g->axisArray[idx]); + g->axisArray[idx]=ax; + return 0; + } + return GWEN_ERROR_INVALID; +} + + + +AQDG_GRAPH_SUBGRAPH_LIST *AQDG_Graph_GetSubGraphList(const AQDG_GRAPH *g) +{ + return g?g->subGraphList:NULL; +} + + + +void AQDG_Graph_AddSubGraph(AQDG_GRAPH *g, AQDG_GRAPH_SUBGRAPH *sg) +{ + if (g && g->subGraphList && sg) + AQDG_Graph_SubGraph_List_Add(sg, g->subGraphList); else { - barWidth=((int)(dataWidth*gr->graphFactorX))-10; - } - - if (barWidth<1) - barWidth=1; - - dpl=AQDG_Graph_DataSet_GetDataPairList(gr->dataSet); - if (dpl) { - AQDG_GRAPH_DATAPAIR *dp; - double minValX; - double maxValX; - double minValY; - double maxValY; - - minValX=AQDG_Graph_DataSet_GetMinValueX(gr->dataSet); - maxValX=AQDG_Graph_DataSet_GetMaxValueX(gr->dataSet); - minValY=AQDG_Graph_DataSet_GetMinValueY(gr->dataSet); - maxValY=AQDG_Graph_DataSet_GetMaxValueY(gr->dataSet); - dp=AQDG_Graph_DataPair_List_First(dpl); - while (dp) { - if (AQDG_Graph_DataPair_GetLevel(dp)==level) { - double vX; - double vY; - int x, y; - int leftX, bw; - - vX=AQDG_Graph_DataPair_GetValueX(dp); - vY=AQDG_Graph_DataPair_GetValueY(dp); - - if (vXmaxValX) - vX=maxValX; - - if (vYmaxValY) - vY=maxValY; - - x=gr->graphOriginX + (vX * gr->graphFactorX); - y=gr->graphOriginY - (vY * gr->graphFactorY); - - /* draw the bar */ - if ((x-(barWidth/2))graphAreaPosX) { - leftX=x; - bw=barWidth/2; - } - else { - leftX=x-(barWidth/2); - bw=barWidth; - } - if ((leftX+bw)>=(gr->graphAreaPosX+gr->graphAreaWidth)) { - bw=barWidth/2; - } - - AQDG_Draw_Context_DrawFilledRect(gr->drawContext, penId, - leftX, gr->xAxisPosY, - bw, y-gr->xAxisPosY); - } - - dp=AQDG_Graph_DataPair_List_Next(dp); - } - + DBG_ERROR(AQDG_LOGDOMAIN, "Nullpointer"); } } -void AQDG_Graph_DrawDataAsPoints(AQDG_GRAPH *gr, int level, int penId) +int AQDG_Graph_GetPen(const AQDG_GRAPH *g, int idx) { - AQDG_GRAPH_DATAPAIR_LIST *dpl; - double dataWidth; - int barWidth; - int rv; - - rv=AQDG_Graph_DataSet_GetMinValueDistX(gr->dataSet, level, &dataWidth); - if (rv<0) { - DBG_INFO(AQDG_LOGDOMAIN, "here (%d)", rv); - return; - } - else if (rv==1) { - /* use full width */ - barWidth=(gr->graphAreaWidth)-10; - } - else { - barWidth=((int)(dataWidth*gr->graphFactorX))-10; - } - - if (barWidth<1) - barWidth=1; - - dpl=AQDG_Graph_DataSet_GetDataPairList(gr->dataSet); - if (dpl) { - AQDG_GRAPH_DATAPAIR *dp; - double minValX; - double maxValX; - double minValY; - double maxValY; - - minValX=AQDG_Graph_DataSet_GetMinValueX(gr->dataSet); - maxValX=AQDG_Graph_DataSet_GetMaxValueX(gr->dataSet); - minValY=AQDG_Graph_DataSet_GetMinValueY(gr->dataSet); - maxValY=AQDG_Graph_DataSet_GetMaxValueY(gr->dataSet); - dp=AQDG_Graph_DataPair_List_First(dpl); - while (dp) { - if (AQDG_Graph_DataPair_GetLevel(dp)==level) { - double vX; - double vY; - int x, y; - - vX=AQDG_Graph_DataPair_GetValueX(dp); - vY=AQDG_Graph_DataPair_GetValueY(dp); - - if (vXmaxValX) - vX=maxValX; - - if (vYmaxValY) - vY=maxValY; - - x=gr->graphOriginX + (vX * gr->graphFactorX); - y=gr->graphOriginY - (vY * gr->graphFactorY); - - /* draw a small star */ - AQDG_Draw_Context_DrawLine(gr->drawContext, penId, x-3, y-3, x+3, y+3); - AQDG_Draw_Context_DrawLine(gr->drawContext, penId, x-3, y+3, x+3, y-3); - AQDG_Draw_Context_DrawLine(gr->drawContext, penId, x, y-3, x, y+3); - AQDG_Draw_Context_DrawLine(gr->drawContext, penId, x-3, y, x+3, y); - } - - dp=AQDG_Graph_DataPair_List_Next(dp); - } - - } + return (g && idxpenArray[idx]:-1; } -int AQDG_Graph_Draw(AQDG_GRAPH *gr) +void AQDG_Graph_SetPen(AQDG_GRAPH *g, int idx, int penId) { - AQDG_GRAPH_SUBGRAPH_LIST *sgList; - - AQDG_Graph_PrepareGraph(gr); - AQDG_Graph_DrawFramework(gr); - - /* draw all levels */ - sgList=AQDG_Graph_DataSet_GetSubGraphList(gr->dataSet); - if (sgList) { - AQDG_GRAPH_SUBGRAPH *sg; - - sg=AQDG_Graph_SubGraph_List_First(sgList); - while (sg) { - /* TODO: select graph type */ - switch (AQDG_Graph_SubGraph_GetGraphType(sg)) { - case AQDG_GRAPH_TYPE_POINTS: - AQDG_Graph_DrawDataAsPoints(gr, AQDG_Graph_SubGraph_GetLevel(sg), AQDG_Graph_SubGraph_GetPenId(sg)); - break; - case AQDG_GRAPH_TYPE_LINE: - AQDG_Graph_DrawDataAsLine(gr, AQDG_Graph_SubGraph_GetLevel(sg), AQDG_Graph_SubGraph_GetPenId(sg)); - break; - case AQDG_GRAPH_TYPE_BARS: - AQDG_Graph_DrawDataAsBars(gr, AQDG_Graph_SubGraph_GetLevel(sg), AQDG_Graph_SubGraph_GetPenId(sg)); - break; - case AQDG_GRAPH_TYPE_NONE: - case AQDG_GRAPH_TYPE_UNKNOWN: - break; - } - sg=AQDG_Graph_SubGraph_List_Next(sg); - } + if (g && idxpenArray[idx]>=0) + AQDG_Draw_Context_PenRelease(g->drawContext, g->penArray[idx]); + g->penArray[idx]=penId; } - - return 0; } + + +int AQDG_Graph_GetFont(const AQDG_GRAPH *g, int idx) +{ + return (g && idxfontArray[idx]:-1; +} + + + +void AQDG_Graph_SetFont(AQDG_GRAPH *g, int idx, int fontId) +{ + if (g && idxfontArray[idx]>=0) + AQDG_Draw_Context_FontRelease(g->drawContext, g->fontArray[idx]); + g->fontArray[idx]=fontId; + } +} + + + +uint32_t AQDG_Graph_GetStandardCurveColor(int idx, uint32_t defCol) +{ + if (idx +/* see https://www.rapidtables.com/web/color/RGB_Color.html */ +#define AQDG_GRAPH_COL_BLACK ((uint32_t) 0x00000000) +#define AQDG_GRAPH_COL_WHITE ((uint32_t) 0xFFFFFF00) +#define AQDG_GRAPH_COL_RED ((uint32_t) 0xFF000000) +#define AQDG_GRAPH_COL_LIME ((uint32_t) 0x00FF0000) +#define AQDG_GRAPH_COL_BLUE ((uint32_t) 0x0000FF00) +#define AQDG_GRAPH_COL_YELLOW ((uint32_t) 0xFFFF0000) +#define AQDG_GRAPH_COL_CYAN ((uint32_t) 0x00FFFF00) +#define AQDG_GRAPH_COL_MAGENTA ((uint32_t) 0xFF00FF00) +#define AQDG_GRAPH_COL_SILVER ((uint32_t) 0xC0C0C000) +#define AQDG_GRAPH_COL_GRAY ((uint32_t) 0x80808000) +#define AQDG_GRAPH_COL_MAROON ((uint32_t) 0x80000000) +#define AQDG_GRAPH_COL_OLIVE ((uint32_t) 0x80800000) +#define AQDG_GRAPH_COL_GREEN ((uint32_t) 0x00800000) +#define AQDG_GRAPH_COL_PURPLE ((uint32_t) 0x80008000) +#define AQDG_GRAPH_COL_TEAL ((uint32_t) 0x00808000) +#define AQDG_GRAPH_COL_NAVY ((uint32_t) 0x00008000) -#include -#include -#include -#include -#include - -#include +#define AQDG_GRAPH_COL_ORANGE ((uint32_t) 0xFFA50000) +#define AQDG_GRAPH_COL_GOLD ((uint32_t) 0xFFD70000) +#define AQDG_GRAPH_COL_TURQUOISE ((uint32_t) 0x40E0D000) +#define AQDG_GRAPH_COL_SKYBLUE ((uint32_t) 0x87CEEB00) +#define AQDG_GRAPH_COL_DEEPPINK ((uint32_t) 0xFF149300) +#define AQDG_GRAPH_COL_COMSILK ((uint32_t) 0xFFF8DC00) +#define AQDG_GRAPH_COL_GAINSBORO ((uint32_t) 0xDCDCDC00) +#define AQDG_GRAPH_COL_WHITESMOKE ((uint32_t) 0xF5F5F500) -#ifdef __cplusplus -extern "C" { -#endif +enum { + AQDG_GRAPH_PEN_IDX_TITLE=0, + AQDG_GRAPH_PEN_IDX_SUBTITLE, + AQDG_GRAPH_PEN_IDX_AXISLINE, + AQDG_GRAPH_PEN_IDX_AXISLABEL, + AQDG_GRAPH_PEN_IDX_TICKLABELMAINLEVEL, + AQDG_GRAPH_PEN_IDX_TICKLABELSUBLEVEL, + AQDG_GRAPH_PEN_IDX_TICKMAINLEVEL, + AQDG_GRAPH_PEN_IDX_TICKSUBLEVEL, + AQDG_GRAPH_PEN_IDX_GRAPHBACKGROUND, + AQDG_GRAPH_PEN_IDX_GRID, + AQDG_GRAPH_PEN_IDX_BACKGROUND, + AQDG_GRAPH_PEN_IDX_CURVE0, + AQDG_GRAPH_PEN_IDX_CURVE1, + AQDG_GRAPH_PEN_IDX_CURVE2, + AQDG_GRAPH_PEN_IDX_CURVE3, + AQDG_GRAPH_PEN_IDX_CURVE4, + AQDG_GRAPH_PEN_IDX_CURVE5, + AQDG_GRAPH_PEN_IDX_CURVE6, + AQDG_GRAPH_PEN_IDX_CURVE7, + + AQDG_GRAPH_PEN_IDX_LAST +}; -typedef struct AQDG_GRAPH AQDG_GRAPH; -GWEN_LIST_FUNCTION_LIB_DEFS(AQDG_GRAPH, AQDG_Graph, AQDG_API) -GWEN_LIST2_FUNCTION_LIB_DEFS(AQDG_GRAPH, AQDG_Graph, AQDG_API) +enum { + AQDG_GRAPH_FONT_IDX_TITLE=0, + AQDG_GRAPH_FONT_IDX_SUBTITLE, + AQDG_GRAPH_FONT_IDX_AXISLABEL, + AQDG_GRAPH_FONT_IDX_TICKLABELMAINLEVEL, + AQDG_GRAPH_FONT_IDX_TICKLABELSUBLEVEL, + AQDG_GRAPH_FONT_IDX_LAST +}; -#define AQDG_GRAPH_FLAGS_WITH_GRID 0x00000001 - enum { AQDG_GRAPH_TYPE_UNKNOWN=-1, @@ -45,27 +87,65 @@ enum { }; -/** - * Takes over AQDG_GRAPHICS object (use AQDG_Graphics_Attach if you still need that object after destroying AQDG_GRAPH). -*/ -AQDG_API AQDG_GRAPH *AQDG_Graph_new(AQDG_GRAPH_DATASET *ds, AQDG_DRAW_CONTEXT *drawContext, int width, int height); -AQDG_API void AQDG_Graph_free(AQDG_GRAPH *gr); -AQDG_API int AQDG_Graph_InitFromDb(AQDG_GRAPH *gr, GWEN_DB_NODE *dbConfig); -AQDG_API int AQDG_Graph_InitFromSettings(AQDG_GRAPH *gr, const AQDG_GRAPH_SETTINGS *gs); -AQDG_API int AQDG_Graph_Fini(AQDG_GRAPH *gr); - -AQDG_API int AQDG_Graph_Draw(AQDG_GRAPH *gr); +enum { + AQDG_GRAPH_AXISPOS_LEFT=0, + AQDG_GRAPH_AXISPOS_BOTTOM, + AQDG_GRAPH_AXISPOS_RIGHT, + AQDG_GRAPH_AXISPOS_TOP +}; -#ifdef __cplusplus -} -#endif +enum { + AQDG_GRAPH_DATATYPE_INT=0, + AQDG_GRAPH_DATATYPE_DOUBLE, + AQDG_GRAPH_DATATYPE_DATE +}; + + +typedef struct AQDG_GRAPH AQDG_GRAPH; + + +#include +#include +#include "aqdiagram/draw/context.h" + + + +AQDG_GRAPH *AQDG_Graph_new(void); +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); + +const char *AQDG_Graph_GetSubTitle(const AQDG_GRAPH *g); +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_GRAPH_SUBGRAPH_LIST *AQDG_Graph_GetSubGraphList(const AQDG_GRAPH *g); +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); + +int AQDG_Graph_GetPen(const AQDG_GRAPH *g, int idx); +void AQDG_Graph_SetPen(AQDG_GRAPH *g, int idx, int penId); + +int AQDG_Graph_GetFont(const AQDG_GRAPH *g, int idx); +void AQDG_Graph_SetFont(AQDG_GRAPH *g, int idx, int fontId); + +int AQDG_Graph_CreatePenFromDb(AQDG_GRAPH *g, GWEN_DB_NODE *db, const char *name, uint32_t defColor, int defWidth, int defDash); +int AQDG_Graph_CreateFontFromDb(AQDG_GRAPH *gr, GWEN_DB_NODE *db, const char *name, int defaultFontSize); +uint32_t AQDG_Graph_GetStandardCurveColor(int idx, uint32_t defCol); + #endif - diff --git a/src/lib/aqdiagram/graph/graph_p.h b/src/lib/aqdiagram/graph/graph_p.h index e38848a..ee69c03 100644 --- a/src/lib/aqdiagram/graph/graph_p.h +++ b/src/lib/aqdiagram/graph/graph_p.h @@ -1,104 +1,39 @@ /**************************************************************************** - * This file is part of the project AqFinance. - * AqFinance (c) by 2013 Martin Preuss, all rights reserved. + * This file is part of the project AqDiagram. + * AqDiagram (c) by 2024 Martin Preuss, all rights reserved. * * The license for this file can be found in the file COPYING which you * should have received along with this file. ****************************************************************************/ +#ifndef AQDG_GRAPH_GRAPH_P_H +#define AQDG_GRAPH_GRAPH_P_H -#ifndef AQDG_GRAPH_P_H -#define AQDG_GRAPH_P_H +#include "./graph.h" -#include - - -#define MAX_TICK_LEVELS 5 - -#define BORDER 12 -#define SMALL_BORDER 8 - -#define MIN_DIST_FOR_TICKS 5 -#define MIN_DIST_FOR_GRIDS 5 - - -#define TICKDRAWFLAGS_MARKS 0x01 -#define TICKDRAWFLAGS_GRIDS 0x02 -#define TICKDRAWFLAGS_LABELS 0x04 - +#define AQDG_GRAPH_NUMAXIS 4 +#define AQDG_GRAPH_NUMPENS AQDG_GRAPH_PEN_IDX_LAST +#define AQDG_GRAPH_NUMFONTS AQDG_GRAPH_FONT_IDX_LAST +typedef struct AQDG_GRAPH AQDG_GRAPH; struct AQDG_GRAPH { - GWEN_LIST_ELEMENT(AQDG_GRAPH) + char *title; + char *subTitle; + AQDG_GRAPH_AXIS *axisArray[AQDG_GRAPH_NUMAXIS]; + AQDG_GRAPH_SUBGRAPH_LIST *subGraphList; - AQDG_GRAPH_DATASET *dataSet; AQDG_DRAW_CONTEXT *drawContext; - int width; - int height; - int penTitle; - int penSubTitle; - int penAxisLabel; - int penAxis; - int penGraph; - int penGraphBackground; - int penGrid; - int penBackground; + int penArray[AQDG_GRAPH_NUMPENS]; + int fontArray[AQDG_GRAPH_NUMFONTS]; - int fontTitle; - int fontSubTitle; - int fontAxisLabel; - int fontTickLabel; - - int xTickLabelMaxWidth; - int xTickLabelMaxHeight; - int xTickLabelPosY; - - int yTickLabelMaxWidth; - int yTickLabelMaxHeight; - int yTickLabelPosX; - - int titleWidth; - int titleHeight; - int titlePosX; - int titlePosY; - - int subTitleWidth; - int subTitleHeight; - int subTitlePosX; - int subTitlePosY; - - int xAxisLabelWidth; - int xAxisLabelHeight; - int xAxisLabelPosX; - int xAxisLabelPosY; - - int yAxisLabelWidth; - int yAxisLabelHeight; - int yAxisLabelPosX; - int yAxisLabelPosY; - - int graphAreaWidth; - int graphAreaHeight; - int graphAreaPosX; - int graphAreaPosY; - - double graphFactorX; - double graphFactorY; - - int graphOriginX; - int graphOriginY; - - int yAxisPosX; - int xAxisPosY; - - uint32_t flags; }; + #endif - diff --git a/src/lib/aqdiagram/graph/layout.c b/src/lib/aqdiagram/graph/layout.c deleted file mode 100644 index e28cac6..0000000 --- a/src/lib/aqdiagram/graph/layout.c +++ /dev/null @@ -1,310 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqFinance. - * AqFinance (c) by 2011 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqdiagram/graph/layout.h" -//#include "aqdiagram/graph/dataset_fns.h" -#include "graph_p.h" - -#include - - -static void _calcTickLabelMaxSizes(AQDG_GRAPH *gr, AQDG_GRAPH_TICK_LIST *tl, int *pMaxWidth, int *pMaxHeight); -static void _sampleSizes(AQDG_GRAPH *gr, AQDG_GRAPH_DATASET *ds); -static void _layout(AQDG_GRAPH *gr, AQDG_GRAPH_DATASET *ds); -static void _calcGraphArea(AQDG_GRAPH *gr, AQDG_GRAPH_DATASET *ds); - - - - -void AQDG_Graph_PrepareGraph(AQDG_GRAPH *gr) -{ - AQDG_GRAPH_TICK_LIST *tl; - - tl=AQDG_Graph_DataSet_GetXTickList(gr->dataSet); - if (tl) - AQDG_Graph_Tick_List_SortByValueAndLevel(tl, 1); - - tl=AQDG_Graph_DataSet_GetYTickList(gr->dataSet); - if (tl) - AQDG_Graph_Tick_List_SortByValueAndLevel(tl, 1); - - _sampleSizes(gr, gr->dataSet); - _layout(gr, gr->dataSet); - _calcGraphArea(gr, gr->dataSet); -} - - - -void _calcTickLabelMaxSizes(AQDG_GRAPH *gr, AQDG_GRAPH_TICK_LIST *tl, int *pMaxWidth, int *pMaxHeight) -{ - if (tl) { - AQDG_GRAPH_TICK *t; - int maxWidth=0; - int maxHeight=0; - - t=AQDG_Graph_Tick_List_First(tl); - while (t) { - const char *s; - - s=AQDG_Graph_Tick_GetLabel(t); - if (s && *s) { - int i; - - i=AQDG_Draw_Context_GetTextWidth(gr->drawContext, gr->fontTickLabel, s); - if (i<0) { - DBG_ERROR(0, "Invalid text width (%d)", i); - } - else { - if (i>maxWidth) - maxWidth=i; - } - i=AQDG_Draw_Context_GetTextHeight(gr->drawContext, gr->fontTickLabel, s); - if (i<0) { - DBG_ERROR(0, "Invalid text height (%d)", i); - } - else { - if (i>maxHeight) - maxHeight=i; - } - } - else { - DBG_ERROR(0, "No tick label"); - } - t=AQDG_Graph_Tick_List_Next(t); - } - - *pMaxWidth=maxWidth; - *pMaxHeight=maxHeight; - } -} - - - - - -void _sampleSizes(AQDG_GRAPH *gr, AQDG_GRAPH_DATASET *ds) -{ - AQDG_GRAPH_TICK_LIST *tl; - const char *s; - - gr->xTickLabelMaxWidth=-1; - gr->xTickLabelMaxHeight=-1; - gr->xTickLabelPosY=-1; - tl=AQDG_Graph_DataSet_GetXTickList(ds); - if (tl) - _calcTickLabelMaxSizes(gr, tl, &(gr->xTickLabelMaxWidth), &(gr->xTickLabelMaxHeight)); - - gr->yTickLabelMaxWidth=-1; - gr->yTickLabelMaxHeight=-1; - gr->yTickLabelPosX=-1; - tl=AQDG_Graph_DataSet_GetYTickList(ds); - if (tl) - _calcTickLabelMaxSizes(gr, tl, &(gr->yTickLabelMaxWidth), &(gr->yTickLabelMaxHeight)); - - /* title */ - gr->titleWidth=-1; - gr->titleHeight=-1; - gr->titlePosX=-1; - gr->titlePosY=-1; - s=AQDG_Graph_DataSet_GetTitle(ds); - if (s && *s) { - gr->titleWidth=AQDG_Draw_Context_GetTextWidth(gr->drawContext, gr->fontTitle, s); - gr->titleHeight=AQDG_Draw_Context_GetTextHeight(gr->drawContext, gr->fontTitle, s); - } - - /* subTitle */ - gr->subTitleWidth=-1; - gr->subTitleHeight=-1; - gr->subTitlePosX=-1; - gr->subTitlePosY=-1; - s=AQDG_Graph_DataSet_GetSubTitle(ds); - if (s && *s) { - gr->subTitleWidth=AQDG_Draw_Context_GetTextWidth(gr->drawContext, gr->fontSubTitle, s); - gr->subTitleHeight=AQDG_Draw_Context_GetTextHeight(gr->drawContext, gr->fontSubTitle, s); - } - - /* xLabel */ - gr->xAxisLabelWidth=-1; - gr->xAxisLabelHeight=-1; - gr->xAxisLabelPosX=-1; - gr->xAxisLabelPosY=-1; - s=AQDG_Graph_DataSet_GetLabelX(ds); - if (s && *s) { - gr->xAxisLabelWidth=AQDG_Draw_Context_GetTextWidth(gr->drawContext, gr->fontAxisLabel, s); - gr->xAxisLabelHeight=AQDG_Draw_Context_GetTextHeight(gr->drawContext, gr->fontAxisLabel, s); - } - - /* yAxisLabel */ - gr->yAxisLabelWidth=-1; - gr->yAxisLabelHeight=-1; - gr->yAxisLabelPosX=-1; - gr->yAxisLabelPosY=-1; - s=AQDG_Graph_DataSet_GetLabelY(ds); - if (s && *s) { - gr->yAxisLabelWidth=AQDG_Draw_Context_GetTextWidth(gr->drawContext, gr->fontAxisLabel, s); - gr->yAxisLabelHeight=AQDG_Draw_Context_GetTextHeight(gr->drawContext, gr->fontAxisLabel, s); - } - - gr->graphAreaWidth=-1; - gr->graphAreaHeight=-1; - gr->graphAreaPosX=-1; - gr->graphAreaPosY=-1; -} - - - -void _layout(AQDG_GRAPH *gr, AQDG_GRAPH_DATASET *ds) -{ - int graphAreaMinX; - int graphAreaMinY; - int graphAreaMaxX; - int graphAreaMaxY; - - graphAreaMinX=BORDER; - graphAreaMaxX=gr->width-BORDER-1; - graphAreaMinY=BORDER; - graphAreaMaxY=gr->height-BORDER-1; - - - /* title */ - if (gr->titleWidth>0 && gr->titleHeight>0) { - gr->titlePosX=(gr->width-gr->titleWidth)/2; - gr->titlePosY=graphAreaMinY; - graphAreaMinY+=gr->titleHeight+SMALL_BORDER; - } - - /* subtitle */ - if (gr->subTitleWidth>0 && gr->subTitleHeight>0) { - gr->subTitlePosX=(gr->width-gr->subTitleWidth)/2; - gr->subTitlePosY=graphAreaMinY; - graphAreaMinY+=gr->subTitleHeight+SMALL_BORDER; - } - - /* y-axis label */ - if (gr->yAxisLabelWidth>0 && gr->yAxisLabelHeight>0) { - gr->yAxisLabelPosX=BORDER; - gr->yAxisLabelPosY=graphAreaMinY; - graphAreaMinY+=gr->yAxisLabelHeight+BORDER; - } - - /* X-axis label */ - if (gr->xAxisLabelWidth>0 && gr->xAxisLabelHeight>0) { - gr->xAxisLabelPosX=graphAreaMaxX-gr->xAxisLabelWidth; - gr->xAxisLabelPosY=gr->height-gr->xAxisLabelHeight-BORDER; - graphAreaMaxX=gr->xAxisLabelPosX-BORDER; - } - - /* y-axis ticklabels */ - if (gr->yTickLabelMaxWidth>0 && gr->yTickLabelMaxHeight>0) { - gr->yTickLabelPosX=BORDER; - graphAreaMinX+=gr->yTickLabelMaxWidth+BORDER; - } - - /* x-axis ticklabels */ - if (gr->xTickLabelMaxWidth>0 && gr->xTickLabelMaxHeight>0) { - gr->xTickLabelPosY=gr->height-gr->xTickLabelMaxHeight-BORDER; - graphAreaMaxY=gr->xTickLabelPosY-BORDER; - } - - /* determine graphics area */ - gr->graphAreaWidth=(graphAreaMaxX-graphAreaMinX); - gr->graphAreaHeight=(graphAreaMaxY-graphAreaMinY); - gr->graphAreaPosX=graphAreaMinX; - gr->graphAreaPosY=graphAreaMinY; - -} - - - -void _calcGraphArea(AQDG_GRAPH *gr, AQDG_GRAPH_DATASET *ds) -{ - double minVal; - double maxVal; - double dist; - - /* determine X-offset of graph origin and xFactor */ - minVal=AQDG_Graph_DataSet_GetMinValueX(ds); - maxVal=AQDG_Graph_DataSet_GetMaxValueX(ds); - gr->graphFactorX=gr->graphAreaWidth/(maxVal-minVal); - if (minVal<=0.0 && maxVal>=0.0) { - /* one negative, the other positive */ - dist=-minVal; - gr->graphOriginX=gr->graphAreaPosX+dist*gr->graphFactorX; - } - else if (minVal<0.0 && maxVal<0.0) { - /* both negative */ - dist=-minVal; - gr->graphOriginX=gr->graphAreaPosX+dist*gr->graphFactorX; - } - else if (minVal>0.0 && maxVal>=0.0) { - /* both positive */ - dist=minVal; - gr->graphOriginX=gr->graphAreaPosX-dist*gr->graphFactorX; - } - - /* determine x-pos of the y-axis */ - if (gr->graphOriginXgraphAreaPosX) { - /* y-axis on left border */ - gr->yAxisPosX=gr->graphAreaPosX; - } - else if (gr->graphOriginX>=gr->graphAreaWidth) { - /* y-axis on right border */ - gr->yAxisPosX=gr->graphAreaPosX+gr->graphAreaWidth-1; - } - else { - /* y-axis somewhere within the graph area */ - gr->yAxisPosX=gr->graphOriginX; - } - - - /* determine Y-offset of graph origin and yFactor */ - minVal=AQDG_Graph_DataSet_GetMinValueY(ds); - maxVal=AQDG_Graph_DataSet_GetMaxValueY(ds); - gr->graphFactorY=gr->graphAreaHeight/(maxVal-minVal); - if (minVal<=0.0 && maxVal>=0.0) { - /* one negative, the other positive */ - dist=maxVal; - gr->graphOriginY=gr->graphAreaPosY+(dist*gr->graphFactorY); - } - else if (minVal<0.0 && maxVal<0.0) { - /* both negative */ - dist=maxVal; - gr->graphOriginY=gr->graphAreaPosY+dist*gr->graphFactorY; - } - else if (minVal>0.0 && maxVal>0.0) { - /* both positive */ - dist=maxVal; - gr->graphOriginY=gr->graphAreaPosY+(dist*gr->graphFactorY); - } - - /* determine y-pos of the x-axis */ - if (gr->graphOriginYgraphAreaPosY) { - /* y-axis on upper border */ - gr->xAxisPosY=gr->graphAreaPosY; - } - else if (gr->graphOriginY>=gr->graphAreaHeight) { - /* y-axis on lower border */ - gr->xAxisPosY=gr->graphAreaPosY+gr->graphAreaHeight-1; - } - else { - /* y-axis somewhere within the graph area */ - gr->xAxisPosY=gr->graphOriginY; - } - - DBG_ERROR(0, "Origin: %d / %d (Axis: x-axis y=%d / y-axis x=%d)", - gr->graphOriginX, gr->graphOriginY, - gr->xAxisPosY, gr->yAxisPosX); -} - - - - diff --git a/src/lib/aqdiagram/graph/o_graph.c b/src/lib/aqdiagram/graph/o_graph.c new file mode 100644 index 0000000..7b02fb7 --- /dev/null +++ b/src/lib/aqdiagram/graph/o_graph.c @@ -0,0 +1,414 @@ +/**************************************************************************** + * This file is part of the project AqDiagram. + * AqDiagram (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "./o_graph_p.h" + +#include "aqdiagram/draw/w_vlayout.h" +#include "aqdiagram/draw/w_mlayout.h" +#include "aqdiagram/draw/w_drawable.h" +#include "aqdiagram/draw/w_label.h" + +#include + + + +/* ------------------------------------------------------------------------------------------------ + * forward declarations + * ------------------------------------------------------------------------------------------------ + */ + +static GWENHYWFAR_CB void _freeData(void *bp, void *p); +AQDG_OBJECT *_createLabel(AQDG_OBJECT *o, AQDG_OBJECT *parent, uint32_t options, const char *s, int penIdx, int fontIdx); + + + +/* ------------------------------------------------------------------------------------------------ + * vars + * ------------------------------------------------------------------------------------------------ + */ + +static uint32_t _curveColors[]={ + AQDG_GRAPH_COL_LIME, + AQDG_GRAPH_COL_BLUE, + AQDG_GRAPH_COL_CYAN, + AQDG_GRAPH_COL_MAGENTA, + AQDG_GRAPH_COL_GREEN, + AQDG_GRAPH_COL_TURQUOISE, + AQDG_GRAPH_COL_DEEPPINK, + AQDG_GRAPH_COL_NAVY +}; + + + +/* ------------------------------------------------------------------------------------------------ + * implementations + * ------------------------------------------------------------------------------------------------ + */ + +GWEN_INHERIT(AQDG_OBJECT, AQDG_OBJECT_GRAPH); + + + +AQDG_OBJECT *AQDG_GraphObject_new(AQDG_OBJECT *parent, uint32_t options, AQDG_DRAW_CONTEXT *drawContext, AQDG_GRAPH *graph) +{ + AQDG_OBJECT *object; + AQDG_OBJECT_GRAPH *xo; + + object=AQDG_VLayoutWidget_new(parent, options, drawContext); + AQDG_Object_SetName(object, "GraphObject"); + GWEN_NEW_OBJECT(AQDG_OBJECT_GRAPH, xo); + GWEN_INHERIT_SETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, object, xo, _freeData); + + xo->graph=graph; + + return object; +} + + + +GWENHYWFAR_CB void _freeData(void *bp, void *p) +{ + AQDG_OBJECT_GRAPH *xo; + + xo=(AQDG_OBJECT_GRAPH*) p; + AQDG_Graph_free(xo->graph); + GWEN_FREE_OBJECT(p); +} + + + +void _setupObjectTree(AQDG_OBJECT *o) +{ + AQDG_OBJECT_GRAPH *xo; + AQDG_OBJECT *oMatrix; + const char *s; + int matrixColumns=1; + + xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o); + + s=AQDG_Graph_GetTitle(xo->graph); + if (s) + _createLabel(o, + o, + AQDG_OBJECT_OPTIONS_STRETCHX | AQDG_OBJECT_OPTIONS_HALIGNCENTER, + s, + AQDG_GRAPHOBJECT_PEN_IDX_TITLE, + AQDG_GRAPHOBJECT_FONT_IDX_TITLE); + + s=AQDG_Graph_GetSubTitle(xo->graph); + if (s) + _createLabel(o, + o, + AQDG_OBJECT_OPTIONS_STRETCHX | AQDG_OBJECT_OPTIONS_HALIGNCENTER, + s, + AQDG_GRAPHOBJECT_PEN_IDX_SUBTITLE, + AQDG_GRAPHOBJECT_FONT_IDX_SUBTITLE); + + if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_LEFT)) + matrixColumns++; + if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_RIGHT)) + matrixColumns++; + oMatrix=AQDG_MatrixLayoutWidgetByRows_new(o, + AQDG_OBJECT_OPTIONS_STRETCHX | AQDG_OBJECT_OPTIONS_STRETCHY, + AQDG_DrawableWidget_GetDrawContext(o), + matrixColumns); + +} + + + +AQDG_OBJECT *_createLabel(AQDG_OBJECT *o, AQDG_OBJECT *parent, uint32_t options, const char *s, int penIdx, int fontIdx) +{ + AQDG_OBJECT *oLabel; + int penId; + int fontId; + + penId=AQDG_GraphObject_GetPen(o, penIdx); + fontId=AQDG_GraphObject_GetFont(o, fontIdx); + oLabel=AQDG_LabelWidget_new(o, options, AQDG_DrawableWidget_GetDrawContext(o), s); + if (penId!=-1) + AQDG_DrawableWidget_SetForegroundPenId(oLabel, penId); + if (fontId!=-1) + AQDG_DrawableWidget_SetFontId(oLabel, fontId); + + return oLabel; +} + + + +void _presetPens(AQDG_OBJECT *o) +{ + if (o) { + AQDG_OBJECT_GRAPH *xo; + + xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o); + if (xo) { + int i; + + for (i=0; ipenArray[i]=-1; + } + } +} + + + +void _presetFonts(AQDG_OBJECT *o) +{ + if (o) { + AQDG_OBJECT_GRAPH *xo; + + xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o); + if (xo) { + int i; + + for (i=0; ifontArray[i]=-1; + } + } +} + + + +void _releasePens(AQDG_OBJECT *o) +{ + if (o) { + AQDG_OBJECT_GRAPH *xo; + + xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o); + if (xo) { + AQDG_DRAW_CONTEXT *dc; + int i; + + dc=AQDG_DrawableWidget_GetDrawContext(o); + for (i=0; ipenArray[i]); + xo->penArray[i]=-1; + } + } + } +} + + + +void _releaseFonts(AQDG_OBJECT *o) +{ + if (o) { + AQDG_OBJECT_GRAPH *xo; + + xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o); + if (xo) { + AQDG_DRAW_CONTEXT *dc; + int i; + + dc=AQDG_DrawableWidget_GetDrawContext(o); + for (i=0; ifontArray[i]); + xo->fontArray[i]=-1; + } + } + } +} + + + + + + +AQDG_GRAPH *AQDG_GraphObject_GetGraph(const AQDG_OBJECT *o) +{ + if (o) { + AQDG_OBJECT_GRAPH *xo; + + xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o); + if (xo) + return xo->graph; + } + return NULL; +} + + + + +int AQDG_GraphObject_GetPen(const AQDG_OBJECT *o, int idx) +{ + if (o && idxpenArray[idx]; + } + + return -1; +} + + + +void AQDG_GraphObject_SetPen(AQDG_OBJECT *o, int idx, int penId) +{ + if (o && idxpenArray[idx]=penId; + } +} + + + +int AQDG_GraphObject_GetFont(const AQDG_OBJECT *o, int idx) +{ + if (o && idxfontArray[idx]; + } + + return -1; +} + + + +void AQDG_GraphObject_SetFont(AQDG_OBJECT *o, int idx, int fontId) +{ + if (o && idxfontArray[idx]=fontId; + } +} + + + +int AQDG_GraphObject_CreatePenFromDb(AQDG_OBJECT *o, GWEN_DB_NODE *db, const char *name, uint32_t defColor, int defWidth, int defDash) +{ + if (o) { + AQDG_OBJECT_GRAPH *xo; + + xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o); + if (xo) { + uint32_t frontColour; + int lineWidth; + int dashType; + int rv; + GWEN_BUFFER *nameBuf; + int bufPos; + AQDG_DRAW_CONTEXT *dc; + + dc=AQDG_DrawableWidget_GetDrawContext(o); + + nameBuf=GWEN_Buffer_new(0, 64, 0, 1); + GWEN_Buffer_AppendString(nameBuf, name); + bufPos=GWEN_Buffer_GetPos(nameBuf); + + /* RGBA */ + GWEN_Buffer_AppendString(nameBuf, "color"); + frontColour=(uint32_t)GWEN_DB_GetIntValue(db, GWEN_Buffer_GetStart(nameBuf), 0, (int)defColor); + + GWEN_Buffer_Crop(nameBuf, 0, bufPos); + GWEN_Buffer_AppendString(nameBuf, "width"); + lineWidth=GWEN_DB_GetIntValue(db, GWEN_Buffer_GetStart(nameBuf), 0, defWidth); + + GWEN_Buffer_Crop(nameBuf, 0, bufPos); + GWEN_Buffer_AppendString(nameBuf, "dash"); + dashType=GWEN_DB_GetIntValue(db, "dashType", 0, defDash); + + GWEN_Buffer_free(nameBuf); + + rv=AQDG_Draw_Context_PenCreate(dc, frontColour, lineWidth, dashType); + if (rv<0) { + DBG_INFO(AQDG_LOGDOMAIN, "here (%d)", rv); + return rv; + } + + return rv; + } + } + return -1; +} + + + +int AQDG_GraphObject_CreateFontFromDb(AQDG_OBJECT *o, GWEN_DB_NODE *db, const char *name, int defaultFontSize) +{ + if (o) { + AQDG_OBJECT_GRAPH *xo; + + xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o); + if (xo) { + const char *fontName; + int fontSize; + int fontSlant; + int fontWeight; + int rv; + GWEN_BUFFER *nameBuf; + int bufPos; + AQDG_DRAW_CONTEXT *dc; + + dc=AQDG_DrawableWidget_GetDrawContext(o); + + nameBuf=GWEN_Buffer_new(0, 64, 0, 1); + GWEN_Buffer_AppendString(nameBuf, name); + bufPos=GWEN_Buffer_GetPos(nameBuf); + + GWEN_Buffer_AppendString(nameBuf, "name"); + fontName=GWEN_DB_GetCharValue(db, GWEN_Buffer_GetStart(nameBuf), 0, ""); + + GWEN_Buffer_Crop(nameBuf, 0, bufPos); + GWEN_Buffer_AppendString(nameBuf, "size"); + fontSize=GWEN_DB_GetIntValue(db, GWEN_Buffer_GetStart(nameBuf), 0, defaultFontSize); + + GWEN_Buffer_Crop(nameBuf, 0, bufPos); + GWEN_Buffer_AppendString(nameBuf, "slant"); + fontSlant=AQDG_Slant_fromString(GWEN_DB_GetCharValue(db, GWEN_Buffer_GetStart(nameBuf), 0, "none")); + + GWEN_Buffer_Crop(nameBuf, 0, bufPos); + GWEN_Buffer_AppendString(nameBuf, "weight"); + fontWeight=AQDG_Weight_fromString(GWEN_DB_GetCharValue(db, GWEN_Buffer_GetStart(nameBuf), 0, "none")); + + GWEN_Buffer_free(nameBuf); + + rv=AQDG_Draw_Context_FontCreate(dc, fontName, fontSize, fontSlant, fontWeight); + if (rv<0) { + DBG_INFO(0, "here (%d)", rv); + return rv; + } + + return rv; + } + } + return -1; +} + + + +uint32_t AQDG_GraphObject_GetStandardCurveColor(int idx, uint32_t defCol) +{ + if (idx +#include + + + +/* see https://www.rapidtables.com/web/color/RGB_Color.html */ +#define AQDG_GRAPHOBJECT_COL_BLACK ((uint32_t) 0x00000000) +#define AQDG_GRAPHOBJECT_COL_WHITE ((uint32_t) 0xFFFFFF00) +#define AQDG_GRAPHOBJECT_COL_RED ((uint32_t) 0xFF000000) +#define AQDG_GRAPHOBJECT_COL_LIME ((uint32_t) 0x00FF0000) +#define AQDG_GRAPHOBJECT_COL_BLUE ((uint32_t) 0x0000FF00) +#define AQDG_GRAPHOBJECT_COL_YELLOW ((uint32_t) 0xFFFF0000) +#define AQDG_GRAPHOBJECT_COL_CYAN ((uint32_t) 0x00FFFF00) +#define AQDG_GRAPHOBJECT_COL_MAGENTA ((uint32_t) 0xFF00FF00) +#define AQDG_GRAPHOBJECT_COL_SILVER ((uint32_t) 0xC0C0C000) +#define AQDG_GRAPHOBJECT_COL_GRAY ((uint32_t) 0x80808000) +#define AQDG_GRAPHOBJECT_COL_MAROON ((uint32_t) 0x80000000) +#define AQDG_GRAPHOBJECT_COL_OLIVE ((uint32_t) 0x80800000) +#define AQDG_GRAPHOBJECT_COL_GREEN ((uint32_t) 0x00800000) +#define AQDG_GRAPHOBJECT_COL_PURPLE ((uint32_t) 0x80008000) +#define AQDG_GRAPHOBJECT_COL_TEAL ((uint32_t) 0x00808000) +#define AQDG_GRAPHOBJECT_COL_NAVY ((uint32_t) 0x00008000) + +#define AQDG_GRAPHOBJECT_COL_ORANGE ((uint32_t) 0xFFA50000) +#define AQDG_GRAPHOBJECT_COL_GOLD ((uint32_t) 0xFFD70000) +#define AQDG_GRAPHOBJECT_COL_TURQUOISE ((uint32_t) 0x40E0D000) +#define AQDG_GRAPHOBJECT_COL_SKYBLUE ((uint32_t) 0x87CEEB00) +#define AQDG_GRAPHOBJECT_COL_DEEPPINK ((uint32_t) 0xFF149300) +#define AQDG_GRAPHOBJECT_COL_COMSILK ((uint32_t) 0xFFF8DC00) +#define AQDG_GRAPHOBJECT_COL_GAINSBORO ((uint32_t) 0xDCDCDC00) +#define AQDG_GRAPHOBJECT_COL_WHITESMOKE ((uint32_t) 0xF5F5F500) + + +enum { + AQDG_GRAPHOBJECT_PEN_IDX_TITLE=0, + AQDG_GRAPHOBJECT_PEN_IDX_SUBTITLE, + AQDG_GRAPHOBJECT_PEN_IDX_AXISLINE, + AQDG_GRAPHOBJECT_PEN_IDX_AXISLABEL, + AQDG_GRAPHOBJECT_PEN_IDX_TICKLABELMAINLEVEL, + AQDG_GRAPHOBJECT_PEN_IDX_TICKLABELSUBLEVEL, + AQDG_GRAPHOBJECT_PEN_IDX_TICKMAINLEVEL, + AQDG_GRAPHOBJECT_PEN_IDX_TICKSUBLEVEL, + AQDG_GRAPHOBJECT_PEN_IDX_GRAPHBACKGROUND, + AQDG_GRAPHOBJECT_PEN_IDX_GRID, + AQDG_GRAPHOBJECT_PEN_IDX_BACKGROUND, + AQDG_GRAPHOBJECT_PEN_IDX_CURVE0, + AQDG_GRAPHOBJECT_PEN_IDX_CURVE1, + AQDG_GRAPHOBJECT_PEN_IDX_CURVE2, + AQDG_GRAPHOBJECT_PEN_IDX_CURVE3, + AQDG_GRAPHOBJECT_PEN_IDX_CURVE4, + AQDG_GRAPHOBJECT_PEN_IDX_CURVE5, + AQDG_GRAPHOBJECT_PEN_IDX_CURVE6, + AQDG_GRAPHOBJECT_PEN_IDX_CURVE7, + + AQDG_GRAPHOBJECT_PEN_IDX_LAST +}; + + + +enum { + AQDG_GRAPHOBJECT_FONT_IDX_TITLE=0, + AQDG_GRAPHOBJECT_FONT_IDX_SUBTITLE, + AQDG_GRAPHOBJECT_FONT_IDX_AXISLABEL, + AQDG_GRAPHOBJECT_FONT_IDX_TICKLABELMAINLEVEL, + AQDG_GRAPHOBJECT_FONT_IDX_TICKLABELSUBLEVEL, + + AQDG_GRAPHOBJECT_FONT_IDX_LAST +}; + + + + +AQDG_OBJECT *AQDG_GraphObject_new(AQDG_OBJECT *parent, uint32_t options, AQDG_DRAW_CONTEXT *drawContext, AQDG_GRAPH *graph); + + +AQDG_GRAPH *AQDG_GraphObject_GetGraph(const AQDG_OBJECT *o); + + +int AQDG_GraphObject_GetPen(const AQDG_OBJECT *o, int idx); +void AQDG_GraphObject_SetPen(AQDG_OBJECT *o, int idx, int penId); + +int AQDG_GraphObject_GetFont(const AQDG_OBJECT *o, int idx); +void AQDG_GraphObject_SetFont(AQDG_OBJECT *o, int idx, int fontId); + +int AQDG_GraphObject_CreatePenFromDb(AQDG_OBJECT *o, GWEN_DB_NODE *db, const char *name, uint32_t defColor, int defWidth, int defDash); +int AQDG_GraphObject_CreateFontFromDb(AQDG_OBJECT *o, GWEN_DB_NODE *db, const char *name, int defaultFontSize); +uint32_t AQDG_GraphObject_GetStandardCurveColor(int idx, uint32_t defCol); + + +#endif + diff --git a/src/lib/aqdiagram/graph/o_graph_p.h b/src/lib/aqdiagram/graph/o_graph_p.h new file mode 100644 index 0000000..2897b6f --- /dev/null +++ b/src/lib/aqdiagram/graph/o_graph_p.h @@ -0,0 +1,43 @@ +/**************************************************************************** + * This file is part of the project AqDiagram. + * AqDiagram (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifndef AQDG_GRAPH_O_GRAPH_P_H +#define AQDG_GRAPH_O_GRAPH_P_H + +#include + + +#define AQDG_GRAPHOBJECT_NUMPENS AQDG_GRAPHOBJECT_PEN_IDX_LAST +#define AQDG_GRAPHOBJECT_NUMFONTS AQDG_GRAPHOBJECT_FONT_IDX_LAST + + + + + +typedef struct AQDG_OBJECT_GRAPH AQDG_OBJECT_GRAPH; +struct AQDG_OBJECT_GRAPH { + AQDG_GRAPH *graph; + + int penArray[AQDG_GRAPHOBJECT_NUMPENS]; + int fontArray[AQDG_GRAPHOBJECT_NUMFONTS]; + + + AQDG_OBJECT *xAxisTopObject; + AQDG_OBJECT *xAxisBottomObject; + AQDG_OBJECT *yAxisLeftObject; + AQDG_OBJECT *yAxisRightObject; + AQDG_OBJECT *graphViewport; + AQDG_OBJECT *legendObject; + AQDG_OBJECT *titleLabel; + AQDG_OBJECT *subtitleLabel; +}; + + + +#endif + diff --git a/src/lib/aqdiagram/graph/o_xaxis.c b/src/lib/aqdiagram/graph/o_xaxis.c new file mode 100644 index 0000000..9db4d78 --- /dev/null +++ b/src/lib/aqdiagram/graph/o_xaxis.c @@ -0,0 +1,65 @@ +/**************************************************************************** + * This file is part of the project AqDiagram. + * AqDiagram (c) by 2024 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "./o_xaxis_p.h" +#include "aqdiagram/draw/w_drawable.h" + + + +/* ------------------------------------------------------------------------------------------------ + * forward declarations + * ------------------------------------------------------------------------------------------------ + */ + +static GWENHYWFAR_CB void _freeData(void *bp, void *p); + + + +/* ------------------------------------------------------------------------------------------------ + * implementations + * ------------------------------------------------------------------------------------------------ + */ + +GWEN_INHERIT(AQDG_OBJECT, AQDG_OBJECT_XAXIS); + + + +AQDG_OBJECT *AQDG_XAxisObject_new(AQDG_OBJECT *parent, uint32_t options, AQDG_OBJECT *graphObject) +{ + AQDG_OBJECT *o; + AQDG_OBJECT_XAXIS *xo; + + o=AQDG_DrawableWidget_new(parent, options, AQDG_DrawableWidget_GetDrawContext(graphObject)); + AQDG_Object_SetName(object, "XAxisObject"); + GWEN_NEW_OBJECT(AQDG_OBJECT_XAXIS, xo); + GWEN_INHERIT_SETDATA(AQDG_OBJECT, AQDG_OBJECT_XAXIS, o, xo, _freeData); + + xo->graphObject=graphObject; + + return o; +} + + + + +GWENHYWFAR_CB void _freeData(void *bp, void *p) +{ + AQDG_OBJECT_XAXIS *xo; + + xo=(AQDG_OBJECT_XAXIS*) p; + + GWEN_FREE_OBJECT(xo); +} + + + + diff --git a/src/lib/aqdiagram/graph/draw.h b/src/lib/aqdiagram/graph/o_xaxis.h similarity index 57% rename from src/lib/aqdiagram/graph/draw.h rename to src/lib/aqdiagram/graph/o_xaxis.h index 54a81c8..4487df6 100644 --- a/src/lib/aqdiagram/graph/draw.h +++ b/src/lib/aqdiagram/graph/o_xaxis.h @@ -1,22 +1,20 @@ /**************************************************************************** * This file is part of the project AqDiagram. - * AqDiagram (c) by 2022 Martin Preuss, all rights reserved. + * AqDiagram (c) by 2023 Martin Preuss, all rights reserved. * * The license for this file can be found in the file COPYING which you * should have received along with this file. ****************************************************************************/ +#ifndef AQDG_GRAPH_O_XAXIS_H +#define AQDG_GRAPH_O_XAXIS_H -#ifndef AQDG_GRAPH_DRAW_H -#define AQDG_GRAPH_DRAW_H +#include -#include +AQDG_OBJECT *AQDG_XAxisObject_new(AQDG_OBJECT *parent, uint32_t options, AQDG_OBJECT *graphObject); -void AQDG_Graph_DrawFramework(AQDG_GRAPH *gr); - - #endif diff --git a/src/lib/aqdiagram/graph/layout.h b/src/lib/aqdiagram/graph/o_xaxis_p.h similarity index 55% rename from src/lib/aqdiagram/graph/layout.h rename to src/lib/aqdiagram/graph/o_xaxis_p.h index b976b6a..c24ed84 100644 --- a/src/lib/aqdiagram/graph/layout.h +++ b/src/lib/aqdiagram/graph/o_xaxis_p.h @@ -1,22 +1,23 @@ /**************************************************************************** * This file is part of the project AqDiagram. - * AqDiagram (c) by 2022 Martin Preuss, all rights reserved. + * AqDiagram (c) by 2023 Martin Preuss, all rights reserved. * * The license for this file can be found in the file COPYING which you * should have received along with this file. ****************************************************************************/ +#ifndef AQDG_GRAPH_O_XAXIS_P_H +#define AQDG_GRAPH_O_XAXIS_P_H -#ifndef AQDG_GRAPH_LAYOUT_H -#define AQDG_GRAPH_LAYOUT_H +#include -#include +typedef struct AQDG_OBJECT_XAXIS AQDG_OBJECT_XAXIS; +struct AQDG_OBJECT_XAXIS { + AQDG_OBJECT *graphObject; +}; -void AQDG_Graph_PrepareGraph(AQDG_GRAPH *gr); - - #endif diff --git a/src/lib/aqdiagram/graph/settings.xml b/src/lib/aqdiagram/graph/settings.xml deleted file mode 100644 index 6c06479..0000000 --- a/src/lib/aqdiagram/graph/settings.xml +++ /dev/null @@ -1,259 +0,0 @@ - - - - - - This class describes data axis. - - - AQDG_GRAPH_SETTINGS - AQDG_Graph_Settings - settings - - - with_db - with_xml - with_list1 - with_list2 - with_refcount - - - -
aqdiagram/aqdg_api.h
-
aqdiagram/draw/context.h
- -
aqdiagram/graph/graph.h
-
aqdiagram/graph/settings_pen.h
-
aqdiagram/graph/settings_font.h
- -
- - - - - - - $(api) void $(struct_prefix)_SetDefaults($(struct_type) *st); - - - - - - void $(struct_prefix)_SetDefaults($(struct_type) *rs) { - AQDG_GRAPH_SETTINGS_PEN *pen; - AQDG_GRAPH_SETTINGS_FONT *font; - - assert(rs); - - pen=AQDG_Graph_SettingsPen_new(); - AQDG_Graph_SettingsPen_SetFrontColour(pen, (int)0x00000000); - AQDG_Graph_SettingsPen_SetLineWidth(pen, 1); - AQDG_Graph_SettingsPen_SetDashType(pen, 0); - $(struct_prefix)_SetPenTitle(rs, pen); - - pen=AQDG_Graph_SettingsPen_new(); - AQDG_Graph_SettingsPen_SetFrontColour(pen, (int)0xff000000); - AQDG_Graph_SettingsPen_SetLineWidth(pen, 1); - AQDG_Graph_SettingsPen_SetDashType(pen, 0); - $(struct_prefix)_SetPenSubTitle(rs, pen); - - pen=AQDG_Graph_SettingsPen_new(); - AQDG_Graph_SettingsPen_SetFrontColour(pen, (int)0x0000000); - AQDG_Graph_SettingsPen_SetLineWidth(pen, 1); - AQDG_Graph_SettingsPen_SetDashType(pen, 0); - $(struct_prefix)_SetPenAxisLabel(rs, pen); - - pen=AQDG_Graph_SettingsPen_new(); - AQDG_Graph_SettingsPen_SetFrontColour(pen, (int)0x0000ff00); - AQDG_Graph_SettingsPen_SetLineWidth(pen, 1); - AQDG_Graph_SettingsPen_SetDashType(pen, 0); - $(struct_prefix)_SetPenAxis(rs, pen); - - pen=AQDG_Graph_SettingsPen_new(); - AQDG_Graph_SettingsPen_SetFrontColour(pen, (int)0x00ff0000); - AQDG_Graph_SettingsPen_SetLineWidth(pen, 1); - AQDG_Graph_SettingsPen_SetDashType(pen, 0); - $(struct_prefix)_SetPenGraph(rs, pen); - - pen=AQDG_Graph_SettingsPen_new(); - AQDG_Graph_SettingsPen_SetFrontColour(pen, (int)0xffec5b00); - AQDG_Graph_SettingsPen_SetLineWidth(pen, 1); - AQDG_Graph_SettingsPen_SetDashType(pen, 0); - $(struct_prefix)_SetPenGraphBackground(rs, pen); - - pen=AQDG_Graph_SettingsPen_new(); - AQDG_Graph_SettingsPen_SetFrontColour(pen, (int)0xc0c0c000); - AQDG_Graph_SettingsPen_SetLineWidth(pen, 1); - AQDG_Graph_SettingsPen_SetDashType(pen, 1); - $(struct_prefix)_SetPenGrid(rs, pen); - - pen=AQDG_Graph_SettingsPen_new(); - AQDG_Graph_SettingsPen_SetFrontColour(pen, (int)0xffffff00); - AQDG_Graph_SettingsPen_SetLineWidth(pen, 1); - AQDG_Graph_SettingsPen_SetDashType(pen, 0); - $(struct_prefix)_SetPenBackground(rs, pen); - - - font=AQDG_Graph_SettingsFont_new(); - AQDG_Graph_SettingsFont_SetFontSize(font, 20); - AQDG_Graph_SettingsFont_SetFontSlant(font, AQDG_Slant_None); - AQDG_Graph_SettingsFont_SetFontWeight(font, AQDG_Weight_Bold); - $(struct_prefix)_SetFontTitle(rs, font); - - font=AQDG_Graph_SettingsFont_new(); - AQDG_Graph_SettingsFont_SetFontSize(font, 16); - AQDG_Graph_SettingsFont_SetFontSlant(font, AQDG_Slant_Italic); - AQDG_Graph_SettingsFont_SetFontWeight(font, AQDG_Weight_None); - $(struct_prefix)_SetFontSubTitle(rs, font); - - font=AQDG_Graph_SettingsFont_new(); - AQDG_Graph_SettingsFont_SetFontSize(font, 12); - AQDG_Graph_SettingsFont_SetFontSlant(font, AQDG_Slant_None); - AQDG_Graph_SettingsFont_SetFontWeight(font, AQDG_Weight_None); - $(struct_prefix)_SetFontAxisLabel(rs, font); - - font=AQDG_Graph_SettingsFont_new(); - AQDG_Graph_SettingsFont_SetFontSize(font, 9); - AQDG_Graph_SettingsFont_SetFontSlant(font, AQDG_Slant_None); - AQDG_Graph_SettingsFont_SetFontWeight(font, AQDG_Weight_None); - $(struct_prefix)_SetFontTickLabel(rs, font); - - $(struct_prefix)_AddFlags(rs, AQDG_GRAPH_FLAGS_WITH_GRID); - } - - - - - - - - -
- - - - - - - - - - - - - 0 - 0 - public - with_getbymember - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - public - own - assign - - - - 0 - 0 - with_flags - public - - - - - -
- -
- diff --git a/src/lib/aqdiagram/graph/settings_font.xml b/src/lib/aqdiagram/graph/settings_font.xml deleted file mode 100644 index 808817b..0000000 --- a/src/lib/aqdiagram/graph/settings_font.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - This class describes data axis. - - - AQDG_GRAPH_SETTINGS_FONT - AQDG_Graph_SettingsFont - settings_font - - - with_db - with_xml - with_list1 - with_list2 - with_refcount - - - -
aqdiagram/aqdg_api.h
-
- -
- - - - - - - - - - - - - 0 - 0 - public - - - - 0 - 0 - public - - - - 0 - 0 - public - - - - - - - 0 - 0 - with_flags - public - - - - - 0 - 0 - public - volatile with_getbymember - - - - - -
- -
- diff --git a/src/lib/aqdiagram/graph/settings_pen.xml b/src/lib/aqdiagram/graph/settings_pen.xml deleted file mode 100644 index 3956be2..0000000 --- a/src/lib/aqdiagram/graph/settings_pen.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - This class describes data axis. - - - AQDG_GRAPH_SETTINGS_PEN - AQDG_Graph_SettingsPen - settings_pen - - - with_db - with_xml - with_list1 - with_list2 - with_refcount - - - -
aqdiagram/aqdg_api.h
-
- -
- - - - - - - - - - - - - 0 - 0 - public - - - - 0 - 0 - public - - - - 1 - 1 - public - - - - - 0 - 0 - public - - - - - - - 0 - 0 - with_flags - public - - - - - 0 - 0 - public - volatile with_getbymember - - - - - -
- -
- diff --git a/src/lib/aqdiagram/graph/setup.c b/src/lib/aqdiagram/graph/setup.c deleted file mode 100644 index 567fe7b..0000000 --- a/src/lib/aqdiagram/graph/setup.c +++ /dev/null @@ -1,516 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqFinance. - * AqFinance (c) by 2011 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqdiagram/graph/setup.h" -#include "aqdiagram/graph/tick_fns.h" -#include "graph_p.h" - -#include - - - -static int _createPenFromDb(AQDG_GRAPH *gr, GWEN_DB_NODE *dbConfig, const char *name); -static int _createFontFromDb(AQDG_GRAPH *gr, GWEN_DB_NODE *dbConfig, const char *name, int defaultFontSize); -static int _createPensAndFontsFromDb(AQDG_GRAPH *gr, GWEN_DB_NODE *dbConfig); - -static int _createPenFromSettings(AQDG_GRAPH *gr, const AQDG_GRAPH_SETTINGS_PEN *sp); -static int _createFontFromSettings(AQDG_GRAPH *gr, const AQDG_GRAPH_SETTINGS_FONT *sf); -static int _createPensAndFontsFromSettings(AQDG_GRAPH *gr, const AQDG_GRAPH_SETTINGS *settings); - -static void _releasePensAndFonts(AQDG_GRAPH *gr); - - - -int AQDG_Graph_InitFromDb(AQDG_GRAPH *gr, GWEN_DB_NODE *dbConfig) -{ - int rv; - int i; - uint32_t flags=0; - - rv=_createPensAndFontsFromDb(gr, dbConfig); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - - for (i=0; i<100; i++) { - const char *s; - - s=GWEN_DB_GetCharValue(dbConfig, "flags", i, NULL); - if (!(s && *s)) - break; - if (strcasecmp(s, "grid")==0) - flags|=AQDG_GRAPH_FLAGS_WITH_GRID; - } - gr->flags=flags; - - - return 0; -} - - - -int AQDG_Graph_InitFromSettings(AQDG_GRAPH *gr, const AQDG_GRAPH_SETTINGS *gs) -{ - int rv; - - rv=_createPensAndFontsFromSettings(gr, gs); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - - gr->flags=AQDG_Graph_Settings_GetFlags(gs); - - return 0; -} - - - -int AQDG_Graph_Fini(AQDG_GRAPH *gr) -{ - _releasePensAndFonts(gr); - - return 0; -} - - - -int _createPenFromDb(AQDG_GRAPH *gr, GWEN_DB_NODE *dbConfig, const char *name) -{ - GWEN_DB_NODE *db; - uint32_t frontColour; - int lineWidth; - int dashType; - int rv; - - db=GWEN_DB_GetGroup(dbConfig, 0, name); - assert(db); - frontColour=(uint32_t)GWEN_DB_GetIntValue(db, "frontColour", 0, (int)0x000000ff); - lineWidth=GWEN_DB_GetIntValue(db, "lineWidth", 0, 1); - dashType=GWEN_DB_GetIntValue(db, "dashType", 0, 0); - - rv=AQDG_Draw_Context_PenCreate(gr->drawContext, frontColour, lineWidth, dashType); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - - return rv; -} - - - -int _createFontFromDb(AQDG_GRAPH *gr, GWEN_DB_NODE *dbConfig, const char *name, int defaultFontSize) -{ - GWEN_DB_NODE *db; - const char *fontName; - int fontSize; - int fontSlant; - int fontWeight; - int rv; - - db=GWEN_DB_GetGroup(dbConfig, 0, name); - assert(db); - - - fontName=GWEN_DB_GetCharValue(db, "fontName", 0, ""); - fontSize=GWEN_DB_GetIntValue(db, "fontSize", 0, defaultFontSize); - fontSlant=AQDG_Slant_fromString(GWEN_DB_GetCharValue(db, "fontSlant", 0, "none")); - fontWeight=AQDG_Weight_fromString(GWEN_DB_GetCharValue(db, "fontWeight", 0, "none")); - - rv=AQDG_Draw_Context_FontCreate(gr->drawContext, fontName, fontSize, fontSlant, fontWeight); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - - return rv; -} - - - - -int _createPensAndFontsFromDb(AQDG_GRAPH *gr, GWEN_DB_NODE *dbConfig) -{ - int rv; - AQDG_GRAPH_SUBGRAPH_LIST *sgList; - - rv=_createPenFromDb(gr, dbConfig, "penTitle"); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penTitle=rv; - - rv=_createPenFromDb(gr, dbConfig, "penSubTitle"); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penSubTitle=rv; - - rv=_createPenFromDb(gr, dbConfig, "penAxisLabel"); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penAxisLabel=rv; - - rv=_createPenFromDb(gr, dbConfig, "penAxis"); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penAxis=rv; - - rv=_createPenFromDb(gr, dbConfig, "penGraph"); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penGraph=rv; - - rv=_createPenFromDb(gr, dbConfig, "penGraphBackground"); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penGraphBackground=rv; - - rv=_createPenFromDb(gr, dbConfig, "penGrid"); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penGrid=rv; - - rv=_createPenFromDb(gr, dbConfig, "penBackground"); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penBackground=rv; - - - - rv=_createFontFromDb(gr, dbConfig, "fontTitle", 16); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->fontTitle=rv; - - rv=_createFontFromDb(gr, dbConfig, "fontSubTitle", 14); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->fontSubTitle=rv; - - rv=_createFontFromDb(gr, dbConfig, "fontAxisLabel", 12); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->fontAxisLabel=rv; - - rv=_createFontFromDb(gr, dbConfig, "fontTickLabel", 10); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->fontTickLabel=rv; - - /* create pens for graphs */ - sgList=AQDG_Graph_DataSet_GetSubGraphList(gr->dataSet); - if (sgList) { - AQDG_GRAPH_SUBGRAPH *sg; - - sg=AQDG_Graph_SubGraph_List_First(sgList); - while (sg) { - - rv=AQDG_Draw_Context_PenCreate(gr->drawContext, - AQDG_Graph_SubGraph_GetColour(sg), - AQDG_Graph_SubGraph_GetLineWidth(sg), - AQDG_Graph_SubGraph_GetDashType(sg)); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - - AQDG_Graph_SubGraph_SetPenId(sg, rv); - - sg=AQDG_Graph_SubGraph_List_Next(sg); - } - } - - return 0; -} - - - -int _createPenFromSettings(AQDG_GRAPH *gr, const AQDG_GRAPH_SETTINGS_PEN *sp) -{ - int rv; - - rv=AQDG_Draw_Context_PenCreate(gr->drawContext, - AQDG_Graph_SettingsPen_GetFrontColour(sp), - AQDG_Graph_SettingsPen_GetLineWidth(sp), - AQDG_Graph_SettingsPen_GetDashType(sp)); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - - return rv; -} - - - -int _createFontFromSettings(AQDG_GRAPH *gr, const AQDG_GRAPH_SETTINGS_FONT *sf) -{ - int rv; - - rv=AQDG_Draw_Context_FontCreate(gr->drawContext, "", - AQDG_Graph_SettingsFont_GetFontSize(sf), - AQDG_Graph_SettingsFont_GetFontSlant(sf), - AQDG_Graph_SettingsFont_GetFontWeight(sf)); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - - return rv; -} - - - - -int _createPensAndFontsFromSettings(AQDG_GRAPH *gr, const AQDG_GRAPH_SETTINGS *settings) -{ - int rv; - const AQDG_GRAPH_SETTINGS_PEN *pen; - const AQDG_GRAPH_SETTINGS_FONT *fnt; - const AQDG_GRAPH_SUBGRAPH_LIST *sgList; - - pen=AQDG_Graph_Settings_GetPenTitle(settings); - if (pen) { - rv=_createPenFromSettings(gr, pen); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penTitle=rv; - } - - pen=AQDG_Graph_Settings_GetPenSubTitle(settings); - if (pen) { - rv=_createPenFromSettings(gr, pen); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penSubTitle=rv; - } - - pen=AQDG_Graph_Settings_GetPenAxisLabel(settings); - if (pen) { - rv=_createPenFromSettings(gr, pen); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penAxisLabel=rv; - } - - pen=AQDG_Graph_Settings_GetPenAxis(settings); - if (pen) { - rv=_createPenFromSettings(gr, pen); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penAxis=rv; - } - - pen=AQDG_Graph_Settings_GetPenGraph(settings); - if (pen) { - rv=_createPenFromSettings(gr, pen); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penGraph=rv; - } - - pen=AQDG_Graph_Settings_GetPenGraphBackground(settings); - if (pen) { - rv=_createPenFromSettings(gr, pen); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penGraphBackground=rv; - } - - pen=AQDG_Graph_Settings_GetPenGrid(settings); - if (pen) { - rv=_createPenFromSettings(gr, pen); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penGrid=rv; - } - - pen=AQDG_Graph_Settings_GetPenBackground(settings); - if (pen) { - rv=_createPenFromSettings(gr, pen); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->penBackground=rv; - } - - - - fnt=AQDG_Graph_Settings_GetFontTitle(settings); - if (fnt) { - rv=_createFontFromSettings(gr, fnt); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->fontTitle=rv; - } - - fnt=AQDG_Graph_Settings_GetFontSubTitle(settings); - if (fnt) { - rv=_createFontFromSettings(gr, fnt); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->fontSubTitle=rv; - } - - fnt=AQDG_Graph_Settings_GetFontAxisLabel(settings); - if (fnt) { - rv=_createFontFromSettings(gr, fnt); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->fontAxisLabel=rv; - } - - fnt=AQDG_Graph_Settings_GetFontTickLabel(settings); - if (fnt) { - rv=_createFontFromSettings(gr, fnt); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - gr->fontTickLabel=rv; - } - - /* create pens for graphs */ - sgList=AQDG_Graph_DataSet_GetSubGraphList(gr->dataSet); - if (sgList) { - AQDG_GRAPH_SUBGRAPH *sg; - - sg=AQDG_Graph_SubGraph_List_First(sgList); - while (sg) { - - rv=AQDG_Draw_Context_PenCreate(gr->drawContext, - AQDG_Graph_SubGraph_GetColour(sg), - AQDG_Graph_SubGraph_GetLineWidth(sg), - AQDG_Graph_SubGraph_GetDashType(sg)); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - return rv; - } - - AQDG_Graph_SubGraph_SetPenId(sg, rv); - - sg=AQDG_Graph_SubGraph_List_Next(sg); - } - } - - return 0; -} - - - -void _releasePensAndFonts(AQDG_GRAPH *gr) -{ - if (gr->penTitle>=0) { - AQDG_Draw_Context_PenRelease(gr->drawContext, gr->penTitle); - gr->penTitle=-1; - } - - if (gr->penSubTitle>=0) { - AQDG_Draw_Context_PenRelease(gr->drawContext, gr->penSubTitle); - gr->penSubTitle=-1; - } - - if (gr->penAxisLabel>=0) { - AQDG_Draw_Context_PenRelease(gr->drawContext, gr->penAxisLabel); - gr->penAxisLabel=-1; - } - - if (gr->penAxis>=0) { - AQDG_Draw_Context_PenRelease(gr->drawContext, gr->penAxis); - gr->penAxis=-1; - } - - if (gr->penGraph>=0) { - AQDG_Draw_Context_PenRelease(gr->drawContext, gr->penGraph); - gr->penGraph=-1; - } - - if (gr->penGraphBackground>=0) { - AQDG_Draw_Context_PenRelease(gr->drawContext, gr->penGraphBackground); - gr->penGraphBackground=-1; - } - - if (gr->penGrid>=0) { - AQDG_Draw_Context_PenRelease(gr->drawContext, gr->penGrid); - gr->penGrid=-1; - } - - - - if (gr->fontTitle>=0) { - AQDG_Draw_Context_FontRelease(gr->drawContext, gr->fontTitle); - gr->fontTitle=-1; - } - - if (gr->fontSubTitle>=0) { - AQDG_Draw_Context_FontRelease(gr->drawContext, gr->fontSubTitle); - gr->fontSubTitle=-1; - } - - if (gr->fontAxisLabel>=0) { - AQDG_Draw_Context_FontRelease(gr->drawContext, gr->fontAxisLabel); - gr->fontAxisLabel=-1; - } - - if (gr->fontTickLabel>=0) { - AQDG_Draw_Context_FontRelease(gr->drawContext, gr->fontTickLabel); - gr->fontTickLabel=-1; - } -} - - diff --git a/src/lib/aqdiagram/graph/setup.h b/src/lib/aqdiagram/graph/setup.h deleted file mode 100644 index 142b4d5..0000000 --- a/src/lib/aqdiagram/graph/setup.h +++ /dev/null @@ -1,20 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqDiagram. - * AqDiagram (c) by 2022 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - - -#ifndef AQDG_GRAPH_SETUP_H -#define AQDG_GRAPH_SETUP_H - - -#include - - - - -#endif - diff --git a/src/lib/aqdiagram/graph/subgraph.t2d b/src/lib/aqdiagram/graph/subgraph.t2d new file mode 100644 index 0000000..b9d696c --- /dev/null +++ b/src/lib/aqdiagram/graph/subgraph.t2d @@ -0,0 +1,137 @@ + + + + + + This class describes a sub graph. + + + AQDG_GRAPH_SUBGRAPH + AQDG_Graph_SubGraph + subgraph + + + with_db + with_xml + with_list1 + with_list2 + with_refcount + + + +
aqdiagram/aqdg_api.h
+
aqdiagram/graph/curve.h
+
aqdiagram/graph/graph.h
+
+ + + + + + $(api) void $(struct_prefix)_CalcMinMaxValues($(struct_type) *st); + + + + + + void $(struct_prefix)_CalcMinMaxValues($(struct_type) *st) \n + { \n + if (st && st->curves) { \n + double minX; \n + double maxX; \n + double maxY; \n + double minY; \n + AQDG_GRAPH_CURVE *curve; \n + \n + curve=AQDG_Graph_Curve_List_First(st->curves); \n + while(curve) { \n + double d; \n + \n + AQDG_Graph_Curve_CalcMinMaxValues(curve); \n + d=AQDG_Graph_Curve_GetMinValueX(curve); \n + minX=(d<minX)?d:minX; \n + d=AQDG_Graph_Curve_GetMinValueY(curve); \n + minY=(d<minY)?d:minY; \n + \n + d=AQDG_Graph_Curve_GetMaxValueX(curve); \n + maxX=(d>maxX)?d:maxX; \n + d=AQDG_Graph_Curve_GetMaxValueY(curve); \n + maxY=(d>maxY)?d:maxY; \n + \n + curve=AQDG_Graph_Curve_List_Next(curve); \n + } \n + \n + st->minValueX=minX; \n + st->maxValueX=maxX; \n + st->minValueY=minY; \n + st->maxValueY=maxY; \n + } \n + } \n + + + + + + + +
+ + + + + 0 + 0 + public + + + + 0 + 0 + public + + + + + + 0.0 + 0.0 + public + + + + 0.0 + 0.0 + public + + + + + 0.0 + 0.0 + public + + + + 0.0 + 0.0 + public + + + + + + NULL + AQDG_Graph_Curve_List_new() + public + own + nodup + none + + + + + +
+ +
+ diff --git a/src/lib/aqdiagram/graph/subgraph.xml b/src/lib/aqdiagram/graph/subgraph.xml deleted file mode 100644 index 50c48e1..0000000 --- a/src/lib/aqdiagram/graph/subgraph.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - This class describes a sub graph. - - - AQDG_GRAPH_SUBGRAPH - AQDG_Graph_SubGraph - subgraph - - - with_db - with_xml - with_list1 - with_list2 - with_refcount - - - -
aqdiagram/aqdg_api.h
-
- -
- - - - - NULL - NULL - public - own - const dup - const - - - - 0 - 0 - public - with_getbymember - - - - 0 - 0 - public - - - - 0 - 0 - public - - - - 0 - 0 - public - - - - 0 - 0 - public - - - - 0 - 0 - public - - - - - 0 - 0 - public - volatile - - - - - -
- -
- diff --git a/src/lib/aqdiagram/graph/tick.xml b/src/lib/aqdiagram/graph/tick.t2d similarity index 77% rename from src/lib/aqdiagram/graph/tick.xml rename to src/lib/aqdiagram/graph/tick.t2d index 81520c5..7c1e9f4 100644 --- a/src/lib/aqdiagram/graph/tick.xml +++ b/src/lib/aqdiagram/graph/tick.t2d @@ -14,19 +14,10 @@ with_db with_xml with_list1 - with_list2 - with_refcount
aqdiagram/aqdg_api.h
- -
aqdiagram/graph/dataset.h
-
aqdiagram/graph/tick_fns.h
-
tick_fns.c
- -
gwenhywfar/gwendate.h
-
gwenhywfar/i18n.h
diff --git a/src/lib/aqdiagram/graph/tick_fns.c b/src/lib/aqdiagram/graph/tick_fns.c deleted file mode 100644 index 997279f..0000000 --- a/src/lib/aqdiagram/graph/tick_fns.c +++ /dev/null @@ -1,607 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqDiagram. - * AqDiagram (c) by 2020 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - - -#define I18N(msg) GWEN_I18N_Translate("aqdiagram", msg) - - - - -double AQDG_Graph_Tick_GetRoundedMaxVal(double val) -{ - double maxVal; - - if (val<0.0) - val=-val; - - if (val>100000000.0) - maxVal=1000000000.0; - else if (val>10000000.0) - maxVal=100000000.0; - else if (val>1000000.0) - maxVal=10000000.0; - else if (val>100000.0) - maxVal=1000000.0; - else if (val>10000.0) - maxVal=100000.0; - else if (val>1000.0) - maxVal=10000.0; - else if (val>100.0) - maxVal=1000.0; - else if (val>10.0) - maxVal=100.0; - else if (val>10.0) - maxVal=100.0; - else if (val>1.0) - maxVal=10.0; - else if (val>0.1) - maxVal=1.0; - else if (val>0.01) - maxVal=0.1; - else if (val>0.001) - maxVal=0.01; - else if (val>0.0001) - maxVal=0.001; - else if (val>0.00001) - maxVal=0.0001; - else if (val>0.000001) - maxVal=0.00001; - else if (val<0.000001) - maxVal=0.000001; - else - maxVal=1; - - return maxVal; -} - - - -static void AQDG_Graph_Tick_AddTicks_IntSubTicks(AQDG_GRAPH_TICK_LIST *tickList, - double minVal, double maxVal, double stepFactor, int level) -{ - double vCurrent; - double vMin, vMax, v; - double steps; - - vMin=AQDG_Graph_Tick_GetRoundedMaxVal(minVal); - if (minVal<0.0) - vMin=-vMin; - vMax=AQDG_Graph_Tick_GetRoundedMaxVal(maxVal); - if (maxVal<0.0) - vMax=-vMax; - - v=(vMin>vMax)?vMin:vMax; - steps=v/stepFactor; - - if (vMin<0.0 && vMax>0.0) { - /* create ticks for negative values */ - vCurrent=-v; - while (vCurrent<0.0) { - if (vCurrent>=minVal) { - AQDG_GRAPH_TICK *t; - char numbuf[64]; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, vCurrent); - AQDG_Graph_Tick_SetLevel(t, level); - snprintf(numbuf, sizeof(numbuf)-1, "%d", (int)vCurrent); - numbuf[sizeof(numbuf)-1]=0; - DBG_ERROR(0, "Tick: %s (steps %f)", numbuf, steps); - AQDG_Graph_Tick_SetLabel(t, numbuf); - AQDG_Graph_Tick_List_Add(t, tickList); - } - - vCurrent+=steps; - } - - /* create ticks for positive values */ - vCurrent=0.0; - while (vCurrent<=vMax) { - AQDG_GRAPH_TICK *t; - char numbuf[64]; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, vCurrent); - AQDG_Graph_Tick_SetLevel(t, level); - snprintf(numbuf, sizeof(numbuf)-1, "%d", (int)vCurrent); - numbuf[sizeof(numbuf)-1]=0; - DBG_ERROR(0, "Tick: %s (steps %f)", numbuf, steps); - AQDG_Graph_Tick_SetLabel(t, numbuf); - AQDG_Graph_Tick_List_Add(t, tickList); - - vCurrent+=steps; - } - } - else if (vMin<0.0 && vMax<0.0) { - /* create ticks for negative values */ - vCurrent=-v; - while (vCurrent<=vMax) { - if (vCurrent>=vMin) { - AQDG_GRAPH_TICK *t; - char numbuf[64]; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, vCurrent); - AQDG_Graph_Tick_SetLevel(t, level); - snprintf(numbuf, sizeof(numbuf)-1, "%d", (int)vCurrent); - numbuf[sizeof(numbuf)-1]=0; - DBG_ERROR(0, "Tick: %s (steps %f)", numbuf, steps); - AQDG_Graph_Tick_SetLabel(t, numbuf); - AQDG_Graph_Tick_List_Add(t, tickList); - } - vCurrent-=steps; - } - } - else if (vMin>0.0 && vMax>0.0) { - /* create ticks for negative values */ - vCurrent=0.0; - while (vCurrent<=vMax) { - if (vCurrent>=vMin) { - AQDG_GRAPH_TICK *t; - char numbuf[64]; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, vCurrent); - AQDG_Graph_Tick_SetLevel(t, level); - snprintf(numbuf, sizeof(numbuf)-1, "%d", (int)vCurrent); - numbuf[sizeof(numbuf)-1]=0; - DBG_ERROR(0, "Tick: %s (steps %f)", numbuf, steps); - AQDG_Graph_Tick_SetLabel(t, numbuf); - AQDG_Graph_Tick_List_Add(t, tickList); - } - - vCurrent+=steps; - } - } -} - - - -void AQDG_Graph_Tick_AddTicks_Int(AQDG_GRAPH_TICK_LIST *tickList, double minVal, double maxVal) -{ - DBG_ERROR(0, "Creating ticks from minVal=%f to maxVal=%f", minVal, maxVal); - -#if 0 - AQDG_Graph_Tick_AddTicks_IntSubTicks(tickList, minVal, maxVal, 10.0, 1); - AQDG_Graph_Tick_AddTicks_IntSubTicks(tickList, minVal, maxVal, 20.0, 2); - AQDG_Graph_Tick_AddTicks_IntSubTicks(tickList, minVal, maxVal, 100.0, 3); -#else - AQDG_Graph_Tick_AddTicks_IntSubTicks(tickList, minVal, maxVal, 2.0, 1); - AQDG_Graph_Tick_AddTicks_IntSubTicks(tickList, minVal, maxVal, 20.0, 2); - AQDG_Graph_Tick_AddTicks_IntSubTicks(tickList, minVal, maxVal, 200.0, 3); -#endif -} - - - - - - - - - - - - - -static void AQDG_Graph_Tick_AddTicks_DoubleSubTicks(AQDG_GRAPH_TICK_LIST *tickList, - double minVal, double maxVal, double stepFactor, - int prec, int level, int withText) -{ - double vCurrent; - double vMin, vMax, v; - double steps; - - vMin=AQDG_Graph_Tick_GetRoundedMaxVal(minVal); - vMax=AQDG_Graph_Tick_GetRoundedMaxVal(maxVal); - - v=(vMin>vMax)?vMin:vMax; - if (minVal<0.0) - vMin=-vMin; - if (maxVal<0.0) - vMax=-vMax; - steps=v/stepFactor; - - if (vMin<0.0 && vMax>0.0) { - /* create ticks for negative values */ - vCurrent=-v; - while (vCurrent<0.0) { - if (vCurrent>=minVal) { - AQDG_GRAPH_TICK *t; - char numbuf[64]; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, vCurrent); - AQDG_Graph_Tick_SetLevel(t, level); - snprintf(numbuf, sizeof(numbuf)-1, "%.*f", prec?prec:2, vCurrent); - numbuf[sizeof(numbuf)-1]=0; - DBG_ERROR(0, "Tick: %s (steps %f)", numbuf, steps); - if (withText) - AQDG_Graph_Tick_SetLabel(t, numbuf); - AQDG_Graph_Tick_List_Add(t, tickList); - } - - vCurrent+=steps; - } - - /* create ticks for positive values */ - vCurrent=0.0; - while (vCurrent<=maxVal) { - AQDG_GRAPH_TICK *t; - char numbuf[64]; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, vCurrent); - AQDG_Graph_Tick_SetLevel(t, level); - snprintf(numbuf, sizeof(numbuf)-1, "%.*f", prec?prec:2, vCurrent); - numbuf[sizeof(numbuf)-1]=0; - DBG_ERROR(0, "Tick: %s (steps %f)", numbuf, steps); - if (withText) - AQDG_Graph_Tick_SetLabel(t, numbuf); - AQDG_Graph_Tick_List_Add(t, tickList); - - vCurrent+=steps; - } - } - else if (vMin<0.0 && vMax<0.0) { - /* create ticks for negative values */ - vCurrent=-v; - while (vCurrent=minVal) { - AQDG_GRAPH_TICK *t; - char numbuf[64]; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, vCurrent); - AQDG_Graph_Tick_SetLevel(t, level); - snprintf(numbuf, sizeof(numbuf)-1, "%.*f", prec?prec:2, vCurrent); - numbuf[sizeof(numbuf)-1]=0; - DBG_ERROR(0, "Tick: %s (steps %f)", numbuf, steps); - if (withText) - AQDG_Graph_Tick_SetLabel(t, numbuf); - AQDG_Graph_Tick_List_Add(t, tickList); - } - - vCurrent+=steps; - } - } - else if (vMin>0.0 && vMax>0.0) { - /* create ticks for negative values */ - vCurrent=0.0; - while (vCurrent<=maxVal) { - if (vCurrent>=minVal) { - AQDG_GRAPH_TICK *t; - char numbuf[64]; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, vCurrent); - AQDG_Graph_Tick_SetLevel(t, level); - snprintf(numbuf, sizeof(numbuf)-1, "%.*f", prec?prec:2, vCurrent); - numbuf[sizeof(numbuf)-1]=0; - DBG_ERROR(0, "Tick: %s (steps %f)", numbuf, steps); - if (withText) - AQDG_Graph_Tick_SetLabel(t, numbuf); - AQDG_Graph_Tick_List_Add(t, tickList); - } - vCurrent+=steps; - } - } -} - - - - - - -static void AQDG_Graph_Tick_AddTicks_Double(AQDG_GRAPH_TICK_LIST *tickList, double minVal, double maxVal, int prec) -{ - int level=1; - - DBG_ERROR(0, "Creating ticks from minVal=%f to maxVal=%f", minVal, maxVal); - -#if 0 - AQDG_Graph_Tick_AddTicks_DoubleSubTicks(tickList, minVal, maxVal, 10.0, prec, level++, 1); - AQDG_Graph_Tick_AddTicks_DoubleSubTicks(tickList, minVal, maxVal, 20.0, prec, level++, 1); - AQDG_Graph_Tick_AddTicks_DoubleSubTicks(tickList, minVal, maxVal, 100.0, prec, level++, 1); -#else - AQDG_Graph_Tick_AddTicks_DoubleSubTicks(tickList, minVal, maxVal, 2.0, prec, level++, 1); - AQDG_Graph_Tick_AddTicks_DoubleSubTicks(tickList, minVal, maxVal, 10.0, prec, level++, 0); - AQDG_Graph_Tick_AddTicks_DoubleSubTicks(tickList, minVal, maxVal, 20.0, prec, level++, 1); - AQDG_Graph_Tick_AddTicks_DoubleSubTicks(tickList, minVal, maxVal, 100.0, prec, level++, 0); - AQDG_Graph_Tick_AddTicks_DoubleSubTicks(tickList, minVal, maxVal, 200.0, prec, level++, 1); -#endif -} - - - -void AQDG_Graph_Tick_AddTicks_DateYears(AQDG_GRAPH_TICK_LIST *tickList, int level, double minVal, double maxVal) -{ - /* add ticks for years */ - int i; - - for (i=(int)minVal; i<=(int) maxVal; i++) { - GWEN_DATE *d; - - d=GWEN_Date_fromJulian(i); - if (d==NULL) { - DBG_ERROR(0, "Invalid julian date %d", i); - } - else { - if (GWEN_Date_DaysInYear(d)==0) { - int rv; - GWEN_BUFFER *tbuf; - - tbuf=GWEN_Buffer_new(0, 256, 0, 1); - rv=GWEN_Date_toStringWithTemplate(d, I18N("YYYY"), tbuf); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - } - else { - AQDG_GRAPH_TICK *t; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, i); - AQDG_Graph_Tick_SetLevel(t, level); - AQDG_Graph_Tick_SetLabel(t, GWEN_Buffer_GetStart(tbuf)); - AQDG_Graph_Tick_List_Add(t, tickList); - } - GWEN_Buffer_free(tbuf); - } - GWEN_Date_free(d); - } - } -} - - - -void AQDG_Graph_Tick_AddTicks_DateMonths(AQDG_GRAPH_TICK_LIST *tickList, int level, double minVal, double maxVal) -{ - int i; - - for (i=(int)minVal; i<=(int) maxVal; i++) { - GWEN_DATE *d; - - d=GWEN_Date_fromJulian(i); - if (d==NULL) { - DBG_ERROR(0, "Invalid julian date %d", i); - } - else { - if (GWEN_Date_GetDay(d)==1) { - int rv; - GWEN_BUFFER *tbuf; - - tbuf=GWEN_Buffer_new(0, 256, 0, 1); - rv=GWEN_Date_toStringWithTemplate(d, I18N("YY/MM"), tbuf); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - } - else { - AQDG_GRAPH_TICK *t; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, i); - AQDG_Graph_Tick_SetLevel(t, level); - AQDG_Graph_Tick_SetLabel(t, GWEN_Buffer_GetStart(tbuf)); - AQDG_Graph_Tick_List_Add(t, tickList); - } - GWEN_Buffer_free(tbuf); - } - GWEN_Date_free(d); - } - } -} - - - -void AQDG_Graph_Tick_AddTicks_DateWeeks(AQDG_GRAPH_TICK_LIST *tickList, int level, double minVal, double maxVal) -{ - int i; - - for (i=(int)minVal; i<=(int) maxVal; i++) { - GWEN_DATE *d; - - d=GWEN_Date_fromJulian(i); - if (d==NULL) { - DBG_ERROR(0, "Invalid julian date %d", i); - } - else { - if (GWEN_Date_WeekDay(d)==1) { /* week starts at monday */ - GWEN_BUFFER *tbuf; - int rv; - - tbuf=GWEN_Buffer_new(0, 256, 0, 1); - rv=GWEN_Date_toStringWithTemplate(d, I18N("YY/MM/DD"), tbuf); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - } - else { - AQDG_GRAPH_TICK *t; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, i); - AQDG_Graph_Tick_SetLevel(t, level); - AQDG_Graph_Tick_SetLabel(t, GWEN_Buffer_GetStart(tbuf)); - AQDG_Graph_Tick_List_Add(t, tickList); - } - GWEN_Buffer_free(tbuf); - } - GWEN_Date_free(d); - } - } -} - - - -void AQDG_Graph_Tick_AddTicks_DateDays(AQDG_GRAPH_TICK_LIST *tickList, int level, double minVal, double maxVal) -{ - int i; - - for (i=(int)minVal; i<=(int) maxVal; i++) { - GWEN_DATE *d; - - d=GWEN_Date_fromJulian(i); - if (d==NULL) { - DBG_ERROR(0, "Invalid julian date %d", i); - } - else { - int rv; - GWEN_BUFFER *tbuf; - - tbuf=GWEN_Buffer_new(0, 256, 0, 1); - rv=GWEN_Date_toStringWithTemplate(d, I18N("YY/MM/DD"), tbuf); - if (rv<0) { - DBG_INFO(0, "here (%d)", rv); - } - else { - AQDG_GRAPH_TICK *t; - - t=AQDG_Graph_Tick_new(); - AQDG_Graph_Tick_SetValue(t, i); - AQDG_Graph_Tick_SetLevel(t, level); - AQDG_Graph_Tick_SetLabel(t, GWEN_Buffer_GetStart(tbuf)); - AQDG_Graph_Tick_List_Add(t, tickList); - } - GWEN_Buffer_free(tbuf); - GWEN_Date_free(d); - } - } -} - - - -static void AQDG_Graph_Tick_AddTicks_Date(AQDG_GRAPH_TICK_LIST *tickList, double minVal, double maxVal) -{ - int dist; - int level; - - dist=maxVal-minVal; - level=1; - - /* add ticks for years */ - if (dist>365) - AQDG_Graph_Tick_AddTicks_DateYears(tickList, level++, minVal, maxVal); - - /* add ticks for months */ - if (dist>30) - AQDG_Graph_Tick_AddTicks_DateMonths(tickList, level++, minVal, maxVal); - - /* add ticks for weeks */ - if (dist>7) - AQDG_Graph_Tick_AddTicks_DateWeeks(tickList, level++, minVal, maxVal); - - /* add ticks for days */ - if (dist>1) - AQDG_Graph_Tick_AddTicks_DateDays(tickList, level++, minVal, maxVal); -} - - - - - - - - - -void AQDG_Graph_Tick_AddTicks(AQDG_GRAPH_TICK_LIST *tickList, int dataType, double minVal, double maxVal, int prec) -{ - switch (dataType) { - case AQDG_Graph_DataSet_DataType_Integer: - AQDG_Graph_Tick_AddTicks_Int(tickList, minVal, maxVal); - break; - case AQDG_Graph_DataSet_DataType_Double: - AQDG_Graph_Tick_AddTicks_Double(tickList, minVal, maxVal, prec); - break; - case AQDG_Graph_DataSet_DataType_Date: - AQDG_Graph_Tick_AddTicks_Date(tickList, minVal, maxVal); - break; - default: - break; - } -} - - - - - -static int GWENHYWFAR_CB AQDG_Graph_Tick_List_Compare_ValueAndLevel(const AQDG_GRAPH_TICK *p_a, const AQDG_GRAPH_TICK *p_b, - int p_ascending) -{ - int p_rv; - - if (p_b->value==p_a->value) { - if (p_b->level==p_a->level) { - p_rv=0; - } - else if (p_a->levellevel) - p_rv=-1; - else - p_rv=1; - } - else if (p_a->valuevalue) - p_rv=-1; - else - p_rv=1; - - if (p_ascending) - return p_rv; - else - return -p_rv; -} - - - -void AQDG_Graph_Tick_List_SortByValueAndLevel(AQDG_GRAPH_TICK_LIST *p_list, int p_ascending) -{ - AQDG_GRAPH_TICK_LIST_SORT_FN oldSortFn; - - oldSortFn=AQDG_Graph_Tick_List_SetSortFn(p_list, AQDG_Graph_Tick_List_Compare_ValueAndLevel); - AQDG_Graph_Tick_List_Sort(p_list, p_ascending); - AQDG_Graph_Tick_List_SetSortFn(p_list, oldSortFn); -} - - - -int AQDG_Graph_Tick_List_GetAverageValueDist(const AQDG_GRAPH_TICK_LIST *tl, int level, double *pResult) -{ - if (tl) { - const AQDG_GRAPH_TICK *t; - double sumOfDists=0.0; - double lastValue=0.0; - int cnt=0; - - t=AQDG_Graph_Tick_List_First(tl); - while (t) { - if (AQDG_Graph_Tick_GetLevel(t)==level) { - double d; - - d=AQDG_Graph_Tick_GetValue(t); - if (cnt) - sumOfDists+=abs(d-lastValue); - lastValue=d; - cnt++; - } - t=AQDG_Graph_Tick_List_Next(t); - } - - if (cnt>1) { - *pResult=sumOfDists/((double)(cnt-1)); - return 0; - } - else - return 1; - } - else { - return GWEN_ERROR_NO_DATA; - } -} - - - - - - diff --git a/src/lib/aqdiagram/graph/tick_fns.h b/src/lib/aqdiagram/graph/tick_fns.h deleted file mode 100644 index 35c8e57..0000000 --- a/src/lib/aqdiagram/graph/tick_fns.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqDiagram. - * AqDiagram (c) by 2020 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - - -#ifndef AQDG_GRAPH_TICK_FNS_H -#define AQDG_GRAPH_TICK_FNS_H - -#ifdef __cplusplus -extern "C" { -#endif - - -AQDG_API void AQDG_Graph_Tick_AddTicks(AQDG_GRAPH_TICK_LIST *tickList, int dataType, double minVal, double maxVal, int prec); - -AQDG_API void AQDG_Graph_Tick_AddTicks_DateYears(AQDG_GRAPH_TICK_LIST *tickList, int level, double minVal, double maxVal); -AQDG_API void AQDG_Graph_Tick_AddTicks_DateMonths(AQDG_GRAPH_TICK_LIST *tickList, int level, double minVal, double maxVal); -AQDG_API void AQDG_Graph_Tick_AddTicks_DateWeeks(AQDG_GRAPH_TICK_LIST *tickList, int level, double minVal, double maxVal); -AQDG_API void AQDG_Graph_Tick_AddTicks_DateDays(AQDG_GRAPH_TICK_LIST *tickList, int level, double minVal, double maxVal); - - -AQDG_API void AQDG_Graph_Tick_List_SortByValueAndLevel(AQDG_GRAPH_TICK_LIST *list, int ascending); - -AQDG_API int AQDG_Graph_Tick_List_GetAverageValueDist(const AQDG_GRAPH_TICK_LIST *tl, int level, double *pResult); - - -#ifdef __cplusplus -} -#endif - - - -#endif - -