Exemple #1
0
        public void DrawRegions(Graphics gfx)
        {
            if (_regions == null)
            {
                return;
            }

            using (StringFormat textFormat = new StringFormat())
            {
                textFormat.Alignment     = StringAlignment.Center;
                textFormat.LineAlignment = StringAlignment.Center;

                using (Font font = new Font(_fontFamily, _labelFontSize))
                {
                    using (Brush textBrush = new SolidBrush(_fontColor))
                    {
                        using (Pen solidPen = new Pen(_fontColor))
                        {
                            using (Pen lightPen = new Pen(Color.FromArgb(128, _fontColor)))
                            {
                                float labelWidth = _barWidth + _spaceBtwBars;

                                for (int i = 0; i < _regions.Length; ++i)
                                {
                                    BarRegion reg = _regions[i];

                                    RectangleF rc = new RectangleF(_xOrigin + (reg.m_RangeFrom * labelWidth), _yOrigin, (reg.m_RangeTo - reg.m_RangeFrom + 1) * labelWidth, _graphHeight);

                                    if (rc.X + rc.Width > _xOrigin + _graphWidth)
                                    {
                                        rc.Width = _xOrigin + _graphWidth - rc.X;
                                    }

                                    using (SolidBrush brsh = new SolidBrush(Color.FromArgb(48, GetColor(i))))
                                    {
                                        gfx.FillRectangle(brsh, rc);
                                    }

                                    rc.Offset((rc.Width - 200.0f) * 0.5f, -16.0f);
                                    rc.Width  = 200.0f;
                                    rc.Height = 20.0f;

                                    gfx.DrawString(reg.m_Name, font, textBrush, rc, textFormat);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void DrawRegions(Graphics gfx)
        {
            if (_regions == null)
            {
                return;
            }

            using (StringFormat textFormat = new StringFormat())
            {
                textFormat.Alignment     = StringAlignment.Center;
                textFormat.LineAlignment = StringAlignment.Center;

                using (Font font = new Font(_fontFamily, _labelFontSize))
                {
                    using (Brush textBrush = new SolidBrush(_fontColor))
                    {
                        using (Pen solidPen = new Pen(_fontColor))
                        {
                            using (Pen lightPen = new Pen(Color.FromArgb(128, _fontColor)))
                            {
                                float labelWidth = _barWidth + _spaceBtwBars;

                                for (int i = 0; i < _regions.Length; ++i)
                                {
                                    BarRegion reg = _regions[i];

                                    RectangleF rc = new RectangleF(_xOrigin + (reg.m_RangeFrom * labelWidth), _yOrigin, (reg.m_RangeTo - reg.m_RangeFrom + 1) * labelWidth, _graphHeight);

                                    if (rc.X + rc.Width > _xOrigin + _graphWidth)
                                    {
                                        rc.Width = _xOrigin + _graphWidth - rc.X;
                                    }

                                    using (SolidBrush brsh = new SolidBrush(Color.FromArgb(48, GetColor(i))))
                                        gfx.FillRectangle(brsh, rc);

                                    rc.Offset((rc.Width - 200.0f) * 0.5f, -16.0f);
                                    rc.Width  = 200.0f;
                                    rc.Height = 20.0f;

                                    gfx.DrawString(reg.m_Name, font, textBrush, rc, textFormat);
                                }
                            }
                        }
                    }
                }
            }

            /*
             * Font lblFont = null;
             * SolidBrush brs = null;
             * StringFormat lblFormat = null;
             * Pen pen = null;
             *
             * try
             * {
             *      brs = new SolidBrush(_fontColor);
             *      pen = new Pen(_fontColor);
             *
             *      if ( _xTitle != null )
             *      {
             *              lblFormat = new StringFormat();
             *              lblFormat.Alignment = StringAlignment.Center;
             *              lblFormat.LineAlignment = StringAlignment.Center;
             * //					sfVLabel.FormatFlags=StringFormatFlags.DirectionVertical;
             *
             *              lblFont = new Font(_fontFamily, _labelFontSize+2.0f, FontStyle.Bold);
             *              graph.DrawString(_xTitle,lblFont,brs,new RectangleF( _xOrigin, _yOrigin+_graphHeight+14.0f+(_renderMode==BarGraphRenderMode.Bars?10.0f:0.0f)+(DataPoints.Count>15?16.0f:0.0f), _graphWidth, 20.0f ), lblFormat );
             *      }
             *
             *      lblFont = new Font(_fontFamily, _labelFontSize);
             *      lblFormat = new StringFormat();
             *      lblFormat.Alignment = StringAlignment.Center;
             *      lblFormat.FormatFlags |= StringFormatFlags.NoClip;
             *      lblFormat.Trimming = StringTrimming.None;
             *      //lblFormat.FormatFlags |= StringFormatFlags.NoWrap;
             *
             *      float of = 0.0f;
             *
             *      if ( _renderMode == BarGraphRenderMode.Bars )
             *      {
             *              of = 10.0f;
             *
             *              // Draw x axis
             *              graph.DrawLine( pen, _xOrigin + of, _yOrigin + _graphHeight + of, _xOrigin + _graphWidth + of, _yOrigin + _graphHeight + of );
             *              graph.DrawLine( pen, _xOrigin, _yOrigin + _graphHeight, _xOrigin + of, _yOrigin + _graphHeight + of );
             *              graph.DrawLine( pen, _xOrigin + _graphWidth, _yOrigin + _graphHeight, _xOrigin + of + _graphWidth, _yOrigin + _graphHeight + of );
             *      }
             *
             *      float currentX;
             *      float currentY = _yOrigin + _graphHeight + 2.0f;	// All x labels are drawn 2 pixels below x-axis
             *      float labelWidth = _barWidth + _spaceBtwBars;		// Fits exactly below the bar
             *      int i = 0;
             *
             *      // Draw x labels
             *      foreach(ChartItem item in DataPoints)
             *      {
             *              if((i%_interval)==0)
             *              {
             *                      currentX = _xOrigin + (i * labelWidth)+of+(labelWidth/2);
             *                      RectangleF recLbl = new RectangleF(currentX-((labelWidth*_interval)/2), currentY+of, labelWidth*_interval, lblFont.Height*2);
             *                      string lblString = _displayLegend ? item.Label : item.Description;	// Decide what to show: short or long
             *
             *                      graph.DrawString(lblString, lblFont, brs, recLbl, lblFormat);
             *              }
             *              i++;
             *      }
             * }
             * finally
             * {
             *      if (lblFont != null) lblFont.Dispose();
             *      if (brs != null) brs.Dispose();
             *      if (lblFormat != null) lblFormat.Dispose();
             *      if (pen != null) pen.Dispose();
             * }
             * }*/
        }
Exemple #3
0
        public static BarGraph OverTime(SnapshotHistory history, string reportName, string valueName, int step, int max, int ival)
        {
            BarGraph barGraph = new BarGraph(valueName + " over time", "graphs_" + valueName.ToLower() + "_ot", 10, "Time", valueName, BarGraphRenderMode.Lines);

            TimeSpan ts = TimeSpan.FromHours(max * step - 0.5);

            DateTime mostRecent = history.Snapshots[history.Snapshots.Count - 1].TimeStamp;
            DateTime minTime    = mostRecent - ts;

            barGraph.FontSize = 6;
            barGraph.Interval = ival;

            ArrayList regions = new ArrayList();

            for (int i = 0; i < history.Snapshots.Count; ++i)
            {
                Snapshot ss        = history.Snapshots[i];
                DateTime timeStamp = ss.TimeStamp;

                if (timeStamp < minTime)
                {
                    continue;
                }

                if (i % step != 0)
                {
                    continue;
                }

                int val = LookupReportValue(ss, reportName, valueName);

                if (val == -1)
                {
                    continue;
                }

                int realHours = timeStamp.TimeOfDay.Hours;
                int hours;

                if (realHours == 0)
                {
                    hours = 12;
                }
                else if (realHours > 12)
                {
                    hours = realHours - 12;
                }
                else
                {
                    hours = realHours;
                }

                string dayName = timeStamp.DayOfWeek.ToString();

                if (regions.Count == 0)
                {
                    regions.Add(new BarRegion(barGraph.Items.Count, barGraph.Items.Count, dayName));
                }
                else
                {
                    BarRegion region = (BarRegion)regions[regions.Count - 1];

                    if (region.m_Name == dayName)
                    {
                        region.m_RangeTo = barGraph.Items.Count;
                    }
                    else
                    {
                        regions.Add(new BarRegion(barGraph.Items.Count, barGraph.Items.Count, dayName));
                    }
                }

                barGraph.Items.Add(hours + (realHours >= 12 ? " PM" : " AM"), val);
            }

            barGraph.Regions = (BarRegion[])regions.ToArray(typeof(BarRegion));

            return(barGraph);
        }
Exemple #4
0
        public static BarGraph Growth(SnapshotHistory history, string reportName, string valueName)
        {
            BarGraph barGraph = new BarGraph("Growth of " + valueName + " over time", "graphs_" + valueName.ToLower() + "_growth", 10, "Time", valueName, BarGraphRenderMode.Lines);

            barGraph.FontSize = 6;
            barGraph.Interval = 7;

            DateTime startPeriod = history.Snapshots[0].TimeStamp.Date + TimeSpan.FromDays(1.0);
            DateTime endPeriod   = history.Snapshots[history.Snapshots.Count - 1].TimeStamp.Date;

            ArrayList regions = new ArrayList();

            DateTime curDate = DateTime.MinValue;
            int      curPeak = -1;
            int      curLow  = 1000;
            int      curTotl = 0;
            int      curCont = 0;
            int      curValu = 0;

            for (int i = 0; i < history.Snapshots.Count; ++i)
            {
                Snapshot ss        = history.Snapshots[i];
                DateTime timeStamp = ss.TimeStamp;

                if (timeStamp < startPeriod || timeStamp >= endPeriod)
                {
                    continue;
                }

                int val = LookupReportValue(ss, reportName, valueName);

                if (val == -1)
                {
                    continue;
                }

                DateTime thisDate = timeStamp.Date;

                if (curDate == DateTime.MinValue)
                {
                    curDate = thisDate;
                }

                curCont++;
                curTotl += val;
                curValu  = curTotl / curCont;

                if (curDate != thisDate && curValu >= 0)
                {
                    string mnthName = thisDate.ToString("MMMM");

                    if (regions.Count == 0)
                    {
                        regions.Add(new BarRegion(barGraph.Items.Count, barGraph.Items.Count, mnthName));
                    }
                    else
                    {
                        BarRegion region = (BarRegion)regions[regions.Count - 1];

                        if (region.m_Name == mnthName)
                        {
                            region.m_RangeTo = barGraph.Items.Count;
                        }
                        else
                        {
                            regions.Add(new BarRegion(barGraph.Items.Count, barGraph.Items.Count, mnthName));
                        }
                    }

                    barGraph.Items.Add(thisDate.Day.ToString(), curValu);

                    curPeak = val;
                    curLow  = val;
                }
                else
                {
                    if (val > curPeak)
                    {
                        curPeak = val;
                    }

                    if (val > 0 && val < curLow)
                    {
                        curLow = val;
                    }
                }

                curDate = thisDate;
            }

            barGraph.Regions = (BarRegion[])regions.ToArray(typeof(BarRegion));

            return(barGraph);
        }
        public static BarGraph OverLongTime(SnapshotHistory history, string reportName, string valueName, int step, int max, int ival)
        {
            BarGraph barGraph = new BarGraph(valueName + " over time", "graphs_" + valueName.ToLower() + "_ot", 10, "Time", valueName, BarGraphRenderMode.Lines);

            TimeSpan ts = TimeSpan.FromDays((max * step) - (step * .5));

            DateTime mostRecent = history.Snapshots[history.Snapshots.Count - 1].TimeStamp;
            DateTime minTime    = mostRecent - ts;

            barGraph.FontSize = 8;
            barGraph.Interval = ival;

            ArrayList regions = new ArrayList();

            for (int i = 0; i < history.Snapshots.Count; ++i)
            {
                Snapshot ss        = history.Snapshots[i];
                DateTime timeStamp = ss.TimeStamp;

                if (timeStamp < minTime)
                {
                    continue;
                }

                if ((i % step) != 0)
                {
                    continue;
                }

                int val = LookupReportValue(ss, reportName, valueName);

                if (val == -1)
                {
                    continue;
                }

                string monthName = timeStamp.ToString("MMMM");

                if (regions.Count == 0)
                {
                    regions.Add(new BarRegion(barGraph.Items.Count, barGraph.Items.Count, monthName));
                }
                else
                {
                    BarRegion region = (BarRegion)regions[regions.Count - 1];

                    if (region.m_Name == monthName)
                    {
                        region.m_RangeTo = barGraph.Items.Count;
                    }
                    else
                    {
                        regions.Add(new BarRegion(barGraph.Items.Count, barGraph.Items.Count, monthName));
                    }
                }

                barGraph.Items.Add(timeStamp.Day.ToString(), val);
            }

            barGraph.Regions = (BarRegion[])regions.ToArray(typeof(BarRegion));

            return(barGraph);
        }