Exemple #1
0
        /// <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 override void ProcessDataBounds(AltaxoVariant org, bool orgfixed, AltaxoVariant end, bool endfixed)
        {
            DateTime dorg;
            DateTime dend;

            if (org.IsType(AltaxoVariant.Content.VDateTime))
            {
                dorg = (DateTime)org;
            }
            else if (org.CanConvertedToDouble)
            {
                dorg = new DateTime((long)(org.ToDouble() * 1E7));
            }
            else
            {
                throw new ArgumentException("Variant org is not a DateTime nor a numeric value");
            }

            if (end.IsType(AltaxoVariant.Content.VDateTime))
            {
                dend = (DateTime)end;
            }
            else if (end.CanConvertedToDouble)
            {
                dend = new DateTime((long)(end.ToDouble() * 1E7));
            }
            else
            {
                throw new ArgumentException("Variant end is not a DateTime nor a numeric value");
            }


            ProcessDataBounds(dorg, orgfixed, dend, endfixed);
        }
Exemple #2
0
        private static void ConvertOrgEndToDateTimeValues(AltaxoVariant org, AltaxoVariant end, out DateTime dorg, out DateTime dend)
        {
            if (org.IsType(AltaxoVariant.Content.VDateTime))
            {
                dorg = org;
            }
            else if (org.CanConvertedToDouble)
            {
                dorg = new DateTime((long)(org.ToDouble() * 1E7));
            }
            else
            {
                throw new ArgumentException("Variant org is not a DateTime nor a numeric value");
            }

            if (end.IsType(AltaxoVariant.Content.VDateTime))
            {
                dend = end;
            }
            else if (end.CanConvertedToDouble)
            {
                dend = new DateTime((long)(end.ToDouble() * 1E7));
            }
            else
            {
                throw new ArgumentException("Variant end is not a DateTime nor a numeric value");
            }
        }
        protected override string FormatItem(AltaxoVariant item)
        {
            if (item.IsType(AltaxoVariant.Content.VDateTime) && !string.IsNullOrEmpty(_formatString))
            {
                var dt = item.ToDateTime();

                switch (_timeConversion)
                {
                case TimeConversion.ToLocal:
                    dt = dt.ToLocalTime();
                    break;

                case TimeConversion.ToUtc:
                    dt = dt.ToUniversalTime();
                    break;
                }

                bool showAlternate = false;
                showAlternate |= (_showAlternateFormattingAtMidnight && Math.Abs(dt.TimeOfDay.TotalSeconds) < 1);
                showAlternate |= (_showAlternateFormattingAtNoon && Math.Abs((dt.TimeOfDay - TimeSpan.FromHours(12)).TotalSeconds) < 1);

                try
                {
                    return(string.Format(showAlternate ? _formatStringAlternate : _formatString, dt));
                }
                catch (Exception)
                {
                }
            }
            return(item.ToString());
        }