Click here to Skip to main content
15,892,809 members
Articles / Programming Languages / C#

Visual Studio .NET 2003 Add-in that adds diff tools, an explore command, Subversion support and web project reporting. Version 2.1

Rate me:
Please Sign up or sign in to vote.
4.88/5 (25 votes)
27 Jul 200528 min read 219.8K   2.8K   142  
With this add-in, you get new tools and commands that boost your productivity while developing and some helpful reports specially for web projects. Version 2.1.
using System;
using System.Text;

namespace WebReports {

  /// <summary>Summary description for svgPie.</summary>
  internal abstract class svgPie {

    /// <summary>Return a string containing svg tags that render as a pie chart.</summary>
    /// <param name="data">The data values.</param>
    /// <param name="legend">The labelsof the corresponding data elements.</param>
    /// <returns>Xml text containing svg tags.</returns>
    public static string RenderPie(double[] data, string[] legend) {
      if (data != null) {
        byte r = 0, g=0, b=0xFF;
        byte shiftValue = 0x11;
        string[] colors = new string[data.Length];

        if (data.Length < 9)
          shiftValue = 0x55;
        else if (data.Length < 15)
          shiftValue = 0x33;

        for (int n = 0; n < data.Length; n++) {
          colors[n] = String.Format("#{0:X2}{1:X2}{2:X2}", r, g, b);

          // shift 0x11 value
          if ((r != 0) & (b == 0)) {
            r -= shiftValue;
            g += shiftValue;
          } else if (g != 0) {
            g -= shiftValue;
            b += shiftValue;
          } else {
            b -= shiftValue;
            r += shiftValue;
          } // if

        } // for
        return(RenderPie(data, legend, colors));
      } // if
      return(String.Empty);
    }


    /// <summary>Return a string containing svg tags that render as a pie chart.</summary>
    /// <param name="data">The data values.</param>
    /// <param name="legend">The labelsof the corresponding data elements.</param>
    /// <param name="colors">The colors of the corresponding data elements.</param>
    /// <returns>Xml text containing svg tags.</returns>
    public static string RenderPie(double[] data, string[] legend, string[] colors) {
      StringBuilder sb = new StringBuilder();
      int mx = 200, my = 200;
      int r = 100;
      double sum, curSum;
      int curX, curY;
      int txtX, txtY;
      string txt;

      sb.AppendFormat("<svg:svg width='{0}' height='{1}'>\n", 2*mx, 2*my);

      sum = 0;
      for (int n = 0; n < data.Length; n++)
        sum += data[n];

      // draw the pie
      curSum = 0;
      curX = mx - r;
      curY = my;
      for (int n = 0; n < data.Length; n++) {
        // draw the pie part
        if (data[n] >= sum / 2)
          sb.AppendFormat("<svg:path d='M {0},{1} L {2},{3} A {4} {4} 0 1 1 ",
            mx, my, curX, curY, r );
        else
          sb.AppendFormat("<svg:path d='M {0},{1} L {2},{3} A {4} {4} 0 0 1 ",
            mx, my, curX, curY, r );

        curSum += data[n];
        curX = mx - (int)(r*Math.Cos(2 * curSum * Math.PI / sum));
        curY = my - (int)(r*Math.Sin(2 * curSum * Math.PI / sum));

        sb.AppendFormat("{0},{1} Z' ",curX, curY);

        sb.AppendFormat(" fill='{0}' stroke='black' stroke-width='1' />\n", colors[n]);

        // draw the text

        if ((legend != null) && (legend.Length > n) && (legend[n] != null) && (legend[n].Length > 0)) {
          txt = legend[n];
        } else {
          txt = data[n].ToString();
        } // if

        txtX = mx - (int)(1.3 * r*Math.Cos(2 * (curSum - data[n]/2) * Math.PI / sum));
        txtY = my - (int)(1.3 * r*Math.Sin(2 * (curSum - data[n]/2) * Math.PI / sum));
        sb.AppendFormat("<svg:text x='{0}' y='{1}' text-anchor='middle' style='fill:black'>{2}</svg:text>\n",
          txtX, txtY, txt);
      } // for

      sb.Append("</svg:svg>\n");
      return(sb.ToString());
    }
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Deutsche Bank AG
Germany Germany
see https://www.mathertel.de

Comments and Discussions