Пример #1
0
        protected override void DrawTickLabels(AxisCanvas canvas, TickCoordinates tickCoords, float offset)
        {
            if (!tickCoords.IsEmpty)
            {
                tickCoords = new TickCoordinates(tickCoords.MinorTicks.Skip(1).ToArray(),
                                                 tickCoords.MajorTicks.Skip(1).ToArray(),
                                                 tickCoords.MinorTickCoordinates.Skip(1).ToArray(),
                                                 tickCoords.MajorTickCoordinates.Skip(1).ToArray());
            }

            base.DrawTickLabels(canvas, tickCoords, offset);
        }
Пример #2
0
 object[] GetItems(Renderer2D rend, AxisCanvas ax)
 {
     if (rend != null)
     {
         if (rend.Inverted)
         {
             if (ax == _ay)
             {
                 return(rend.ItemNames);
             }
         }
         else if (ax == _ax)
         {
             return(rend.ItemNames);
         }
     }
     return(null);
 }
Пример #3
0
        void PerformPlotAreaLayout()
        {
            List <AreaDef> list  = new List <AreaDef>();
            List <AreaDef> list2 = new List <AreaDef>();
            int            num   = _view.Axes.Count;

            for (int i = 0; i < num; i++)
            {
                Axis axis = _view.Axes[i];
                if (axis.AxisType == AxisType.X)
                {
                    while (list.Count <= axis.PlotAreaIndex)
                    {
                        list.Add(new AreaDef());
                    }
                    list[axis.PlotAreaIndex].Axes.Add(axis);
                }
                else if (axis.AxisType == AxisType.Y)
                {
                    while (list2.Count <= axis.PlotAreaIndex)
                    {
                        list2.Add(new AreaDef());
                    }
                    list2[axis.PlotAreaIndex].Axes.Add(axis);
                }
            }
            int        ncols    = list.Count;
            int        nrows    = list2.Count;
            Renderer2D renderer = _view.Renderer as Renderer2D;
            Size       size     = new Size(CurrentSize.Width, 0.3 * CurrentSize.Height);
            Size       size2    = new Size(CurrentSize.Height, 0.3 * CurrentSize.Width);
            double     left     = 0.0;
            double     top      = 0.0;
            double     width    = CurrentSize.Width;
            double     height   = CurrentSize.Height;

            for (int j = 0; j < ncols; j++)
            {
                AreaDef def = list[j];
                def.Right  = CurrentSize.Width;
                def.Bottom = CurrentSize.Height;
                for (int num10 = 0; num10 < def.Axes.Count; num10++)
                {
                    AxisCanvas iax   = def.Axes[num10].iax as AxisCanvas;
                    Size       size3 = iax.GetSize(GetItems(renderer, iax), false);
                    if (size3.Height > size.Height)
                    {
                        size3.Height = size.Height;
                    }
                    size3.Width     = size.Width;
                    iax.DesiredSize = size3;
                    if (j == 0)
                    {
                        def.Left = Math.Max(def.Left, iax.AnnoSize.Width * 0.5);
                    }
                    if (j == (ncols - 1))
                    {
                        def.Right = Math.Min(def.Right, CurrentSize.Width - (iax.AnnoSize.Width * 0.5));
                    }
                    if (iax.IsNear)
                    {
                        def.Bottom -= size3.Height;
                    }
                    else if (iax.IsFar)
                    {
                        def.Top += size3.Height;
                    }
                }
            }
            for (int k = 0; k < nrows; k++)
            {
                AreaDef def2 = list2[k];
                def2.Right  = CurrentSize.Width;
                def2.Bottom = CurrentSize.Height;
                for (int num12 = 0; num12 < def2.Axes.Count; num12++)
                {
                    AxisCanvas ax    = def2.Axes[num12].iax as AxisCanvas;
                    Size       size4 = ax.GetSize(GetItems(renderer, ax), false);
                    if (size4.Height > size2.Height)
                    {
                        size4.Height = size2.Height;
                    }
                    size4.Width    = size2.Width;
                    ax.DesiredSize = size4;
                    if (k == 0)
                    {
                        def2.Top = Math.Max(def2.Top, ax.AnnoSize.Width * 0.5);
                    }
                    if (k == (nrows - 1))
                    {
                        def2.Bottom = Math.Min(def2.Bottom, CurrentSize.Height - (ax.AnnoSize.Width * 0.5));
                    }
                    if (ax.IsNear)
                    {
                        def2.Left += size4.Height;
                    }
                    else if (ax.IsFar)
                    {
                        def2.Right -= size4.Height;
                    }
                }
            }
            double num13 = 0.0;
            double num14 = 0.0;
            double num15 = CurrentSize.Width;
            double num16 = CurrentSize.Height;

            for (int m = 0; m < ncols; m++)
            {
                AreaDef def3 = list[m];
                num13 = Math.Max(num13, def3.Left);
                num14 = Math.Max(num14, def3.Top);
                num15 = Math.Min(num15, def3.Right);
                num16 = Math.Min(num16, def3.Bottom);
            }
            for (int n = 0; n < nrows; n++)
            {
                AreaDef def4 = list2[n];
                num13 = Math.Max(num13, def4.Left);
                num14 = Math.Max(num14, def4.Top);
                num15 = Math.Min(num15, def4.Right);
                num16 = Math.Min(num16, def4.Bottom);
            }
            double w = 0.0;
            double h = 0.0;

            AdjustMargins(ref left, ref width, ref top, ref height, ref w, ref h, ref num13, ref num15, ref num14, ref num16);
            _plot = _plot0 = new Rect(left, top, w, h);
            double x = left;

            double[] numArray = _view.PlotAreas.CalculateWidths(w, ncols);
            int      num22    = InternalChildren.Count - 1;

            for (int num23 = 0; num23 < ncols; num23++)
            {
                num16 = height;
                num14 = top;
                AreaDef def5  = list[num23];
                double  num24 = numArray[num23];
                for (int num25 = 0; num25 < def5.Axes.Count; num25++)
                {
                    AxisCanvas canvas3 = def5.Axes[num25].iax as AxisCanvas;
                    canvas3._plot = new Rect(x, _plot0.Top, num24, _plot0.Height);
                    Rect r = new Rect();
                    if (canvas3.IsNear)
                    {
                        r      = new Rect(x, num16, num24, canvas3.DesiredSize.Height);
                        num16 += canvas3.DesiredSize.Height;
                    }
                    else if (canvas3.IsFar)
                    {
                        r      = new Rect(x, num14 - canvas3.DesiredSize.Height, num24, canvas3.DesiredSize.Height);
                        num14 -= canvas3.DesiredSize.Height;
                    }
                    canvas3.Layout(r);
                    if (((canvas3 == _ax) && (renderer != null)) && !renderer.Inverted)
                    {
                        canvas3.CreateLabels(renderer.ItemNames);
                    }
                    else
                    {
                        canvas3.CreateLabels(null);
                    }
                    canvas3.CreateAnnosAndTicks(false);
                }
                foreach (PlotArea area in _view.PlotAreas)
                {
                    if (area.Column == num23)
                    {
                        area.SetPlotX(x, num24);
                    }
                }
                x += num24;
            }
            double y = height;

            double[] numArray2 = _view.PlotAreas.CalculateHeights(h, nrows);
            for (int num27 = 0; num27 < nrows; num27++)
            {
                num13 = left;
                num15 = width;
                AreaDef def6  = list2[num27];
                double  num28 = numArray2[num27];
                y -= num28;
                for (int num29 = 0; num29 < def6.Axes.Count; num29++)
                {
                    AxisCanvas canvas4 = def6.Axes[num29].iax as AxisCanvas;
                    canvas4._plot = new Rect(_plot0.Left, y, _plot0.Width, num28);
                    Rect rect2 = new Rect();
                    if (canvas4.IsNear)
                    {
                        rect2  = new Rect(num13 - canvas4.DesiredSize.Height, y, num28, canvas4.DesiredSize.Height);
                        num13 -= canvas4.DesiredSize.Height;
                    }
                    else if (canvas4.IsFar)
                    {
                        rect2  = new Rect(num15, y, num28, canvas4.DesiredSize.Height);
                        num15 += canvas4.DesiredSize.Height;
                    }
                    canvas4.Layout(rect2);
                    if (((canvas4 == _ay) && (renderer != null)) && renderer.Inverted)
                    {
                        canvas4.CreateLabels(renderer.ItemNames);
                    }
                    else
                    {
                        canvas4.CreateLabels(null);
                    }
                    canvas4.CreateAnnosAndTicks(false);
                }
                foreach (PlotArea area2 in _view.PlotAreas)
                {
                    if (area2.Row == num27)
                    {
                        area2.SetPlotY(y, num28);
                    }
                }
            }
            using (IEnumerator <PlotArea> enumerator = _view.PlotAreas.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    UIElement uIElement = enumerator.Current.UIElement;
                    if ((uIElement != null) && !InternalChildren.Contains(uIElement))
                    {
                        InternalChildren.Insert(num22++, uIElement);
                    }
                }
            }
        }
        private void DrawAxis()
        {
            //Clear all existing elements in axis canvas
            AxisCanvas.Children.Clear();
            //number of days in the range. Includes partial days.
            double numDays    = (_endDate.Value - _startDate.Value).TotalDays;
            double totalWidth = PlotCanvas.ActualWidth;

            //Set the axis to span the whole plot canvas
            AxisLine.X2 = totalWidth;
            AxisCanvas.Children.Add(AxisLine);
            //Get the Width of a day as represented in the axis. This value wil be used to compute
            //the date/time info represented by a point on the plot canvas until the next time axis changes
            _widthOfADay           = totalWidth / numDays;
            _mouseHighlight.Width  = _widthOfADay;
            _mouseHighlight.Height = PlotCanvas.Height;
            Canvas.SetLeft(_mouseHighlight, 0 - _widthOfADay);
            PlotCanvas.Children.Add(_mouseHighlight);
            //The first day may be a partial day. If it is, account for this on the axis.
            //axisOffset represents the part of the day before the axis starts
            _axisOffset = (_startDate.Value.TimeOfDay - _startDate.Value.Date.TimeOfDay).TotalDays * _widthOfADay;
            for (double i = 0; i <= numDays; i++)
            {
                //day we are dealing with
                DateTime currentDate = _startDate.Value.AddDays(i);

                //'left' is the point on the axis that represents the start of the day
                double left = _widthOfADay * i - _axisOffset;

                //draw the vertical hash on axis
                var l = new Line {
                    Y2     = 10, StrokeThickness = 0.1,
                    Stroke = new SolidColorBrush {
                        Color = Colors.Black
                    }
                };
                Canvas.SetLeft(l, left);
                Canvas.SetTop(l, 40);
                AxisCanvas.Children.Add(l);

                //Date and DayOfWeek are written on the axis if the width of a day is more than 20
                if (_widthOfADay > 20)
                {
                    //Write date on the axis, starting 3 units from center of the day width
                    var t = new TextBlock {
                        Text = currentDate.Day.ToString(), FontSize = 9, FontWeight = FontWeights.Thin, Foreground = new SolidColorBrush {
                            Color = Colors.Gray
                        }
                    };
                    Canvas.SetLeft(t, left + _widthOfADay / 2 - 3);
                    Canvas.SetTop(t, 30);
                    AxisCanvas.Children.Add(t);

                    //Write dayOfWeek on the axis, starting 3 units from center of the day width
                    var d = new TextBlock {
                        Text = currentDate.DayOfWeek.ToString().Substring(0, 3), FontSize = 9, FontWeight = FontWeights.Medium, Foreground = new SolidColorBrush {
                            Color = Colors.LightGray
                        }
                    };
                    Canvas.SetLeft(d, left + _widthOfADay / 2 - 8);
                    Canvas.SetTop(d, 15);
                    AxisCanvas.Children.Add(d);
                }

                //if it is the first day of the month or the second day on the axis (because the first day may be
                //a partial and hence we won't see the value), write the month on the axis
                if (i == 1 || currentDate.Day == 1)
                {
                    var tmonth = new TextBlock {
                        Text = Enum.GetName(typeof(Months), currentDate.Month - 1), FontSize = 10, FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush {
                            Color = Colors.Gray
                        }
                    };
                    if (currentDate.Month == 1)
                    {
                        tmonth.Text += " " + currentDate.Year;
                    }
                    Canvas.SetLeft(tmonth, left);
                    Canvas.SetTop(tmonth, 2);
                    AxisCanvas.Children.Add(tmonth);
                }
                //Draw the vertical gridline on the plot canvas for the start of the day.
                DrawGridLine(left);

                //If the day is today, do some special stuff
                if (currentDate.Date == DateTime.Now.Date)
                {
                    //color the day in plot canvas
                    ColorColumn(left, _widthOfADay, (Brush)Application.Current.Resources["TimeLineTodayColumn"]);
                    //Draw a colored rectangle on the axis that spans the entire day
                    var r = new Rectangle
                    {
                        Height = AxisCanvas.ActualHeight,
                        Width  = _widthOfADay,
                        Fill   = new SolidColorBrush {
                            Color = Colors.Gray
                        },
                        Opacity = .1
                    };
                    Canvas.SetLeft(r, left);
                    ToolTipService.SetToolTip(r, "Today");
                    AxisCanvas.Children.Add(r);
                }
                //if it is weekend and not today, color it differently.
                else if (currentDate.DayOfWeek == DayOfWeek.Sunday || currentDate.DayOfWeek == DayOfWeek.Saturday)
                {
                    ColorColumn(left, _widthOfADay, (Brush)Application.Current.Resources["TimeLineWeekendColumn"]);
                }
            }
            AxisCanvas.UpdateLayout();
        }