Ejemplo n.º 1
0
 private void AddDataSource(DataSource initial_source, Color color)
 {
     float min_y = 0;
     float max_y = 0;
     if (is_sigmoid)
     {
         min_y = 0;
         max_y = 1;
     }
     if (is_hyperbolic)
     {
         min_y = -1;
         max_y = 1;
     }
     display.DataSources.Add(initial_source);
     initial_source.AutoScaleY = false;
     initial_source.SetGridDistanceY(100);
     initial_source.OnRenderYAxisLabel = RenderYLabel;
     initial_source.GraphColor = color;
     //            initial_source.AutoScaleY = true;
     initial_source.SetDisplayRangeY(min_y, max_y);
     initial_source.XAutoScaleOffset = 0;
 }
Ejemplo n.º 2
0
        private DataSource PredictionSource(int step)
        {
            double[] prediction = trainer.GetPrediction(train_data, step);
            DataSource prediction_source = new DataSource();
            prediction_source.Length = data.Length;

            float acc = 0;
            for (int i = 0; i < data.Length; i++)
            {
                if (i < network.InputCount() + step - 1)
                {
            //                    prediction_source.Samples[i].x = i;
            //                    prediction_source.Samples[i].y = 0.5f;
                    prediction_source.Samples[i].x = 0;
                    prediction_source.Samples[i].y = 0;
                }
                else if (i < network.InputCount() + prediction.Length + step - 1)
                {
                    prediction_source.Samples[i].x = i;
                    prediction_source.Samples[i].y = (float) prediction[i - network.InputCount() - step + 1];
            //                    acc += (float) normalizer.Denormalize(prediction[i - network.InputCount()]);
            //                    prediction_source.Samples[i].y = acc;
                }
                else
                {
                    prediction_source.Samples[i].x = 0;
                    prediction_source.Samples[i].y = 0;
                }
            }
            return prediction_source;
        }
Ejemplo n.º 3
0
 private String RenderYLabel(DataSource s, float  value)
 {
     return String.Format("{0:0.0}", value);
 }
Ejemplo n.º 4
0
 protected void CalcSinusFunction_3(DataSource ds, int idx,float time)
 {
     cPoint[] src = ds.Samples;
     for (int i = 0; i < src.Length; i++)
     {
         src[i].x = i;
         src[i].y = 200 + (float)((200 * Math.Sin((idx + 1) * (time + i * 100) / 8000.0)))+
                         +(float)((40  * Math.Sin((idx + 1) * (time + i * 200) / 2000.0)));
         /**
                     (float)( 4* Math.Sin( ((time + (i+8) * 100) / 900.0)))+
                     (float)(28 * Math.Sin(((time + (i + 8) * 100) / 290.0))); */
     }
 }
Ejemplo n.º 5
0
 protected void CalcSinusFunction_0(DataSource src, int idx)
 {
     for (int i = 0; i < src.Length; i++)
     {
         src.Samples[i].x = i;
         src.Samples[i].y = (float)(((float)200 * Math.Sin((idx + 1) *(i + 1.0) * 48 / src.Length)));
     }
 }
Ejemplo n.º 6
0
        protected void fillDataSource(DataSource src, int idx)
        {
            if (idx < 0 || idx > numGraphs - 1) return;
            for (int i = 0; i < src.Length; i++)
            {
                src.Samples[i].x = i;

                src.Samples[i].y = (float)Graphs[idx].valueCache[i];
            }
            src.OnRenderYAxisLabel = RenderYLabel;
        }
Ejemplo n.º 7
0
        private void DrawXLabels(Graphics g, DataSource source, List<int> marker_pos, float offset_x, float offset_y)
        {
            Color XLabColor = source.GraphColor;

            if (layout == LayoutMode.NORMAL || layout == LayoutMode.STACKED)
            {
                XLabColor = GraphBoxColor;
            }

            using (Brush b = new SolidBrush(XLabColor))
            {
                using (Pen pen = new Pen(b))
                {
                    pen.DashPattern = new float[] { 2, 2 };

                    if (DX != 0 && source.DY != 0)
                    {
                        if (source.Samples != null && source.Samples.Count > 1)
                        {
                            IList<cPoint> data = source.Samples;

                            float mult_y = source.CurGraphHeight / source.DY;
                            float mult_x = source.CurGraphWidth / DX;

                            float coff_x = off_X - starting_idx * mult_x;

                            if (source.AutoScaleX)
                            {
                                coff_x = off_X;     // avoid dragging in x-autoscale mode
                            }

                            foreach (int i in marker_pos)
                            {
                                int xi = (int)(data[i].x);

                                if (xi % grid_distance_x == 0)
                                {
                                    float x = data[i].x * mult_x   + coff_x;

                                    String value = "" + data[i].x;

                                    if (source.OnRenderXAxisLabel != null)
                                    {
                                        value = source.OnRenderXAxisLabel(source, i);
                                    }

                                    if (MoveMinorGrid == false)
                                    {
                                        g.DrawLine(pen, x, GraphCaptionLineHeight + offset_y + source.CurGraphHeight - 14, x, GraphCaptionLineHeight + offset_y + source.CurGraphHeight);
                                        g.DrawString(value, legendFont, b, new PointF((int)(0.5f + x + offset_x + 4), GraphCaptionLineHeight + offset_y + source.CurGraphHeight - 14));
                                    }
                                    else
                                    {
                                        SizeF dim = g.MeasureString(value, legendFont);
                                        g.DrawString(value, legendFont, b, new PointF((int)(0.5f + x + offset_x + 4 - dim.Width / 2), GraphCaptionLineHeight + offset_y + source.CurGraphHeight - 14));

                                    }
                                }
                            }
                        }
                    }

                }
            }
        }
Ejemplo n.º 8
0
        private List<int> DrawGraphCurve( Graphics g, DataSource source,  float offset_x, float offset_y )
        {
            List<int> marker_positions = new List<int>();

            if (DX != 0 && source.DY != 0)
            {
                List<Point> ps = new List<Point>();

                if (source.Samples != null && source.Samples.Count > 1)
                {

                    int DownSample = source.Downsampling;
                    IList<cPoint> data = source.Samples;
                    float mult_y = source.CurGraphHeight / source.DY;
                    float mult_x = source.CurGraphWidth / DX;
                    float coff_x = off_X - starting_idx * mult_x;

                    if (source.AutoScaleX)
                    {
                        coff_x = off_X;     // avoid dragging in x-autoscale mode
                    }

                    for (int i = 0; i < data.Count - 1; i += DownSample)
                    {
                        float x = data[i].x  * mult_x   + coff_x;
                        float y = data[i].y  * mult_y + source.off_Y;

                        int xi = (int)(data[i].x);

                        if (xi % grid_distance_x == 0)
                        {
                            if (x >= (0 - pad_xlabel) && x <= (source.CurGraphWidth + pad_xlabel))
                            {
                                marker_positions.Add(i);
                            }
                        }

                        if (x > 0 && x < (source.CurGraphWidth))
                        {
                            ps.Add(new Point((int)(x + offset_x+0.5f), (int)(y  + offset_y  + 0.5f)));
                        }
                        else if (x > source.CurGraphWidth)
                        {
                            break;
                        }
                    }

                    using (Pen p = new Pen(source.GraphColor))
                    {
                        if (ps.Count > 0)
                        {
                            g.DrawLines(p, ps.ToArray());
                        }
                    }
                }
            }
            return marker_positions;
        }
Ejemplo n.º 9
0
        private void initGraph()
        {
            CowabungaStrategy cowabunga = Backtester.Program.testCowabunga(@"C:\Users\Ralf\Desktop\talib_test\DAT_ASCII_EURGBP_M1_2015.csv");

            display.SetDisplayRangeX(0, 10);
            display.PanelLayout = PlotterGraphPaneEx.LayoutMode.NORMAL;

            DataSource closingPrices = new DataSource();
            closingPrices.Length = cowabunga.ticks.Length;
            //closingPrices.Samples = new cPoint[cowabunga.ticks.Length];
            closingPrices.Name = "Closing Prices";
            closingPrices.AutoScaleY = true;
            closingPrices.SetDisplayRangeY(0.6f, 0.8f);
            closingPrices.SetGridDistanceY(1);

            closingPrices.OnRenderXAxisLabel = RenderXLabel;
            closingPrices.OnRenderYAxisLabel = RenderYLabel;

            for (int i = 0; i < cowabunga.ticks.Length; i++)
            {
                Tick tick = cowabunga.ticks[i];

                closingPrices.Samples[i].x = i;
                closingPrices.Samples[i].y = (float)tick.closePrice;
            }

            DataSource ema75source = new DataSource();
            ema75source.Name = "EMA 75";

            //setupDataSource(ema75source, cowabunga.ema75);

            display.DataSources.Add(closingPrices);
            //display.DataSources.Add(ema75source);

            ResumeLayout();
            display.Refresh();
        }
Ejemplo n.º 10
0
        void GetRange(DataSource source, double offset_x, double offset_y, ref double yMax, ref double yMin)
        {
            if (source.Samples == null)
            {
            }
            int start = 0;

            yMax=int.MinValue;
            yMin=int.MaxValue;

            double mult_x = (source.CurGraphWidth - pad_label - pad_right - 1) / (DX);
            cPoint[] data = source.Samples;
            if (data == null)
                return;
            int nopoints = (int)((source.CurGraphWidth - pad_label + pad_right - 1) / mult_x);

            if (scroll >= (ScrollBarMax - 10))
            {
                if (nopoints < data.Length)
                {
                    start = data.Length - nopoints;
                    double Maxx = data[data.Length - 1].x;
                    double MinX = Maxx - DX;
                    if (XD0 > MinX)
                        MinX = XD0;
                    while (start >= 1 && (data[start - 1].x) >= MinX)
                    {
                        start--;
                    }
                }
                else
                    start = 0;
            }
            else
            {
                double xRange = data[data.Length - 1].x - data[0].x;
                double startx = data[0].x + scroll * xRange / ScrollBarMax;
                double Maxx = data[data.Length - 1].x;
                double MinX = Maxx - DX;
                if (XD0 > MinX)
                    MinX = XD0;
                if (startx >= MinX)
                {
                    start = (int)data.Length - 1;
                    while (start >= 1 && (data[start - 1].x) >= MinX)
                    {
                        start--;
                    }
                }
                else
                {
                    while (start <= data.Length - 2 && (data[start + 1].x) < startx)
                    {
                        start++;
                    }
                }
            }
            if (source.AutoScaleY)
            {
                for (int counter = start; counter < data.Length; counter++)
                {
                    double x = ((data[counter].x - data[start].x)) /*counter*/ * mult_x;
                    if (x > source.CurGraphWidth)
                    {
                        break;
                    }
                    if (data[counter].y < yMin)
                        yMin = data[counter].y;
                    if (data[counter].y > yMax)
                        yMax = data[counter].y;
                }
            }
            else
            {
                yMax = source.YMax;
                yMin = source.YMin;
            }
            source.StartIndex = start;
        }
Ejemplo n.º 11
0
        private void DrawXLabels(Graphics g, DataSource source, List<int> marker_pos, float offset_x, float offset_y)
        {
            lock (obj)
            {
                if (!this.Enabled)
                    return;
                SizeF dim = new SizeF();
                Color XLabColor = source.GraphColor;
                if (layout == LayoutMode.NORMAL || layout == LayoutMode.STACKED)
                {
                    XLabColor = GraphBoxColor;
                }
                //using (Brush b = new SolidBrush(XLabColor))
                Color color = this.Enabled ? Color.Black : Color.Gray;
                using (Brush b = new SolidBrush(color))
                {
                    using (Pen pen = new Pen(b))
                    {
                        pen.DashPattern = new float[] { 2, 2 };
                        using (Font axisFont = new Font(FontFamily.GenericSansSerif, 10.0f, FontStyle.Bold))
                        {
                            dim = g.MeasureString(XaxisName, axisFont);
                            g.DrawString(XaxisName, axisFont, b, new PointF((float)(0.5f + source.CurGraphWidth + pad_left + pad_label - dim.Width) / 2,
                                (float)(this.Height - dim.Height)));
                        }
                        if (DX != 0 && source.DY != 0)
                        {
                            if (source.Samples != null && source.Samples.Length > 1)
                            {
                                cPoint[] data = source.Samples;
                                double mult_y = source.CurGraphHeight / source.DY;
                                double mult_x = (source.CurGraphWidth - pad_label - pad_right - 1) / (DX);
                                if ((source.CurGraphWidth - pad_label - pad_right - 1) % DX != 0 && (source.CurGraphWidth - pad_label - pad_right - 1) % DX < (source.CurGraphWidth - pad_label - pad_right - 1) / DX / 2)
                                {
                                    //mult_x = (source.CurGraphWidth - pad_label + pad_right - 1) / (DX + grid_distance_x);
                                }

                                double coff_x = off_X - starting_idx * mult_x;
                                if (source.AutoScaleX)
                                {
                                    coff_x = off_X;     // avoid dragging in x-autoscale mode
                                }
                                double counter = XD0;
                                coff_x = 0;

                                double xmin = ((int)(Min_X / grid_distance_x)) * grid_distance_x;
                                while (counter<XD1)
                                {
                                    {
                                        double x = ((xmin - Min_X)) /*counter*/ * mult_x + coff_x;
                                        /*if (scroll > 9990)
                                        {

                                            x = counter * mult_x;
                                        } */
                                        String value = "" + string.Format("{0:0.#}",xmin);
                                        if (source.OnRenderXAxisLabel != null)
                                        {
                                            //value = source.OnRenderXAxisLabel(source, i);
                                            value = xmin.ToString();
                                        }
                                        //Console.WriteLine("Min:" + Min_X + " Value: " + value + " x:" + x + " Counter:" + counter);
                                        if (MoveMinorGrid == false)
                                        {
                                            g.DrawLine(pen, (float)x, (float)(GraphCaptionLineHeight + offset_y + source.CurGraphHeight - 14), (float)x, (float)(GraphCaptionLineHeight + offset_y + source.CurGraphHeight));
                                            g.DrawString(value, legendFont, b, new PointF((int)(0.5f + x + offset_x + 4), (float)(GraphCaptionLineHeight + offset_y + source.CurGraphHeight - 14)));
                                        }
                                        else
                                        {
                                            dim = g.MeasureString(value, legendFont);
                                            if (counter >= 0 && value!="0")
                                                g.DrawString(value, legendFont, b, new PointF((int)(0.5f + x + offset_x - dim.Width / 2), (float)(GraphCaptionLineHeight + offset_y + source.CurGraphHeight - 14)));
                                            else
                                                if (value != "0")
                                                {
                                                    g.DrawString(value, legendFont, b, new PointF((int)(x + offset_x), (float)(GraphCaptionLineHeight + offset_y + source.CurGraphHeight - 14)));
                                                }
                                                    //if (int.Parse(value) == (int)XD1)
                                            //{
                                            //    Xco_ordForMiddleLine = ((int)(x + offset_x));
                                            //}
                                        }
                                    }
                                    xmin += grid_distance_x;
                                    counter += grid_distance_x;
                                }

                                }
            #if TEST
                                foreach (int i in marker_pos)
                                {
                                    double xi = (data[i].x);
                                    double modulo = xi % grid_distance_x;
                                    if (modulo <= 0.000001f || (xi / grid_distance_x * grid_distance_x) == xi)
                                    {
                                        double x = data[i].x * mult_x + coff_x;
                                        x = ((data[i].x - Min_X)) /*counter*/ * mult_x + coff_x;
                                        /*if (scroll > 9990)
                                        {

                                            x = counter * mult_x;
                                        } */
                                        String value = "" + data[i].x;
                                        if (source.OnRenderXAxisLabel != null)
                                        {
                                            value = source.OnRenderXAxisLabel(source, i);
                                        }
                                        Console.WriteLine("Value: " + value + " x:" + x + " grid_distance_x:" + grid_distance_x);
                                        if (MoveMinorGrid == false)
                                        {
                                            g.DrawLine(pen, (float)x, (float)(GraphCaptionLineHeight + offset_y + source.CurGraphHeight - 14), (float)x, (float)(GraphCaptionLineHeight + offset_y + source.CurGraphHeight));
                                            g.DrawString(value, legendFont, b, new PointF((int)(0.5f + x + offset_x + 4), (float)(GraphCaptionLineHeight + offset_y + source.CurGraphHeight - 14)));
                                        }
                                        else
                                        {
                                            dim = g.MeasureString(value, legendFont);
                                            if (counter > 0)
                                                g.DrawString(value, legendFont, b, new PointF((int)(0.5f + x + offset_x - dim.Width / 2), (float)(GraphCaptionLineHeight + offset_y + source.CurGraphHeight - 14)));
                                            else
                                                g.DrawString(value, legendFont, b, new PointF((int)(x + offset_x), (float)(GraphCaptionLineHeight + offset_y + source.CurGraphHeight - 14)));
                                        }
                                        counter++;
                                    }
                                }
                            }
            #endif

                        }
                    }
                }
        }
Ejemplo n.º 12
0
        private List<int> DrawGraphCurve(Graphics g, DataSource source, double offset_x, double offset_y)
        {
            List<int> marker_positions = new List<int>();
            int maxYCordinate = (int)(1 + source.CurGraphHeight + GraphCaptionLineHeight / 2 + 0.5f);
            if (DX != 0 && source.DY != 0)
            {
                List<Point> ps = new List<Point>();
                if (source.Samples != null && source.Samples.Length > 1)
                {
                    int DownSample = source.Downsampling;
                    cPoint[] data = source.Samples;
                    double mult_y = source.CurGraphHeight / source.DY;
                    //float mult_x = source.CurGraphWidth / DX;
                    double mult_x = (source.CurGraphWidth - pad_label - pad_right - 1) / (DX);
                    if ((source.CurGraphWidth - pad_label - pad_right - 1) % DX != 0 && (source.CurGraphWidth - pad_label - pad_right - 1) % DX < (source.CurGraphWidth - pad_label - pad_right - 1) / DX / 2)
                    {
                        //mult_x = (source.CurGraphWidth - pad_label + pad_right - 1) / (DX + grid_distance_x);
                    }

                    double coff_x = off_X - starting_idx * mult_x;
                    if (source.AutoScaleX)
                    {
                        coff_x = off_X;     // avoid dragging in x-autoscale mode
                    }
                    else
                        coff_x = 0;

                    int counter = 0;
                    double modulo = 0;

                    Pen pen12 = new Pen(Color.Black,1.0f);
                    g.DrawLine(pen12, new PointF((int)offset_x, (int)(source.off_Y + offset_y)), new PointF((int)(offset_x + source.CurGraphWidth - pad_label + pad_right - 0.5f), (int)(source.off_Y+offset_y)));
                    for (int i =source.StartIndex; i < data.Length; i += DownSample)
                    {
                        if (Min_X >= MAX_X)
                            Min_X = data[i].x;
                        double x = ((data[i].x - Min_X)) /*counter*/ * mult_x + coff_x;
                        double y = data[i].y * mult_y + source.off_Y;
                        double xi = (data[i].x);

                        modulo =(xi % grid_distance_x);

                        if (modulo <= 0.00001 || (xi > grid_distance_x && Convert.ToDecimal(((int)Convert.ToDecimal(xi / grid_distance_x)) * grid_distance_x) == Convert.ToDecimal(xi)))
                        {
                            if (x >= 0 && x <= (source.CurGraphWidth))
                            {
                                marker_positions.Add(i);
                            }
                        }

                        if (x >= 0 && x < (source.CurGraphWidth))
                        {
                            ps.Add(new Point((int)(x + offset_x + 0f), (int)(y + offset_y + 0f)));
                        }
                        else if (x > source.CurGraphWidth)
                        {
                            break;
                        }
                        else
                        {
                        }
                        counter++;
                    }

                    using (Pen pen = new Pen(source.GraphColor,1.0f))
                    {
                        if (ps.Count > 1)
                        {
                            Point[] gPoints = ps.ToArray();
                            for (int iterator = 0; iterator < gPoints.Length - 1; iterator++)
                            {
                                Point point1 = gPoints[iterator];
                                Point point2 = gPoints[iterator + 1];
                                float slope = 0;
                                if ((maxYCordinate < point1.Y))
                                {
                                    if ((point2.X - point1.X) == 0)
                                        slope = 0;
                                    else
                                        slope = (point2.Y - point1.Y) / (point2.X - point1.X);
                                    float c = point2.Y - (slope * point2.X);
                                    float reqX = (maxYCordinate - c) / slope;
                                    point1.X = (int)reqX;
                                    point1.Y = maxYCordinate;
                                }
                                if ((maxYCordinate < point2.Y))
                                {
                                    if ((point2.X - point1.X) == 0)
                                        slope = 0;
                                    else
                                        slope = (point2.Y - point1.Y) / (point2.X - point1.X);
                                    float c = point2.Y - (slope * point2.X);
                                    float reqX = (maxYCordinate - c) / slope;
                                    point2.X = (int)reqX;
                                    point2.Y = maxYCordinate;
                                }
                                if (point1.X < 0 || point2.X < 0)
                                    continue;
                                if (!(maxYCordinate < point1.Y || maxYCordinate < point2.Y))
                                   g.DrawLine(pen, point1, point2);
                            }
                            // g.DrawLines(p, ps.ToArray());
                        }
                    }
                }
            }

            return marker_positions;
        }
        /*
        protected void CalcSinusFunction_0(DataSource src, int idx)
        {
            for (int i = 0; i < src.Length; i++)
            {
                src.Samples[i].x = i;
                src.Samples[i].y = (float)(((float)200 * Math.Sin((idx + 1) * (i + 1.0) * 48 / src.Length)));
            }
        }
        protected void CalcSinusFunction_1(DataSource src, int idx)
        {
            for (int i = 0; i < src.Length; i++)
            {
                src.Samples[i].x = i;

                src.Samples[i].y = (float)(((float)20 *
                                            Math.Sin(20 * (idx + 1) * (i + 1) * 3.141592 / src.Length)) *
                                            Math.Sin(40 * (idx + 1) * (i + 1) * 3.141592 / src.Length)) +
                                            (float)(((float)200 *
                                            Math.Sin(200 * (idx + 1) * (i + 1) * 3.141592 / src.Length)));
            }
            src.OnRenderYAxisLabel = RenderYLabel;
        }
        protected void CalcSinusFunction_2(DataSource src, int idx)
        {
            for (int i = 0; i < src.Length; i++)
            {
                src.Samples[i].x = i;

                src.Samples[i].y = (float)(((float)20 *
                                            Math.Sin(40 * (idx + 1) * (i + 1) * 3.141592 / src.Length)) *
                                            Math.Sin(160 * (idx + 1) * (i + 1) * 3.141592 / src.Length)) +
                                            (float)(((float)200 *
                                            Math.Sin(4 * (idx + 1) * (i + 1) * 3.141592 / src.Length)));
            }
            src.OnRenderYAxisLabel = RenderYLabel;
        }
        protected void CalcSinusFunction_3(DataSource ds, int idx, float time)
        {
            cPoint[] src = ds.Samples;
            for (int i = 0; i < src.Length; i++)
            {
                src[i].x = i;
                src[i].y = 200 + (float)((200 * Math.Sin((idx + 1) * (time + i * 100) / 8000.0))) +
                                +(float)((40 * Math.Sin((idx + 1) * (time + i * 200) / 2000.0)));

                            (float)( 4* Math.Sin( ((time + (i+8) * 100) / 900.0)))+
                            (float)(28 * Math.Sin(((time + (i + 8) * 100) / 290.0)));
            }

        }
        */
        protected void myfunc(DataSource ds, int idx)
        {
            cPoint[] src = ds.Samples;
            for (int i = 0; i < src.Length; i++)
            {
                src[i].x = i;
                //пример из базы как будто взят и помешщен в листбокс
                src[i].y = (float)Convert.ToInt32(listBox1.Items[i]);
            }
        }
Ejemplo n.º 14
0
        private DataSource TestSource(int step)
        {
            double[] prediction_on_test = trainer.GetPrediction(test_data, step);
            DataSource prediction_source = new DataSource();
            prediction_source.Length = data.Length;

            float acc = 0;
            for (int i = 0; i < data.Length; i++)
            {
                if (i < network.InputCount() + train_data.Length + step - 1)
                {
                    prediction_source.Samples[i].x = 0;
                    prediction_source.Samples[i].y = 0;
                }
                else
                {
                    prediction_source.Samples[i].x = i;
                    prediction_source.Samples[i].y = (float)prediction_on_test[i - network.InputCount() - train_data.Length - step + 1];
                }
            }
            return prediction_source;
        }
Ejemplo n.º 15
0
        private void DrawGraphBox(  Graphics g, DataSource source,
            float offset_x,
            float offset_y,
            float GraphCaptionLineHeight)
        {
            using (Pen p2 = new Pen(GraphBoxColor))
            {
                g.DrawLine(p2, new Point((int)(offset_x + 0.5f), (int)(offset_y + 0.5f)),
                              new Point((int)(offset_x + source.CurGraphWidth - 0.5f), (int)(offset_y + 0.5f)));

                g.DrawLine(p2, new Point((int)(offset_x + source.CurGraphWidth - 0.5f), (int)(offset_y + 0.5f)),
                             new Point((int)(offset_x + source.CurGraphWidth - 0.5f), (int)(offset_y + source.CurGraphHeight + GraphCaptionLineHeight / 2 + 0.5f)));

                g.DrawLine(p2, new Point((int)(offset_x + source.CurGraphWidth - 0.5f), (int)(offset_y + source.CurGraphHeight + GraphCaptionLineHeight / 2 + 0.5f)),
                           new Point((int)(offset_x + 0.5f), (int)(offset_y + source.CurGraphHeight + GraphCaptionLineHeight / 2 + 0.5f)));

                g.DrawLine(p2, new Point((int)(offset_x + 0.5f), (int)(offset_y + source.CurGraphHeight + GraphCaptionLineHeight / 2 + 0.5f)),
                          new Point((int)(offset_x + 0.5f), (int)(offset_y + 0.5f)));
            }
        }
Ejemplo n.º 16
0
        private void setupDataSource(DataSource source, double[] data)
        {
            source.Samples = new cPoint[data.Length];
            for (int i = 0; i < data.Length; i++)
            {
                double d = data[i];

                source.Samples[i].x = i;
                source.Samples[i].y = (float)data[i];
                source.OnRenderYAxisLabel = RenderYLabel;
                source.OnRenderXAxisLabel = RenderXLabel;
            }

            source.AutoScaleY = true;
        }
Ejemplo n.º 17
0
        private void DrawGraphCaption(Graphics g, DataSource source, List<int> marker_pos, float offset_x, float offset_y)
        {
            using (Brush b = new SolidBrush(source.GraphColor))
            {
                using (Pen pen = new Pen(b))
                {
                    pen.DashPattern = new float[] { 2, 2 };

                    g.DrawString(source.Name, legendFont, b, new PointF(offset_x + 12, offset_y + 2));

                }
            }
        }
Ejemplo n.º 18
0
        void IspisiPodatke(DataSource src, int idx, List<double> vrijeme, List<double> napon)
        {
            // for (int i = 0; i < src.Length; i++)

            double granica = vrijeme.Count;
            if (napon.Count < granica)
                granica = napon.Count;

            for (int i = 0; i < granica; i++)
            {
                src.Samples[i].x = (float)vrijeme[i];
                src.Samples[i].y = (float)napon[i];
            }
            src.OnRenderYAxisLabel = RenderYLabel;
        }
Ejemplo n.º 19
0
        private void DrawGrid( Graphics g, DataSource source,  float CurrOffX, float CurOffY )
        {
            int Idx = 0;
            float mult_x = source.CurGraphWidth / DX;
            float coff_x = off_X - starting_idx * mult_x;

            if (source.AutoScaleX)
            {
            coff_x = off_X;     // avoid dragging in x-autoscale mode
            }

            Color CurGridColor = MajorGridColor;
            Color CurMinGridClor = MinorGridColor;

            if (layout == LayoutMode.NORMAL && source.AutoScaleY)
            {
            CurGridColor = source.GraphColor;
            CurMinGridClor = source.GraphColor;
            }

            using (Pen minorGridPen = new Pen(CurMinGridClor))
            {
               minorGridPen.DashPattern = MinorGridPattern;
               minorGridPen.DashStyle = MinorGridDashStyle;

               using (Pen p2 = new Pen(CurGridColor))
               {
                p2.DashPattern = MajorGridPattern;
                p2.DashStyle = MajorGridDashStyle;

                if (DX != 0)
                {
                    while (true)
                    {
                        float x = Idx * grid_distance_x * source.CurGraphWidth / DX + grid_off_x * source.CurGraphWidth / DX;

                        if (MoveMinorGrid)
                        {
                            x += coff_x;
                        }

                        if (x > 0 && x < source.CurGraphWidth)
                        {
                            g.DrawLine(minorGridPen, new Point((int)(x + CurrOffX - 0.5f), (int)(CurOffY)),
                                                     new Point((int)(x + CurrOffX - 0.5f), (int)(CurOffY + source.CurGraphHeight)));
                        }
                        if (x > source.CurGraphWidth)
                        {
                            break;
                        }

                        Idx++;
                    }
                }

                if (source.DY != 0)
                {
                    float y0 = (float)(source.grid_off_y * source.CurGraphHeight / source.DY + source.off_Y);

                    // draw horizontal zero grid lines
                    g.DrawLine(p2, new Point((int)CurrOffX, (int)(CurOffY + y0 + 0.5f)), new Point((int)(CurrOffX + source.CurGraphWidth + 0.5f), (int)(CurOffY + y0 + 0.5f)));

                    // draw horizontal grid lines
                    for (Idx = (int)(source.grid_off_y);Idx > (int)(source.YD0 ); Idx -= (int)source.grid_distance_y)
                    {
                        float y = (float)(Idx * source.CurGraphHeight) / source.DY + source.off_Y;

                        if (y >= 0 && y < source.CurGraphHeight)
                        {
                            g.DrawLine(minorGridPen,
                                        new Point((int)CurrOffX, (int)(CurOffY + y + 0.5f)),
                                        new Point((int)(CurrOffX + source.CurGraphWidth + 0.5f), (int)(0.5f + CurOffY + y)));
                        }
                    }

                    // draw horizontal grid lines
                    for (Idx = (int)(source.grid_off_y); Idx < (int)(source.YD1  ); Idx += (int)source.grid_distance_y)
                    {
                        float y = (float)Idx * source.CurGraphHeight / source.DY + source.off_Y;

                        if (y >= 0 && y < source.CurGraphHeight)
                        {
                            g.DrawLine(minorGridPen,
                                       new Point((int)CurrOffX, (int)(CurOffY + y + 0.5f)),
                                       new Point((int)(CurrOffX + source.CurGraphWidth + 0.5f), (int)(0.5f + CurOffY + y)));
                        }
                    }
                }
            }
            }
        }
Ejemplo n.º 20
0
 private String RenderXLabel(DataSource s, int idx)
 {
     if (s.AutoScaleX)
     {
         //if (idx % 2 == 0)
         {
             double Value = (s.Samples[idx].x);
             return "" + Value;
         }
         //return "";
     }
     else
     {
         double Value = (s.Samples[idx].x);
         return "" + Value;
     }
 }
Ejemplo n.º 21
0
        private void DrawYLabels(Graphics g, DataSource source, List<int> marker_pos,  float offset_x,  float offset_y )
        {
            using (Brush b = new SolidBrush(source.GraphColor))
            {
                using (Pen pen = new Pen(b))
                {
                    pen.DashPattern = new float[] { 2, 2 };

                    // draw labels for horizontal lines
                    if (source.DY != 0)
                    {
                        float Idx = 0;

                        float y0 = (float)(source.grid_off_y * source.CurGraphHeight / source.DY + source.off_Y);

                        String value = "" + Idx;

                        if (source.OnRenderYAxisLabel != null)
                        {
                            value = source.OnRenderYAxisLabel(source, Idx);
                        }

                        SizeF dim = g.MeasureString(value, legendFont);
                        g.DrawString(value, legendFont, b, new PointF((int)offset_x - dim.Width, (int)(offset_y + y0 + 0.5f + dim.Height / 2)));

                        float GridDistY = source.grid_distance_y;

                        if (source.AutoScaleY)
                        {
                            // calculate a matching grid distance
                            GridDistY = - Utilities.MostSignificantDigit(source.DY );

                            if (GridDistY == 0)
                            {
                                GridDistY =  source.grid_distance_y;

                            }
                        }

                        for (Idx =  (source.grid_off_y); Idx >  (source.Cur_YD0); Idx -=  GridDistY)
                        {
                            if (Idx != 0)
                            {
                                float y1 = (float)((Idx) * source.CurGraphHeight) / source.DY + source.off_Y;

                                value = "" + (Idx);

                                if (source.OnRenderYAxisLabel != null)
                                {
                                    value = source.OnRenderYAxisLabel(source, Idx);
                                }

                                dim = g.MeasureString(value, legendFont);
                                g.DrawString(value, legendFont, b, new PointF((int)offset_x - dim.Width, (int)(offset_y + y1 + 0.5f + dim.Height / 2)));
                            }
                        }

                        for (Idx =  (source.grid_off_y); Idx <  (source.Cur_YD1); Idx +=  GridDistY)
                        {
                            if (Idx != 0)
                            {
                                float y2 = (float)((Idx) * source.CurGraphHeight) / source.DY + source.off_Y;

                                value = "" + (Idx);

                                if (source.OnRenderYAxisLabel != null)
                                {
                                    value = source.OnRenderYAxisLabel(source, Idx);
                                }

                                dim = g.MeasureString(value, legendFont);
                                g.DrawString(value, legendFont, b, new PointF((int)offset_x - dim.Width, (int)(offset_y + y2 + 0.5f + dim.Height / 2)));
                            }
                        }
                    }
                }
            }
        }
        // ------------------------------------------------------------------------------------------------------
        private void _addChannelGraph(EEGChannelBuffer buf)
        {
            DataSource ds = new DataSource();
            display.DataSources.Add(ds);
            ds.OnRenderXAxisLabel += _onRenderXLabel;
            ds.OnRenderYAxisLabel = _onRenderYLabel;
            ds.Name = buf.Name;
            ds.Length = (int)buf.Length;
            ds.XAutoScaleOffset = 0;

            ds.AutoScaleX = true;
            ds.AutoScaleY = false;

            ds.SetDisplayRangeY(-300, 300);
            ds.SetGridDistanceY(100);

            channelGraphs.Add(new ChannelGraph(ds, buf));
        }
Ejemplo n.º 23
0
 private String RenderXLabel(DataSource s, int idx)
 {
     return String.Format("{0}", (int)s.Samples[idx].x);
 }
 // ------------------------------------------------------------------------------------------------------
 private String _onRenderXLabel(DataSource s, int idx)
 {
     //            return "Time";
     return plotName;
 }
Ejemplo n.º 25
0
        protected void CalcSinusFunction_2(DataSource src, int idx)
        {
            for (int i = 0; i < src.Length; i++)
            {
                src.Samples[i].x = i;

                src.Samples[i].y = (float)(((float)20 *
                                            Math.Sin(40 * (idx + 1) * (i + 1) * Math.PI / src.Length)) *
                                            Math.Sin(160 * (idx + 1) * (i + 1) * Math.PI / src.Length)) +
                                            (float)(((float)200 *
                                            Math.Sin(4 * (idx + 1) * (i + 1) * Math.PI / src.Length)));
            }
            src.OnRenderYAxisLabel = RenderYLabel;
        }
 // ------------------------------------------------------------------------------------------------------
 private void _updateDataSource(DataSource ds, EEGChannelBuffer buf)
 {
     cPoint[] dest = ds.Samples;
     for (uint i = 0; i < buf.BufferSize; i++)
     {
         EEGChannelBuffer.sample s = buf.getSample(i);
         dest[i].x = s.time;
         dest[i].y = s.value;
     }
 }
Ejemplo n.º 27
0
 private String RenderXLabel(DataSource s, int idx)
 {
     if (s.AutoScaleX)
     {
         //if (idx % 2 == 0)
         {
             int Value = (int)(s.Samples[idx].x );
             return "" + Value;
         }
         return "";
     }
     else
     {
         int Value = (int)(s.Samples[idx].x / 200);
         String Label = "" + Value + "\"";
         return Label;
     }
 }
 public ChannelGraph(DataSource ds, EEGChannelBuffer bf)
 {
     EEGChannelBuffer = bf;
     dataSource = ds;
 }
        /// <summary>
        /// Constructor
        /// </summary>
        public NeuralNetworkAnalysisForm()
        {
            InitializeComponent();

            this.actualDS = new DataSource();
            this.predictedDS = new DataSource();
            this.validationDS = new DataSource();

            this.actualDS.Name = "Actual";
            this.predictedDS.Name = "Predicted";
            this.validationDS.Name = "Validation";

            this.actualDS.GraphColor = Color.Blue;
            this.predictedDS.GraphColor = Color.Red;
            this.validationDS.GraphColor = Color.Green;

            seriesGraph.Sources.Add(this.actualDS);
            seriesGraph.Sources.Add(this.predictedDS);
            seriesGraph.Sources.Add(this.validationDS);

            seriesGraph.BgndColorTop = Color.White;
            seriesGraph.BgndColorBot = Color.FromArgb(203, 255, 203);
            seriesGraph.MinorGridColor= Color.Green;
            seriesGraph.MajorGridColor= Color.Green;

            this.updateSettings();
        }
Ejemplo n.º 30
0
 private DataSource InitialSource()
 {
     DataSource initial_source;
     initial_source = new DataSource();
     initial_source.Length = data.Length;
     for (int i = 0; i < data.Length; i++)
     {
         initial_source.Samples[i].x = i;
         initial_source.Samples[i].y = (float) data[i];
     }
     return initial_source;
 }