增加AxisceilRate设置最大最小值的取整倍率

This commit is contained in:
monitor1394
2020-03-29 15:46:01 +08:00
parent af8127ef2c
commit 9a295d674f
6 changed files with 61 additions and 31 deletions

View File

@@ -1,6 +1,7 @@
# 更新日志
* (2020.03.29) 增加`Axis``ceilRate`设置最大最小值的取整倍率
* (2020.03.29) 增加`BarChart`可通过`itemStyle``cornerRadius`设置`圆角柱图`
* (2020.03.29) 增加`itemStyle``cornerRadius`支持圆角矩形
* (2020.03.24) 优化`Editor`参数编辑,兼容`Unity2019.3`及以上版本

View File

@@ -321,6 +321,7 @@
* `Custom`:自定义的最小值-最大值。
* `min`:设定的坐标轴刻度最小值,当 `minMaxType``Custom` 时有效。
* `max`:设定的坐标轴刻度最大值,当 `minMaxType``Custom` 时有效。
* `ceilRate`最大最小值向上取整的倍率。默认为0时自动计算。
* `splitNumber`:坐标轴的分割段数。默认为 `5`。当 `splitNumber` 设为 `0` 时,表示绘制所有的类目数据。
* `interval`:强制设置坐标轴分割间隔。无法在类目轴中使用。设置改值时 `splitNumber` 无效。
* `boundaryGap`:坐标轴两边是否留白。默认为 `true`

View File

@@ -48,6 +48,7 @@ namespace XCharts
SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType");
SerializedProperty m_Min = prop.FindPropertyRelative("m_Min");
SerializedProperty m_Max = prop.FindPropertyRelative("m_Max");
SerializedProperty m_CeilRate = prop.FindPropertyRelative("m_CeilRate");
int index = InitToggle(prop);
bool toggle = m_AxisModuleToggle[index];
@@ -87,8 +88,9 @@ namespace XCharts
EditorGUI.indentLevel--;
break;
}
EditorGUI.PropertyField(drawRect, m_CeilRate);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
EditorGUI.PropertyField(drawRect, m_SplitNumber);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Interval);
@@ -168,7 +170,7 @@ namespace XCharts
}
else if (type == Axis.AxisType.Value)
{
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
height += 2 * EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType");
if (m_MinMaxType.enumValueIndex == (int)Axis.AxisMinMaxType.Custom)
{

View File

@@ -76,6 +76,7 @@ namespace XCharts
[SerializeField] protected int m_MaxCache = 0;
[SerializeField] protected float m_LogBase = 10;
[SerializeField] protected bool m_LogBaseE = false;
[SerializeField] protected int m_CeilRate = 0;
[SerializeField] protected List<string> m_Data = new List<string>();
[SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine;
[SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName;
@@ -187,6 +188,14 @@ namespace XCharts
set { if (PropertyUtility.SetStruct(ref m_MaxCache, value < 0 ? 0 : value)) SetAllDirty(); }
}
/// <summary>
/// 最大最小值向上取整的倍率。默认为0时自动计算。
/// </summary>
public int ceilRate
{
get { return m_CeilRate; }
set { if (PropertyUtility.SetStruct(ref m_CeilRate, value < 0 ? 0 : value)) SetAllDirty(); }
}
/// <summary>
/// Category data, available in type: 'Category' axis.
/// 类目数据在类目轴type: 'category')中有效。
/// </summary>
@@ -746,22 +755,22 @@ namespace XCharts
else if (minValue > 0 && maxValue > 0)
{
minValue = 0;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue) : maxValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue,m_CeilRate) : maxValue;
}
else if (minValue < 0 && maxValue < 0)
{
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue) : minValue;
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue,m_CeilRate) : minValue;
maxValue = 0;
}
else
{
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue) : maxValue;
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue,m_CeilRate) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue,m_CeilRate) : maxValue;
}
break;
case Axis.AxisMinMaxType.MinMax:
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue) : maxValue;
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue,m_CeilRate) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue,m_CeilRate) : maxValue;
break;
}
}

View File

@@ -269,7 +269,6 @@ namespace XCharts
brRb = cornerRadius != null && cornerRadius.Length > 2 ? cornerRadius[2] : 0;
brLb = cornerRadius != null && cornerRadius.Length > 3 ? cornerRadius[3] : 0;
needRound = brLb != 0 || brRt != 0 || brRb != 0 || brLb != 0;
var min = Mathf.Min(width, height);
if (needRound)
{
if (brLt + brRt > width)

View File

@@ -480,7 +480,7 @@ namespace XCharts
return (Color32)color;
}
public static float GetMaxDivisibleValue(float max)
public static float GetMaxDivisibleValue(float max, int ceilRate)
{
if (max == 0) return 0;
if (max > -1 && max < 1)
@@ -495,23 +495,32 @@ namespace XCharts
if (max > 0) return 1 / Mathf.Pow(10, count - 1);
else return -1 / Mathf.Pow(10, count);
}
int bigger = Mathf.CeilToInt(Mathf.Abs(max));
int n = 1;
while (bigger / (Mathf.Pow(10, n)) > 10)
if (ceilRate == 0)
{
n++;
int bigger = Mathf.CeilToInt(Mathf.Abs(max));
int n = 1;
while (bigger / (Mathf.Pow(10, n)) > 10)
{
n++;
}
float mm = bigger;
if (mm > 10)
{
mm = bigger - bigger % (Mathf.Pow(10, n));
mm += max > 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
}
if (max < 0) return -Mathf.CeilToInt(mm);
else return Mathf.CeilToInt(mm);
}
float mm = bigger;
if (mm > 10)
else
{
mm = bigger - bigger % (Mathf.Pow(10, n));
mm += max > 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
var mod = max % ceilRate;
int rate = (int)(max / ceilRate);
return mod == 0 ? max : (max < 0 ? rate : rate + 1) * ceilRate;
}
if (max < 0) return -Mathf.CeilToInt(mm);
else return Mathf.CeilToInt(mm);
}
public static float GetMinDivisibleValue(float min)
public static float GetMinDivisibleValue(float min, int ceilRate)
{
if (min == 0) return 0;
if (min > -1 && min < 1)
@@ -526,20 +535,29 @@ namespace XCharts
if (min > 0) return 1 / Mathf.Pow(10, count);
else return -1 / Mathf.Pow(10, count - 1);
}
int bigger = Mathf.FloorToInt(Mathf.Abs(min));
int n = 1;
while (bigger / (Mathf.Pow(10, n)) > 10)
if (ceilRate == 0)
{
n++;
int bigger = Mathf.FloorToInt(Mathf.Abs(min));
int n = 1;
while (bigger / (Mathf.Pow(10, n)) > 10)
{
n++;
}
float mm = bigger;
if (mm > 10)
{
mm = bigger - bigger % (Mathf.Pow(10, n));
mm += min < 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
}
if (min < 0) return -Mathf.FloorToInt(mm);
else return Mathf.FloorToInt(mm);
}
float mm = bigger;
if (mm > 10)
else
{
mm = bigger - bigger % (Mathf.Pow(10, n));
mm += min < 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
var mod = min % ceilRate;
int rate = (int)(min / ceilRate);
return mod == 0 ? min : (min < 0 ? rate - 1 : rate) * ceilRate;
}
if (min < 0) return -Mathf.FloorToInt(mm);
else return Mathf.FloorToInt(mm);
}
public static float GetMaxLogValue(float value, float logBase, bool isLogBaseE, out int splitNumber)