void updateDegrees() { if (valuesChanged || degreesChanged || minMaxChanged) { Vector3 baseRotation = new Vector3(0, 0, -degrees / 2); float newFill = (360 - degrees) / 360f; // extra ring changeRadialSpriteRotation(extraRing, baseRotation); changeSpriteFill(extraRing, newFill); // rings and bands for (int i = 0; i < rings.Count; i++) { // rings changeRadialSpriteRotation(rings[i].ring, baseRotation); changeSpriteFill(rings[i].ring, newFill); // bands float valPercent = values[i] / (maxValue - minValue); changeRadialSpriteRotation(rings[i].band, baseRotation); changeSpriteFill(rings[i].band, 0); if (animateData) { WMG_Anim.animFill(rings[i].band, animDuration, animEaseType, newFill * valPercent); } else { changeSpriteFill(rings[i].band, newFill * valPercent); } // labels rings[i].label.transform.localEulerAngles = baseRotation; rings[i].labelBackground.transform.localEulerAngles = -baseRotation; changeSpritePositionTo(rings[i].labelBackground, new Vector3(0, -15 - getSpriteHeight(rings[i].label), 0)); Vector3 labelRotation = new Vector3(0, 0, -valPercent * (360 - degrees)); if (animateData) { if (DOTween.IsTweening(rings[i].label.transform)) // if already animating, then don't animate relative to current rotation { WMG_Anim.animRotation(rings[i].label, animDuration, animEaseType, labelRotation + new Vector3(0, 0, 360) + baseRotation, false); WMG_Anim.animRotationCallbackC(rings[i].labelBackground, animDuration, animEaseType, -labelRotation - baseRotation, false, () => labelRotationCompleted(i)); } else { WMG_Anim.animRotation(rings[i].label, animDuration, animEaseType, labelRotation, true); WMG_Anim.animRotationCallbackC(rings[i].labelBackground, animDuration, animEaseType, -labelRotation, true, () => labelRotationCompleted(i)); } } else { rings[i].label.transform.localEulerAngles = labelRotation + baseRotation; rings[i].labelBackground.transform.localEulerAngles = -labelRotation - baseRotation; if (i == rings.Count - 1) { repositionLabels(); } } } // zero line zeroLine.transform.localEulerAngles = baseRotation; zeroLineText.transform.localEulerAngles = -baseRotation; } }
public void animBandFill(int ringNum, float endFill) { if (!graph.bandMode) { return; } if (!graph.useComputeShader) { WMG_Anim.animFill(band, graph.animDuration, graph.animEaseType, endFill); } else { animTimeline = 0; WMG_Anim.animFloatCallbackU(() => animTimeline, x => animTimeline = x, graph.animDuration, 1, () => onUpdateAnimateBandFill(ringNum, endFill), graph.animEaseType); } if (graph.pieMode) { WMG_Anim.animFill(interactibleObj, graph.animDuration, graph.animEaseType, endFill); } }
void UpdateVisuals(bool noAnim) { // Update internal bookkeeping variables UpdateData(); // Creates and deletes slices and slice legend objects based on the slice values CreateOrDeleteSlicesBasedOnValues(); // Update background changeSpriteHeight(background, Mathf.RoundToInt(pieSize + topBotPadding.x + topBotPadding.y)); changeSpriteWidth(background, Mathf.RoundToInt(pieSize + leftRightPadding.x + leftRightPadding.y)); changeSpriteSize(backgroundCircle, Mathf.RoundToInt(pieSize + bgCircleOffset), Mathf.RoundToInt(pieSize + bgCircleOffset)); Vector2 offset = getPaddingOffset(); changeSpritePositionTo(slicesParent, new Vector3(-offset.x, -offset.y)); 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++) { WMG_Legend_Entry entry = legend.legendEntries[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, Mathf.RoundToInt(pieSize), Mathf.RoundToInt(pieSize)); } else { int newSize = Mathf.RoundToInt(pieSize + explodeLength * 2); changeSpriteSize(pieSlice.objectToColor, newSize, newSize); changeSpriteSize(pieSlice.objectToMask, newSize + Mathf.RoundToInt(explodeLength * 4), newSize + 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; } // Hide if 0 if (sliceValue == 0) { SetActive(pieSlice.objectToLabel, false); } float slicePercent = sliceValue / totalVal; float afterExplodeAngle = newAngle * -1 + 0.5f * slicePercent * 360; float sliceLabelRadius = sliceLabelExplodeLength + pieSize / 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, getLabelText(sliceLabel, sliceLabelType, sliceValue, slicePercent, numberDecimalsInPercents)); pieSlice.objectToLabel.transform.localScale = new Vector3(sliceLabelFontSize, sliceLabelFontSize); // Update Gameobject names slices[i].name = sliceLabel; legend.legendEntries[i].name = sliceLabel; // Update legend changeLabelText(entry.label, getLabelText(sliceLabel, legend.labelType, sliceValue, slicePercent, legend.numDecimals)); changeSpriteColor(entry.swatchNode, sliceColor); // Hide legend if 0 if (sliceValue == 0) { SetActive(entry.gameObject, false); } else { SetActive(entry.gameObject, true); } curTotalRot += slicePercent * 360; } }
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, getLabelText(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, getLabelText(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.LegendChanged(); updateAutoCenter(); if (!setOrig) { setOrig = true; setOriginalPropertyValues(); } }
void updateDegreesAring(int i) { Vector3 baseRotation = new Vector3(0, 0, -degrees / 2); float newFill = (360 - degrees) / 360f; // extra ring changeRadialSpriteRotation(extraRing, baseRotation); changeSpriteFill(extraRing, newFill); bool ringIsZero = false; WMG_Ring ring = rings[i]; // rings changeRadialSpriteRotation(rings[i].ring, baseRotation); changeSpriteFill(rings[i].ring, newFill); // bands float valPercent = values[i] / (maxValue - minValue); changeRadialSpriteRotation(rings[i].band, baseRotation); changeSpriteFill(rings[i].band, 0); if (animateData) { WMG_Anim.animFill(rings[i].band, animDuration, animEaseType, newFill * valPercent); } else { changeSpriteFill(rings[i].band, newFill * valPercent); } if (valPercent == 0) { ringIsZero = true; } // labels int numOverlapping = 0; for (int j = i - 1; j >= 0; j--) { float valPercentPrev = values[j] / (maxValue - minValue); if (Mathf.Abs(valPercent - valPercentPrev) < 0.01f) // within 1% { numOverlapping++; valPercent = valPercentPrev; } } Vector3 labelRotation = new Vector3(0, 0, -valPercent * (360 - degrees)); if (animateData) { if (DOTween.IsTweening(rings[i].label.transform)) // if already animating, then don't animate relative to current rotation { updateLabelRotationAndPosition(ring, 0, numOverlapping, false); float degOffset = 90; if (ring.label.transform.localEulerAngles.z < 180) { degOffset *= -1; } WMG_Anim.animRotation(rings[i].label, animDuration, animEaseType, labelRotation + new Vector3(0, 0, 360) + baseRotation, false); WMG_Anim.animRotationCallbacks(rings[i].textLine, animDuration, animEaseType, -labelRotation - baseRotation + new Vector3(0, 0, degOffset), false, () => labelRotationUpdated(ring, degOffset, numOverlapping), () => labelRotationComplete(ring, degOffset, numOverlapping)); } else { rings[i].label.transform.localEulerAngles = baseRotation; rings[i].textLine.transform.localEulerAngles = -baseRotation + new Vector3(0, 0, 90); WMG_Anim.animRotation(rings[i].label, animDuration, animEaseType, labelRotation, true); WMG_Anim.animRotationCallbacks(rings[i].textLine, animDuration, animEaseType, -labelRotation, true, () => labelRotationUpdated(ring, 0, numOverlapping), () => labelRotationComplete(ring, 0, numOverlapping)); } } else { updateLabelLineBasedOnOverlap(ring, numOverlapping); rings[i].label.transform.localEulerAngles = labelRotation + baseRotation; rings[i].textLine.transform.localEulerAngles = -labelRotation - baseRotation + new Vector3(0, 0, 90); updateLabelRotationAndPosition(ring, 0, numOverlapping, false); } // zero line zeroLine.transform.localEulerAngles = baseRotation; zeroLineText.transform.localEulerAngles = -baseRotation; if (i == 0) { SetActive(zeroLine, !ringIsZero); } else { if (zeroLine.activeSelf) // previously not 0 { SetActive(zeroLine, !ringIsZero); } else // there was a zero at one point in the past, always hide { SetActive(zeroLine, false); } } }