示例#1
0
    void setLabelData(GameObject theLabel, labelTypes theLabelType, string labelText, float slicePercent, float sliceValue, float numberToMult)
    {
        UILabel theUILabel = theLabel.GetComponent <UILabel>();
        string  theText    = labelText;

        if (theLabelType == labelTypes.Labels_Percents)
        {
            theText += " (" + (Mathf.Round(slicePercent * numberToMult) / numberToMult * 100).ToString() + "%)";
        }
        else if (theLabelType == labelTypes.Labels_Values)
        {
            theText += " (" + Mathf.Round(sliceValue).ToString() + ")";
        }
        else if (theLabelType == labelTypes.Labels_Values_Percents)
        {
            theText += " - " + Mathf.Round(sliceValue).ToString() + " (" + (Mathf.Round(slicePercent * numberToMult) / numberToMult * 100).ToString() + "%)";
        }
        else if (theLabelType == labelTypes.Values_Only)
        {
            theText = Mathf.Round(sliceValue).ToString();
        }
        else if (theLabelType == labelTypes.Percents_Only)
        {
            theText = (Mathf.Round(slicePercent * numberToMult) / numberToMult * 100).ToString() + "%";
        }
        else if (theLabelType == labelTypes.Values_Percents)
        {
            theText = Mathf.Round(sliceValue).ToString() + " (" + (Mathf.Round(slicePercent * numberToMult) / numberToMult * 100).ToString() + "%)";
        }
        theUILabel.text = theText;
    }
示例#2
0
	public void ChangeOrientationEnd(labelTypes tLabelType, float tAxisMaxValue, float tAxisMinValue, int tAxisNumTicks, int tnumDecimalsAxisLabels,
	                                 bool tMinAutoGrow, bool tMaxAutoGrow, bool tMinAutoShrink, bool tMaxAutoShrink,
	                                 bool tSetLabelsUsingMaxMin, float tAxisLabelSpacing, string tAxisTitleString, List<string> tLabels, bool tHideTicks) {
		LabelType = tLabelType;
		AxisMaxValue = tAxisMaxValue;
		AxisMinValue = tAxisMinValue;
		AxisNumTicks = tAxisNumTicks;
		hideTicks = tHideTicks;
		numDecimalsAxisLabels = tnumDecimalsAxisLabels;
		MinAutoGrow = tMinAutoGrow;
		MaxAutoGrow = tMaxAutoGrow;
		MinAutoShrink = tMinAutoShrink;
		MaxAutoShrink = tMaxAutoShrink;
		SetLabelsUsingMaxMin = tSetLabelsUsingMaxMin;
		AxisLabelSpacing = tAxisLabelSpacing;
		AxisTitleString = tAxisTitleString;
		axisLabels.SetList(tLabels);
	}
示例#3
0
    void SetAxisLabels(	bool isY, GameObject AxisLabelObjs, ref List<string> AxisLabels, int numTicks, bool hideTick, 
	                   int axisTick, bool hideLabels, float labelSize, bool setUsingMaxMin, float axisMax, float axisMin, int numDecimals,
	                   ref float AxisLabelSpacing, float AxisLength, labelTypes LabelType)
    {
        // Calculate the number of labels we have
        int numLabels = 0;
        if (isY) {
            if (LabelType == labelTypes.ticks) numLabels = numTicks;
            else if (LabelType == labelTypes.ticks_center) numLabels = numTicks - 1;
            else if (LabelType == labelTypes.groups) numLabels = groups.Count;
            else numLabels = AxisLabels.Count;
        }
        else {
            if (LabelType == labelTypes.ticks) numLabels = numTicks;
            else if (LabelType == labelTypes.ticks_center) numLabels = numTicks - 1;
            else if (LabelType == labelTypes.groups) numLabels = groups.Count;
            else numLabels = AxisLabels.Count;
        }

        // Update spacing between labels
        float distBetween = getDistBetween(groups.Count);
        if (isY) {
            if (LabelType == labelTypes.ticks) yAxisLabelDistBetween = AxisLength / (numLabels - 1);
            else if (LabelType == labelTypes.ticks_center) yAxisLabelDistBetween = AxisLength / numLabels;
            else if (LabelType == labelTypes.groups) yAxisLabelDistBetween = distBetween;
        }
        else {
            if (LabelType == labelTypes.ticks) xAxisLabelDistBetween = AxisLength / (numLabels - 1);
            else if (LabelType == labelTypes.ticks_center) xAxisLabelDistBetween = AxisLength / numLabels;
            else if (LabelType == labelTypes.groups) xAxisLabelDistBetween = distBetween;
        }

        // Actually create or delete the labels and apply the spacing
        WMG_Grid axisLabelGrid = AxisLabelObjs.GetComponent<WMG_Grid>();
        if (isY) {
            axisLabelGrid.gridNumNodesY = numLabels;
            axisLabelGrid.gridLinkLengthY = yAxisLabelDistBetween;
            axisLabelGrid.Refresh();
        }
        else {
            axisLabelGrid.gridNumNodesX = numLabels;
            axisLabelGrid.gridLinkLengthX = xAxisLabelDistBetween;
            axisLabelGrid.Refresh();
        }

        // Create or delete strings based on number of labels
        for (int i = 0; i < numLabels; i++) {
            if (AxisLabels.Count <= i) {
                AxisLabels.Add("");
            }
        }
        for (int i = AxisLabels.Count - 1; i >= 0; i--) {
            if (i >= numLabels) {
                AxisLabels.RemoveAt(i);
            }
        }

        // Update xSpacingx and ySpacingy
        if (LabelType == labelTypes.ticks) AxisLabelSpacing = 0;
        else if (LabelType == labelTypes.ticks_center) {
            if (numTicks == 1) AxisLabelSpacing = 0;
            else AxisLabelSpacing = AxisLength / (numTicks - 1) / 2;
        }
        else if (LabelType == labelTypes.groups) {
            if (groupsCentered) {
                AxisLabelSpacing = distBetween / 2;
                if (graphType == graphTypes.bar_side) {
                    AxisLabelSpacing += lineSeries.Count * barWidth / 2;
                }
                else if (graphType == graphTypes.bar_stacked) {
                    AxisLabelSpacing += barWidth / 2;
                }
                else if (graphType == graphTypes.bar_stacked_percent) {
                    AxisLabelSpacing += barWidth / 2;
                }
                if (isY) AxisLabelSpacing += 2; // todo
            }
            else AxisLabelSpacing = 0;
        }

        // Position the label parent objects
        if (isY) {
            if (!yAxisTicksRight) {
                changeSpritePositionToX(AxisLabelObjs, yAxisPercentagePosition * xAxisLength - tickSize.y / 2 - axisWidth / 2);
            }
            else {
                changeSpritePositionToX(AxisLabelObjs, yAxisPercentagePosition * xAxisLength + axisWidth / 2);
            }
        }
        else {
            if (!xAxisTicksAbove) {
                changeSpritePositionToY(AxisLabelObjs, xAxisPercentagePosition * yAxisLength - tickSize.y / 2 - axisWidth / 2);
            }
            else {
                changeSpritePositionToY(AxisLabelObjs, xAxisPercentagePosition * yAxisLength + axisWidth / 2);
            }
        }

        // Get the label objects, change their position, and set their text
        List<WMG_Node> LabelNodes = null;
        if (isY) LabelNodes = getYAxisLabels();
        else LabelNodes = getXAxisLabels();

        if (LabelNodes == null) return;

        for (int i = 0; i < AxisLabels.Count; i++) {
            if (i >= LabelNodes.Count) break;

            // Hide labels
            SetActive(LabelNodes[i].gameObject,!hideLabels);
            // Hide label that is the same as the axis
            if (LabelType == labelTypes.ticks) {
                if (hideTick && i == axisTick) SetActive(LabelNodes[axisTick].gameObject,false);
            }

            // Position the labels
            if (isY) {
                LabelNodes[i].objectToLabel.transform.localEulerAngles = new Vector3(0, 0, yAxisLabelRotation);
                if (!yAxisTicksRight) {
                    changeSpritePivot(LabelNodes[i].objectToLabel, WMG_Graph_Manager.WMGpivotTypes.Right);
                    changeSpritePositionTo(LabelNodes[i].objectToLabel, new Vector3(-yAxisLabelSpacingX, yAxisLabelSpacingY, 0));
                }
                else {
                    changeSpritePivot(LabelNodes[i].objectToLabel, WMG_Graph_Manager.WMGpivotTypes.Left);
                    changeSpritePositionTo(LabelNodes[i].objectToLabel, new Vector3(yAxisLabelSpacingX, yAxisLabelSpacingY, 0));
                }
            }
            else {
                LabelNodes[i].objectToLabel.transform.localEulerAngles = new Vector3(0, 0, xAxisLabelRotation);
                if (!xAxisTicksAbove) {
                    changeSpritePivot(LabelNodes[i].objectToLabel, WMG_Graph_Manager.WMGpivotTypes.Center);
                    changeSpritePositionTo(LabelNodes[i].objectToLabel, new Vector3(xAxisLabelSpacingX, -xAxisLabelSpacingY, 0));
                }
                else {
                    changeSpritePivot(LabelNodes[i].objectToLabel, WMG_Graph_Manager.WMGpivotTypes.Center);
                    changeSpritePositionTo(LabelNodes[i].objectToLabel, new Vector3(xAxisLabelSpacingX, xAxisLabelSpacingY, 0));
                }
            }

            // Scale the labels
            LabelNodes[i].objectToLabel.transform.localScale = new Vector3(labelSize, labelSize, 1);

            // Set the labels
            if (setUsingMaxMin) {
                float num = axisMin + i * (axisMax - axisMin) / (LabelNodes.Count-1);
                if (i == 0) num = axisMin;

                if (graphType == graphTypes.bar_stacked_percent && ((isY && orientationType == orientationTypes.vertical)
                                                                    || (!isY && orientationType == orientationTypes.horizontal))) {
                    num = i / (LabelNodes.Count-1f) * 100f;
                }
                float numberToMult = Mathf.Pow(10f, numDecimals);

                AxisLabels[i] = (Mathf.Round(num*numberToMult)/numberToMult).ToString();
                if (graphType == graphTypes.bar_stacked_percent && ((isY && orientationType == orientationTypes.vertical)
                                                                    || (!isY && orientationType == orientationTypes.horizontal))) {
                    AxisLabels[i] += "%";
                }
            }
            if (LabelType == labelTypes.groups) {
                AxisLabels[i] = groups[i];
            }

            changeLabelText(LabelNodes[i].objectToLabel, AxisLabels[i]);
        }
    }