Example #1
0
    ///<summary>Instantiates emptyGraphPrefab (pie graph) and initializes it.</summary>
    void InitializeGraph()
    {
        GameObject graphGO = base.InstantiateGraph();

        graph = graphGO.GetComponent <WMG_Pie_Graph> ();
        graph.Init();
    }
    void Hello()
    {
        pieGraph = transform.Find("PieGraphData").GetComponent <WMG_Pie_Graph>();

        pieGraph.Init();

        pieGraph.resizeEnabled = true;

        pieGraph.explodeLength = 1.1f;         //饼块分离程度为0,意思为不分离

        pieGraph.useDoughnut = true;           //中间掏空

        pieGraph.doughnutPercentage = 0.4f;    //掏空大小

        pieGraph.autoCenter = true;            //自动居中

        pieGraph.autoCenterMinPadding = 41.4f; //自动居中后插孔填充背景

        pieGraph.bgCircleOffset = 4.7f;

        pieGraph.sliceLabelType = WMG_Enums.labelTypes.Labels_Percents; //显示标题和百分比

        pieGraph.sortBy = WMG_Pie_Graph.sortMethod.None;                //摆放顺序

        //调整标签
        pieGraph.sliceLabelExplodeLength = 35;

        pieGraph.sliceLabelFontSize = 15;

        pieGraph.numberDecimalsInPercents = 1;

        pieGraph.sliceLabelColor = new Color32(73, 181, 255, 255);
    }
Example #3
0
 void WMG_Pie_Legend_Entry_Click_2(GameObject go)
 {
     if (WMG_Pie_Legend_Entry_Click != null)
     {
         WMG_Pie_Graph pieGraph = go.GetComponent <WMG_Legend_Entry>().legend.theGraph.GetComponent <WMG_Pie_Graph>();
         WMG_Pie_Legend_Entry_Click(pieGraph, go.GetComponent <WMG_Legend_Entry>());
     }
 }
Example #4
0
 private void WMG_Pie_Legend_Entry_Click_2(GameObject go, PointerEventData pointerEventData)
 {
     if (WMG_Pie_Legend_Entry_Click != null)
     {
         WMG_Pie_Graph pieGraph = go.GetComponent <WMG_Legend_Entry>().legend.theGraph.GetComponent <WMG_Pie_Graph>();
         WMG_Pie_Legend_Entry_Click(pieGraph, go.GetComponent <WMG_Legend_Entry>(), pointerEventData);
     }
 }
    // Use this for initialization
    void Start()
    {
        GameObject graphGO = GameObject.Instantiate(emptyPiePrefab);

        graphGO.transform.SetParent(this.transform, false);
        pieGraph = graphGO.GetComponent <WMG_Pie_Graph>();

        pieGraph.Init(); // Important this gets called before setting data
    }
	void myPieSliceHoverFunction(WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice, bool hover) {
		//Debug.Log("Pie Slice Hover: " + pieGraph.sliceLabels[aSlice.sliceIndex]);
		if (hover) {
			Vector3 newPos = graph.getPositionFromExplode(aSlice, 30);
			WMG_Anim.animPosition(aSlice.gameObject, 1, DG.Tweening.Ease.OutQuad, newPos);
		}
		else {
			Vector3 newPos = graph.getPositionFromExplode(aSlice, 0);
			WMG_Anim.animPosition(aSlice.gameObject, 1, DG.Tweening.Ease.OutQuad, newPos);
		}
	}
Example #7
0
 void TooltipLegendLinkMouseEnter(WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice, bool state)
 {
     Debug.Log("========= : " + state);
     if (state)
     {
         WMG_Anim.animScale(aSlice.gameObject, 0.5f, Ease.Linear, Vector3.one * 1.2f, 0);
     }
     else
     {
         WMG_Anim.animScale(aSlice.gameObject, 0.5f, Ease.Linear, Vector3.one, 0);
     }
 }
    // Use this for initialization
    void Start()
    {
        GameObject graphGO = GameObject.Instantiate(emptyPiePrefab);

        graphGO.transform.SetParent(this.transform, false);
        pieGraph = graphGO.GetComponent <WMG_Pie_Graph>();

        pieGraph.Init();         // Important this gets called before setting data

        pieGraph.sliceValues.SetList(testData);
        pieGraph.sliceLabels.SetList(testStrings);
    }
Example #9
0
    // Use this for initialization
    void Start()
    {
        GameObject pieGraphObj = Instantiate <WMG_Pie_Graph>(pieGraphPrefab).gameObject;

        pieGraphObj.transform.SetParent(GameObject.Find("Canvas").transform, worldPositionStays: false);
        pieGraphObj.GetComponent <RectTransform>().sizeDelta     = pieGraphObj.transform.parent.GetComponent <RectTransform>().rect.size *0.3f; //全屏
        pieGraphObj.GetComponent <RectTransform>().localPosition = new Vector2(-604.6f, 119f);
        WMG_Pie_Graph pieGraph = pieGraphObj.GetComponent <WMG_Pie_Graph>();

        pieGraph.Init();

        //Debug.Log(pieGraph.gameObject.name);
        WMG_List <float> pieValues = new WMG_List <float>()
        {
            60f, 80f, 75f, 90f, 100f, 85f, 95f
        };
        WMG_List <string> pieLabels = new WMG_List <string>()
        {
            "One", "Two", "Three", "Four", "Five", "Six", "Seven"
        };
        WMG_List <Color> pieColor = new WMG_List <Color>()
        {
            Color.red, Color.yellow, Color.green, Color.blue, Color.cyan, Color.black
        };

        //pieGraph.resizeEnabled = true;

        ///////pieGraph.sliceValues = pieValues;  Debug.Log("草泥马有几个:" + pieGraph.sliceValues.Count);
        ////////pieGraph.sliceLabels = pieLabels;  //不能直接改变量,要用内置函数去改
        ////////pieGraph.sliceColors = pieColor;
        pieGraph.sliceValues.SetList(pieValues);
        pieGraph.sliceLabels.SetList(pieLabels);
        pieGraph.sliceColors.SetList(pieColor);

        pieGraph.sliceLabelExplodeLength = -10f;
        pieGraph.autoCenter = false;
        //pieGraph.autoCenterMinPadding = 10f;
        //pieGraph.bgCircleOffset = 80f;
        pieGraph.sortBy        = WMG_Pie_Graph.sortMethod.None;
        pieGraph.explodeLength = 1f;
        //pieGraph.explodeSymmetrical = false;
        pieGraph.sliceLabelFontSize       = 10;
        pieGraph.numberDecimalsInPercents = 1;


        pieGraph.interactivityEnabled        = true;
        pieGraph.WMG_Pie_Slice_Click        += SliceClickEvent;
        pieGraph.WMG_Pie_Legend_Entry_Click += SliceLegendEntryClickEvent;
        pieGraph.WMG_Pie_Slice_MouseEnter   += TooltipLegendLinkMouseEnter;

        //pieGraph.Refresh();
    }
 void myPieSliceHoverFunction(WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice, bool hover)
 {
     //GlobalVariableBackground.Instance.conManager.WriteLog("Pie Slice Hover: " + pieGraph.sliceLabels[aSlice.sliceIndex]);
     if (hover)
     {
         Vector3 newPos = graph.getPositionFromExplode(aSlice, 30);
         WMG_Anim.animPosition(aSlice.gameObject, 1, DG.Tweening.Ease.OutQuad, newPos);
     }
     else
     {
         Vector3 newPos = graph.getPositionFromExplode(aSlice, 0);
         WMG_Anim.animPosition(aSlice.gameObject, 1, DG.Tweening.Ease.OutQuad, newPos);
     }
 }
 void myPieSliceHoverFunction(WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice, bool hover)
 {
     //Debug.Log("Pie Slice Hover: " + pieGraph.sliceLabels[aSlice.sliceIndex]);
     if (hover)
     {
         Vector3 newPos = graph.getPositionFromExplode(aSlice, 30);
         WMG_Anim.animPosition(aSlice.gameObject, 1, DG.Tweening.Ease.OutQuad, newPos);
     }
     else
     {
         Vector3 newPos = graph.getPositionFromExplode(aSlice, 0);
         WMG_Anim.animPosition(aSlice.gameObject, 1, DG.Tweening.Ease.OutQuad, newPos);
     }
 }
	// Use this for initialization
	void Start () {
		GameObject graphGO = GameObject.Instantiate(pieGraphPrefab) as GameObject;
		graphGO.transform.SetParent(this.transform, false);
		graph = graphGO.GetComponent<WMG_Pie_Graph>();

		graph.Init(); // Call Init() to ensure things are initialized

		// lets create an interactive doughnut chart
		graph.interactivityEnabled = true;
		graph.useDoughnut = true;
		graph.doughnutPercentage = 0.5f;
		graph.explodeLength = 0;
		graph.WMG_Pie_Slice_Click += myPieSliceClickFunction;
		graph.WMG_Pie_Slice_MouseEnter += myPieSliceHoverFunction;
	}
Example #13
0
    public void Init()
    {
        if (hasInit) return;
        hasInit = true;

        pieGraph = theGraph.GetComponent<WMG_Pie_Graph>();
        axisGraph = theGraph.GetComponent<WMG_Axis_Graph>();

        changeObjs.Add(legendC);

        setOriginalPropertyValues();

        legendC.OnChange += LegendChanged;

        PauseCallbacks();
    }
    // Use this for initialization
    void Start()
    {
        GameObject graphGO = GameObject.Instantiate(pieGraphPrefab) as GameObject;

        graphGO.transform.SetParent(this.transform, false);
        graph = graphGO.GetComponent <WMG_Pie_Graph>();

        graph.Init();         // Call Init() to ensure things are initialized

        // lets create an interactive doughnut chart
        graph.interactivityEnabled      = true;
        graph.useDoughnut               = true;
        graph.doughnutPercentage        = 0.5f;
        graph.explodeLength             = 0;
        graph.WMG_Pie_Slice_Click      += myPieSliceClickFunction;
        graph.WMG_Pie_Slice_MouseEnter += myPieSliceHoverFunction;
    }
    // Use this for initialization
    void Awake()
    {
        pieGraphGF = transform.Find("PieGraphGF").GetComponent <WMG_Pie_Graph>();
        pieGraphCN = transform.Find("PieGraphCN").GetComponent <WMG_Pie_Graph>();
        pieGraphDW = transform.Find("PieGraphDW").GetComponent <WMG_Pie_Graph>();

        GF_Percent = transform.Find("PieGraphGF/Text").GetComponent <Text>();
        CN_Percent = transform.Find("PieGraphCN/Text").GetComponent <Text>();
        DW_Percent = transform.Find("PieGraphDW/Text").GetComponent <Text>();

        GF = transform.Find("PieGraphGF/Textkwh").GetComponent <Text>();
        CN = transform.Find("PieGraphCN/Textkwh").GetComponent <Text>();
        DW = transform.Find("PieGraphDW/Textkwh").GetComponent <Text>();

        //circleGF = transform.Find("CircleGF");
        //circleCN = transform.Find("CircleCN");
        //circleDW = transform.Find("CircleDW");

        Hello();
        GetData();
    }
Example #16
0
 void myPieSliceHoverFunction(WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice, bool hover)
 {
     Debug.Log("Pie Slice Hover: " + pieGraph.sliceLabels[aSlice.sliceIndex]);
     if (hover)
     {
         Vector3 newPos = graph.getPositionFromExplode(aSlice, 15);
         graph.WMG_Pie_Slice_MouseEnter -= myPieSliceHoverFunction;
         WMG_Anim.animPositionCallbackC(aSlice.gameObject, 1, DG.Tweening.Ease.OutQuad, newPos, () =>
         {
             graph.WMG_Pie_Slice_MouseEnter += myPieSliceHoverFunction;
         });
     }
     else
     {
         Vector3 newPos = graph.getPositionFromExplode(aSlice, 0);
         graph.WMG_Pie_Slice_MouseEnter -= myPieSliceHoverFunction;
         WMG_Anim.animPositionCallbackC(aSlice.gameObject, 1, DG.Tweening.Ease.OutQuad, newPos, () =>
         {
             graph.WMG_Pie_Slice_MouseEnter += myPieSliceHoverFunction;
         });
     }
 }
	void myPieSliceClickFunction(WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice) {
		//Debug.Log("Pie Slice Clicked: " + pieGraph.sliceLabels[aSlice.sliceIndex]);
	}
Example #18
0
 void SliceClickEvent(WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice)
 {
     Debug.Log("== : " + aSlice.name);
     WMG_Anim.animScale(aSlice.gameObject, 0.5f, Ease.Linear, Vector3.one * 0.8f, 0);
 }
Example #19
0
	public void Init() {
		if (hasInit) return;
		hasInit = true;

		pieGraph = theGraph.GetComponent<WMG_Pie_Graph>();
		axisGraph = theGraph.GetComponent<WMG_Axis_Graph>();
		
		changeObjs.Add(legendC);
		
		setOriginalPropertyValues();
		
		legendC.OnChange += LegendChanged;

		PauseCallbacks();
	}
	void OnEnable()
	{
		graph = (WMG_Pie_Graph)target;
		fields = GetProperties(graph);
	}
Example #21
0
 void SliceLegendEntryClickEvent(WMG_Pie_Graph pieGraph, WMG_Legend_Entry legendEntry)
 {
     Debug.Log("====");
 }
 void myPieSliceClickFunction(WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice)
 {
     //Debug.Log("Pie Slice Clicked: " + pieGraph.sliceLabels[aSlice.sliceIndex]);
 }
Example #23
0
 void myPieLegendEntryClickFunction(WMG_Pie_Graph pieGraph, WMG_Legend_Entry legendEntry, UnityEngine.EventSystems.PointerEventData pointerEventData)
 {
     //Debug.Log("Pie Legend Entry Clicked: " + legendEntry.name);
 }
Example #24
0
 void myPieSliceClickFunction(WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice, UnityEngine.EventSystems.PointerEventData pointerEventData)
 {
     //Debug.Log("Pie Slice Clicked: " + pieGraph.sliceLabels[aSlice.sliceIndex]);
 }
Example #25
0
 void OnEnable()
 {
     graph  = (WMG_Pie_Graph)target;
     fields = GetProperties(graph);
 }
Example #26
0
 void myPieLegendEntryClickFunction(WMG_Pie_Graph pieGraph, WMG_Legend_Entry legendEntry)
 {
     //Debug.Log("Pie Legend Entry Clicked: " + legendEntry.name);
 }
 void myPieSliceClickFunction(WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice)
 {
     //GlobalVariableBackground.Instance.conManager.WriteLog("Pie Slice Clicked: " + pieGraph.sliceLabels[aSlice.sliceIndex]);
 }
Example #28
0
 public void Init(WMG_Pie_Graph graph)
 {
     this.graph  = graph;
     positioning = new GraphPositioning(graph as WMG_Graph_Manager);
 }
Example #29
0
    public void updateLegend()
    {
        if (legendTypeChanged || legendChanged)
        {
            if (!hideLegend && showBackground && !theGraph.activeInHierarchy(background))
            {
                theGraph.SetActive(background, true);
            }
            if ((hideLegend || !showBackground) && theGraph.activeInHierarchy(background))
            {
                theGraph.SetActive(background, false);
            }
            if (!hideLegend && !theGraph.activeInHierarchy(entriesParent))
            {
                theGraph.SetActive(entriesParent, true);
            }
            if (hideLegend && theGraph.activeInHierarchy(entriesParent))
            {
                theGraph.SetActive(entriesParent, false);
            }
            if (hideLegend)
            {
                return;
            }

            // Swap parent offsets when changing the legend type
            if (legendTypeChanged)
            {
                theGraph.SwapVals <float>(ref offsetX, ref offsetY);
            }

            WMG_Axis_Graph axisGraph    = theGraph.GetComponent <WMG_Axis_Graph>();
            WMG_Pie_Graph  pieGraph     = theGraph.GetComponent <WMG_Pie_Graph>();
            float          graphY       = 0;
            float          graphX       = 0;
            float          maxPointSize = 0;
            if (axisGraph != null)
            {
                graphY       = axisGraph.yAxisLength;
                graphX       = axisGraph.xAxisLength;
                maxPointSize = axisGraph.getMaxPointSize();
            }
            if (pieGraph != null)
            {
                graphY       = pieGraph.pieSize + pieGraph.explodeLength;
                graphX       = graphY;
                maxPointSize = pieSwatchSize;
            }
            int numEntries = legendEntries.Count;
            for (int j = 0; j < legendEntries.Count; j++)
            {
                if (!activeInHierarchy(legendEntries[j].gameObject))
                {
                    numEntries--;
                }
            }
            int maxInRowOrColumn = Mathf.CeilToInt(1f * numEntries / numRowsOrColumns);             // Max elements in a row for horizontal legends

            float oppositeSideOffset = 0;
            if (legendType == legendTypes.Bottom)
            {
                if (autoCenterLegend)
                {
                    offsetX = (-maxInRowOrColumn * legendEntryWidth) / 2f + legendEntryLinkSpacing + 5;
                }
                if (oppositeSideLegend)
                {
                    oppositeSideOffset = 2 * offsetY + graphY;
                }
                changeSpritePositionTo(this.gameObject, new Vector3(graphX / 2 + offsetX, -offsetY + oppositeSideOffset, 0));
            }
            else if (legendType == legendTypes.Right)
            {
                if (autoCenterLegend)
                {
                    offsetY = (-(maxInRowOrColumn - 1) * legendEntryHeight) / 2f;
                }
                if (oppositeSideLegend)
                {
                    oppositeSideOffset = -2 * offsetX - graphX - legendEntryWidth + 2 * legendEntryLinkSpacing;
                }
                changeSpritePositionTo(this.gameObject, new Vector3(graphX + offsetX + oppositeSideOffset, graphY / 2 - offsetY, 0));
            }
            if (pieGraph != null)
            {
                Vector2 offset = pieGraph.getPaddingOffset();
                changeSpritePositionRelativeToObjBy(this.gameObject, this.gameObject, new Vector3(-graphX / 2f - offset.x, -graphY / 2f - offset.y));
            }

            int numRows = maxInRowOrColumn;
            int numCols = numRowsOrColumns;

            if (legendType == legendTypes.Right)
            {
                theGraph.SwapVals <int>(ref numRows, ref numCols);
            }

            changeSpriteWidth(background, Mathf.RoundToInt(legendEntryWidth * numRows + 2 * backgroundPadding + legendEntryLinkSpacing));
            changeSpriteHeight(background, Mathf.RoundToInt(legendEntryHeight * numCols + 2 * backgroundPadding));
            changeSpritePositionTo(background, new Vector3(-backgroundPadding - legendEntryLinkSpacing - maxPointSize / 2f, backgroundPadding + legendEntryHeight / 2f));

            if (numRowsOrColumns < 1)
            {
                numRowsOrColumns = 1;                                   // Ensure not less than 1
            }
            if (numRowsOrColumns > numEntries)
            {
                numRowsOrColumns = numEntries;                                            // Ensure cannot exceed number series
            }
            int extras = 0;
            if (numEntries > 0)
            {
                extras = numEntries % numRowsOrColumns; // When the number series does not divide evenly by the num rows setting, then this is the number of extras
            }
            int  origExtras       = extras;             // Save the original extras, since we will need to decrement extras in the loop
            int  cumulativeOffset = 0;                  // Used to offset the other dimension, for example, elements moved to a lower row (y), need to also move certain distance (x) left
            int  previousI        = 0;                  // Used to determine when the i (row for horizontal) has changed from the previous i, which is used to increment the cumulative offset
            bool useSmaller       = false;              // Used to determine whether we need to subtract 1 from maxInRowOrColumn when calculating the cumulative offset

            if (maxInRowOrColumn == 0)
            {
                return;                                    // Legend hidden / all entries deactivated
            }
            // Calculate the position of the legend entry for each line series
            for (int j = 0; j < legendEntries.Count; j++)
            {
                WMG_Legend_Entry legendEntry = legendEntries[j];

                if (axisGraph != null)
                {
                    theGraph.changeSpritePositionRelativeToObjBy(legendEntry.nodeLeft, legendEntry.swatchNode, new Vector3(-legendEntryLinkSpacing, 0, 0));
                    theGraph.changeSpritePositionRelativeToObjBy(legendEntry.nodeRight, legendEntry.swatchNode, new Vector3(legendEntryLinkSpacing, 0, 0));

                    WMG_Link theLine = legendEntry.line.GetComponent <WMG_Link>();
                    theLine.Reposition();
                }
                else
                {
                    changeSpriteWidth(legendEntry.swatchNode, Mathf.RoundToInt(pieSwatchSize));
                    changeSpriteHeight(legendEntry.swatchNode, Mathf.RoundToInt(pieSwatchSize));
                }

                theGraph.changeSpritePositionToX(legendEntry.label, legendEntrySpacing);

                // Legend text
                if (axisGraph != null)
                {
                    string theText = legendEntry.seriesRef.seriesName;

                    if (labelType == WMG_Enums.labelTypes.None)
                    {
                        theText = "";
                    }
                    changeLabelText(legendEntry.label, theText);
                }
                legendEntry.label.transform.localScale = new Vector3(legendEntryFontSize, legendEntryFontSize, 1);

                // i is the row for horizontal legends, and the column for vertical
                int i = Mathf.FloorToInt(j / maxInRowOrColumn);
                if (origExtras > 0)
                {
                    i = Mathf.FloorToInt((j + 1) / maxInRowOrColumn);
                }

                // If there were extras, but no longer any more extras, then need to subtract 1 from the maxInRowOrColumn, and recalculate i
                if (extras == 0 && origExtras > 0)
                {
                    i = origExtras + Mathf.FloorToInt((j - origExtras * maxInRowOrColumn) / (maxInRowOrColumn - 1));
                    if ((j - origExtras * maxInRowOrColumn) > 0)
                    {
                        useSmaller = true;
                    }
                }

                // When there are extras decrease i for the last element in the row
                if (extras > 0)
                {
                    if ((j + 1) % maxInRowOrColumn == 0)
                    {
                        extras--;
                        i--;
                    }
                }

                // Increment cumulative offset when i changes, use offset to position other dimension correctly.
                if (previousI != i)
                {
                    previousI = i;
                    if (useSmaller)
                    {
                        cumulativeOffset += (maxInRowOrColumn - 1);
                    }
                    else
                    {
                        cumulativeOffset += maxInRowOrColumn;
                    }
                }

                // Set the position based on the series index (j), i (row index for horizontal), and cumulative offset
                if (legendType == legendTypes.Bottom)
                {
                    theGraph.changeSpritePositionTo(legendEntry.gameObject, new Vector3(j * legendEntryWidth - legendEntryWidth * cumulativeOffset, -i * legendEntryHeight, 0));
                }
                else if (legendType == legendTypes.Right)
                {
                    theGraph.changeSpritePositionTo(legendEntry.gameObject, new Vector3(i * legendEntryWidth, -j * legendEntryHeight + legendEntryHeight * cumulativeOffset, 0));
                }
            }
        }
    }
Example #30
0
 public void Init(WMG_Pie_Graph graph)
 {
     this.graph = graph;
 }
Example #31
0
    void OnEnable()
    {
//		myTarget = new SerializedObject(target);
        graph = (WMG_Pie_Graph)target;
    }
 void OnEnable()
 {
     //		myTarget = new SerializedObject(target);
     graph = (WMG_Pie_Graph)target;
 }