Ejemplo n.º 1
0
        private void RotateLabelBottom(TextBlock label, AngleQuadrantInfo angleQuadrantInfo, Size labelTextSize)
        {
            if (!angleQuadrantInfo.Rotate)
            {
                return;
            }

            var transformGroup = new TransformGroup();

            var rotateTransform = new RotateTransform();

            rotateTransform.CenterX = ChartConstant.ZERO_D;
            rotateTransform.CenterY = ChartConstant.ZERO_D;
            rotateTransform.Angle   = angleQuadrantInfo.Angle;
            transformGroup.Children.Add(rotateTransform);

            var    translateTransform = new TranslateTransform();
            double x, y;

            switch (angleQuadrantInfo.Quadrant)
            {
            case Quadrant.One:    //angle:270-360°
                x = labelTextSize.Width * Math.Sin(angleQuadrantInfo.Radians);
                y = labelTextSize.Width * Math.Cos(angleQuadrantInfo.Radians);
                translateTransform.X = labelTextSize.Width / 2 - x;
                translateTransform.Y = y;
                break;

            case Quadrant.Two:     //angle:180-270°
                x = labelTextSize.Width * Math.Cos(angleQuadrantInfo.Radians) - labelTextSize.Height * Math.Sin(angleQuadrantInfo.Radians);
                y = labelTextSize.Width * Math.Sin(angleQuadrantInfo.Radians) + labelTextSize.Height * Math.Cos(angleQuadrantInfo.ModRadians);
                translateTransform.X = labelTextSize.Width / 2 + x;
                translateTransform.Y = y;
                break;

            case Quadrant.Three:    //angle:90-180°
                x = labelTextSize.Height * Math.Sin(angleQuadrantInfo.ModRadians);
                y = labelTextSize.Height * Math.Cos(angleQuadrantInfo.ModRadians);;
                translateTransform.X = labelTextSize.Width / 2 + x;
                translateTransform.Y = y;
                break;

            case Quadrant.Four:    //angle:0-90°
                translateTransform.X = labelTextSize.Width / 2;
                translateTransform.Y = ChartConstant.ZERO_D;
                break;

            default:
                throw new NotImplementedException(angleQuadrantInfo.Quadrant.ToString());
            }

            transformGroup.Children.Add(translateTransform);
            label.RenderTransform = transformGroup;
        }
Ejemplo n.º 2
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);
        }