protected override void DrawInitialActualSpaceOverlays(GraphicsWrapper g, ChartSeries dateAssignedSeries) { base.DrawInitialActualSpaceOverlays(g, dateAssignedSeries); if (_showMainChartSynchronizationImage && _masterSynchronizationImage != null) { g.DrawImageUnscaledAndClipped(_masterSynchronizationImage, new Rectangle(4, (int)LabelsTopMargin, _masterSynchronizationImage.Width, _masterSynchronizationImage.Height)); } }
protected virtual void DrawInitialActualSpaceOverlays(GraphicsWrapper g, ChartSeries timeBasedSeries) { {// X Axis labels. float totalItemWidth = _seriesItemWidth + _seriesItemMargin; float actualXSpacing = _xAxisLabelSpacing * totalItemWidth; if (_considerAxisLabelsSpacingScale) { int xScaling = Math.Abs((int)(1 / _graphicsWrapper.DrawingSpaceTransform.Elements[0])); if (xScaling > 1) { actualXSpacing = actualXSpacing * xScaling; } } // Set starting to the closes compatible positionactualXSpacing // TODO : this can be optimized further by narrowing the range of xStart to end float xStart = (int)(_drawingSpaceDisplayLimit.X / actualXSpacing); xStart = xStart * actualXSpacing; for (float i = xStart; i < _drawingSpaceDisplayLimit.X + _drawingSpaceDisplayLimit.Width; i += actualXSpacing) { PointF point = GraphicsWrapper.DrawingSpaceToActualSpace(new PointF(i, 0), true); if (point.X > _actualDrawingSpaceArea.X - 10 && point.X < _actualDrawingSpaceArea.X + _actualDrawingSpaceArea.Width) { int index = (int)(i / totalItemWidth); string message = string.Empty; if (timeBasedSeries != null) {// If there is a leading dateAssignedSeries show labels based on its timing. if (timeBasedSeries.MaximumIndex > index) { message = GeneralHelper.GetShortDateTime(timeBasedSeries.GetTimeAtIndex(index)); } } else { message = index.ToString(_xAxisLabelsFormat); } if (_axisLabelsFont != null && _xAxisLabelsFontBrush != null) { g.DrawString(message, _axisLabelsFont, _xAxisLabelsFontBrush, point.X, _actualDrawingSpaceArea.Y + _actualDrawingSpaceArea.Height); } // Draw the small line indicating where the string applies for. g.DrawLine(_actualDrawingSpaceAreaBorderPen, point.X, _actualDrawingSpaceArea.Y + _actualDrawingSpaceArea.Height, point.X, _actualDrawingSpaceArea.Y + _actualDrawingSpaceArea.Height + 5); } } } if (_axisLabelsFont != null && _xAxisLabelsFontBrush != null) { _actualDrawingSpaceAreaMarginBottom = 20; } else { _actualDrawingSpaceAreaMarginBottom = 8; } {// Y Axis labels. int? yAxisLabelsWidth = null; float actualYSpacing = _yAxisLabelSpacing; if (_considerAxisLabelsSpacingScale) { int yScaling = Math.Abs((int)(1 / _graphicsWrapper.DrawingSpaceTransform.Elements[3])); if (yScaling > 1) { actualYSpacing = actualYSpacing * yScaling; } } // Set starting to the closes compatible positionactualXSpacing int maxDecimalPlaces = actualYSpacing.ToString().Length - 1; float yStart = (int)(_drawingSpaceDisplayLimit.Y / actualYSpacing); yStart = yStart * actualYSpacing; // Round off to a fixed number of post decimal point digits, will only work for values under 1 yStart = (float)Math.Round(yStart, maxDecimalPlaces); { //float minLabelValue = yStart; //float maxLabelValue = _drawingSpaceDisplayLimit.Y + _drawingSpaceDisplayLimit.Height; // Harry--Modified // This must auto adjust to format the number properly and always fit in 6 spaces. // Specify positive, negative and zero formats. _yAxisLabelsFormat = " #0.#####;-#0.#####; Zero"; //_yAxisLabelsFormat = " #0.##;-#0.##; Zero"; // original //_yAxisLabelsFormat = " #0.#####;-#0.#####; Zero"; //_yAxisLabelsFormat = " 0.000;-0.000;Zero"; // The default is 6 positions total for the y axis labels. yAxisLabelsWidth = ((int)g.MeasureString("00.00000", _axisLabelsFont).Width); //yAxisLabelsWidth = ((int)g.MeasureString("00.00", _axisLabelsFont).Width); } if (yAxisLabelsWidth.HasValue) {// Calculate the current margin and confirm with any controling subscriber. _actualDrawingSpaceAreaMarginLeft = yAxisLabelsWidth.Value + 5; if (ActualDrawingSpaceMarginLeftUpdateEvent != null) { _actualDrawingSpaceAreaMarginLeft = ActualDrawingSpaceMarginLeftUpdateEvent(this, _actualDrawingSpaceAreaMarginLeft); } } // Pass 2 - actually draw the labels and label lines at the established and confirmed location. for (float i = yStart; i < _drawingSpaceDisplayLimit.Y + _drawingSpaceDisplayLimit.Height; i += actualYSpacing) { i = (float)Math.Round(i, maxDecimalPlaces); PointF point = GraphicsWrapper.DrawingSpaceToActualSpace(new PointF(0, i), true); if (point.Y > _actualDrawingSpaceArea.Y && point.Y < _actualDrawingSpaceArea.Y + _actualDrawingSpaceArea.Height) { if (_axisLabelsFont != null && _yAxisLabelsFontBrush != null) { g.DrawString((i).ToString(_yAxisLabelsFormat), _axisLabelsFont, _yAxisLabelsFontBrush, _actualDrawingSpaceAreaMarginLeft - yAxisLabelsWidth.Value - 3, point.Y); } // Draw the small line indicating where the string applies for. g.DrawLine(_actualDrawingSpaceAreaBorderPen, _actualDrawingSpaceAreaMarginLeft - 5, point.Y, _actualDrawingSpaceAreaMarginLeft, point.Y); } } } if (ShowSeriesLabels) { _actualDrawingSpaceAreaMarginTop = 30; } else { _actualDrawingSpaceAreaMarginTop = 5; } UpdateActualDrawingSpaceArea(); // Actual space, drawing area, grid. _actualSpaceGrid.Draw(g, _actualDrawingSpaceArea, _actualDrawingSpaceArea, 1); if (ShowSeriesLabels) { DrawGraphicSeriesLabels(g, _actualDrawingSpaceArea.Left); } // Show if (_customObjectsManager.IsBuildingObject) { g.DrawImageUnscaledAndClipped(_customObjectDrawingImage, new Rectangle(4, (int)LabelsTopMargin, _customObjectDrawingImage.Width, _customObjectDrawingImage.Height)); } }