private void Initialize()
        {
            //Init original ChartData
            ChartData original = ChartData.GetInstance();

            //Initialize mousemarkercontrol
            this.mouseMarkerControl1             = new MouseMarkerControl();
            this.mouseMarkerControl1.Dock        = DockStyle.Fill;
            this.mouseMarkerControl1.ContextMenu = this.contextMenu1;
            this.mouseMarkerControl1.PickPoints  = false;
            this.mouseMarkerControl1.TraceValues = false;
            this.mouseMarkerControl1.NewMarker  += new NextGenLab.Chart.MouseMarkerControl.NewMarkerHandler(mouseMarkerControl1_NewMarker);
            this.mouseMarkerControl1.ForeColor   = ForeColor;
            this.mouseMarkerControl1.BackColor   = BackColor;

            //	this.mouseMarkerControl1.ChartData = original;
            this.Controls.Add(this.mouseMarkerControl1);


            //Initialize printer
            cp = new ChartPrint(mouseMarkerControl1);

            //Init splitter
            Splitter sp = new Splitter();

            sp.Dock    = DockStyle.Bottom;
            sp.MinSize = 3;
            this.Controls.Add(sp);

            //Init markers window
            markers         = new Markers();
            markers.Visible = false;
            markers.Dock    = DockStyle.Bottom;
            markers.Size    = new Size(50, 100);
            this.Controls.Add(markers);

            MenuItem m;

            //Get ChartTypes
            string[] strs = Enum.GetNames(typeof(ChartType));
            foreach (string s in strs)
            {
                m = new MenuItem(s, new EventHandler(Click_ChartType));
                this.miChartType.MenuItems.Add(m);
            }

            //X-Axis
            //MenuItem mi = new MenuItem("Type");
            //miXaxis.MenuItems.Add(mi);
            strs = Enum.GetNames(typeof(AxisType));
            foreach (string s in strs)
            {
                m = new MenuItem(s, new EventHandler(Click_AxisTypeX));
                miXaxis.MenuItems.Add(m);
            }

            //Y-Axis
            //mi = new MenuItem("Type");
            //miYaxis.MenuItems.Add(mi);
            foreach (string s in strs)
            {
                m = new MenuItem(s, new EventHandler(Click_AxisTypeY));
                miYaxis.MenuItems.Add(m);
            }

            //Trace
            miTraceType         = new MenuItem("Type");
            miTraceType.Enabled = false;
            miTrace.MenuItems.Add(miTraceType);
            strs = Enum.GetNames(typeof(ChartTraceType));
            foreach (string s in strs)
            {
                m = new MenuItem(s, new EventHandler(Click_ChartTraceType));
                miTraceType.MenuItems.Add(m);
            }
        }
Example #2
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);
        }
Example #3
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);
            }
        }
Example #4
0
        /// <summary>
        /// Initialize the graph component, only called explicitly when the graph changes
        /// </summary>
        void InitializeComponents(Graphics g)
        {
            if (cds.Length == 0)
            {
                return;
            }

            gr = new DrawGrid(cds);
            colorTheme.Reset();
            legend = new DrawLegend();
            DrawPlot dp;

            for (int i = 0; i < cds.Length; i++)
            {
                ChartData cd = cds[i];

                if (cd.Y.Length == 0 || cd.X.Length == 0)
                {
                    continue;
                }

                //Choose chart
                switch (cd.ChartType)
                {
                case ChartType.Curve:
                    dp = new ChartTypes.Curve(cd.X, cd.Y, cd.TitlesY);
                    break;

                case ChartType.Stem:
                    dp = new ChartTypes.Stem(cd.X, cd.Y, cd.TitlesY);
                    break;

                case ChartType.Fast:
                    dp = new ChartTypes.FastCurve(cd.X, cd.Y, cd.TitlesY);
                    break;

                case ChartType.Histogram:
                    dp = new ChartTypes.Histogram(cd.X, cd.Y, cd.TitlesY);
                    break;

                case ChartType.Points:
                    dp = new ChartTypes.Points(cd.X, cd.Y, cd.TitlesY);
                    break;

                case ChartType.Cross:
                    dp = new ChartTypes.Cross(cd.X, cd.Y, cd.TitlesY);
                    break;

                case ChartType.Step:
                    dp = new ChartTypes.Step(cd.X, cd.Y, cd.TitlesY);
                    break;

                case ChartType.CurveWide:
                    dp = new ChartTypes.CurveWide(cd.X, cd.Y, cd.TitlesY);
                    break;

                default:
                    dp = new ChartTypes.Curve(cd.X, cd.Y, cd.TitlesY);
                    break;
                }


                //Set colors
                Color[] plotcolors = new Color[cd.Y.Length];
                for (int j = 0; j < cd.Y.Length; j++)
                {
                    if (cd.Z != null && cd.Z.Length > j)
                    {
                        //int index = (int)Math.Floor(cd.Z[j] % cols.Length);
                        //if (index > 0 && index < cols.Length)
                        //    plotcolors[j] = cols[index];
                        //plotcolors[j] = Color.FromArgb((int)cd.Z[j] * 25, 66, 99);
                    }
                    else
                    {
                        plotcolors[j] = colorTheme.Next();
                    }
                    //    }
                }
                dp.Colors = plotcolors;

                //Set legend
                for (int j = 0; j < cd.Y.Length; j++)
                {
                    if (cd.TitlesY != null)
                    {
                        if (cd.TitlesY.Length > j)
                        {
                            legend.Add(dp.Colors[j], cd.TitlesY[j]);
                        }
                    }
                }

                gr.Add(dp);
            }
            //Add axis labels
            lg = new DrawGridAxis(gr);
            lg.NumberOfDecimals = numbdecimals;

            //Add text
            l = new DrawText(lg, cds[0]);
            l.SetLegend(legend);
            l.ShowTitle  = ShowTitle;
            l.ShowLegend = ShowLegend;
            l.Location   = new System.Drawing.Point(0, 0);
            l.Size       = this.Size;


            //Set ForeColors
            gr.GridColor     = this.ForeColor;
            lg.ForeColor     = this.ForeColor;
            legend.ForeColor = this.ForeColor;
            l.ForeColor      = this.ForeColor;

            //Initialize Controls
            l.Init(g);
        }
Example #5
0
 public void PowerSpectralDensity(double[] d, out ChartData cd, WindowBase window, double fs)
 {
     PowerSpectralDensity(d, out cd, window, fs, double.NaN);
 }
 public ChartData GetDefault()
 {
     return(ChartData.GetInstance());
 }