use AQDG_Graph_Axis_AddMargins()

This commit is contained in:
Martin Preuss
2025-12-31 14:05:33 +01:00
parent aefee5d631
commit a2319c1823

View File

@@ -37,9 +37,6 @@
* ------------------------------------------------------------------------------------------------ * ------------------------------------------------------------------------------------------------
*/ */
static void _addMarginsToAxis(AQDG_GRAPH_AXIS *axis, double percent);
static void _setupTicksForTimeAxis(AQDG_GRAPH_AXIS *axis);
static void _setupTicksForDataAxis(AQDG_GRAPH_AXIS *axis);
static int _readNumFromString(const char **sPtr); static int _readNumFromString(const char **sPtr);
@@ -49,8 +46,6 @@ static int _readNumFromString(const char **sPtr);
* ------------------------------------------------------------------------------------------------ * ------------------------------------------------------------------------------------------------
*/ */
AQDG_GRAPH *AQDG_TimeGraph_new(const char *sTitle, AQDG_GRAPH *AQDG_TimeGraph_new(const char *sTitle,
const char *sSubTitle, const char *sSubTitle,
const char *sYLabel, const char *sYLabel,
@@ -114,102 +109,24 @@ void AQDG_TimeGraph_SetupTicks(AQDG_GRAPH *g, uint32_t flags, double minY, doubl
/* create ticks for X axis */ /* create ticks for X axis */
axis=AQDG_Graph_GetAxisByIndex(g, AQDG_GRAPH_AXISPOS_BOTTOM); axis=AQDG_Graph_GetAxisByIndex(g, AQDG_GRAPH_AXISPOS_BOTTOM);
if (axis) { if (axis) {
_addMarginsToAxis(axis, AQDG_TIMEGRAPH_MARGINSPERCENT_X); AQDG_Graph_Axis_AddMargins(axis, AQDG_TIMEGRAPH_MARGINSPERCENT_X);
_setupTicksForTimeAxis(axis); AQDG_Graph_Axis_GenTimeTicks(axis);
} }
/* create ticks for Y axis */ /* create ticks for Y axis */
axis=AQDG_Graph_GetAxisByIndex(g, AQDG_GRAPH_AXISPOS_LEFT); axis=AQDG_Graph_GetAxisByIndex(g, AQDG_GRAPH_AXISPOS_LEFT);
if (axis) { if (axis) {
_addMarginsToAxis(axis, AQDG_TIMEGRAPH_MARGINSPERCENT_Y); AQDG_Graph_Axis_AddMargins(axis, AQDG_TIMEGRAPH_MARGINSPERCENT_Y);
if (flags & AQDG_TIMEGRAPH_SETUPTICKS_FLAGS_MINY) if (flags & AQDG_TIMEGRAPH_SETUPTICKS_FLAGS_MINY)
AQDG_Graph_Axis_SetMinValue(axis, minY); AQDG_Graph_Axis_SetMinValue(axis, minY);
if (flags & AQDG_TIMEGRAPH_SETUPTICKS_FLAGS_MAXY) if (flags & AQDG_TIMEGRAPH_SETUPTICKS_FLAGS_MAXY)
AQDG_Graph_Axis_SetMaxValue(axis, maxY); AQDG_Graph_Axis_SetMaxValue(axis, maxY);
_setupTicksForDataAxis(axis);
}
}
void _addMarginsToAxis(AQDG_GRAPH_AXIS *axis, double percent)
{
double vMax;
double vMin;
double vDiff;
vMin=AQDG_Graph_Axis_GetMinValue(axis);
vMax=AQDG_Graph_Axis_GetMaxValue(axis);
vDiff=vMax-vMin;
DBG_ERROR(NULL, "old vMin=%.2f, vMax=%.2f", vMin, vMax);
if (vDiff==0.0) {
DBG_ERROR(NULL, "min = max = %.2f", vMax);
vDiff=vMax;
if (vDiff==0.0)
vDiff=1.0;
}
if (vDiff>0.0) {
double vDiffForPercent;
DBG_ERROR(NULL, "Setting vmin and vmax");
vDiffForPercent=vDiff*(percent/100.0);
vMin-=vDiffForPercent;
vMax+=vDiffForPercent;
DBG_ERROR(NULL, "new vMin=%.2f, vMax=%.2f", vMin, vMax);
AQDG_Graph_Axis_SetMinValue(axis, vMin);
AQDG_Graph_Axis_SetMaxValue(axis, vMax);
}
}
void _setupTicksForTimeAxis(AQDG_GRAPH_AXIS *axis)
{
#if 0
double minValue;
double maxValue;
double diffInDays;
minValue=AQDG_Graph_Axis_GetMinValue(axis);
maxValue=AQDG_Graph_Axis_GetMaxValue(axis);
diffInDays=(maxValue-minValue)/(24*60*60);
DBG_ERROR(AQDG_LOGDOMAIN, "Difference in days: %f.0", diffInDays);
if (diffInDays<3) {
AQDG_Graph_Axis_GenHourTicks(axis, 0, 1);
}
else if (diffInDays<32) {
AQDG_Graph_Axis_GenDayTicks(axis, 0); /* level 0: gen tick for every day */
AQDG_Graph_Axis_GenHourTicks(axis, 1, 8); /* level 1: gen tick for every 8h */
}
else if (diffInDays<90) {
AQDG_Graph_Axis_GenWeekTicks(axis, 0);
AQDG_Graph_Axis_GenDayTicks(axis, 1);
}
else {
AQDG_Graph_Axis_GenMonthTicks(axis, 0);
if (diffInDays<100) {
AQDG_Graph_Axis_GenDayTicks(axis, 1);
}
else if (diffInDays<400) {
AQDG_Graph_Axis_GenWeekTicks(axis, 1);
}
}
#else
AQDG_Graph_Axis_GenTimeTicks(axis);
#endif
}
void _setupTicksForDataAxis(AQDG_GRAPH_AXIS *axis)
{
AQDG_Graph_Axis_GenLog10Ticks(axis); AQDG_Graph_Axis_GenLog10Ticks(axis);
}
} }
void AQDG_TimeGraph_ModifyDataAndAddCurve(AQDG_GRAPH *g, const char *sLabel, const char *sModifier, void AQDG_TimeGraph_ModifyDataAndAddCurve(AQDG_GRAPH *g, const char *sLabel, const char *sModifier,
AQDG_GRAPH_DATAPAIR_LIST *dpList) AQDG_GRAPH_DATAPAIR_LIST *dpList)
{ {