private void initGraph() { mGraph.GraphPane.Title.IsVisible = false; mGraph.GraphPane.XAxis.Title.IsVisible = false; mGraph.GraphPane.YAxis.Title.IsVisible = false; mGraph.IsEnableZoom = false; mGraph.MouseDownEvent += onGraphMouseDown; mGraph.MouseMoveEvent += onGraphMouseMove; mGraph.MouseUpEvent += onGraphMouseUp; // X axis mGraph.GraphPane.XAxis.Scale.MinorStep = 5; mGraph.GraphPane.XAxis.Scale.MajorStep = 10; mGraph.GraphPane.XAxis.Scale.Min = 0; mGraph.GraphPane.XAxis.Scale.Max = 100; mGraph.GraphPane.XAxis.MinorGrid.IsVisible = false; mGraph.GraphPane.XAxis.MajorGrid.IsVisible = true; mGraph.GraphPane.XAxis.Type = AxisType.Linear; mGraph.GraphPane.XAxis.ScaleFormatEvent += (pane, axis, val, index) => { var min = OptionManager.getInstance().IsFahrenheit == false ? 0 : 32; var majorStep = OptionManager.getInstance().IsFahrenheit == false ? 10 : 18; var temp = min + majorStep * index; return(temp + (OptionManager.getInstance().IsFahrenheit == false ? "°C" : "°F")); }; // Y axis mGraph.GraphPane.YAxis.Scale.MinorStep = 5; mGraph.GraphPane.YAxis.Scale.MajorStep = 10; mGraph.GraphPane.YAxis.Scale.Min = 0; mGraph.GraphPane.YAxis.Scale.Max = 100; mGraph.GraphPane.YAxis.Scale.Format = "0%"; mGraph.GraphPane.YAxis.MajorGrid.IsVisible = true; mGraph.GraphPane.YAxis.Type = AxisType.Linear; mGraph.GraphPane.CurveList.Clear(); // line mPointList = new PointPairList(); for (int i = 0; i < FanData.MAX_FAN_VALUE_SIZE_5; i++) { mPointList.Add(5 * i, 50); } mLineItem = mGraph.GraphPane.AddCurve("Graph", mPointList, Color.Blue, SymbolType.Circle); mLineItem.Line.Width = 2.0f; mLineItem.Symbol.Size = 10.0f; mLineItem.Symbol.Fill = new Fill(Color.White); mAutoPolyObj = new ZedGraph.PolyObj { Points = new[] { new ZedGraph.PointD(0, 0), new ZedGraph.PointD(0, 100), new ZedGraph.PointD(0, 0), }, Fill = new ZedGraph.Fill(Color.White), ZOrder = ZedGraph.ZOrder.B_BehindLegend, }; mGraph.GraphPane.GraphObjList.Add(mAutoPolyObj); mNowPoint = new PointObj(50, 50, 10.0, 10.0, ZedGraph.SymbolType.Circle, Color.Red); mNowPoint.Fill = new ZedGraph.Fill(Color.Red); mNowPoint.ZOrder = ZedGraph.ZOrder.A_InFront; mGraph.GraphPane.GraphObjList.Add(mNowPoint); mPresetLabel.Visible = false; mPresetLoadButton.Visible = false; mPresetSaveButton.Visible = false; mUnitLabel.Visible = false; mUnitComboBox.Visible = false; mGraph.Visible = false; mAutoLabel.Visible = false; mAutoNumericUpDown.Visible = false; mStepCheckBox.Visible = false; mHysLabel.Visible = false; mHysNumericUpDown.Visible = false; }
/// <summary> /// Creates guard image, using IGuard's position and orientation /// </summary> public void setImage() { int tileSize = MySize * 2; //Create a blue rectangle, that extends to edge of tile only on orientation direction // The other sides will be shortened by tileSize/4 if (MyPosition == null) { return; } int sizeDiff = tileSize - size; IPoint _bLeft = new PointObj(), _bRight = new PointObj(), _tLeft = new PointObj(), _tRight = new PointObj(), _tO = MyPosition; GuardRectangle rect = new GuardRectangle(); #region Determine orientation //Determine long side switch (MyOrientation) { case OpenGlGuard.OpenGlGuardOrientation.left: //Make distances from {_bLeft,_bRight}{_tLeft,_tRight} Long _bLeft = new PointObj(_tO.X, _tO.Y + sizeDiff / 2, _tO.Z + 1); _tLeft = new PointObj(_tO.X, _tO.Y + size + sizeDiff / 2, _tO.Z + 1); _bRight = new PointObj(_tO.X + size + sizeDiff / 2, _tO.Y + sizeDiff / 2, _tO.Z + 1); _tRight = new PointObj(_tO.X + size + sizeDiff / 2, _tO.Y + sizeDiff / 2 + size, _tO.Z + 1); break; case OpenGlGuard.OpenGlGuardOrientation.right: //Make distances from {_bLeft,_bRight}{_tLeft,_tRight} Long _bLeft = new PointObj(_tO.X + sizeDiff / 2, _tO.Y + sizeDiff / 2, _tO.Z + 1); _tLeft = new PointObj(_tO.X + sizeDiff / 2, _tO.Y + size + sizeDiff / 2, _tO.Z + 1); _bRight = new PointObj(_tO.X + size + sizeDiff, _tO.Y + sizeDiff / 2, _tO.Z + 1); _tRight = new PointObj(_tO.X + size + sizeDiff, _tO.Y + sizeDiff / 2 + size, _tO.Z + 1); break; case OpenGlGuard.OpenGlGuardOrientation.up: //Make distances from {_bLeft,_tLeft}{_tRight,_bRight} Long _bLeft = new PointObj(_tO.X + sizeDiff / 2, _tO.Y + sizeDiff / 2, _tO.Z + 1); _tLeft = new PointObj(_tO.X + sizeDiff / 2, _tO.Y + size + sizeDiff, _tO.Z + 1); _bRight = new PointObj(_tO.X + size + sizeDiff / 2, _tO.Y + sizeDiff / 2, _tO.Z + 1); _tRight = new PointObj(_tO.X + size + sizeDiff / 2, _tO.Y + sizeDiff + size, _tO.Z + 1); break; case OpenGlGuard.OpenGlGuardOrientation.down: //Make distances from {_bLeft,_tLeft}{_tRight,_bRight} Long _bLeft = new PointObj(_tO.X + sizeDiff / 2, _tO.Y, _tO.Z + 1); _tLeft = new PointObj(_tO.X + sizeDiff / 2, _tO.Y + size + sizeDiff / 2, _tO.Z + 1); _bRight = new PointObj(_tO.X + size + sizeDiff / 2, _tO.Y, _tO.Z + 1); _tRight = new PointObj(_tO.X + size + sizeDiff / 2, _tO.Y + sizeDiff / 2 + size, _tO.Z + 1); break; case OpenGlGuard.OpenGlGuardOrientation.none: //Make tile _bLeft = new PointObj(_tO.X + sizeDiff / 2, _tO.Y + sizeDiff / 2, _tO.Z + 1); break; default: break; } #endregion //If orientation is none, create a square else create rectangle if (MyOrientation == OpenGlGuardOrientation.none) { myImage = ((IDrawable) new Tile(_bLeft.toArray(), size)); } else { rect.MyRectangle = new rectangleObj(_bLeft, _tLeft, _bRight, _tRight, Common.colorBlue, Common.colorBlack); myImage = rect; } }
//-->> #region Acciones - Botones private void cmdAddObject_Click(object sender, EventArgs e) { try { int xinicial = int.Parse(txtXInicial.Text); int yinicial = int.Parse(txtYInicial.Text); int alto = int.Parse(txtAlto.Text); int ancho = int.Parse(txtAncho.Text); int cantidad = int.Parse(txtCantidad.Text); PointObj.enumDireccion _direccion = PointObj.enumDireccion.Derecha; switch (cmbDireccion.Text) { case "Arriba": _direccion = PointObj.enumDireccion.Arriba; break; case "Abajo": _direccion = PointObj.enumDireccion.Abajo; break; case "Izquierda": _direccion = PointObj.enumDireccion.Izquierda; break; case "Derecha": _direccion = PointObj.enumDireccion.Derecha; break; } List <PointObj> newobjects = new List <PointObj>(); int numobjects = OBJETOS.Count; string nombre = ""; string nombrebase = ""; if (txtNombre.Text.Trim().Length > 0) { nombrebase = txtNombre.Text.Trim().ToLower(); } else { nombrebase = "RunTimeObj"; } for (int cont = 0; cont < cantidad; cont++) { nombre = nombrebase + "_" + (OBJETOS.Count + cont + 1).ToString(); PointObj _point = new PointObj(SelectedColor, xinicial, yinicial, alto, ancho, _direccion, picOut.Width, picOut.Height, nombre, _negobjectbuffer, _negudpclient); newobjects.Add(_point); } OBJETOS.AddRange(newobjects); SetIdJourney(); //Graba la acción if (Grabando) { ActionRecord.AgregaObjetos(OBJETOS.Except(ObjetosGrabados).ToList()); ObjetosGrabados = new List <PointObj>(OBJETOS); } } catch { } }
//------------------------------------------------------------------------ // Update data on initialization or on timer //------------------------------------------------------------------------ private void calc(XDate now, bool timer) { var oldTimerEnabled = m_Timer.Enabled; m_Timer.Enabled = false; const double diff = 5.0f / XDate.SecondsPerDay; var tm = now - 5; var add = !timer || (m_Data.Count > 0 && ((now - LastPoint.Date) > diff)); StockPt pt = null; var up = m_Rand.NextDouble() > 0.5; var val = up ? LastPoint.Low : LastPoint.High; Action <double, double, bool> set_min_max = (min, max, absolute) => { var grace = (m_Pane.Y2Axis.Scale.Max - m_Pane.Y2Axis.Scale.Min) * m_Pane.Y2Axis.Scale.MaxGrace; var gap = grace; //m_Pane.Y2Axis.Scale.ReverseTransform(10) + grace; m_Pane.Y2Axis.Scale.Min = absolute ? min - gap : Math.Min(m_Pane.Y2Axis.Scale.Min, min - gap); m_Pane.Y2Axis.Scale.Max = absolute ? max + gap : Math.Max(m_Pane.Y2Axis.Scale.Max, max + gap); }; if (add) { var open = (float)(m_Open + m_Rand.NextDouble() * 10.0 - 5.0); var close = (float)(m_Open + m_Rand.NextDouble() * 10.0 - 5.0); var hi = (float)(Math.Max(open, close) + m_Rand.NextDouble() * 5.0); var low = (float)(Math.Min(open, close) - m_Rand.NextDouble() * 5.0); var bvol = m_Rand.NextDouble() * 1000; var svol = m_Rand.NextDouble() * 1000; var x = now.XLDate - (now.XLDate % diff); pt = new StockPt(x, open, hi, low, close, (int)bvol, (int)svol); m_Data.Add(pt); m_Open = close; m_EMA = EMA_ALPHA * close + (1.0 - EMA_ALPHA) * m_EMA; m_EMAData.Add(x, m_EMA); if (timer) { //m_Pane.XAxis.Scale.Max = now + 5; //m_Pane.XAxis.Scale.Min += diff; if (Math.Abs(Math.Round(m_Pane.XAxis.Scale.Max) - m_Data.Count) < 5) { var window = (int)(m_Pane.XAxis.Scale.Max - m_Pane.XAxis.Scale.Min); //m_Pane.XAxis.Scale.SetRange(); m_Pane.XAxis.Scale.Max = m_Data.Count + 1; m_Pane.XAxis.Scale.Min = m_Pane.XAxis.Scale.Max - window; double min = double.MaxValue, max = double.MinValue; var xMin = Scale.MinMax(0, (int)m_Pane.XAxis.Scale.Min, m_Data.Count); var xMax = Scale.MinMax(0, (int)m_Pane.XAxis.Scale.Max, m_Data.Count); for (int i = xMin; i < xMax; ++i) { var d = (StockPt)m_Data[i]; min = Math.Min(d.Low, min); max = Math.Max(d.High, max); } set_min_max(min, max, true); m_Pane.AxisChange(); } if (m_Data.Count % 1 == 0) { var yy = m_Pane.Y2Axis.Scale.ReverseTransform(m_Pane.Y2Axis.Scale.Transform(val) + (up ? 5 : -5)); //var y2 = val * (up ? 0.96 : 1.03); var arrow = new PointObj(m_Data.Count - 1, yy, 5, up ? SymbolType.ArrowUp : SymbolType.ArrowDown, up ? Color.Green : Color.Red) { IsMovable = false, IsY2Axis = true, YAxisIndex = 0, //Fill = {Type = FillType.None}, IsClippedToChartRect = true }; //arrow.Line.Width = 1; //arrow.Location.CoordinateFrame = CoordType.AxisXYScale; m_Pane.GraphObjList.Add(arrow); } } } else if (m_Data.Count > 0) { pt = LastPoint; pt.Close = (float)(m_Open + m_Rand.NextDouble() * 10.0 - 5.0); pt.High = (float)Math.Max(pt.High, Math.Max(m_Open, pt.Close) + m_Rand.NextDouble() * 5.0); pt.Low = (float)Math.Min(pt.Low, Math.Min(m_Open, pt.Close) - m_Rand.NextDouble() * 5.0); if (timer && Math.Abs(Math.Round(m_Pane.XAxis.Scale.Max) - m_Data.Count) < 5) { set_min_max(pt.Low, pt.High, false); } } if (m_Line != null) { m_Line.Value = pt.Close; } m_Now = now; m_Timer.Enabled = oldTimerEnabled; }