/// <summary> /// 获取X坐标轴高度 /// </summary> /// <returns>X坐标轴高度</returns> protected override double PrimitiveGetXAxisHeight() { string labelText = this.CreateAxisText(123d); double axisHeight = ChartHelper.MeasureLabelTextSize(this, labelText).Height; return(base.CalculateAxisSize(axisHeight)); }
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); }
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 Size MeasureLabelTextSize() { string labelText = this.CreateAxisText(DateTime.Parse("2020-12-12 22:22:22")); return(ChartHelper.MeasureLabelTextSize(this, labelText)); }