private void DrawHorizontalLine(IGridState state, IDrawing drawing, Structs.Size canvasSize, IMargin margin, ref SizeF strY, double valueData, double stepData, bool calcWidth, ref double maxTextSize, StringAlignment align, ref int lastTextPos) { double y = this.scaleService.ToScreenY(valueData); if (y >= 0 && y <= canvasSize.Height - margin.Bottom - margin.Top) { if (calcWidth) { var strValue = state.ItemFormatter.ToString(Axis.Y, new DataItem(0, valueData), stepData); var strSize = drawing.MeasureText(strValue); maxTextSize = maxTextSize < strSize.Width ? strSize.Width : maxTextSize; strY.Height = strSize.Height; } else { double lineYPos = canvasSize.Height - margin.Bottom - y; // Invert graphic var color = valueData != 0 ? state.GridColor : state.AxeColor; drawing.Line(color, margin.Left, lineYPos, canvasSize.Width - margin.Right, lineYPos); if (CalcAndCheckLabelRectY(state, canvasSize, margin, ref strY, valueData, align, lineYPos, out Rectangle rect, out bool borderValue)) { var strValue = state.ItemFormatter.ToString(Axis.Y, new DataItem(0, valueData), stepData); drawing.Text(state.TextYColor, rect, strValue, StringAlignment.Far, align); lastTextPos = rect.Top; } } } }
private void MeashureLabelSizes(IDrawing drawing, IMargin margin, IGridState state, Structs.Size canvasSize, out SizeF strX, out SizeF strY, out double stepDataY) { // For bottom offset get X string height for 0 value var strValueX = state.ItemFormatter.ToString(Axis.X, new DataItem(0, 0), this.scaleService.ScaleToDataX(state.MinGridLineDistance)); strX = drawing.MeasureText(strValueX); strY = new SizeF(); // For left offset find max Y string width stepDataY = 0; if (this.scaleService.State.Y1 <= 0 && this.scaleService.State.Y2 > 0) { DrawHorizontalLines(state, drawing, canvasSize, margin, ref strY, ref stepDataY, true, false, true); DrawHorizontalLines(state, drawing, canvasSize, margin, ref strY, ref stepDataY, true, true, true); } else if (this.scaleService.State.Y1 != this.scaleService.State.Y2) { DrawHorizontalLines(state, drawing, canvasSize, margin, ref strY, ref stepDataY, false, false, true); } }