mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 06:20:15 +00:00
AxisType.Value类型的坐标轴可以设置AxisMinMaxType控制最大最小刻度
This commit is contained in:
@@ -15,6 +15,13 @@ namespace XCharts
|
||||
//Log
|
||||
}
|
||||
|
||||
public enum AxisMinMaxType
|
||||
{
|
||||
Default,
|
||||
MinMax,
|
||||
Custom
|
||||
}
|
||||
|
||||
public enum SplitLineType
|
||||
{
|
||||
None,
|
||||
@@ -54,6 +61,9 @@ namespace XCharts
|
||||
|
||||
[SerializeField] protected bool m_Show = true;
|
||||
[SerializeField] protected AxisType m_Type;
|
||||
[SerializeField] protected AxisMinMaxType m_MinMaxType;
|
||||
[SerializeField] protected int m_Min;
|
||||
[SerializeField] protected int m_Max;
|
||||
[SerializeField] protected int m_SplitNumber = 5;
|
||||
[SerializeField] protected int m_TextRotation = 0;
|
||||
[SerializeField] protected bool m_ShowSplitLine = false;
|
||||
@@ -64,6 +74,9 @@ namespace XCharts
|
||||
|
||||
public bool show { get { return m_Show; }set { m_Show = value; } }
|
||||
public AxisType type { get { return m_Type; } set { m_Type = value; } }
|
||||
public AxisMinMaxType minMaxType { get { return m_MinMaxType; } set { m_MinMaxType = value; } }
|
||||
public int min { get { return m_Min; } set { m_Min = value; } }
|
||||
public int max { get { return m_Max; } set { m_Max = value; } }
|
||||
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
|
||||
public int textRotation { get { return m_TextRotation; } set { m_TextRotation = value; } }
|
||||
public bool showSplitLine { get { return m_ShowSplitLine; } set { m_ShowSplitLine = value; } }
|
||||
@@ -76,6 +89,8 @@ namespace XCharts
|
||||
{
|
||||
m_Show = other.show;
|
||||
m_Type = other.type;
|
||||
m_Min = other.min;
|
||||
m_Max = other.max;
|
||||
m_SplitNumber = other.splitNumber;
|
||||
m_TextRotation = other.textRotation;
|
||||
m_ShowSplitLine = other.showSplitLine;
|
||||
@@ -187,6 +202,8 @@ namespace XCharts
|
||||
{
|
||||
return show == other.show &&
|
||||
type == other.type &&
|
||||
min == other.min &&
|
||||
max == other.max &&
|
||||
splitNumber == other.splitNumber &&
|
||||
showSplitLine == other.showSplitLine &&
|
||||
textRotation == other.textRotation &&
|
||||
@@ -228,6 +245,8 @@ namespace XCharts
|
||||
{
|
||||
m_Show = true,
|
||||
m_Type = AxisType.Category,
|
||||
m_Min = 0,
|
||||
m_Max = 0,
|
||||
m_SplitNumber = 5,
|
||||
m_TextRotation = 0,
|
||||
m_ShowSplitLine = false,
|
||||
@@ -254,6 +273,8 @@ namespace XCharts
|
||||
{
|
||||
m_Show = true,
|
||||
m_Type = AxisType.Value,
|
||||
m_Min = 0,
|
||||
m_Max = 0,
|
||||
m_SplitNumber = 5,
|
||||
m_TextRotation = 0,
|
||||
m_ShowSplitLine = false,
|
||||
|
||||
@@ -80,7 +80,8 @@ namespace XCharts
|
||||
CheckLegend();
|
||||
CheckTooltip();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
ChartHelper.DestoryAllChilds(transform);
|
||||
@@ -93,6 +94,7 @@ namespace XCharts
|
||||
InitLegend();
|
||||
InitTooltip();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
@@ -224,6 +226,7 @@ namespace XCharts
|
||||
anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight));
|
||||
|
||||
m_Legend.SetButton(i, btn);
|
||||
m_Legend.SetActive(i, IsActive(i));
|
||||
m_Legend.UpdateButtonColor(i, m_ThemeInfo.GetColor(i), m_ThemeInfo.unableColor);
|
||||
btn.GetComponentInChildren<Text>().text = m_Legend.data[i];
|
||||
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
|
||||
|
||||
@@ -335,7 +335,60 @@ namespace XCharts
|
||||
int tempMaxValue = 100;
|
||||
if (m_Series != null)
|
||||
{
|
||||
m_Series.GetMinMaxValue(m_Legend, out tempMinValue, out tempMaxValue);
|
||||
m_Series.GetMinMaxValue(out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
if (m_XAxis.type == Axis.AxisType.Value)
|
||||
{
|
||||
switch (m_XAxis.minMaxType)
|
||||
{
|
||||
case Axis.AxisMinMaxType.Default:
|
||||
if (tempMinValue > 0 && tempMaxValue > 0)
|
||||
{
|
||||
tempMinValue = 0;
|
||||
tempMaxValue = ChartHelper.GetMaxDivisibleValue(tempMaxValue);
|
||||
}
|
||||
else if (tempMinValue < 0 && tempMaxValue < 0)
|
||||
{
|
||||
tempMinValue = ChartHelper.GetMinDivisibleValue(tempMinValue);
|
||||
tempMaxValue = 0;
|
||||
}
|
||||
break;
|
||||
case Axis.AxisMinMaxType.MinMax:
|
||||
tempMinValue = ChartHelper.GetMinDivisibleValue(tempMinValue);
|
||||
tempMaxValue = ChartHelper.GetMaxDivisibleValue(tempMaxValue);
|
||||
break;
|
||||
case Axis.AxisMinMaxType.Custom:
|
||||
if (m_XAxis.min != 0) tempMinValue = m_XAxis.min;
|
||||
if (m_XAxis.max != 0) tempMaxValue = m_XAxis.max;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (m_YAxis.type == Axis.AxisType.Value)
|
||||
{
|
||||
switch (m_YAxis.minMaxType)
|
||||
{
|
||||
case Axis.AxisMinMaxType.Default:
|
||||
if (tempMinValue > 0 && tempMaxValue > 0)
|
||||
{
|
||||
tempMinValue = 0;
|
||||
tempMaxValue = ChartHelper.GetMaxDivisibleValue(tempMaxValue);
|
||||
}
|
||||
else if (tempMinValue < 0 && tempMaxValue < 0)
|
||||
{
|
||||
tempMinValue = ChartHelper.GetMinDivisibleValue(tempMinValue);
|
||||
tempMaxValue = 0;
|
||||
}
|
||||
break;
|
||||
case Axis.AxisMinMaxType.MinMax:
|
||||
tempMinValue = ChartHelper.GetMinDivisibleValue(tempMinValue);
|
||||
tempMaxValue = ChartHelper.GetMaxDivisibleValue(tempMaxValue);
|
||||
break;
|
||||
case Axis.AxisMinMaxType.Custom:
|
||||
if (m_YAxis.min != 0) tempMinValue = m_YAxis.min;
|
||||
if (m_YAxis.max != 0) tempMaxValue = m_YAxis.max;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (tempMinValue != minValue || tempMaxValue != maxValue)
|
||||
{
|
||||
@@ -343,12 +396,12 @@ namespace XCharts
|
||||
maxValue = tempMaxValue;
|
||||
if (m_XAxis.type == Axis.AxisType.Value)
|
||||
{
|
||||
m_ZeroXOffset = Mathf.Abs(minValue) * (coordinateWid / (Mathf.Abs(minValue) + Mathf.Abs(maxValue)));
|
||||
m_ZeroXOffset = minValue > 0 ? 0 : Mathf.Abs(minValue) * (coordinateWid / (Mathf.Abs(minValue) + Mathf.Abs(maxValue)));
|
||||
OnXMaxValueChanged();
|
||||
}
|
||||
else if (m_YAxis.type == Axis.AxisType.Value)
|
||||
{
|
||||
m_ZeroYOffset = Mathf.Abs(minValue) * (coordinateHig / (Mathf.Abs(minValue) + Mathf.Abs(maxValue)));
|
||||
m_ZeroYOffset = minValue > 0 ? 0 : Mathf.Abs(minValue) * (coordinateHig / (Mathf.Abs(minValue) + Mathf.Abs(maxValue)));
|
||||
OnYMaxValueChanged();
|
||||
}
|
||||
RefreshChart();
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void GetMinMaxValue(Legend legend, out int minVaule, out int maxValue)
|
||||
public void GetMinMaxValue(out int minVaule, out int maxValue)
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
float max = int.MinValue;
|
||||
@@ -199,7 +199,7 @@ namespace XCharts
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (legend.IsActive(i))
|
||||
if (IsActive(i))
|
||||
{
|
||||
if (m_Series[i].Max > max) max = m_Series[i].Max;
|
||||
if (m_Series[i].Min < min) min = m_Series[i].Min;
|
||||
@@ -211,21 +211,26 @@ namespace XCharts
|
||||
minVaule = 0;
|
||||
maxValue = 100;
|
||||
}
|
||||
else if (max > 0 && min > 0)
|
||||
{
|
||||
minVaule = 0;
|
||||
maxValue = ChartHelper.GetMaxDivisibleValue(max);
|
||||
}
|
||||
else if (min < 0 && max < 0)
|
||||
{
|
||||
minVaule = ChartHelper.GetMaxDivisibleValue(min);
|
||||
maxValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
minVaule = ChartHelper.GetMaxDivisibleValue(min);
|
||||
maxValue = ChartHelper.GetMaxDivisibleValue(max);
|
||||
minVaule = (int)min;
|
||||
maxValue = (int)max;
|
||||
}
|
||||
//else if (max > 0 && min > 0)
|
||||
//{
|
||||
// minVaule = 0;
|
||||
// maxValue = ChartHelper.GetMaxDivisibleValue(max);
|
||||
//}
|
||||
//else if (min < 0 && max < 0)
|
||||
//{
|
||||
// minVaule = ChartHelper.GetMaxDivisibleValue(min);
|
||||
// maxValue = 0;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// minVaule = ChartHelper.GetMaxDivisibleValue(min);
|
||||
// maxValue = ChartHelper.GetMaxDivisibleValue(max);
|
||||
//}
|
||||
}
|
||||
|
||||
public float GetMaxValue(int index, int splitNumber = 0)
|
||||
|
||||
Reference in New Issue
Block a user