Example #1
0
        public static ARGB[,] DrawSlice(ARGB[,] Target, double startangle, double angletodraw, ARGB color)
        {
            int          sizepiechart = Target.GetLength(0);
            SimpleVector oldVec, newVec;

            oldVec   = new SimpleVector();
            newVec   = new SimpleVector();
            newVec.x = Math.Cos(angletodraw);
            newVec.y = Math.Sin(angletodraw);
            oldVec.x = Math.Cos(startangle);
            oldVec.y = Math.Sin(startangle);
            for (int x = 0; x < sizepiechart; x++)
            {
                for (int y = 0; y < sizepiechart; y++)
                {
                    if (Math.Sqrt(Math.Pow(x - sizepiechart / 2, 2) + Math.Pow(y - sizepiechart / 2, 2)) < sizepiechart / 2)
                    {
                        if (isCounterClockwise(newVec, new SimpleVector(x, y)) && !isCounterClockwise(oldVec, new SimpleVector(x, y)))
                        {
                            Target[x, y] = color;
                        }
                    }
                }
            }
            return(Target);
        }
Example #2
0
        public static ARGB[,] Make(List <Duodata <string, int> > aDuodataList)
        {
            int GHeight  = 500;
            int GWidth   = 500;
            int GIndex   = aDuodataList.Count;               //amount of bars
            int GBarSize = (GHeight / GIndex) - 10 * GIndex; //individual bar size (vertical)

            Random rnd = new Random();

            ARGB[,] barchart = new ARGB[GHeight, GWidth];
            int total     = 0;
            int iteration = 0;

            foreach (Duodata <string, int> i in aDuodataList)
            {
                total += i.GetAttr2();
            }

            for (int x = 0; x < GWidth; x++)
            {
                for (int y = 0; x < GWidth; x++)
                {
                    barchart[x, y] = new ARGB(0, 0, 0, 0); //draw transparent array
                }
            }

            foreach (Duodata <string, int> i in aDuodataList)
            {
                iteration += 1; //because I'm too bad to figure out how to call the iterator count in a foreach-loop
                double percentage = i.GetAttr2() / total * 100;
                for (int x = 0; x < GWidth; x++)
                {
                    for (int y = 0; y < GHeight; y++)
                    {
                        if (x < percentage * GWidth / 100 && GHeight / GIndex * iteration < y && y <= GHeight / GIndex * iteration + GBarSize) //if pixel on [x,y] falls within drawable bounds of the bar in the current iteration
                        {
                            barchart[x, y] = new ARGB(255, 0, 0, 0);
                        }
                        else
                        {
                            ;
                        }
                    }
                }
            }

            //ARGB[,] barchart = new ARGB[GHeight, GWidth];
            //int GCurrentIndex = 1;
            //int total = 0;
            //foreach (Duodata<string, int> i in aDuodataList)
            //{
            //    GBarColor = new ARGB(255, Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)));
            //    GBarName = i.GetAttr1();
            //    GBarAmount = i.GetAttr2();
            //    total += i.GetAttr2();
            //    GCurrentIndex += 1;
            //}
            throw new System.Exception("Not implemented");
        }
Example #3
0
        public static ARGB[,] Make(List <Duodata <string, int> > aDuodataList)
        {
            int sizepiechart = 500;

            ARGB[,] piechart = new ARGB[sizepiechart, sizepiechart];

            double lastAngle = 0;
            double newangle;
            double percentage;
            ARGB   colortofill;



            for (int x = 0; x < sizepiechart; x++)
            {
                for (int y = 0; y < sizepiechart; y++)
                {
                    piechart[x, y] = new ARGB(0, 0, 0, 0);
                }
            }

            int total = 0;

            foreach (Duodata <string, int> i in aDuodataList)
            {
                total += i.GetAttr2();
            }

            for (int j = 0; j < aDuodataList.Count; j++)
            {
                Duodata <string, int> i = aDuodataList[j];

                colortofill = ListOfColorsToUse[j];
                if (i.GetAttr2() > total / 2)
                {
                    percentage = (double)i.GetAttr2() / (double)total * 100 / 2;
                    newangle   = lastAngle + 2 * Math.PI * percentage;
                    piechart   = DrawSlice(piechart, lastAngle, newangle, colortofill);
                    lastAngle  = newangle;


                    percentage = (double)i.GetAttr2() / (double)total * 100 / 2;
                    newangle   = lastAngle + 2 * Math.PI * percentage;
                    piechart   = DrawSlice(piechart, lastAngle, newangle, colortofill);
                    lastAngle  = newangle;
                }
                else
                {
                    percentage = (double)i.GetAttr2() / (double)total * 100;
                    newangle   = lastAngle + 2 * Math.PI * percentage;
                    piechart   = DrawSlice(piechart, lastAngle, newangle, colortofill);
                    lastAngle  = newangle;
                }
            }

            return(piechart);
        }