Ejemplo n.º 1
0
        /// <summary>
        /// stub method that passes control for the render event to the the registered
        /// event handler.
        /// </summary>
        protected virtual void OnDrawPane( Graphics g, MasterPane mp )
        {
            ZeeGraphWebControlEventHandler handler;
            handler = (ZeeGraphWebControlEventHandler)Events[_eventRender];

            MasterPaneFill.CopyTo( mp.Fill );
            MasterPaneBorder.CopyTo( mp.Border );

            if ( ( handler == null ) && ( CurveList.Count == 0 ) && ( GraphObjList.Count == 0 ) )
            {
                // default with the sample graph if no callback provided
                foreach ( GraphPane p in mp.PaneList )
                {
                    ZeeGraphWeb.RenderDemo( g, p );
                }
            }
            else
            {
                foreach ( GraphPane p in mp.PaneList )
                {
                    // Add visual designer influences here - first!!
                    SetWebProperties( g, p );

                    // Add DataSource values if available before the callback
                    PopulateByDataSource( g, p );

                    //Add Graph Items
                    AddWebGraphItems( g, p );
                }

                //TODO: verify callback regression test
                // Add custom callback tweeking next
                if ( handler != null )
                    handler( this, g, mp );

                // Set the layout according to user preferences
                mp.ReSize( g );
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="OutputStream"></param>
        /// <param name="Format"></param>
        /// <param name="bShowTransparency">if true, draw squares instead of leaving the
        /// background transparent</param>
        /// <remarks>
        /// bShowTransparency is set to true in design mode, to false otherwise.
        /// </remarks>
        protected MasterPane CreateGraph( System.IO.Stream OutputStream, ImageFormat Format,
				bool bShowTransparency )
        {
            RectangleF rect = new RectangleF( 0, 0, this.Width, this.Height );
            MasterPane mp = new MasterPane( string.Empty, rect );
            mp.Margin.All = 0;
            mp.Fill.IsVisible = false;
            mp.Border.IsVisible = false;

            // create all required panes
            //for ( int i = 0; i < this.PaneCount; i++ )
            //{
            mp.Add( new GraphPane( rect, Title, string.Empty, string.Empty ) );
            //}

            // create output bitmap container
            Bitmap image = new Bitmap( this.Width, this.Height );
            using ( Graphics g = Graphics.FromImage( image ) )
            {
                // Apply layout plan
                //mp.SetLayout( this.PaneLayout );
                mp.ReSize( g, rect );

                // Use callback to gather more settings and data values
                OnDrawPane( g, mp );

                // Allow designer control of axischange
                if ( this.AxisChanged ) mp.AxisChange( g );

                // Render the graph to a bitmap
                if ( bShowTransparency && mp.Fill.Color.A != 255 )
                {
                    //Show the transparency as white/gray filled squares
                    // We need to add the resource namespace to its name
                    //string resourceName = string.Format( "{0}.transparency.png", GetType().Namespace );
                    string resourceName = "ZedGraph.ZedGraph.transparency.png";
                    Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( resourceName );

                    if ( stream == null )
                        throw new Exception( "Does the Build Action of the resource " + resourceName + " is set to Embedded Resource ?" );

                    using ( System.Drawing.Image brushImage = new Bitmap( stream ) )
                    using ( TextureBrush brush = new TextureBrush( brushImage, WrapMode.Tile ) )
                    {
                        g.FillRectangle( brush, 0, 0, this.Width, this.Height );
                    }
                    stream.Close();
                }
                mp.Draw( g );
            }

            // Stream the graph out
            MemoryStream ms = new MemoryStream();
            image.Save( ms, Format );

            //TODO: provide caching options
            ms.WriteTo( OutputStream );

            return mp;
        }