示例#1
0
        ///
        /// <summary>
        /// After current data is changed this function fixes positions of all columns
        /// and all events</summary>
        ///
        private void FixPositions(
            bool displayEvents,
            bool animate        = false,
            bool updateDuration = false
            )
        {
            double startLeft;
            double posOffset;

            int  colcount;
            long newStart;
            long idxOffset;

            colcount  = (m_columnCount + EXTRA_COLUMNS);
            posOffset = TimeSpanToPixels(CurrentDateTime - m_timeline.GetFloorTime(CurrentDateTime));

            newStart  = m_timeline.IndexOf(CurrentDateTime) - colcount / 2;
            startLeft = (PixelWidth / 2 - ColumnPixelWidth * (colcount / 2)) - posOffset;

            if (m_startIndex == INVALID_COLUMN_IDX || newStart > m_startIndex + colcount || newStart + colcount < m_startIndex)
            {
                //
                // this is case when we draw columns for the first time, or there are no columns which data contexts
                // may be reused
                //
                PositionColumnAndMarker(newStart, startLeft, 0, true, null);
            }
            else if (m_startIndex == newStart)
            {
                //
                // this is the case when we reuse existing column context (date string)
                //
                PositionColumnAndMarker(newStart, startLeft, 0, false, null);
            }
            else
            {
                idxOffset = m_startIndex - newStart;

                ShiftArray(m_columns, idxOffset, out m_columns);
                ShiftArray(m_columnMarkers, idxOffset, out m_columnMarkers);

                PositionColumnAndMarker(newStart, startLeft, 0, false, null);

                if (idxOffset > 0)
                {
                    for (int i = 0; i < idxOffset; ++i)
                    {
                        SetColumnDataContext(newStart + i, i);
                    }
                }
                else
                {
                    for (int i = colcount + (int)idxOffset; i < colcount; ++i)
                    {
                        SetColumnDataContext(newStart + i, i);
                    }
                }
            }
            m_startIndex = Math.Max(0, newStart);

            if (displayEvents)
            {
                DisplayEvents(animate);
            }

            if (updateDuration)
            {
                foreach (var ve in m_visibleEvents)
                {
                    var evnt = ve.Key;
                    TimelineDisplayEvent tde = m_dispEvents[evnt];

                    tde.Recalculate();
                }
            }
        }
示例#2
0
        ///
        /// <summary>
        /// After current data is changed this function fixes positions of all columns
        /// and all events</summary>
        ///
        private void FixPositions(
            )
        {
            double width;
            double height;
            object el;
            double x;
            double ox;
            long   index;
            double posOffset;

            object[] elements;
            object[] textElements = null;
            int      middle;
            DateTime floor;
            DateTime currDate;
            long     maxIndex;

            width  = PixelWidth;
            height = PixelHeight;

            m_minIndex = 0;
            m_maxIndex = 0;

            currDate = CurrentDateTime;

            floor     = m_timeline.GetFloorTime(currDate);
            posOffset = TimeSpanToPixels(currDate - floor);

            elements = new object[m_columnCount + 2];
            m_columnIndexes.Keys.CopyTo(elements, 0);

            textElements = new object[m_columnCount + 2];
            m_columnTextIndexes.Keys.CopyTo(textElements, 0);

            middle   = m_columnCount / 2 + 1;
            ox       = width / 2 - posOffset;
            index    = m_timeline.IndexOf(currDate);
            x        = ox;
            maxIndex = m_timeline.IndexOf(m_timeline.MaxDateTime);

            for (int i = middle; i < m_columnCount + 2; ++i)
            {
                el = elements[i];
                MoveColumn(el, x, GetDataContext(index));
                m_columnIndexes[el] = Math.Min(maxIndex, index);

                el = textElements[i];

                if (el != null)
                {
                    MoveColumnText(el, x, GetDataContext(index));
                    m_columnTextIndexes[el] = Math.Min(maxIndex, index);
                }

                x += ColumnPixelWidth;

                if (index != int.MaxValue)
                {
                    ++index;
                }
            }

            m_maxIndex = index;

            index = m_timeline.IndexOf(currDate) - 1;
            x     = ox - ColumnPixelWidth;

            for (int i = middle - 1; i >= 0; --i, --index)
            {
                el = elements[i];
                MoveColumn(el, x, GetDataContext(index));
                m_columnIndexes[el] = Math.Max(-1, index);

                el = textElements[i];

                if (el != null)
                {
                    MoveColumnText(el, x, GetDataContext(index));
                    m_columnTextIndexes[el] = Math.Min(-1, index);
                }

                x -= ColumnPixelWidth;
            }
            m_minIndex = Math.Max(index, 0);
            DisplayEvents(true);
        }