示例#1
0
    private void animateLinkCallback(WMG_Series aSeries, GameObject aGO)
    {
        WMG_Node aNode   = aGO.GetComponent <WMG_Node>();
        WMG_Link theLine = aNode.links[aNode.links.Count - 1].GetComponent <WMG_Link>();

        theLine.Reposition();
        if (aSeries.connectFirstToLast)           // One extra link to animate for circles / close loop series
        {
            aNode   = aSeries.getPoints()[0].GetComponent <WMG_Node>();
            theLine = aNode.links[0].GetComponent <WMG_Link>();
            theLine.Reposition();
        }
    }
示例#2
0
 private void animateLinkCallbackEnd(WMG_Series aSeries)
 {
     for (int i = 0; i < aSeries.getLines().Count; i++)
     {
         WMG_Link theLine = aSeries.getLines()[i].GetComponent <WMG_Link>();
         theLine.Reposition();
     }
 }
示例#3
0
 /// <summary>
 /// Update the position of this node. Also repositions and rotates its links to correctly correspond with the new node position.
 /// </summary>
 /// <param name="x">The x coordinate.</param>
 /// <param name="y">The y coordinate.</param>
 public virtual void Reposition(float x, float y)
 {
     changeSpritePositionTo(this.gameObject, new Vector3(x, y, 1));
     for (int i = 0; i < numLinks; i++)
     {
         WMG_Link theLink = links[i].GetComponent <WMG_Link>();
         theLink.Reposition();
     }
 }
示例#4
0
 public void Reposition(float x, float y)
 {
     // Updates the local position of this node and all associated links
     changeSpritePositionTo(this.gameObject, new Vector3(x, y, 1));
     for (int i = 0; i < numLinks; i++)
     {
         WMG_Link theLink = links[i].GetComponent <WMG_Link>();
         theLink.Reposition();
     }
 }
示例#5
0
    // Only Used in Editor -
    public void RepositionRelativeToNode(WMG_Node fromNode, bool fixAngle, int degreeStep, float lengthStep)
    {
        // This is used to reposition the node and associated links based on a fixed angle or fixed length step relative to another node
        float posXdif = (this.transform.localPosition.x - fromNode.transform.localPosition.x);
        float posYdif = (this.transform.localPosition.y - fromNode.transform.localPosition.y);

        float angle = Mathf.Atan2(posYdif, posXdif) * Mathf.Rad2Deg;

        if (angle < 0)
        {
            angle += 360;
        }

        float length = Mathf.Sqrt(Mathf.Pow(posYdif, 2) + Mathf.Pow(posXdif, 2));

        if (length < 0)
        {
            length = 0;
        }

        float newAngle = angle;

        if (fixAngle)
        {
            newAngle = 0;
            for (int i = 0; i < 360 / degreeStep; i++)
            {
                if (angle >= i * degreeStep - 0.5f * degreeStep && angle < (i + 1) * degreeStep - 0.5f * degreeStep)
                {
                    newAngle = i * degreeStep;
                }
            }
        }
        else
        {
            float mod = length % lengthStep;
            length -= mod;
            if (lengthStep - mod < lengthStep / 2)
            {
                length += lengthStep;
            }
        }

        this.transform.localPosition = new Vector3(fromNode.transform.localPosition.x + length * Mathf.Cos(Mathf.Deg2Rad * (newAngle)),
                                                   fromNode.transform.localPosition.y + length * Mathf.Sin(Mathf.Deg2Rad * (newAngle)),
                                                   this.transform.localPosition.z);

        for (int i = 0; i < numLinks; i++)
        {
            WMG_Link theLink = links[i].GetComponent <WMG_Link>();
            theLink.Reposition();
        }
    }
示例#6
0
    public void UpdateLegendEntry()
    {
        if (legendEntryLinkSpacingChanged)
        {
            // Update legend entry lines based on legendEntryLinkSpacing
            theGraph.changeSpritePositionRelativeToObjBy(legendEntryNodeLeft, legendEntryNode, new Vector3(-legendEntryLinkSpacing, 0, 0));
            theGraph.changeSpritePositionRelativeToObjBy(legendEntryNodeRight, legendEntryNode, new Vector3(legendEntryLinkSpacing, 0, 0));

            WMG_Link theLine = legendEntryLink.GetComponent <WMG_Link>();
            theLine.Reposition();
        }
    }
	private void animateLinkCallback(WMG_Series aSeries, GameObject aGO, bool isLast) {
		WMG_Node aNode = aGO.GetComponent<WMG_Node>();
		if (aNode.links.Count != 0) {
			WMG_Link theLine = aNode.links[aNode.links.Count-1].GetComponent<WMG_Link>();
			theLine.Reposition();
		}
		if (isLast) {
			aSeries.updateAreaShading(null);
		}
		if (aSeries.connectFirstToLast) { // One extra link to animate for circles / close loop series
			aNode = aSeries.getPoints()[0].GetComponent<WMG_Node>();
			WMG_Link theLine = aNode.links[0].GetComponent<WMG_Link>();
			theLine.Reposition();
		}
	}
示例#8
0
    public void updateLegend()
    {
        if (backgroundEnabled() && !theGraph.activeInHierarchy(background))
        {
            theGraph.SetActive(background, true);
        }
        if (!backgroundEnabled() && 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;
        }

        float maxPointSize = 0;

        Vector2 entriesAnchor = Vector2.zero;
        Vector2 entriesPivot  = Vector2.zero;
        Vector2 entriesOffset = Vector2.zero;

        if (axisGraph != null)
        {
            maxPointSize = axisGraph.getMaxPointSize();
        }
        if (pieGraph != null)
        {
            maxPointSize = pieSwatchSize;
        }

        if (legendType == legendTypes.Bottom)
        {
            if (oppositeSideLegend)
            {
                entriesAnchor = new Vector2(0.5f, 1);
                entriesPivot  = entriesAnchor;
                entriesOffset = new Vector2(0, -offset);
            }
            else
            {
                entriesAnchor = new Vector2(0.5f, 0);
                entriesPivot  = entriesAnchor;
                entriesOffset = new Vector2(0, offset);
            }
        }
        else if (legendType == legendTypes.Right)
        {
            if (oppositeSideLegend)
            {
                entriesAnchor = new Vector2(0, 0.5f);
                entriesPivot  = entriesAnchor;
                entriesOffset = new Vector2(offset, 0);
            }
            else
            {
                entriesAnchor = new Vector2(1, 0.5f);
                entriesPivot  = entriesAnchor;
                entriesOffset = new Vector2(-offset, 0);
            }
        }

        // For pie graphs anchor the legend to the edge of the pie
        if (pieGraph != null)
        {
            entriesOffset = new Vector2(-1 * entriesOffset.x, -1 * entriesOffset.y);
            if (legendType == legendTypes.Bottom)
            {
                entriesPivot = new Vector2(entriesPivot.x, 1 - entriesPivot.y);
            }
            else
            {
                entriesPivot = new Vector2(1 - entriesPivot.x, entriesPivot.y);
            }
        }

        changeSpriteWidth(this.gameObject, LegendWidth);
        changeSpriteHeight(this.gameObject, LegendHeight);

        setAnchor(this.gameObject, entriesAnchor, entriesPivot, entriesOffset);

        Vector2 entriesParentOffset = new Vector2(legendEntryLinkSpacing + backgroundPadding + maxPointSize / 2f,
                                                  -legendEntryHeight / 2f + LegendHeight / 2f - backgroundPadding);

        setAnchor(entriesParent, new Vector2(0, 0.5f), new Vector2(0, 0.5f), entriesParentOffset);



        int numEntries       = NumEntries;
        int maxInRowOrColumn = MaxInRowOrColumn;         // Max elements in a row for horizontal legends

        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)
            {
                if (legendEntry.swatchNode == null)
                {
                    foreach (GameObject seriesGO in axisGraph.lineSeries)
                    {
                        seriesGO.GetComponent <WMG_Series>().CreateOrDeleteSpritesBasedOnPointValues();
                    }
                }

                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));
            }

            if (axisGraph != null)
            {
                theGraph.changeSpritePositionToX(legendEntry.label, legendEntrySpacing);
            }
            else
            {
                theGraph.changeSpritePositionToX(legendEntry.label, legendEntrySpacing + pieSwatchSize / 2);
            }

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

                if (labelType == WMG_Enums.labelTypes.None)
                {
                    theText = "";
                }
                changeLabelText(legendEntry.label, theText);
            }
            changeLabelFontSize(legendEntry.label, legendEntryFontSize);
            changeSpriteColor(legendEntry.label, labelColor);
            // Font Style
            changeLabelFontStyle(legendEntry.label, legendEntryFontStyle);
            // Font
            if (legendEntryFont != null)
            {
                changeLabelFont(legendEntry.label, legendEntryFont);
            }

            // 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));
            }
        }

        // This needs to be called after label text is set
        if (setWidthFromLabels)
        {
            if (axisGraph != null && (axisGraph.graphType == WMG_Axis_Graph.graphTypes.line || axisGraph.graphType == WMG_Axis_Graph.graphTypes.line_stacked))
            {
                legendEntryWidth = Mathf.Max(legendEntryLinkSpacing, maxPointSize / 2) + legendEntrySpacing + getMaxLabelWidth() + 5;
            }
            else
            {
                legendEntryWidth = maxPointSize + legendEntrySpacing + getMaxLabelWidth() + 5;
            }
        }

        if (autofitEnabled)
        {
            if (legendType == legendTypes.Bottom)
            {
                if (LegendWidth > getSpriteWidth(theGraph.gameObject))
                {
                    if (numRowsOrColumns < NumEntries)
                    {
                        numRowsOrColumns++;
                    }
                }
                else
                {
                    if (numRowsOrColumns > 1)
                    {
                        _numRowsOrColumns--;                                   // temporarily decrease without callback
                        if (LegendWidth > getSpriteWidth(theGraph.gameObject)) // if new temporary width exceeds border, then dont do anything
                        {
                            _numRowsOrColumns++;
                        }
                        else                           // new width doesn't exceed the border, actually decrease
                        {
                            _numRowsOrColumns++;
                            numRowsOrColumns--;
                        }
                    }
                }
            }
            else
            {
                if (LegendHeight > getSpriteHeight(theGraph.gameObject))
                {
                    if (numRowsOrColumns < NumEntries)
                    {
                        numRowsOrColumns++;
                    }
                }
                else
                {
                    if (numRowsOrColumns > 1)
                    {
                        _numRowsOrColumns--;                                     // temporarily decrease without callback
                        if (LegendHeight > getSpriteHeight(theGraph.gameObject)) // if new temporary width exceeds border, then dont do anything
                        {
                            _numRowsOrColumns++;
                        }
                        else                           // new width doesn't exceed the border, actually decrease
                        {
                            _numRowsOrColumns++;
                            numRowsOrColumns--;
                        }
                    }
                }
            }
        }
    }
示例#9
0
    public void UpdateSprites(List <GameObject> prevPoints)
    {
        if (pointValuesChanged)
        {
            // Auto set xDistBetween based on the axis length and point count
            if (AutoUpdateXDistBetween)
            {
                if (theGraph.orientationType == WMG_Axis_Graph.orientationTypes.vertical)
                {
                    xDistBetweenPoints = theGraph.xAxisLength / points.Count;
                }
                else
                {
                    xDistBetweenPoints = theGraph.yAxisLength / points.Count;
                }
                cachedXDistBetweenPoints = xDistBetweenPoints;
            }
            // Update point positions
            for (int i = 0; i < points.Count; i++)
            {
                if (i >= pointValues.Count)
                {
                    break;
                }
                float newX = 0;
                float newY = 0;
                // If using xDistBetween then point positioning based on previous point point position
                if (UseXDistBetweenToSpace)
                {
                    if (i > 0)                       // For points greater than 0, use the previous point position plus xDistBetween
                    {
                        if (theGraph.orientationType == WMG_Axis_Graph.orientationTypes.vertical)
                        {
                            newX = theGraph.getSpritePositionX(points[i - 1]) + xDistBetweenPoints + theGraph.getSpriteOffsetX(points[i]);
                            newY = (pointValues[i].y - theGraph.yAxisMinValue) / (theGraph.yAxisMaxValue - theGraph.yAxisMinValue) * theGraph.yAxisLength;
                        }
                        else
                        {
                            newX = (pointValues[i].y - theGraph.xAxisMinValue) / (theGraph.xAxisMaxValue - theGraph.xAxisMinValue) * theGraph.xAxisLength;
                            newY = theGraph.getSpritePositionY(points[i - 1]) + xDistBetweenPoints - (theGraph.getSpriteFactorY(points[i]) - 1) * theGraph.barWidth;
                        }
                    }
                    else                       // For point 0, one of the positions is just 0
                    {
                        if (theGraph.orientationType == WMG_Axis_Graph.orientationTypes.vertical)
                        {
                            newY = (pointValues[i].y - theGraph.yAxisMinValue) / (theGraph.yAxisMaxValue - theGraph.yAxisMinValue) * theGraph.yAxisLength;
                        }
                        else
                        {
                            newX = (pointValues[i].y - theGraph.xAxisMinValue) / (theGraph.xAxisMaxValue - theGraph.xAxisMinValue) * theGraph.xAxisLength;
                        }
                    }
                }
                else                   // Not using xDistBetween, so use the actual x values in the Vector2 list
                {
                    if (i < pointValues.Count)
                    {
                        if (theGraph.orientationType == WMG_Axis_Graph.orientationTypes.vertical)
                        {
                            newX = (pointValues[i].x - theGraph.xAxisMinValue) / (theGraph.xAxisMaxValue - theGraph.xAxisMinValue) * theGraph.xAxisLength;
                            newY = (pointValues[i].y - theGraph.yAxisMinValue) / (theGraph.yAxisMaxValue - theGraph.yAxisMinValue) * theGraph.yAxisLength;
                        }
                        else
                        {
                            newX = (pointValues[i].y - theGraph.xAxisMinValue) / (theGraph.xAxisMaxValue - theGraph.xAxisMinValue) * theGraph.xAxisLength;
                            newY = (pointValues[i].x - theGraph.yAxisMinValue) / (theGraph.yAxisMaxValue - theGraph.yAxisMinValue) * theGraph.yAxisLength;
                        }
                    }
                }

                // For bar graphs, need to update sprites width and height based on positions
                if (theGraph.graphType != WMG_Axis_Graph.graphTypes.line)
                {
                    // For stacked percentage, need to set a y position based on the percentage of all series values combined
                    if (theGraph.graphType == WMG_Axis_Graph.graphTypes.bar_stacked_percent && theGraph.TotalPointValues.Count > i)
                    {
                        if (theGraph.orientationType == WMG_Axis_Graph.orientationTypes.vertical)
                        {
                            newY = (pointValues[i].y - theGraph.yAxisMinValue) / theGraph.TotalPointValues[i] * theGraph.yAxisLength;
                        }
                        else
                        {
                            newX = (pointValues[i].y - theGraph.xAxisMinValue) / theGraph.TotalPointValues[i] * theGraph.xAxisLength;
                        }
                    }
                    // Update sprite dimensions and increase position using previous point position
                    // Previous points is null for side by side bar, but should not be empty for stacked and stacked percentage for series after the first series
                    WMG_Node thePoint = points[i].GetComponent <WMG_Node>();
                    if (theGraph.orientationType == WMG_Axis_Graph.orientationTypes.vertical)
                    {
//						theGraph.changeSpritePivot(thePoint.objectToColor, WMG_GUI_Functions.WMGpivotTypes.Bottom);
                        theGraph.changeSpriteHeight(thePoint.objectToColor, Mathf.RoundToInt(newY));
                        theGraph.changeSpriteWidth(thePoint.objectToColor, Mathf.RoundToInt(theGraph.barWidth));
                        newY -= theGraph.getSpriteOffsetY(points[i]);
                        newY -= (theGraph.getSpriteFactorY(points[i]) - 1) * -theGraph.getSpriteHeight(points[i]);                         // new
                        if (prevPoints != null && i < prevPoints.Count)
                        {
                            newY += theGraph.getSpritePositionY(prevPoints[i]);
                            newY += (theGraph.getSpriteFactorY(points[i]) - 1) * -theGraph.getSpriteHeight(prevPoints[i]);                             // new
                        }
                    }
                    else
                    {
//						theGraph.changeSpritePivot(thePoint.objectToColor, WMG_GUI_Functions.WMGpivotTypes.Left);
                        theGraph.changeSpriteHeight(thePoint.objectToColor, Mathf.RoundToInt(theGraph.barWidth));
                        theGraph.changeSpriteWidth(thePoint.objectToColor, Mathf.RoundToInt(newX));
                        newX  = 0;
                        newY -= theGraph.barWidth;
                        if (prevPoints != null && i < prevPoints.Count)
                        {
                            newX += theGraph.getSpritePositionX(prevPoints[i]);
                            newX += theGraph.getSpriteWidth(prevPoints[i]);
                        }
                    }
                }
                // Finally, set the positions calculated above
                theGraph.changeSpritePositionTo(points[i], new Vector3(newX, newY, 0));
            }
            // Reposition existing lines based on the new point positions
            for (int i = 0; i < lines.Count; i++)
            {
                WMG_Link theLine = lines[i].GetComponent <WMG_Link>();
                theLine.Reposition();
            }
        }
    }
示例#10
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));
                }
            }
        }
    }