Esempio n. 1
0
        public ChartGridRowColumnDefinition(Grid chartContentGrid, AxisXHeightInfo axisXHeightInfo)
        {
            if (axisXHeightInfo.TopAxisTotalHeight > ChartConstant.ZERO_D)
            {
                this.TopAxis = new RowColumnDefinitionItem();
            }

            if (axisXHeightInfo.BottomAxisTotalHeight > ChartConstant.ZERO_D)
            {
                this.BottomAxis = new RowColumnDefinitionItem();
            }

            this.Chart = new RowColumnDefinitionItem();


            if (axisXHeightInfo.TopAxisTotalHeight > ChartConstant.ZERO_D)
            {
                this.TopAxis.CreateRow(chartContentGrid, axisXHeightInfo.TopAxisTotalHeight, GridUnitType.Pixel);
            }
            this.Chart.CreateRow(chartContentGrid, ChartConstant.GRID_START_SIZE, GridUnitType.Star);
            if (axisXHeightInfo.BottomAxisTotalHeight > ChartConstant.ZERO_D)
            {
                this.BottomAxis.CreateRow(chartContentGrid, axisXHeightInfo.BottomAxisTotalHeight, GridUnitType.Pixel);
            }



            if (this.TopAxis != null)
            {
                this.TopAxis.MergeRowColumn(chartContentGrid, this.Chart);
            }

            if (this.BottomAxis != null)
            {
                this.BottomAxis.MergeRowColumn(chartContentGrid, this.Chart);
            }

            this.Chart.MergeRowColumn(chartContentGrid, this.Chart);
        }
Esempio n. 2
0
        private void FreezeYLayout(ChartCollection <AxisAbs> axisCollection, IChartLegend legend, Canvas chartCanvas, Grid chartGrid, ScrollViewer scrollViewer, Grid chartContentGrid, LegendAddResult legendAddResult, AxisXHeightInfo axisXHeightInfo, AxisYWidthInfo axisYWidthInfo)
        {
            //添加scrollViewer
            scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Disabled;
            scrollViewer.Content             = chartContentGrid;
            scrollViewer.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
            scrollViewer.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            chartGrid.Children.Add(scrollViewer);


            //左中右三列布局,legend另算
            var chartGridRowColumnDefinition = new ChartGridRowColumnDefinition(legendAddResult.HasLegend, legend, chartGrid, axisYWidthInfo);

            if (legendAddResult.HasLegend)
            {
                this.SetRowColumn(chartGrid, legend.LegendControl, chartGridRowColumnDefinition.Legend);
            }

            if (axisCollection != null && axisCollection.Count > ChartConstant.ZERO_I)
            {
                RowColumnDefinitionItem rowColumnDefinition;
                foreach (var axis in axisCollection)
                {
                    if (axis.AxisType != AxisType.Y)
                    {
                        continue;
                    }

                    switch (axis.DockOrientation)
                    {
                    case ChartDockOrientation.Left:
                        rowColumnDefinition = chartGridRowColumnDefinition.LeftAxis;
                        break;

                    case ChartDockOrientation.Right:
                        rowColumnDefinition = chartGridRowColumnDefinition.RightAxis;
                        break;

                    case ChartDockOrientation.Top:
                    case ChartDockOrientation.Bottom:
                    default:
                        throw new NotImplementedException(axis.DockOrientation.ToString());
                    }

                    this.SetRowColumn(chartGrid, axis.AxisControl, rowColumnDefinition);
                }
            }

            this.SetRowColumn(chartGrid, scrollViewer, chartGridRowColumnDefinition.Chart);



            //上中下三行布局
            var chartGridRowColumnDefinition2 = new ChartGridRowColumnDefinition(chartContentGrid, axisXHeightInfo);

            if (axisCollection != null && axisCollection.Count > ChartConstant.ZERO_I)
            {
                RowColumnDefinitionItem rowColumnDefinition;
                foreach (var axis in axisCollection)
                {
                    if (axis.AxisType != AxisType.X)
                    {
                        continue;
                    }

                    switch (axis.DockOrientation)
                    {
                    case ChartDockOrientation.Top:
                        rowColumnDefinition = chartGridRowColumnDefinition2.TopAxis;
                        break;

                    case ChartDockOrientation.Bottom:
                        rowColumnDefinition = chartGridRowColumnDefinition2.BottomAxis;
                        break;

                    case ChartDockOrientation.Left:
                    case ChartDockOrientation.Right:
                    default:
                        throw new NotImplementedException(axis.DockOrientation.ToString());
                    }

                    this.SetRowColumn(chartContentGrid, axis.AxisControl, rowColumnDefinition);
                }
            }
            this.SetRowColumn(chartContentGrid, chartCanvas, chartGridRowColumnDefinition2.Chart);
        }
Esempio n. 3
0
        private void UpdateFreezeY(AxisFreezeInfo axisFreezeInfo, ChartCollection <AxisAbs> axisCollection, ChartCollection <ISeries> seriesCollection,
                                   IChartLegend legend, Canvas chartCanvas, Grid chartGrid, ScrollViewer scrollViewer, Grid chartContentGrid)
        {
            /************************************************************************************************************
            * 步骤:
            * 1.添加legend,并计算出发四周所占高度或宽度
            * 2.计算X轴总高度
            * 3.根据X轴总高度计算图表区域高度高度(等于Y轴高度)
            * 4.根据Y轴高度绘制Y轴,并计算Y轴宽度
            * 5.根据宽度绘制X轴
            * 6.绘制坐标背景标记线
            * 7.布局UI
            * 8.绘各Series和填充legend
            ************************************************************************************************************/

            //chartGrid.ShowGridLines = true;
            //chartCanvas.Background = ColorBrushHelper.GetNextColor();
            this.Content = chartGrid;


            //第一步 添加legend,并计算出发四周所占高度或宽度
            LegendAddResult legendAddResult = this.AddLegend(legend, chartGrid);

            //第二步 计算X轴总高度
            AxisXHeightInfo axisXHeightInfo = this.CalculateAxisXHeight(axisCollection);

            //第三步 根据X轴总高度计算图表区域高度高度(等于Y轴高度)
            double yAxisHeight = axisFreezeInfo.Height - axisXHeightInfo.TopAxisTotalHeight - axisXHeightInfo.BottomAxisTotalHeight - legendAddResult.Top - legendAddResult.Bottom - this._scrollBarWidth;

            if (yAxisHeight < ChartConstant.ZERO_D)
            {
                yAxisHeight = ChartConstant.ZERO_D;
            }

            //第四步 根据Y轴高度绘制Y轴,并计算Y轴宽度
            AxisYWidthInfo axisYWidthInfo = this.DrawAxisYByAxisXHeightInfo(axisCollection, chartGrid.Children, seriesCollection, yAxisHeight, axisXHeightInfo.TopAxisTotalHeight);


            //第五步 根据宽度绘制X轴
            double width      = this.ActualWidth - axisYWidthInfo.LeftAxisTotalWidth - axisYWidthInfo.RightAxisTotalWidth - legendAddResult.Left - legendAddResult.Right;
            double xAxisWidth = axisFreezeInfo.Width;

            if (xAxisWidth < ChartConstant.ZERO_D)
            {
                xAxisWidth = ChartConstant.ZERO_D;
            }
            else if (xAxisWidth - width < ChartConstant.ZERO_D)
            {
                //真实宽度大于最小值,取更大值
                xAxisWidth = width;
            }
            Dictionary <AxisAbs, List <double> > axisXLabelDic = this.DrawAxisX(axisCollection, seriesCollection, chartContentGrid, xAxisWidth, ChartConstant.ZERO_D);

            chartCanvas.Width  = xAxisWidth;
            chartCanvas.Height = yAxisHeight;
            chartContentGrid.Children.Add(chartCanvas);

            //第六步 绘制坐标背景标记线
            this.DrawAxisBackgroundLabelLine(chartCanvas, axisYWidthInfo.AxisYLabelDic, axisXLabelDic);

            //第七步 布局UI
            this.FreezeYLayout(axisCollection, legend, chartCanvas, chartGrid, scrollViewer, chartContentGrid, legendAddResult, axisXHeightInfo, axisYWidthInfo);

            //第八步 绘各Series和填充legend
            this.DrawSeries(chartGrid, chartCanvas, seriesCollection, legendAddResult, legend);
        }
Esempio n. 4
0
        private void UpdateFreezeX(AxisFreezeInfo axisFreezeInfo, ChartCollection <AxisAbs> axisCollection, ChartCollection <ISeries> seriesCollection,
                                   IChartLegend legend, Canvas chartCanvas, Grid chartGrid, ScrollViewer scrollViewer, Grid chartContentGrid)
        {
            /************************************************************************************************************
            * 步骤:
            * 1.添加legend,并计算出发四周所占高度或宽度
            * 2.计算X轴总高度
            * 3.根据Y轴高度绘制Y轴,并计算Y轴宽度
            * 4.根据Y轴宽度计算X轴宽度并绘制X轴
            * 5.绘制坐标背景标记线
            * 6.绘各Series
            * 7.绘各Series和填充legend
            ************************************************************************************************************/

            this.Content = chartGrid;

            //第一步 添加legend,并计算出发四周所占高度或宽度
            LegendAddResult legendAddResult = this.AddLegend(legend, chartGrid);

            //第二步 计算X轴总高度
            AxisXHeightInfo axisXHeightInfo = this.CalculateAxisXHeight(axisCollection);


            double height = this.ActualHeight - axisXHeightInfo.TopAxisTotalHeight - axisXHeightInfo.BottomAxisTotalHeight - legendAddResult.Top - legendAddResult.Bottom;

            //第三步 根据Y轴高度绘制Y轴,并计算Y轴宽度
            double yAxisHeight = axisFreezeInfo.Height;

            if (yAxisHeight < ChartConstant.ZERO_D)
            {
                yAxisHeight = ChartConstant.ZERO_D;
            }
            else if (yAxisHeight - height < ChartConstant.ZERO_D)
            {
                //真实高度大于最小值,取更大值
                yAxisHeight = height;
            }
            AxisYWidthInfo axisYWidthInfo = this.DrawAxisYByAxisXHeightInfo(axisCollection, chartContentGrid.Children, seriesCollection, yAxisHeight, ChartConstant.ZERO_D);


            //第四步 根据Y轴宽度计算X轴宽度并绘制X轴
            double xAxisWidth = axisFreezeInfo.Width - axisYWidthInfo.LeftAxisTotalWidth - axisYWidthInfo.RightAxisTotalWidth - legendAddResult.Left - legendAddResult.Right - this._scrollBarWidth;

            if (xAxisWidth < ChartConstant.ZERO_D)
            {
                xAxisWidth = ChartConstant.ZERO_D;
            }
            Dictionary <AxisAbs, List <double> > axisXLabelDic = this.DrawAxisX(axisCollection, seriesCollection, chartGrid, xAxisWidth, axisYWidthInfo.LeftAxisTotalWidth);


            chartCanvas.Width  = xAxisWidth;
            chartCanvas.Height = yAxisHeight;
            chartContentGrid.Children.Add(chartCanvas);

            //第五步 绘制坐标背景标记线
            this.DrawAxisBackgroundLabelLine(chartCanvas, axisYWidthInfo.AxisYLabelDic, axisXLabelDic);

            //第六步 布局UI
            this.FreezeXLayout(axisCollection, legend, chartCanvas, chartGrid, scrollViewer, chartContentGrid, legendAddResult, axisXHeightInfo, axisYWidthInfo);

            //第七步 绘各Series和填充legend
            this.DrawSeries(chartGrid, chartCanvas, seriesCollection, legendAddResult, legend);
        }
Esempio n. 5
0
        private void NoneFreezeLayout(ChartCollection <AxisAbs> axisCollection, IChartLegend legend, Canvas chartCanvas, Grid chartGrid, ScrollViewer scrollViewer, LegendAddResult legendAddResult, AxisXHeightInfo axisXHeightInfo, AxisYWidthInfo axisYWidthInfo)
        {
            var chartGridRowColumnDefinition = new ChartGridRowColumnDefinition(legendAddResult.HasLegend, legend, chartGrid, axisYWidthInfo, axisXHeightInfo);

            if (legendAddResult.HasLegend)
            {
                this.SetRowColumn(chartGrid, legend.LegendControl, chartGridRowColumnDefinition.Legend);
            }

            if (axisCollection != null && axisCollection.Count > ChartConstant.ZERO_I)
            {
                RowColumnDefinitionItem rowColumnDefinition;
                foreach (var axis in axisCollection)
                {
                    switch (axis.DockOrientation)
                    {
                    case ChartDockOrientation.Left:
                        rowColumnDefinition = chartGridRowColumnDefinition.LeftAxis;
                        break;

                    case ChartDockOrientation.Top:
                        rowColumnDefinition = chartGridRowColumnDefinition.TopAxis;
                        break;

                    case ChartDockOrientation.Right:
                        rowColumnDefinition = chartGridRowColumnDefinition.RightAxis;
                        break;

                    case ChartDockOrientation.Bottom:
                        rowColumnDefinition = chartGridRowColumnDefinition.BottomAxis;
                        break;

                    default:
                        throw new NotImplementedException(axis.DockOrientation.ToString());
                    }

                    this.SetRowColumn(chartGrid, axis.AxisControl, rowColumnDefinition);
                }
            }

            this.SetRowColumn(chartGrid, scrollViewer, chartGridRowColumnDefinition.Chart);


            chartCanvas.MouseWheel          += ChartCanvas_MouseWheel;
            chartCanvas.MouseLeftButtonDown += ChartCanvas_MouseLeftButtonDown;
            chartCanvas.MouseMove           += ChartCanvas_MouseMove;
        }
Esempio n. 6
0
        private void UpdateNoneFreeze(AxisFreezeInfo axisFreezeInfo, ChartCollection <AxisAbs> axisCollection, ChartCollection <ISeries> seriesCollection,
                                      IChartLegend legend, Canvas chartCanvas, Grid chartGrid, ScrollViewer scrollViewer)
        {
            /************************************************************************************************************
            * 步骤:
            * 1.添加legend,并计算出发四周所占高度或宽度
            * 2.计算X轴总高度
            * 3.根据X轴总高度计算图表区域高度高度(等于Y轴高度)
            * 4.根据Y轴高度绘制Y轴,并计算Y轴宽度
            * 5.根据Y轴宽度计算X轴宽度并绘制X轴
            * 6.绘制坐标背景标记线
            * 7.布局UI
            * 8.绘各Series和填充legend
            ************************************************************************************************************/

            //chartGrid.ShowGridLines = true;
            //chartCanvas.Background = ColorBrushHelper.GetNextColor();
            this.Content = chartGrid;



            //第一步 添加legend,并计算出发四周所占高度或宽度
            LegendAddResult legendAddResult = this.AddLegend(legend, chartGrid);


            //第二步 计算X轴总高度
            AxisXHeightInfo axisXHeightInfo = this.CalculateAxisXHeight(axisCollection);


            //第三步 根据X轴总高度计算图表区域高度高度(等于Y轴高度)
            double yAxisHeight = axisFreezeInfo.Height - axisXHeightInfo.TopAxisTotalHeight - axisXHeightInfo.BottomAxisTotalHeight - legendAddResult.Top - legendAddResult.Bottom;

            if (yAxisHeight < ChartConstant.ZERO_D)
            {
                yAxisHeight = ChartConstant.ZERO_D;
            }

            //第四步 根据Y轴高度绘制Y轴,并计算Y轴宽度
            AxisYWidthInfo axisYWidthInfo = this.DrawAxisYByAxisXHeightInfo(axisCollection, chartGrid.Children, seriesCollection, yAxisHeight, ChartConstant.ZERO_D);


            //第五步 根据Y轴宽度计算X轴宽度并绘制X轴
            double xAxisWidth = axisFreezeInfo.Width - axisYWidthInfo.LeftAxisTotalWidth - axisYWidthInfo.RightAxisTotalWidth - legendAddResult.Left - legendAddResult.Right;

            if (xAxisWidth < ChartConstant.ZERO_D)
            {
                xAxisWidth = ChartConstant.ZERO_D;
            }
            Dictionary <AxisAbs, List <double> > axisXLabelDic = this.DrawAxisX(axisCollection, seriesCollection, chartGrid, xAxisWidth, ChartConstant.ZERO_D);

            chartCanvas.Width            = xAxisWidth;
            chartCanvas.Height           = yAxisHeight;
            scrollViewer.BorderThickness = new Thickness(ChartConstant.ZERO_D);
            scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
            scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden;
            scrollViewer.Background = Brushes.Transparent;
            scrollViewer.Content    = chartCanvas;
            chartGrid.Children.Add(scrollViewer);

            //第六步 绘制坐标背景标记线
            this.DrawAxisBackgroundLabelLine(chartCanvas, axisYWidthInfo.AxisYLabelDic, axisXLabelDic);

            //第七步 布局UI
            this.NoneFreezeLayout(axisCollection, legend, chartCanvas, chartGrid, scrollViewer, legendAddResult, axisXHeightInfo, axisYWidthInfo);

            //第八步 绘各Series和填充legend
            this.DrawSeries(chartGrid, chartCanvas, seriesCollection, legendAddResult, legend);
        }
Esempio n. 7
0
        /// <summary>
        /// NoFreeze
        /// </summary>
        /// <param name="hasLegend"></param>
        /// <param name="legend"></param>
        /// <param name="chartGrid"></param>
        /// <param name="axisYWidthInfo"></param>
        /// <param name="axisXHeightInfo"></param>
        public ChartGridRowColumnDefinition(bool hasLegend, IChartLegend legend, Grid chartGrid,
                                            AxisYWidthInfo axisYWidthInfo, AxisXHeightInfo axisXHeightInfo)
        {
            if (hasLegend)
            {
                this.Legend = new RowColumnDefinitionItem();
            }

            if (axisYWidthInfo.LeftAxisTotalWidth > ChartConstant.ZERO_D)
            {
                this.LeftAxis = new RowColumnDefinitionItem();
            }

            if (axisYWidthInfo.RightAxisTotalWidth > ChartConstant.ZERO_D)
            {
                this.RightAxis = new RowColumnDefinitionItem();
            }

            if (axisXHeightInfo.TopAxisTotalHeight > ChartConstant.ZERO_D)
            {
                this.TopAxis = new RowColumnDefinitionItem();
            }

            if (axisXHeightInfo.BottomAxisTotalHeight > ChartConstant.ZERO_D)
            {
                this.BottomAxis = new RowColumnDefinitionItem();
            }

            this.Chart = new RowColumnDefinitionItem();



            if (axisYWidthInfo.LeftAxisTotalWidth > ChartConstant.ZERO_D)
            {
                this.LeftAxis.CreateColumn(chartGrid, axisYWidthInfo.LeftAxisTotalWidth, GridUnitType.Pixel);
            }
            this.Chart.CreateColumn(chartGrid, ChartConstant.GRID_START_SIZE, GridUnitType.Star);
            if (axisYWidthInfo.RightAxisTotalWidth > ChartConstant.ZERO_D)
            {
                this.RightAxis.CreateColumn(chartGrid, axisYWidthInfo.RightAxisTotalWidth, GridUnitType.Pixel);
            }


            if (axisXHeightInfo.TopAxisTotalHeight > ChartConstant.ZERO_D)
            {
                this.TopAxis.CreateRow(chartGrid, axisXHeightInfo.TopAxisTotalHeight, GridUnitType.Pixel);
            }
            this.Chart.CreateRow(chartGrid, ChartConstant.GRID_START_SIZE, GridUnitType.Star);
            if (axisXHeightInfo.BottomAxisTotalHeight > ChartConstant.ZERO_D)
            {
                this.BottomAxis.CreateRow(chartGrid, axisXHeightInfo.BottomAxisTotalHeight, GridUnitType.Pixel);
            }

            if (hasLegend)
            {
                this.Legend.CreateLegendRowColumn(chartGrid, legend);
            }


            if (this.LeftAxis != null)
            {
                this.LeftAxis.MergeRowColumn(chartGrid, this.Chart);
            }

            if (this.RightAxis != null)
            {
                this.RightAxis.MergeRowColumn(chartGrid, this.Chart);
            }

            if (this.TopAxis != null)
            {
                this.TopAxis.MergeRowColumn(chartGrid, this.Chart);
            }

            if (this.BottomAxis != null)
            {
                this.BottomAxis.MergeRowColumn(chartGrid, this.Chart);
            }

            this.Chart.MergeRowColumn(chartGrid, this.Chart);
        }