///<summary>sets default values. For when all category values = 0</summary> void SetEmptyDefaultValues() { List <float> emptyValues = MathScientific.RepeatedList(0.1f, graph.sliceLabels.Count); graph.sliceValues.SetList(emptyValues); emptyDefaultValuesOn = true; }
// returns the next tick interval if current x corresponds to both the section number at interval increase and a factor of ten. // else returns current interval int GetNewXTickInterval() { float newXBaseInterval = (float)CurrentPointNum / (float)xSectNumAtIntervalIncrease; // can't be a new interval if the new base interval is not a whole number if (newXBaseInterval != (int)newXBaseInterval) { return(xTickInterval); } // working with base interval (divided by the interval increase rate) int tenMultiplier = (int)Mathf.Pow(10, MathScientific.GetTenPow(newXBaseInterval)); float baseIntervalAsUnit = (float)(newXBaseInterval) / (float)(tenMultiplier); if (baseIntervalAsUnit == 1) { return(2 * tenMultiplier); } if (baseIntervalAsUnit == 2) { return(5 * tenMultiplier); } if (baseIntervalAsUnit == 5) { return(10 * tenMultiplier); } return(xTickInterval); }
string GetListItem(float newXValue, float newYValue) { // set significant figures, optional metric unit prefix and formatting in list x and y values string xListItem; if (xHasMetricFormat) { xListItem = MathScientific.ToMetric(newXValue, xValueFormat, listNumSigFigs.x); } else { xListItem = MathScientific.ToFormattedValue(newXValue, xValueFormat, listNumSigFigs.x); } string yListItem; if (yHasMetricFormat) { yListItem = MathScientific.ToMetric(newYValue, yValueFormat, listNumSigFigs.y); } else { yListItem = MathScientific.ToFormattedValue(newYValue, yValueFormat, listNumSigFigs.y); } return("X: " + xListItem + ",\n\t Y: " + yListItem); }
// updates using new value and saved range if new value provided and no values have been removed. // otherwise, has to find the range by iterating through all points, which uses more processing power. // returns true if range was updated, false if not. private bool _UpdateRangeQuery(IEnumerable <Vector2> points, Func <Vector2, float> getXOrY, bool pointsRemoved = true, float?newValue = null) { if ((!pointsRemoved) && (newValue != null)) { if (newValue < RawMin) { _rawMin = (float)newValue; } else if (newValue > RawMax) { _rawMax = (float)newValue; } else { return(false); } } else // need to completely update range if a value was removed or new value is not provided { _rawMin = MathScientific.Min(points, getXOrY); _rawMax = MathScientific.Max(points, getXOrY); } return(true); }
///<summary>sets all values to zero and sets given value. Called when first value added.</summary> void SetInitialValues(int index, float firstValue) { List <float> initialValues = MathScientific.RepeatedList(0f, graph.sliceLabels.Count); initialValues[index] = firstValue; graph.sliceValues.SetList(initialValues); emptyDefaultValuesOn = false; }
// takes a label value, and related varaibles, and returns it formatted to fit the axis formatting public string FormatLabel(float value, string valueFormat, int sigFigs) { if (unitIsMetric) { return(MathScientific.ToMetric(value, valueFormat, BaseSigFigs + sigFigs, customThsdPow: ThsdPow)); } return(MathScientific.ToFormattedValue(value, valueFormat, BaseSigFigs + sigFigs)); }
// sets closest min, max and tick number to raw values based on legal intervals private void _SnapRawValuesToInterval() { float rawInterval = (RawMax - RawMin) / RawNumSects; float interval = MathScientific.Best1v2v5SeriesTerm(rawInterval); _min = Mathf.Floor(RawMin / interval) * interval; _max = Mathf.Ceil(RawMax / interval) * interval; _numTicks = Mathf.RoundToInt((Max - Min) / interval + 1); _SetMetricPrefix(interval); }
// finds each object in the given label container transform, and returns the one with the rect of maximum width private float GetMaxWidthLabel(Transform labelContainer) { List <Transform> nodes = new List <Transform>(); foreach (Transform node in labelContainer) { nodes.Add(node); } return(MathScientific.Max(nodes, (Transform t) => t.GetChild(0).GetComponent <RectTransform>().rect.width)); }
// custom update function for labelling any axis with metric units public string GetMetricAxisLabel(WMG_Axis axis, int labelIndex, string valueFormat, int sigFigs, AxisAutoFunctions autoAxisParams = null) { // map label value to min/max float num = axis.AxisMinValue + labelIndex * (axis.AxisMaxValue - axis.AxisMinValue) / (axis.axisLabels.Count - 1); if (autoAxisParams == null) { return(MathScientific.ToMetric(num, valueFormat, sigFigs)); } return(autoAxisParams.FormatLabel(num, valueFormat, sigFigs)); }
///<summary>adds a new data value to the list</summary> public void AddListDataItem(string value) { // increase data item count by one dataCounter++; // get item at bottom of list, move it to top and set value to new data value Transform newItemTranf = ContentPanel.transform.GetChild(ContentPanel.transform.childCount - 1); newItemTranf.SetAsFirstSibling(); ListItemController itemController = newItemTranf.GetComponent <ListItemController> (); itemController.dataText.text = MathScientific.ToMetric((float)dataCounter) + ") " + value; }
// formats an axis title to include the unit public string GetMetricAxisTitle(string axisTitle, string unit, bool unitIsMetric = false, string metricPrefix = "") { // return title only, if no unit if (unit == "" || unit == " ") { return(axisTitle); } // return title and unit only if no metric if (!unitIsMetric) { return(axisTitle + " (" + unit + ")"); } // if metric, return title AND unit with metric unit prefix written out in full return(axisTitle + " (" + MathScientific.GetFullMetricPrefix(metricPrefix) + unit + ")"); }
///<summary>Adds a new value to the Tab, including Graph, Ticker List and dataValues.</summary> ///<param name = "newValue">The value to be added to the graph (displayed on y-axis)</param> public void AddSingleValue(float newValue) { dataValues.Add(newValue); graphScript.AddPoint(newValue); // set decimals in list value string newListItem; if (yHasMetricFormat) { newListItem = MathScientific.ToMetric(newValue, valueFormat, listNumSigFigs); } else { newListItem = MathScientific.ToFormattedValue(newValue, valueFormat, listNumSigFigs); } tickerList.GetComponent <ListController> ().AddListDataItem(newListItem); }
// sets a base number of significant figures to ensure the interval is always visible. private void _SetBaseSigFigs() { _baseSigFigs = MathScientific.GetTenPow((RawMax + RawMin) / (RawMax - RawMin)); }
// sets the metric unit prefix of axis labels based on power of 1000 of interval. private void _SetMetricPrefix(float interval) { _thsdPow = MathScientific.GetThsdPow(interval); _metricPrefix = MathScientific.GetMetricUnit(_thsdPow); }