Ejemplo n.º 1
0
        private List <double> DrawXAxisLeftToRight(Canvas axisCanvas, NumberAxisData axisData)
        {
            List <double>     xList         = new List <double>();
            double            axisWidth     = axisCanvas.Width;
            double            labelStep     = this.CalculateLabelStep(axisData.Area, axisWidth);
            double            labelStepSize = ChartHelper.CalculateLabelStepSize(axisData.Area, axisWidth, labelStep);
            double            left          = ChartConstant.ZERO_D;
            double            lastLabelX    = ChartConstant.ZERO_D;
            double            x             = ChartConstant.ZERO_D;
            double            value         = axisData.MinValue;
            TextBlock         label;
            Size              labelSize;
            AxisLabelLocation labelTextLocation = AxisLabelLocation.First;
            bool              addLabelControl;
            double            offset;

            while (true)
            {
                label     = ChartHelper.CreateLabelControl(this, this.CreateAxisText(value));
                labelSize = UITextHelper.MeasureTextSize(label);
                if (axisWidth - labelSize.Width > ChartConstant.LABEL_TEXT_INTERVAL)
                {
                    addLabelControl = false;
                    switch (labelTextLocation)
                    {
                    case AxisLabelLocation.First:
                        axisCanvas.Children.Add(label);
                        addLabelControl = true;
                        Canvas.SetLeft(label, left);
                        lastLabelX        = left + labelSize.Width;
                        labelTextLocation = AxisLabelLocation.Middle;
                        break;

                    case AxisLabelLocation.Middle:
                        left  += labelStepSize;
                        offset = left - labelSize.Width / 2 - lastLabelX;
                        if (offset >= ChartConstant.LABEL_TEXT_INTERVAL)
                        {
                            axisCanvas.Children.Add(label);
                            addLabelControl = true;

                            Canvas.SetLeft(label, left - labelSize.Width / 2);
                            lastLabelX = left + labelSize.Width;
                        }
                        else if (offset > 0)
                        {
                            axisCanvas.Children.Add(label);
                            addLabelControl = true;

                            Canvas.SetLeft(label, left - labelSize.Width / 2 + offset);
                            lastLabelX = left + labelSize.Width + offset;
                        }
                        break;

                    case AxisLabelLocation.Last:
                        if (lastLabelX + labelSize.Width + ChartConstant.LABEL_TEXT_INTERVAL <= axisWidth)
                        {
                            axisCanvas.Children.Add(label);
                            addLabelControl = true;
                            Canvas.SetRight(label, ChartConstant.ZERO_D);
                            lastLabelX = axisWidth;
                        }
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    if (addLabelControl)
                    {
                        if (base.IsAxisXBottom())
                        {
                            Canvas.SetBottom(label, ChartConstant.LABEL_TEXT_INTERVAL);
                        }
                        else
                        {
                            Canvas.SetTop(label, ChartConstant.LABEL_TEXT_INTERVAL);
                        }
                    }
                }

                if (labelTextLocation == AxisLabelLocation.Last)
                {
                    if (this._showLastLabel)
                    {
                        xList.Add(x);
                    }
                    break;
                }
                xList.Add(x);

                value += labelStep;

                if (value >= axisData.MaxValue)
                //if (tmp - axisData.MaxValue > _PRE)
                {
                    value             = axisData.MaxValue;
                    x                 = axisWidth;
                    labelTextLocation = AxisLabelLocation.Last;
                }
                else
                {
                    x += labelStepSize;
                }
            }

            return(xList);
        }
Ejemplo n.º 2
0
        private List <double> DrawYAxisBottomToTop(Canvas axisCanvas, NumberAxisData axisData)
        {
            List <double>     yList = new List <double>();
            double            axisHeight = axisCanvas.Height;
            double            labelStep = this.CalculateLabelStep(axisData.Area, axisHeight);
            double            labelStepSize = ChartHelper.CalculateLabelStepSize(axisData.Area, axisHeight, labelStep);
            double            labelTextLineInterval = base.GetAxisYLabelTextLineInterval();
            double            bottom = ChartConstant.ZERO_D, bottom2;
            double            value = axisData.MinValue;
            double            y = axisHeight;
            TextBlock         label;
            Size              labelSize;
            double            labelWidth        = ChartConstant.ZERO_D;
            AxisLabelLocation labelTextLocation = AxisLabelLocation.First;
            bool              addLabelControl;
            double            lastLabelY = axisHeight;

            while (true)
            {
                label     = ChartHelper.CreateLabelControl(this, this.CreateAxisText(value));
                labelSize = UITextHelper.MeasureTextSize(label);
                if (labelSize.Width - labelWidth > base._PRE)
                {
                    labelWidth = labelSize.Width;
                }

                if (axisHeight > labelSize.Height)
                {
                    addLabelControl = false;
                    switch (labelTextLocation)
                    {
                    case AxisLabelLocation.First:
                        axisCanvas.Children.Add(label);
                        addLabelControl = true;
                        Canvas.SetBottom(label, bottom);
                        lastLabelY        = axisHeight - labelSize.Height;
                        labelTextLocation = AxisLabelLocation.Middle;
                        break;

                    case AxisLabelLocation.Middle:
                        bottom2 = bottom - labelSize.Height / 2;
                        if (bottom2 > ChartConstant.ZERO_D)
                        {
                            axisCanvas.Children.Add(label);
                            addLabelControl = true;
                            Canvas.SetBottom(label, bottom2);
                            lastLabelY = bottom2 - labelSize.Height;
                        }
                        break;

                    case AxisLabelLocation.Last:
                        if (lastLabelY - labelSize.Height > ChartConstant.ZERO_D)
                        {
                            axisCanvas.Children.Add(label);
                            addLabelControl = true;
                            Canvas.SetTop(label, ChartConstant.ZERO_D);
                        }
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    if (addLabelControl)
                    {
                        if (base.IsAxisYLeft())
                        {
                            Canvas.SetRight(label, labelTextLineInterval);
                        }
                        else
                        {
                            Canvas.SetLeft(label, labelTextLineInterval);
                        }
                    }
                }

                if (labelTextLocation == AxisLabelLocation.Last)
                {
                    if (this._showLastLabel)
                    {
                        yList.Add(y);
                    }
                    break;
                }
                yList.Add(y);

                value += labelStep;
                if (value >= axisData.MaxValue)
                {
                    labelStepSize = (labelStep - (value - axisData.MaxValue)) * labelStepSize / labelStep;
                    double labelHeight = ChartHelper.MeasureLabelTextSize(this, axisData.MaxValue.ToString()).Height + 10d;
                    if (labelStepSize < labelHeight)
                    {
                        break;
                    }

                    value             = axisData.MaxValue;
                    y                 = ChartConstant.ZERO_D;
                    labelTextLocation = AxisLabelLocation.Last;
                }
                else
                {
                    y -= labelStepSize;
                }

                bottom += labelStepSize;
            }

            axisCanvas.Width = base.CalculateAxisSize(labelWidth);
            return(yList);
        }
Ejemplo n.º 3
0
        private List <double> DrawX(Canvas axisCanvas)
        {
            double            labelStepSize      = this.CalculateLabelStepSize(this._axisData.Count, axisCanvas.Width);
            double            columnSeriesOffset = this.CalculateSeriesSize(this._seriesSizeDic, labelStepSize);
            TextBlock         label;
            var               angleQuadrantInfo = new AngleQuadrantInfo(this._angle, base._PRE);
            Size              labelTextSize;
            double            left = 0d, labelTextOffset;
            AxisLabelLocation labelLocation = AxisLabelLocation.First;
            object            labelObj;
            LabelSeriesItem   labelItem;
            List <double>     xList             = new List <double>();
            double            labelStepSizeHalf = labelStepSize / 2;
            double            x;

            for (int i = 0; i < this._axisData.Count; i++)
            {
                labelObj  = this._axisData.ElementAt(i).Key;
                labelItem = this._axisData.ElementAt(i).Value;

                label         = ChartHelper.CreateLabelControl(this, this.CreateAxisText(labelObj));
                labelTextSize = UITextHelper.MeasureTextSize(label);
                axisCanvas.Children.Add(label);
                labelTextOffset = (labelStepSize - labelTextSize.Width) / 2;
                Canvas.SetLeft(label, left + labelTextOffset);
                if (this.IsAxisXBottom())
                {
                    Canvas.SetTop(label, ChartConstant.LABEL_TEXT_INTERVAL);
                    this.RotateLabelBottom(label, angleQuadrantInfo, labelTextSize);
                }
                else
                {
                    Canvas.SetBottom(label, ChartConstant.LABEL_TEXT_INTERVAL);
                    this.RotateLabelTop(label, angleQuadrantInfo, labelTextSize);
                }

                switch (labelLocation)
                {
                case AxisLabelLocation.First:
                    x             = columnSeriesOffset;
                    labelLocation = AxisLabelLocation.Middle;
                    break;

                case AxisLabelLocation.Middle:
                case AxisLabelLocation.Last:
                    x = left + columnSeriesOffset;
                    break;

                default:
                    throw new NotImplementedException(labelLocation.ToString());
                }

                foreach (var key in labelItem.Keys.ToArray())
                {
                    labelItem[key] = x;
                    x += labelItem.Series.Size;
                }

                xList.Add(left + labelStepSizeHalf);
                left += labelStepSize;
            }

            ChartHelper.DrawXAxisLabelLine(this, axisCanvas, ChartConstant.ZERO_D, axisCanvas.Height);
            return(xList);
        }
Ejemplo n.º 4
0
        private List <double> DrawY(Canvas axisCanvas)
        {
            double            labelStepSize      = this.CalculateLabelStepSize(this._axisData.Count, axisCanvas.Height);
            double            columnSeriesOffset = this.CalculateSeriesSize(this._seriesSizeDic, labelStepSize);
            TextBlock         label;
            Size              labelTextSize;
            double            top = 0d, labelTextOffset;
            AxisLabelLocation labelLocation = AxisLabelLocation.First;
            object            labelObj;
            LabelSeriesItem   labelItem;
            double            y;
            List <double>     yList             = new List <double>();
            double            labelStepSizeHalf = labelStepSize / 2;

            for (int i = 0; i < this._axisData.Count; i++)
            {
                labelObj  = this._axisData.ElementAt(i).Key;
                labelItem = this._axisData.ElementAt(i).Value;

                label         = ChartHelper.CreateLabelControl(this, this.CreateAxisText(labelObj));
                labelTextSize = UITextHelper.MeasureTextSize(label);
                axisCanvas.Children.Add(label);
                labelTextOffset = (labelStepSize - labelTextSize.Height) / 2;
                Canvas.SetTop(label, top + labelTextOffset);
                if (this.IsAxisYLeft())
                {
                    Canvas.SetRight(label, ChartConstant.LABEL_TEXT_INTERVAL);
                }
                else
                {
                    Canvas.SetLeft(label, ChartConstant.LABEL_TEXT_INTERVAL);
                }

                switch (labelLocation)
                {
                case AxisLabelLocation.First:
                    y             = columnSeriesOffset;
                    labelLocation = AxisLabelLocation.Middle;
                    break;

                case AxisLabelLocation.Middle:
                case AxisLabelLocation.Last:
                    y = top + columnSeriesOffset;
                    break;

                default:
                    throw new NotImplementedException(labelLocation.ToString());
                }

                foreach (var key in labelItem.Keys.ToArray())
                {
                    labelItem[key] = y;
                    y += labelItem.Series.Size;
                }

                yList.Add(top + labelStepSizeHalf);
                top += labelStepSize;
            }

            ChartHelper.DrawYAxisLabelLine(this, axisCanvas, ChartConstant.ZERO_D, axisCanvas.Height);
            return(yList);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 将Series绘制到已设置设定大小的画布中
        /// </summary>
        /// <param name="canvas">目标画布</param>
        protected override void PrimitiveDraw(Canvas canvas)
        {
            this._segmentList.Clear();
            this.AddLegendItem();

            if (base._values == null || base._values.Count == 0)
            {
                return;
            }

            IChartAxisDoubleValue doubleValue;
            double x1, x2, y1, y2;

            foreach (var value in base._values)
            {
                doubleValue = value as IChartAxisDoubleValue;
                if (doubleValue == null)
                {
                    continue;
                }

                switch (this._orientation)
                {
                case SeriesOrientation.Horizontal:
                    object obj = doubleValue.GetYValue1().GetValue();
                    y1 = this.AxisY.GetY(doubleValue.GetYValue1());
                    if (ChartHelper.DoubleHasValue(y1))
                    {
                        //第一个有值
                        y2 = y1;
                    }
                    else
                    {
                        y2 = this.AxisY.GetY(doubleValue.GetYValue2());
                        if (ChartHelper.DoubleHasValue(y2))
                        {
                            //第一个没有值,第二个有值
                            y1 = y2;
                        }
                        else
                        {
                            //两个都没有值
                            continue;
                        }
                    }

                    x1 = this.AxisX.GetX(doubleValue.GetXValue1());
                    if (!ChartHelper.DoubleHasValue(x1))
                    {
                        continue;
                    }

                    x2 = this.AxisX.GetX(doubleValue.GetXValue2());
                    if (!ChartHelper.DoubleHasValue(x2))
                    {
                        continue;
                    }
                    break;

                case SeriesOrientation.Vertical:
                    x1 = this.AxisX.GetX(doubleValue.GetXValue1());
                    if (ChartHelper.DoubleHasValue(x1))
                    {
                        //第一个有值
                        x2 = x1;
                    }
                    else
                    {
                        x2 = this.AxisX.GetX(doubleValue.GetXValue2());
                        if (ChartHelper.DoubleHasValue(x2))
                        {
                            //第一个没有值,第二个有值
                            x1 = x2;
                        }
                        else
                        {
                            //两个都没有值
                            continue;
                        }
                    }

                    y1 = this.AxisY.GetY(doubleValue.GetYValue1());
                    if (!ChartHelper.DoubleHasValue(y1))
                    {
                        continue;
                    }

                    y2 = this.AxisY.GetY(doubleValue.GetYValue2());
                    if (!ChartHelper.DoubleHasValue(y2))
                    {
                        continue;
                    }
                    break;

                default:
                    throw new NotImplementedException(this._orientation.ToString());
                }

                Line line = new Line();
                line.Style      = this.GetStyle();
                line.X1         = x1;
                line.X2         = x2;
                line.Y1         = y1;
                line.Y2         = y2;
                line.Visibility = base.Visibility;
                if (this.EnableTooltip)
                {
                    line.ToolTip = doubleValue.TooltipText;
                }
                line.Tag = doubleValue;
                canvas.Children.Add(line);
                this._segmentList.Add(line);
            }
        }