Ejemplo n.º 1
0
    public List <GameObject> GenerateGraph()
    {
        GameObject fromN    = theGraph.CreateNode(nodePrefab, null);
        WMG_Node   fromNode = fromN.GetComponent <WMG_Node>();

        return(GenerateGraphFromNode(fromNode));
    }
Ejemplo n.º 2
0
 // Used for other graphs
 public WMG_Legend_Entry createLegendEntry(Object prefab, WMG_Series series, int index)
 {
     GameObject obj = Instantiate(prefab) as GameObject;
     theGraph.changeSpriteParent(obj, entriesParent);
     WMG_Legend_Entry entry = obj.GetComponent<WMG_Legend_Entry>();
     entry.seriesRef = series;
     entry.legend = this;
     entry.nodeLeft = theGraph.CreateNode(emptyPrefab, obj);
     entry.nodeRight = theGraph.CreateNode(emptyPrefab, obj);
     //		_legendEntrySpacing = theGraph.getSpritePositionX(entry.label);
     legendEntries.Insert(index, entry);
     return entry;
 }
Ejemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        UIEventListener.Get(background).onDrag   += OnMapBackgroundDragged;
        UIEventListener.Get(background).onScroll += OnMapBackgroundScrolled;
        theMap                     = MapManagerObject.GetComponent <WMG_Graph_Manager>();
        theMapGenerator            = MapManagerObject.GetComponent <WMG_Random_Graph>();
        theMapGenerator.nodePrefab = NodePrefab;
        theMapGenerator.linkPrefab = LinkPrefab;
        CurrentNode                = theMap.CreateNode(NodePrefab, PanParentObject);
//		CurrentNode.transform.parent = PanParentObject.transform;
        WMG_Node_World_Map startNode = CurrentNode.GetComponent <WMG_Node_World_Map>();

        theMap.SetActive(startNode.SelectionObject, true);
        theMapGenerator.GenerateGraphFromNode(startNode);

        foreach (GameObject child in theMap.LinksParent)
        {
            theMap.SetActive(child, false);
        }
        foreach (GameObject child in theMap.NodesParent)
        {
            UIEventListener.Get(child).onClick += OnNodeClick;
            UIEventListener.Get(child).onHover += OnNodeHover;
            WMG_Node_World_Map aNode = child.GetComponent <WMG_Node_World_Map>();
            AnimateSelection(aNode);
            if (aNode.id != startNode.id)
            {
                theMap.SetActive(child, false);
            }
        }
        ActivateNeighbors(startNode);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Creates a legend entry, used in axis graphs.
    /// </summary>
    /// <returns>The legend entry.</returns>
    /// <param name="prefab">Prefab.</param>
    /// <param name="series">Series.</param>
    /// <param name="index">Index.</param>
    public WMG_Legend_Entry createLegendEntry(Object prefab, WMG_Series series, int index)
    {
        GameObject obj = Instantiate(prefab) as GameObject;

        // 3/25일 clone 복제 안하게 되면서 아래 주석처리함 -> 4/5 다시 복구
        theGraph.changeSpriteParent(obj, entriesParent);

        WMG_Legend_Entry entry = obj.GetComponent <WMG_Legend_Entry>();

        entry.seriesRef = series;
        entry.legend    = this;
        entry.nodeLeft  = theGraph.CreateNode(emptyPrefab, obj);
        entry.nodeRight = theGraph.CreateNode(emptyPrefab, obj);
        legendEntries.Insert(index, entry);
        return(entry);
    }
Ejemplo n.º 5
0
    // Used for other graphs
    public WMG_Legend_Entry createLegendEntry(Object prefab, WMG_Series series, int index)
    {
        GameObject obj = Instantiate(prefab) as GameObject;

        theGraph.changeSpriteParent(obj, entriesParent);
        WMG_Legend_Entry entry = obj.GetComponent <WMG_Legend_Entry>();

        entry.seriesRef = series;
        entry.legend    = this;
        entry.nodeLeft  = theGraph.CreateNode(emptyPrefab, obj);
        entry.nodeRight = theGraph.CreateNode(emptyPrefab, obj);
        if (theGraph.isDaikon())
        {
            theGraph.changeSpritePivot(entry.nodeLeft, WMG_Graph_Manager.WMGpivotTypes.Center);
            theGraph.changeSpritePivot(entry.nodeRight, WMG_Graph_Manager.WMGpivotTypes.Center);
        }
        legendEntrySpacing = theGraph.getSpritePositionX(entry.label);
        legendEntries.Insert(index, entry);
        return(entry);
    }
Ejemplo n.º 6
0
    public void refreshGraph(float animateDuration)
    {
        // Find the total number of slices
        bool isOtherSlice = false;

        numSlices = sliceValues.Count;
        if (limitNumberSlices)
        {
            if (numSlices > maxNumberSlices)
            {
                numSlices = maxNumberSlices;
                if (includeOthers)
                {
                    isOtherSlice = true;
                    numSlices++;
                }
            }
        }
        // Create pie slices based on sliceValues data
        for (int i = 0; i < numSlices; i++)
        {
            if (sliceLabels.Count <= i)
            {
                sliceLabels.Add("");
            }
            if (sliceColors.Count <= i)
            {
                sliceColors.Add(Color.white);
            }
            if (slices.Count <= i)
            {
                GameObject curObj = theGraph.CreateNode(nodePrefab, slicesParent);
//				curObj.transform.parent = slicesParent.transform;
                slices.Add(curObj);
            }
            if (sliceLegendEntries.Count <= i)
            {
                GameObject curObj = theGraph.CreateNode(legendEntryPrefab, legendParent);
//				curObj.transform.parent = legendParent.transform;
                sliceLegendEntries.Add(curObj);
            }
            if (slicePercents.Count <= i)
            {
                slicePercents.Add(0);
            }
            if (sliceExplodeAngles.Count <= i)
            {
                sliceExplodeAngles.Add(0);
            }
        }
        // Find Other Slice Value and Total Value
        float otherSliceValue = 0;
        float totalVal        = 0;

        for (int i = 0; i < sliceValues.Count; i++)
        {
            totalVal += sliceValues[i];
            if (isOtherSlice && i >= maxNumberSlices)
            {
                otherSliceValue += sliceValues[i];
            }
            if (limitNumberSlices && !isOtherSlice && i >= maxNumberSlices)
            {
                totalVal -= sliceValues[i];
            }
        }

        // If there are more sliceLegendEntries or slices than sliceValues data, delete the extras
        for (int i = sliceLegendEntries.Count - 1; i >= 0; i--)
        {
            if (sliceLegendEntries[i] != null && i >= numSlices)
            {
                WMG_Node theEntry = sliceLegendEntries[i].GetComponent <WMG_Node>();
                theGraph.DeleteNode(theEntry);
                sliceLegendEntries.RemoveAt(i);
            }
        }
        for (int i = slices.Count - 1; i >= 0; i--)
        {
            if (slices[i] != null && i >= numSlices)
            {
                WMG_Node theSlice = slices[i].GetComponent <WMG_Node>();
                theGraph.DeleteNode(theSlice);
                slices.RemoveAt(i);
            }
        }

        // Update Legend Background
        if (legendType != labelTypes.None && !theGraph.activeInHierarchy(legendParent))
        {
            theGraph.SetActive(legendParent, true);
        }
        if (legendType == labelTypes.None && theGraph.activeInHierarchy(legendParent))
        {
            theGraph.SetActive(legendParent, false);
        }
        changeSpriteWidth(legendBackground, Mathf.RoundToInt(legendWidth));
        changeSpriteHeight(legendBackground, Mathf.RoundToInt(10 + legendRowHeight * numSlices));
        WMG_Node legendSlice = slices[0].GetComponent <WMG_Node>();

        if (legendLocation == legendLocations.Right)
        {
            legendParent.transform.localPosition = new Vector3(getSpriteWidth(legendBackground) / 2 + getSpriteWidth(legendSlice.objectToColor) / 2 + 20, 0, legendParent.transform.localPosition.z);
        }
        else if (legendLocation == legendLocations.Left)
        {
            legendParent.transform.localPosition = new Vector3(-getSpriteWidth(legendBackground) / 2 - getSpriteWidth(legendSlice.objectToColor) / 2 - 20, 0, legendParent.transform.localPosition.z);
        }
        else if (legendLocation == legendLocations.Below)
        {
            legendParent.transform.localPosition = new Vector3(0, -getSpriteHeight(legendBackground) / 2 - getSpriteHeight(legendSlice.objectToColor) / 2 - 20, legendParent.transform.localPosition.z);
        }

        float curTotalRot = 0;

        for (int i = 0; i < numSlices; i++)
        {
            // Update Legend Entries
            sliceLegendEntries[i].transform.localPosition = new Vector3(-getSpriteWidth(legendBackground) / 2 + 30, getSpriteHeight(legendBackground) / 2 - 25 - i * 40, 0);
            WMG_Node sliceLegend       = sliceLegendEntries[i].GetComponent <WMG_Node>();
            UISprite sliceLegendSprite = sliceLegend.objectToColor.GetComponent <UISprite>();
            float    numberToMult      = Mathf.Pow(10f, numberDecimalsInPercents + 2);

            // Update Pie Slices
            float newAngle = -1 * curTotalRot;
            if (newAngle < 0)
            {
                newAngle += 360;
            }
            WMG_Node pieSlice = slices[i].GetComponent <WMG_Node>();
            if (sliceLabelType != labelTypes.None && !theGraph.activeInHierarchy(pieSlice.objectToLabel))
            {
                theGraph.SetActive(pieSlice.objectToLabel, true);
            }
            if (sliceLabelType == labelTypes.None && theGraph.activeInHierarchy(pieSlice.objectToLabel))
            {
                theGraph.SetActive(pieSlice.objectToLabel, false);
            }

            // Set Slice Data and maybe Other Slice Data
            float slicePercent = sliceValues[i] / totalVal;
            if (isOtherSlice && i == numSlices - 1)
            {
                slicePercent = otherSliceValue / totalVal;
                StartCoroutine(AnimateSpriteFill(i, animateDuration, slicePercent, newAngle, numSlices - 1, includeOthersColor));                 // Animate fill and rotation of slice sprites
                setLabelData(sliceLegend.objectToLabel, legendType, includeOthersLabel, slicePercent, otherSliceValue, numberToMult);
                setLabelData(pieSlice.objectToLabel, sliceLabelType, includeOthersLabel, slicePercent, otherSliceValue, numberToMult);
                sliceLegendSprite.color = includeOthersColor;
            }
            else
            {
                StartCoroutine(AnimateSpriteFill(i, animateDuration, slicePercent, newAngle, numSlices - 1, sliceColors[i]));                 // Animate fill and rotation of slice sprites
                setLabelData(sliceLegend.objectToLabel, legendType, sliceLabels[i], slicePercent, sliceValues[i], numberToMult);
                setLabelData(pieSlice.objectToLabel, sliceLabelType, sliceLabels[i], slicePercent, sliceValues[i], numberToMult);
                sliceLegendSprite.color = sliceColors[i];
            }

            curTotalRot += slicePercent * 360;
        }
    }