Beispiel #1
0
        // /// <summary>Indicates that the axis origin is fixed to a certain value.</summary>
        // public abstract bool   OrgFixed { get; set; }
        // /// <summary>Indicates that the axis end is fixed to a certain value.</summary>
        // public abstract bool   EndFixed { get; set; }

        /// <summary>
        /// calculates the axis org and end using the databounds
        /// the org / end is adjusted only if it is not fixed
        /// and the DataBound object contains valid data
        /// </summary>

        public void ProcessDataBounds(DateTime org, bool orgfixed, DateTime end, bool endfixed)
        {
            if (IsLinked)
            {
                return;
            }

            DateTime     oldAxisOrg  = _axisOrg;
            DateTime     oldAxisEnd  = _axisEnd;
            SpanCompound oldAxisSpan = _majorSpan;

            CalculateTicks(org, end, out _majorSpan, out _minorTicks);

            if (end >= org)
            {
                if (orgfixed)
                {
                    _axisOrg = org;
                }
                else
                {
                    _axisOrg = _majorSpan.RoundDown(org);
                }

                if (endfixed)
                {
                    _axisEnd = end;
                }
                else
                {
                    _axisEnd = _majorSpan.RoundUp(end);
                }
            }
            else // org is greater than end !
            {
                if (orgfixed)
                {
                    _axisOrg = org;
                }
                else
                {
                    _axisOrg = _majorSpan.RoundUp(org);
                }

                if (endfixed)
                {
                    _axisEnd = end;
                }
                else
                {
                    _axisEnd = _majorSpan.RoundDown(end);
                }
            }

            // compare with the saved values to find out whether or not something changed
            if (_axisOrg != oldAxisOrg || _axisEnd != oldAxisEnd || _majorSpan._span != oldAxisSpan._span || _majorSpan._unit != oldAxisSpan._unit)
            {
                OnChanged();
            }
        }
Beispiel #2
0
        public void CopyFrom(DateTimeScale from)
        {
            if (object.ReferenceEquals(this, from))
            {
                return;
            }

            IsLinked = from.IsLinked;

            _axisOrg    = from._axisOrg;
            _axisEnd    = from._axisEnd;
            _majorSpan  = from._majorSpan;
            _minorTicks = from._minorTicks;

            InternalSetDataBounds((FiniteDateTimeBoundaries)from._dataBounds.Clone());
            InternalSetRescaling((DateTimeScaleRescaleConditions)from._rescaling.Clone());
        }
Beispiel #3
0
        static void CalculateTicks(
            DateTime min,               // Minimum of data
            DateTime max,               // Maximum of data
            out SpanCompound majorspan, // the span between two major ticks
            out int minorticks          // number of ticks in a major tick span
            )
        {
            if (min > max) // should not happen, but can happen when there are no data and min and max are uninitialized
            {
                min = max = DateTime.MinValue;
            }

            TimeSpan span = max - min; // span width between max and min

            if (0 == span.Ticks)
            {
                TimeSpan diff;
                // if span width is zero, then 1% of the velue, in case of min==max==0 we use 1
                if (DateTime.MinValue == max || DateTime.MinValue == min) // if one is null, the other should also be null, but to be secure...
                {
                    diff = TimeSpan.FromSeconds(1);
                }
                else
                {
                    diff = TimeSpan.FromDays(1); // wir can be sure, that min==max, because span==0
                }
                min -= diff;
                max += diff;

                span = max - min;
            } // if 0==span


            if (span > _fixedSpan[_fixedSpan.Length - 1])
            {
                if (span >= TimeSpan.FromDays(365 * 4 + 1))
                {
                    minorticks = 0;
                    majorspan  = CalculateYearTicks(span);
                }
                else
                {
                    minorticks = 0;
                    majorspan  = CalculateMonthTicks(span);
                }
            }
            else
            {
                int      i           = _fixedSpan.Length - 1;
                TimeSpan quarterspan = new TimeSpan(span.Ticks / 4);
                for (i = _fixedSpan.Length - 1; i >= 0; i--)
                {
                    if (_fixedSpan[i] < quarterspan)
                    {
                        break;
                    }
                }
                minorticks = 0;
                majorspan  = new SpanCompound(Unit.Span, _fixedSpan[Math.Max(i, 0)]);
                if (span < TimeSpan.FromTicks(6 * majorspan._span.Ticks))
                {
                    minorticks = 1;
                }
            }
        } // end of function
Beispiel #4
0
		private static void CalculateTicks(
			DateTime min,                // Minimum of data
			DateTime max,                // Maximum of data
			out SpanCompound majorspan,      // the span between two major ticks
			out int minorticks      // number of ticks in a major tick span
			)
		{
			if (min > max) // should not happen, but can happen when there are no data and min and max are uninitialized
			{
				min = max = DateTime.MinValue;
			}

			TimeSpan span = max - min; // span width between max and min

			if (0 == span.Ticks)
			{
				TimeSpan diff;
				// if span width is zero, then 1% of the velue, in case of min==max==0 we use 1
				if (DateTime.MinValue == max || DateTime.MinValue == min) // if one is null, the other should also be null, but to be secure...
					diff = TimeSpan.FromSeconds(1);
				else
					diff = TimeSpan.FromDays(1); // wir can be sure, that min==max, because span==0

				min -= diff;
				max += diff;

				span = max - min;
			} // if 0==span

			if (span > _fixedSpan[_fixedSpan.Length - 1])
			{
				if (span >= TimeSpan.FromDays(365 * 4 + 1))
				{
					minorticks = 0;
					majorspan = CalculateYearTicks(span);
				}
				else
				{
					minorticks = 0;
					majorspan = CalculateMonthTicks(span);
				}
			}
			else
			{
				int i = _fixedSpan.Length - 1;
				TimeSpan quarterspan = new TimeSpan(span.Ticks / 4);
				for (i = _fixedSpan.Length - 1; i >= 0; i--)
				{
					if (_fixedSpan[i] < quarterspan)
						break;
				}
				minorticks = 0;
				majorspan = new SpanCompound(Unit.Span, _fixedSpan[Math.Max(i, 0)]);
				if (span < TimeSpan.FromTicks(6 * majorspan._span.Ticks))
					minorticks = 1;
			}
		} // end of function
Beispiel #5
0
		public void CopyFrom(DateTimeScale from)
		{
			if (object.ReferenceEquals(this, from))
				return;

			this.IsLinked = from.IsLinked;

			this._axisOrg = from._axisOrg;
			this._axisEnd = from._axisEnd;
			this._majorSpan = from._majorSpan;
			this._minorTicks = from._minorTicks;

			this.InternalSetDataBounds((FiniteDateTimeBoundaries)from._dataBounds.Clone());
			this.InternalSetRescaling((DateTimeScaleRescaleConditions)from._rescaling.Clone());
		}