improved X-axis ticks.

This commit is contained in:
Martin Preuss
2025-12-23 16:58:00 +01:00
parent a75680d875
commit 988ad356c4
2 changed files with 150 additions and 2 deletions

View File

@@ -213,6 +213,56 @@
</inline>
<inline loc="end" access="public">
<content>
$(api) void $(struct_prefix)_GenMinuteTicks($(struct_type) *st, int lvl, int minutes);
</content>
</inline>
<inline loc="code">
<content>
void $(struct_prefix)_GenMinuteTicks($(struct_type) *st, int lvl, int minutes) \n
{ \n
double minValue; \n
double maxValue; \n
GWEN_BUFFER *dbuf; \n
GWEN_TIMESTAMP *ts; \n
int m; \n
int addSecs; \n
\n
addSecs=minutes*60; \n
maxValue=st-&gt;maxValue; \n
minValue=st-&gt;minValue; \n
ts=GWEN_Timestamp_fromLocalTime(minValue); \n
m=(GWEN_Timestamp_GetMinute(ts)/minutes); \n
GWEN_Timestamp_SetTime(ts, GWEN_Timestamp_GetHour(ts), m*minutes, 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;maxValue) { \n
GWEN_Buffer_AppendArgs(dbuf, \n
"%02d:%02d", \n
GWEN_Timestamp_GetHour(ts), \n
GWEN_Timestamp_GetMinute(ts)); \n
if (!$(struct_prefix)_HasTickValue(st, v)) \n
$(struct_prefix)_AddNewTick(st, GWEN_Buffer_GetStart(dbuf), v, lvl, 0, (double) addSecs); \n
GWEN_Buffer_Reset(dbuf); \n
} \n
GWEN_Timestamp_AddSeconds(ts, addSecs); \n
if (v&gt;maxValue) \n
break; \n
} \n
GWEN_Buffer_free(dbuf); \n
GWEN_Timestamp_free(ts); \n
} \n
</content>
</inline>
<inline loc="end" access="public">
<content>
$(api) void $(struct_prefix)_GenHourTicks($(struct_type) *st, int lvl, int hours);
@@ -406,8 +456,8 @@
v=GWEN_Date_toLocalTime(dtCurrent); \n
if (v&gt;=minValue &amp;&amp; v&lt;maxValue) { \n
GWEN_Buffer_AppendArgs(dbuf, \n
"%04d/%02d", \n
GWEN_Date_GetYear(dtCurrent), \n
"%02d/%02d", \n
GWEN_Date_GetYear(dtCurrent)-2000, \n
GWEN_Date_GetMonth(dtCurrent)); \n
if (!$(struct_prefix)_HasTickValue(st, v)) \n
$(struct_prefix)_AddNewTick(st, GWEN_Buffer_GetStart(dbuf), v, lvl, 0, (double) addSecs); \n
@@ -425,6 +475,100 @@
</content>
</inline>
<inline loc="end" access="public">
<content>
$(api) void $(struct_prefix)_GenTimeTicks($(struct_type) *st);
</content>
</inline>
<inline loc="code">
<content>
void $(struct_prefix)_GenTimeTicks($(struct_type) *st) \n
{ \n
int nextLevel=0; \n
\n
$(struct_prefix)_GenMonthTicks(st, nextLevel); \n
if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n
nextLevel++; \n
else \n
$(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n
\n
if (nextLevel&lt;3) { \n
$(struct_prefix)_GenWeekTicks(st, nextLevel); \n
if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n
nextLevel++; \n
else \n
$(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n
} \n
\n
if (nextLevel&lt;3) { \n
$(struct_prefix)_GenDayTicks(st, nextLevel); \n
if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n
nextLevel++; \n
else \n
$(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n
} \n
\n
if (nextLevel&lt;3) { \n
$(struct_prefix)_GenHourTicks(st, nextLevel, 12); \n
if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n
nextLevel++; \n
else \n
$(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n
} \n
\n
if (nextLevel&lt;3) { \n
$(struct_prefix)_GenHourTicks(st, nextLevel, 6); \n
if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n
nextLevel++; \n
else \n
$(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n
} \n
\n
if (nextLevel&lt;3) { \n
$(struct_prefix)_GenHourTicks(st, nextLevel, 6); \n
if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n
nextLevel++; \n
else \n
$(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n
} \n
\n
if (nextLevel&lt;3) { \n
$(struct_prefix)_GenHourTicks(st, nextLevel, 1); \n
if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n
nextLevel++; \n
else \n
$(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n
} \n
if (nextLevel&lt;3) { \n
$(struct_prefix)_GenMinuteTicks(st, nextLevel, 30); \n
if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n
nextLevel++; \n
else \n
$(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n
} \n
if (nextLevel&lt;3) { \n
$(struct_prefix)_GenMinuteTicks(st, nextLevel, 5); \n
if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n
nextLevel++; \n
else \n
$(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n
} \n
if (nextLevel&lt;3) { \n
$(struct_prefix)_GenMinuteTicks(st, nextLevel, 1); \n
if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n
nextLevel++; \n
else \n
$(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n
} \n
} \n
</content>
</inline>
</inlines>
</lang>

View File

@@ -147,6 +147,7 @@ void AQDG_TimeGraph_SetupTicks(AQDG_GRAPH *g, uint32_t flags, double minY, doubl
void _setupTicksForTimeAxis(AQDG_GRAPH_AXIS *axis)
{
#if 0
double minValue;
double maxValue;
double diffInDays;
@@ -175,6 +176,9 @@ void _setupTicksForTimeAxis(AQDG_GRAPH_AXIS *axis)
AQDG_Graph_Axis_GenWeekTicks(axis, 1);
}
}
#else
AQDG_Graph_Axis_GenTimeTicks(axis);
#endif
}