private void DrawXLabelsForAutoScaleX(Graphics g, DataSource source, List <Int32> marker_data, float offset_x, float offset_y)
        {
            Color XLabColor = source.GraphColor;

            using (Brush brush = new SolidBrush(Color.Cyan))
            {
                using (Pen pen = new Pen(brush))
                {
                    pen.DashPattern = MajorGridPattern;

                    if (DX != 0 && source.DY != 0)
                    {
                        if (source.Samples != null && source.Samples.Count > 1)
                        {
                            float mult_y = source.CurGraphHeight / source.DY;
                            float mult_x = source.CurGraphWidth / DX;
                            off_X = 0;
                            float coff_x = off_X - starting_idx * mult_x;

                            if (source.AutoScaleX)
                            {
                                coff_x = off_X;     // avoid dragging in x-autoscale mode
                            }
                            float offset_xCor   = -3.0f + offset_x + 4;
                            float unknownOffset = -12;// -14;
                            float offset_yCor   = GraphCaptionLineHeight + offset_y + source.CurGraphHeight + unknownOffset;
                            foreach (Int32 XData in marker_data)
                            {
                                float  x     = XData * mult_x + coff_x;
                                String value = "" + XData;

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

                                /// TODO: find out how to calculate this offset. Must be padding + something else

                                SizeF dim = g.MeasureString(value, legendFont);
                                g.DrawString(value, legendFont, brush,
                                             new PointF((Int32)(x + offset_xCor - dim.Width / 2), offset_yCor));
                            }
                        }
                    }
                }
            }
        }
Example #2
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));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        /*
         *
         *
         **/
        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 brush = new SolidBrush(XLabColor))
            {
                using (Pen pen = new Pen(brush))
                {
                    pen.DashPattern = MajorGridPattern;

                    if (DX != 0 && source.DY != 0)
                    {
                        if (source.Samples != null && source.Samples.Length > 1)
                        {
                            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);
                                    }

                                    /// TODO: find out how to calculate this offset. Must be padding + something else
                                    float unknownOffset = -14;// -14;

                                    if (MoveMinorGrid == false)
                                    {
                                        g.DrawLine(pen, x, offset_y + GraphCaptionLineHeight + source.CurGraphHeight + unknownOffset,
                                                   x, offset_y + GraphCaptionLineHeight + source.CurGraphHeight);

                                        g.DrawString(value, legendFont, brush,
                                                     new PointF((int)(0.5f + x + offset_x + 4),
                                                                GraphCaptionLineHeight + offset_y + source.CurGraphHeight + unknownOffset));
                                    }
                                    else
                                    {
                                        SizeF dim = g.MeasureString(value, legendFont);
                                        g.DrawString(value, legendFont, brush,
                                                     new PointF((int)(0.5f + x + offset_x + 4 - dim.Width / 2),
                                                                GraphCaptionLineHeight + offset_y + source.CurGraphHeight + unknownOffset));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #4
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));

                                    }
                                }
                            }
                        }
                    }

                }
            }
        }
        private List <Int32> DrawGraphCurve(Graphics g, DataSource source, float offset_x, float offset_y)
        {
            List <Int32> marker_positions = new List <Int32>();

            if (DX != 0 && source.DY != 0)
            {
                if (source.Samples != null && source.Samples.Count > 1)
                {
                    List <Point> ps         = new List <Point>();
                    Int32        DownSample = source.Downsampling;
                    float        mult_y     = source.CurGraphHeight / source.DY;
                    float        mult_x     = source.CurGraphWidth / DX;
                    off_X = 0;
                    float coff_x = off_X - starting_idx * mult_x;
                    if (source.AutoScaleX)
                    {
                        coff_x = off_X;     // avoid dragging in x-autoscale mode
                    }
                    Boolean firstPoint = true;
                    //for gain time
                    float endGraph         = source.CurGraphWidth + xLabelAreaheight;
                    float CurGraphWidthCor = source.CurGraphWidth - 1.0f;
                    float offset_xCor      = offset_x + 1.0f;
                    float offset_xCorM     = offset_x - 1.0f;
                    float offset_yCor      = offset_y + 0.0f;
                    for (Int32 i = 0; i < source.Samples.Count - 1; i += DownSample)
                    {
                        float x = source.Samples[i].X * mult_x + coff_x;
                        float y = source.Samples[i].Y * mult_y + source.off_Y;
                        if (source.AutoScaleX)
                        {
                            if ((Int32)(source.Samples[i].X) % grid_distance_x == 0)
                            {
                                if (x >= xLabelAreaheight && x < endGraph)
                                {
                                    marker_positions.Add(i);
                                }
                            }
                        }
                        if (x >= 0 && x < CurGraphWidthCor)  //
                        {
                            if (firstPoint)
                            {
                                float y1 = source.Samples[i].Y * mult_y + source.off_Y;
                                ps.Add(new Point((Int32)offset_xCor, (Int32)(y1 + offset_yCor))); //
                                firstPoint = false;
                            }
                            ps.Add(new Point((Int32)(x + offset_xCor), (Int32)(y + offset_yCor))); //
                        }
                        else if (x >= CurGraphWidthCor)                                            //
                        {
                            if (i > 0)
                            {
                                y = source.Samples[i - 1].Y * mult_y + source.off_Y;
                                ps.Add(new Point((Int32)(source.CurGraphWidth + offset_xCorM), (Int32)(y + offset_yCor))); //
                            }
                            break;
                        }
                    }

                    using (Pen p = new Pen(source.GraphColor))
                    {
                        if (ps.Count > 2)
                        {
                            if (ps.Count < (source.CurGraphWidth / 20))
                            {
                                endZoom += 1;
                                Int32 axeY = (Int32)(offset_y + source.CurGraphHeight / 2);   // (Int32)(((source.Cur_YD1 - source.Cur_YD0) / 2) + offset_yCor);
                                using (Brush brush = new SolidBrush(Color.Cyan))
                                {
                                    System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
                                    drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
                                    float memoPsX = (ps[2].X / mult_x + coff_x - offset_x);
                                    for (Int32 i = 2; i < ps.Count - 2; i++)  //reject first and last no good value
                                    {
                                        float currentX = (ps[i + 1].X / mult_x + coff_x - offset_x);
                                        Int32 deltaX   = (Int32)(currentX - memoPsX);
                                        memoPsX = currentX;
                                        if (deltaX > 0)
                                        {
                                            String value = "";
                                            if (source.OnRenderXAxisLabel != null)
                                            {
                                                value = source.OnRenderXAxisLabel(deltaX);
                                            }
                                            g.DrawString(value, legendFont, brush, new PointF(ps[i].X + 1, axeY), drawFormat);
                                        }
                                    }
                                }
                            }

                            g.DrawLines(p, ps.ToArray());
                        }
                        else
                        {
                            endZoom += 1;
                        }
                    }
                    ps.Clear();
                    ps = null;
                }
            }

            return(marker_positions);  //if AutoScaleX:marker_positions else marker_positionsForAutoScaleX
        }
Example #6
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

                        }
                    }
                }
        }
        /*
         * 
         * 
         **/
        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 brush = new SolidBrush(XLabColor))
            {
                using (Pen pen = new Pen(brush))
                {
                    pen.DashPattern = MajorGridPattern;
                  
                    if (DX != 0 && source.DY != 0)
                    {
                        if (source.Samples != null && source.Samples.Length > 1)
                        {
                            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);
                                    }

                                    /// TODO: find out how to calculate this offset. Must be padding + something else
                                    float unknownOffset = -14;// -14;

                                    if (MoveMinorGrid == false)
                                    {
                                        g.DrawLine(pen, x, offset_y +  GraphCaptionLineHeight  + source.CurGraphHeight + unknownOffset,
                                                        x, offset_y + GraphCaptionLineHeight + source.CurGraphHeight);

                                        g.DrawString(value, legendFont, brush, 
                                                        new PointF((int)(0.5f + x + offset_x + 4),
                                                        GraphCaptionLineHeight + offset_y + source.CurGraphHeight + unknownOffset));
                                    }
                                    else
                                    {
                                        SizeF dim = g.MeasureString(value, legendFont);
                                        g.DrawString(value, legendFont, brush, 
                                                            new PointF((int)(0.5f + x + offset_x + 4 - dim.Width / 2),
                                                            GraphCaptionLineHeight + offset_y + source.CurGraphHeight + unknownOffset));

                                    }
                                }
                            }
                        }
                    }

                   
                }
            }
        }