Beispiel #1
0
            protected internal CandleMidLineElement(CandleMidLineView view, PlotPane host, Point[] points) : base(host)
            {
                m_View   = view;
                m_Points = points;

                this.Region = new Rectangle(points[0].X, 0, points[points.Length - 1].X, host.Height);
            }
Beispiel #2
0
        protected override Elements.Element MakeSampleElement(TimeSeriesChart chart, PlotPane pane, CandleSample sample, int x, float minScale, float maxScale)
        {
            var elm = new CandleElement(pane, sample, x, minScale, maxScale, BlackWhite);

            if (ShowBalloons)
            {
                elm.MouseClick += elm_MouseClick;
            }

            return(elm);
        }
Beispiel #3
0
            protected internal YLevelElement(PlotPane host, TimeSeries.YLevel level, float minScale, float maxScale) : base(host)
            {
                m_Level = level;

                //   m_Style = new Style(null, getBaseStyle());
                m_ScaleMin = minScale;
                m_ScaleMax = maxScale;

                computeCoords();
                this.Region = new Rectangle(0, m_Y - 2, host.Width, m_Y + 2);
            }
Beispiel #4
0
            protected internal CandleBuySellElement(CandleBuySellView view, PlotPane host, CandleSample sample, int x, float minScale, float maxScale) : base(host)
            {
                m_View     = view;
                m_Sample   = sample;
                m_ScaleMin = minScale;
                m_ScaleMax = maxScale;

                computeCoords();
                var h = Math.Max(m_Lay_BuyHeight, m_Lay_SellHeight);

                this.Region = new Rectangle(x, (int)(host.Height / host.Zoom) - h, CandleView.BAR_WIDTH, h);
            }
Beispiel #5
0
            protected internal CandleElement(PlotPane host, CandleSample candle, int x, float minScale, float maxScale, bool bw) : base(host)
            {
                Candle = candle;

                //   m_Style = new Style(null, getBaseStyle());
                m_ScaleMin = minScale;
                m_ScaleMax = maxScale;
                m_Lay_X    = x;
                m_Lay_W    = CandleView.BAR_WIDTH - 1;

                computeCoords();
                this.Region = new Rectangle(m_Lay_X, m_Lay_Y, m_Lay_W, m_Lay_H);
                m_BW        = bw;
            }
Beispiel #6
0
        protected internal virtual void OnChartPaneMouseEvent(
            ChartPaneMouseEventArgs.MouseEventType et, PlotPane senderPane, MouseEventArgs mouse)
        {
            if (this.ChartPaneMouseEvent == null)
            {
                return;
            }

            var sample = MapXToSample(mouse.X);
            var value  = MapPaneYToValue(senderPane, mouse.Y);
            var args   = new ChartPaneMouseEventArgs(et, this, senderPane, mouse, sample, value);

            ChartPaneMouseEvent(this, args);
        }
Beispiel #7
0
 internal ChartPaneMouseEventArgs(MouseEventType type,
                                  TimeSeriesChart chart,
                                  PlotPane pane,
                                  MouseEventArgs mouse,
                                  ITimeSeriesSample sample,
                                  float value)
 {
     this.EventType  = type;
     this.Chart      = chart;
     this.Pane       = pane;
     this.MouseEvent = mouse;
     this.SampleAtX  = sample;
     this.ValueAtY   = value;
 }
Beispiel #8
0
        /// <summary>
        /// Maps mouse Y coordinate per pane's vertical scale value
        /// </summary>
        public float MapPaneYToValue(PlotPane pane, int y)
        {
            if (pane == null)
            {
                throw new WFormsException(StringConsts.ARGUMENT_ERROR +
                                          "MapPaneYToValue(pane==null)");
            }

            if (pane.Chart != this)
            {
                throw new WFormsException(StringConsts.ARGUMENT_ERROR +
                                          "MapPaneYToValue(pane.Chart!=this)");
            }

            var pp = (pane.VRulerMaxScale - pane.VRulerMinScale) /
                     (float)(pane.Height == 0 ? 1 : pane.Height);

            return(pane.VRulerMaxScale - (y * pp));
        }
Beispiel #9
0
        protected override Element MakeSeriesElement(TimeSeriesChart chart,
                                                     PlotPane pane,
                                                     IEnumerable <CandleSample> data,
                                                     int xStart,
                                                     float minScale,
                                                     float maxScale,
                                                     int maxSampleWidth,
                                                     out int fitSamplesCount)
        {
            var points = new List <Point>();


            var pxTotalHeight = (int)(pane.Height / pane.Zoom);
            var pxPrice       = (float)pxTotalHeight / (maxScale - minScale);

            fitSamplesCount = 0;
            var x      = xStart + (maxSampleWidth / 2);
            var xcutof = chart.VRulerPosition == VRulerPosition.Right ? pane.Width - 1 - chart.VRulerWidth : pane.Width;

            foreach (var candle in data)
            {
                var midPrice = MidLineType == Temporal.MidLineType.HighLow ?
                               (candle.LowPrice + ((candle.HighPrice - candle.LowPrice) / 2f)) :
                               (Math.Min(candle.OpenPrice, candle.ClosePrice) + (Math.Abs(candle.OpenPrice - candle.ClosePrice) / 2f));


                var y = pxTotalHeight - (int)((midPrice - minScale) * pxPrice);
                points.Add(new Point(x, y));


                x += maxSampleWidth;
                x++;
                if ((x * pane.Zoom) >= xcutof)
                {
                    break;
                }
                fitSamplesCount++;
            }

            return(new CandleMidLineElement(this, pane, points.ToArray()));
        }
Beispiel #10
0
 protected override Elements.Element MakeSampleElement(TimeSeriesChart chart, PlotPane pane, CandleSample sample, int x, float minScale, float maxScale)
 {
     return(null);
 }
Beispiel #11
0
 /// <summary>
 /// Override to build elements that render the data by adding drawable elements to the chart.
 /// Returns how many samples could fit
 /// </summary>
 public abstract int BuildElements(TimeSeriesChart chart, PlotPane pane, TimeSeries series, int maxSampleWidth);
Beispiel #12
0
 protected override Elements.Element MakeSampleElement(TimeSeriesChart chart, PlotPane pane, CandleSample sample, int x, float minScale, float maxScale)
 {
     return(new CandleBuySellElement(this, pane, sample, x, minScale, maxScale));
 }
Beispiel #13
0
        private void buildPanesCore()
        {
            if (m_Series == null || m_NeedRebuildPanes)
            {
                foreach (var ctl in m_Panes)
                {
                    m_ChartPanel.Controls.Remove(ctl);
                    ctl.Dispose();
                }

                m_Panes.Clear();

                //todo ubit shkalu X vnizy
                if (m_Series == null)
                {
                    return;
                }
            }

            var paneNames = m_Series.GetPaneNames().ToArray();

            //1. Delete panes that are no longer in series
            var toDelete = m_Panes.Select(p => p.Name).Except(paneNames);

            foreach (var pn in toDelete)
            {
                var ctl = m_Panes[pn];
                if (ctl != null)
                {
                    m_Panes.Unregister(ctl);
                    m_ChartPanel.Controls.Remove(ctl);
                    ctl.Dispose();
                }
            }

            var totPanes = paneNames.Length;
            var i        = 0;

            int      controlHeight = m_ChartPanel.Height;
            PlotPane lastPane      = null;

            //2. Add panes
            foreach (var pn in paneNames.Reverse())
            {
                var pane = m_Panes[pn];
                if (pane != null)
                {
                    pane.UpdateZoom(m_Zoom);
                    pane.DeleteAllElements(); //Clear the pane
                    if (lastPane == null)
                    {
                        lastPane = pane;
                    }
                    continue; //pane already exists
                }
                //Add pane
                pane         = new PlotPane(this, pn, m_Panes.Count + 1);
                pane.TabStop = false;
                pane.Cursor  = Cursors.Cross;
                pane.Height  = (int)(controlHeight * GetPaneVProportion(pn));
                SetPaneVProportion(pn, pane.Height / (float)(controlHeight > 0 ? controlHeight : 1));

                pane.Parent = m_ChartPanel;
                pane.UpdateZoom(m_Zoom);
                pane.Dock = DockStyle.Top;

                lastPane = pane;

                //ctl.BackColor = Color.HotPink;
                m_Panes.Register(pane);

                if (i < totPanes - 1)
                {
                    // Build splitter
                    //   pane.Dock = DockStyle.Top;
                    if (pane.m_Splitter != null)
                    {
                        continue;
                    }
                    pane.m_Splitter = new Splitter
                    {
                        Parent      = m_ChartPanel,
                        Dock        = DockStyle.Top,
                        Height      = SPLITTER_HEIGHT,
                        BackColor   = SplitterStyle.BGColor,
                        BorderStyle = BorderStyle.FixedSingle
                    };
                    //this.Controls.SetChildIndex(pane.m_Splitter, this.Controls.GetChildIndex(pane));
                    //todo Splitter moving - suspend update?
                    pane.m_Splitter.SplitterMoved += delegate(object sender, SplitterEventArgs e)
                    {
                        this.NotifySeriesChange(false);
                        int height = m_ChartPanel.Height;
                        foreach (var p in m_Panes)
                        {
                            SetPaneVProportion(p.Name, p.Height / (float)(height > 0 ? height : 1));
                        }
                    };
                }
            }
            // This must be the last Dock command
            if (lastPane != null)
            {
                lastPane.Dock = DockStyle.Fill;
            }
        }