示例#1
0
 protected override void OnInit(Graphics g)
 {
     pen1 = new Pen(this.majorline);
     pen2 = new Pen(this.minorline);
     gm   = new GraphMath(Size, this.X, this.Y);
     base.OnInit(g);
 }
示例#2
0
        /// <summary>
        /// Generate ChartData with default values. Autoscale axisrange for X and Y
        /// arrays
        /// </summary>
        /// <param name="x">xvalue series</param>
        /// <param name="y">yvalues series</param>
        /// <returns>ChartData</returns>
        public static ChartData GetAutoScaleInstance(double[] x, double[][] y)
        {
            ChartData cd = GetInstance();

            cd.AxisRangeX = GraphMath.Transform(x);
            cd.AxisRangeY = GraphMath.Transform(y);
            cd.X          = x;
            cd.Y          = y;
            return(cd);
        }
示例#3
0
        /// <summary>
        /// Set Chart value series and autoscale Axis
        /// </summary>
        /// <param name="x">xvalue series</param>
        /// <param name="y">yvalues series</param>
        void SetValuesAutoScale(double[] x, double[][] y)
        {
            ChartData cd = cds[0];

            cd.AxisRangeX = GraphMath.Transform(x);
            cd.AxisRangeY = GraphMath.Transform(y);
            cd.X          = x;
            cd.Y          = y;
            cds[0]        = cd;
            changed       = true;
        }
示例#4
0
 /// <summary>
 /// Get AxisData (Min, Max, Step) from double[][] array
 /// </summary>
 /// <param name="f">double[][]</param>
 /// <returns>AxisData</returns>
 public static AxisData  Transform(double[][] f)
 {
     return(GraphMath.AxisScale(TransformNoScale(f)));
 }
示例#5
0
        private ChartData[] ReadXmlv2(string xml)
        {
            NextGenLab.DataSets.NglXml1 nx = new NextGenLab.DataSets.NglXml1();
            nx.DataSetName = "NglXml1";
            nx.Locale      = new System.Globalization.CultureInfo("en-US");

            nx.ReadXml(new MemoryStream(Encoding.Unicode.GetBytes(xml)));

            if (nx.Results.Count > 1)
            {
                throw new Exception("To many results, can't handle more than one");
            }
            if (nx.Results.Count == 0)
            {
                throw new ArgumentException("Can't find any results!!");
            }

            NglXml1.Plot[] plots  = nx.Results[0].GetPlots();
            ChartData[]    charts = new ChartData[plots.Length];
            NglXml1.Plot   p;
            ChartData      cd;

            Widths  = new int[plots.Length];
            Heights = new int[plots.Length];
            for (int j = 0; j < plots.Length; j++)
            {
                p  = plots[j];
                cd = ChartData.GetInstance();

                NglXml1.YVal[] yv = p.GetYVals();
                cd.Y = new double[yv.Length][];
                for (int i = 0; i < yv.Length; i++)
                {
                    cd.Y[i] = ParseValueString(yv[i].Y);
                }

                cd.X          = ParseValueString(p.X);
                cd.Title      = p.YLabel;
                cd.TitleX     = p.XLabel;
                cd.AxisLabelX = "[" + p.XUnit + "]";
                cd.AxisLabelY = "[" + p.YUnit + "]";
                cd.AxisTypeX  = (AxisType)Enum.Parse(typeof(AxisType), p.XScale, true);
                cd.AxisTypeY  = (AxisType)Enum.Parse(typeof(AxisType), p.YScale, true);

                switch (cd.AxisTypeX)
                {
                case AxisType.LOG:
                    cd.AxisRangeX = GraphMath.TransformNoScale(cd.X);
                    break;

                case AxisType.LIN:
                    cd.AxisRangeX = GraphMath.Transform(cd.X);
                    break;
                }

                switch (cd.AxisTypeY)
                {
                case AxisType.LOG:
                    cd.AxisRangeY = GraphMath.TransformNoScale(cd.Y);
                    break;

                case AxisType.LIN:
                    cd.AxisRangeY = GraphMath.Transform(cd.Y);
                    break;
                }

                Widths[j]   = p.Width;
                Heights[j]  = p.Height;
                cd.ShowZero = true;
                charts[j]   = cd;
            }

            return(charts);
        }
示例#6
0
        /// <summary>
        /// Reads Graph Xml from a string
        /// </summary>
        /// <param name="ResultXml">Graph Xml</param>
        /// <returns>Array of GraphDTO objects</returns>
        private ChartData[] ReadXmlv1(string ResultXml)
        {
            ArrayList   graphs = new ArrayList();
            ArrayList   yvals  = new ArrayList();
            XmlDocument doc    = new XmlDocument();

            doc.LoadXml(ResultXml);
            XmlNodeList graphList = doc.DocumentElement.GetElementsByTagName("GRAPH");

            Widths  = new int[graphList.Count];
            Heights = new int[graphList.Count];
            for (int j = 0; j < graphList.Count; j++)
            {
                XmlNode graph = graphList[j];
                try
                {
                    XmlDocument graph_doc = new XmlDocument();
                    graph_doc.LoadXml(graph.OuterXml);

                    ChartData cd = ChartData.GetInstance();

                    //Get YValues
                    yvals = new ArrayList();
                    XmlNodeList temp_node_list = graph_doc.DocumentElement.GetElementsByTagName("YVALUES");

                    cd.Y = new double[temp_node_list.Count][];
                    for (int i = 0; i < temp_node_list.Count; i++)
                    {
                        XmlNode TempNode = temp_node_list[i];
                        cd.Y[i] = ParseValueString(TempNode.InnerText);
                    }
                    //Get XValues
                    cd.X = ParseValueString(graph_doc.DocumentElement.GetElementsByTagName("XVALUES")[0].InnerText);

                    cd.Title      = graph_doc.DocumentElement.GetElementsByTagName("YLABEL")[0].InnerText;
                    cd.TitleX     = graph_doc.DocumentElement.GetElementsByTagName("XLABEL")[0].InnerText;
                    cd.TitlesY    = new string[] {};
                    cd.AxisLabelX = "[" + graph_doc.DocumentElement.GetElementsByTagName("XVAL")[0].InnerText + "]";
                    cd.AxisLabelY = "[" + graph_doc.DocumentElement.GetElementsByTagName("YVAL")[0].InnerText + "]";

                    cd.AxisTypeX = (AxisType)Enum.Parse(typeof(AxisType), graph_doc.DocumentElement.GetElementsByTagName("TYPE_X")[0].InnerText, false);
                    cd.AxisTypeY = (AxisType)Enum.Parse(typeof(AxisType), graph_doc.DocumentElement.GetElementsByTagName("TYPE_Y")[0].InnerText, false);

                    Heights[j] = Int32.Parse(graph_doc.DocumentElement.GetElementsByTagName("VSIZE")[0].InnerText);
                    Widths[j]  = Int32.Parse(graph_doc.DocumentElement.GetElementsByTagName("HSIZE")[0].InnerText);

                    switch (cd.AxisTypeX)
                    {
                    case AxisType.LOG:
                        cd.AxisRangeX = GraphMath.TransformNoScale(cd.X);
                        break;

                    case AxisType.LIN:
                        cd.AxisRangeX = GraphMath.Transform(cd.X);
                        break;
                    }

                    switch (cd.AxisTypeY)
                    {
                    case AxisType.LOG:
                        cd.AxisRangeY = GraphMath.TransformNoScale(cd.Y);
                        break;

                    case AxisType.LIN:
                        cd.AxisRangeY = GraphMath.Transform(cd.Y);
                        break;
                    }


                    cd.ShowZero = true;

                    graphs.Add(cd);
                }
                catch
                {
                    //Could not parse graph
                }
            }

            if (graphs.Count > 0)
            {
                return((ChartData[])graphs.ToArray(typeof(ChartData)));
            }
            else
            {
                return(null);
            }
        }
示例#7
0
        public void Rescale()
        {
            //Get max and min value and compare too current;
            AxisData tarx;
            AxisData tary;

            arx = new AxisData(double.MaxValue, double.MinValue, 1);
            ary = new AxisData(double.MaxValue, double.MinValue, 1);


            oarx = new AxisData(double.MaxValue, double.MinValue, 1);
            oary = new AxisData(double.MaxValue, double.MinValue, 1);

            ChartData d;

            for (int i = 0; i < this.Length; i++)
            {
                d = this[i];

                if (d.AxisRangeX.Max != 1e-31 && (d.AxisRangeX.Max != d.AxisRangeX.Min) && !AutoScale)
                {
                    tarx = d.AxisRangeX;
                }
                else
                {
                    switch (AxisTypeX)
                    {
                    case AxisType.LOG:
                        tarx = GraphMath.GetMaxMinLog(d.X);
                        break;

                    case AxisType.LIN:
                        tarx = GraphMath.TransformNoScale(d.X);
                        break;

                    default:
                        tarx = GraphMath.TransformNoScale(d.X);
                        break;
                    }
                }
                if (d.AxisRangeY.Max != 1e-31 && (d.AxisRangeY.Max != d.AxisRangeY.Min) && !AutoScale)
                {
                    tary = d.AxisRangeY;
                }
                else
                {
                    switch (AxisTypeY)
                    {
                    case AxisType.LOG:
                        tary = GraphMath.GetMaxMinLog(d.Y);
                        break;

                    case AxisType.LIN:
                        tary = GraphMath.TransformNoScale(d.Y);
                        break;

                    default:
                        tary = GraphMath.TransformNoScale(d.Y);
                        break;
                    }
                }

                if (arx.Max < tarx.Max)
                {
                    arx.Max = tarx.Max;
                }
                if (arx.Min > tarx.Min)
                {
                    arx.Min = tarx.Min;
                }

                if (ary.Max < tary.Max)
                {
                    ary.Max = tary.Max;
                }
                if (ary.Min > tary.Min)
                {
                    ary.Min = tary.Min;
                }
            }

            if (arx.Max == double.MinValue)
            {
                arx.Max = 10;
            }
            if (arx.Min == double.MaxValue)
            {
                arx.Min = arx.Max - 10;
            }

            if (ary.Max == double.MinValue)
            {
                ary.Max = 10;
            }
            if (ary.Min == double.MaxValue)
            {
                ary.Min = ary.Max - 10;
            }

            arx.Step = Math.Abs(arx.Max - arx.Min) / 5;
            ary.Step = Math.Abs(ary.Max - ary.Min) / 5;

            oarx = arx;
            oary = ary;
        }
示例#8
0
        /// <summary>
        /// Do not draw grid
        /// </summary>
        //public bool NoGrid{get{return nogrid;}set{nogrid = value;}}
        #endregion

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="cd">Chart Data</param>
        public DrawGrid(ChartDataList cds) : base()
        {
            //Initialize fields
            this.X         = cds.AxisRangeX;
            this.Y         = cds.AxisRangeY;
            this.GridColor = Color.LightGray;

            xAxisType = cds.AxisTypeX;
            yAxisType = cds.AxisTypeY;

            //Check if were gonna do autoscale
            if (cds.AutoScale)
            {
                //Scale X values
                if (this.XAxisType == AxisType.LOG)
                {
                    this.X = GraphMath.TransformLogX(cds.AxisRangeX.Min, cds.AxisRangeX.Max);
                }
                else
                {
                    this.X = GraphMath.AxisScale(cds.AxisRangeX);
                }

                //Scale Y values
                if (this.YAxisType == AxisType.LOG)
                {
                    this.Y = GraphMath.TransformLogY(cds.AxisRangeY.Min, cds.AxisRangeY.Max);
                }
                else
                {
                    this.Y = GraphMath.AxisScale(cds.AxisRangeY);
                }
            }
            else
            {
                //Scale X values with axisdata for X as limiter
                if (this.XAxisType == AxisType.LOG)
                {
                    this.X = GraphMath.TransformLog(X, GraphMath.TransformLogX(cds.AxisRangeX.Min, cds.AxisRangeX.Max));
                }
                else
                if (((X.Max - X.Min) / X.Step) > 30)
                {
                    this.X = GraphMath.AxisScale(cds.AxisRangeX);
                }


                //Scale Y values with axisdata for Y as limiter
                if (this.YAxisType == AxisType.LOG)
                {
                    this.Y = GraphMath.TransformLog(Y, GraphMath.TransformLogY(cds.AxisRangeY.Min, cds.AxisRangeY.Max));
                }
                else
                if (((Y.Max - Y.Min) / Y.Step) > 30)
                {
                    this.Y = GraphMath.AxisScale(cds.AxisRangeY);
                }
            }

            if (cds.Length > 0)
            {
                showzero = cds[0].ShowZero;
            }
        }
示例#9
0
        //Draw Axis labels
        private void GenerateAxis(Graphics g)
        {
            //Initialize variables
            data   d;
            SizeF  size;
            int    maxwidth  = int.MinValue;
            int    maxheight = int.MinValue;
            double tmp       = 0.0f;
            double tx        = 0.0f;
            double ty        = 0.0f;
            double dbl       = 0.0f;
            int    length    = 0;
            int    maxpower  = 0;
            string postfix   = "";
            double denum     = 0;

            #region Make axislabels for X axis
            switch (gr.XAxisType)
            {
            //Generate axis labels for X axis
            case AxisType.LIN:
                //Get postfix and denumerator
                maxpower = GraphMath.MaxPower(gr.X.Max, gr.X.Min);
                GraphMath.GetPostfix(maxpower, out postfix, out denum);


                //Get number of steps
                length = 0;
                tmp    = gr.X.Min;
                while (tmp < (gr.X.Max + gr.X.Step / 2))
                {
                    length++;
                    if (length > 1000)
                    {
                        break;
                    }
                    tmp += gr.X.Step;
                }

                //Generated axis label
                xaxis = new data[length];
                tx    = gr.X.Min;
                for (int i = 0; i < length; i++)
                {
                    //Init
                    d = new data();

                    //Adjust value and add postfix
                    d.Name = DoubleToString((double)(tx / denum)) + postfix;

                    //Get the screensize of the value
                    size = g.MeasureString(d.Name, Font);
                    if (maxheight < size.Height)
                    {
                        maxheight = (int)Math.Ceiling(size.Height);
                    }
                    d.Width  = d.Ceiling(size.Width);
                    d.Height = d.Ceiling(size.Height);

                    d.f = tx;

                    //Save for later
                    xaxis[i] = d;

                    //Step
                    tx += gr.X.Step;
                }
                break;

            //Make axislabel for logarithmic x axis
            case AxisType.LOG:
                //Get number of gridlines
                length = (int)Math.Ceiling((gr.X.Max + 1) - gr.X.Min);

                //Make label
                xaxis = new data[length];
                for (int i = 0; i < length; i++)
                {
                    //Get value;
                    dbl = i + gr.X.Min;

                    //Init
                    d = new data();

                    //Prettyfie the value
                    d.Name = GraphMath.GetPrettyString(Math.Pow(10, dbl));

                    //Measure Height of the value
                    size = g.MeasureString(d.Name, Font);
                    if (maxheight < size.Height)
                    {
                        maxheight = (int)Math.Ceiling(size.Height);
                    }

                    //Set width&Height
                    d.Width  = d.Ceiling(size.Width);
                    d.Height = d.Ceiling(size.Height);

                    //Store value
                    d.f = dbl;

                    //Save for later
                    xaxis[i] = d;
                }
                break;
            }
            #endregion


            #region Make axislabels for Y axis
            switch (gr.YAxisType)
            {
            case AxisType.LIN:

                //Make postfix and denummerator
                maxpower = GraphMath.MaxPower(gr.Y.Max, gr.Y.Min);
                GraphMath.GetPostfix(maxpower, out postfix, out denum);


                //Get number of steps
                length = 0;
                tmp    = gr.Y.Min;
                while (tmp < (gr.Y.Max + gr.Y.Step / 2))
                {
                    length++;
                    if (length > 1000)
                    {
                        break;
                    }
                    tmp += gr.Y.Step;
                }

                //Generate Axis
                bool zeroexist = false;
                yaxis = new data[length + 1];
                ty    = gr.Y.Min;
                for (int i = 0; i < length; i++)
                {
                    //Init
                    d = new data();

                    //Check if any of the values are zero
                    if (ty == 0)
                    {
                        zeroexist = true;
                    }

                    //Adjust value and add postfix
                    d.Name = DoubleToString((double)(ty / denum)) + postfix;
                    d.f    = (double)ty;

                    //Get/set size
                    size = g.MeasureString(d.Name, Font);
                    if (maxwidth < size.Width)
                    {
                        maxwidth = (int)Math.Ceiling(size.Width);
                    }
                    d.Width  = d.Ceiling(size.Width);
                    d.Height = d.Ceiling(size.Height);

                    //Save for later
                    yaxis[i] = d;

                    //Step
                    ty += gr.Y.Step;
                }

                //If there was a zero don't add zero line
                if (!zeroexist)
                {
                    d        = new data();
                    d.Name   = "0";
                    size     = g.MeasureString("0", Font);
                    d.Width  = d.Ceiling(size.Width);
                    d.Height = d.Ceiling(size.Height);
                    d.f      = 0;
                    yaxis[yaxis.Length - 1] = d;
                }
                else
                {
                    d        = new data();
                    d.Name   = "";
                    size     = g.MeasureString("", Font);
                    d.Width  = d.Ceiling(size.Width);
                    d.Height = d.Ceiling(size.Height);
                    d.f      = double.NaN;
                    yaxis[yaxis.Length - 1] = d;
                }
                break;

            //Make axislabels for logarithmic Y axis
            case AxisType.LOG:

                //Get Number of gridlines
                length = (int)Math.Ceiling((gr.Y.Max + 1) - gr.Y.Min);

                //Make axislabels
                yaxis = new data[length];
                for (int i = 0; i < length; i++)
                {
                    //Get value
                    dbl = i + gr.Y.Min;

                    //Initialize
                    d = new data();

                    //Prettyfy value
                    d.Name = GraphMath.GetPrettyString(Math.Pow(10, dbl));
                    d.f    = (double)dbl;

                    //Get/Set Size
                    size = g.MeasureString(d.Name, Font);
                    if (maxwidth < size.Width)
                    {
                        maxwidth = (int)Math.Ceiling(size.Width);
                    }
                    d.Width  = d.Ceiling(size.Width);
                    d.Height = d.Ceiling(size.Height);

                    //Store
                    yaxis[i] = d;
                }
                break;
            }
            #endregion

            //Set margins from calculated width and height of the axislabels
            this.MarginLeft   = maxwidth;
            this.MarginBottom = maxheight;

            //Set the Right Margin
            if (xaxis != null)
            {
                if (xaxis.Length > 0)
                {
                    this.MarginRight = (int)Math.Ceiling((double)xaxis[xaxis.Length - 1].Width / 2);
                }
            }

            //Set the Left Margin
            if (yaxis != null)
            {
                if (yaxis.Length > 0)
                {
                    this.MarginTop = (int)Math.Ceiling((double)yaxis[yaxis.Length - 1].Height / 2);
                }
            }
        }