예제 #1
0
        protected static TimeSpan Shift(TimeSpan span, DifferenceIn diff)
        {
            TimeSpan res = span;

            TimeSpan shift = new TimeSpan();

            switch (diff)
            {
            case DifferenceIn.Year:
            case DifferenceIn.Month:
            case DifferenceIn.Day:
                shift = TimeSpan.FromDays(1);
                break;

            case DifferenceIn.Hour:
                shift = TimeSpan.FromHours(1);
                break;

            case DifferenceIn.Minute:
                shift = TimeSpan.FromMinutes(1);
                break;

            case DifferenceIn.Second:
                shift = TimeSpan.FromSeconds(1);
                break;

            case DifferenceIn.Millisecond:
                shift = TimeSpan.FromMilliseconds(1);
                break;
            }

            res = res.Add(shift);
            return(res);
        }
예제 #2
0
        public ITicksInfo <T> GetTicks(Range <T> range, int ticksCount)
        {
            T            start = range.Min;
            T            end   = range.Max;
            DifferenceIn diff  = Difference;

            start = RoundDown(start, end);
            end   = RoundUp(start, end);

            RoundingInfo bounds = RoundHelper.CreateRoundedRange(
                GetSpecificValue(start, start),
                GetSpecificValue(start, end));

            int delta = (int)(bounds.Max - bounds.Min);

            if (delta == 0)
            {
                return new TicksInfo <T> {
                           Ticks = new T[] { start }
                }
            }
            ;

            int step = delta / ticksCount;

            if (step == 0)
            {
                step = 1;
            }

            T    tick          = GetStart(start, (int)bounds.Min, step);
            bool isMinDateTime = IsMinDate(tick) && step != 1;

            if (isMinDateTime)
            {
                step--;
            }

            List <T> ticks      = new List <T>();
            T        finishTick = AddStep(range.Max, step);

            while (Continue(tick, finishTick))
            {
                ticks.Add(tick);
                tick = AddStep(tick, step);
                if (isMinDateTime)
                {
                    isMinDateTime = false;
                    step++;
                }
            }

            ticks = Trim(ticks, range);

            TicksInfo <T> res = new TicksInfo <T> {
                Ticks = ticks.ToArray(), Info = diff
            };

            return(res);
        }
        public ITicksInfo <T> GetTicks(Range <T> range, int ticksCount)
        {
            Verify.IsTrue(ticksCount > 0);

            T        start  = range.Min;
            T        end    = range.Max;
            TimeSpan length = GetDifference(start, end);

            diff = strategy.GetDifference(length);

            TicksInfo <T> res = new TicksInfo <T> {
                Info = diff
            };

            if (providers.ContainsKey(diff))
            {
                ITicksInfo <T> result     = providers[diff].GetTicks(range, ticksCount);
                T[]            mayorTicks = result.Ticks;

                res.Ticks   = mayorTicks;
                this.result = res;
                return(res);
            }

            throw new InvalidOperationException();
        }
예제 #4
0
    private void CreateCurrencyDataSource() {
      if (IsPlotterInitialised) return;
      dateAxis.MayorLabelProvider = null;
      var ticksProvider = ((Microsoft.Research.DynamicDataDisplay.Charts.TimeTicksProviderBase<System.DateTime>)(dateAxis.TicksProvider));
      ticksProvider.Strategy = new Microsoft.Research.DynamicDataDisplay.Charts.Axes.DateTime.Strategies.DelegateDateTimeStrategy(GetDifference);
      dateAxis.LabelProvider.SetCustomFormatter(info => {
        DifferenceIn differenceIn = (DifferenceIn)info.Info;
        if (differenceIn == DifferenceIn.Hour) {
          return info.Tick.ToString("H:");
        }
        return null;
      });
      dateAxis.LabelProvider.SetCustomView((li, uiElement) => {
        FrameworkElement element = (FrameworkElement)uiElement;
        element.LayoutTransform = new RotateTransform(-90, 0, 0);
      });
      var a = FindName("PART_AdditionalLabelsCanvas");

      #region Plotter
      IsPlotterInitialised = true;
      plotter.Children.RemoveAt(0);
      var verticalAxis = plotter.Children.OfType<VerticalAxis>().First();
      verticalAxis.FontSize = 10;
      verticalAxis.ShowMinorTicks = false;
      innerPlotter.Children.Remove(innerPlotter.Children.OfType<VerticalAxis>().Single());
      plotter.Children.OfType<VerticalAxis>().First().Placement = AxisPlacement.Right;
      #endregion

      #region Add Main Graph
      {

        EnumerableDataSource<DateTime> xSrc = new EnumerableDataSource<DateTime>(animatedTimeX);

        EnumerableDataSource<double> animatedDataSource1 = new EnumerableDataSource<double>(animatedPrice1Y);
        animatedDataSource1.SetYMapping(y => y);
        plotter.AddLineGraph(new CompositeDataSource(xSrc, animatedDataSource1), Colors.DarkGray, 1, "")
          .Description.LegendItem.Visibility = Visibility.Collapsed;

        xSrc.SetXMapping(x => dateAxis.ConvertToDouble(x));
        animatedDataSource = new EnumerableDataSource<double>(animatedPriceY);
        animatedDataSource.SetYMapping(y => y);
        this.PriceLineGraph = plotter.AddLineGraph(new CompositeDataSource(xSrc, animatedDataSource), priceLineGraphColorAsk, 1, "");
        this.PriceLineGraph.Description.LegendItem.Visibility = System.Windows.Visibility.Collapsed;

        if (true) {
          animatedDataSourceBid = new EnumerableDataSource<double>(animatedPriceBidY);
          animatedDataSourceBid.SetYMapping(y => y);
          this.PriceLineGraphBid = plotter.AddLineGraph(new CompositeDataSource(xSrc, animatedDataSourceBid), priceLineGraphColorBid, 1, "");
          this.PriceLineGraphBid.Description.LegendItem.Visibility = Visibility.Collapsed;
        }
      }
      //var ticksLineGraph = plotter.AddLineGraph(Ticks.AsDataSource(), Colors.Black, 1, "1M").Description.LegendItem.Visibility = Visibility.Collapsed;
      #endregion

      plotter.KeyDown += new KeyEventHandler(plotter_KeyDown);




    }
예제 #5
0
        public override UIElement[] CreateLabels(ITicksInfo <DateTime> ticksInfo)
        {
            object info  = ticksInfo.Info;
            var    ticks = ticksInfo.Ticks;

            if (info is DifferenceIn)
            {
                DifferenceIn diff = (DifferenceIn)info;
                DateFormat = GetDateFormat(diff);
            }

            LabelTickInfo <DateTime> tickInfo = new LabelTickInfo <DateTime> {
                Info = info
            };

            UIElement[] res = new UIElement[ticks.Length];
            for (int i = 0; i < ticks.Length; i++)
            {
                tickInfo.Tick = ticks[i];

                string    tickText = GetString(tickInfo);
                UIElement label    = new TextBlock {
                    Text = tickText, ToolTip = ticks[i]
                };
                ApplyCustomView(tickInfo, label);
                res[i] = label;
            }

            return(res);
        }
        public ITicksInfo <T> GetTicks(Range <T> range, int ticksCount)
        {
            Verify.IsTrue(ticksCount > 0);

            T        start  = range.Min;
            T        end    = range.Max;
            TimeSpan length = GetDifference(start, end);

            diff = strategy.GetDifference(length);

            TicksInfo <T> result = new TicksInfo <T> {
                Info = diff
            };

            if (providers.ContainsKey(diff))
            {
                ITicksInfo <T> innerResult = providers[diff].GetTicks(range, ticksCount);
                T[]            ticks       = ModifyTicksGuard(innerResult.Ticks, diff);

                result.Ticks = ticks;
                this.result  = result;
                return(result);
            }

            throw new InvalidOperationException(Strings.Exceptions.UnsupportedRangeInAxis);
        }
예제 #7
0
        public sealed override ITicksInfo <DateTime> GetTicks(Range <DateTime> range, int ticksCount)
        {
            DateTime start  = range.Min;
            DateTime end    = range.Max;
            TimeSpan length = end - start;

            bool         isPositive = length.Ticks > 0;
            DifferenceIn diff       = difference;

            DateTime newStart = isPositive ? RoundDown(start, diff) : SafelyRoundUp(start);
            DateTime newEnd   = isPositive ? SafelyRoundUp(end) : RoundDown(end, diff);

            RoundingInfo bounds = RoundHelper.CreateRoundedRange(GetSpecificValue(newStart, newStart), GetSpecificValue(newStart, newEnd));

            int delta = (int)(bounds.Max - bounds.Min);

            if (delta == 0)
            {
                return new TicksInfo <DateTime> {
                           Ticks = new DateTime[] { newStart }
                }
            }
            ;

            int step = delta / ticksCount;

            if (step == 0)
            {
                step = 1;
            }

            DateTime tick          = GetStart(newStart, (int)bounds.Min, step);
            bool     isMinDateTime = IsMinDate(tick) && step != 1;

            if (isMinDateTime)
            {
                step--;
            }

            List <DateTime> ticks      = new List <DateTime>();
            DateTime        finishTick = AddStep(range.Max, step);

            while (tick < finishTick)
            {
                ticks.Add(tick);
                tick = AddStep(tick, step);
                if (isMinDateTime)
                {
                    isMinDateTime = false;
                    step++;
                }
            }

            TicksInfo <DateTime> res = new TicksInfo <DateTime> {
                Ticks = ticks.ToArray(), Info = diff
            };

            return(res);
        }
예제 #8
0
        /// <summary>
        /// Gets the ticks.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="ticksCount">The ticks count.</param>
        /// <returns></returns>
        public override ITicksInfo <DateTime> GetTicks(Range <DateTime> range, int ticksCount)
        {
            Verify.Is(ticksCount > 0);

            DateTime start  = range.Min;
            DateTime end    = range.Max;
            TimeSpan length = end - start;

            diff = GetDifference(length);

            TicksInfo <DateTime> res = new TicksInfo <DateTime> {
                Info = diff
            };

            if (providers.ContainsKey(diff))
            {
                ITicksInfo <DateTime> result     = providers[diff].GetTicks(range, ticksCount);
                DateTime[]            mayorTicks = result.Ticks;

                res.Ticks = mayorTicks;

                DifferenceIn lowerDiff = DifferenceIn.Year;
                // todo разобраться с minor ticks
                bool lowerDiffExists = TryGetLowerDiff(diff, out lowerDiff);
                if (lowerDiffExists && providers.ContainsKey(lowerDiff))
                {
                    var minorTicks = result.Ticks.GetPairs().Select(r => ((IMinorTicksProvider <DateTime>)providers[lowerDiff]).CreateTicks(r)).
                                     SelectMany(m => m).ToArray();

                    res.MinorTicks = minorTicks;
                }
                return(res);
            }


            DateTime newStart = RoundDown(start, diff);
            DateTime newEnd   = RoundUp(end, diff);

            DebugVerify.Is(newStart <= start);

            List <DateTime> resultTicks = new List <DateTime>();
            DateTime        dt          = newStart;

            do
            {
                resultTicks.Add(dt);
                dt = Shift(dt, diff);
            } while (dt <= newEnd);

            while (resultTicks.Count > ticksCount)
            {
                var res2 = resultTicks;
                resultTicks = res2.Where((date, i) => i % 2 == 0).ToList();
            }

            res.Ticks = resultTicks.ToArray();

            return(res);
        }
예제 #9
0
        protected sealed override TimeSpan RoundUp(TimeSpan dateTime, DifferenceIn diff)
        {
            TimeSpan res = RoundDown(dateTime, diff);

            res = Shift(res, diff);

            return(res);
        }
예제 #10
0
        public override DifferenceIn GetDifference(TimeSpan span)
        {
            DifferenceIn?customResult = function(span);

            DifferenceIn result = customResult.HasValue ?
                                  customResult.Value :
                                  base.GetDifference(span);

            return(result);
        }
예제 #11
0
		public bool TryGetBiggerDiff(DifferenceIn diff, out DifferenceIn biggerDiff)
		{
			biggerDiff = diff;

			int index = Array.IndexOf(diffs, diff);
			if (index == -1 || index == 0)
				return false;

			biggerDiff = diffs[index - 1];
			return true;
		}
예제 #12
0
		public virtual bool TryGetLowerDiff(DifferenceIn diff, out DifferenceIn lowerDiff)
		{
			lowerDiff = diff;

			int code = (int)diff;
			bool res = code > (int)DifferenceIn.Smallest;
			if (res)
			{
				lowerDiff = (DifferenceIn)(code - 1);
			}
			return res;
		}
예제 #13
0
		public virtual bool TryGetBiggerDiff(DifferenceIn diff, out DifferenceIn biggerDiff)
		{
			biggerDiff = diff;

			int code = (int)diff;
			bool res = code < (int)DifferenceIn.Biggest;
			if (res)
			{
				biggerDiff = (DifferenceIn)(code + 1);
			}
			return res;
		}
예제 #14
0
        public virtual bool TryGetBiggerDiff(DifferenceIn diff, out DifferenceIn biggerDiff)
        {
            biggerDiff = diff;

            int  code = (int)diff;
            bool res  = code < (int)DifferenceIn.Biggest;

            if (res)
            {
                biggerDiff = (DifferenceIn)(code + 1);
            }
            return(res);
        }
예제 #15
0
        public virtual bool TryGetLowerDiff(DifferenceIn diff, out DifferenceIn lowerDiff)
        {
            lowerDiff = diff;

            int  code = (int)diff;
            bool res  = code > (int)DifferenceIn.Smallest;

            if (res)
            {
                lowerDiff = (DifferenceIn)(code - 1);
            }
            return(res);
        }
예제 #16
0
        /// <summary>
        /// Tries the get lower diff.
        /// </summary>
        /// <param name="diff">The diff.</param>
        /// <param name="lowerDiff">The lower diff.</param>
        /// <returns></returns>
        private static bool TryGetLowerDiff(DifferenceIn diff, out DifferenceIn lowerDiff)
        {
            lowerDiff = diff;

            int  code = (int)diff;
            bool res  = code > 0;

            if (res)
            {
                lowerDiff = (DifferenceIn)(code - 1);
            }
            return(res);
        }
예제 #17
0
        public bool TryGetBiggerDiff(DifferenceIn diff, out DifferenceIn biggerDiff)
        {
            biggerDiff = diff;

            int index = Array.IndexOf(diffs, diff);

            if (index == -1 || index == 0)
            {
                return(false);
            }

            biggerDiff = diffs[index - 1];
            return(true);
        }
예제 #18
0
		public bool TryGetLowerDiff(DifferenceIn diff, out DifferenceIn lowerDiff)
		{
			lowerDiff = diff;

			int index = Array.IndexOf(diffs, diff);
			if (index == -1)
				return false;

			if (index == diffs.Length - 1)
				return false;

			lowerDiff = diffs[index + 1];
			return true;
		}
        protected sealed override TimeSpan RoundDown(TimeSpan timeSpan, DifferenceIn diff)
        {
            TimeSpan res = timeSpan;

            if (timeSpan.Ticks < 0)
            {
                res = RoundUp(timeSpan.Duration(), diff).Negate();
            }
            else
            {
                switch (diff)
                {
                case DifferenceIn.Year:
                case DifferenceIn.Month:
                case DifferenceIn.Day:
                    res = TimeSpan.FromDays(timeSpan.Days);
                    break;

                case DifferenceIn.Hour:
                    res = TimeSpan.FromDays(timeSpan.Days).
                          Add(TimeSpan.FromHours(timeSpan.Hours));
                    break;

                case DifferenceIn.Minute:
                    res = TimeSpan.FromDays(timeSpan.Days).
                          Add(TimeSpan.FromHours(timeSpan.Hours)).
                          Add(TimeSpan.FromMinutes(timeSpan.Minutes));
                    break;

                case DifferenceIn.Second:
                    res = TimeSpan.FromDays(timeSpan.Days).
                          Add(TimeSpan.FromHours(timeSpan.Hours)).
                          Add(TimeSpan.FromMinutes(timeSpan.Minutes)).
                          Add(TimeSpan.FromSeconds(timeSpan.Seconds));
                    break;

                case DifferenceIn.Millisecond:
                    res = timeSpan;
                    break;

                default:
                    break;
                }
            }

            return(res);
        }
예제 #20
0
        public bool TryGetLowerDiff(DifferenceIn diff, out DifferenceIn lowerDiff)
        {
            lowerDiff = diff;

            int index = Array.IndexOf(diffs, diff);

            if (index == -1)
            {
                return(false);
            }

            if (index == diffs.Length - 1)
            {
                return(false);
            }

            lowerDiff = diffs[index + 1];
            return(true);
        }
예제 #21
0
        protected sealed override DateTime RoundDown(DateTime time, DifferenceIn diff)
        {
            DateTime res = time;

            switch (diff)
            {
            case DifferenceIn.Year:
                res = new DateTime(time.Year, 1, 1);
                break;

            case DifferenceIn.Month:
                res = new DateTime(time.Year, time.Month, 1);
                break;

            case DifferenceIn.Day:
                res = time.Date;
                break;

            case DifferenceIn.Hour:
                res = time.Date.AddHours(time.Hour);
                break;

            case DifferenceIn.Minute:
                res = time.Date.AddHours(time.Hour).AddMinutes(time.Minute);
                break;

            case DifferenceIn.Second:
                res = time.Date.AddHours(time.Hour).AddMinutes(time.Minute).AddSeconds(time.Second);
                break;

            case DifferenceIn.Millisecond:
                res = time.Date.AddHours(time.Hour).AddMinutes(time.Minute).AddSeconds(time.Second).AddMilliseconds(time.Millisecond);
                break;

            default:
                break;
            }

            DebugVerify.Is(res <= time);

            return(res);
        }
예제 #22
0
        public override List <FrameworkElement> CreateLabels(ITicksInfo <DateTime> ticksInfo)
        {
            object info  = ticksInfo.Info;
            var    ticks = ticksInfo.Ticks;

            if (info is DifferenceIn)
            {
                DifferenceIn diff = (DifferenceIn)info;
                DateFormat = GetDateFormat(diff);
            }

            tickInfo.Info = info;

            int ticksNum = ticks.Length;

            for (int i = 0; i < ticksNum; i++)
            {
                tickInfo.Tick = ticks[i];
                string    tickText = GetString(tickInfo);
                TextBlock label;
                if (i < allocatedCount)
                {
                    label = allocatedTextBlocksList[i];
                }
                else
                {
                    label = new TextBlock();
                    allocatedFrameworkElementList.Add(label);
                    allocatedTextBlocksList.Add(label);
                }
                label.Text = tickText;
                ApplyCustomView(tickInfo, label);
            }
            if (allocatedCount > ticksNum)
            {
                allocatedFrameworkElementList.RemoveRange(ticksNum, allocatedCount - ticksNum);
                allocatedTextBlocksList.RemoveRange(ticksNum, allocatedCount - ticksNum);
            }
            allocatedCount = ticksNum;

            return(allocatedFrameworkElementList);
        }
        protected static DateTime Shift(DateTime dateTime, DifferenceIn diff)
        {
            DateTime res = dateTime;

            switch (diff)
            {
            case DifferenceIn.Year:
                res = res.AddYears(1);
                break;

            case DifferenceIn.Month:
                res = res.AddMonths(1);
                break;

            case DifferenceIn.Day:
                res = res.AddDays(1);
                break;

            case DifferenceIn.Hour:
                res = res.AddHours(1);
                break;

            case DifferenceIn.Minute:
                res = res.AddMinutes(1);
                break;

            case DifferenceIn.Second:
                res = res.AddSeconds(1);
                break;

            case DifferenceIn.Millisecond:
                res = res.AddMilliseconds(1);
                break;

            default:
                break;
            }

            return(res);
        }
예제 #24
0
        protected override string GetDateFormat(DifferenceIn diff)
        {
            string format = null;

            switch (diff)
            {
            case DifferenceIn.Year:
                format = "yyyy";
                break;

            case DifferenceIn.Month:
                format = "MMMM yyyy";
                break;

            case DifferenceIn.Day:
                format = "%d MMMM yyyy";
                break;

            case DifferenceIn.Hour:
                format = "HH:mm %d MMMM yyyy";
                break;

            case DifferenceIn.Minute:
                format = "HH:mm %d MMMM yyyy";
                break;

            case DifferenceIn.Second:
                format = "HH:mm:ss %d MMMM yyyy";
                break;

            case DifferenceIn.Millisecond:
                format = "fff";
                break;

            default:
                break;
            }

            return(format);
        }
        protected virtual string GetDateFormat(DifferenceIn diff)
        {
            string format = null;

            switch (diff)
            {
            case DifferenceIn.Year:
                format = "yyyy";
                break;

            case DifferenceIn.Month:
                format = "MMM";
                break;

            case DifferenceIn.Day:
                format = "%d";
                break;

            case DifferenceIn.Hour:
                format = "HH:mm";
                break;

            case DifferenceIn.Minute:
                format = "%m";
                break;

            case DifferenceIn.Second:
                format = "ss";
                break;

            case DifferenceIn.Millisecond:
                format = "fff";
                break;

            default:
                break;
            }

            return(format);
        }
예제 #26
0
        protected override DateTime RoundUp(DateTime dateTime, DifferenceIn diff)
        {
            DateTime res = RoundDown(dateTime, diff);

            switch (diff)
            {
            case DifferenceIn.Year:
                res = res.AddYears(1);
                break;

            case DifferenceIn.Month:
                res = res.AddMonths(1);
                break;

            case DifferenceIn.Day:
                res = res.AddDays(1);
                break;

            case DifferenceIn.Hour:
                res = res.AddHours(1);
                break;

            case DifferenceIn.Minute:
                res = res.AddMinutes(1);
                break;

            case DifferenceIn.Second:
                res = res.AddSeconds(1);
                break;

            case DifferenceIn.Millisecond:
                res = res.AddMilliseconds(1);
                break;

            default:
                break;
            }

            return(res);
        }
예제 #27
0
        protected static DateTime RoundDown(DateTime dateTime, DifferenceIn diff)
        {
            DateTime res = dateTime;

            switch (diff)
            {
            case DifferenceIn.Year:
                res = new DateTime(dateTime.Year, 1, 1);
                break;

            case DifferenceIn.Month:
                res = new DateTime(dateTime.Year, dateTime.Month, 1);
                break;

            case DifferenceIn.Day:
                res = dateTime.Date;
                break;

            case DifferenceIn.Hour:
                res = dateTime.Date.AddHours(dateTime.Hour);
                break;

            case DifferenceIn.Minute:
                res = dateTime.Date.AddHours(dateTime.Hour).AddMinutes(dateTime.Minute);
                break;

            case DifferenceIn.Second:
                res = dateTime.Date.AddHours(dateTime.Hour).AddMinutes(dateTime.Minute).AddSeconds(dateTime.Second);
                break;

            case DifferenceIn.Millisecond:
                res = dateTime.Date.AddHours(dateTime.Hour).AddMinutes(dateTime.Minute).AddSeconds(dateTime.Second).AddMilliseconds(dateTime.Millisecond);
                break;
            }

            DebugVerify.Is(res <= dateTime);

            return(res);
        }
예제 #28
0
        public AxisColoringSample()
        {
            InitializeComponent();

            // setting custom colors of background, axis text labels and axis ticks:
            {
                // background brush is for axis's background
                plotter.MainHorizontalAxis.Background = Brushes.Aqua.MakeTransparent(0.1);
                // foreground bruhs is for axis's labels foreground
                plotter.MainHorizontalAxis.Foreground = Brushes.DarkMagenta;

                plotter.MainVerticalAxis.Background = new LinearGradientBrush(Colors.White, Colors.LightBlue, 90);
                plotter.MainVerticalAxis.Foreground = Brushes.DarkGoldenrod;

                // stroke brush is
                // ------ /*to rule them all*/ ------
                // for ticks' fill
                ((NumericAxis)plotter.MainHorizontalAxis).AxisControl.TicksPath.Stroke = Brushes.OrangeRed;
            }

            // this will make the most left axis to display ticks as percents
            secondAxis.LabelProvider = new ToStringLabelProvider();
            secondAxis.LabelProvider.LabelStringFormat = "{0}%";
            secondAxis.LabelProvider.SetCustomFormatter(info => (info.Tick * 100).ToString());
            // percent values that can be divided by 50 without a remainder will be red and with bigger font size
            secondAxis.LabelProvider.SetCustomView((info, ui) =>
            {
                if (((int)Math.Round(info.Tick * 100)) % 50 == 0)
                {
                    TextBlock text  = (TextBlock)ui;
                    text.Foreground = Brushes.Red;
                    text.FontSize   = 20;
                }
            });

            // you can add new axes not only from XAML, but from C#, too:
            HorizontalDateTimeAxis thirdAxis = new HorizontalDateTimeAxis();

            thirdAxis.LabelProvider.SetCustomFormatter(info =>
            {
                DifferenceIn dateTimeDifference = (DifferenceIn)info.Info;
                if (dateTimeDifference == DifferenceIn.Minute)
                {
                    return(info.Tick.ToString("%m:ss"));
                }

                // null should be returned if you want to use default label text
                return(null);
            });

            // let's have major labels for hours in Spanish,
            // for other time periods your Thread.CurrentThread.CurrentCulture will be used to format date.
            // You can change this default thread culture and get desired look of labels.

            CultureInfo culture = new CultureInfo("es-ES");

            thirdAxis.MajorLabelProvider.SetCustomFormatter(info =>
            {
                MajorLabelsInfo mInfo = (MajorLabelsInfo)info.Info;
                if ((DifferenceIn)mInfo.Info == DifferenceIn.Hour)
                {
                    return(info.Tick.ToString("MMMM/dd %m:ss", culture));
                }
                return(null);
            });
            plotter.Children.Add(thirdAxis);

            SetupLocationalAxis();

            SetupPiAxis();

            SetupOneThirdAxis();
        }
        public override UIElement[] CreateLabels(ITicksInfo <DateTime> ticksInfo)
        {
            object info  = ticksInfo.Info;
            var    ticks = ticksInfo.Ticks;

            UIElement[] res       = new UIElement[ticks.Length - 1];
            int         labelsNum = 3;

            if (info is DifferenceIn)
            {
                DifferenceIn diff = (DifferenceIn)info;
                DateFormat = GetDateFormat(diff);
            }
            else if (info is MajorLabelsInfo)
            {
                MajorLabelsInfo mInfo = (MajorLabelsInfo)info;
                DifferenceIn    diff  = (DifferenceIn)mInfo.Info;
                DateFormat = GetDateFormat(diff);
                labelsNum  = mInfo.MajorLabelsCount + 1;

                //DebugVerify.Is(labelsNum < 100);
            }

            DebugVerify.Is(ticks.Length < 10);

            LabelTickInfo <DateTime> tickInfo = new LabelTickInfo <DateTime>();

            for (int i = 0; i < ticks.Length - 1; i++)
            {
                tickInfo.Info = info;
                tickInfo.Tick = ticks[i];

                string tickText = GetString(tickInfo);

                Grid grid = new Grid {
                };

                // doing binding as described at http://sdolha.spaces.live.com/blog/cns!4121802308C5AB4E!3724.entry?wa=wsignin1.0&sa=835372863

                grid.SetBinding(Grid.BackgroundProperty, new Binding {
                    Path = new PropertyPath("(0)", DateTimeAxis.MajorLabelBackgroundBrushProperty), RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor)
                    {
                        AncestorType = typeof(AxisControlBase)
                    }
                });
                Rectangle rect = new Rectangle
                {
                    StrokeThickness = 2
                };
                rect.SetBinding(Rectangle.StrokeProperty, new Binding {
                    Path = new PropertyPath("(0)", DateTimeAxis.MajorLabelRectangleBorderPropertyProperty), RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor)
                    {
                        AncestorType = typeof(AxisControlBase)
                    }
                });

                Grid.SetColumn(rect, 0);
                Grid.SetColumnSpan(rect, labelsNum);

                for (int j = 0; j < labelsNum; j++)
                {
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                }

                grid.Children.Add(rect);

                for (int j = 0; j < labelsNum; j++)
                {
                    var tb = new TextBlock
                    {
                        Text = tickText,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        Margin = new Thickness(0, 3, 0, 3)
                    };
                    Grid.SetColumn(tb, j);
                    grid.Children.Add(tb);
                }

                ApplyCustomView(tickInfo, grid);

                res[i] = grid;
            }

            return(res);
        }
예제 #30
0
        public override UIElement[] CreateLabels(ITicksInfo <DateTime> ticksInfo)
        {
            object info  = ticksInfo.Info;
            var    ticks = ticksInfo.Ticks;

            UIElement[] res       = new UIElement[ticks.Length - 1];
            int         labelsNum = 3;

            if (info is DifferenceIn)
            {
                DifferenceIn diff = (DifferenceIn)info;
                DateFormat = GetDateFormat(diff);
            }
            else if (info is MayorLabelsInfo)
            {
                MayorLabelsInfo mInfo = (MayorLabelsInfo)info;
                DifferenceIn    diff  = (DifferenceIn)mInfo.Info;
                DateFormat = GetDateFormat(diff);
                labelsNum  = mInfo.MayorLabelsCount + 1;

                //DebugVerify.Is(labelsNum < 100);
            }

            DebugVerify.Is(ticks.Length < 10);

            LabelTickInfo <DateTime> tickInfo = new LabelTickInfo <DateTime>();

            for (int i = 0; i < ticks.Length - 1; i++)
            {
                tickInfo.Info = info;
                tickInfo.Tick = ticks[i];

                string tickText = GetString(tickInfo);

                Grid grid = new Grid
                {
                    Background = Brushes.Beige
                };
                Rectangle rect = new Rectangle
                {
                    Stroke          = Brushes.Peru,
                    StrokeThickness = 2
                };
                Grid.SetColumn(rect, 0);
                Grid.SetColumnSpan(rect, labelsNum);

                for (int j = 0; j < labelsNum; j++)
                {
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                }

                grid.Children.Add(rect);

                for (int j = 0; j < labelsNum; j++)
                {
                    var tb = new TextBlock
                    {
                        Text = tickText,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        Margin = new Thickness(0, 3, 0, 3)
                    };
                    Grid.SetColumn(tb, j);
                    grid.Children.Add(tb);
                }

                ApplyCustomView(tickInfo, grid);

                res[i] = grid;
            }

            return(res);
        }
예제 #31
0
 protected abstract T RoundDown(T time, DifferenceIn diff);
        protected override string GetDateFormat(DifferenceIn diff)
        {
            string format = null;

            switch (diff)
            {
                case DifferenceIn.Year:
                    format = "yyyy";
                    break;
                case DifferenceIn.Month:
                    format = "MMMM yyyy";
                    break;
                case DifferenceIn.Day:
                    format = "%d MMMM yyyy";
                    break;
                case DifferenceIn.Hour:
                    format = "HH:mm %d MMMM yyyy";
                    break;
                case DifferenceIn.Minute:
                    format = "HH:mm %d MMMM yyyy";
                    break;
                case DifferenceIn.Second:
                    format = "HH:mm:ss %d MMMM yyyy";
                    break;
                case DifferenceIn.Millisecond:
                    format = "fff";
                    break;
                default:
                    break;
            }

            return format;
        }