Exemple #1
0
        /// <summary>
        /// Calculate the values needed to properly display this <see cref="GasGaugeNeedle"/>.
        /// </summary>
        /// <param name="pane">
        /// A graphic device object to be drawn into. This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        public static void CalculateGasGaugeParameters(GraphPane pane)
        {
            //loop thru slices and get total value and maxDisplacement
            double minVal = double.MaxValue;
            double maxVal = double.MinValue;

            foreach (CurveItem curve in pane.CurveList)
            {
                if (curve is GasGaugeRegion)
                {
                    GasGaugeRegion ggr = (GasGaugeRegion)curve;
                    if (maxVal < ggr.MaxValue)
                    {
                        maxVal = ggr.MaxValue;
                    }

                    if (minVal > ggr.MinValue)
                    {
                        minVal = ggr.MinValue;
                    }
                }
            }

            //Set Needle Sweep angle values here based on the min and max values of the GasGuage
            foreach (CurveItem curve in pane.CurveList)
            {
                if (curve is GasGaugeNeedle)
                {
                    GasGaugeNeedle ggn   = (GasGaugeNeedle)curve;
                    float          sweep = ((float)ggn.NeedleValue - (float)minVal) /
                                           ((float)maxVal - (float)minVal) * 180.0f;
                    ggn.SweepAngle = sweep;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Calculate the <see cref="RectangleF"/> that will be used to define the bounding rectangle of
        /// the GasGaugeNeedle.
        /// </summary>
        /// <remarks>This rectangle always lies inside of the <see cref="Chart.Rect"/>, and it is
        /// normally a square so that the pie itself is not oval-shaped.</remarks>
        /// <param name="g">
        /// A graphic device object to be drawn into. This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects. This is calculated and
        /// passed down by the parent <see cref="ZedGraph.GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <param name="chartRect">The <see cref="RectangleF"/> (normally the <see cref="Chart.Rect"/>)
        /// that bounds this pie.</param>
        /// <returns></returns>
        public static RectangleF CalcRectangle(Graphics g, GraphPane pane, float scaleFactor, RectangleF chartRect)
        {
            RectangleF nonExpRect = chartRect;

            nonExpRect.Height -= pane.GasGaugeRegionWidth / 2;
            nonExpRect.Width  -= pane.GasGaugeRegionWidth;

            float width = nonExpRect.Width;
            float height;

            double sineVal = Math.Sin((Math.PI / 180) * ((pane.Angle - 180) / 2));

            //take at least half a circle
            if (pane.Angle <= 180)
            {
                height = (width / 2);
            }
            else
            {
                height             = (float)((width / 2) + ((width / 2) * sineVal));
                nonExpRect.Height -= (float)(pane.GasGaugeRegionWidth / 2 * sineVal);
            }


            height *= 1.05f;

            float ratio = width / height;

            if ((ratio * nonExpRect.Height) > nonExpRect.Width)
            {
                //Scale based on width
                nonExpRect.Height = nonExpRect.Width;
            }
            else
            {
                //Scale based on height
                nonExpRect.Width  = nonExpRect.Height * ratio;
                nonExpRect.Height = nonExpRect.Width;
            }

            //define the place on the pane
            nonExpRect.X = (pane.Rect.Width - nonExpRect.Width) / 2;
            nonExpRect.Y = pane.Chart.Rect.Top + pane.GasGaugeRegionWidth / 2;

            GasGaugeNeedle.CalculateGasGaugeParameters(pane);

            foreach (CurveItem curve in pane.CurveList)
            {
                if (curve is GasGaugeNeedle)
                {
                    GasGaugeNeedle ggn = (GasGaugeNeedle)curve;
                    ggn._boundingRectangle = nonExpRect;
                }
            }

            return(nonExpRect);
        }
Exemple #3
0
 /// <summary>
 /// The Copy Constructor
 /// </summary>
 /// <param name="ggn">The <see cref="GasGaugeNeedle"/> object from which to copy</param>
 public GasGaugeNeedle(GasGaugeNeedle ggn)
     : base(ggn)
 {
     NeedleValue  = ggn.NeedleValue;
     NeedleColor  = ggn.NeedleColor;
     NeedleWidth  = ggn.NeedleWidth;
     SweepAngle   = ggn.SweepAngle;
     _border      = ggn.Border.Clone();
     _labelDetail = ggn.LabelDetail.Clone();
     _labelDetail.FontSpec.Size = ggn.LabelDetail.FontSpec.Size;
 }
Exemple #4
0
        /// <summary>
        /// Calculate the <see cref="RectangleF"/> that will be used to define the bounding rectangle of
        /// the GasGaugeNeedle.
        /// </summary>
        /// <remarks>This rectangle always lies inside of the <see cref="Chart.Rect"/>, and it is
        /// normally a square so that the pie itself is not oval-shaped.</remarks>
        /// <param name="g">
        /// A graphic device object to be drawn into. This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects. This is calculated and
        /// passed down by the parent <see cref="ZedGraph.GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <param name="chartRect">The <see cref="RectangleF"/> (normally the <see cref="Chart.Rect"/>)
        /// that bounds this pie.</param>
        /// <returns></returns>
        public static RectangleF CalcRectangle(Graphics g, GraphPane pane, float scaleFactor, RectangleF chartRect)
        {
            RectangleF nonExpRect = chartRect;

            if ((2 * nonExpRect.Height) > nonExpRect.Width)
            {
                //Scale based on width
                float percentS = ((nonExpRect.Height * 2) - nonExpRect.Width) / (nonExpRect.Height * 2);
                nonExpRect.Height = ((nonExpRect.Height * 2) - ((nonExpRect.Height * 2) * percentS));
            }
            else
            {
                nonExpRect.Height = nonExpRect.Height * 2;
            }

            nonExpRect.Width = nonExpRect.Height;

            float xDelta = (chartRect.Width / 2) - (nonExpRect.Width / 2);

            //Align Horizontally
            nonExpRect.X += xDelta;

            nonExpRect.Inflate(-(float)0.05F * nonExpRect.Height, -(float)0.05 * nonExpRect.Width);

            GasGaugeNeedle.CalculateGasGaugeParameters(pane);

            foreach (CurveItem curve in pane.CurveList)
            {
                if (curve is GasGaugeNeedle)
                {
                    GasGaugeNeedle ggn = (GasGaugeNeedle)curve;
                    ggn._boundingRectangle = nonExpRect;
                }
            }

            return(nonExpRect);
        }
Exemple #5
0
        private void CreateGraph_GasGauge( ZedGraphControl zgc )
        {
            GraphPane myPane = zgc.GraphPane;

            // Define the title
            myPane.Title.Text = "Gas Gauge Demo";

            // Fill the pane with gray
            myPane.Fill = new Fill( Color.LightGray, Color.White, 45.0f );
            // Fill the chart rect with blue
            myPane.Chart.Fill = new Fill( Color.White, Color.SkyBlue, 45.0f );

            // Don't show any axes for the gas gauge
            myPane.XAxis.IsVisible = false;
            myPane.Y2Axis.IsVisible = false;
            myPane.YAxis.IsVisible = false;

            //Define needles; can add more than one
            GasGaugeNeedle gg1 = new GasGaugeNeedle( "Cereal", 30.0f, Color.Black );
            GasGaugeNeedle gg2 = new GasGaugeNeedle( "Milk", 80.0f, Color.DarkGreen );
            myPane.CurveList.Add( gg1 );
            myPane.CurveList.Add( gg2 );

            //Define all regions
            GasGaugeRegion ggr1 = new GasGaugeRegion( "Red", 20f, 33.0f, Color.Red );
            GasGaugeRegion ggr2 = new GasGaugeRegion( "Yellow", 33.0f, 66.0f, Color.Yellow );
            GasGaugeRegion ggr3 = new GasGaugeRegion( "Green", 66.0f, 100.0f, Color.Green );

            // Add the curves
            myPane.CurveList.Add( ggr1 );
            myPane.CurveList.Add( ggr2 );
            myPane.CurveList.Add( ggr3 );

            zgc.AxisChange();
        }
Exemple #6
0
		/// <summary>
		/// The Copy Constructor
		/// </summary>
		/// <param name="ggn">The <see cref="GasGaugeNeedle"/> object from which to copy</param>
		public GasGaugeNeedle(GasGaugeNeedle ggn)
			: base(ggn)
		{
			NeedleValue = ggn.NeedleValue;
			NeedleColor = ggn.NeedleColor;
			NeedleWidth = ggn.NeedleWidth;
			SweepAngle = ggn.SweepAngle;
			_border = ggn.Border.Clone();
			_labelDetail = ggn.LabelDetail.Clone();
			_labelDetail.FontSpec.Size = ggn.LabelDetail.FontSpec.Size;
		}
Exemple #7
0
        private void tabPowerChannel_Enter(object sender, EventArgs e)
        {
            if (m_graphPowerChannel == null)
            {
                m_graphPowerChannel = new ZedGraphControl();
                m_panelPowerChannel.Controls.Add(m_graphPowerChannel);
                m_graphPowerChannel.EditButtons = System.Windows.Forms.MouseButtons.Left;
                m_graphPowerChannel.IsAntiAlias = true;
                m_graphPowerChannel.IsEnableSelection = false;
                m_graphPowerChannel.Location = new System.Drawing.Point(5, 5);
                m_graphPowerChannel.Name = "zedPowerChannel";
                m_graphPowerChannel.ScrollGrace = 0D;
                m_graphPowerChannel.ScrollMaxX = 0D;
                m_graphPowerChannel.ScrollMaxY = 0D;
                m_graphPowerChannel.ScrollMaxY2 = 0D;
                m_graphPowerChannel.ScrollMinX = 0D;
                m_graphPowerChannel.ScrollMinY = 0D;
                m_graphPowerChannel.ScrollMinY2 = 0D;
                m_graphPowerChannel.Size = new System.Drawing.Size(600, 300);
                m_graphPowerChannel.TabIndex = 49;
                m_graphPowerChannel.TabStop = false;
                m_graphPowerChannel.UseExtendedPrintDialog = true;
                m_graphPowerChannel.Visible = true;
                m_graphPowerChannel.GraphPane.Title.Text = "RF Explorer Channel Power Meter";
                m_graphPowerChannel.GraphPane.Title.FontSpec.Size = 18f;
                m_graphPowerChannel.GraphPane.TitleGap = 6;
                m_graphPowerChannel.Dock = DockStyle.Fill;
                m_graphPowerChannel.ContextMenuBuilder += new ZedGraph.ZedGraphControl.ContextMenuBuilderEventHandler(this.objGraphPowerChannel_ContextMenuBuilder);
                //m_graphSpectrumAnalyzer.ZoomEvent += new ZedGraph.ZedGraphControl.ZoomEventHandler(this.zedSpectrumAnalyzer_ZoomEvent);

                m_graphPowerChannel.GraphPane.XAxis.IsVisible = false;
                m_graphPowerChannel.GraphPane.Y2Axis.IsVisible = false;
                m_graphPowerChannel.GraphPane.YAxis.IsVisible = false;
                m_graphPowerChannel.GraphPane.Border.IsVisible = false;

                //Define needles; can add more than one
                m_PowerChannelNeedle = new GasGaugeNeedle("Realtime", -30.0f, Color.Blue);
                m_PowerChannelNeedle.NeedleWidth = 10f;
                m_PowerChannelNeedle.NeedleColor = Color.Blue;
                m_PowerChannelNeedle.Label.IsVisible = false;
                m_PowerChannelNeedle.LineCap = LineCap.ArrowAnchor;
                m_graphPowerChannel.GraphPane.CurveList.Add(m_PowerChannelNeedle);

                //Define all regions
                m_PowerChannelRegion_Low = new GasGaugeRegion("Low", -120.0f, -90.0f, Color.Blue);
                m_PowerChannelRegion_Low.HasLabel = true;
                m_PowerChannelRegion_Medium = new GasGaugeRegion("Medium", -90.0f, -30.0f, Color.LightBlue);
                m_PowerChannelRegion_High = new GasGaugeRegion("High", -30.0f, 0.0f, Color.Red);
                m_PowerChannelRegion_High.HasLabel = true;
                m_PowerChannelRegion_Low.Label.IsVisible = false;
                m_PowerChannelRegion_Medium.Label.IsVisible = false;
                m_PowerChannelRegion_High.Label.IsVisible = false;

                //not working as intended
                //m_PowerChannelRegion_Low.RegionColorStart = Color.LightGreen;
                //m_PowerChannelRegion_Low.RegionColorEnd = Color.LightBlue;
                //m_PowerChannelRegion_Medium.RegionColorStart = Color.LightBlue;
                //m_PowerChannelRegion_Medium.RegionColorEnd = Color.Blue;
                //m_PowerChannelRegion_High.RegionColorStart = Color.Blue;
                //m_PowerChannelRegion_High.RegionColorEnd = Color.Red;

                m_PowerChannelText = new TextObj("No data available", 0.5, 0.25, CoordType.PaneFraction);
                m_PowerChannelText.IsClippedToChartRect = false;
                m_PowerChannelText.FontSpec.FontColor = Color.DarkBlue;
                m_PowerChannelText.Location.AlignH = AlignH.Center;
                m_PowerChannelText.Location.AlignV = AlignV.Center;
                m_PowerChannelText.FontSpec.IsBold = false;
                m_PowerChannelText.FontSpec.Size = 16f;
                m_PowerChannelText.FontSpec.Border.IsVisible = false;
                m_PowerChannelText.FontSpec.Fill.IsVisible = false;
                m_PowerChannelText.FontSpec.StringAlignment = StringAlignment.Center;
                m_PowerChannelText.FontSpec.Family = "Arial";
                m_graphPowerChannel.GraphPane.GraphObjList.Add(m_PowerChannelText);

                // Add the curves
                m_graphPowerChannel.GraphPane.CurveList.Add(m_PowerChannelRegion_Low);
                m_graphPowerChannel.GraphPane.CurveList.Add(m_PowerChannelRegion_Medium);
                m_graphPowerChannel.GraphPane.CurveList.Add(m_PowerChannelRegion_High);
                m_graphPowerChannel.GraphPane.Angle = 150;
                m_graphPowerChannel.GraphPane.GasGaugeRegionWidth = 25;
                m_graphPowerChannel.GraphPane.GasGaugeBorder = false;
                m_graphPowerChannel.GraphPane.ShowGasGaugeValueLabel = false; //needs better code to paint value + unit
                m_graphPowerChannel.GraphPane.HasLabel = false; //needs better code to paint values
                m_graphPowerChannel.GraphPane.Border.IsVisible = false;
                m_graphPowerChannel.GraphPane.Chart.Border.IsVisible = false;
                m_graphPowerChannel.GraphPane.Clockwise = true;
                m_graphPowerChannel.AxisChange();
            }

            DisplayGroups();
            m_tabPowerChannel.Invalidate();
        }
Exemple #8
0
        /// <summary>
        /// Gas gauge chart.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="_options">GraphOptions.</param>
        /// <param name="binaryOutput">if set to <c>true</c> the image will output in the response stream.</param>
        /// <returns></returns>
        public static System.Drawing.Bitmap GasGauge( string query, Dictionary<string, object> _options, bool binaryOutput )
        {
            ( "FUNCTION /w binaryStream gasGauge" ).Debug( 10 );
            JToken jtOpt = JToken.FromObject( _options );
            JsonSerializer serializer = new JsonSerializer();
            GraphOptions options = null;
            using( JTokenReader jtr = new JTokenReader( jtOpt ) ) {
                options = ( GraphOptions )serializer.Deserialize( jtr, typeof( GraphOptions ) );
            }
            GraphPane myPane = new GraphPane( new System.Drawing.Rectangle( 0, 0, options.Width, options.Height ), options.Title, "", "" );
            myPane.Title.Text = options.Title;

            // Define the title
            myPane.Title.Text = "Gas Gauge Demo";

            // Fill the pane with gray
            myPane.Fill = new Fill( System.Drawing.Color.LightGray, System.Drawing.Color.White, 45.0f );
            // Fill the chart rect with blue
            myPane.Chart.Fill = new Fill( System.Drawing.Color.White, System.Drawing.Color.SkyBlue, 45.0f );

            // Don't show any axes for the gas gauge
            myPane.XAxis.IsVisible = false;
            myPane.Y2Axis.IsVisible = false;
            myPane.YAxis.IsVisible = false;

            //Define needles; can add more than one
            GasGaugeNeedle gg1 = new GasGaugeNeedle( "Cereal", 30.0f, System.Drawing.Color.Black );
            GasGaugeNeedle gg2 = new GasGaugeNeedle( "Milk", 80.0f, System.Drawing.Color.DarkGreen );
            myPane.CurveList.Add( gg1 );
            myPane.CurveList.Add( gg2 );

            //Define all regions
            GasGaugeRegion ggr1 = new GasGaugeRegion( "Red", 0.0f, 33.0f, System.Drawing.Color.Red );
            GasGaugeRegion ggr2 = new GasGaugeRegion( "Yellow", 33.0f, 66.0f, System.Drawing.Color.Yellow );
            GasGaugeRegion ggr3 = new GasGaugeRegion( "Green", 66.0f, 100.0f, System.Drawing.Color.Green );

            // Add the curves
            myPane.CurveList.Add( ggr1 );
            myPane.CurveList.Add( ggr2 );
            myPane.CurveList.Add( ggr3 );

            System.Drawing.Bitmap image = myPane.GetImage( true );
            if( binaryOutput ) {
                using( MemoryStream ms = new MemoryStream() ) {
                    image.Save( ms, System.Drawing.Imaging.ImageFormat.Png );
                    if(HttpContext.Current!=null){
                        HttpContext.Current.Response.Clear();
                        HttpContext.Current.Response.ContentType = "image/png";
                        HttpContext.Current.Response.AddHeader( "Expires", "0" );/* RFC 2616 14.21 Content has already expired */
                        HttpContext.Current.Response.AddHeader( "Cache-Control", "no-store" );/* RFC 2616 14.9.2 Don't ever cache */
                        HttpContext.Current.Response.AddHeader( "Pragma", "no-store" );/* RFC 2616 14.32 Pragma - same as cache control */
                        ms.WriteTo( HttpContext.Current.Response.OutputStream );
                    }
                }
                image.Dispose();
            }
            return image;
        }