public override void OnMouseMove(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint) { if (IsLocked && DrawingState != DrawingState.Building) { return; } if (DrawingState == DrawingState.Building) { // Start anchor will not be editing here because we start building as soon as user clicks, which // plops down a start anchor right away if (EndAnchor.IsEditing) { dataPoint.CopyDataValues(EndAnchor); } else if (ExtensionAnchor.IsEditing) { dataPoint.CopyDataValues(ExtensionAnchor); } } else if (DrawingState == DrawingState.Editing && editingAnchor != null) { dataPoint.CopyDataValues(editingAnchor); } else if (DrawingState == DrawingState.Moving) { foreach (ChartAnchor anchor in Anchors) { anchor.MoveAnchor(InitialMouseDownAnchor, dataPoint, chartControl, chartPanel, chartScale, this); } // Don't forget to update delta to last used } }
public override Cursor GetCursor(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, Point point) { if (DrawingState == DrawingState.Building) { return(Cursors.Pen); } if (DrawingState == DrawingState.Moving) { return(IsLocked ? Cursors.No : Cursors.SizeAll); } if (DrawingState == DrawingState.Editing) { return(IsLocked ? Cursors.No : Cursors.SizeWE); } if (GetClosestBarAnchor(chartControl, point, false) != int.MinValue) { return(Cursors.SizeWE); } else if (IsPointOnTimeCyclesOutline(chartControl, chartPanel, point)) { return(Cursors.SizeAll); } return(Cursors.Arrow); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public ElderThermometer(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.ElderThermometer; Init(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public HighMinusLow(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.HighMinusLow; Init(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public HighLowBands(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.HighLowBands; Init(); }
public override void OnRender(ChartControl chartControl, ChartScale chartScale) { base.OnRender(chartControl, chartScale); InitializeDrawingTools(); //Calculate where to draw the text. //Refer to parent class Lines.cs OnRender method for more information. ChartPanel panel = chartControl.ChartPanels[chartScale.PanelIndex]; double strokePixAdj = ((double)(Stroke.Width % 2)).ApproxCompare(0) == 0 ? 0.5d : 0d; Vector pixelAdjustVec = new Vector(strokePixAdj, strokePixAdj); Point endPoint = EndAnchor.GetPoint(chartControl, panel, chartScale); Point endPointAdjusted = endPoint + pixelAdjustVec; SharpDX.Vector2 endVec = endPointAdjusted.ToVector2(); //Calculate the current price. string text = (Text != "" ? Text : chartControl.Instrument.MasterInstrument.FormatPrice(chartScale.GetValueByY(endVec.Y), true)); //Set properties for rectangle to draw the object. TextLayout tl = new TextLayout(Core.Globals.DirectWriteFactory, text, cachedTextFormat, ChartPanel.W, ChartPanel.H); SharpDX.RectangleF rect = new SharpDX.RectangleF(); rect.X = (float)endVec.X; rect.Y = (float)endVec.Y - 6f; rect.Width = (float)-(tl.Metrics.Width); rect.Height = (float)-(tl.Metrics.Height); //Draw the text. using (SharpDX.Direct2D1.Brush myDxBrush = TextColor.ToDxBrush(RenderTarget)) { chartScale.GetValueByY(endVec.Y); RenderTarget.DrawText(string.Format("{0}", text), cachedTextFormat, rect, myDxBrush); } }
public override void OnRender(ChartControl chartControl, ChartScale chartScale) { ChartPanel panel = chartControl.ChartPanels[PanelIndex]; UpdateArcGeometry(chartControl, panel, chartScale); base.OnRender(chartControl, chartScale); RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; if (AreaBrush != null && !IsInHitTest) { areaBrushDevice.RenderTarget = RenderTarget; if (areaBrushDevice.Brush == null) { Brush brushCopy = AreaBrush.Clone(); brushCopy.Opacity = areaOpacity / 100d; areaBrushDevice.Brush = brushCopy; } RenderTarget.FillGeometry(arcGeometry, areaBrushDevice.BrushDX); } ArcStroke.RenderTarget = RenderTarget; SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : ArcStroke.BrushDX; RenderTarget.DrawGeometry(arcGeometry, tmpBrush, ArcStroke.Width, ArcStroke.StrokeStyle); }
public override void OnMouseMove(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint) { if (IsLocked && DrawingState != DrawingState.Building) { return; } switch (DrawingState) { case DrawingState.Building: if (StartAnchor.IsEditing) { dataPoint.CopyDataValues(StartAnchor); } if (EndAnchor.IsEditing) { dataPoint.CopyDataValues(EndAnchor); } break; case DrawingState.Editing: dataPoint.CopyDataValues(EndAnchor); break; case DrawingState.Moving: StartAnchor.MoveAnchor(InitialMouseDownAnchor, dataPoint, chartControl, chartPanel, chartScale, this); EndAnchor.MoveAnchor(InitialMouseDownAnchor, dataPoint, chartControl, chartPanel, chartScale, this); break; } }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public RainbowOscillator(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.RainbowOscillator; Init(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public Median(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.Median; Init(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public FractalChaosOscillator(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.FractalChaosOscillator; Init(); }
public override void OnMouseMove(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint) { if (IsLocked && DrawingState != DrawingState.Building) { return; } if (DrawingState == DrawingState.Building && EndAnchor.IsEditing) { if (Mode == RegionHighlightMode.Price) { dataPoint.Time = chartControl.FirstTimePainted.AddSeconds((chartControl.LastTimePainted - chartControl.FirstTimePainted).TotalSeconds / 2); } else { dataPoint.Price = chartScale.MinValue + chartScale.MaxMinusMin / 2; } dataPoint.CopyDataValues(EndAnchor); //Point buildAdjusted = Mode == RegionHighlightMode.Time ? new Point(point.X, startAnchorPoint.Y) : new Point(startAnchorPoint.X, point.Y); //EndAnchor.UpdateFromPoint(buildAdjusted, chartControl, chartScale); } else if (DrawingState == DrawingState.Editing && editingAnchor != null) { dataPoint.CopyDataValues(editingAnchor); } else if (DrawingState == DrawingState.Moving) { foreach (ChartAnchor anchor in Anchors) { anchor.MoveAnchor(InitialMouseDownAnchor, dataPoint, chartControl, chartPanel, chartScale, this); } } }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public UltimateOscillator(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.UltimateOscillator; Init(); }
private bool IsPointOnTimeCyclesOutline(ChartControl chartControl, ChartPanel chartPanel, Point p) { if (radius < 0) { return(false); } int leftX = chartControl.GetXByTime(GetChartBars().GetTimeByBarIdx(chartControl, 0)) - diameter; for (int i = 0; i < anchorBars.Count - 1; i++) { if (anchorBars[i] < leftX) { continue; } // We get the angle from the center of ellipse to point p, then calculate the expected point on the ellipse and compare to that double startX = anchorBars[i] + radius; double startY = chartPanel.Y + chartPanel.H; double rad = Math.Atan2(p.Y - startY, p.X - startX); double deg = rad * (180.0 / Math.PI); double t = Math.Atan(radius * Math.Tan(rad) / radius) + (deg > 90 ? Math.PI : deg < -90 ? 0 - Math.PI : 0); double checkX = startX + radius * Math.Cos(t); double checkY = startY + radius * Math.Sin(t); if (p.X < checkX + cursorSensitivity && p.X > checkX - cursorSensitivity && p.Y < checkY + cursorSensitivity && p.Y > checkY - cursorSensitivity) { return(true); } } return(false); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public VolumeROC(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.VolumeROC; Init(); }
public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint) { switch (DrawingState) { case DrawingState.Building: if (StartAnchor.IsEditing) { dataPoint.CopyDataValues(StartAnchor); dataPoint.CopyDataValues(EndAnchor); StartAnchor.IsEditing = false; } else if (EndAnchor.IsEditing) { dataPoint.CopyDataValues(EndAnchor); EndAnchor.IsEditing = false; DrawingState = DrawingState.Normal; IsSelected = false; } break; case DrawingState.Normal: Point p = dataPoint.GetPoint(chartControl, chartPanel, chartScale); Cursor c = GetCursor(chartControl, chartPanel, chartScale, p); if (c == Cursors.SizeWE) { int editingAnchor = GetClosestBarAnchor(chartControl, p, false); int i = anchorBars.IndexOf(editingAnchor); if (editingAnchor != int.MinValue && i > -1) { StartAnchor.UpdateXFromPoint(new Point(anchorBars[i == 0 ? i : i - 1], chartPanel.Y + chartPanel.H), chartControl, chartScale); EndAnchor.UpdateXFromPoint(new Point(anchorBars[i == 0 ? i + 1 : i], chartPanel.Y + chartPanel.H), chartControl, chartScale); EndAnchor.IsEditing = true; DrawingState = DrawingState.Editing; } } else if (c == Cursors.SizeAll) { int editingAnchor = GetClosestBarAnchor(chartControl, p, true); int i = anchorBars.IndexOf(editingAnchor); if (editingAnchor != int.MinValue && i > -1) { StartAnchor.UpdateXFromPoint(new Point(anchorBars[i - 1], chartPanel.Y + chartPanel.H), chartControl, chartScale); EndAnchor.UpdateXFromPoint(new Point(anchorBars[i], chartPanel.Y + chartPanel.H), chartControl, chartScale); // We have to update the InitialMouseDownAnchor here because we moved our Start/End anchors InitialMouseDownAnchor = dataPoint.Clone() as ChartAnchor; DrawingState = DrawingState.Moving; } } else { IsSelected = false; } break; } }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public SimpleMovingAverage(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.SimpleMovingAverage; Init(); }
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { if (Bars == null || ChartControl == null) { return; } RenderTarget.AntialiasMode = AntialiasMode.PerPrimitive; ChartPanel panel = chartControl.ChartPanels[ChartPanel.PanelIndex]; int idx = BarsArray[0].Count - 1 - (Calculate == Calculate.OnBarClose ? 1 : 0); double intercept = interceptSeries.GetValueAt(idx); double slope = slopeSeries.GetValueAt(idx); double stdDev = stdDeviationSeries.GetValueAt(idx); int stdDevPixels = (int)Math.Round(((stdDev * Width) / (chartScale.MaxValue - chartScale.MinValue)) * panel.H, 0); int xPos = GetXPos(Period - 1 - Displacement); int yPos = GetYPos(intercept, chartScale); int xPos2 = GetXPos(0 - Displacement); int yPos2 = GetYPos(intercept + slope * (Period - 1), chartScale); Vector2 startVector = new Vector2(xPos, yPos); Vector2 endVector = new Vector2(xPos2, yPos2); // Middle RenderTarget.DrawLine(startVector, endVector, Plots[0].BrushDX, Plots[0].Width, Plots[0].StrokeStyle); // Upper RenderTarget.DrawLine(new Vector2(startVector.X, startVector.Y - stdDevPixels), new Vector2(endVector.X, endVector.Y - stdDevPixels), Plots[1].BrushDX, Plots[1].Width, Plots[1].StrokeStyle); // Lower RenderTarget.DrawLine(new Vector2(startVector.X, startVector.Y + stdDevPixels), new Vector2(endVector.X, endVector.Y + stdDevPixels), Plots[2].BrushDX, Plots[2].Width, Plots[2].StrokeStyle); RenderTarget.AntialiasMode = AntialiasMode.Aliased; }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public MarketFacilitationIndex(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.MarketFacilitationIndex; Init(); }
private void MenuItemNewHistoryChart_Click(object sender, EventArgs e) { int numCharts = chartPanels.Count; string chartId = (numCharts + 1).ToString(); string menuText = "History Chart " + chartId; string menuItemName = "MenuItem_Chart_" + chartId; ChartPanel newPanel = new ChartPanel(); newPanel.FormClosing += (s, a) => { RemoveChartPanelFromBrokerAndMenu(newPanel, menuItemName); }; newPanel.Text = menuText; newPanel.Tag = newPanel; newPanel.Show(mainPanel, DockState.Document); chartPanels.Add(newPanel); shadowBroker.Register(newPanel); if (chartPanels.Count == 1) { MenuView.DropDownItems.Add(new ToolStripSeparator()); } ToolStripMenuItem newMenuItem = new ToolStripMenuItem(menuText, null, HistoryChartMenuItemClicked /*(s, ea) => { chartPanels.Find(x => x.Text == menuText)?.Focus(); }*/, menuItemName); MenuView.DropDownItems.Add(newMenuItem); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public MACDHistogram(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.MACDHistogram; Init(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public WellesWilderSmoothing(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.WellesWilderSmoothing; Init(); }
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { if (BarsArray[0] == null || ChartBars == null) { return; } ChartPanel panel = chartControl.ChartPanels[chartScale.PanelIndex]; float endX = panel.X + panel.W; if (ShowAskLine && Values[0].IsValidDataPointAt(Values[0].Count - 1)) { float startX = Convert.ToSingle(panel.X + panel.W * (1 - AskLineLength / 100.0)); float y = chartScale.GetYByValue(Values[0].GetValueAt(Values[0].Count - 1)); RenderTarget.DrawLine(new SharpDX.Vector2(startX, y), new SharpDX.Vector2(endX, y), AskStroke.BrushDX, AskStroke.Width, AskStroke.StrokeStyle); } if (ShowBidLine && Values[1].IsValidDataPointAt(Values[1].Count - 1)) { float startX = Convert.ToSingle(panel.X + panel.W * (1 - BidLineLength / 100.0)); float y = chartScale.GetYByValue(Values[1].GetValueAt(Values[1].Count - 1)); RenderTarget.DrawLine(new SharpDX.Vector2(startX, y), new SharpDX.Vector2(endX, y), BidStroke.BrushDX, BidStroke.Width, BidStroke.StrokeStyle); } if (ShowLastLine && Values[2].IsValidDataPointAt(Values[2].Count - 1)) { float startX = Convert.ToSingle(panel.X + panel.W * (1 - LastLineLength / 100.0)); float y = chartScale.GetYByValue(Values[2].GetValueAt(Values[2].Count - 1)); RenderTarget.DrawLine(new SharpDX.Vector2(startX, y), new SharpDX.Vector2(endX, y), LastStroke.BrushDX, LastStroke.Width, LastStroke.StrokeStyle); } }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public BollingerBands(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.BollingerBands; Init(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public LinearRegressionForecast(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.LinearRegressionForecast; Init(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public WilliamsPctR(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.WilliamsPctR; Init(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public DetrendedPriceOscillator(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.DetrendedPriceOscillator; Init(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Indicator name</param> /// <param name="chartPanel">Reference to a panel where it will be placed</param> public TradeVolumeIndex(string name, ChartPanel chartPanel) : base(name, chartPanel) { _indicatorType = IndicatorType.TradeVolumeIndex; Init(); }
public Markers() { InitializeComponent(); SampleData.CreateData(chart); chart.ChartType = ChartType.XYPlot; chart.Palette = ColorGeneration.Urban; var pnl = new ChartPanel(); var vmarker = CreateMarker(false); pnl.Children.Add(vmarker); vmarker.Action = ChartPanelAction.MouseMove; var hmarker = CreateMarker(true); pnl.Children.Add(hmarker); hmarker.Action = ChartPanelAction.MouseMove; chart.View.Layers.Add(pnl); cbAttach.ItemsSource = Utils.GetEnumValues(typeof(ChartPanelAttach)); cbAttach.SelectedIndex = 0; cbAttach.SelectionChanged += (s, e) => { hmarker.Attach = vmarker.Attach = (ChartPanelAttach)Enum.Parse(typeof(ChartPanelAttach), cbAttach.SelectedValue.ToString(), true); }; }
public override Cursor GetCursor(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, Point point) { switch (DrawingState) { case DrawingState.Building: return(Cursors.Pen); case DrawingState.Moving: return(IsLocked ? Cursors.No : Cursors.SizeAll); case DrawingState.Editing: if (IsLocked) { return(Cursors.No); } if (editingAnchor == TextAnchor) { return(Cursors.SizeNESW); } return(editingAnchor == StartAnchor ? Cursors.SizeNESW : Cursors.SizeNWSE); default: // see if we are near an anchor right away. this is is cheap so no big deal to do often ChartAnchor closest = GetClosestAnchor(chartControl, chartPanel, chartScale, cursorSensitivity, point); if (closest != null) { if (IsLocked) { return(Cursors.Arrow); } return(closest == StartAnchor ? Cursors.SizeNESW : Cursors.SizeNWSE); } // draw move cursor if cursor is near line path anywhere Point startAnchorPoint = StartAnchor.GetPoint(chartControl, chartPanel, chartScale); Point endAnchorPoint = EndAnchor.GetPoint(chartControl, chartPanel, chartScale); Point txtAnchorPoint = TextAnchor.GetPoint(chartControl, chartPanel, chartScale); Vector startEndVector = endAnchorPoint - startAnchorPoint; Vector endToTextVector = txtAnchorPoint - endAnchorPoint; //Text Outline Box Path as well UpdateTextLayout(chartControl, ChartPanel, chartScale); Point bottomLeft = new Point(txtAnchorPoint.X - textLayout.MaxWidth - textMargin, txtAnchorPoint.Y); Point topLeft = new Point(bottomLeft.X, txtAnchorPoint.Y - textLayout.MaxHeight - 2 * textMargin); Point topRight = new Point(txtAnchorPoint.X, txtAnchorPoint.Y - textLayout.MaxHeight - 2 * textMargin); Vector txtBottomLeft = bottomLeft - txtAnchorPoint; Vector bottomLeftTopLeft = topLeft - bottomLeft; Vector topLeftTopRight = topRight - topLeft; Vector topRightTxt = txtAnchorPoint - topRight; if (MathHelper.IsPointAlongVector(point, startAnchorPoint, startEndVector, cursorSensitivity) || MathHelper.IsPointAlongVector(point, endAnchorPoint, endToTextVector, cursorSensitivity) || MathHelper.IsPointAlongVector(point, txtAnchorPoint, txtBottomLeft, cursorSensitivity) || MathHelper.IsPointAlongVector(point, bottomLeft, bottomLeftTopLeft, cursorSensitivity) || MathHelper.IsPointAlongVector(point, topLeft, topLeftTopRight, cursorSensitivity) || MathHelper.IsPointAlongVector(point, topRight, topRightTxt, cursorSensitivity)) { return(IsLocked ? Cursors.Arrow : Cursors.SizeAll); } return(null); } }
public void init_or_deinit(object indi_or_strat_, bool init) { if (init && indi_or_strat == null) { indi_or_strat = (NinjaTrader.NinjaScript.NinjaScriptBase)indi_or_strat_; if (indi_or_strat_ is NinjaTrader.NinjaScript.IndicatorBase) { indi = (NinjaTrader.NinjaScript.Indicators.Indicator)indi_or_strat_; chartControl = indi.ChartControl; chartPnl = indi.ChartControl.ChartPanels[0]; chartBars = indi.ChartBars; } else if (indi_or_strat_ is NinjaTrader.NinjaScript.Strategies.Strategy) { strat = (NinjaTrader.NinjaScript.Strategies.Strategy)indi_or_strat_; chartControl = strat.ChartControl; chartPnl = strat.ChartControl.ChartPanels[0]; chartBars = strat.ChartBars; } if (chartControl == null || chartPnl == null) { enabled = false; return; } enabled = true; registerEventHandlers(); } else { checkForDeregister(); } }
public void Initialize() { //create and initialize chart descriptor (common parent of all charts) _chartDescriptor = SpcManager.CreateChartDescriptor(ChartTypesEnum.XMRChart); //check properties initialized Assert.IsNotNull(_chartDescriptor); Assert.IsNotNull(_chartDescriptor.Charts); Assert.AreEqual(_chartDescriptor.ChartType, ChartTypesEnum.XMRChart); Assert.AreEqual(_chartDescriptor.DataPoints, 0); Assert.AreEqual(_chartDescriptor.SubgroupSize, 0); Assert.AreEqual(_chartDescriptor.RangeSteps, 0); Assert.AreEqual(_chartDescriptor.Exponent, 0); Assert.IsFalse(_chartDescriptor.ShowUSL); Assert.IsFalse(_chartDescriptor.ShowLSL); Assert.AreEqual(_chartDescriptor.USL, 0.0); Assert.AreEqual(_chartDescriptor.LSL, 0.0); Assert.AreEqual(_chartDescriptor.HeightMultiplier, 1.0); Assert.IsTrue(_chartDescriptor.CalculateControlLimits); //test list of initial data _list = new List<SamplePrimitive> { new SamplePrimitive(2.0, 52, "Number"), new SamplePrimitive(3.0, 52, "Number"), new SamplePrimitive(2.0, 52, "Number"), new SamplePrimitive(3.0, 52, "Number"), new SamplePrimitive(4.0, 52, "Number"), new SamplePrimitive(4.0, 48, "Number"), new SamplePrimitive(5.5, 48, "Number"), new SamplePrimitive(7.0, 48, "Number"), new SamplePrimitive(12.0, 48, "Number"), new SamplePrimitive(15.0, 48, "Number"), new SamplePrimitive(5.0, 49, "Number"), new SamplePrimitive(6.0, 49, "Number") }; //create charts according to chart type SpcManager.CreateCharts(_chartDescriptor, ChartTypesEnum.XMRChart); //check charts created Assert.AreEqual(_chartDescriptor.Charts.Count, 2); Assert.IsTrue(_chartDescriptor.Charts[0] is XBarChart); Assert.IsTrue(_chartDescriptor.Charts[1] is XMRChart); _chartDescriptor.CustomLCL = 2.0; _chartDescriptor.CustomUCL = 4.0; _chartDescriptor.LSL = 1.0; _chartDescriptor.USL = 6.0; _chartDescriptor.DataPoints = 5; _chartDescriptor.SubgroupSize = 3; }
public MainWindow() { InitializeComponent(); #region DataCreation XYDataSeries Ds = new XYDataSeries(); Ds.ChartType = ChartType.Line; List<int> xvalues = new List<int>(); xvalues.Add(1); xvalues.Add(2); xvalues.Add(3); xvalues.Add(4); xvalues.Add(5); xvalues.Add(6); xvalues.Add(7); xvalues.Add(8); xvalues.Add(9); List<int> yvalues = new List<int>(); yvalues.Add(200); yvalues.Add(130); yvalues.Add(303); yvalues.Add(442); yvalues.Add(190); yvalues.Add(239); yvalues.Add(400); yvalues.Add(350); yvalues.Add(9); Ds.XValuesSource = xvalues; Ds.ValuesSource = yvalues; #endregion chart.Data.Children.Add(Ds); var pnl = new ChartPanel(); pnl.MouseMove += new MouseEventHandler(pnl_MouseMove); var vmarker = CreateMarker(false, new Point()); pnl.Children.Add(vmarker); vmarker.Action = ChartPanelAction.None; var hmarker = CreateMarker(true, new Point()); pnl.Children.Add(hmarker); hmarker.Action = ChartPanelAction.None; chart.View.Layers.Add(pnl); }
private void Chart_OnSubscribeIndicatorElement(ChartIndicatorElement element, CandleSeries series, IIndicator indicator, ChartPanel chart) { var values = _allCandles .Select(candle => { if (candle.State != CandleStates.Finished) candle.State = CandleStates.Finished; return new RefPair<DateTimeOffset, IDictionary<IChartElement, object>>(candle.OpenTime, new Dictionary<IChartElement, object> { { element, indicator.Process(candle) } }); }) .ToArray(); chart.Draw(values); }
public void Initialize() { _chartDescriptorWithData = Mock.Create<ChartPanel>(Constructor.Mocked, Behavior.Loose); var chartCollection = new ChartCollection(); _chartDescriptorWithData.Charts = chartCollection; var xChart = Mock.Create<XBarChart>(Constructor.Mocked, Behavior.Loose); Mock.Arrange(() => xChart.IsChild).Returns(true); xChart.DataSource = new MobileObservableCollection<SampleUnit> { CreateSample(1.0, 1.61, 1.36, 1.11, 7), CreateSample(1.0, 1.61, 1.36, 1.11, 7), CreateSample(0.8571428571428571, 1.61, 1.36, 1.11, 7), CreateSample(0.0, 1.61, 1.36, 1.11, 7), CreateSample(0.0, 1.61, 1.36, 1.11, 7), CreateSample(0.0, 1.61, 1.36, 1.11, 7), CreateSample(0.5714285714285714, 1.61, 1.36, 1.11, 7), CreateSample(2.0, 1.61, 1.36, 1.11, 7), CreateSample(3.4285714285714284, 1.61, 1.36, 1.11, 7), CreateSample(4.7142857142857144, 1.61, 1.36, 1.11, 7) }; chartCollection.Add(xChart); var rChart = Mock.Create<RChart>(Constructor.Mocked, Behavior.Loose); Mock.Arrange(() => rChart.IsChild).Returns(true); rChart.DataSource = new MobileObservableCollection<SampleUnit> { CreateSample(0.0, 1.15, 0.6, 0.05, 7), CreateSample(0.0, 1.15, 0.6, 0.05, 7), CreateSample(1.0, 1.15, 0.6, 0.05, 7), CreateSample(0.0, 1.15, 0.6, 0.05, 7), CreateSample(0.0, 1.15, 0.6, 0.05, 7), CreateSample(0.0, 1.15, 0.6, 0.05, 7), CreateSample(1.0, 1.15, 0.6, 0.05, 7), CreateSample(2.0, 1.15, 0.6, 0.05, 7), CreateSample(1.0, 1.15, 0.6, 0.05, 7), CreateSample(1.0, 1.15, 0.6, 0.05, 7) }; chartCollection.Add(rChart); }
public static void CreateCharts(ChartPanel parentPanel, ChartTypesEnum chartType) { parentPanel.SetSilently(ChartPanel.ChartsProperty, DataPortal.FetchChild<ChartCollection>()); parentPanel.Charts.PopulateCollection(chartType); }
public MouseMarker() { InitializeComponent(); SampleData.CreateData(chart); chart.ChartType = ChartType.LineSymbols; var pnl = new ChartPanel(); var obj = new ChartPanelObject() { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom }; var bdr = new Border() { Background = new SolidColorBrush(Colors.Green) { Opacity = 0.4 }, BorderBrush = new SolidColorBrush(Colors.Green), BorderThickness = new Thickness(1, 1, 3, 3), CornerRadius = new CornerRadius(6, 6, 0, 6), Padding = new Thickness(3) }; //bdr.Padding = new Thickness(16, 16, 0, 0); var sp = new StackPanel(); var tb1 = new TextBlock(); var bind1 = new Binding(); bind1.Source = obj; bind1.StringFormat = "x={0:#.##}"; bind1.Path = new PropertyPath("DataPoint.X"); tb1.SetBinding(TextBlock.TextProperty, bind1); var tb2 = new TextBlock(); var bind2 = new Binding(); bind2.Source = obj; bind2.StringFormat = "y={0:#.##}"; bind2.Path = new PropertyPath("DataPoint.Y"); tb2.SetBinding(TextBlock.TextProperty, bind2); sp.Children.Add(tb1); sp.Children.Add(tb2); bdr.Child = sp; obj.Content = bdr; obj.DataPoint = new Point(); obj.Action = ChartPanelAction.MouseMove; pnl.Children.Add(obj); chart.View.Layers.Add(pnl); cbAttach.ItemsSource = Utils.GetEnumValues(typeof(ChartPanelAttach)); cbAttach.SelectedIndex = 0; cbAttach.SelectionChanged += (s, e) => { obj.Attach = (ChartPanelAttach)Enum.Parse(typeof(ChartPanelAttach), cbAttach.SelectedValue.ToString(), true); }; }
public static Task<ChartPanel> GetSampleDataForSPCAsync(IEditableRoot instance, string spcFieldName, ChartTypesEnum chartType, ChartPanel chartDescriptor, bool isForExpressions) { return TaskHelper.FromResult(chartDescriptor); }
/// <summary> /// 鼠标单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ChartGraph_MouseDown(object sender, MouseEventArgs e) { Point mp = GetCrossHairPoint(); mouse_x = mp.X; mouse_y = mp.Y; if (e.Button == MouseButtons.Left && processBarValue == 0) { crossHair_y = mp.Y; if (e.Clicks == 1) { //单击改变十字线准星位置 this.crossOverIndex = this.GetCrossOverIndex(); object obj = JudgeSelectedSeries(crossOverIndex, crossHair_y, true); if (obj != null && !showCrossHair && canDragSeries) { this.Cursor = Cursors.Cross; } DrawGraph(); } else if (e.Clicks == 2) { //双击显示或隐藏十字线 this.ShowCrossHair = !this.ShowCrossHair; this.crossOverIndex = this.GetCrossOverIndex(); selectedObject = null; DrawGraph(); } } //判断是否要进行resize if (!showCrossHair) { int pIndex = 0; //当鼠标到纵向下边线上时,认为是需要调整大小 foreach (ChartPanel chartPanel in this.dicChartPanel.Values) { pIndex++; if (pIndex == dicChartPanel.Count) { break; } Rectangle resizeRect = new Rectangle(0, chartPanel.RectPanel.Bottom - 2, chartPanel.RectPanel.Width, 4); if (resizeRect.Contains(mp)) { this.Cursor = Cursors.SizeNS; userResizePanel = chartPanel; DrawGraph(); goto OutLoop; } } OutLoop: ; } else { userResizePanel = null; } this.Focus(); }
/// <summary> /// 获取某一值的纵坐标 /// </summary> /// <param name="chartPanel"></param> /// <param name="value"></param> public float GetValueYPixel(ChartPanel chartPanel, double chartValue) { return Convert.ToSingle((chartPanel.MaxValue - chartValue) / (chartPanel.MaxValue - chartPanel.MinValue) * GetWorkSpaceY(chartPanel.PanelID) + chartPanel.TitleHeight + chartPanel.RectPanel.Y); }
/// <summary> /// 添加新的面板 /// </summary> /// <returns></returns> public int AddChartPanel(int verticalPercent) { int locationY = 0; foreach (ChartPanel cp in this.dicChartPanel.Values) { locationY += Convert.ToInt32((double)cp.VerticalPercent / 100 * this.Height); } int panelHeight = Convert.ToInt32((double)verticalPercent / 100 * this.Height); ChartPanel chartPanel = new ChartPanel(); chartPanel.VerticalPercent = verticalPercent; chartPanel.PanelID = CommonClass.GetPanelID(); chartPanel.RectPanel = new Rectangle(0, locationY, this.Width, panelHeight); this.dicChartPanel[chartPanel.PanelID] = chartPanel; return chartPanel.PanelID; }
/// <summary> /// 用户自己拖动图像改变大小 /// </summary> public void DragChartPanel() { if (userResizePanel != null) { Point mp = GetCrossHairPoint(); ChartPanel nextCP = null; bool rightP = false; foreach (ChartPanel chartPanel in this.dicChartPanel.Values) { if (rightP) { nextCP = chartPanel; break; } if (chartPanel == userResizePanel) { rightP = true; } } int originalVP = userResizePanel.VerticalPercent; if (userResizePanel.RectPanel.Contains(mp)) { userResizePanel.VerticalPercent = Convert.ToInt32(((double)mp.Y - (double)userResizePanel.RectPanel.Top) / (double)this.Height * 100); if (userResizePanel.VerticalPercent < 1) { userResizePanel.VerticalPercent = 1; } if (nextCP != null) { nextCP.VerticalPercent += originalVP - userResizePanel.VerticalPercent; } } else { if (nextCP != null && nextCP.RectPanel.Contains(mp)) { userResizePanel.VerticalPercent = Convert.ToInt32(((double)mp.Y - (double)userResizePanel.RectPanel.Top) / (double)this.Height * 100); if (userResizePanel.VerticalPercent >= originalVP + nextCP.VerticalPercent) { userResizePanel.VerticalPercent -= 1; } nextCP.VerticalPercent = originalVP + nextCP.VerticalPercent - userResizePanel.VerticalPercent; } } userResizePanel = null; ResizeGraph(); DrawGraph(); } }