Page Index Toggle Pages: 1 [2]  Send TopicPrint
Hot Topic (More than 10 Replies) How to show scroll bar in container node ! (Read 9407 times)
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: How to show scroll bar in container node !
Reply #15 - Aug 8th, 2019 at 11:14am
Print Post  
Hi,

It turned out the ScrollBar control wasn't considering variable row heights, we fixed that and the fix will be included in the next release. Until then, as a workaround you can override a couple of the scroller methods to account for the non-uniform heights of your rows:
Code (Javascript)
Select All
MindFusion.Diagramming.ScrollBar.prototype.getThumbRect = function (node, rect)
{
    if (!rect)
        rect = this.getRect();

    if (node.rows.length > 0)
    {
        var allRowsHeight = 0, posHeight = 0;
        for (var i = 0; i < node.rows.length; i++)
        {
            if (i == node.currentScrollRow)
                posHeight = allRowsHeight;
            var rowHeight = node.rows[i] !== undefined ? node.rows[i].height : node.rows[0].height;
            allRowsHeight += rowHeight;
        }

        if (allRowsHeight > rect.height)
        {
            var mm = MindFusion.Drawing.GraphicsUnit.getMillimeter(node.parent.measureUnit);
            var ah = 4 * mm;

            var range = rect.height - 2 * ah;
            var thumbHeight = Math.max(4 * mm, range * rect.height / allRowsHeight);
            range -= thumbHeight;
            var pos = range * posHeight / allRowsHeight;

            var thumbRect = rect.clone();
            thumbRect.height = thumbHeight;
            thumbRect.y += ah + pos;
            return thumbRect;
        }
    }
    return null;
};

MindFusion.Diagramming.ScrollBar.prototype.calcScrollPos = function (mousePosition)
{
    var node = this.node;

    if (node.rows.length > 0)
    {
        var allRowsHeight = 0;
        for (var i = 0; i < node.rows.length; i++)
        {
            var rowHeight = node.rows[i] !== undefined ? node.rows[i].height : node.rows[0].height;
            allRowsHeight += rowHeight;
        }

        var rect = this.getRect();

        if (allRowsHeight > rect.height)
        {
            var mm = MindFusion.Drawing.GraphicsUnit.getMillimeter(node.parent.measureUnit);
            var ah = 4 * mm;

            var range = rect.height - 2 * ah;
            var rellativeY = mousePosition.y - rect.y - ah;
            var relativeScroll = rellativeY / range;
            var totalHeight = 0, scrollPos = node.currentScrollRow;
            for (var i = 0; i < node.rows.length; i++)
            {
                var rowHeight = node.rows[i] !== undefined ? node.rows[i].height : node.rows[0].height;
                var rowLow = totalHeight / allRowsHeight;
                totalHeight += rowHeight;
                var rowHigh = totalHeight / allRowsHeight;
                if (relativeScroll >= rowLow && relativeScroll <= rowHigh)
                {
                    scrollPos = i;
                    break;
                }
            }
            scrollPos = Math.max(0, scrollPos);
            scrollPos = Math.min(scrollPos, node.rows.length - 1);
            return scrollPos;
        }
    }
    return 0;
} 



Regards,
Lyubo
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint