private List <double> DrawX(Canvas axisCanvas) { if (this._axisData == null) { return(null); } List <double> xList; double labelStepMilliseconds = this.CalculateXLabelStep(this._axisData); double labelStepSize = ChartHelper.CalculateLabelStepSize(this._axisData.Area.TotalMilliseconds, axisCanvas.Width, labelStepMilliseconds); switch (base.Orientation) { case AxisLabelOrientation.LeftToRight: xList = this.DrawXAxisLeftToRight(axisCanvas, this._axisData, labelStepMilliseconds, labelStepSize); break; case AxisLabelOrientation.RightToLeft: xList = this.DrawXAxisRightToLeft(axisCanvas, this._axisData, labelStepMilliseconds, labelStepSize); break; default: throw new ArgumentException($"未知的{base.Orientation.ToString()}"); } ChartHelper.DrawXAxisLabelLine(this, axisCanvas, xList); return(xList); }
private List <double> DrawY(Canvas axisCanvas) { if (this._axisData == null) { return(null); } double labelStepMilliseconds = this.CalculateYLabelStep(this._axisData); double labelStepSize = ChartHelper.CalculateLabelStepSize(this._axisData.Area.TotalMilliseconds, axisCanvas.Height, labelStepMilliseconds); List <double> yList; switch (base.Orientation) { case AxisLabelOrientation.BottomToTop: yList = this.DrawYAxisBottomToTop(axisCanvas, this._axisData, labelStepMilliseconds, labelStepSize); break; case AxisLabelOrientation.TopToBottom: yList = this.DrawXAxisTopToBottom(axisCanvas, this._axisData, labelStepMilliseconds, labelStepSize); break; default: throw new ArgumentException($"未知的{base.Orientation.ToString()}"); } ChartHelper.DrawYAxisLabelLine(this, axisCanvas, yList); return(yList); }
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); }