diff --git a/Assets/XCharts/CHANGELOG-EN.md b/Assets/XCharts/CHANGELOG-EN.md
index 3c856060..b901079e 100644
--- a/Assets/XCharts/CHANGELOG-EN.md
+++ b/Assets/XCharts/CHANGELOG-EN.md
@@ -35,6 +35,7 @@
## master
+* (2021.06.05) Improved Candlestickchart support for inverse (#152)
* (2021.06.04) Optimized auto-refresh of custom `Theme` (#148)
* (2021.06.04) Fixed `Gauge` having an abnormal pointer position when the minimum value is negative
diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md
index a78125f3..a8cf44fd 100644
--- a/Assets/XCharts/CHANGELOG.md
+++ b/Assets/XCharts/CHANGELOG.md
@@ -35,6 +35,7 @@
## master
+* (2021.06.05) 完善`CandlestickChart`对`inverse`的支持 (#152)
* (2021.06.04) 优化自定义主题`Theme`的自动刷新 (#148)
* (2021.06.04) 修复`Gauge`在最小值为负数时指针指示位置异常的问题
diff --git a/Assets/XCharts/Runtime/Component/Sub/SerieData.cs b/Assets/XCharts/Runtime/Component/Sub/SerieData.cs
index a88d0639..3cf65215 100644
--- a/Assets/XCharts/Runtime/Component/Sub/SerieData.cs
+++ b/Assets/XCharts/Runtime/Component/Sub/SerieData.cs
@@ -123,40 +123,7 @@ namespace XCharts
/// 是否可以显示Label
///
public bool canShowLabel { get { return m_CanShowLabel; } set { m_CanShowLabel = value; } }
- ///
- /// the maxinum value.
- /// 最大值。
- ///
- public float max
- {
- get
- {
- if (m_Data.Count == 0) return 0;
- float temp = float.MinValue;
- for (int i = 0; i < m_Data.Count; i++)
- {
- if (m_Data[i] > temp) temp = m_Data[i];
- }
- return temp;
- }
- }
- ///
- /// the mininum value.
- /// 最小值。
- ///
- public float min
- {
- get
- {
- if (m_Data.Count == 0) return 0;
- float temp = float.MaxValue;
- for (int i = 0; i < m_Data.Count; i++)
- {
- if (m_Data[i] < temp) temp = m_Data[i];
- }
- return temp;
- }
- }
+
///
/// 饼图数据项的开始角度(运行时自动计算)
///
@@ -328,6 +295,38 @@ namespace XCharts
}
}
+ ///
+ /// the maxinum value.
+ /// 最大值。
+ ///
+ public float GetMaxData(bool inverse = false)
+ {
+ if (m_Data.Count == 0) return 0;
+ float temp = float.MinValue;
+ for (int i = 0; i < m_Data.Count; i++)
+ {
+ var value = GetData(i, inverse);
+ if (value > temp) temp = value;
+ }
+ return temp;
+ }
+
+ ///
+ /// the mininum value.
+ /// 最小值。
+ ///
+ public float GetMinData(bool inverse = false)
+ {
+ if (m_Data.Count == 0) return 0;
+ float temp = float.MaxValue;
+ for (int i = 0; i < m_Data.Count; i++)
+ {
+ var value = GetData(i, inverse);
+ if (value < temp) temp = value;
+ }
+ return temp;
+ }
+
public bool UpdateData(int dimension, float value, bool updateAnimation, float animationDuration = 500f)
{
if (dimension >= 0 && dimension < data.Count)
diff --git a/Assets/XCharts/Runtime/Helper/SeriesHelper.cs b/Assets/XCharts/Runtime/Helper/SeriesHelper.cs
index 99e36473..2f16e5d5 100644
--- a/Assets/XCharts/Runtime/Helper/SeriesHelper.cs
+++ b/Assets/XCharts/Runtime/Helper/SeriesHelper.cs
@@ -457,8 +457,8 @@ namespace XCharts
{
if (serie.type == SerieType.Candlestick)
{
- var dataMin = data.min;
- var dataMax = data.max;
+ var dataMin = data.GetMinData(inverse);
+ var dataMax = data.GetMaxData(inverse);
if (dataMax > max) max = dataMax;
if (dataMin < min) min = dataMin;
}
@@ -502,7 +502,7 @@ namespace XCharts
var currData = 0f;
if (serie.type == SerieType.Candlestick)
{
- currData = showData[j].max;
+ currData = showData[j].GetMaxData(false);
}
else
{
diff --git a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawCandlestick.cs b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawCandlestick.cs
index e2b20f9b..751c5899 100644
--- a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawCandlestick.cs
+++ b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawCandlestick.cs
@@ -50,7 +50,7 @@ namespace XCharts
var close = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var lowest = serieData.GetCurrData(2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var heighest = serieData.GetCurrData(3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
- var isRise = close > open;
+ var isRise = yAxis.inverse ? close < open : close > open;
var borderWidth = open == 0 ? 0f
: (itemStyle.runtimeBorderWidth == 0 ? m_Theme.serie.candlestickBorderWidth
: itemStyle.runtimeBorderWidth);