hide labels which don't fit inside the axis widget.

This commit is contained in:
Martin Preuss
2025-12-26 11:21:32 +01:00
parent c6edc77a3d
commit 031357d2fb

View File

@@ -36,7 +36,10 @@ static GWENHYWFAR_CB void _freeData(void *bp, void *p);
static void _setupObjectTree(AQDG_OBJECT *o);
static void _createTickLabelsForLevel(AQDG_OBJECT *o, AQDG_GRAPH *graph, const AQDG_GRAPH_TICK_LIST *tickList, int level);
static int _doesCollideWithOtherChildren(const AQDG_OBJECT *object, const AQDG_OBJECT *newObject);
static int _fitsIntoAxisWidget(const AQDG_OBJECT *o, AQDG_OBJECT *child);
static int _hasLabelCollisions(const AQDG_OBJECT *o);
static void _hideNonFittingLabels(const AQDG_OBJECT *o);
static int _hideEverySecondLabel(AQDG_OBJECT *o);
@@ -196,6 +199,8 @@ void AQDG_AxisWidget_HideCollidingChildren(AQDG_OBJECT *o)
{
int doRun=1;
_hideNonFittingLabels(o);
while(doRun) {
if (_hasLabelCollisions(o))
doRun=(_hideEverySecondLabel(o)<0)?0:1;
@@ -334,11 +339,31 @@ int _doesCollideWithOtherChildren(const AQDG_OBJECT *object, const AQDG_OBJECT *
int _fitsIntoAxisWidget(const AQDG_OBJECT *o, AQDG_OBJECT *child)
{
int xLeft;
int xRight;
int yTop;
int yBottom;
int parentWidth;
int parentHeight;
parentWidth=AQDG_Object_GetWidth(o);
parentHeight=AQDG_Object_GetHeight(o);
xLeft=AQDG_Object_GetRelativeX(child);
xRight=xLeft+AQDG_Object_GetWidth(child);
yTop=AQDG_Object_GetRelativeY(child);
yBottom=yTop+AQDG_Object_GetHeight(child);
return ((xLeft>=0) && (xRight<parentWidth) && (yTop>=0) && (yBottom<parentHeight))?1:0;
}
int _hasLabelCollisions(const AQDG_OBJECT *o)
{
AQDG_OBJECT *child;
/* align left */
child=AQDG_Object_Tree2_GetFirstChild(o);
while(child) {
if (!(AQDG_Object_GetFlags(child) & AQDG_OBJECT_FLAGS_HIDDEN)) {
@@ -352,6 +377,22 @@ int _hasLabelCollisions(const AQDG_OBJECT *o)
void _hideNonFittingLabels(const AQDG_OBJECT *o)
{
AQDG_OBJECT *child;
child=AQDG_Object_Tree2_GetFirstChild(o);
while(child) {
if (!(AQDG_Object_GetFlags(child) & AQDG_OBJECT_FLAGS_HIDDEN)) {
if (!_fitsIntoAxisWidget(o, child))
AQDG_Object_AddFlags(child, AQDG_OBJECT_FLAGS_HIDDEN);
}
child=AQDG_Object_Tree2_GetNext(child);
}
}
int _hideEverySecondLabel(AQDG_OBJECT *o)
{
AQDG_OBJECT *child;