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); }
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); }
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); }
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); }
private List <double> DrawXAxisLeftToRight(Canvas axisCanvas, DateTimeAxisData axisData, double labelStepMilliseconds, double labelStepSize) { List <double> xList = new List <double>(); double axisWidth = axisCanvas.Width; double left = ChartConstant.ZERO_D; double lastLabelX = ChartConstant.ZERO_D; DateTime time = axisData.MinValue; AxisLabelLocation labelTextLocation = AxisLabelLocation.First; double labelTextWidth = this._labelTextSize.Width; double labelTextWidthHalf = labelTextWidth / 2; double offset = labelTextWidth / 2; TextBlock label; bool addLabelControl; double x = left; while (true) { label = ChartHelper.CreateLabelControl(this, this.CreateAxisText(time)); if (axisWidth - labelTextWidth > ChartConstant.LABEL_TEXT_INTERVAL) { addLabelControl = false; switch (labelTextLocation) { case AxisLabelLocation.First: this._axisCanvas.Children.Add(label); addLabelControl = true; Canvas.SetLeft(label, left); lastLabelX = left + labelTextWidth; labelTextLocation = AxisLabelLocation.Middle; break; case AxisLabelLocation.Middle: left += labelStepSize; offset = left - labelTextWidthHalf - lastLabelX; if (offset >= ChartConstant.LABEL_TEXT_INTERVAL) { axisCanvas.Children.Add(label); addLabelControl = true; Canvas.SetLeft(label, left - labelTextWidthHalf); lastLabelX = left + labelTextWidth; } else if (offset > 0) { axisCanvas.Children.Add(label); addLabelControl = true; Canvas.SetLeft(label, left - labelTextWidthHalf + offset); lastLabelX = left + labelTextWidth + offset; } break; case AxisLabelLocation.Last: if (lastLabelX + labelTextWidth + 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); time = time.AddMilliseconds(labelStepMilliseconds); if (time >= axisData.MaxValue) { x = this._axisCanvas.Width; time = axisData.MaxValue; labelTextLocation = AxisLabelLocation.Last; } else { x += labelStepSize; } } return(xList); }
private List <double> DrawYAxisBottomToTop(Canvas axisCanvas, DateTimeAxisData axisData, double labelStepMilliseconds, double labelStepSize) { List <double> yList = new List <double>(); double axisHeight = axisCanvas.Height; double bottom = ChartConstant.ZERO_D, bottom2; DateTime time = axisData.MinValue; double y = axisHeight; TextBlock label; Size labelSize = this._labelTextSize; double heightHalf = labelSize.Height / 2; AxisLabelLocation labelLocation = AxisLabelLocation.First; bool addLabelControl; double lastLabelY = axisHeight; while (true) { label = ChartHelper.CreateLabelControl(this, this.CreateAxisText(time)); if (axisHeight > labelSize.Height) { addLabelControl = false; switch (labelLocation) { case AxisLabelLocation.First: axisCanvas.Children.Add(label); addLabelControl = true; Canvas.SetBottom(label, bottom); lastLabelY = axisHeight - labelSize.Height; labelLocation = AxisLabelLocation.Middle; break; case AxisLabelLocation.Middle: bottom2 = bottom - heightHalf; 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(labelLocation.ToString()); } if (addLabelControl) { if (base.IsAxisYLeft()) { Canvas.SetLeft(label, ChartConstant.LABEL_TEXT_INTERVAL); } else { Canvas.SetRight(label, ChartConstant.LABEL_TEXT_INTERVAL); } } } if (labelLocation == AxisLabelLocation.Last) { if (this._showLastLabel) { yList.Add(y); } break; } yList.Add(y); time = time.AddMilliseconds(labelStepMilliseconds); if (time >= axisData.MaxValue) { labelStepSize = (labelStepMilliseconds - (time - axisData.MaxValue).TotalMilliseconds) * labelStepSize / labelStepMilliseconds; double labelHeight = ChartHelper.MeasureLabelTextSize(this, axisData.MaxValue.ToString()).Height + 10d; if (labelStepSize < labelHeight) { break; } time = axisData.MaxValue; y = ChartConstant.ZERO_D; labelLocation = AxisLabelLocation.Last; } else { y -= labelStepSize; } bottom += labelStepSize; } return(yList); }