make _GenHourTicks more granular. simplified tick functions.

This commit is contained in:
Martin Preuss
2025-10-01 23:08:02 +02:00
parent 1b63d50d6b
commit b0b13aa471

View File

@@ -22,7 +22,6 @@
<header type="sys" loc="pre">gwenhywfar/buffer.h</header>
<header type="sys" loc="pre">gwenhywfar/timestamp.h</header>
<header type="sys" loc="pre">gwenhywfar/gwendate.h</header>
<header type="sys" loc="pre">gwenhywfar/debug.h</header>
<header type="sys" loc="pre">math.h</header>
</headers>
@@ -47,7 +46,6 @@
if (st-&gt;tickList==NULL) \n
st-&gt;tickList=AQDG_Graph_Tick_List_new(); \n
AQDG_Graph_Tick_List_Add(tick, st-&gt;tickList); \n
DBG_ERROR(NULL, "Added tick: %s (%.2f) [%d]", label, v, lvl);
} \n
</content>
</inline>
@@ -137,46 +135,42 @@
<inline loc="end" access="public">
<content>
$(api) void $(struct_prefix)_GenHourTicks($(struct_type) *st, int lvl);
$(api) void $(struct_prefix)_GenHourTicks($(struct_type) *st, int lvl, int hours);
</content>
</inline>
<inline loc="code">
<content>
void $(struct_prefix)_GenHourTicks($(struct_type) *st, int lvl) \n
void $(struct_prefix)_GenHourTicks($(struct_type) *st, int lvl, int hours) \n
{ \n
double minValue; \n
double maxValue; \n
double endTime; \n
GWEN_BUFFER *dbuf; \n
GWEN_TIMESTAMP *ts; \n
int h; \n
\n
maxValue=st-&gt;maxValue; \n
ts=GWEN_Timestamp_fromLocalTime(maxValue); \n
GWEN_Timestamp_SetTime(ts, GWEN_Timestamp_GetHour(ts), 0, 0); \n
GWEN_Timestamp_AddSeconds(ts, 60*60); \n
endTime=GWEN_Timestamp_toTimeT(ts); \n
GWEN_Timestamp_free(ts); \n
\n
minValue=st-&gt;minValue; \n
ts=GWEN_Timestamp_fromLocalTime(minValue); \n
GWEN_Timestamp_SetTime(ts, GWEN_Timestamp_GetHour(ts), 0, 0); \n
h=(GWEN_Timestamp_GetHour(ts)/hours); \n
GWEN_Timestamp_SetTime(ts, h*hours, 0, 0); \n
\n
dbuf=GWEN_Buffer_new(0, 256, 0, 1); \n
while(1) { \n
double v; \n
\n
v=GWEN_Timestamp_toTimeT(ts); \n
if (v&gt;=minValue &amp;&amp; v&lt;endTime) { \n
if (v&gt;=minValue &amp;&amp; v&lt;maxValue) { \n
GWEN_Buffer_AppendArgs(dbuf, \n
"%02d:%02d", \n
GWEN_Timestamp_GetHour(ts), \n
GWEN_Timestamp_GetMinute(ts)); \n
$(struct_prefix)_AddNewTick(st, GWEN_Buffer_GetStart(dbuf), v, lvl, 0); \n
if (!$(struct_prefix)_HasTickValue(st, v)) \n
$(struct_prefix)_AddNewTick(st, GWEN_Buffer_GetStart(dbuf), v, lvl, 0); \n
GWEN_Buffer_Reset(dbuf); \n
} \n
GWEN_Timestamp_AddSeconds(ts, 60*60); \n
if (v&gt;=endTime) \n
GWEN_Timestamp_AddSeconds(ts, hours*60*60); \n
if (v&gt;maxValue) \n
break; \n
} \n
GWEN_Buffer_free(dbuf); \n
@@ -198,15 +192,10 @@
{ \n
double minValue; \n
double maxValue; \n
double endTime; \n
GWEN_BUFFER *dbuf; \n
GWEN_DATE *dt; \n
\n
maxValue=st-&gt;maxValue; \n
dt=GWEN_Date_fromLocalTime(maxValue); \n
endTime=GWEN_Date_toLocalTime(dt); \n
GWEN_Date_free(dt); \n
\n
minValue=st-&gt;minValue; \n
dt=GWEN_Date_fromLocalTime(minValue); \n
\n
@@ -215,7 +204,7 @@
double v; \n
\n
v=GWEN_Date_toLocalTime(dt); \n
if (v&gt;=minValue &amp;&amp; v&lt;endTime) { \n
if (v&gt;=minValue &amp;&amp; v&lt;maxValue) { \n
GWEN_Buffer_AppendArgs(dbuf, \n
"%04d/%02d/%02d", \n
GWEN_Date_GetYear(dt), \n
@@ -225,7 +214,7 @@
GWEN_Buffer_Reset(dbuf); \n
} \n
GWEN_Date_AddDays(dt, 1); \n
if (v&gt;=endTime) \n
if (v&gt;maxValue) \n
break; \n
} \n
GWEN_Buffer_free(dbuf); \n