mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 14:30:10 +00:00
增加Axis可通过inverse参数设置坐标轴反向
This commit is contained in:
@@ -77,6 +77,7 @@ namespace XCharts
|
||||
[SerializeField] protected float m_LogBase = 10;
|
||||
[SerializeField] protected bool m_LogBaseE = false;
|
||||
[SerializeField] protected int m_CeilRate = 0;
|
||||
[SerializeField] protected bool m_Inverse = false;
|
||||
[SerializeField] protected List<string> m_Data = new List<string>();
|
||||
[SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine;
|
||||
[SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName;
|
||||
@@ -196,6 +197,15 @@ namespace XCharts
|
||||
set { if (PropertyUtility.SetStruct(ref m_CeilRate, value < 0 ? 0 : value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether the axis are reversed or not. Invalid in `Category` axis.
|
||||
/// 是否反向坐标轴。在类目轴中无效。
|
||||
/// </summary>
|
||||
public bool inverse
|
||||
{
|
||||
get { return m_Inverse; }
|
||||
set { if (m_Type == AxisType.Value && PropertyUtility.SetStruct(ref m_Inverse, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Category data, available in type: 'Category' axis.
|
||||
/// 类目数据,在类目轴(type: 'category')中有效。
|
||||
/// </summary>
|
||||
@@ -328,7 +338,7 @@ namespace XCharts
|
||||
public float runtimeZeroYOffset { get; internal set; }
|
||||
public int runtimeMinLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMinValue) : (int)Mathf.Log(runtimeMinValue, logBase); } }
|
||||
public int runtimeMaxLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMaxValue) : (int)Mathf.Log(runtimeMaxValue, logBase); } }
|
||||
|
||||
internal bool runtimeLastCheckInverse { get; set; }
|
||||
private int filterStart;
|
||||
private int filterEnd;
|
||||
private int filterMinShow;
|
||||
@@ -566,7 +576,6 @@ namespace XCharts
|
||||
DataZoom dataZoom, bool forcePercent)
|
||||
{
|
||||
int split = GetSplitNumber(coordinateWidth, dataZoom);
|
||||
|
||||
if (m_Type == AxisType.Value)
|
||||
{
|
||||
if (minValue == 0 && maxValue == 0) return string.Empty;
|
||||
@@ -581,6 +590,12 @@ namespace XCharts
|
||||
{
|
||||
value = (minValue + (maxValue - minValue) * index / (split - 1));
|
||||
}
|
||||
if (inverse)
|
||||
{
|
||||
value = -value;
|
||||
minValue = -minValue;
|
||||
maxValue = -maxValue;
|
||||
}
|
||||
if (forcePercent) return string.Format("{0}%", (int)value);
|
||||
else return m_AxisLabel.GetFormatterContent(value, minValue, maxValue);
|
||||
}
|
||||
@@ -588,6 +603,12 @@ namespace XCharts
|
||||
{
|
||||
float value = m_LogBaseE ? Mathf.Exp(runtimeMinLogIndex + index) :
|
||||
Mathf.Pow(m_LogBase, runtimeMinLogIndex + index);
|
||||
if (inverse)
|
||||
{
|
||||
value = -value;
|
||||
minValue = -minValue;
|
||||
maxValue = -maxValue;
|
||||
}
|
||||
return m_AxisLabel.GetFormatterContent(value, minValue, maxValue, true);
|
||||
}
|
||||
var showData = GetDataList(dataZoom);
|
||||
@@ -740,8 +761,16 @@ namespace XCharts
|
||||
{
|
||||
if (min != 0 || max != 0)
|
||||
{
|
||||
minValue = min;
|
||||
maxValue = max;
|
||||
if (inverse)
|
||||
{
|
||||
minValue = -max;
|
||||
maxValue = -min;
|
||||
}
|
||||
else
|
||||
{
|
||||
minValue = min;
|
||||
maxValue = max;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -755,22 +784,22 @@ namespace XCharts
|
||||
else if (minValue > 0 && maxValue > 0)
|
||||
{
|
||||
minValue = 0;
|
||||
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue,m_CeilRate) : maxValue;
|
||||
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, m_CeilRate) : maxValue;
|
||||
}
|
||||
else if (minValue < 0 && maxValue < 0)
|
||||
{
|
||||
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue,m_CeilRate) : minValue;
|
||||
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, m_CeilRate) : minValue;
|
||||
maxValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue,m_CeilRate) : minValue;
|
||||
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue,m_CeilRate) : 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,m_CeilRate) : minValue;
|
||||
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue,m_CeilRate) : maxValue;
|
||||
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, m_CeilRate) : minValue;
|
||||
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, m_CeilRate) : maxValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -723,10 +723,10 @@ namespace XCharts
|
||||
/// <param name="axisIndex"></param>
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
internal void GetXMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
internal void GetXMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis, bool inverse,
|
||||
out float minVaule, out float maxValue)
|
||||
{
|
||||
GetMinMaxValue(dataZoom, axisIndex, isValueAxis, false, out minVaule, out maxValue);
|
||||
GetMinMaxValue(dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -736,15 +736,15 @@ namespace XCharts
|
||||
/// <param name="axisIndex"></param>
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
internal void GetYMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
internal void GetYMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis, bool inverse,
|
||||
out float minVaule, out float maxValue)
|
||||
{
|
||||
GetMinMaxValue(dataZoom, axisIndex, isValueAxis, true, out minVaule, out maxValue);
|
||||
GetMinMaxValue(dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue);
|
||||
}
|
||||
|
||||
private Dictionary<int, List<Serie>> _stackSeriesForMinMax = new Dictionary<int, List<Serie>>();
|
||||
private Dictionary<int, float> _serieTotalValueForMinMax = new Dictionary<int, float>();
|
||||
internal void GetMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis, bool yValue,
|
||||
internal void GetMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis, bool inverse, bool yValue,
|
||||
out float minVaule, out float maxValue)
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
@@ -769,17 +769,9 @@ namespace XCharts
|
||||
var showData = m_Series[i].GetDataList(dataZoom);
|
||||
foreach (var data in showData)
|
||||
{
|
||||
if (yValue)
|
||||
{
|
||||
var currData = data.GetData(1);
|
||||
if (currData > max) max = currData;
|
||||
if (currData < min) min = currData;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (data.data[0] > max) max = data.data[0];
|
||||
if (data.data[0] < min) min = data.data[0];
|
||||
}
|
||||
var currData = data.GetData(yValue ? 1 : 0, inverse);
|
||||
if (currData > max) max = currData;
|
||||
if (currData < min) min = currData;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -809,11 +801,11 @@ namespace XCharts
|
||||
{
|
||||
if (!_serieTotalValueForMinMax.ContainsKey(j))
|
||||
_serieTotalValueForMinMax[j] = 0;
|
||||
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] +
|
||||
(yValue ? showData[j].GetData(1) : showData[i].data[0]);
|
||||
var currData = (yValue ? showData[j].GetData(1) : showData[j].GetData(0));
|
||||
if (inverse) currData = -currData;
|
||||
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
float tmax = int.MinValue;
|
||||
float tmin = int.MaxValue;
|
||||
|
||||
Reference in New Issue
Block a user