/// <summary> /// 获得分割段宽度 /// </summary> /// <param name="coordinateWidth"></param> /// <param name="dataZoom"></param> /// <returns></returns> public static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom = null) { if (index < 0) { return(0); } int num = GetScaleNumber(axis, coordinateWidth, dataZoom); int splitNum = GetSplitNumber(axis, coordinateWidth, dataZoom); if (num <= 0) { num = 1; } if (axis.type == Axis.AxisType.Value && axis.interval > 0) { if (axis.runtimeMinMaxRange <= 0) { return(0); } if (index >= splitNum) { return((float)(coordinateWidth - (index - 1) * axis.interval * coordinateWidth / axis.runtimeMinMaxRange)); } else { return((float)(axis.interval * coordinateWidth / axis.runtimeMinMaxRange)); } } else { var data = axis.GetDataList(dataZoom); if (axis.IsCategory() && data.Count > 0) { var count = axis.boundaryGap ? data.Count : data.Count - 1; int tick = count / splitNum; if (count <= 0) { return(0); } var each = coordinateWidth / count; if (axis.insertDataToHead) { var max = axis.boundaryGap ? splitNum : splitNum - 1; if (index == 1) { if (axis.axisTick.alignWithLabel) { return(each * tick); } else { return(coordinateWidth - each * tick * max); } } else { if (count < splitNum) { return(each); } else { return(each * (count / splitNum)); } } } else { var max = axis.boundaryGap ? num - 1 : num; if (index >= max) { if (axis.axisTick.alignWithLabel) { return(each * tick); } else { return(coordinateWidth - each * tick * (index - 1)); } } else { if (count < splitNum) { return(each); } else { return(each * (count / splitNum)); } } } } else { if (splitNum <= 0) { return(0); } else { return(coordinateWidth / splitNum); } } } }
/// <summary> /// 获得分割段数 /// </summary> /// <param name="dataZoom"></param> /// <returns></returns> public static int GetSplitNumber(Axis axis, float coordinateWid, DataZoom dataZoom) { if (axis.type == Axis.AxisType.Value) { if (axis.interval > 0) { if (coordinateWid <= 0) { return(0); } int num = (int)(axis.runtimeMinMaxRange / axis.interval); int maxNum = Mathf.CeilToInt(coordinateWid / 15); if (num > maxNum) { axis.interval *= 2; num = (int)(axis.runtimeMinMaxRange / axis.interval); } return(num); } else { return(axis.splitNumber > 0 ? axis.splitNumber : 4); } } else if (axis.type == Axis.AxisType.Time) { if (axis.interval > 0) { if (coordinateWid <= 0) { return(0); } int num = (int)(axis.runtimeMinMaxRange / axis.interval); int maxNum = Mathf.CeilToInt(coordinateWid / 15); if (num > maxNum) { axis.interval *= 2; num = (int)(axis.runtimeMinMaxRange / axis.interval); } return(num); } else { return(axis.splitNumber > 0 ? axis.splitNumber : 4); } } else if (axis.type == Axis.AxisType.Log) { return(axis.splitNumber > 0 ? axis.splitNumber : 4); } else if (axis.type == Axis.AxisType.Category) { int dataCount = axis.GetDataList(dataZoom).Count; if (!axis.boundaryGap) { dataCount -= 1; } if (axis.splitNumber <= 0 || axis.splitNumber > dataCount) { return(dataCount); } if (dataCount >= axis.splitNumber * 2) { return(axis.splitNumber); } else { return(dataCount); } } return(0); }
/// <summary> /// 获得标签显示的名称 /// </summary> /// <param name="index"></param> /// <param name="minValue"></param> /// <param name="maxValue"></param> /// <param name="dataZoom"></param> /// <returns></returns> public static string GetLabelName(Axis axis, float coordinateWidth, int index, double minValue, double maxValue, DataZoom dataZoom, bool forcePercent) { int split = GetSplitNumber(axis, coordinateWidth, dataZoom); if (axis.type == Axis.AxisType.Value) { if (minValue == 0 && maxValue == 0) { maxValue = axis.max != 0 ? axis.max : 1; } double value = 0; if (forcePercent) { maxValue = 100; } if (axis.interval > 0) { if (index == split) { value = maxValue; } else { value = minValue + index * axis.interval; } } else { value = minValue + (maxValue - minValue) * index / split; if (!axis.clockwise && value != minValue) { value = maxValue - value; } } if (axis.inverse) { value = -value; minValue = -minValue; maxValue = -maxValue; } if (forcePercent) { return(string.Format("{0}%", (int)value)); } else { return(axis.axisLabel.GetFormatterContent(index, value, minValue, maxValue)); } } else if (axis.type == Axis.AxisType.Log) { float value = axis.logBaseE ? Mathf.Exp(axis.runtimeMinLogIndex + index) : Mathf.Pow(axis.logBase, axis.runtimeMinLogIndex + index); if (axis.inverse) { value = -value; minValue = -minValue; maxValue = -maxValue; } return(axis.axisLabel.GetFormatterContent(index, value, minValue, maxValue, true)); } else if (axis.type == Axis.AxisType.Time) { if (minValue == 0 && maxValue == 0) { return(string.Empty); } double value = 0; if (axis.interval > 0) { if (index == split) { value = maxValue; } else { value = minValue + index * axis.interval; } } else { value = minValue + (maxValue - minValue) * index / split; } return(axis.axisLabel.GetFormatterDateTime(index, value)); } var showData = axis.GetDataList(dataZoom); int dataCount = showData.Count; if (dataCount <= 0) { return(""); } int rate = axis.boundaryGap ? (dataCount / split) : (dataCount - 1) / split; if (rate == 0) { rate = 1; } if (axis.insertDataToHead) { if (index > 0) { var residue = (dataCount - 1) - split * rate; var newIndex = residue + (index - 1) * rate; if (newIndex < 0) { newIndex = 0; } return(axis.axisLabel.GetFormatterContent(newIndex, showData[newIndex])); } else { if (axis.boundaryGap && coordinateWidth / dataCount > 5) { return(string.Empty); } else { return(axis.axisLabel.GetFormatterContent(0, showData[0])); } } } else { int newIndex = index * rate; if (newIndex < dataCount) { return(axis.axisLabel.GetFormatterContent(newIndex, showData[newIndex])); } else { if (axis.boundaryGap && coordinateWidth / dataCount > 5) { return(string.Empty); } else { return(axis.axisLabel.GetFormatterContent(dataCount - 1, showData[dataCount - 1])); } } } }
/// <summary> /// 获得标签显示的名称 /// </summary> /// <param name="index"></param> /// <param name="minValue"></param> /// <param name="maxValue"></param> /// <param name="dataZoom"></param> /// <returns></returns> internal static string GetLabelName(Axis axis, float coordinateWidth, int index, float minValue, float maxValue, DataZoom dataZoom, bool forcePercent) { int split = GetSplitNumber(axis, coordinateWidth, dataZoom); if (axis.type == Axis.AxisType.Value) { if (minValue == 0 && maxValue == 0) { return(string.Empty); } var value = 0f; if (forcePercent) { maxValue = 100; } if (axis.interval > 0) { if (index == split) { value = maxValue; } else { value = minValue + index * axis.interval; } } else { value = minValue + (maxValue - minValue) * index / split; if (!axis.clockwise && value != minValue) { value = maxValue - value; } } if (axis.inverse) { value = -value; minValue = -minValue; maxValue = -maxValue; } if (forcePercent) { return(string.Format("{0}%", (int)value)); } else { return(axis.axisLabel.GetFormatterContent(value, minValue, maxValue)); } } else if (axis.type == Axis.AxisType.Log) { float value = axis.logBaseE ? Mathf.Exp(axis.runtimeMinLogIndex + index) : Mathf.Pow(axis.logBase, axis.runtimeMinLogIndex + index); if (axis.inverse) { value = -value; minValue = -minValue; maxValue = -maxValue; } return(axis.axisLabel.GetFormatterContent(value, minValue, maxValue, true)); } var showData = axis.GetDataList(dataZoom); int dataCount = showData.Count; if (dataCount <= 0) { return(""); } int rate = Mathf.RoundToInt(dataCount * 1f / split); int newIndex = index * rate; if (newIndex <= dataCount - 1) { return(axis.axisLabel.GetFormatterContent(showData[newIndex])); } else { if (rate == 1) { return(string.Empty); } else if (axis.boundaryGap && coordinateWidth / dataCount > 10) { return(string.Empty); } else { if ((index - 1) * rate > dataCount - 1) { return(string.Empty); } else { return(axis.axisLabel.GetFormatterContent(showData[dataCount - 1])); } } } }
/// <summary> /// 获得标签显示的名称 /// </summary> /// <param name="index"></param> /// <param name="minValue"></param> /// <param name="maxValue"></param> /// <param name="dataZoom"></param> /// <returns></returns> internal static string GetLabelName(Axis axis, float coordinateWidth, int index, float minValue, float maxValue, DataZoom dataZoom, bool forcePercent) { int split = GetSplitNumber(axis, coordinateWidth, dataZoom); if (axis.type == Axis.AxisType.Value) { if (minValue == 0 && maxValue == 0) { return(string.Empty); } float value = 0; if (forcePercent) { maxValue = 100; } if (axis.interval > 0) { if (index == split - 1) { value = maxValue; } else { value = minValue + index * axis.interval; } } else { value = (minValue + (maxValue - minValue) * index / (split - 1)); } if (axis.inverse) { value = -value; minValue = -minValue; maxValue = -maxValue; } if (forcePercent) { return(string.Format("{0}%", (int)value)); } else { return(axis.axisLabel.GetFormatterContent(value, minValue, maxValue)); } } else if (axis.type == Axis.AxisType.Log) { float value = axis.logBaseE ? Mathf.Exp(axis.runtimeMinLogIndex + index) : Mathf.Pow(axis.logBase, axis.runtimeMinLogIndex + index); if (axis.inverse) { value = -value; minValue = -minValue; maxValue = -maxValue; } return(axis.axisLabel.GetFormatterContent(value, minValue, maxValue, true)); } var showData = axis.GetDataList(dataZoom); int dataCount = showData.Count; if (dataCount <= 0) { return(""); } if (index == split - 1 && !axis.boundaryGap) { return(axis.axisLabel.GetFormatterContent(showData[dataCount - 1])); } else { float rate = dataCount / split; if (rate < 1) { rate = 1; } int offset = axis.boundaryGap ? (int)(rate / 2) : 0; int newIndex = (int)(index * rate >= dataCount - 1 ? dataCount - 1 : offset + index * rate); return(axis.axisLabel.GetFormatterContent(showData[newIndex])); } }
/// <summary> /// 获得分割段宽度 /// </summary> /// <param name="coordinateWidth"></param> /// <param name="dataZoom"></param> /// <returns></returns> internal static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom = null) { if (index < 0) { return(0); } int num = GetScaleNumber(axis, coordinateWidth, dataZoom); int splitNum = GetSplitNumber(axis, coordinateWidth, dataZoom); if (num <= 0) { num = 1; } if (axis.type == Axis.AxisType.Value && axis.interval > 0) { if (axis.runtimeMinMaxRange <= 0) { return(0); } if (index >= splitNum) { return(coordinateWidth - (index - 1) * axis.interval * coordinateWidth / axis.runtimeMinMaxRange); } else { return(axis.interval * coordinateWidth / axis.runtimeMinMaxRange); } } else { var data = axis.GetDataList(); if (axis.IsCategory() && data.Count > 0) { int tick = Mathf.RoundToInt(data.Count * 1f / splitNum); var count = axis.boundaryGap ? data.Count : data.Count - 1; if (count <= 0) { return(0); } var each = coordinateWidth / count; if (index >= num - 1) { if (axis.axisTick.alignWithLabel) { return(each * tick); } else { return(coordinateWidth - each * tick * (index - 1)); } } else { return(each * tick); } } else { if (splitNum <= 0) { return(0); } else { return(coordinateWidth / splitNum); } } } }