Ejemplo n.º 1
0
        private void ArrangeChildenSize(double height, double width, FrameworkElementBase data)
        {
            List <FrameworkElementBase> listX = new List <FrameworkElementBase>();
            List <FrameworkElementBase> listY = new List <FrameworkElementBase>();

            if (LegendCanDraw)
            {
                switch (Legend.Position)
                {
                case LegendPosition.Left:
                case LegendPosition.Right:
                    listX.Add(Legend);
                    break;

                case LegendPosition.Top:
                case LegendPosition.Bottom:
                    listY.Add(Legend);
                    break;

                default:
                    break;
                }
            }

            if (AxesCanDraw)
            {
                if (Axes.AxisX.Count > 0)
                {
                    listY.AddRange(Axes.AxisX);
                }

                if (Axes.AxisY.Count > 0)
                {
                    listX.AddRange(Axes.AxisY);
                }
            }

            //if (DataCanDraw)
            //{
            //    listX.Add(Data);
            //    listY.Add(Data);
            //}
            //else
            //{
            //    listX.Add(defaultData);
            //    listY.Add(defaultData);
            //}
            listX.Add(data);
            listY.Add(data);

            double startCount = 0;

            double requiredSize = 0;

            foreach (var item in listX)
            {
                if (item.Width.IsStar)
                {
                    startCount += item.Width.Value;
                }
                else
                {
                    requiredSize     += item.Width.Value;
                    item._actualWidth = item.Width.Value;
                }
            }

            if (startCount > 0)
            {
                var totalSize = width - requiredSize;
                var starValue = totalSize > 0 ? totalSize / startCount : 0;

                foreach (var item in listX)
                {
                    if (item.Width.IsStar)
                    {
                        item._actualWidth = starValue * item.Width.Value;
                    }
                }
            }

            startCount = 0;

            requiredSize = 0;

            foreach (var item in listY)
            {
                if (item.Height.IsStar)
                {
                    startCount += item.Height.Value;
                }
                else
                {
                    requiredSize      += item.Height.Value;
                    item._actualHeight = item.Height.Value;
                }
            }

            if (startCount > 0)
            {
                var totalSize = height - requiredSize;
                var starValue = totalSize > 0 ? totalSize / startCount : 0;

                foreach (var item in listY)
                {
                    if (item.Height.IsStar)
                    {
                        item._actualHeight = starValue * item.Height.Value;
                    }
                }
            }


            if (LegendCanDraw)
            {
                switch (Legend.Position)
                {
                case LegendPosition.Left:
                case LegendPosition.Right:
                    Legend._actualHeight = data._actualHeight;
                    break;

                case LegendPosition.Top:
                case LegendPosition.Bottom:
                    Legend._actualWidth = data._actualWidth;
                    break;

                default:
                    break;
                }
            }

            if (AxesCanDraw)
            {
                if (Axes.AxisX.Count > 0)
                {
                    foreach (var item in Axes.AxisX)
                    {
                        item._actualWidth = data._actualWidth;
                    }
                }

                if (Axes.AxisY.Count > 0)
                {
                    foreach (var item in Axes.AxisY)
                    {
                        item._actualHeight = data._actualHeight;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private Rect GetCorpRect(double x, double y, FrameworkElementBase febase)
 {
     return(new Rect(x, y, febase.ActualWidth, febase.ActualHeight));
 }
Ejemplo n.º 3
0
        private void ArrangeChildenCorpRect(FrameworkElementBase data)
        {
            if (LegendCanDraw)
            {
                switch (Legend.Position)
                {
                case LegendPosition.Left:
                    Legend.CropRect = GetCorpRect(0, 0, Legend);
                    if (AxesCanDraw)
                    {
                        if (Axes.AxisY.Count > 0)
                        {
                            var py = Axes.PrimaryAxisY;
                            py.CropRect = GetCorpRect(Legend.ActualWidth, 0, py);

                            data.CropRect = GetCorpRect(py.CropRect.Right, 0, data);

                            var otherY = Axes.AxisY.Except(new List <Axis>()
                            {
                                py
                            });
                            if (otherY != null)
                            {
                                var offset = data.CropRect.Right;
                                foreach (var item in otherY)
                                {
                                    item.CropRect = GetCorpRect(offset, 0, item);
                                    offset        = item.CropRect.Right;
                                }
                            }
                        }
                        else
                        {
                            data.CropRect = GetCorpRect(Legend.CropRect.Right, 0, data);
                        }

                        //
                        if (Axes.AxisX.Count > 0)
                        {
                            var px = Axes.PrimaryAxisX;
                            px.CropRect = GetCorpRect(data.CropRect.Left, data.CropRect.Bottom, px);


                            var otherX = Axes.AxisX.Except(new List <Axis>()
                            {
                                px
                            });
                            if (otherX != null)
                            {
                                var offset = px.CropRect.Bottom;
                                foreach (var item in otherX)
                                {
                                    item.CropRect = GetCorpRect(px.CropRect.Left, offset, item);
                                    offset        = item.CropRect.Bottom;
                                }
                            }
                        }
                    }
                    else
                    {
                        data.CropRect = GetCorpRect(Legend.CropRect.Right, 0, data);
                    }

                    break;

                case LegendPosition.Right:
                    if (AxesCanDraw)
                    {
                        if (Axes.AxisY.Count > 0)
                        {
                            var py = Axes.PrimaryAxisY;
                            py.CropRect = GetCorpRect(0, 0, py);

                            data.CropRect = GetCorpRect(py.CropRect.Right, 0, data);

                            var otherY = Axes.AxisY.Except(new List <Axis>()
                            {
                                py
                            });
                            var offset = data.CropRect.Right;
                            if (otherY != null)
                            {
                                foreach (var item in otherY)
                                {
                                    item.CropRect = GetCorpRect(offset, 0, item);
                                    offset        = item.CropRect.Right;
                                }
                            }
                            Legend.CropRect = GetCorpRect(offset, 0, Legend);
                        }
                        else
                        {
                            data.CropRect   = GetCorpRect(0, 0, data);
                            Legend.CropRect = GetCorpRect(data.CropRect.Right, 0, Legend);
                        }

                        //
                        if (Axes.AxisX.Count > 0)
                        {
                            var px = Axes.PrimaryAxisX;
                            px.CropRect = GetCorpRect(data.CropRect.Left, data.CropRect.Bottom, px);

                            var otherX = Axes.AxisX.Except(new List <Axis>()
                            {
                                px
                            });
                            if (otherX != null)
                            {
                                var offset = px.CropRect.Bottom;
                                foreach (var item in otherX)
                                {
                                    item.CropRect = GetCorpRect(px.CropRect.Left, offset, item);
                                    offset        = item.CropRect.Bottom;
                                }
                            }
                        }
                    }
                    else
                    {
                        data.CropRect   = GetCorpRect(0, 0, data);
                        Legend.CropRect = GetCorpRect(data.CropRect.Right, 0, Legend);
                    }

                    break;

                case LegendPosition.Top:
                    if (AxesCanDraw)
                    {
                        if (Axes.AxisY.Count > 0)
                        {
                            var py = Axes.PrimaryAxisY;
                            py.CropRect = GetCorpRect(0, Legend._actualHeight, py);

                            Legend.CropRect = GetCorpRect(py.CropRect.Right, 0, Legend);

                            data.CropRect = GetCorpRect(py.CropRect.Right, Legend.CropRect.Bottom, data);

                            var otherY = Axes.AxisY.Except(new List <Axis>()
                            {
                                py
                            });

                            if (otherY != null)
                            {
                                var offset = data.CropRect.Right;
                                foreach (var item in otherY)
                                {
                                    item.CropRect = GetCorpRect(offset, py.CropRect.Top, item);
                                    offset        = item.CropRect.Right;
                                }
                            }
                        }
                        else
                        {
                            Legend.CropRect = GetCorpRect(0, 0, Legend);
                            data.CropRect   = GetCorpRect(0, Legend.CropRect.Bottom, data);
                        }

                        //
                        if (Axes.AxisX.Count > 0)
                        {
                            var px = Axes.PrimaryAxisX;
                            px.CropRect = GetCorpRect(data.CropRect.Left, data.CropRect.Bottom, px);

                            var otherX = Axes.AxisX.Except(new List <Axis>()
                            {
                                px
                            });
                            if (otherX != null)
                            {
                                var offset = px.CropRect.Bottom;
                                foreach (var item in otherX)
                                {
                                    item.CropRect = GetCorpRect(px.CropRect.Left, offset, item);
                                    offset        = item.CropRect.Bottom;
                                }
                            }
                        }
                    }
                    else
                    {
                        Legend.CropRect = GetCorpRect(0, 0, Legend);
                        data.CropRect   = GetCorpRect(0, Legend.CropRect.Bottom, data);
                    }
                    break;

                case LegendPosition.Bottom:
                    if (AxesCanDraw)
                    {
                        if (Axes.AxisY.Count > 0)
                        {
                            var py = Axes.PrimaryAxisY;
                            py.CropRect = GetCorpRect(0, 0, py);

                            data.CropRect = GetCorpRect(py.CropRect.Right, 0, data);

                            var otherY = Axes.AxisY.Except(new List <Axis>()
                            {
                                py
                            });
                            if (otherY != null)
                            {
                                var offsetY = data.CropRect.Right;
                                foreach (var item in otherY)
                                {
                                    item.CropRect = GetCorpRect(offsetY, py.CropRect.Top, item);
                                    offsetY       = item.CropRect.Right;
                                }
                            }
                        }
                        else
                        {
                            data.CropRect = GetCorpRect(0, 0, data);
                        }

                        var offset = data.CropRect.Bottom;
                        //
                        if (Axes.AxisX.Count > 0)
                        {
                            var px = Axes.PrimaryAxisX;
                            px.CropRect = GetCorpRect(data.CropRect.Left, data.CropRect.Bottom, px);
                            offset      = px.CropRect.Bottom;
                            var otherX = Axes.AxisX.Except(new List <Axis>()
                            {
                                px
                            });
                            if (otherX != null)
                            {
                                foreach (var item in otherX)
                                {
                                    item.CropRect = GetCorpRect(px.CropRect.Left, offset, item);
                                    offset        = item.CropRect.Bottom;
                                }
                            }
                        }

                        Legend.CropRect = GetCorpRect(data.CropRect.Left, offset, Legend);
                    }
                    else
                    {
                        data.CropRect   = GetCorpRect(0, 0, data);
                        Legend.CropRect = GetCorpRect(0, data.CropRect.Bottom, Legend);
                    }
                    break;

                default:
                    break;
                }
            }
            else
            {
                if (AxesCanDraw)
                {
                    if (Axes.AxisY.Count > 0)
                    {
                        var py = Axes.PrimaryAxisY;
                        py.CropRect = GetCorpRect(0, 0, py);

                        data.CropRect = GetCorpRect(py.CropRect.Right, 0, data);

                        var otherY = Axes.AxisY.Except(new List <Axis>()
                        {
                            py
                        });
                        if (otherY != null)
                        {
                            var offsetY = data.CropRect.Right;
                            foreach (var item in otherY)
                            {
                                item.CropRect = GetCorpRect(offsetY, py.CropRect.Top, item);
                                offsetY       = item.CropRect.Right;
                            }
                        }
                    }
                    else
                    {
                        data.CropRect = GetCorpRect(0, 0, data);
                    }


                    //
                    if (Axes.AxisX.Count > 0)
                    {
                        var px = Axes.PrimaryAxisX;
                        px.CropRect = GetCorpRect(data.CropRect.Left, data.CropRect.Bottom, px);
                        var offset = px.CropRect.Bottom;
                        var otherX = Axes.AxisX.Except(new List <Axis>()
                        {
                            px
                        });
                        if (otherX != null)
                        {
                            foreach (var item in otherX)
                            {
                                item.CropRect = GetCorpRect(px.CropRect.Left, offset, item);
                                offset        = item.CropRect.Bottom;
                            }
                        }
                    }
                }
            }
        }