Exemple #1
0
 void UpdateLabels()
 {
     for (int i = 0; i < values.Count; i++)
     {
         changeLabelText(bands[i].percentLabel, WMG_Util.FormatValueLabel("", WMG_Enums.labelTypes.Percents_Only, 0, (bands[i].cumulativePercent - bands[i].prevCumulativePercent), numDecimals));
         changeLabelText(bands[i].label, labels[i]);
     }
 }
Exemple #2
0
    void UpdateVisuals(bool noAnim)
    {
        // Update internal bookkeeping variables
        UpdateData();

        // Creates and deletes slices and slice legend objects based on the slice values
        CreateOrDeleteSlicesBasedOnValues();

        if (totalVal == 0 && numSlices > 0)
        {
            return;                                         // all values are 0, or mixed negative and positive values
        }
        // Update explode symmetrical
        for (int i = 0; i < numSlices; i++)
        {
            WMG_Pie_Graph_Slice pieSlice = slices[i].GetComponent <WMG_Pie_Graph_Slice>();
            SetActive(pieSlice.objectToMask, explodeSymmetrical);
            if (explodeSymmetrical)
            {
                changeSpriteParent(pieSlice.objectToColor, pieSlice.objectToMask);
            }
            else
            {
                changeSpriteParent(pieSlice.objectToColor, pieSlice.gameObject);
                bringSpriteToFront(pieSlice.objectToLabel);
            }
        }

        int thePieSize = Mathf.RoundToInt(pieSize);

        updateBG(thePieSize);

        if (animationDuration == 0 && sortBy != sortMethod.None)
        {
            sortData();
        }
        float curTotalRot = 0;

        if (!noAnim)
        {
            animSortSwap = false;                  // Needed because if sortAnimationDuration = 0, nothing sets animSortSwap to false
        }
        for (int i = 0; i < numSlices; i++)
        {
            // Update Pie Slices
            float newAngle = -1 * curTotalRot;
            if (newAngle < 0)
            {
                newAngle += 360;
            }
            WMG_Pie_Graph_Slice pieSlice = slices[i].GetComponent <WMG_Pie_Graph_Slice>();
            if (sliceLabelType != WMG_Enums.labelTypes.None && !activeInHierarchy(pieSlice.objectToLabel))
            {
                SetActive(pieSlice.objectToLabel, true);
            }
            if (sliceLabelType == WMG_Enums.labelTypes.None && activeInHierarchy(pieSlice.objectToLabel))
            {
                SetActive(pieSlice.objectToLabel, false);
            }

            if (!explodeSymmetrical)
            {
                changeSpriteSize(pieSlice.objectToColor, thePieSize, thePieSize);
            }
            else
            {
                changeSpriteSize(pieSlice.objectToColor, thePieSize, thePieSize);
                changeSpriteSize(pieSlice.objectToMask,
                                 thePieSize + Mathf.RoundToInt(explodeLength * 4),
                                 thePieSize + Mathf.RoundToInt(explodeLength * 4));
            }

            // Set Slice Data and maybe Other Slice Data
            Color  sliceColor = sliceColors[i];
            string sliceLabel = sliceLabels[i];
            float  sliceValue = sliceValues[i];
            if (isOtherSlice && i == numSlices - 1)
            {
                sliceColor = includeOthersColor;
                sliceLabel = includeOthersLabel;
                sliceValue = otherSliceValue;
            }
            if (!LabelToSliceMap.ContainsKey(sliceLabel))
            {
                LabelToSliceMap.Add(sliceLabel, pieSlice);
            }

            // Hide if 0
            if (sliceValue == 0)
            {
                SetActive(pieSlice.objectToLabel, false);
            }

            float slicePercent = sliceValue / totalVal;
            pieSlice.slicePercent = slicePercent * 360;
            float afterExplodeAngle = newAngle * -1 + 0.5f * slicePercent * 360;
            float sliceLabelRadius  = sliceLabelExplodeLength + thePieSize / 2;
            float sin = Mathf.Sin(afterExplodeAngle * Mathf.Deg2Rad);
            float cos = Mathf.Cos(afterExplodeAngle * Mathf.Deg2Rad);

            if (!noAnim && animationDuration > 0)
            {
                isAnimating = true;
                WMG_Anim.animFill(pieSlice.objectToColor, animationDuration, Ease.Linear, slicePercent);
                WMG_Anim.animPosition(pieSlice.objectToLabel, animationDuration, Ease.Linear, new Vector3(sliceLabelRadius * sin,
                                                                                                          sliceLabelRadius * cos));
                int newI = i;
                WMG_Anim.animPositionCallbackC(slices[i], animationDuration, Ease.Linear, new Vector3(explodeLength * sin,
                                                                                                      explodeLength * cos), () => shrinkSlices(newI));
                if (!explodeSymmetrical)
                {
                    WMG_Anim.animRotation(pieSlice.objectToColor, animationDuration, Ease.Linear, new Vector3(0, 0, newAngle), false);
                    WMG_Anim.animPosition(pieSlice.objectToColor, animationDuration, Ease.Linear, Vector3.zero);
                }
                else
                {
                    WMG_Anim.animRotation(pieSlice.objectToColor, animationDuration, Ease.Linear, Vector3.zero, false);
                    Vector2 newPos = new Vector2(-explodeLength * sin, -explodeLength * cos);
                    float   sin2   = Mathf.Sin(newAngle * Mathf.Deg2Rad);
                    float   cos2   = Mathf.Cos(newAngle * Mathf.Deg2Rad);
                    WMG_Anim.animPosition(pieSlice.objectToColor, animationDuration, Ease.Linear, new Vector3(cos2 * newPos.x + sin2 * newPos.y, cos2 * newPos.y - sin2 * newPos.x));
                    // Mask
                    WMG_Anim.animRotation(pieSlice.objectToMask, animationDuration, Ease.Linear, new Vector3(0, 0, newAngle), false);
                    WMG_Anim.animFill(pieSlice.objectToMask, animationDuration, Ease.Linear, slicePercent);
                }
            }
            else
            {
                changeSpriteFill(pieSlice.objectToColor, slicePercent);
                pieSlice.objectToLabel.transform.localPosition = new Vector3(sliceLabelRadius * sin,
                                                                             sliceLabelRadius * cos);
                slices[i].transform.localPosition = new Vector3(explodeLength * sin,
                                                                explodeLength * cos);
                if (!explodeSymmetrical)
                {
                    pieSlice.objectToColor.transform.localEulerAngles = new Vector3(0, 0, newAngle);
                    pieSlice.objectToColor.transform.localPosition    = Vector3.zero;
                }
                else
                {
                    pieSlice.objectToColor.transform.localEulerAngles = Vector3.zero;
                    Vector2 newPos = new Vector2(-explodeLength * sin, -explodeLength * cos);
                    float   sin2   = Mathf.Sin(newAngle * Mathf.Deg2Rad);
                    float   cos2   = Mathf.Cos(newAngle * Mathf.Deg2Rad);
                    pieSlice.objectToColor.transform.localPosition = new Vector3(cos2 * newPos.x + sin2 * newPos.y, cos2 * newPos.y - sin2 * newPos.x);
                    // Mask
                    pieSlice.objectToMask.transform.localEulerAngles = new Vector3(0, 0, newAngle);
                    changeSpriteFill(pieSlice.objectToMask, slicePercent);
                }
            }

            // Update slice color
            changeSpriteColor(pieSlice.objectToColor, sliceColor);
            changeSpriteColor(pieSlice.objectToMask, sliceColor);

            // Update slice labels
            changeLabelText(pieSlice.objectToLabel, WMG_Util.FormatValueLabel(sliceLabel, sliceLabelType, sliceValue, slicePercent, numberDecimalsInPercents));
            changeLabelFontSize(pieSlice.objectToLabel, sliceLabelFontSize);
            changeSpriteColor(pieSlice.objectToLabel, sliceLabelColor);

            // Update Gameobject names
            slices[i].name = sliceLabel;
            legend.legendEntries[i].name = sliceLabel;

            curTotalRot += slicePercent * 360;

            pieSlice.slicePercentPosition = curTotalRot - pieSlice.slicePercent / 2;

            // Update legend
            WMG_Legend_Entry entry = legend.legendEntries[i];
            changeLabelText(entry.label, WMG_Util.FormatValueLabel(sliceLabel, legend.labelType, sliceValue, slicePercent, legend.numDecimals));
            changeSpriteColor(entry.swatchNode, sliceColor);
            // Hide legend if 0
            if (hideZeroValueLegendEntry)
            {
                if (sliceValue == 0)
                {
                    SetActive(entry.gameObject, false);
                }
                else
                {
                    SetActive(entry.gameObject, true);
                }
            }
            else
            {
                SetActive(entry.gameObject, true);
            }
        }
        legend.updateLegend();

        updateAutoCenter();

        if (!setOrig)
        {
            setOrig = true;
            setOriginalPropertyValues();
        }
    }