From 976d850c9dbd505f0892a13cbf4fb568aeb21475 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Wed, 22 Oct 2025 23:47:40 +0200 Subject: [PATCH] further improved y-axis tick generation. now makes sure the Y axis has at least 4 labeled ticks in level 0. --- src/lib/aqdiagram/graph/axis.t2d | 8 ++++---- src/lib/aqdiagram/graph/w_viewport.c | 11 +++++++---- src/lib/aqdiagram/graph/w_yaxis.c | 11 +++++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/lib/aqdiagram/graph/axis.t2d b/src/lib/aqdiagram/graph/axis.t2d index e61e3d1..5ecb85a 100644 --- a/src/lib/aqdiagram/graph/axis.t2d +++ b/src/lib/aqdiagram/graph/axis.t2d @@ -85,7 +85,7 @@ \n while(v>=0.0) { \n DBG_ERROR(NULL, "Handling level %d (%.2f)", nextLevel, v); \n - if (nextLevel>=2) \n + if (nextLevel>=3) \n break; \n vRun=startValue; \n while(vRun<=(st->maxValue)) { \n @@ -100,13 +100,13 @@ vRun+=v; \n } \n v/=2.0; \n - if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:2)) \n + if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n nextLevel++; \n else \n $(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n \n DBG_ERROR(NULL, "Handling level %d (%.2f)", nextLevel, v); \n - if (nextLevel>=2) \n + if (nextLevel>=3) \n break; \n vRun=startValue; \n while(vRun<=(st->maxValue)) { \n @@ -121,7 +121,7 @@ vRun+=v; \n } \n v/=5.0; \n - if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:2)) \n + if ($(struct_prefix)_HasAtLeastNLevelTicks(st, nextLevel, nextLevel?1:4)) \n nextLevel++; \n else \n $(struct_prefix)_RemoveLevelTicks(st, nextLevel); \n diff --git a/src/lib/aqdiagram/graph/w_viewport.c b/src/lib/aqdiagram/graph/w_viewport.c index a12b837..9b6c7f3 100644 --- a/src/lib/aqdiagram/graph/w_viewport.c +++ b/src/lib/aqdiagram/graph/w_viewport.c @@ -285,6 +285,7 @@ void _drawHorizontalGrid(AQDG_OBJECT *o, AQDG_DRAW_CONTEXT *dc) int x1; int x2; int showLevel1; + int showLevel2; x1=AQDG_Object_GetAbsoluteX(o)+AQDG_Object_GetBorderLeft(o); x2=AQDG_Object_GetAbsoluteX(o)+AQDG_Object_GetWidth(o)-AQDG_Object_GetBorderLeft(o)-AQDG_Object_GetBorderRight(o); @@ -295,20 +296,22 @@ void _drawHorizontalGrid(AQDG_OBJECT *o, AQDG_DRAW_CONTEXT *dc) pen1=AQDG_GraphWidget_GetPen(xo->graphObject, AQDG_GRAPHWIDGET_PEN_IDX_GRID1); pen2=AQDG_GraphWidget_GetPen(xo->graphObject, AQDG_GRAPHWIDGET_PEN_IDX_GRID2); showLevel1=(_screenDistBetweenLevelTicksY(tickList, 1, contentSize, minValue, maxValue)>AQDG_WIDGET_VIEWPORT_TICK_MIN_Y)?1:0; + showLevel2=(_screenDistBetweenLevelTicksY(tickList, 2, contentSize, minValue, maxValue)>AQDG_WIDGET_VIEWPORT_TICK_MIN_Y)?1:0; tick=AQDG_Graph_Tick_List_First(tickList); while(tick) { double value; int ypos; + int tickLevel; value=AQDG_Graph_Tick_GetValue(tick); ypos=_calcVerticalPos(value, contentSize, minValue, maxValue); ypos+=AQDG_Object_GetBorderTop(o); - if (AQDG_Graph_Tick_GetLevel(tick)==0) + tickLevel=AQDG_Graph_Tick_GetLevel(tick); + if (tickLevel==0) AQDG_Draw_Context_DrawLine(dc, pen1, x1, absY+ypos, x2, absY+ypos); - else { - if (showLevel1) - AQDG_Draw_Context_DrawLine(dc, pen2, x1, absY+ypos, x2, absY+ypos); + else if ((tickLevel==1 && showLevel1) || ((tickLevel==2 && showLevel2))) { + AQDG_Draw_Context_DrawLine(dc, pen2, x1, absY+ypos, x2, absY+ypos); } tick=AQDG_Graph_Tick_List_Next(tick); } diff --git a/src/lib/aqdiagram/graph/w_yaxis.c b/src/lib/aqdiagram/graph/w_yaxis.c index 12f555c..6e2a7b8 100644 --- a/src/lib/aqdiagram/graph/w_yaxis.c +++ b/src/lib/aqdiagram/graph/w_yaxis.c @@ -160,6 +160,7 @@ void _drawTicks(AQDG_OBJECT *o, AQDG_DRAW_CONTEXT *dc, int absX) int absY; int pen; int showLevel1; + int showLevel2; contentSize=AQDG_Object_GetHeight(o)-AQDG_Object_GetBorderTop(o)-AQDG_Object_GetBorderBottom(o); scaleSize=AQDG_AxisWidget_GetScaleSize(o); @@ -168,20 +169,22 @@ void _drawTicks(AQDG_OBJECT *o, AQDG_DRAW_CONTEXT *dc, int absX) maxValue=AQDG_AxisWidget_GetMaxValue(o); pen=AQDG_DrawableWidget_GetForegroundPenId(o); showLevel1=(_screenDistBetweenLevelTicks(tickList, 1, contentSize, minValue, maxValue)>AQDG_WIDGET_YAXIS_TICK_MIN_Y)?1:0; + showLevel2=(_screenDistBetweenLevelTicks(tickList, 2, contentSize, minValue, maxValue)>AQDG_WIDGET_YAXIS_TICK_MIN_Y)?1:0; tick=AQDG_Graph_Tick_List_First(tickList); while(tick) { double value; int ypos; + int tickLevel; value=AQDG_Graph_Tick_GetValue(tick); ypos=_calcVerticalPos(value, contentSize, minValue, maxValue); ypos+=AQDG_Object_GetBorderTop(o); - if (AQDG_Graph_Tick_GetLevel(tick)==0) + tickLevel=AQDG_Graph_Tick_GetLevel(tick); + if (tickLevel==0) AQDG_Draw_Context_DrawLine(dc, pen, absX-(scaleSize/2), absY+ypos, absX+(scaleSize/2), absY+ypos); - else { - if (showLevel1) - AQDG_Draw_Context_DrawLine(dc, pen, absX-(scaleSize/4), absY+ypos, absX+(scaleSize/4), absY+ypos); + else if ((tickLevel==1 && showLevel1) || ((tickLevel==2 && showLevel2))) { + AQDG_Draw_Context_DrawLine(dc, pen, absX-(scaleSize/4), absY+ypos, absX+(scaleSize/4), absY+ypos); } tick=AQDG_Graph_Tick_List_Next(tick); }