Esempio n. 1
0
        private void DrawBarSlice(int index, ref Graphics g)
        {
            BarSlice bar   = barGraph.BarSliceCollection[index];
            double   width = barSliceWidth;

            if (width > bar.MaxWidth)
            {
                width = bar.MaxWidth;
            }

            Pen                 gPen    = new Pen(Color.Black, (float)0.03);
            SolidBrush          gBrush  = new SolidBrush(barGraph.Color);
            LinearGradientBrush lgBrush = null;

            int       startX = (int)((barSliceAllotedWidth * index) + (barSliceAllotedWidth / 2) - (width / 2));
            Rectangle rect;
            Rectangle shadowRect;

            if (bar.GetType().Name != "MultipleBarSlice")
            {
                if (bar.Value >= 0)
                {
                    rect =
                        new Rectangle((int)MappedXCoordinate(startX), (int)MappedYCoordinate(bar.Value), (int)width,
                                      (int)((bar.Value * drawingAreaHeightPixels) / totalValue));
                    shadowRect =
                        new Rectangle((int)MappedXCoordinate(startX) + 2, (int)MappedYCoordinate(bar.Value) - 3,
                                      (int)width, (int)((bar.Value * drawingAreaHeightPixels) / totalValue));
                    try
                    {
                        lgBrush = new LinearGradientBrush(rect, bar.Color, bar.ColorGradient, (float)(45 * (-1)), true);
                    }
                    catch
                    {
                    }
                    ;
                }
                else
                {
                    rect =
                        new Rectangle((int)MappedXCoordinate(startX), (int)MappedYCoordinate(0.0), (int)width,
                                      (int)((bar.Value * (-1) * drawingAreaHeightPixels) / totalValue));
                    shadowRect =
                        new Rectangle((int)MappedXCoordinate(startX) + 2, (int)MappedYCoordinate(0.0) + 3, (int)width,
                                      (int)((bar.Value * (-1) * drawingAreaHeightPixels) / totalValue));
                    try
                    {
                        lgBrush = new LinearGradientBrush(rect, bar.Color, bar.ColorGradient, (float)(45), true);
                    }
                    catch
                    {
                    }
                    ;
                }

                if (lgBrush != null)
                {
                    gBrush.Color = Color.LightGray;
                    g.FillRectangle(gBrush, shadowRect);
                    gBrush.Color = bar.Color;

                    //g.FillRectangle(gBrush, rect);
                    g.FillRectangle(lgBrush, rect);
                    g.DrawRectangle(gPen, rect);
                }
            }
            else
            {
                MultipleBarSlice mbs = (MultipleBarSlice)bar;
                if (mbs.PartialValues == null)
                {
                    return;
                }
                if (mbs.PartialValues.Length == 0)
                {
                    return;
                }

                if (barGraph.MultiBarDisplayStyle == MultiBarDisplayStyle.SeparateBars) // SeparateBars
                {
                    double partialValue    = 0;
                    double cumulativeValue = 0;

                    for (int i = 0; i < mbs.PartialValues.Length; i++)
                    {
                        partialValue     = mbs.PartialValues[i];
                        cumulativeValue += mbs.PartialValues[i];
                        if (partialValue >= 0)
                        {
                            rect =
                                new Rectangle((int)MappedXCoordinate(startX + (i * width / mbs.PartialValues.Length)),
                                              (int)MappedYCoordinate(partialValue),
                                              (int)(width / mbs.PartialValues.Length),
                                              (int)((partialValue * drawingAreaHeightPixels) / totalValue));
                            shadowRect =
                                new Rectangle((int)MappedXCoordinate(startX + (i * width / mbs.PartialValues.Length)) + 2,
                                              (int)MappedYCoordinate(partialValue) - 3,
                                              (int)(width / mbs.PartialValues.Length),
                                              (int)((partialValue * drawingAreaHeightPixels) / totalValue));
                        }
                        else
                        {
                            rect =
                                new Rectangle((int)MappedXCoordinate(startX + (i * width / mbs.PartialValues.Length)),
                                              (int)MappedYCoordinate(0), (int)(width / mbs.PartialValues.Length),
                                              (int)((partialValue * (-1) * drawingAreaHeightPixels) / totalValue));
                            shadowRect =
                                new Rectangle((int)MappedXCoordinate(startX + (i * width / mbs.PartialValues.Length)) + 2,
                                              (int)MappedYCoordinate(0) + 3, (int)(width / mbs.PartialValues.Length),
                                              (int)((partialValue * (-1) * drawingAreaHeightPixels) / totalValue));
                        }

                        gBrush.Color = Color.LightGray;
                        g.FillRectangle(gBrush, shadowRect);
                        gBrush.Color = mbs.PartialColors[i];
                        g.FillRectangle(gBrush, rect);
                        g.DrawRectangle(gPen, rect);
                    } // for
                }     // if SeparateBars

                else  // SingleBar
                {
                    double partialValue    = 0;
                    double cumulativeValue = 0;

                    for (int i = 0; i < mbs.PartialValues.Length; i++)
                    {
                        partialValue     = mbs.PartialValues[i];
                        cumulativeValue += mbs.PartialValues[i];
                        if (partialValue >= 0)
                        {
                            rect =
                                new Rectangle((int)MappedXCoordinate(startX), (int)MappedYCoordinate(cumulativeValue),
                                              (int)width, (int)((partialValue * drawingAreaHeightPixels) / totalValue));
                            shadowRect =
                                new Rectangle((int)MappedXCoordinate(startX) + 2,
                                              (int)MappedYCoordinate(cumulativeValue) - 3, (int)width,
                                              (int)((partialValue * drawingAreaHeightPixels) / totalValue));
                        }
                        else
                        {
                            rect =
                                new Rectangle((int)MappedXCoordinate(startX),
                                              (int)MappedYCoordinate(cumulativeValue - partialValue), (int)width,
                                              (int)((partialValue * (-1) * drawingAreaHeightPixels) / totalValue));
                            shadowRect =
                                new Rectangle((int)MappedXCoordinate(startX) + 2,
                                              (int)MappedYCoordinate(cumulativeValue - partialValue) + 3, (int)width,
                                              (int)((partialValue * (-1) * drawingAreaHeightPixels) / totalValue));
                        }

                        gBrush.Color = Color.LightGray;
                        g.FillRectangle(gBrush, shadowRect);
                        gBrush.Color = mbs.PartialColors[i];
                        g.FillRectangle(gBrush, rect);
                        g.DrawRectangle(gPen, rect);
                    } // for
                }     // else SingleBar
            }         // else -> MultipleBarSlice
        }             // DrawBarSlice function
Esempio n. 2
0
        }             // DrawBarSlice function

        private void DrawText(int index, ref Graphics g)
        {
            // Set up Font
            SolidBrush   gBrush = new SolidBrush(Color.Black);
            StringFormat format = new StringFormat(StringFormatFlags.NoClip);

            float fontSize = (float)0.5 * (float)gridHeightPixels;

            if (fontSize > (float)7.0)
            {
                fontSize = (float)7.0;
            }

            if (fontSize < (float)1.0)
            {
                fontSize = (float)1.0;
            }

            BarSlice bar   = barGraph.BarSliceCollection[index];
            double   width = barSliceWidth;

            if (width > bar.MaxWidth)
            {
                width = bar.MaxWidth;
            }

            Rectangle rect;
            Rectangle shadowRect;
            int       startX = (int)((barSliceAllotedWidth * index) + (barSliceAllotedWidth / 2) - (width / 2));

            if (bar.Value >= 0)
            {
                rect =
                    new Rectangle((int)MappedXCoordinate(startX), (int)MappedYCoordinate(bar.Value), (int)width,
                                  (int)((bar.Value * drawingAreaHeightPixels) / totalValue));
                shadowRect =
                    new Rectangle((int)MappedXCoordinate(startX) + 2, (int)MappedYCoordinate(bar.Value) - 3,
                                  (int)width, (int)((bar.Value * drawingAreaHeightPixels) / totalValue));

                if (barGraph.Alignment == Alignment.VerticalBottom)
                {
                    //Draw Text
                    format.Alignment     = StringAlignment.Far;
                    format.LineAlignment = StringAlignment.Center;

                    Point Middle = new Point(rect.Left + (int)(rect.Width / 2), rect.Bottom + 4);

                    g.TranslateTransform(Middle.X, Middle.Y);
                    g.RotateTransform((float)45.0 * -1);
                    g.DrawString(bar.Text, new Font("Tahoma", fontSize), gBrush, 0, 0, format);
                    g.RotateTransform((float)45.0);
                    g.TranslateTransform(-Middle.X, -Middle.Y);
                }
                else if (barGraph.Alignment == Alignment.HorizontalLeft)
                {
                    //Draw Text
                    format.Alignment     = StringAlignment.Far;
                    format.LineAlignment = StringAlignment.Center;

                    Point Middle = new Point(rect.Left + (int)(rect.Width / 2), rect.Bottom + 4);

                    g.TranslateTransform(Middle.X, Middle.Y);
                    g.RotateTransform((float)245.0);
                    g.DrawString(bar.Text, new Font("Tahoma", fontSize), gBrush, 0, 0, format);
                    g.RotateTransform((float)245.0 * -1);
                    g.TranslateTransform(-Middle.X, -Middle.Y);
                }
            }
            else
            {
                rect =
                    new Rectangle((int)MappedXCoordinate(startX), (int)MappedYCoordinate(0.0), (int)width,
                                  (int)((bar.Value * (-1) * drawingAreaHeightPixels) / totalValue));
                shadowRect =
                    new Rectangle((int)MappedXCoordinate(startX) + 2, (int)MappedYCoordinate(0.0) + 3, (int)width,
                                  (int)((bar.Value * (-1) * drawingAreaHeightPixels) / totalValue));

                if (barGraph.Alignment == Alignment.VerticalBottom)
                {
                    //Draw Text
                    format.Alignment     = StringAlignment.Near;
                    format.LineAlignment = StringAlignment.Center;

                    Point Middle = new Point(rect.Left + (int)(rect.Width / 2), rect.Top - 4);

                    g.TranslateTransform(Middle.X, Middle.Y);
                    g.RotateTransform((float)45.0 * -1);
                    g.DrawString(bar.Text, new Font("Tahoma", fontSize), gBrush, 0, 0, format);
                    g.RotateTransform((float)45.0);
                    g.TranslateTransform(-Middle.X, -Middle.Y);
                }
                else if (barGraph.Alignment == Alignment.HorizontalLeft)
                {
                    //Draw Text
                    format.Alignment     = StringAlignment.Near;
                    format.LineAlignment = StringAlignment.Center;

                    Point Middle = new Point(rect.Left + (int)(rect.Width / 2), rect.Top - 4);

                    g.TranslateTransform(Middle.X, Middle.Y);
                    g.RotateTransform((float)245.0);
                    g.DrawString(bar.Text, new Font("Tahoma", fontSize), gBrush, 0, 0, format);
                    g.RotateTransform((float)245.0 * -1);
                    g.TranslateTransform(-Middle.X, -Middle.Y);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Determines whether [contains] [the specified value].
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns>
 ///     <c>true</c> if [contains] [the specified value]; otherwise, <c>false</c>.
 /// </returns>
 public bool Contains(BarSlice value)
 {
     return(List.Contains(value));
 }
Esempio n. 4
0
 /// <summary>
 /// Adds the specified value.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public int Add(BarSlice value)
 {
     return(List.Add(value));
 }
Esempio n. 5
0
 /// <summary>
 /// Removes the specified value.
 /// </summary>
 /// <param name="value">The value.</param>
 public void Remove(BarSlice value)
 {
     List.Remove(value);
 }
Esempio n. 6
0
 /// <summary>
 /// Inserts the specified index.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <param name="value">The value.</param>
 public void Insert(int index, BarSlice value)
 {
     List.Insert(index, value);
 }
Esempio n. 7
0
 /// <summary>
 /// Indexes the of.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public int IndexOf(BarSlice value)
 {
     return(List.IndexOf(value));
 }