Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Gtk.Application.Init("test", ref args);
            Gtk.Window      window = new Gtk.Window("Test");
            Gtk.WindowGroup grp    = new Gtk.WindowGroup();
            grp.AddWindow(window);

            window.SetDefaultSize(400, 300);
            Plot.Widget area = new Plot.Widget();

            d_graph = area.Graph;

            d_graph.AxisAspect = 1;
            d_graph.KeepAspect = true;

            window.Add(area);

            window.ShowAll();
            window.DeleteEvent += delegate {
                Gtk.Application.Quit();
            };

            d_i = 0;

            Plot.Series.Point s1 = new Plot.Series.Point("test 1");
            s1.Size      = 5;
            s1.ShowLines = true;

            Plot.Series.Line s2 = new Plot.Series.Line("test 2");

            d_graph.ShowRuler = true;

            d_graph.Add(s1);
            d_graph.Add(s2);

            List <Plot.Point <double> > d1 = new List <Plot.Point <double> >();
            List <Plot.Point <double> > d2 = new List <Plot.Point <double> >();

            int samplesize = 1000;

            //GLib.Timeout.Add(10, delegate {
            for (int i = 0; i <= samplesize; ++i)
            {
                d_i = i;

                double x = d_i++ / (double)samplesize;

                Plot.Point <double> pt1 = new Plot.Point <double>(x, Math.Sin(x * Math.PI * 2));
                Plot.Point <double> pt2 = new Plot.Point <double>(x, Math.Cos(x * Math.PI * 2));

                d1.Add(pt1);
                d2.Add(pt2);
            }

            s1.Data = d1;
            s2.Data = d2;

            Gtk.Application.Run();
        }
Exemplo n.º 2
0
        private Gdk.Pixbuf PixbufForRenderer(Plot.Graph graph, Plot.Renderers.Renderer renderer)
        {
            Plot.Renderers.ILabeled lbl = renderer as Plot.Renderers.ILabeled;

            if (lbl == null)
            {
                return(null);
            }

            Plot.Renderers.IColored col = renderer as Plot.Renderers.IColored;

            string s;

            if (lbl.YLabelMarkup != null)
            {
                s = lbl.YLabelMarkup;
            }
            else
            {
                s = System.Security.SecurityElement.Escape(lbl.YLabel);
            }

            if (col != null)
            {
                string hex = String.Format("#{0:x2}{1:x2}{2:x2}",
                                           (int)(col.Color.R * 255),
                                           (int)(col.Color.G * 255),
                                           (int)(col.Color.B * 255));

                s = String.Format("<span color=\"{0}\">{1}</span>", hex, s);
            }

            Pango.Layout layout = CreatePangoLayout("");
            layout.SetMarkup(s);

            if (graph.Font != null)
            {
                layout.FontDescription = graph.Font;
            }

            int w;
            int h;

            layout.GetPixelSize(out w, out h);

            int xpadding = 4;
            int ypadding = 3;

            w += 2 * xpadding;
            h += 2 * ypadding;

            Gdk.Pixmap map = new Gdk.Pixmap(GdkWindow, w, h);

            using (Cairo.Context ctx = Gdk.CairoHelper.Create(map))
            {
                ctx.Rectangle(0.5, 0.5, w - 1, h - 1);
                ctx.LineWidth = 1;

                ctx.SetSourceRGB(1, 1, 1);
                ctx.FillPreserve();

                graph.AxisLabelColors.Bg.Set(ctx);
                ctx.FillPreserve();

                graph.AxisLabelColors.Fg.Set(ctx);
                ctx.Stroke();

                ctx.Translate(xpadding + 1, ypadding);

                Pango.CairoHelper.ShowLayout(ctx, layout);
            }

            return(Gdk.Pixbuf.FromDrawable(map, map.Colormap, 0, 0, 0, 0, w, h));
        }