started working on new graph module.
This commit is contained in:
@@ -33,44 +33,36 @@
|
|||||||
|
|
||||||
|
|
||||||
<setVar name="local/typefiles" >
|
<setVar name="local/typefiles" >
|
||||||
datapair.xml
|
datapair.t2d
|
||||||
dataset.xml
|
subgraph.t2d
|
||||||
tick.xml
|
tick.t2d
|
||||||
subgraph.xml
|
axis.t2d
|
||||||
settings_pen.xml
|
curve.t2d
|
||||||
settings_font.xml
|
|
||||||
settings.xml
|
|
||||||
</setVar>
|
</setVar>
|
||||||
|
|
||||||
<setVar name="local/built_sources" >
|
<setVar name="local/built_sources" >
|
||||||
datapair.c
|
datapair.c
|
||||||
dataset.c
|
|
||||||
tick.c
|
|
||||||
subgraph.c
|
subgraph.c
|
||||||
settings_pen.c
|
tick.c
|
||||||
settings_font.c
|
axis.c
|
||||||
settings.c
|
curve.c
|
||||||
</setVar>
|
</setVar>
|
||||||
|
|
||||||
<setVar name="local/built_headers_pub">
|
<setVar name="local/built_headers_pub">
|
||||||
datapair.h
|
datapair.h
|
||||||
dataset.h
|
|
||||||
tick.h
|
|
||||||
subgraph.h
|
subgraph.h
|
||||||
settings_pen.h
|
tick.h
|
||||||
settings_font.h
|
axis.h
|
||||||
settings.h
|
curve.h
|
||||||
</setVar>
|
</setVar>
|
||||||
|
|
||||||
|
|
||||||
<setVar name="local/built_headers_priv" >
|
<setVar name="local/built_headers_priv" >
|
||||||
datapair_p.h
|
datapair_p.h
|
||||||
dataset_p.h
|
|
||||||
tick_p.h
|
|
||||||
subgraph_p.h
|
subgraph_p.h
|
||||||
settings_pen_p.h
|
tick_p.h
|
||||||
settings_font_p.h
|
axis_p.h
|
||||||
settings_p.h
|
curve_p.h
|
||||||
</setVar>
|
</setVar>
|
||||||
|
|
||||||
|
|
||||||
@@ -86,40 +78,29 @@
|
|||||||
|
|
||||||
<headers dist="true" install="$(pkgincludedir)">
|
<headers dist="true" install="$(pkgincludedir)">
|
||||||
graph.h
|
graph.h
|
||||||
draw.h
|
o_graph.h
|
||||||
layout.h
|
|
||||||
setup.h
|
|
||||||
</headers>
|
</headers>
|
||||||
|
|
||||||
|
|
||||||
<headers dist="true">
|
<headers dist="true">
|
||||||
graph_p.h
|
graph_p.h
|
||||||
|
o_graph_p.h
|
||||||
</headers>
|
</headers>
|
||||||
|
|
||||||
|
|
||||||
<sources>
|
<sources>
|
||||||
$(local/typefiles)
|
$(local/typefiles)
|
||||||
graph.c
|
graph.c
|
||||||
draw.c
|
g_setup.c
|
||||||
layout.c
|
o_graph.c
|
||||||
setup.c
|
|
||||||
</sources>
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
<data DIST="FALSE" generated="TRUE" >
|
<data DIST="FALSE" generated="TRUE" >
|
||||||
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
|
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
|
|
||||||
<extradist>
|
<extradist>
|
||||||
dataset_fns.c dataset_fns.h
|
|
||||||
tick_fns.c tick_fns.h
|
|
||||||
</extradist>
|
</extradist>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
123
src/lib/aqdiagram/graph/axis.t2d
Normal file
123
src/lib/aqdiagram/graph/axis.t2d
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<tm2>
|
||||||
|
<type id="AQDG_GRAPH_AXIS" type="pointer">
|
||||||
|
<descr>
|
||||||
|
This class describes data axis.
|
||||||
|
</descr>
|
||||||
|
<lang id="c">
|
||||||
|
<identifier>AQDG_GRAPH_AXIS</identifier>
|
||||||
|
<prefix>AQDG_Graph_Axis</prefix>
|
||||||
|
<baseFileName>axis</baseFileName>
|
||||||
|
|
||||||
|
<flags>
|
||||||
|
with_db
|
||||||
|
with_xml
|
||||||
|
with_list1
|
||||||
|
</flags>
|
||||||
|
|
||||||
|
<headers>
|
||||||
|
<header type="sys" loc="pre">aqdiagram/aqdg_api.h</header>
|
||||||
|
<header type="sys" loc="pre">aqdiagram/graph/tick.h</header>
|
||||||
|
</headers>
|
||||||
|
|
||||||
|
</lang>
|
||||||
|
|
||||||
|
|
||||||
|
<defines>
|
||||||
|
<define id="AQDG_GRAPH_AXIS_TYPE" prefix="AQDG_GRAPH_AXIS_TYPE_">
|
||||||
|
<item name="HORIZONTAL" value="0" />
|
||||||
|
<item name="VERTICAL" value="1" />
|
||||||
|
</define>
|
||||||
|
|
||||||
|
</defines>
|
||||||
|
|
||||||
|
|
||||||
|
<members>
|
||||||
|
|
||||||
|
<member name="label" type="char_ptr" maxlen="128" >
|
||||||
|
<default>NULL</default>
|
||||||
|
<preset>NULL</preset>
|
||||||
|
<access>public</access>
|
||||||
|
<flags>own</flags>
|
||||||
|
<setflags>const dup</setflags>
|
||||||
|
<getflags>const</getflags>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="units" type="char_ptr" maxlen="128" >
|
||||||
|
<default>NULL</default>
|
||||||
|
<preset>NULL</preset>
|
||||||
|
<access>public</access>
|
||||||
|
<flags>own</flags>
|
||||||
|
<setflags>const dup</setflags>
|
||||||
|
<getflags>const</getflags>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="dataType" type="int" maxlen="8" >
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="axisType" type="int" maxlen="8" >
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="precision" type="int" maxlen="8" >
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="minValue" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="maxValue" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="offset" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="factor" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="flags" type="uint32_t" maxlen="8">
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<flags>with_flags</flags>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
|
||||||
|
<member name="tickList" type="AQDG_GRAPH_TICK_LIST" >
|
||||||
|
<default>NULL</default>
|
||||||
|
<preset>AQDG_Graph_Tick_List_new()</preset>
|
||||||
|
<access>public</access>
|
||||||
|
<flags>own</flags>
|
||||||
|
<setflags>nodup</setflags>
|
||||||
|
<getflags>none</getflags>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</members>
|
||||||
|
|
||||||
|
</type>
|
||||||
|
|
||||||
|
</tm2>
|
||||||
|
|
||||||
150
src/lib/aqdiagram/graph/curve.t2d
Normal file
150
src/lib/aqdiagram/graph/curve.t2d
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<tm2>
|
||||||
|
<type id="AQDG_GRAPH_CURVE" type="pointer">
|
||||||
|
<descr>
|
||||||
|
This class describes curve.
|
||||||
|
</descr>
|
||||||
|
<lang id="c">
|
||||||
|
<identifier>AQDG_GRAPH_CURVE</identifier>
|
||||||
|
<prefix>AQDG_Graph_Curve</prefix>
|
||||||
|
<baseFileName>curve</baseFileName>
|
||||||
|
|
||||||
|
<flags>
|
||||||
|
with_db
|
||||||
|
with_xml
|
||||||
|
with_list1
|
||||||
|
</flags>
|
||||||
|
|
||||||
|
<headers>
|
||||||
|
<header type="sys" loc="pre">aqdiagram/aqdg_api.h</header>
|
||||||
|
<header type="sys" loc="pre">aqdiagram/graph/datapair.h</header>
|
||||||
|
</headers>
|
||||||
|
|
||||||
|
<inlines>
|
||||||
|
|
||||||
|
<inline loc="end" access="public">
|
||||||
|
<content>
|
||||||
|
$(api) void $(struct_prefix)_CalcMinMaxValues($(struct_type) *st);
|
||||||
|
</content>
|
||||||
|
</inline>
|
||||||
|
|
||||||
|
<inline loc="code">
|
||||||
|
<content>
|
||||||
|
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
|
||||||
|
</content>
|
||||||
|
</inline>
|
||||||
|
|
||||||
|
|
||||||
|
</inlines>
|
||||||
|
|
||||||
|
|
||||||
|
</lang>
|
||||||
|
|
||||||
|
<members>
|
||||||
|
|
||||||
|
<member name="penId" type="int" maxlen="8" >
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="label" type="char_ptr" maxlen="128" >
|
||||||
|
<default>NULL</default>
|
||||||
|
<preset>NULL</preset>
|
||||||
|
<access>public</access>
|
||||||
|
<flags>own</flags>
|
||||||
|
<setflags>const dup</setflags>
|
||||||
|
<getflags>const</getflags>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="graphType" type="int" maxlen="8" >
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="flags" type="uint32_t" maxlen="8">
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<flags>with_flags</flags>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
|
||||||
|
<member name="minValueX" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="maxValueX" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="minValueY" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="maxValueY" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="dataPairs" type="AQDG_GRAPH_DATAPAIR_LIST" >
|
||||||
|
<default>NULL</default>
|
||||||
|
<preset>AQDG_Graph_DataPair_List_new()</preset>
|
||||||
|
<access>public</access>
|
||||||
|
<flags>own</flags>
|
||||||
|
<setflags>nodup</setflags>
|
||||||
|
<getflags>none</getflags>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
</members>
|
||||||
|
|
||||||
|
</type>
|
||||||
|
|
||||||
|
</tm2>
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
<flags>sortbymember</flags>
|
<flags>sortbymember</flags>
|
||||||
</member>
|
</member>
|
||||||
|
|
||||||
<member name="level" type="int" maxlen="8" >
|
<member name="subGraphId" type="int" maxlen="8" >
|
||||||
<default>0</default>
|
<default>0</default>
|
||||||
<preset>0</preset>
|
<preset>0</preset>
|
||||||
<access>public</access>
|
<access>public</access>
|
||||||
@@ -1,195 +0,0 @@
|
|||||||
<?xml?>
|
|
||||||
|
|
||||||
<tm2>
|
|
||||||
<type id="AQDG_GRAPH_DATASET" type="pointer">
|
|
||||||
<descr>
|
|
||||||
</descr>
|
|
||||||
<lang id="c">
|
|
||||||
<identifier>AQDG_GRAPH_DATASET</identifier>
|
|
||||||
<prefix>AQDG_Graph_DataSet</prefix>
|
|
||||||
<baseFileName>dataset</baseFileName>
|
|
||||||
|
|
||||||
<flags>
|
|
||||||
with_db
|
|
||||||
with_xml
|
|
||||||
with_list1
|
|
||||||
with_list2
|
|
||||||
with_refcount
|
|
||||||
</flags>
|
|
||||||
|
|
||||||
<headers>
|
|
||||||
<header type="sys" loc="pre">aqdiagram/aqdg_api.h</header>
|
|
||||||
<header type="sys" loc="pre">aqdiagram/graph/datapair.h</header>
|
|
||||||
<header type="sys" loc="pre">aqdiagram/graph/tick.h</header>
|
|
||||||
<header type="sys" loc="pre">aqdiagram/graph/subgraph.h</header>
|
|
||||||
|
|
||||||
<header type="sys" loc="post">dataset_fns.h</header>
|
|
||||||
<header type="local" loc="codeEnd">dataset_fns.c</header>
|
|
||||||
</headers>
|
|
||||||
|
|
||||||
</lang>
|
|
||||||
|
|
||||||
|
|
||||||
<enums>
|
|
||||||
|
|
||||||
<enum id="AQDG_GRAPH_DATASET_DATATYPE" prefix="AQDG_Graph_DataSet_DataType_">
|
|
||||||
<item name="integer">
|
|
||||||
<descr>integer type</descr>
|
|
||||||
</item>
|
|
||||||
|
|
||||||
<item name="double">
|
|
||||||
<descr>floating point type (double precision)</descr>
|
|
||||||
</item>
|
|
||||||
|
|
||||||
<item name="date">
|
|
||||||
<descr>date type</descr>
|
|
||||||
</item>
|
|
||||||
|
|
||||||
</enum>
|
|
||||||
|
|
||||||
</enums>
|
|
||||||
|
|
||||||
|
|
||||||
<members>
|
|
||||||
|
|
||||||
<member name="title" type="char_ptr" maxlen="128" >
|
|
||||||
<default>NULL</default>
|
|
||||||
<preset>NULL</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>const dup</setflags>
|
|
||||||
<getflags>const</getflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="subTitle" type="char_ptr" maxlen="128" >
|
|
||||||
<default>NULL</default>
|
|
||||||
<preset>NULL</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>const dup</setflags>
|
|
||||||
<getflags>const</getflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="dataPairList" type="AQDG_GRAPH_DATAPAIR_LIST" >
|
|
||||||
<default>NULL</default>
|
|
||||||
<preset>AQDG_Graph_DataPair_List_new()</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>nodup</setflags>
|
|
||||||
<getflags>none</getflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="subGraphList" type="AQDG_GRAPH_SUBGRAPH_LIST" >
|
|
||||||
<default>NULL</default>
|
|
||||||
<preset>AQDG_Graph_SubGraph_List_new()</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>nodup</setflags>
|
|
||||||
<getflags>none</getflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- X-axis -->
|
|
||||||
<member name="dataTypeX" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="precisionX" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="minValueX" type="double" maxlen="8" >
|
|
||||||
<default>0.0</default>
|
|
||||||
<preset>0.0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="maxValueX" type="double" maxlen="8" >
|
|
||||||
<default>0.0</default>
|
|
||||||
<preset>0.0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="labelX" type="char_ptr" maxlen="128" >
|
|
||||||
<default>NULL</default>
|
|
||||||
<preset>NULL</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>const dup</setflags>
|
|
||||||
<getflags>const</getflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="xTickList" type="AQDG_GRAPH_TICK_LIST" >
|
|
||||||
<default>NULL</default>
|
|
||||||
<preset>AQDG_Graph_Tick_List_new()</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>nodup</setflags>
|
|
||||||
<getflags>none</getflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Y-axis -->
|
|
||||||
|
|
||||||
<member name="dataTypeY" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="precisionY" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="minValueY" type="double" maxlen="8" >
|
|
||||||
<default>0.0</default>
|
|
||||||
<preset>0.0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="maxValueY" type="double" maxlen="8" >
|
|
||||||
<default>0.0</default>
|
|
||||||
<preset>0.0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="labelY" type="char_ptr" maxlen="128" >
|
|
||||||
<default>NULL</default>
|
|
||||||
<preset>NULL</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>const dup</setflags>
|
|
||||||
<getflags>const</getflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="yTickList" type="AQDG_GRAPH_TICK_LIST" >
|
|
||||||
<default>NULL</default>
|
|
||||||
<preset>AQDG_Graph_Tick_List_new()</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>nodup</setflags>
|
|
||||||
<getflags>none</getflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<member name="flags" type="uint32_t" maxlen="8">
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<flags>with_flags</flags>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
</members>
|
|
||||||
|
|
||||||
</type>
|
|
||||||
|
|
||||||
</tm2>
|
|
||||||
|
|
||||||
@@ -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 (v<minVal)
|
|
||||||
minVal=v;
|
|
||||||
if (v>maxVal)
|
|
||||||
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 (v<minVal)
|
|
||||||
minVal=v;
|
|
||||||
if (v>maxVal)
|
|
||||||
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 (cnt<num) {
|
|
||||||
/* buffer not full, average over the values we already have */
|
|
||||||
if (cnt) {
|
|
||||||
double totalSum=0.0;
|
|
||||||
|
|
||||||
for (i=0; i<cnt; i++) {
|
|
||||||
totalSum+=lastValues[i];
|
|
||||||
}
|
|
||||||
AQDG_Graph_DataPair_SetValueY(dp, totalSum/((double)cnt));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
double totalSum=0.0;
|
|
||||||
|
|
||||||
/* buffer full, average over full buffer */
|
|
||||||
for (i=0; i<num; i++) {
|
|
||||||
totalSum+=lastValues[i];
|
|
||||||
}
|
|
||||||
AQDG_Graph_DataPair_SetValueY(dp, totalSum/((double)num));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dp=AQDG_Graph_DataPair_List_Next(dp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int AQDG_Graph_DataSet_GetAverageValueDistX(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_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 (dist<minDist)
|
|
||||||
minDist=dist;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
minDist=dist;
|
|
||||||
}
|
|
||||||
lastValue=d;
|
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
dp=AQDG_Graph_DataPair_List_Next(dp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cnt>1) {
|
|
||||||
*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 (dist<minDist)
|
|
||||||
minDist=dist;
|
|
||||||
}
|
|
||||||
lastValue=d;
|
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
dp=AQDG_Graph_DataPair_List_Next(dp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cnt>1) {
|
|
||||||
*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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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 <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "aqdiagram/graph/draw.h"
|
|
||||||
#include "aqdiagram/graph/dataset_fns.h"
|
|
||||||
#include "graph_p.h"
|
|
||||||
|
|
||||||
#include <gwenhywfar/debug.h>
|
|
||||||
|
|
||||||
|
|
||||||
#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; level<MAX_TICK_LEVELS+1; level++) {
|
|
||||||
uint8_t tickDrawFlags=0;
|
|
||||||
//int maxWidth=0;
|
|
||||||
int dist;
|
|
||||||
int every=1;
|
|
||||||
|
|
||||||
//maxWidth=_getMaxTickLabelWidthForLevel(gr, tl, level);
|
|
||||||
|
|
||||||
/* check medium width for the current level */
|
|
||||||
dist=_calcDistBetweenFirstTwoTicksOfLevel(gr, tl, level);
|
|
||||||
if (dist==0)
|
|
||||||
dist=gr->graphAreaWidth;
|
|
||||||
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<m2; j++) {
|
|
||||||
if (j<0 || 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; j<m2; j++)
|
|
||||||
pMask[j]=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void _probablyDrawGridLineForXTick(const AQDG_GRAPH *gr, int x, uint8_t tickDrawFlags)
|
|
||||||
{
|
|
||||||
if (tickDrawFlags & TICKDRAWFLAGS_GRIDS) {
|
|
||||||
if (gr->flags & 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; level<MAX_TICK_LEVELS+1; level++) {
|
|
||||||
uint8_t tickDrawFlags=0;
|
|
||||||
int maxHeight=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, "Y-Level %d: [%s] = %f", level, s, AQDG_Graph_Tick_GetValue(t));
|
|
||||||
i=AQDG_Draw_Context_GetTextHeight(gr->drawContext, 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 */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* This file is part of the project AqDiagram.
|
* 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
|
* The license for this file can be found in the file COPYING which you
|
||||||
* should have received along with this file.
|
* should have received along with this file.
|
||||||
@@ -10,308 +10,253 @@
|
|||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "graph_p.h"
|
#include "./graph_p.h"
|
||||||
#include "aqdiagram/graph/draw.h"
|
|
||||||
#include "aqdiagram/graph/layout.h"
|
|
||||||
#include "aqdiagram/graph/setup.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <gwenhywfar/misc.h>
|
||||||
#include <gwenhywfar/debug.h>
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
|
||||||
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_NEW_OBJECT(AQDG_GRAPH, g);
|
||||||
GWEN_LIST_INIT(AQDG_GRAPH, gr)
|
|
||||||
|
|
||||||
gr->dataSet=ds;
|
_presetPens(g);
|
||||||
gr->drawContext=drawContext;
|
_presetFonts(g);
|
||||||
gr->width=width;
|
g->subGraphList=AQDG_Graph_SubGraph_List_new();
|
||||||
gr->height=height;
|
|
||||||
|
|
||||||
return gr;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AQDG_Graph_free(AQDG_GRAPH *gr)
|
void AQDG_Graph_free(AQDG_GRAPH *g)
|
||||||
{
|
{
|
||||||
if (gr) {
|
if (g) {
|
||||||
GWEN_LIST_FINI(AQDG_GRAPH, gr)
|
int i;
|
||||||
AQDG_Draw_Context_free(gr->drawContext);
|
|
||||||
GWEN_FREE_OBJECT(gr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
_releaseFonts(g);
|
||||||
|
_releasePens(g);
|
||||||
void AQDG_Graph_DrawDataAsLine(AQDG_GRAPH *gr, int level, int penId)
|
for (i=0; i<AQDG_GRAPH_NUMAXIS; i++) {
|
||||||
{
|
AQDG_Graph_Axis_free(g->axisArray[i]);
|
||||||
AQDG_GRAPH_DATAPAIR_LIST *dpl;
|
g->axisArray[i]=NULL;
|
||||||
|
|
||||||
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 (vX<minValX)
|
|
||||||
vX=minValX;
|
|
||||||
else if (vX>maxValX)
|
|
||||||
vX=maxValX;
|
|
||||||
|
|
||||||
if (vY<minValY)
|
|
||||||
vY=minValY;
|
|
||||||
else if (vY>maxValY)
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
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;
|
if (g) {
|
||||||
double dataWidth;
|
int i;
|
||||||
int barWidth;
|
|
||||||
int rv;
|
|
||||||
|
|
||||||
rv=AQDG_Graph_DataSet_GetMinValueDistX(gr->dataSet, level, &dataWidth);
|
for (i=0; i<AQDG_GRAPH_PEN_IDX_LAST; i++) {
|
||||||
if (rv<0) {
|
g->penArray[i]=-1;
|
||||||
DBG_INFO(AQDG_LOGDOMAIN, "here (%d)", rv);
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (rv==1) {
|
}
|
||||||
/* use full width */
|
|
||||||
barWidth=(gr->graphAreaWidth)-10;
|
|
||||||
|
|
||||||
|
void _presetFonts(AQDG_GRAPH *g)
|
||||||
|
{
|
||||||
|
if (g) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<AQDG_GRAPH_FONT_IDX_LAST; i++) {
|
||||||
|
g->fontArray[i]=-1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void _releasePens(AQDG_GRAPH *g)
|
||||||
|
{
|
||||||
|
if (g) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<AQDG_GRAPH_PEN_IDX_LAST; i++) {
|
||||||
|
AQDG_Draw_Context_PenRelease(g->drawContext, g->penArray[i]);
|
||||||
|
g->penArray[i]=-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void _releaseFonts(AQDG_GRAPH *g)
|
||||||
|
{
|
||||||
|
if (g) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<AQDG_GRAPH_FONT_IDX_LAST; i++) {
|
||||||
|
AQDG_Draw_Context_FontRelease(g->drawContext, 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 && idx<AQDG_GRAPH_NUMAXIS)?(g->axisArray[idx]):NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQDG_Graph_SetAxis(AQDG_GRAPH *g, int idx, AQDG_GRAPH_AXIS *ax)
|
||||||
|
{
|
||||||
|
if (g && idx<AQDG_GRAPH_NUMAXIS) {
|
||||||
|
if (g->axisArray[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 {
|
else {
|
||||||
barWidth=((int)(dataWidth*gr->graphFactorX))-10;
|
DBG_ERROR(AQDG_LOGDOMAIN, "Nullpointer");
|
||||||
}
|
|
||||||
|
|
||||||
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 (vX<minValX)
|
|
||||||
vX=minValX;
|
|
||||||
else if (vX>maxValX)
|
|
||||||
vX=maxValX;
|
|
||||||
|
|
||||||
if (vY<minValY)
|
|
||||||
vY=minValY;
|
|
||||||
else if (vY>maxValY)
|
|
||||||
vY=maxValY;
|
|
||||||
|
|
||||||
x=gr->graphOriginX + (vX * gr->graphFactorX);
|
|
||||||
y=gr->graphOriginY - (vY * gr->graphFactorY);
|
|
||||||
|
|
||||||
/* draw the bar */
|
|
||||||
if ((x-(barWidth/2))<gr->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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
return (g && idx<AQDG_GRAPH_PEN_IDX_LAST)?g->penArray[idx]:-1;
|
||||||
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 (vX<minValX)
|
|
||||||
vX=minValX;
|
|
||||||
else if (vX>maxValX)
|
|
||||||
vX=maxValX;
|
|
||||||
|
|
||||||
if (vY<minValY)
|
|
||||||
vY=minValY;
|
|
||||||
else if (vY>maxValY)
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int AQDG_Graph_Draw(AQDG_GRAPH *gr)
|
void AQDG_Graph_SetPen(AQDG_GRAPH *g, int idx, int penId)
|
||||||
{
|
{
|
||||||
AQDG_GRAPH_SUBGRAPH_LIST *sgList;
|
if (g && idx<AQDG_GRAPH_PEN_IDX_LAST) {
|
||||||
|
if (g->penArray[idx]>=0)
|
||||||
AQDG_Graph_PrepareGraph(gr);
|
AQDG_Draw_Context_PenRelease(g->drawContext, g->penArray[idx]);
|
||||||
AQDG_Graph_DrawFramework(gr);
|
g->penArray[idx]=penId;
|
||||||
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQDG_Graph_GetFont(const AQDG_GRAPH *g, int idx)
|
||||||
|
{
|
||||||
|
return (g && idx<AQDG_GRAPH_FONT_IDX_LAST)?g->fontArray[idx]:-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQDG_Graph_SetFont(AQDG_GRAPH *g, int idx, int fontId)
|
||||||
|
{
|
||||||
|
if (g && idx<AQDG_GRAPH_FONT_IDX_LAST) {
|
||||||
|
if (g->fontArray[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<sizeof(_curveColors)/sizeof(uint32_t))
|
||||||
|
return _curveColors[idx];
|
||||||
|
return defCol;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +1,82 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* This file is part of the project AqDiagram.
|
* 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
|
* The license for this file can be found in the file COPYING which you
|
||||||
* should have received along with this file.
|
* should have received along with this file.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef AQDG_GRAPH_GRAPH_H
|
||||||
|
#define AQDG_GRAPH_GRAPH_H
|
||||||
|
|
||||||
#ifndef AQDG_GRAPH_H
|
#include <aqdiagram/aqdg_api.h>
|
||||||
#define AQDG_GRAPH_H
|
|
||||||
|
|
||||||
|
/* 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 <aqdiagram/aqdiagram.h>
|
#define AQDG_GRAPH_COL_ORANGE ((uint32_t) 0xFFA50000)
|
||||||
#include <aqdiagram/draw/context.h>
|
#define AQDG_GRAPH_COL_GOLD ((uint32_t) 0xFFD70000)
|
||||||
#include <aqdiagram/graph/dataset.h>
|
#define AQDG_GRAPH_COL_TURQUOISE ((uint32_t) 0x40E0D000)
|
||||||
#include <aqdiagram/graph/subgraph.h>
|
#define AQDG_GRAPH_COL_SKYBLUE ((uint32_t) 0x87CEEB00)
|
||||||
#include <aqdiagram/graph/settings.h>
|
#define AQDG_GRAPH_COL_DEEPPINK ((uint32_t) 0xFF149300)
|
||||||
|
#define AQDG_GRAPH_COL_COMSILK ((uint32_t) 0xFFF8DC00)
|
||||||
#include <gwenhywfar/db.h>
|
#define AQDG_GRAPH_COL_GAINSBORO ((uint32_t) 0xDCDCDC00)
|
||||||
|
#define AQDG_GRAPH_COL_WHITESMOKE ((uint32_t) 0xF5F5F500)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
enum {
|
||||||
extern "C" {
|
AQDG_GRAPH_PEN_IDX_TITLE=0,
|
||||||
#endif
|
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;
|
enum {
|
||||||
GWEN_LIST_FUNCTION_LIB_DEFS(AQDG_GRAPH, AQDG_Graph, AQDG_API)
|
AQDG_GRAPH_FONT_IDX_TITLE=0,
|
||||||
GWEN_LIST2_FUNCTION_LIB_DEFS(AQDG_GRAPH, AQDG_Graph, AQDG_API)
|
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 {
|
enum {
|
||||||
AQDG_GRAPH_TYPE_UNKNOWN=-1,
|
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);
|
enum {
|
||||||
AQDG_API int AQDG_Graph_InitFromSettings(AQDG_GRAPH *gr, const AQDG_GRAPH_SETTINGS *gs);
|
AQDG_GRAPH_AXISPOS_LEFT=0,
|
||||||
AQDG_API int AQDG_Graph_Fini(AQDG_GRAPH *gr);
|
AQDG_GRAPH_AXISPOS_BOTTOM,
|
||||||
|
AQDG_GRAPH_AXISPOS_RIGHT,
|
||||||
AQDG_API int AQDG_Graph_Draw(AQDG_GRAPH *gr);
|
AQDG_GRAPH_AXISPOS_TOP
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
enum {
|
||||||
}
|
AQDG_GRAPH_DATATYPE_INT=0,
|
||||||
#endif
|
AQDG_GRAPH_DATATYPE_DOUBLE,
|
||||||
|
AQDG_GRAPH_DATATYPE_DATE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct AQDG_GRAPH AQDG_GRAPH;
|
||||||
|
|
||||||
|
|
||||||
|
#include <aqdiagram/graph/axis.h>
|
||||||
|
#include <aqdiagram/graph/subgraph.h>
|
||||||
|
#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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,104 +1,39 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* This file is part of the project AqFinance.
|
* This file is part of the project AqDiagram.
|
||||||
* AqFinance (c) by 2013 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
|
* The license for this file can be found in the file COPYING which you
|
||||||
* should have received along with this file.
|
* should have received along with this file.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef AQDG_GRAPH_GRAPH_P_H
|
||||||
|
#define AQDG_GRAPH_GRAPH_P_H
|
||||||
|
|
||||||
#ifndef AQDG_GRAPH_P_H
|
#include "./graph.h"
|
||||||
#define AQDG_GRAPH_P_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <aqdiagram/graph/graph.h>
|
#define AQDG_GRAPH_NUMAXIS 4
|
||||||
|
#define AQDG_GRAPH_NUMPENS AQDG_GRAPH_PEN_IDX_LAST
|
||||||
|
#define AQDG_GRAPH_NUMFONTS AQDG_GRAPH_FONT_IDX_LAST
|
||||||
#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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct AQDG_GRAPH AQDG_GRAPH;
|
||||||
struct 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;
|
AQDG_DRAW_CONTEXT *drawContext;
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
|
|
||||||
int penTitle;
|
int penArray[AQDG_GRAPH_NUMPENS];
|
||||||
int penSubTitle;
|
int fontArray[AQDG_GRAPH_NUMFONTS];
|
||||||
int penAxisLabel;
|
|
||||||
int penAxis;
|
|
||||||
int penGraph;
|
|
||||||
int penGraphBackground;
|
|
||||||
int penGrid;
|
|
||||||
int penBackground;
|
|
||||||
|
|
||||||
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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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 <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "aqdiagram/graph/layout.h"
|
|
||||||
//#include "aqdiagram/graph/dataset_fns.h"
|
|
||||||
#include "graph_p.h"
|
|
||||||
|
|
||||||
#include <gwenhywfar/debug.h>
|
|
||||||
|
|
||||||
|
|
||||||
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->graphOriginX<gr->graphAreaPosX) {
|
|
||||||
/* 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->graphOriginY<gr->graphAreaPosY) {
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
414
src/lib/aqdiagram/graph/o_graph.c
Normal file
414
src/lib/aqdiagram/graph/o_graph.c
Normal file
@@ -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 <config.h>
|
||||||
|
#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 <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* 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; i<AQDG_GRAPHOBJECT_PEN_IDX_LAST; i++)
|
||||||
|
xo->penArray[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; i<AQDG_GRAPHOBJECT_FONT_IDX_LAST; i++)
|
||||||
|
xo->fontArray[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; i<AQDG_GRAPHOBJECT_PEN_IDX_LAST; i++) {
|
||||||
|
AQDG_Draw_Context_PenRelease(dc, xo->penArray[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; i<AQDG_GRAPHOBJECT_FONT_IDX_LAST; i++) {
|
||||||
|
AQDG_Draw_Context_FontRelease(dc, xo->fontArray[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 && idx<AQDG_GRAPHOBJECT_PEN_IDX_LAST) {
|
||||||
|
AQDG_OBJECT_GRAPH *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o);
|
||||||
|
if (xo)
|
||||||
|
return xo->penArray[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQDG_GraphObject_SetPen(AQDG_OBJECT *o, int idx, int penId)
|
||||||
|
{
|
||||||
|
if (o && idx<AQDG_GRAPHOBJECT_PEN_IDX_LAST) {
|
||||||
|
AQDG_OBJECT_GRAPH *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o);
|
||||||
|
if (xo)
|
||||||
|
xo->penArray[idx]=penId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQDG_GraphObject_GetFont(const AQDG_OBJECT *o, int idx)
|
||||||
|
{
|
||||||
|
if (o && idx<AQDG_GRAPHOBJECT_FONT_IDX_LAST) {
|
||||||
|
AQDG_OBJECT_GRAPH *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o);
|
||||||
|
if (xo)
|
||||||
|
return xo->fontArray[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQDG_GraphObject_SetFont(AQDG_OBJECT *o, int idx, int fontId)
|
||||||
|
{
|
||||||
|
if (o && idx<AQDG_GRAPHOBJECT_FONT_IDX_LAST) {
|
||||||
|
AQDG_OBJECT_GRAPH *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_GRAPH, o);
|
||||||
|
if (xo)
|
||||||
|
xo->fontArray[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<sizeof(_curveColors)/sizeof(uint32_t))
|
||||||
|
return _curveColors[idx];
|
||||||
|
return defCol;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
102
src/lib/aqdiagram/graph/o_graph.h
Normal file
102
src/lib/aqdiagram/graph/o_graph.h
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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_H
|
||||||
|
#define AQDG_GRAPH_O_GRAPH_H
|
||||||
|
|
||||||
|
#include <aqdiagram/placement/object.h>
|
||||||
|
#include <aqdiagram/graph/graph.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
|
||||||
43
src/lib/aqdiagram/graph/o_graph_p.h
Normal file
43
src/lib/aqdiagram/graph/o_graph_p.h
Normal file
@@ -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 <aqdiagram/graph/o_graph.h>
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
65
src/lib/aqdiagram/graph/o_xaxis.c
Normal file
65
src/lib/aqdiagram/graph/o_xaxis.c
Normal file
@@ -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 <config.h>
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,22 +1,20 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* This file is part of the project AqDiagram.
|
* 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
|
* The license for this file can be found in the file COPYING which you
|
||||||
* should have received along with this file.
|
* should have received along with this file.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef AQDG_GRAPH_O_XAXIS_H
|
||||||
|
#define AQDG_GRAPH_O_XAXIS_H
|
||||||
|
|
||||||
#ifndef AQDG_GRAPH_DRAW_H
|
#include <aqdiagram/graph/o_graph.h>
|
||||||
#define AQDG_GRAPH_DRAW_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <aqdiagram/graph/graph.h>
|
AQDG_OBJECT *AQDG_XAxisObject_new(AQDG_OBJECT *parent, uint32_t options, AQDG_OBJECT *graphObject);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AQDG_Graph_DrawFramework(AQDG_GRAPH *gr);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1,22 +1,23 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* This file is part of the project AqDiagram.
|
* 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
|
* The license for this file can be found in the file COPYING which you
|
||||||
* should have received along with this file.
|
* 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
|
#include <aqdiagram/graph/o_graph.h>
|
||||||
#define AQDG_GRAPH_LAYOUT_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <aqdiagram/graph/graph.h>
|
typedef struct AQDG_OBJECT_XAXIS AQDG_OBJECT_XAXIS;
|
||||||
|
struct AQDG_OBJECT_XAXIS {
|
||||||
|
AQDG_OBJECT *graphObject;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AQDG_Graph_PrepareGraph(AQDG_GRAPH *gr);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1,259 +0,0 @@
|
|||||||
<?xml?>
|
|
||||||
|
|
||||||
<tm2>
|
|
||||||
<type id="AQDG_GRAPH_SETTINGS" type="pointer">
|
|
||||||
<descr>
|
|
||||||
This class describes data axis.
|
|
||||||
</descr>
|
|
||||||
<lang id="c">
|
|
||||||
<identifier>AQDG_GRAPH_SETTINGS</identifier>
|
|
||||||
<prefix>AQDG_Graph_Settings</prefix>
|
|
||||||
<baseFileName>settings</baseFileName>
|
|
||||||
|
|
||||||
<flags>
|
|
||||||
with_db
|
|
||||||
with_xml
|
|
||||||
with_list1
|
|
||||||
with_list2
|
|
||||||
with_refcount
|
|
||||||
</flags>
|
|
||||||
|
|
||||||
<headers>
|
|
||||||
<header type="sys" loc="pre">aqdiagram/aqdg_api.h</header>
|
|
||||||
<header type="sys" loc="pre">aqdiagram/draw/context.h</header>
|
|
||||||
|
|
||||||
<header type="sys" loc="post">aqdiagram/graph/graph.h</header>
|
|
||||||
<header type="sys" loc="post">aqdiagram/graph/settings_pen.h</header>
|
|
||||||
<header type="sys" loc="post">aqdiagram/graph/settings_font.h</header>
|
|
||||||
|
|
||||||
</headers>
|
|
||||||
|
|
||||||
|
|
||||||
<inlines>
|
|
||||||
|
|
||||||
<inline loc="end" access="public">
|
|
||||||
<content>
|
|
||||||
$(api) void $(struct_prefix)_SetDefaults($(struct_type) *st);
|
|
||||||
</content>
|
|
||||||
</inline>
|
|
||||||
|
|
||||||
<inline loc="code">
|
|
||||||
<content>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
</content>
|
|
||||||
</inline>
|
|
||||||
|
|
||||||
|
|
||||||
</inlines>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</lang>
|
|
||||||
|
|
||||||
<defines>
|
|
||||||
|
|
||||||
<define id="AQDG_GRAPH_SETTINGS_FLAGS" prefix="AQDG_GRAPH_SETTINGS_FLAGS_">
|
|
||||||
</define>
|
|
||||||
|
|
||||||
</defines>
|
|
||||||
|
|
||||||
|
|
||||||
<members>
|
|
||||||
|
|
||||||
<member name="id" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>with_getbymember</flags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="penTitle" type="AQDG_GRAPH_SETTINGS_PEN" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="penSubTitle" type="AQDG_GRAPH_SETTINGS_PEN" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="penAxisLabel" type="AQDG_GRAPH_SETTINGS_PEN" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="penAxis" type="AQDG_GRAPH_SETTINGS_PEN" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="penGraph" type="AQDG_GRAPH_SETTINGS_PEN" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="penGraphBackground" type="AQDG_GRAPH_SETTINGS_PEN" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="penGrid" type="AQDG_GRAPH_SETTINGS_PEN" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="penBackground" type="AQDG_GRAPH_SETTINGS_PEN" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="fontTitle" type="AQDG_GRAPH_SETTINGS_FONT" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="fontSubTitle" type="AQDG_GRAPH_SETTINGS_FONT" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="fontAxisLabel" type="AQDG_GRAPH_SETTINGS_FONT" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="fontTickLabel" type="AQDG_GRAPH_SETTINGS_FONT" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>assign</setflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="flags" type="uint32_t" maxlen="8">
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<flags>with_flags</flags>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
</members>
|
|
||||||
|
|
||||||
</type>
|
|
||||||
|
|
||||||
</tm2>
|
|
||||||
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
<?xml?>
|
|
||||||
|
|
||||||
<tm2>
|
|
||||||
<type id="AQDG_GRAPH_SETTINGS_FONT" type="pointer">
|
|
||||||
<descr>
|
|
||||||
This class describes data axis.
|
|
||||||
</descr>
|
|
||||||
<lang id="c">
|
|
||||||
<identifier>AQDG_GRAPH_SETTINGS_FONT</identifier>
|
|
||||||
<prefix>AQDG_Graph_SettingsFont</prefix>
|
|
||||||
<baseFileName>settings_font</baseFileName>
|
|
||||||
|
|
||||||
<flags>
|
|
||||||
with_db
|
|
||||||
with_xml
|
|
||||||
with_list1
|
|
||||||
with_list2
|
|
||||||
with_refcount
|
|
||||||
</flags>
|
|
||||||
|
|
||||||
<headers>
|
|
||||||
<header type="sys" loc="pre">aqdiagram/aqdg_api.h</header>
|
|
||||||
</headers>
|
|
||||||
|
|
||||||
</lang>
|
|
||||||
|
|
||||||
<defines>
|
|
||||||
|
|
||||||
<define id="AQDG_GRAPH_SETTINGS_FONT_FLAGS" prefix="AQDG_GRAPH_SETTINGS_FONT_FLAGS_">
|
|
||||||
</define>
|
|
||||||
|
|
||||||
</defines>
|
|
||||||
|
|
||||||
|
|
||||||
<members>
|
|
||||||
|
|
||||||
<member name="fontSize" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="fontSlant" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="fontWeight" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<member name="flags" type="uint32_t" maxlen="8">
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<flags>with_flags</flags>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
<member name="id" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>volatile with_getbymember</flags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
</members>
|
|
||||||
|
|
||||||
</type>
|
|
||||||
|
|
||||||
</tm2>
|
|
||||||
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
<?xml?>
|
|
||||||
|
|
||||||
<tm2>
|
|
||||||
<type id="AQDG_GRAPH_SETTINGS_PEN" type="pointer">
|
|
||||||
<descr>
|
|
||||||
This class describes data axis.
|
|
||||||
</descr>
|
|
||||||
<lang id="c">
|
|
||||||
<identifier>AQDG_GRAPH_SETTINGS_PEN</identifier>
|
|
||||||
<prefix>AQDG_Graph_SettingsPen</prefix>
|
|
||||||
<baseFileName>settings_pen</baseFileName>
|
|
||||||
|
|
||||||
<flags>
|
|
||||||
with_db
|
|
||||||
with_xml
|
|
||||||
with_list1
|
|
||||||
with_list2
|
|
||||||
with_refcount
|
|
||||||
</flags>
|
|
||||||
|
|
||||||
<headers>
|
|
||||||
<header type="sys" loc="pre">aqdiagram/aqdg_api.h</header>
|
|
||||||
</headers>
|
|
||||||
|
|
||||||
</lang>
|
|
||||||
|
|
||||||
<defines>
|
|
||||||
|
|
||||||
<define id="AQDG_GRAPH_SETTINGS_PEN_FLAGS" prefix="AQDG_GRAPH_SETTINGS_PEN_FLAGS_">
|
|
||||||
</define>
|
|
||||||
|
|
||||||
</defines>
|
|
||||||
|
|
||||||
|
|
||||||
<members>
|
|
||||||
|
|
||||||
<member name="frontColour" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="backColour" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="lineWidth" type="int" maxlen="8" >
|
|
||||||
<default>1</default>
|
|
||||||
<preset>1</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
<member name="dashType" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<member name="flags" type="uint32_t" maxlen="8">
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<flags>with_flags</flags>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
<member name="id" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>volatile with_getbymember</flags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
</members>
|
|
||||||
|
|
||||||
</type>
|
|
||||||
|
|
||||||
</tm2>
|
|
||||||
|
|
||||||
@@ -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 <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "aqdiagram/graph/setup.h"
|
|
||||||
#include "aqdiagram/graph/tick_fns.h"
|
|
||||||
#include "graph_p.h"
|
|
||||||
|
|
||||||
#include <gwenhywfar/debug.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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 <aqdiagram/graph/graph.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
137
src/lib/aqdiagram/graph/subgraph.t2d
Normal file
137
src/lib/aqdiagram/graph/subgraph.t2d
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<tm2>
|
||||||
|
<type id="AQDG_GRAPH_SUBGRAPH" type="pointer">
|
||||||
|
<descr>
|
||||||
|
This class describes a sub graph.
|
||||||
|
</descr>
|
||||||
|
<lang id="c">
|
||||||
|
<identifier>AQDG_GRAPH_SUBGRAPH</identifier>
|
||||||
|
<prefix>AQDG_Graph_SubGraph</prefix>
|
||||||
|
<baseFileName>subgraph</baseFileName>
|
||||||
|
|
||||||
|
<flags>
|
||||||
|
with_db
|
||||||
|
with_xml
|
||||||
|
with_list1
|
||||||
|
with_list2
|
||||||
|
with_refcount
|
||||||
|
</flags>
|
||||||
|
|
||||||
|
<headers>
|
||||||
|
<header type="sys" loc="pre">aqdiagram/aqdg_api.h</header>
|
||||||
|
<header type="sys" loc="pre">aqdiagram/graph/curve.h</header>
|
||||||
|
<header type="sys" loc="post">aqdiagram/graph/graph.h</header>
|
||||||
|
</headers>
|
||||||
|
|
||||||
|
<inlines>
|
||||||
|
|
||||||
|
<inline loc="end" access="public">
|
||||||
|
<content>
|
||||||
|
$(api) void $(struct_prefix)_CalcMinMaxValues($(struct_type) *st);
|
||||||
|
</content>
|
||||||
|
</inline>
|
||||||
|
|
||||||
|
<inline loc="code">
|
||||||
|
<content>
|
||||||
|
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
|
||||||
|
</content>
|
||||||
|
</inline>
|
||||||
|
|
||||||
|
|
||||||
|
</inlines>
|
||||||
|
|
||||||
|
|
||||||
|
</lang>
|
||||||
|
|
||||||
|
<members>
|
||||||
|
|
||||||
|
<member name="indexAxisX" type="int" maxlen="8" >
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="indexAxisY" type="int" maxlen="8" >
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<member name="minValueX" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="maxValueX" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
|
||||||
|
<member name="minValueY" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="maxValueY" type="double" maxlen="8" >
|
||||||
|
<default>0.0</default>
|
||||||
|
<preset>0.0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<member name="curves" type="AQDG_GRAPH_CURVE_LIST" >
|
||||||
|
<default>NULL</default>
|
||||||
|
<preset>AQDG_Graph_Curve_List_new()</preset>
|
||||||
|
<access>public</access>
|
||||||
|
<flags>own</flags>
|
||||||
|
<setflags>nodup</setflags>
|
||||||
|
<getflags>none</getflags>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
|
||||||
|
</members>
|
||||||
|
|
||||||
|
</type>
|
||||||
|
|
||||||
|
</tm2>
|
||||||
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
<?xml?>
|
|
||||||
|
|
||||||
<tm2>
|
|
||||||
<type id="AQDG_GRAPH_SUBGRAPH" type="pointer">
|
|
||||||
<descr>
|
|
||||||
This class describes a sub graph.
|
|
||||||
</descr>
|
|
||||||
<lang id="c">
|
|
||||||
<identifier>AQDG_GRAPH_SUBGRAPH</identifier>
|
|
||||||
<prefix>AQDG_Graph_SubGraph</prefix>
|
|
||||||
<baseFileName>subgraph</baseFileName>
|
|
||||||
|
|
||||||
<flags>
|
|
||||||
with_db
|
|
||||||
with_xml
|
|
||||||
with_list1
|
|
||||||
with_list2
|
|
||||||
with_refcount
|
|
||||||
</flags>
|
|
||||||
|
|
||||||
<headers>
|
|
||||||
<header type="sys" loc="pre">aqdiagram/aqdg_api.h</header>
|
|
||||||
</headers>
|
|
||||||
|
|
||||||
</lang>
|
|
||||||
|
|
||||||
<members>
|
|
||||||
|
|
||||||
<member name="label" type="char_ptr" maxlen="128" >
|
|
||||||
<default>NULL</default>
|
|
||||||
<preset>NULL</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>own</flags>
|
|
||||||
<setflags>const dup</setflags>
|
|
||||||
<getflags>const</getflags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="level" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>with_getbymember</flags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="graphType" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="dataMode" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="colour" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="lineWidth" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
<member name="dashType" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
<member name="penId" type="int" maxlen="8" >
|
|
||||||
<default>0</default>
|
|
||||||
<preset>0</preset>
|
|
||||||
<access>public</access>
|
|
||||||
<flags>volatile</flags>
|
|
||||||
</member>
|
|
||||||
|
|
||||||
|
|
||||||
</members>
|
|
||||||
|
|
||||||
</type>
|
|
||||||
|
|
||||||
</tm2>
|
|
||||||
|
|
||||||
@@ -14,19 +14,10 @@
|
|||||||
with_db
|
with_db
|
||||||
with_xml
|
with_xml
|
||||||
with_list1
|
with_list1
|
||||||
with_list2
|
|
||||||
with_refcount
|
|
||||||
</flags>
|
</flags>
|
||||||
|
|
||||||
<headers>
|
<headers>
|
||||||
<header type="sys" loc="pre">aqdiagram/aqdg_api.h</header>
|
<header type="sys" loc="pre">aqdiagram/aqdg_api.h</header>
|
||||||
|
|
||||||
<header type="sys" loc="post">aqdiagram/graph/dataset.h</header>
|
|
||||||
<header type="sys" loc="post">aqdiagram/graph/tick_fns.h</header>
|
|
||||||
<header type="local" loc="codeEnd">tick_fns.c</header>
|
|
||||||
|
|
||||||
<header type="sys" loc="pre">gwenhywfar/gwendate.h</header>
|
|
||||||
<header type="sys" loc="pre">gwenhywfar/i18n.h</header>
|
|
||||||
</headers>
|
</headers>
|
||||||
|
|
||||||
</lang>
|
</lang>
|
||||||
@@ -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<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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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->level<p_b->level)
|
|
||||||
p_rv=-1;
|
|
||||||
else
|
|
||||||
p_rv=1;
|
|
||||||
}
|
|
||||||
else if (p_a->value<p_b->value)
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user