Exemplo n.º 1
0
        public void DisplayCalcs(ComparisonCalculationBase[] calcs)
        {
            if (calcs == null) return;
            currentCalcs = calcs;
            if (comparisonItems == null) comparisonItems = new List<ComparisonGraphItem>();
            int i = 0;
#if DEBUG
            DateTime dtA = DateTime.Now;
#endif

            minScale = 0; maxScale = 0;
            foreach (ComparisonCalculationBase c in calcs)
            {
                if (c == null) continue;
                float min = 0f, max = 0f;
                if (Mode == DisplayMode.Overall)
                {
                    if (c.OverallPoints < 0) min += c.OverallPoints;
                    else max += c.OverallPoints;
                }
                else
                {
                    foreach (float f in c.SubPoints)
                    {
                        if (f < 0) min += f;
                        else max += f;
                    }
                }
                if (min < minScale) minScale = min;
                if (max > maxScale) maxScale = max;
            }
            if (minScale > -.01f) minScale = 0f;
            if (maxScale < .01f) maxScale = 0f;
            if (maxScale == 0f && minScale == 0f) maxScale = 2f;

            // Section 1: Initial Scales and Step value
            float largestScale = Math.Max(-minScale, maxScale);
            float roundTo = 2f;
            if (largestScale >= 10) roundTo = (int)Math.Pow(10, Math.Floor(Math.Log10(largestScale) - .6f));
            minScale = roundTo * (float)Math.Floor(minScale / roundTo);
            maxScale = roundTo * (float)Math.Ceiling(maxScale / roundTo);
            float totalScale = maxScale - minScale;
            float step = totalScale / 8f;
            // Section 2: Determine what the points are and check if there's a 0 in the points
            bool hasZero = false;
            List<float> pointsList = new List<float>();
            int countBelow = 0;
            for (int p = 0; p < 9; p++) {
                pointsList.Add(minScale + p * step);
                if (pointsList[p] < 0) { countBelow++; }
            }
            hasZero = pointsList.Contains(0);
            int countLargest = Math.Max(countBelow, 9 - countBelow);
            // Section 3: If there is not a zero, we need to round it out so that there is one
            if (!hasZero) {
                step = roundTo * (float)Math.Ceiling(largestScale / (countLargest - 1));
                while (step > totalScale)//maxScale)
                {
                    // In some cases, the roundTo goes out of control
                    // This brings it back in line
                    step /= 10;
                }
                //
                pointsList.Clear();
                for (int p = -countBelow; p < (9 - countBelow); p++) {
                    pointsList.Add(p * step);
                }
            }
            // Section 4: Set the min/max scales based on the points we determined (which could be adjusted)
            minScale = pointsList[0];
            maxScale = pointsList[8];

#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase A: {0}ms", DateTime.Now.Subtract(dtA).TotalMilliseconds));
            DateTime dtB = DateTime.Now;
#endif

            ChangedSize(this, null);
            IOrderedEnumerable<ComparisonCalculationBase> orderedCalcs;
            if (Sort == ComparisonSort.Alphabetical) 
                orderedCalcs = calcs.OrderBy(calc => calc == null ? "" : calc.Name);
            else if (Sort == ComparisonSort.Overall)
                orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.OverallPoints);
            else if ((int)Sort >= calcs[0].SubPoints.Length)
                // It's a combination one
                if        (calcs[0].SubPoints.Length == 3) {
                    switch ((int)Sort) {
                        case 3: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[1]); break; }
                        case 4: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[2]); break; }
                        default:{ orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }
                    }
                } else if (calcs[0].SubPoints.Length == 4) {
                    switch ((int)Sort) {
                        case 4: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[1]); break; }
                        case 5: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[2]); break; }
                        case 6: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[3]); break; }
                        case 7: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }
                        case 8: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }
                        default:{ orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[2] + calc.SubPoints[3]); break; }
                    }
                }
                else /*if (calcs[0].SubPoints.Length == 5)*/ {
                    switch ((int)Sort) {
                        case 5: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[1]); break; }
                        case 6: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[2]); break; }
                        case 7: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[3]); break; }
                        case 8: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[4]); break; }
                        case 9: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }
                        case 10:{ orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[3]); break; }
                        case 11:{ orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[4]); break; }
                        case 12:{ orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[2] + calc.SubPoints[3]); break; }
                        case 13:{ orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[2] + calc.SubPoints[4]); break; }
                        default:{ orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[3] + calc.SubPoints[4]); break; }
                    }
                }
            else
                orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[(int)Sort]);
#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase B: {0}ms", DateTime.Now.Subtract(dtB).TotalMilliseconds));
            DateTime dtC = DateTime.Now;
#endif
            foreach (ComparisonCalculationBase c in orderedCalcs)
            {
                if (c == null) continue;
                ComparisonGraphItem item;
                if (i >= comparisonItems.Count)
                {
                    item = new ComparisonGraphItem(LegendItems.Values);
                    item.Character = Character;
                    item.Slot = Slot;
                    comparisonItems.Add(item);
                    ItemStack.Children.Add(item);
                    item.NameGrid.MouseEnter += new MouseEventHandler(NameGrid_MouseEnter);
                    item.NameGrid.MouseLeave += new MouseEventHandler(NameGrid_MouseLeave);

//#if SILVERLIGHT
//                    item.NameGrid.MouseLeftButtonDown += new MouseButtonEventHandler(NameGrid_MouseLeftButtonDown);
//#else
//                    item.NameGrid.ContextMenu = ItemContextMenu;
//                    item.NameGrid.ContextMenuOpening += new ContextMenuEventHandler(NameGrid_ContextMenuOpening);
//#endif
                }
                else item = comparisonItems[i];
                bool isGem = c.Item != null && c.Item.IsGem;
                string s = c.Name;
                if (c.Item != null && c.Item.ItemLevel != 0 && !isGem) { s += string.Format(" [{0}]", c.Item.ItemLevel); }
                item.Title = s;
                item.Equipped = c.Equipped;
                item.PartEquipped = c.PartEquipped;
                item.OtherItem = c.Item;
                item.ItemInstance = c.ItemInstance;
                item.MinScale = minScale;
                item.MaxScale = maxScale;
                item.Slot = Slot;
                // Items will generate their own icon image, but if you supply one manually (like in custom charts), this will set it that way instead
                if (c.Item == null && c.ImageSource != null) { item.NonItemImageSource = c.ImageSource; }
                // Gems however, will not and we have to manually set them
                if (isGem && c.ImageSource != null) { item.NonItemImageSource = c.ImageSource; }

                item.NameGrid.Tag = c;

                // set visibility first, otherwise ActualWidth is 0 and it will fail to reset colors
                item.Visibility = Visibility.Visible;
                if (Mode == DisplayMode.Overall) { item[0] = c.OverallPoints; }
                else { for (int j = 0; j < c.SubPoints.Length; j++) item[j] = c.SubPoints[j]; }
                
                i++;
            }
#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase C: {0}ms", DateTime.Now.Subtract(dtC).TotalMilliseconds));
            DateTime dtD = DateTime.Now;
#endif
            for (; i < comparisonItems.Count; i++) comparisonItems[i].Visibility = Visibility.Collapsed;
#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase D: {0}ms", DateTime.Now.Subtract(dtD).TotalMilliseconds));
            System.Diagnostics.Debug.WriteLine(string.Format("Finished DisplayCalcs: Total {0}ms", DateTime.Now.Subtract(dtA).TotalMilliseconds));
#endif
        }
Exemplo n.º 2
0
        public void DisplayCalcs(ComparisonCalculationBase[] calcs)
        {
            if (calcs == null)
            {
                return;
            }
            currentCalcs = calcs;
            if (comparisonItems == null)
            {
                comparisonItems = new List <ComparisonGraphItem>();
            }
            int i = 0;

#if DEBUG
            DateTime dtA = DateTime.Now;
#endif

            minScale = 0; maxScale = 0;
            foreach (ComparisonCalculationBase c in calcs)
            {
                if (c == null)
                {
                    continue;
                }
                float min = 0f, max = 0f;
                if (Mode == DisplayMode.Overall)
                {
                    if (c.OverallPoints < 0)
                    {
                        min += c.OverallPoints;
                    }
                    else
                    {
                        max += c.OverallPoints;
                    }
                }
                else
                {
                    foreach (float f in c.SubPoints)
                    {
                        if (f < 0)
                        {
                            min += f;
                        }
                        else
                        {
                            max += f;
                        }
                    }
                }
                if (min < minScale)
                {
                    minScale = min;
                }
                if (max > maxScale)
                {
                    maxScale = max;
                }
            }
            if (minScale > -.01f)
            {
                minScale = 0f;
            }
            if (maxScale < .01f)
            {
                maxScale = 0f;
            }
            if (maxScale == 0f && minScale == 0f)
            {
                maxScale = 2f;
            }

            // Section 1: Initial Scales and Step value
            float largestScale = Math.Max(-minScale, maxScale);
            float roundTo      = 2f;
            if (largestScale >= 10)
            {
                roundTo = (int)Math.Pow(10, Math.Floor(Math.Log10(largestScale) - .6f));
            }
            minScale = roundTo * (float)Math.Floor(minScale / roundTo);
            maxScale = roundTo * (float)Math.Ceiling(maxScale / roundTo);
            float totalScale = maxScale - minScale;
            float step       = totalScale / 8f;
            // Section 2: Determine what the points are and check if there's a 0 in the points
            bool         hasZero    = false;
            List <float> pointsList = new List <float>();
            int          countBelow = 0;
            for (int p = 0; p < 9; p++)
            {
                pointsList.Add(minScale + p * step);
                if (pointsList[p] < 0)
                {
                    countBelow++;
                }
            }
            hasZero = pointsList.Contains(0);
            int countLargest = Math.Max(countBelow, 9 - countBelow);
            // Section 3: If there is not a zero, we need to round it out so that there is one
            if (!hasZero)
            {
                step = roundTo * (float)Math.Ceiling(largestScale / (countLargest - 1));
                while (step > totalScale)//maxScale)
                {
                    // In some cases, the roundTo goes out of control
                    // This brings it back in line
                    step /= 10;
                }
                //
                pointsList.Clear();
                for (int p = -countBelow; p < (9 - countBelow); p++)
                {
                    pointsList.Add(p * step);
                }
            }
            // Section 4: Set the min/max scales based on the points we determined (which could be adjusted)
            minScale = pointsList[0];
            maxScale = pointsList[8];

#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase A: {0}ms", DateTime.Now.Subtract(dtA).TotalMilliseconds));
            DateTime dtB = DateTime.Now;
#endif

            ChangedSize(this, null);
            IOrderedEnumerable <ComparisonCalculationBase> orderedCalcs;
            if (Sort == ComparisonSort.Alphabetical)
            {
                orderedCalcs = calcs.OrderBy(calc => calc == null ? "" : calc.Name);
            }
            else if (Sort == ComparisonSort.Overall)
            {
                orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.OverallPoints);
            }
            else if ((int)Sort >= calcs[0].SubPoints.Length)
            {
                // It's a combination one
                if (calcs[0].SubPoints.Length == 3)
                {
                    switch ((int)Sort)
                    {
                    case 3: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[1]); break; }

                    case 4: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[2]); break; }

                    default: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }
                    }
                }
                else if (calcs[0].SubPoints.Length == 4)
                {
                    switch ((int)Sort)
                    {
                    case 4: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[1]); break; }

                    case 5: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[2]); break; }

                    case 6: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[3]); break; }

                    case 7: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }

                    case 8: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }

                    default: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[2] + calc.SubPoints[3]); break; }
                    }
                }
                else /*if (calcs[0].SubPoints.Length == 5)*/
                {
                    switch ((int)Sort)
                    {
                    case 5: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[1]); break; }

                    case 6: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[2]); break; }

                    case 7: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[3]); break; }

                    case 8: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[4]); break; }

                    case 9: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }

                    case 10: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[3]); break; }

                    case 11: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[4]); break; }

                    case 12: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[2] + calc.SubPoints[3]); break; }

                    case 13: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[2] + calc.SubPoints[4]); break; }

                    default: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[3] + calc.SubPoints[4]); break; }
                    }
                }
            }
            else
            {
                orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[(int)Sort]);
            }
#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase B: {0}ms", DateTime.Now.Subtract(dtB).TotalMilliseconds));
            DateTime dtC = DateTime.Now;
#endif
            foreach (ComparisonCalculationBase c in orderedCalcs)
            {
                if (c == null)
                {
                    continue;
                }
                ComparisonGraphItem item;
                if (i >= comparisonItems.Count)
                {
                    item           = new ComparisonGraphItem(LegendItems.Values);
                    item.Character = Character;
                    item.Slot      = Slot;
                    comparisonItems.Add(item);
                    ItemStack.Children.Add(item);
                    item.NameGrid.MouseEnter += new MouseEventHandler(NameGrid_MouseEnter);
                    item.NameGrid.MouseLeave += new MouseEventHandler(NameGrid_MouseLeave);

//#if SILVERLIGHT
//                    item.NameGrid.MouseLeftButtonDown += new MouseButtonEventHandler(NameGrid_MouseLeftButtonDown);
//#else
//                    item.NameGrid.ContextMenu = ItemContextMenu;
//                    item.NameGrid.ContextMenuOpening += new ContextMenuEventHandler(NameGrid_ContextMenuOpening);
//#endif
                }
                else
                {
                    item = comparisonItems[i];
                }
                bool   isGem = c.Item != null && c.Item.IsGem;
                string s     = c.Name;
                if (c.Item != null && c.Item.ItemLevel != 0 && !isGem)
                {
                    s += string.Format(" [{0}]", c.Item.ItemLevel);
                }
                item.Title        = s;
                item.Equipped     = c.Equipped;
                item.PartEquipped = c.PartEquipped;
                item.OtherItem    = c.Item;
                item.ItemInstance = c.ItemInstance;
                item.MinScale     = minScale;
                item.MaxScale     = maxScale;
                item.Slot         = Slot;
                // Items will generate their own icon image, but if you supply one manually (like in custom charts), this will set it that way instead
                if (c.Item == null && c.ImageSource != null)
                {
                    item.NonItemImageSource = c.ImageSource;
                }
                // Gems however, will not and we have to manually set them
                if (isGem && c.ImageSource != null)
                {
                    item.NonItemImageSource = c.ImageSource;
                }

                item.NameGrid.Tag = c;

                // set visibility first, otherwise ActualWidth is 0 and it will fail to reset colors
                item.Visibility = Visibility.Visible;
                if (Mode == DisplayMode.Overall)
                {
                    item[0] = c.OverallPoints;
                }
                else
                {
                    for (int j = 0; j < c.SubPoints.Length; j++)
                    {
                        item[j] = c.SubPoints[j];
                    }
                }

                i++;
            }
#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase C: {0}ms", DateTime.Now.Subtract(dtC).TotalMilliseconds));
            DateTime dtD = DateTime.Now;
#endif
            for (; i < comparisonItems.Count; i++)
            {
                comparisonItems[i].Visibility = Visibility.Collapsed;
            }
#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase D: {0}ms", DateTime.Now.Subtract(dtD).TotalMilliseconds));
            System.Diagnostics.Debug.WriteLine(string.Format("Finished DisplayCalcs: Total {0}ms", DateTime.Now.Subtract(dtA).TotalMilliseconds));
#endif
        }
Exemplo n.º 3
0
        public void DisplayCalcs(ComparisonCalculationBase[] calcs)
        {
            if (calcs == null)
            {
                return;
            }
            currentCalcs = calcs;
            if (comparisonItems == null)
            {
                comparisonItems = new List <ComparisonGraphItem>();
            }
            int i = 0;

#if DEBUG
            DateTime dtA = DateTime.Now;
#endif

            minScale = 0; maxScale = 0;
            foreach (ComparisonCalculationBase c in calcs)
            {
                if (c == null)
                {
                    continue;
                }
                float min = 0f, max = 0f;
                if (Mode == DisplayMode.Overall)
                {
                    if (c.OverallPoints < 0)
                    {
                        min += c.OverallPoints;
                    }
                    else
                    {
                        max += c.OverallPoints;
                    }
                }
                else
                {
                    foreach (float f in c.SubPoints)
                    {
                        if (f < 0)
                        {
                            min += f;
                        }
                        else
                        {
                            max += f;
                        }
                    }
                }
                if (min < minScale)
                {
                    minScale = min;
                }
                if (max > maxScale)
                {
                    maxScale = max;
                }
            }
            if (minScale > -.01f)
            {
                minScale = 0f;
            }
            if (maxScale < .01f)
            {
                maxScale = 0f;
            }
            if (maxScale == 0f && minScale == 0f)
            {
                maxScale = 2f;
            }

            float totalScale = maxScale - minScale;

            float roundTo = 2f;
            if (totalScale >= 10)
            {
                roundTo = (int)Math.Pow(10, Math.Floor(Math.Log10(totalScale) - .3f));
            }
            totalScale = roundTo * (float)Math.Ceiling(totalScale / roundTo);

            minScale = -(float)Math.Ceiling(-minScale / totalScale * 8f) * (totalScale / 8f);
            maxScale = (float)Math.Ceiling(maxScale / totalScale * 8f) * (totalScale / 8f);
            if (maxScale - minScale > totalScale)
            {
                totalScale = maxScale - minScale; roundTo = 2f;
                if (totalScale >= 10)
                {
                    roundTo = (int)Math.Pow(10, Math.Floor(Math.Log10(totalScale) - .3f));
                }
                totalScale = roundTo * (float)Math.Ceiling(totalScale / roundTo);

                minScale = -(float)Math.Ceiling(-minScale / totalScale * 8f) * (totalScale / 8f);
                maxScale = (float)Math.Ceiling(maxScale / totalScale * 8f) * (totalScale / 8f);
            }
#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase A: {0}ms", DateTime.Now.Subtract(dtA).TotalMilliseconds));
            DateTime dtB = DateTime.Now;
#endif

            ChangedSize(this, null);
            IOrderedEnumerable <ComparisonCalculationBase> orderedCalcs;
            if (Sort == ComparisonSort.Alphabetical)
            {
                orderedCalcs = calcs.OrderBy(calc => calc == null ? "" : calc.Name);
            }
            else if (Sort == ComparisonSort.Overall)
            {
                orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.OverallPoints);
            }
            else if ((int)Sort >= calcs[0].SubPoints.Length)
            {
                // It's a combination one
                if (calcs[0].SubPoints.Length == 3)
                {
                    switch ((int)Sort)
                    {
                    case 3: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[1]); break; }

                    case 4: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[2]); break; }

                    default: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }
                    }
                }
                else if (calcs[0].SubPoints.Length == 4)
                {
                    switch ((int)Sort)
                    {
                    case 3: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[1]); break; }

                    case 4: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[2]); break; }

                    case 5: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[3]); break; }

                    case 6: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }

                    case 7: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }

                    default: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[2] + calc.SubPoints[3]); break; }
                    }
                }
                else /*if (calcs[0].SubPoints.Length == 5)*/
                {
                    switch ((int)Sort)
                    {
                    case 3: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[1]); break; }

                    case 4: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[2]); break; }

                    case 5: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[3]); break; }

                    case 6: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[0] + calc.SubPoints[4]); break; }

                    case 7: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[2]); break; }

                    case 8: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[3]); break; }

                    case 9: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[1] + calc.SubPoints[4]); break; }

                    case 10: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[2] + calc.SubPoints[3]); break; }

                    case 11: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[2] + calc.SubPoints[4]); break; }

                    default: { orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[3] + calc.SubPoints[4]); break; }
                    }
                }
            }
            else
            {
                orderedCalcs = calcs.OrderByDescending(calc => calc == null ? 0 : calc.SubPoints[(int)Sort]);
            }
#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase B: {0}ms", DateTime.Now.Subtract(dtB).TotalMilliseconds));
            DateTime dtC = DateTime.Now;
#endif
            foreach (ComparisonCalculationBase c in orderedCalcs)
            {
                if (c == null)
                {
                    continue;
                }
                ComparisonGraphItem item;
                if (i >= comparisonItems.Count)
                {
                    item           = new ComparisonGraphItem(LegendItems.Values);
                    item.Character = Character;
                    item.Slot      = Slot;
                    comparisonItems.Add(item);
                    ItemStack.Children.Add(item);
                    item.NameGrid.MouseEnter += new MouseEventHandler(NameGrid_MouseEnter);
                    item.NameGrid.MouseLeave += new MouseEventHandler(NameGrid_MouseLeave);

//#if SILVERLIGHT
//                    item.NameGrid.MouseLeftButtonDown += new MouseButtonEventHandler(NameGrid_MouseLeftButtonDown);
//#else
//                    item.NameGrid.ContextMenu = ItemContextMenu;
//                    item.NameGrid.ContextMenuOpening += new ContextMenuEventHandler(NameGrid_ContextMenuOpening);
//#endif
                }
                else
                {
                    item = comparisonItems[i];
                }
                bool   isGem = c.Item != null && c.Item.IsGem;
                string s     = c.Name;
                if (c.Item != null && c.Item.ItemLevel != 0 && !isGem)
                {
                    s += string.Format(" [{0}]", c.Item.ItemLevel);
                }
                item.Title        = s;
                item.Equipped     = c.Equipped;
                item.PartEquipped = c.PartEquipped;
                item.OtherItem    = c.Item;
                item.ItemInstance = c.ItemInstance;
                item.MinScale     = minScale;
                item.MaxScale     = maxScale;
                item.Slot         = Slot;

                item.NameGrid.Tag = c;

                // set visibility first, otherwise ActualWidth is 0 and it will fail to reset colors
                item.Visibility = Visibility.Visible;
                if (Mode == DisplayMode.Overall)
                {
                    item[0] = c.OverallPoints;
                }
                else
                {
                    for (int j = 0; j < c.SubPoints.Length; j++)
                    {
                        item[j] = c.SubPoints[j];
                    }
                }

                i++;
            }
#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase C: {0}ms", DateTime.Now.Subtract(dtC).TotalMilliseconds));
            DateTime dtD = DateTime.Now;
#endif
            for (; i < comparisonItems.Count; i++)
            {
                comparisonItems[i].Visibility = Visibility.Collapsed;
            }
#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format("DisplayCalcs Phase D: {0}ms", DateTime.Now.Subtract(dtD).TotalMilliseconds));
            System.Diagnostics.Debug.WriteLine(string.Format("Finished DisplayCalcs: Total {0}ms", DateTime.Now.Subtract(dtA).TotalMilliseconds));
#endif
        }