public virtual void Add(ChartSeries series, bool usePaneColorSelector, bool replaceSeriesWithSameName) { if (replaceSeriesWithSameName) { this.RemoveByName(series.Name); } if (_series.Contains(series)) {// Already present. return; } if (usePaneColorSelector) { _colorSelector.SetupSeries(series); } //if (series.ChartType == ChartSeries.ChartTypeEnum.ColoredArea) //{// Colored areas better be inserted first, in rendering they will not overlap other drawings. // _series.Insert(0, series); //} //else //{ _series.Add(series); //} series.SeriesUpdatedEvent += new ChartSeries.SeriesUpdatedDelegate(series_SeriesUpdatedEvent); series.AddedToChart(); UpdateDrawingSpace(); this.Invalidate(); }
protected override void OnMouseClick(MouseEventArgs e) { base.OnMouseClick(e); CleanTimePriceLabel(); if (ShowSeriesLabels) { for (int i = 0; i < _currentLabelsRectangles.Length; i++) {// Find if click was inside one of the labels. if (_currentLabelsRectangles[i].Contains(e.Location)) {// Label clicked. if (e.Button == MouseButtons.Left) {// Show/Hide series. _series[i].Visible = !_series[i].Visible; } else if (e.Button == MouseButtons.Right) {// Prepare context sensitive right click menu items. string[] seriesTypeNames = _series[i].ChartTypes; _seriesTypeDynamicContextMenu.Items.Clear(); for (int j = 0; j < seriesTypeNames.Length; j++) { ToolStripMenuItem item = new ToolStripMenuItem(seriesTypeNames[j]); _seriesTypeDynamicContextMenu.Items.Add(item); item.Click += new EventHandler(MenuSeriesItem_Click); item.Checked = _series[i].SelectedChartType == seriesTypeNames[j]; if (item.Checked) {// Mark the currently selected item item.Image = (Image)(_resources.GetObject("imageDot")); } item.Tag = seriesTypeNames[j]; } _seriesTypeDynamicContextMenu.Items.Add(new ToolStripSeparator()); ToolStripItem propertiesMenuItem = _seriesTypeDynamicContextMenu.Items.Add("Properties"); propertiesMenuItem.Click += new EventHandler(seriesPropertiesMenuItem_Click); propertiesMenuItem.Tag = _series[i]; _lastSeriesClicked = _series[i]; _seriesTypeDynamicContextMenu.Show(this, e.Location); } this.Invalidate(); return; } } } if (e.Button == MouseButtons.Right) { if (CurrentUserSelectedRectangle.HasValue) { PointF actualSpace = GraphicsWrapper.DrawingSpaceToActualSpace(new PointF(CurrentUserSelectedRectangle.Value.Width, CurrentUserSelectedRectangle.Value.Height), false); if (actualSpace.X < MinimumAbsoluteSelectionWidth) {// Selection applied is too small and a context menu is displayed. ShowChartContextMenu(e.Location); } } } }
public virtual void Add(ChartSeries series) { this.Add(series, false, false); }
/// <summary> /// Does NOT consider series visibility. /// </summary> protected void GetSingleSeriesMinMax(ChartSeries series, int? startIndex, int? endIndex, ref float min, ref float max) { int actualStartIndex = 0; int actualEndIndex = series.MaximumIndex; if (startIndex.HasValue) { actualStartIndex = startIndex.Value; } if (endIndex.HasValue) { actualEndIndex = endIndex.Value; } min = Math.Min(min, series.GetTotalMinimum(actualStartIndex, actualEndIndex)); max = Math.Max(max, series.GetTotalMaximum(actualStartIndex, actualEndIndex)); if (min < float.MaxValue && float.IsNaN(min) == false && max > float.MinValue && float.IsNaN(max) == false) { // Provide a 5% advance on min and max. float differencePart = Math.Abs(max - min) / 20f; // Harry -- Modified if (differencePart < 0.001) differencePart = 0.001001f; //max += diff; //min -= diff; // Harry add diff between high and low max += differencePart * 2f; min -= differencePart * 2f; //max += differencePart * 10f; //min -= differencePart * 10f; } }
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)); } }
public virtual void series_SeriesUpdatedEvent(ChartSeries series, bool updateUI) { this.BeginInvoke(new GeneralHelper.DefaultDelegate(UpdateDrawingSpace)); this.Invalidate(); }
public virtual void Remove(ChartSeries series) { if (_series.Remove(series)) { series.SeriesUpdatedEvent -= new ChartSeries.SeriesUpdatedDelegate(series_SeriesUpdatedEvent); series.RemovedFromChart(); } UpdateDrawingSpace(); this.Invalidate(); }
public void SetupSeries(ChartSeries inputSeries) { if (inputSeries is TradeChartSeries) { TradeChartSeries series = (TradeChartSeries)inputSeries; switch (_seriesIndex) { case 0: { series.DefaultPen = Pens.DarkSeaGreen; series.RisingBarPen = Pens.DarkSeaGreen; series.RisingBarFill = null; series.FallingBarPen = Pens.IndianRed; series.FallingBarFill = Brushes.IndianRed; } break; case 1: { series.DefaultPen = Pens.LightBlue; series.RisingBarPen = Pens.LightBlue; series.RisingBarFill = null; series.FallingBarPen = Pens.LightBlue; series.FallingBarFill = Brushes.LightBlue; } break; case 2: { series.DefaultPen = Pens.LightSlateGray; series.RisingBarPen = Pens.LightSlateGray; series.RisingBarFill = null; series.FallingBarPen = Pens.LightSlateGray; series.FallingBarFill = Brushes.LightSlateGray; } break; case 3: { series.DefaultPen = Pens.Lavender; series.RisingBarPen = Pens.Lavender; series.RisingBarFill = null; series.FallingBarPen = Pens.Lavender; series.FallingBarFill = Brushes.Lavender; } break; case 4: { series.DefaultPen = Pens.OrangeRed; series.RisingBarPen = Pens.OrangeRed; series.RisingBarFill = null; series.FallingBarPen = Pens.OrangeRed; series.FallingBarFill = Brushes.OrangeRed; } break; case 5: { series.DefaultPen = Pens.Gold; series.RisingBarPen = Pens.Gold; series.RisingBarFill = null; series.FallingBarPen = Pens.Gold; series.FallingBarFill = Brushes.Gold; } break; case 6: { series.DefaultPen = Pens.GreenYellow; series.RisingBarPen = Pens.GreenYellow; series.RisingBarFill = null; series.FallingBarPen = Pens.GreenYellow; series.FallingBarFill = Brushes.GreenYellow; } break; case 7: { series.DefaultPen = Pens.BlueViolet; series.RisingBarPen = Pens.BlueViolet; series.RisingBarFill = null; series.FallingBarPen = Pens.BlueViolet; series.FallingBarFill = Brushes.BlueViolet; } break; } } _seriesIndex++; }