October 31, 2020, 01:50:13 AM

See more Support incidents in our old archived forum.

Author Topic: Zoom behavior issue since 7.0  (Read 5005 times)

joachim.saesen

  • Customers
  • Newbie
  • *
  • Posts: 9
Zoom behavior issue since 7.0
« on: October 01, 2015, 10:15:21 AM »
Hi,

I've implemented some custom logic after zooming. Some requirements:

- The time that is under the mouse cursor while zooming with Ctrl+scroll, has to remain under the mouse cursor, to give the user the impression that he/she is zooming into that point. In case of CTRL+ (in which I call zoom manually by catching key events) the time in the center of the screen must remain in the center.
- The start time of the gantt must always remain the same after zooming. With 'start time' I mean the most left time on the viewport (scrolloffset 0). The user has to be able to get there without using the time shift left button.

I've implemented the following logic to achieve this (see code block). This worked fine with the 6.5 gantt package (and was being tested for several months now) but behaves weird with the 7.0 package. When zooming out to a certain point, the call to gantt.GanttChart.SetStartTime doesn't work anymore, causing the left part of the view not to be visible anymore.

Code: [Select]
        private void Gantt_BeforeZooming(object sender, BeforeZoomEventArgs e)
        {
            _DesiredZoomViewWidth = (_DesiredZoomViewWidth.HasValue ? _DesiredZoomViewWidth.Value : gantt.GanttChart.ViewWidth) * (e.NewBaseTimeUnitWidth / gantt.GanttChart.BaseTimeUnitWidth);

            //For now, assume that scroll is being performed by mouse if not by key, because there is no other way of checking the source of the zoom
            //A zoom called by the control itself will often not pass in the beforezooming event anyway ...
            if (_ZoomTrigger != ZoomTrigger.CtrlKey)
                _ZoomTrigger = ZoomTrigger.CtrlMouse;

            if (_ZoomTrigger == ZoomTrigger.CtrlMouse)
            {
                var mousePosX = Mouse.GetPosition(gantt.GanttChart.ScrollViewerElement).X;
                var time = gantt.GanttChart.ConvertXToTime(mousePosX + gantt.GanttChart.ScrollViewerElement.HorizontalOffset);
                _OffsetTimeBeforeZoom = time;
                _OffsetTimePixelsToViewportBeforeZoom = mousePosX;
            }
            else if (_ZoomTrigger == ZoomTrigger.CtrlKey)
            {
                var centerTimeBeforeZoom = gantt.GanttChart.VisualStartTime.Add(new TimeSpan((gantt.GanttChart.VisualEndTime - gantt.GanttChart.VisualStartTime).Ticks / 2));
                _OffsetTimeBeforeZoom = centerTimeBeforeZoom;
                _OffsetTimePixelsToViewportBeforeZoom = gantt.GanttChart.ConvertTimeToX(centerTimeBeforeZoom) - gantt.GanttChart.ScrollViewerElement.HorizontalOffset;
            }

            _ComputedStartTimeBeforeZoom = gantt.GanttChart.ComputedStartTime;
        }

        private void Gantt_Zoomed(object sender, ZoomedEventArgs args)
        {
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate()
            {
                if (_ZoomTrigger != ZoomTrigger.System)
                {
                    _ZoomTrigger = ZoomTrigger.System; // Set for next time, because system zoom often doesn't get in the 'BeforeZoom' event ...

                    if (!_DesiredZoomViewWidth.HasValue) return;

                    var desiredZoomViewWidth = _DesiredZoomViewWidth.Value;

                    //Change view width in a way that it's wide enough to contain all items in the scroll area from before the zoom (with a maximum of 12000 pix, unfortunately)

                    //If the desired width is greater than 12000, the start time of the scrollable area will stay the same but end time is being cut
                    //This will happen automatically because the start time and ViewWidth is set right on every zoom
                    gantt.GanttChart.ViewWidth = desiredZoomViewWidth > 12000 ? 12000 : (desiredZoomViewWidth < _MinViewWidth ? _MinViewWidth : desiredZoomViewWidth);

                    //The start time of the scrollable area stays the same as before the zoom anytime!
                    gantt.GanttChart.SetStartTime(_ComputedStartTimeBeforeZoom);
                   
                    //Center the time which was in the middle of the screen before zooming (ctrl +/-)
                    //OR set same time under the mouse arrow as before the zoom (ctrl scroll)
                    var timeOffset = this.gantt.GanttChart.ConvertTimeToX(_OffsetTimeBeforeZoom);
                    if (timeOffset >= 0)
                    {
                        // Set amount of pixels relative to the viewport left the same as before the zoom
                        if (timeOffset <= gantt.GanttChart.ViewWidth)
                            gantt.GanttChart.ScrollViewerElement.ScrollToHorizontalOffset(-_OffsetTimePixelsToViewportBeforeZoom + timeOffset);
                        else
                            gantt.GanttChart.ScrollViewerElement.ScrollToRightEnd();
                    }
                }
            }));
        }

        #endregion

Any clues on this one?

Thanks in advance!

Joachim

Rajagopal

  • RQ Members
  • Full Member
  • *
  • Posts: 149
Re: Zoom behavior issue since 7.0
« Reply #1 on: October 01, 2015, 02:27:34 PM »
Joachim,

We will take a closer look.

So, did you say that after zooming, the time under the mouse doesn't change and the start time doesn't change either? This would mean that you are also changing the ViewWidth and call SetStartTime on the chart. Is that what you did?


Thanks,
- Raja.

joachim.saesen

  • Customers
  • Newbie
  • *
  • Posts: 9
Re: Zoom behavior issue since 7.0
« Reply #2 on: October 01, 2015, 02:41:07 PM »
Hi Raja,

That's indeed what I tried to achieve with setting the ViewWidth and the StartTime after zooming. Forgot to mention here that there's of course a limit to that while zooming out. Because at a certain moment, there's simply not enough space left between the left side of the gantt and the mouse arrow to do that. At that point the item under the mouse moves to the left, and everything else is pressed to the left as well (while still keeping the original start time!).

This all worked correctly in the 6.5 version. However in version 7.0, at some point while zooming out, the SetStartTime method doesn't set the actual start time anymore. I can continue zooming out but the start time is never set right again (although passed correctly).


ForumAdmin

  • Administrator
  • Jr. Member
  • *****
  • Posts: 89
Re: Zoom behavior issue since 7.0
« Reply #3 on: October 01, 2015, 04:49:23 PM »
Joachim,

Can you apply this code on one of our samples (like the GantttControlCustomDataBinding) and then provide us the updated .cs file of that sample? Right now, this is throwing a lot of compiler errors, if we try to use it in one of our samples.

Thanks
RQ Support

joachim.saesen

  • Customers
  • Newbie
  • *
  • Posts: 9
Re: Zoom behavior issue since 7.0
« Reply #4 on: October 02, 2015, 07:37:42 AM »
Hi,

I applied it on the above sample project. Forgot to notice that I'm experiencing the problem on the FlexyGantt control (and didn't notice at first that the sample project was a GanttControl). The problem was not reproducable on the GanttControl. But I'll search for another sample project and apply it there.

Joachim

joachim.saesen

  • Customers
  • Newbie
  • *
  • Posts: 9
Re: Zoom behavior issue since 7.0
« Reply #5 on: October 02, 2015, 09:02:24 AM »
I've managed to be able to reproduce the problem in another test project. I'll send a mail to support@radiantq.com with the updated files.

ForumAdmin

  • Administrator
  • Jr. Member
  • *****
  • Posts: 89
Re: Zoom behavior issue since 7.0
« Reply #6 on: October 05, 2015, 03:29:28 PM »
Joachim,

In 7.0, we prevent rendering partial day headers in the beginning of the timeline headers (when there are hidden hour or minute headers). So, to work around this. Please do the following.

a) In your .cs subclass FlexyGantt like this:
Code: [Select]
    /// <summary>
    /// Overriden to allow rendering partial day headers in the beginning of the time-line header.
    /// </summary>
    public class RDFlexyGantt : FlexyGantt
    {
        public override TimeScaleType GetBTSTToRenderAgainst()
        {
            if (this.WorkTimeSchedule == null)
                return this.BaseTimeScaleType;
            else
                // Return this when WTS is not null or when WTS has anything less than 24 hours a day.
                // Or when your have custom resource level schedules set in the FlexyGantt.
                return base.GetBTSTToRenderAgainst();
        }
        public override double GetBTUWToRenderAgainst()
        {
            if (this.WorkTimeSchedule == null)
                return this.BaseTimeUnitWidth;
            else
                // Return this when WTS is not null or when WTS has anything less than 24 hours a day.
                // Or when your have custom resource level schedules set in the FlexyGantt.
                return base.GetBTUWToRenderAgainst();
        }
    }

b) Then in your XAML replace fxgantt:FlexyGantt with local:RDFlexyGantt.

This also requires an updated assembly which we will email you shortly.

Thanks
RQ Support

joachim.saesen

  • Customers
  • Newbie
  • *
  • Posts: 9
Re: Zoom behavior issue since 7.0
« Reply #7 on: October 06, 2015, 12:48:13 PM »
Everything seems to work fine now. Thanks!