重构代码,将与绘制相关的Color改为Color32,减少隐式转换

This commit is contained in:
monitor1394
2020-08-23 14:31:26 +08:00
parent 85e8b17171
commit 951c3fe16c
30 changed files with 323 additions and 263 deletions

View File

@@ -1,6 +1,7 @@
# 更新日志
* (2020.08.23) Refactor code, replace `Color` with `Color32` for reduce implicit conversion (Can cause custom colors to lose, reference [Q&A 29](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/xcharts-questions-and-answers-EN.md) to upgrade)
* (2020.08.15) Optimize `PieChart` drawing performance effect #85
* (2020.08.11) Added `LiquidChart` data change animation#83
* (2020.08.11) Optimize `PieChart` text stack and lead line effects#85

View File

@@ -1,6 +1,7 @@
# 更新日志
* (2020.08.23) 重构代码,将与绘制相关的`Color`改为`Color32`,减少隐式转换(更新后会导致自定义的颜色丢失,可参考[问答29](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/XCharts问答.md)进行升级)
* (2020.08.15) 优化`PieChart`绘制表现效果#85
* (2020.08.11) 增加`LiquidChart`数据变更动画#83
* (2020.08.11) 优化`PieChart`文本堆叠和引线效果#85

View File

@@ -32,6 +32,7 @@
[QA 26如何使用背景组件有什么条件限制](#如何使用背景组件?有什么条件限制)
[QA 27Mesh can not have more than 65000 vertices?](#Mesh_cannot_have_more_than_65000_vertices)
[QA 28为什么serie里设置的参数运行后又被重置了?](#为什么serie里设置的参数运行后又被重置了)
[QA 29为什么升级到1.6.0版本后很多自定义颜色丢失了?应该如何升级?](#为什么升级到1.6.0版本后很多自定义颜色丢失了?应该如何升级)
## 如何调整坐标轴与背景的边距
@@ -149,6 +150,16 @@
答:检测下代码里是否调用了`RemoveData()`并重新添加`Serie`了。如果想保留`Serie`的配置可以只`ClearData()`,然后重新添加数据。
## 为什么升级到1.6.0版本后很多自定义颜色丢失了?应该如何升级
1.6.0版本为了减少隐式转换,将所有的绘制相关的`Color`都改为了`Color32`,所以会导致一些自定义的颜色的丢失。影响到的主要组件有:`ItemStyle``LineStyle``AreaStyle``Vessel``VisualMap``AxisSplitArea``AxisSplitLine``GaugeAxis``SerieLabel`等。可以用脚本[UpgradeChartColor.cs](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Editor/Tools/UpgradeChartColor.cs)进行升级。
升级步骤如下:
1. 备份项目。
2. 下载或拷贝脚本[UpgradeChartColor.cs](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Editor/Tools/UpgradeChartColor.cs)放到旧项目的`Editor`下,将里面编译报错的`color`字段改为`Color.clear`(因为旧版本可能有些字段还不存在)。
3. 编译通过后,通过`菜单栏->XCharts->ExportColorConfig`导出旧版本的颜色配置文件(配置文件默认保存到`Assets`下的`color.config`)。
4. 升级`XCharts`到最新版本。
5. 通过`菜单栏->XCharts->ImportColorConfig``color.config`导入即可恢复自定义的颜色(如果`color.config`不在升级后的项目的`Assets`下的话需要拷贝到此目录下)。
[返回首页](https://github.com/monitor1394/unity-ugui-XCharts)
[XChartsAPI接口](XChartsAPI.md)
[XCharts配置项手册](XCharts配置项手册.md)

View File

@@ -32,6 +32,7 @@
[QA 26: How do I use the background component? What are the conditions?](#How-do-I-use-the-background-component-What-are-the-conditions)
[QA 27: Mesh can not have more than 65000 vertices?](#Mesh-cannot-have-more-than-65000-vertices)
[QA 28: Why are the parameters set in Serie reset after they run?](#Why-are-the-parameters-set-in-Serie-reset-after-they-run)
[QA 29: Why are many custom colors lost after upgrading to 1.6.0? How should I upgrade?](#Why_are_many_custom_colors_lost_after_upgrading_to_1.6.0_How_should_I_upgrade)
## How-to-adjust-the-margin-between-the-axis-and-the=-background
@@ -145,6 +146,16 @@ A: This is the limit of `UGUI` on the number of vertices for a single `Graphic`.
A: Check whether `RemoveData()` and add new `Serie` in the code. If you want to keep the configuration of `Serie`, you can only `ClearData()` which just clear data and then readd the data to the old serie.
## Why_are_many_custom_colors_lost_after_upgrading_to_1.6.0_How_should_I_upgrade
A: In version `1.6.0`, in order to reduce implicit conversion, all drawing related `Color` was changed to `Color32`, so some custom colors were lost. The main components affected are: `ItemStyle`, `LineStyle`, `AreaStyle`, `Vessel`, `VisualMap`, `AxisSplitArea`, `AxisSplitLine`, `GaugeAxis`,`SerieLabel`, etc. Can use the script [UpgradeChartColor.cs](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Editor/Tools/UpgradeChartColor.cs) to upgrade.
The upgrade steps are as follows:
1. Back up the project.
2. Download or copy the script [UpgradeChartColor.cs](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Editor/Tools/UpgradeChartColor.cs) in the old project `Editor`, Change the `color` field inside to `color.clear` (because some fields may not exist in the old version).
3. After compilation, the old version of color configuration file is exported through `menu bar -> XCharts-> ExportColorConfig` (the configuration file is saved by default to `color.config` under `Assets`).
4. Upgrade `XCharts` to the latest version.
5. The custom color can be restored by importing `color.config` through `menu bar -> XCharts-> ImportColorConfig` (if `color.config` is not under `Assets` of the upgraded project, copy it to this directory).
[XCharts Homepage](https://github.com/monitor1394/unity-ugui-XCharts)
[XCharts API](xcharts-api-EN.md)
[XCharts Configuration](xcharts-configuration-EN.md)

View File

@@ -47,8 +47,8 @@ namespace XCharts
[SerializeField] private Shape m_Shape = Shape.Circle;
[SerializeField] private float m_ShapeWidth = 5f;
[SerializeField] private float m_Gap = 10f;
[SerializeField] private Color m_Color;
[SerializeField] private Color m_BackgroundColor;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_BackgroundColor;
[SerializeField] private bool m_AutoColor = true;
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
[SerializeField] private float m_Radius = 0.5f;
@@ -132,7 +132,7 @@ namespace XCharts
/// 背景色,默认透明。
/// [default: `Color.clear`]
/// </summary>
public Color backgroundColor
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
@@ -141,7 +141,7 @@ namespace XCharts
/// Vessel color. The default is consistent with Serie.
/// 容器颜色。默认和serie一致。
/// </summary>
public Color color
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }

View File

@@ -88,8 +88,8 @@ namespace XCharts
[SerializeField] private bool m_AutoMinMax = true;
[SerializeField] private Orient m_Orient = Orient.Horizonal;
[SerializeField] private Location m_Location = Location.defaultLeft;
[SerializeField] private List<Color> m_InRange = new List<Color>();
[SerializeField] private List<Color> m_OutOfRange = new List<Color>();
[SerializeField] private List<Color32> m_InRange = new List<Color32>();
[SerializeField] private List<Color32> m_OutOfRange = new List<Color32>();
/// <summary>
/// Whether enable visualMap component.
@@ -297,7 +297,7 @@ namespace XCharts
/// Defines the visual color in the selected range.
/// 定义 在选中范围中 的视觉颜色。
/// </summary>
public List<Color> inRange
public List<Color32> inRange
{
get { return m_InRange; }
set { if (value != null) { m_InRange = value; SetVerticesDirty(); } }
@@ -306,7 +306,7 @@ namespace XCharts
/// Defines a visual color outside of the selected range.
/// 定义 在选中范围外 的视觉颜色。
/// </summary>
public List<Color> outOfRange
public List<Color32> outOfRange
{
get { return m_OutOfRange; }
set { if (value != null) { m_OutOfRange = value; SetVerticesDirty(); } }
@@ -375,8 +375,8 @@ namespace XCharts
public float runtimeRangeMinHeight { get { return (rangeMin - min) / (max - min) * itemHeight; } }
public float runtimeRangeMaxHeight { get { return (rangeMax - min) / (max - min) * itemHeight; } }
private List<Color> m_RtInRange = new List<Color>();
public List<Color> runtimeInRange
private List<Color32> m_RtInRange = new List<Color32>();
public List<Color32> runtimeInRange
{
get
{
@@ -413,7 +413,7 @@ namespace XCharts
else
{
var rate = (rtValue - inValue) / diff1;
m_RtInRange.Add(Color.Lerp(m_InRange[inCount], m_InRange[inCount + 1], rate));
m_RtInRange.Add(Color32.Lerp(m_InRange[inCount], m_InRange[inCount + 1], rate));
}
}
}
@@ -422,21 +422,21 @@ namespace XCharts
}
}
public Color GetColor(float value)
public Color32 GetColor(float value)
{
if (value < m_Min || value > m_Max)
{
if (m_OutOfRange.Count > 0) return m_OutOfRange[0];
else return Color.clear;
else return ChartConst.clearColor32;
}
int splitNumber = runtimeInRange.Count;
if (splitNumber <= 0) return Color.clear;
if (splitNumber <= 0) return ChartConst.clearColor32;
var index = GetIndex(value);
if (m_Type == VisualMap.Type.Piecewise)
{
if (index >= 0 && index < runtimeInRange.Count)
return runtimeInRange[index];
else return Color.clear;
else return ChartConst.clearColor32;
}
else
{
@@ -444,7 +444,7 @@ namespace XCharts
var nowMin = m_Min + index * diff;
var rate = (value - nowMin) / diff;
if (index == splitNumber - 1) return runtimeInRange[index];
else return Color.Lerp(runtimeInRange[index], runtimeInRange[index + 1], rate);
else return Color32.Lerp(runtimeInRange[index], runtimeInRange[index + 1], rate);
}
}

View File

@@ -41,12 +41,12 @@ namespace XCharts
}
[SerializeField] private bool m_Show;
[SerializeField] private AreaOrigin m_Origin;
[SerializeField] private Color m_Color;
[SerializeField] private Color m_ToColor;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_ToColor;
[SerializeField] [Range(0, 1)] private float m_Opacity;
[SerializeField] private bool m_TooltipHighlight;
[SerializeField] private Color m_HighlightColor;
[SerializeField] private Color m_HighlightToColor;
[SerializeField] private Color32 m_HighlightColor;
[SerializeField] private Color32 m_HighlightToColor;
/// <summary>
/// Set this to false to prevent the areafrom showing.
@@ -70,7 +70,7 @@ namespace XCharts
/// the color of area,default use serie color.
/// 区域填充的颜色如果toColor不是默认值则表示渐变色的起点颜色。
/// </summary>
public Color color
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
@@ -79,7 +79,7 @@ namespace XCharts
/// Gradient color, start color to toColor.
/// 渐变色的终点颜色。
/// </summary>
public Color toColor
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtility.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
@@ -105,7 +105,7 @@ namespace XCharts
/// the color of area,default use serie color.
/// 高亮时区域填充的颜色如果highlightToColor不是默认值则表示渐变色的起点颜色。
/// </summary>
public Color highlightColor
public Color32 highlightColor
{
get { return m_HighlightColor; }
set { if (PropertyUtility.SetColor(ref m_HighlightColor, value)) SetVerticesDirty(); }
@@ -114,7 +114,7 @@ namespace XCharts
/// Gradient color, start highlightColor to highlightToColor.
/// 高亮时渐变色的终点颜色。
/// </summary>
public Color highlightToColor
public Color32 highlightToColor
{
get { return m_HighlightToColor; }
set { if (PropertyUtility.SetColor(ref m_HighlightToColor, value)) SetVerticesDirty(); }

View File

@@ -19,7 +19,7 @@ namespace XCharts
public class AxisSplitArea : SubComponent
{
[SerializeField] private bool m_Show;
[SerializeField] private List<Color> m_Color;
[SerializeField] private List<Color32> m_Color;
/// <summary>
/// Set this to true to show the splitArea.
@@ -36,7 +36,7 @@ namespace XCharts
/// Dark and light colors in turns are used by default.
/// 分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
/// </summary>
public List<Color> color
public List<Color32> color
{
get { return m_Color; }
set { if (value != null) { m_Color = value; SetVerticesDirty(); } }
@@ -49,7 +49,7 @@ namespace XCharts
return new AxisSplitArea()
{
m_Show = false,
m_Color = new List<Color>(){
m_Color = new List<Color32>(){
new Color32(250,250,250,77),
new Color32(200,200,200,77)
}
@@ -61,7 +61,7 @@ namespace XCharts
{
var axisSplitArea = new AxisSplitArea();
axisSplitArea.show = show;
axisSplitArea.color = new List<Color>();
axisSplitArea.color = new List<Color32>();
ChartHelper.CopyList(axisSplitArea.color, color);
return axisSplitArea;
}
@@ -73,7 +73,7 @@ namespace XCharts
ChartHelper.CopyList(color, splitArea.color);
}
public Color getColor(int index)
public Color32 getColor(int index)
{
var i = index % color.Count;
return color[i];

View File

@@ -77,18 +77,16 @@ namespace XCharts
lineStyle.Copy(splitLine.lineStyle);
}
internal Color GetColor(ThemeInfo theme)
internal Color32 GetColor(ThemeInfo theme)
{
if (!ChartHelper.IsClearColor(lineStyle.color))
{
var color = lineStyle.color;
color.a *= lineStyle.opacity;
return color;
return lineStyle.GetColor();
}
else
{
var color = (Color)theme.axisSplitLineColor;
color.a *= lineStyle.opacity;
var color = theme.axisSplitLineColor;
color.a *= (byte)(color.a * lineStyle.opacity);
return color;
}
}

View File

@@ -24,7 +24,7 @@ namespace XCharts
public class StageColor
{
[SerializeField] private float m_Percent;
[SerializeField] private Color m_Color;
[SerializeField] private Color32 m_Color;
/// <summary>
/// 结束位置百分比。
/// </summary>
@@ -32,9 +32,9 @@ namespace XCharts
/// <summary>
/// 颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public Color32 color { get { return m_Color; } set { m_Color = value; } }
public StageColor(float percent, Color color)
public StageColor(float percent, Color32 color)
{
m_Percent = percent;
m_Color = color;
@@ -43,8 +43,8 @@ namespace XCharts
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Width = 15f;
[SerializeField] private float m_Opacity = 1f;
[SerializeField] private Color m_BarColor;
[SerializeField] private Color m_BarBackgroundColor = new Color32(200, 200, 200, 255);
[SerializeField] private Color32 m_BarColor;
[SerializeField] private Color32 m_BarBackgroundColor = new Color32(200, 200, 200, 255);
[SerializeField]
private List<StageColor> m_StageColor = new List<StageColor>()
{
@@ -71,11 +71,11 @@ namespace XCharts
/// <summary>
/// 进度条颜色。
/// </summary>
public Color barColor { get { return m_BarColor; } set { m_BarColor = value; } }
public Color32 barColor { get { return m_BarColor; } set { m_BarColor = value; } }
/// <summary>
/// 进度条背景颜色。
/// </summary>
public Color barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } }
public Color32 barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } }
/// <summary>
/// 阶段颜色。
/// </summary>
@@ -183,27 +183,27 @@ namespace XCharts
public List<Vector3> runtimeLabelPosition = new List<Vector3>();
private List<LabelObject> m_RuntimeLabelList = new List<LabelObject>();
internal Color GetAxisLineColor(ThemeInfo theme, int index)
internal Color32 GetAxisLineColor(ThemeInfo theme, int index)
{
var color = !ChartHelper.IsClearColor(axisLine.barColor) ? axisLine.barColor : (Color)theme.GetColor(index);
color.a *= axisLine.opacity;
var color = !ChartHelper.IsClearColor(axisLine.barColor) ? axisLine.barColor : theme.GetColor(index);
ChartHelper.SetColorOpacity(ref color, axisLine.opacity);
return color;
}
internal Color GetAxisLineBackgroundColor(ThemeInfo theme, int index)
internal Color32 GetAxisLineBackgroundColor(ThemeInfo theme, int index)
{
var color = !ChartHelper.IsClearColor(axisLine.barBackgroundColor) ? axisLine.barBackgroundColor : Color.grey;
color.a *= axisLine.opacity;
var color = !ChartHelper.IsClearColor(axisLine.barBackgroundColor) ? axisLine.barBackgroundColor : ChartConst.greyColor32;
ChartHelper.SetColorOpacity(ref color, axisLine.opacity);
return color;
}
internal Color GetSplitLineColor(ThemeInfo theme, int serieIndex, float angle)
internal Color32 GetSplitLineColor(ThemeInfo theme, int serieIndex, float angle)
{
Color color;
Color32 color;
if (!ChartHelper.IsClearColor(splitLine.lineStyle.color))
{
color = splitLine.lineStyle.color;
color.a *= splitLine.lineStyle.opacity;
ChartHelper.SetColorOpacity(ref color, splitLine.lineStyle.opacity);
return color;
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
@@ -211,22 +211,22 @@ namespace XCharts
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
color.a *= splitLine.lineStyle.opacity;
ChartHelper.SetColorOpacity(ref color, splitLine.lineStyle.opacity);
return color;
}
}
color = theme.GetColor(serieIndex);
color.a *= splitLine.lineStyle.opacity;
ChartHelper.SetColorOpacity(ref color, splitLine.lineStyle.opacity);
return color;
}
internal Color GetAxisTickColor(ThemeInfo theme, int serieIndex, float angle)
internal Color32 GetAxisTickColor(ThemeInfo theme, int serieIndex, float angle)
{
Color color;
Color32 color;
if (!ChartHelper.IsClearColor(axisTick.lineStyle.color))
{
color = axisTick.lineStyle.color;
color.a *= axisTick.lineStyle.opacity;
ChartHelper.SetColorOpacity(ref color, axisTick.lineStyle.opacity);
return color;
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
@@ -234,35 +234,33 @@ namespace XCharts
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
color.a *= axisTick.lineStyle.opacity;
ChartHelper.SetColorOpacity(ref color, axisTick.lineStyle.opacity);
return color;
}
}
color = theme.GetColor(serieIndex);
color.a *= axisTick.lineStyle.opacity;
ChartHelper.SetColorOpacity(ref color, axisTick.lineStyle.opacity);
return color;
}
internal Color GetPointerColor(ThemeInfo theme, int serieIndex, float angle, ItemStyle itemStyle)
internal Color32 GetPointerColor(ThemeInfo theme, int serieIndex, float angle, ItemStyle itemStyle)
{
Color color;
Color32 color;
if (!ChartHelper.IsClearColor(itemStyle.color))
{
color = itemStyle.color;
color.a *= itemStyle.opacity;
return color;
return itemStyle.GetColor();
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
{
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
color.a *= itemStyle.opacity;
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
}
color = theme.GetColor(serieIndex);
color.a *= itemStyle.opacity;
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}

View File

@@ -36,16 +36,16 @@ namespace XCharts
Dotted
}
[SerializeField] private bool m_Show = false;
[SerializeField] private Color m_Color;
[SerializeField] private Color m_ToColor;
[SerializeField] private Color m_ToColor2;
[SerializeField] private Color m_BackgroundColor;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_ToColor;
[SerializeField] private Color32 m_ToColor2;
[SerializeField] private Color32 m_BackgroundColor;
[SerializeField] private float m_BackgroundWidth;
[SerializeField] private Color m_CenterColor;
[SerializeField] private Color32 m_CenterColor;
[SerializeField] private float m_CenterGap;
[SerializeField] private Type m_BorderType = Type.Solid;
[SerializeField] private float m_BorderWidth = 0;
[SerializeField] private Color m_BorderColor;
[SerializeField] private Color32 m_BorderColor;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
[SerializeField] private string m_TooltipFormatter;
[SerializeField] private string m_NumericFormatter = "";
@@ -89,7 +89,7 @@ namespace XCharts
/// <summary>
/// 数据项颜色。
/// </summary>
public Color color
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
@@ -98,7 +98,7 @@ namespace XCharts
/// Gradient color1.
/// 渐变色的颜色1。
/// </summary>
public Color toColor
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtility.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
@@ -107,7 +107,7 @@ namespace XCharts
/// Gradient color2.Only valid in line diagrams.
/// 渐变色的颜色2。只在折线图中有效。
/// </summary>
public Color toColor2
public Color32 toColor2
{
get { return m_ToColor2; }
set { if (PropertyUtility.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
@@ -115,7 +115,7 @@ namespace XCharts
/// <summary>
/// 数据项背景颜色。
/// </summary>
public Color backgroundColor
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
@@ -123,7 +123,7 @@ namespace XCharts
/// <summary>
/// 中心区域颜色。
/// </summary>
public Color centerColor
public Color32 centerColor
{
get { return m_CenterColor; }
set { if (PropertyUtility.SetColor(ref m_CenterColor, value)) SetVerticesDirty(); }
@@ -155,7 +155,7 @@ namespace XCharts
/// <summary>
/// 边框的颜色。
/// </summary>
public Color borderColor
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtility.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
@@ -218,11 +218,11 @@ namespace XCharts
return borderWidth != 0 && !ChartHelper.IsClearColor(borderColor);
}
public Color GetColor()
public Color32 GetColor()
{
if (m_Opacity == 1) return m_Color;
if (m_Opacity == 1 || m_Color.a == 0) return m_Color;
var color = m_Color;
color.a *= m_Opacity;
color.a = (byte)(color.a * m_Opacity);
return color;
}
@@ -231,19 +231,19 @@ namespace XCharts
return !ChartHelper.IsClearColor(m_ToColor) || !ChartHelper.IsClearColor(m_ToColor2);
}
public Color GetGradientColor(float value, Color defaultColor)
public Color32 GetGradientColor(float value, Color32 defaultColor)
{
if (!IsNeedGradient()) return Color.clear;
if (!IsNeedGradient()) return ChartConst.clearColor32;
value = Mathf.Clamp01(value);
var startColor = m_Color == Color.clear ? defaultColor : m_Color;
if (m_ToColor2 != Color.clear)
var startColor = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
if (!ChartHelper.IsClearColor(m_ToColor2))
{
if (value <= 0.5f) return Color.Lerp(startColor, m_ToColor, 2 * value);
else return Color.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
if (value <= 0.5f) return Color32.Lerp(startColor, m_ToColor, 2 * value);
else return Color32.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
}
else
{
return Color.Lerp(startColor, m_ToColor, value);
return Color32.Lerp(startColor, m_ToColor, value);
}
}
}

View File

@@ -46,7 +46,7 @@ namespace XCharts
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Type m_Type = Type.Solid;
[SerializeField] private Color m_Color;
[SerializeField] private Color32 m_Color;
[SerializeField] private float m_Width = 0.8f;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
@@ -72,7 +72,7 @@ namespace XCharts
/// the color of line, default use serie color.
/// 线的颜色。
/// </summary>
public Color color
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
@@ -131,10 +131,11 @@ namespace XCharts
opacity = lineStyle.opacity;
}
public Color GetColor()
public Color32 GetColor()
{
if (m_Opacity == 1) return m_Color;
var color = m_Color;
color.a *= m_Opacity;
color.a *= (byte)(color.a * m_Opacity);
return color;
}
}

View File

@@ -87,20 +87,20 @@ namespace XCharts
[SerializeField] private float m_PaddingLeftRight = 2f;
[SerializeField] private float m_PaddingTopBottom = 2f;
[SerializeField] private Color m_Color;
[SerializeField] private Color m_BackgroundColor;
[SerializeField] private Color32 m_BackgroundColor;
[SerializeField] private float m_BackgroundWidth = 0;
[SerializeField] private float m_BackgroundHeight = 0;
[SerializeField] private int m_FontSize = 18;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private bool m_Line = true;
[SerializeField] private LineType m_LineType = LineType.BrokenLine;
[SerializeField] private Color m_LineColor = Color.clear;
[SerializeField] private Color32 m_LineColor = ChartConst.clearColor32;
[SerializeField] private float m_LineWidth = 1.0f;
[SerializeField] private float m_LineLength1 = 25f;
[SerializeField] private float m_LineLength2 = 15f;
[SerializeField] private bool m_Border = false;
[SerializeField] private float m_BorderWidth = 0.5f;
[SerializeField] private Color m_BorderColor = Color.grey;
[SerializeField] private Color32 m_BorderColor = ChartConst.greyColor32;
[SerializeField] private string m_NumericFormatter = "";
[SerializeField] private bool m_AutoOffset = false;
@@ -197,7 +197,7 @@ namespace XCharts
/// the background color. If set as default, it means than don't show background.
/// 标签的背景色,默认无颜色。
/// </summary>
public Color backgroundColor
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetStruct(ref m_BackgroundColor, value)) SetVerticesDirty(); }
@@ -289,7 +289,7 @@ namespace XCharts
/// the color of visual guild line.
/// 视觉引导线颜色。默认和serie一致取自调色板。
/// </summary>
public Color lineColor
public Color32 lineColor
{
get { return m_LineColor; }
set { if (PropertyUtility.SetStruct(ref m_LineColor, value)) SetVerticesDirty(); }
@@ -343,7 +343,7 @@ namespace XCharts
/// the color of border.
/// 边框颜色。
/// </summary>
public Color borderColor
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtility.SetStruct(ref m_BorderColor, value)) SetVerticesDirty(); }

View File

@@ -106,7 +106,7 @@ namespace XCharts
var serieData = serie.data[(int)xData * yCount + (int)yData];
var value = serieData.data[2];
var color = m_VisualMap.enable ? m_VisualMap.GetColor(value) :
(Color)m_ThemeInfo.GetColor(serie.index);
m_ThemeInfo.GetColor(serie.index);
sb.Append("\n")
.Append(key).Append(!string.IsNullOrEmpty(key) ? "\n" : "")
.Append("<color=#").Append(ChartCached.ColorToStr(color)).Append(">● </color>")

View File

@@ -727,7 +727,7 @@ namespace XCharts
}
public void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
float tickness, Vector3 pos, Color color, Color toColor, float gap, float[] cornerRadius)
float tickness, Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius)
{
var backgroundColor = ThemeHelper.GetBackgroundColor(m_ThemeInfo, m_Background);
var smoothness = m_Settings.cicleSmoothness;
@@ -771,7 +771,6 @@ namespace XCharts
ChartDrawer.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(),
serieLabel.borderWidth, serieLabel.borderColor, serieLabel.rotate);
}
ChartDrawer.DrawPolygon(vh, serieData.labelPosition, 0.3f, Color.red);
}
}
}

View File

@@ -1180,11 +1180,13 @@ namespace XCharts
np = new Vector3(pX, m_ChartY + m_DataZoom.bottom + dataHig);
if (i > 0)
{
Color color = m_ThemeInfo.dataZoomLineColor;
var color = m_ThemeInfo.dataZoomLineColor;
ChartDrawer.DrawLine(vh, lp, np, xAxis.axisLine.width, color);
Vector3 alp = new Vector3(lp.x, lp.y - xAxis.axisLine.width);
Vector3 anp = new Vector3(np.x, np.y - xAxis.axisLine.width);
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
var areaColor = color;
areaColor.a = (byte)(areaColor.a * 0.75f);
Vector3 tnp = new Vector3(np.x, m_ChartY + m_DataZoom.bottom + xAxis.axisLine.width);
Vector3 tlp = new Vector3(lp.x, m_ChartY + m_DataZoom.bottom + xAxis.axisLine.width);
ChartDrawer.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
@@ -1830,7 +1832,7 @@ namespace XCharts
}
protected void CheckClipAndDrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
float tickness, Vector3 pos, Color color, Color toColor, float gap, bool clip, float[] cornerRadius)
float tickness, Vector3 pos, Color32 color, Color32 toColor, float gap, bool clip, float[] cornerRadius)
{
if (!IsInChart(pos)) return;
if (!clip || (clip && (IsInCooridate(pos))))
@@ -1845,16 +1847,16 @@ namespace XCharts
ChartDrawer.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color);
}
protected Color GetXLerpColor(Color areaColor, Color areaToColor, Vector3 pos)
protected Color32 GetXLerpColor(Color32 areaColor, Color32 areaToColor, Vector3 pos)
{
if (areaColor == areaToColor) return areaColor;
return Color.Lerp(areaToColor, areaColor, (pos.y - m_CoordinateY) / m_CoordinateHeight);
if (ChartHelper.IsValueEqualsColor(areaColor, areaToColor)) return areaColor;
return Color32.Lerp(areaToColor, areaColor, (pos.y - m_CoordinateY) / m_CoordinateHeight);
}
protected Color GetYLerpColor(Color areaColor, Color areaToColor, Vector3 pos)
protected Color32 GetYLerpColor(Color32 areaColor, Color32 areaToColor, Vector3 pos)
{
if (areaColor == areaToColor) return areaColor;
return Color.Lerp(areaToColor, areaColor, (pos.x - m_CoordinateX) / m_CoordinateWidth);
if (ChartHelper.IsValueEqualsColor(areaColor, areaToColor)) return areaColor;
return Color32.Lerp(areaToColor, areaColor, (pos.x - m_CoordinateX) / m_CoordinateWidth);
}
}
}

View File

@@ -298,8 +298,8 @@ namespace XCharts
bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
Vector3 prb, bool isYAxis)
{
Color areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis);
var borderWidth = itemStyle.runtimeBorderWidth;
if (isYAxis)
@@ -360,7 +360,7 @@ namespace XCharts
bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
Vector3 prb, bool isYAxis)
{
Color areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis);
if (isYAxis)
{
@@ -382,8 +382,8 @@ namespace XCharts
bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
Vector3 prb, bool isYAxis)
{
Color areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis);
var borderWidth = itemStyle.runtimeBorderWidth;
var radius = barWidth / 2 - borderWidth;
@@ -400,8 +400,8 @@ namespace XCharts
if (isGradient)
{
var barLen = prt.x - plt.x;
var rectStartColor = Color.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, rectStartColor, rectEndColor, serie.clip);
ChartDrawer.DrawSector(vh, pcl, radius, areaColor, rectStartColor, 180, 360, 1, isYAxis);
ChartDrawer.DrawSector(vh, pcr, radius, rectEndColor, areaToColor, 0, 180, 1, isYAxis);
@@ -423,8 +423,8 @@ namespace XCharts
if (isGradient)
{
var barLen = plt.x - prt.x;
var rectStartColor = Color.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, rectStartColor, rectEndColor, serie.clip);
ChartDrawer.DrawSector(vh, pcl, radius, rectStartColor, areaColor, 0, 180, 1, isYAxis);
ChartDrawer.DrawSector(vh, pcr, radius, areaToColor, rectEndColor, 180, 360, 1, isYAxis);
@@ -450,8 +450,8 @@ namespace XCharts
if (isGradient)
{
var barLen = plt.y - plb.y;
var rectStartColor = Color.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, rectStartColor, rectEndColor, serie.clip);
ChartDrawer.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 270, 450, 1, isYAxis);
ChartDrawer.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 90, 270, 1, isYAxis);
@@ -473,8 +473,8 @@ namespace XCharts
if (isGradient)
{
var barLen = plb.y - plt.y;
var rectStartColor = Color.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, rectStartColor, rectEndColor, serie.clip);
ChartDrawer.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 90, 270, 1, isYAxis);
ChartDrawer.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 270, 450, 1, isYAxis);
@@ -493,7 +493,7 @@ namespace XCharts
private void DrawBarBackground(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
bool highlight, float pX, float pY, float space, float barWidth, bool isYAxis)
{
Color color = SerieHelper.GetItemBackgroundColor(serie, serieData, m_ThemeInfo, colorIndex, highlight, false);
var color = SerieHelper.GetItemBackgroundColor(serie, serieData, m_ThemeInfo, colorIndex, highlight, false);
if (ChartHelper.IsClearColor(color)) return;
if (isYAxis)
{
@@ -525,8 +525,8 @@ namespace XCharts
var p4 = prt - diff - Vector3.up * borderWidth / 2;
ChartDrawer.DrawLine(vh, p1, p2, borderWidth / 2, borderColor);
ChartDrawer.DrawLine(vh, p3, p4, borderWidth / 2, borderColor);
ChartDrawer.DrawDoughnut(vh, pcl, inRadius, outRadius, borderColor, Color.clear, 180, 360, smoothness);
ChartDrawer.DrawDoughnut(vh, pcr, inRadius, outRadius, borderColor, Color.clear, 0, 180, smoothness);
ChartDrawer.DrawDoughnut(vh, pcl, inRadius, outRadius, borderColor, ChartConst.clearColor32, 180, 360, smoothness);
ChartDrawer.DrawDoughnut(vh, pcr, inRadius, outRadius, borderColor, ChartConst.clearColor32, 0, 180, smoothness);
}
}
else
@@ -564,8 +564,8 @@ namespace XCharts
var p4 = prt - diff - Vector3.right * borderWidth / 2;
ChartDrawer.DrawLine(vh, p1, p2, borderWidth / 2, borderColor);
ChartDrawer.DrawLine(vh, p3, p4, borderWidth / 2, borderColor);
ChartDrawer.DrawDoughnut(vh, pct, inRadius, outRadius, borderColor, Color.clear, 270, 450, smoothness);
ChartDrawer.DrawDoughnut(vh, pcb, inRadius, outRadius, borderColor, Color.clear, 90, 270, smoothness);
ChartDrawer.DrawDoughnut(vh, pct, inRadius, outRadius, borderColor, ChartConst.clearColor32, 270, 450, smoothness);
ChartDrawer.DrawDoughnut(vh, pcb, inRadius, outRadius, borderColor, ChartConst.clearColor32, 90, 270, smoothness);
}
}
else

View File

@@ -131,8 +131,8 @@ namespace XCharts
var rangeMax = m_VisualMap.rangeMax;
var color = m_ThemeInfo.GetColor(serie.index);
var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : Color.clear;
borderColor.a *= serie.itemStyle.opacity;
var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : ChartConst.clearColor32;
borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity);
serie.dataPoints.Clear();
serie.animation.InitProgress(1, 0, xCount);
var animationIndex = serie.animation.GetCurrIndex();
@@ -181,7 +181,7 @@ namespace XCharts
if (m_VisualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0)
{
var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderColor : Color.clear;
var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderColor : ChartConst.clearColor32;
ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor);
}
}

View File

@@ -57,7 +57,7 @@ namespace XCharts
if (serie.type != SerieType.Line) continue;
if (!serie.show || !serie.lineArrow.show) continue;
if (serie.dataPoints.Count < 2) return;
Color lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, n, false);
Color32 lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, n, false);
Vector3 startPos, arrowPos;
switch (serie.lineArrow.position)
{
@@ -95,12 +95,12 @@ namespace XCharts
if (serie.animation.HasFadeOut()) return;
var showData = serie.GetDataList(m_DataZoom);
if (showData.Count <= 0) return;
Color lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, colorIndex, serie.highlighted);
Color srcAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, false);
Color srcAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, false);
Color highlightAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, true);
Color highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, true);
Color areaColor, areaToColor;
Color32 lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, colorIndex, serie.highlighted);
Color32 srcAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, false);
Color32 srcAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, false);
Color32 highlightAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, true);
Color32 highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, true);
Color32 areaColor, areaToColor;
Vector3 lp = Vector3.zero, np = Vector3.zero, llp = Vector3.zero, nnp = Vector3.zero;
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
@@ -488,12 +488,12 @@ namespace XCharts
Vector3 np = Vector3.zero;
Vector3 llp = Vector3.zero;
Vector3 nnp = Vector3.zero;
Color lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, colorIndex, serie.highlighted);
Color srcAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, false);
Color srcAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, false);
Color highlightAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, true);
Color highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, true);
Color areaColor, areaToColor;
var lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, colorIndex, serie.highlighted);
var srcAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, false);
var srcAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, false);
var highlightAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, true);
var highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, true);
Color32 areaColor, areaToColor;
var xAxis = m_XAxises[serie.axisIndex];
var yAxis = m_YAxises[serie.axisIndex];
var zeroPos = new Vector3(m_CoordinateX + xAxis.runtimeZeroXOffset, m_CoordinateY);
@@ -646,7 +646,7 @@ namespace XCharts
private Vector3 stPos1, stPos2, lastDir, lastDnPos;
private bool lastIsDown;
private bool DrawNormalLine(VertexHelper vh, Serie serie, Axis axis, Vector3 lp, Vector3 np, Vector3 nnp,
int dataIndex, Color lineColor, Color areaColor, Color areaToColor,
int dataIndex, Color32 lineColor, Color32 areaColor, Color32 areaToColor,
Vector3 zeroPos, int startIndex = 0)
{
var defaultLineColor = lineColor;
@@ -1055,7 +1055,7 @@ namespace XCharts
return false;
}
private void CheckLineGradientColor(Vector3 cp, ItemStyle itemStyle, Axis axis, Color defaultLineColor, ref Color lineColor)
private void CheckLineGradientColor(Vector3 cp, ItemStyle itemStyle, Axis axis, Color32 defaultLineColor, ref Color32 lineColor)
{
if (VisualMapHelper.IsNeedGradient(m_VisualMap))
lineColor = VisualMapHelper.GetLineGradientColor(m_VisualMap, cp, this, axis, defaultLineColor);
@@ -1082,7 +1082,7 @@ namespace XCharts
}
private void DrawPolygonToZero(VertexHelper vh, Vector3 sp, Vector3 ep, Axis axis, Vector3 zeroPos,
Color areaColor, Color areaToColor, Vector3 areaDiff, bool clip = false)
Color32 areaColor, Color32 areaToColor, Vector3 areaDiff, bool clip = false)
{
float diff = 0;
if (axis is YAxis)
@@ -1115,8 +1115,8 @@ namespace XCharts
private List<Vector3> posList = new List<Vector3>();
private bool DrawOtherLine(VertexHelper vh, Serie serie, Axis axis, Vector3 lp,
Vector3 np, int dataIndex, Color lineColor, Color areaColor,
Color areaToColor, Vector3 zeroPos)
Vector3 np, int dataIndex, Color32 lineColor, Color32 areaColor,
Color32 areaToColor, Vector3 zeroPos)
{
//lp = ClampInChart(lp);
//np = ClampInChart(np);
@@ -1157,8 +1157,8 @@ namespace XCharts
private List<Vector3> bezierPoints = new List<Vector3>();
private Vector3 smoothStartPosUp, smoothStartPosDn;
private bool DrawSmoothLine(VertexHelper vh, Serie serie, Axis xAxis, Vector3 lp,
Vector3 np, Vector3 llp, Vector3 nnp, int dataIndex, Color lineColor, Color areaColor,
Color areaToColor, bool isStack, Vector3 zeroPos, int startIndex = 0)
Vector3 np, Vector3 llp, Vector3 nnp, int dataIndex, Color32 lineColor, Color32 areaColor,
Color32 areaToColor, bool isStack, Vector3 zeroPos, int startIndex = 0)
{
var defaultLineColor = lineColor;
bool isYAxis = xAxis is YAxis;
@@ -1319,7 +1319,7 @@ namespace XCharts
}
private void DrawStackArea(VertexHelper vh, Serie serie, Axis axis, List<Vector3> smoothPoints,
List<Vector3> lastSmoothPoints, Color areaColor, Color areaToColor)
List<Vector3> lastSmoothPoints, Color32 areaColor, Color32 areaToColor)
{
if (!serie.areaStyle.show || lastSmoothPoints.Count <= 0) return;
Vector3 start, to;
@@ -1409,7 +1409,7 @@ namespace XCharts
private List<Vector3> linePointList = new List<Vector3>();
private bool DrawStepLine(VertexHelper vh, Serie serie, Axis axis, Vector3 lp, Vector3 np,
Vector3 nnp, int dataIndex, Color lineColor, Color areaColor, Color areaToColor, Vector3 zeroPos)
Vector3 nnp, int dataIndex, Color32 lineColor, Color32 areaColor, Color32 areaToColor, Vector3 zeroPos)
{
bool isYAxis = axis is YAxis;
float lineWidth = serie.lineStyle.width;

View File

@@ -62,7 +62,7 @@ namespace XCharts
for (int count = 0; count < symbol.animationSize.Count; count++)
{
var nowSize = symbol.animationSize[count];
color.a = (symbolSize - nowSize) / symbolSize;
color.a = (byte)(255 * (symbolSize - nowSize) / symbolSize);
DrawSymbol(vh, symbol.type, nowSize, symbolBorder, pos, color, toColor, symbol.gap, cornerRadius);
}
RefreshChart();

View File

@@ -11,17 +11,17 @@ namespace XCharts
{
public static partial class SerieHelper
{
internal static Color GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index,
internal static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index,
bool highlight, bool useDefault = true)
{
var color = Color.clear;
var color = ChartConst.clearColor32;
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.backgroundColor))
{
color = itemStyleEmphasis.backgroundColor;
color.a *= itemStyleEmphasis.opacity;
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
return color;
}
}
@@ -29,60 +29,55 @@ namespace XCharts
if (!ChartHelper.IsClearColor(itemStyle.backgroundColor))
{
color = itemStyle.backgroundColor;
if (highlight) color *= color;
color.a *= itemStyle.opacity;
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
else if (useDefault)
{
color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a = 0.2f;
color = theme.GetColor(index);
if (highlight) color = ChartHelper.GetHighlightColor(color);
color.a = 50;
return color;
}
return color;
}
internal static Color GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
internal static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
{
if (serie == null) return Color.clear;
if (serie == null) return ChartConst.clearColor32;
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
{
var color = itemStyleEmphasis.color;
color.a *= itemStyleEmphasis.opacity;
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
return color;
}
}
var itemStyle = GetItemStyle(serie, serieData);
if (!ChartHelper.IsClearColor(itemStyle.color))
{
var color = itemStyle.color;
if (highlight) color *= color;
color.a *= itemStyle.opacity;
return color;
return itemStyle.GetColor();
}
else
{
var color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a *= itemStyle.opacity;
var color = theme.GetColor(index);
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
}
internal static Color GetItemToColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
internal static Color32 GetItemToColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
{
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.toColor))
{
var color = itemStyleEmphasis.toColor;
color.a *= itemStyleEmphasis.opacity;
return color;
return itemStyleEmphasis.GetColor();
}
}
var itemStyle = GetItemStyle(serie, serieData, highlight);
@@ -90,22 +85,22 @@ namespace XCharts
if (!ChartHelper.IsClearColor(itemStyle.toColor))
{
var color = itemStyle.toColor;
if (highlight) color *= color;
color.a *= itemStyle.opacity;
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
if (!ChartHelper.IsClearColor(itemStyle.color))
{
var color = itemStyle.color;
if (highlight) color *= color;
color.a *= itemStyle.opacity;
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
else
{
var color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a *= itemStyle.opacity;
var color = theme.GetColor(index);
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
}
@@ -179,20 +174,20 @@ namespace XCharts
else return serie.symbol;
}
internal static Color GetAreaColor(Serie serie, ThemeInfo theme, int index, bool highlight)
internal static Color32 GetAreaColor(Serie serie, ThemeInfo theme, int index, bool highlight)
{
var areaStyle = serie.areaStyle;
var color = !ChartHelper.IsClearColor(areaStyle.color) ? areaStyle.color : (Color)theme.GetColor(index);
var color = !ChartHelper.IsClearColor(areaStyle.color) ? areaStyle.color : theme.GetColor(index);
if (highlight)
{
if (!ChartHelper.IsClearColor(areaStyle.highlightColor)) color = areaStyle.highlightColor;
else color *= color;
else color = ChartHelper.GetHighlightColor(color);
}
color.a *= areaStyle.opacity;
ChartHelper.SetColorOpacity(ref color, areaStyle.opacity);
return color;
}
internal static Color GetAreaToColor(Serie serie, ThemeInfo theme, int index, bool highlight)
internal static Color32 GetAreaToColor(Serie serie, ThemeInfo theme, int index, bool highlight)
{
var areaStyle = serie.areaStyle;
if (!ChartHelper.IsClearColor(areaStyle.toColor))
@@ -201,9 +196,9 @@ namespace XCharts
if (highlight)
{
if (!ChartHelper.IsClearColor(areaStyle.highlightToColor)) color = areaStyle.highlightToColor;
else color *= color;
else color = ChartHelper.GetHighlightColor(color);
}
color.a *= areaStyle.opacity;
ChartHelper.SetColorOpacity(ref color, areaStyle.opacity);
return color;
}
else
@@ -212,16 +207,16 @@ namespace XCharts
}
}
internal static Color GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight)
internal static Color32 GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight)
{
var color = Color.clear;
Color32 color = ChartConst.clearColor32;
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, null);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
{
color = itemStyleEmphasis.color;
color.a *= itemStyleEmphasis.opacity;
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
return color;
}
}
@@ -229,10 +224,10 @@ namespace XCharts
else if (!ChartHelper.IsClearColor(serie.itemStyle.color)) color = serie.itemStyle.GetColor();
if (ChartHelper.IsClearColor(color))
{
color = (Color)theme.GetColor(index);
color.a = serie.lineStyle.opacity;
color = theme.GetColor(index);
ChartHelper.SetColorOpacity(ref color, serie.lineStyle.opacity);
}
if (highlight) color *= color;
if (highlight) color = ChartHelper.GetHighlightColor(color);
return color;
}

View File

@@ -131,7 +131,7 @@ namespace XCharts
{
if (serie.show && serie.areaStyle.show && stack.Equals(serie.stack))
{
if (serie.areaStyle.color != serie.areaStyle.toColor
if (!ChartHelper.IsValueEqualsColor(serie.areaStyle.color, serie.areaStyle.toColor)
&& !ChartHelper.IsClearColor(serie.areaStyle.toColor))
return true;
}

View File

@@ -11,9 +11,9 @@ namespace XCharts
{
internal static class ThemeHelper
{
public static Color GetBackgroundColor(ThemeInfo themeInfo, Background background)
public static Color32 GetBackgroundColor(ThemeInfo themeInfo, Background background)
{
if (background.show && background.runtimeActive && background.hideThemeBackgroundColor) return Color.clear;
if (background.show && background.runtimeActive && background.hideThemeBackgroundColor) return ChartConst.clearColor32;
else return themeInfo.backgroundColor;
}
}

View File

@@ -457,19 +457,17 @@ namespace XCharts
else return tooltip.numericFormatter;
}
public static Color GetLineColor(Tooltip tooltip, ThemeInfo theme)
public static Color32 GetLineColor(Tooltip tooltip, ThemeInfo theme)
{
var lineStyle = tooltip.lineStyle;
if (!ChartHelper.IsClearColor(lineStyle.color))
{
var color = lineStyle.color;
color.a *= lineStyle.opacity;
return color;
return lineStyle.GetColor();
}
else
{
var color = (Color)theme.tooltipLineColor;
color.a *= lineStyle.opacity;
var color = theme.tooltipLineColor;
ChartHelper.SetColorOpacity(ref color, lineStyle.opacity);
return color;
}
}

View File

@@ -12,7 +12,7 @@ namespace XCharts
{
public static class VesselHelper
{
internal static Color GetColor(Vessel vessel, Serie serie, ThemeInfo themeInfo, List<string> legendRealShowName)
internal static Color32 GetColor(Vessel vessel, Serie serie, ThemeInfo themeInfo, List<string> legendRealShowName)
{
if (serie != null && vessel.autoColor)
{

View File

@@ -53,10 +53,10 @@ namespace XCharts
}
public static void GetLineGradientColor(VisualMap visualMap, float xValue, float yValue,
out Color startColor, out Color toColor)
out Color32 startColor, out Color32 toColor)
{
startColor = Color.clear;
toColor = Color.clear;
startColor = ChartConst.clearColor32;
toColor = ChartConst.clearColor32;
switch (visualMap.direction)
{
case VisualMap.Direction.Default:
@@ -71,7 +71,7 @@ namespace XCharts
}
}
internal static Color GetLineGradientColor(VisualMap visualMap, Vector3 pos, CoordinateChart chart, Axis axis, Color defaultColor)
internal static Color32 GetLineGradientColor(VisualMap visualMap, Vector3 pos, CoordinateChart chart, Axis axis, Color32 defaultColor)
{
float value = 0;
switch (visualMap.direction)
@@ -103,7 +103,7 @@ namespace XCharts
else return color;
}
internal static Color GetItemStyleGradientColor(ItemStyle itemStyle, Vector3 pos, CoordinateChart chart, Axis axis, Color defaultColor)
internal static Color32 GetItemStyleGradientColor(ItemStyle itemStyle, Vector3 pos, CoordinateChart chart, Axis axis, Color32 defaultColor)
{
var min = axis.runtimeMinValue;
var max = axis.runtimeMaxValue;

View File

@@ -0,0 +1,18 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
namespace XCharts
{
public static class ChartConst
{
public static readonly Color32 clearColor32 = new Color32(0, 0, 0, 0);
public static readonly Color32 greyColor32 = new Color32(128, 128, 128, 255);
public static readonly Color clearColor = Color.clear;
}
}

View File

@@ -14,6 +14,7 @@ namespace XCharts
{
public static class ChartDrawer
{
private static Color32 s_Color32Clear = new Color32(0, 0, 0, 0);
private static readonly Vector2 zeroVector2 = Vector2.zero;
private static UIVertex[] vertex = new UIVertex[4];
private static List<Vector3> s_CurvesPosList = new List<Vector3>();
@@ -251,7 +252,7 @@ namespace XCharts
}
public static void DrawPolygon(VertexHelper vh, Vector3 p, float xRadius, float yRadius,
Color32 color, Color toColor, bool vertical = true)
Color32 color, Color32 toColor, bool vertical = true)
{
Vector3 p1, p2, p3, p4;
if (vertical)
@@ -484,13 +485,13 @@ namespace XCharts
}
else
{
var tempLeftColor = Color.Lerp(color, toColor, maxLeft / rectWidth);
var upLeftColor = Color.Lerp(color, tempLeftColor, brLt / maxLeft);
var downLeftColor = Color.Lerp(color, tempLeftColor, brLb / maxLeft);
var tempLeftColor = Color32.Lerp(color, toColor, maxLeft / rectWidth);
var upLeftColor = Color32.Lerp(color, tempLeftColor, brLt / maxLeft);
var downLeftColor = Color32.Lerp(color, tempLeftColor, brLb / maxLeft);
var tempRightColor = Color.Lerp(color, toColor, (rectWidth - maxRight) / rectWidth);
var upRightColor = Color.Lerp(tempRightColor, toColor, (maxRight - brRt) / maxRight);
var downRightColor = Color.Lerp(tempRightColor, toColor, (maxRight - brRb) / maxRight);
var tempRightColor = Color32.Lerp(color, toColor, (rectWidth - maxRight) / rectWidth);
var upRightColor = Color32.Lerp(tempRightColor, toColor, (maxRight - brRt) / maxRight);
var downRightColor = Color32.Lerp(tempRightColor, toColor, (maxRight - brRb) / maxRight);
DrawSector(vh, roundLt, brLt, color, upLeftColor, 270, 360, 1, isYAxis);
DrawSector(vh, roundRt, brRt, upRightColor, toColor, 0, 90, 1, isYAxis);
@@ -570,12 +571,12 @@ namespace XCharts
}
else
{
var tempUpColor = Color.Lerp(color, toColor, (rectHeight - maxup) / rectHeight);
var leftUpColor = Color.Lerp(tempUpColor, toColor, (maxup - brLt) / maxup);
var rightUpColor = Color.Lerp(tempUpColor, toColor, (maxup - brRt) / maxup);
var tempDownColor = Color.Lerp(color, toColor, maxdown / rectHeight);
var leftDownColor = Color.Lerp(color, tempDownColor, brLb / maxdown);
var rightDownColor = Color.Lerp(color, tempDownColor, brRb / maxdown);
var tempUpColor = Color32.Lerp(color, toColor, (rectHeight - maxup) / rectHeight);
var leftUpColor = Color32.Lerp(tempUpColor, toColor, (maxup - brLt) / maxup);
var rightUpColor = Color32.Lerp(tempUpColor, toColor, (maxup - brRt) / maxup);
var tempDownColor = Color32.Lerp(color, toColor, maxdown / rectHeight);
var leftDownColor = Color32.Lerp(color, tempDownColor, brLb / maxdown);
var rightDownColor = Color32.Lerp(color, tempDownColor, brRb / maxdown);
DrawSector(vh, roundLt, brLt, leftUpColor, toColor, 270, 360, 1, isYAxis);
DrawSector(vh, roundRt, brRt, rightUpColor, toColor, 0, 90, 1, isYAxis);
@@ -644,7 +645,7 @@ namespace XCharts
if (brLt > 0)
{
tempCenter = new Vector3(center.x - halfWid + brLt, center.y + halfHig - brLt);
DrawDoughnut(vh, tempCenter, brLt, brLt + borderWidth, color, Color.clear, 270, 360);
DrawDoughnut(vh, tempCenter, brLt, brLt + borderWidth, color, s_Color32Clear, 270, 360);
ltIn = tempCenter + brLt * Vector3.left;
ltOt = tempCenter + (brLt + borderWidth) * Vector3.left;
ltIn2 = tempCenter + brLt * Vector3.up;
@@ -653,7 +654,7 @@ namespace XCharts
if (brRt > 0)
{
tempCenter = new Vector3(center.x + halfWid - brRt, center.y + halfHig - brRt);
DrawDoughnut(vh, tempCenter, brRt, brRt + borderWidth, color, Color.clear, 0, 90);
DrawDoughnut(vh, tempCenter, brRt, brRt + borderWidth, color, s_Color32Clear, 0, 90);
rtIn = tempCenter + brRt * Vector3.up;
rtOt = tempCenter + (brRt + borderWidth) * Vector3.up;
rtIn2 = tempCenter + brRt * Vector3.right;
@@ -662,7 +663,7 @@ namespace XCharts
if (brRb > 0)
{
tempCenter = new Vector3(center.x + halfWid - brRb, center.y - halfHig + brRb);
DrawDoughnut(vh, tempCenter, brRb, brRb + borderWidth, color, Color.clear, 90, 180);
DrawDoughnut(vh, tempCenter, brRb, brRb + borderWidth, color, s_Color32Clear, 90, 180);
rbIn = tempCenter + brRb * Vector3.right;
rbOt = tempCenter + (brRb + borderWidth) * Vector3.right;
rbIn2 = tempCenter + brRb * Vector3.down;
@@ -671,7 +672,7 @@ namespace XCharts
if (brLb > 0)
{
tempCenter = new Vector3(center.x - halfWid + brLb, center.y - halfHig + brLb);
DrawDoughnut(vh, tempCenter, brLb, brLb + borderWidth, color, Color.clear, 180, 270);
DrawDoughnut(vh, tempCenter, brLb, brLb + borderWidth, color, s_Color32Clear, 180, 270);
lbIn = tempCenter + brLb * Vector3.left;
lbOt = tempCenter + (brLb + borderWidth) * Vector3.left;
lbIn2 = tempCenter + brLb * Vector3.down;
@@ -748,13 +749,13 @@ namespace XCharts
public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color,
float smoothness = 2f)
{
DrawCricle(vh, p, radius, color, color, 0, Color.clear, smoothness);
DrawCricle(vh, p, radius, color, color, 0, s_Color32Clear, smoothness);
}
public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color,
Color32 toColor, float smoothness = 2f)
{
DrawSector(vh, p, radius, color, toColor, 0, 360, 0, Color.clear, smoothness);
DrawSector(vh, p, radius, color, toColor, 0, 360, 0, s_Color32Clear, smoothness);
}
public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color,
@@ -772,7 +773,7 @@ namespace XCharts
public static void DrawEmptyCricle(VertexHelper vh, Vector3 p, float radius, float tickness,
Color32 color, Color32 emptyColor, float smoothness = 2f)
{
DrawDoughnut(vh, p, radius - tickness, radius, color, color, emptyColor, 0, 360, 0, Color.clear, 0, smoothness);
DrawDoughnut(vh, p, radius - tickness, radius, color, color, emptyColor, 0, 360, 0, s_Color32Clear, 0, smoothness);
}
public static void DrawEmptyCricle(VertexHelper vh, Vector3 p, float radius, float tickness,
@@ -786,7 +787,7 @@ namespace XCharts
Color32 color, Color32 toColor, Color32 emptyColor, float smoothness = 2f)
{
DrawDoughnut(vh, p, radius - tickness, radius, color, toColor, emptyColor, 0, 360, 0,
Color.clear, 0, smoothness);
s_Color32Clear, 0, smoothness);
}
public static void DrawEmptyCricle(VertexHelper vh, Vector3 p, float radius, float tickness,
@@ -800,13 +801,13 @@ namespace XCharts
public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color,
float startDegree, float toDegree, float smoothness = 2f)
{
DrawSector(vh, p, radius, color, color, startDegree, toDegree, 0, Color.clear, smoothness);
DrawSector(vh, p, radius, color, color, startDegree, toDegree, 0, s_Color32Clear, smoothness);
}
public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color, Color32 toColor,
float startDegree, float toDegree, int gradientType = 0, bool isYAxis = false, float smoothness = 2f)
{
DrawSector(vh, p, radius, color, toColor, startDegree, toDegree, 0, Color.clear, 0, smoothness, gradientType, isYAxis);
DrawSector(vh, p, radius, color, toColor, startDegree, toDegree, 0, s_Color32Clear, 0, smoothness, gradientType, isYAxis);
}
public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color,
@@ -917,7 +918,7 @@ namespace XCharts
{
p4 = new Vector3(p3.x, realCenter.y);
var dist = p4.x - realCenter.x;
var tcolor = Color.Lerp(color, toColor, dist >= 0 ? dist / radius : Mathf.Min(radius + dist, radius) / radius);
var tcolor = Color32.Lerp(color, toColor, dist >= 0 ? dist / radius : Mathf.Min(radius + dist, radius) / radius);
if (isLeft && (i == segments || i == 0)) tcolor = toColor;
DrawPolygon(vh, lastP4, p2, p3, p4, lastColor, tcolor);
lastP4 = p4;
@@ -926,7 +927,7 @@ namespace XCharts
else
{
p4 = new Vector3(realCenter.x, p3.y);
var tcolor = Color.Lerp(color, toColor, Mathf.Abs(p4.y - realCenter.y) / radius);
var tcolor = Color32.Lerp(color, toColor, Mathf.Abs(p4.y - realCenter.y) / radius);
DrawPolygon(vh, lastP4, p2, p3, p4, lastColor, tcolor);
lastP4 = p4;
lastColor = tcolor;
@@ -934,7 +935,7 @@ namespace XCharts
}
else if (gradientType == 2)
{
var tcolor = Color.Lerp(color, toColor, i / segments);
var tcolor = Color32.Lerp(color, toColor, i / segments);
DrawPolygon(vh, realCenter, p2, p3, realCenter, lastColor, tcolor);
lastColor = tcolor;
}
@@ -955,7 +956,7 @@ namespace XCharts
{
var realStartDegree = (realStartAngle - borderAngle) * Mathf.Rad2Deg;
var realToDegree = (realToAngle + borderAngle) * Mathf.Rad2Deg;
DrawDoughnut(vh, p, radius, radius + borderWidth, borderColor, Color.clear, realStartDegree,
DrawDoughnut(vh, p, radius, radius + borderWidth, borderColor, s_Color32Clear, realStartDegree,
realToDegree, smoothness);
}
}
@@ -965,7 +966,7 @@ namespace XCharts
public static void DrawRoundCap(VertexHelper vh, Vector3 center, float width, float radius, float angle,
bool clockwise, Color color, bool end)
bool clockwise, Color32 color, bool end)
{
var px = Mathf.Sin(angle * Mathf.Deg2Rad) * radius;
var py = Mathf.Cos(angle * Mathf.Deg2Rad) * radius;
@@ -973,36 +974,36 @@ namespace XCharts
if (end)
{
if (clockwise)
ChartDrawer.DrawSector(vh, pos, width, color, angle, angle + 180, 0, Color.clear);
ChartDrawer.DrawSector(vh, pos, width, color, angle, angle + 180, 0, s_Color32Clear);
else
ChartDrawer.DrawSector(vh, pos, width, color, angle, angle - 180, 0, Color.clear);
ChartDrawer.DrawSector(vh, pos, width, color, angle, angle - 180, 0, s_Color32Clear);
}
else
{
if (clockwise)
ChartDrawer.DrawSector(vh, pos, width, color, angle + 180, angle + 360, 0, Color.clear);
ChartDrawer.DrawSector(vh, pos, width, color, angle + 180, angle + 360, 0, s_Color32Clear);
else
ChartDrawer.DrawSector(vh, pos, width, color, angle - 180, angle - 360, 0, Color.clear);
ChartDrawer.DrawSector(vh, pos, width, color, angle - 180, angle - 360, 0, s_Color32Clear);
}
}
public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius,
Color32 color, Color emptyColor, float smoothness = 2f)
Color32 color, Color32 emptyColor, float smoothness = 2f)
{
DrawDoughnut(vh, p, insideRadius, outsideRadius, color, color, emptyColor, 0, 360, 0, Color.clear,
DrawDoughnut(vh, p, insideRadius, outsideRadius, color, color, emptyColor, 0, 360, 0, s_Color32Clear,
0, smoothness);
}
public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius,
Color32 color, Color emptyColor, float startDegree,
Color32 color, Color32 emptyColor, float startDegree,
float toDegree, float smoothness = 2f)
{
DrawDoughnut(vh, p, insideRadius, outsideRadius, color, color, emptyColor, startDegree, toDegree,
0, Color.clear, 0, smoothness);
0, s_Color32Clear, 0, smoothness);
}
public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius,
Color32 color, Color emptyColor, float startDegree,
Color32 color, Color32 emptyColor, float startDegree,
float toDegree, float borderWidth, Color32 borderColor, float smoothness = 2f)
{
DrawDoughnut(vh, p, insideRadius, outsideRadius, color, color, emptyColor, startDegree, toDegree,
@@ -1010,14 +1011,14 @@ namespace XCharts
}
public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius,
Color32 color, Color32 toColor, Color emptyColor, float smoothness = 2f)
Color32 color, Color32 toColor, Color32 emptyColor, float smoothness = 2f)
{
DrawDoughnut(vh, p, insideRadius, outsideRadius, color, toColor, emptyColor, 0, 360, 0, Color.clear,
DrawDoughnut(vh, p, insideRadius, outsideRadius, color, toColor, emptyColor, 0, 360, 0, s_Color32Clear,
0, smoothness);
}
public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius,
Color32 color, Color32 toColor, Color emptyColor, float startDegree, float toDegree, float borderWidth,
Color32 color, Color32 toColor, Color32 emptyColor, float startDegree, float toDegree, float borderWidth,
Color32 borderColor, float space, float smoothness, bool roundCap = false, bool clockwise = true)
{
if (toDegree - startDegree == 0) return;
@@ -1170,7 +1171,7 @@ namespace XCharts
DrawSector(vh, roundCenter, roundRadius, color, sectorStartDegree, sectorToDegree, smoothness / 2);
if (needBorder)
{
DrawDoughnut(vh, roundCenter, roundRadius, roundRadius + borderWidth, borderColor, Color.clear,
DrawDoughnut(vh, roundCenter, roundRadius, roundRadius + borderWidth, borderColor, s_Color32Clear,
sectorStartDegree, sectorToDegree, smoothness / 2);
}
p1 = ChartHelper.GetPos(p, insideRadius, realStartOutAngle);
@@ -1195,7 +1196,7 @@ namespace XCharts
DrawSector(vh, roundCenter, roundRadius, toColor, sectorStartDegree, sectorToDegree, smoothness / 2);
if (needBorder)
{
DrawDoughnut(vh, roundCenter, roundRadius, roundRadius + borderWidth, borderColor, Color.clear,
DrawDoughnut(vh, roundCenter, roundRadius, roundRadius + borderWidth, borderColor, s_Color32Clear,
sectorStartDegree, sectorToDegree, smoothness / 2);
}
e1 = ChartHelper.GetPos(p, insideRadius, realToOutAngle);
@@ -1213,7 +1214,7 @@ namespace XCharts
if (!ChartHelper.IsClearColor(emptyColor)) DrawTriangle(vh, p, p1, p4, emptyColor);
if (isGradient)
{
var tcolor = Color.Lerp(color, toColor, i * 1.0f / segments);
var tcolor = Color32.Lerp(color, toColor, i * 1.0f / segments);
DrawPolygon(vh, p2, p3, p4, p1, tcolor, tcolor);
}
else
@@ -1238,9 +1239,9 @@ namespace XCharts
var inStartDegree = roundCap ? realStartDegree : (startAngle + spaceInAngle) * Mathf.Rad2Deg;
var inToDegree = roundCap ? realToDegree : (toAngle - spaceInAngle) * Mathf.Rad2Deg;
if (inToDegree < inStartDegree) inToDegree = inStartDegree;
if (isInAngleFixed) DrawDoughnut(vh, p, insideRadius - borderWidth, insideRadius, borderColor, Color.clear,
if (isInAngleFixed) DrawDoughnut(vh, p, insideRadius - borderWidth, insideRadius, borderColor, s_Color32Clear,
inStartDegree, inToDegree, smoothness);
DrawDoughnut(vh, p, outsideRadius, outsideRadius + borderWidth, borderColor, Color.clear,
DrawDoughnut(vh, p, outsideRadius, outsideRadius + borderWidth, borderColor, s_Color32Clear,
realStartDegree, realToDegree, smoothness);
}
}
@@ -1256,9 +1257,9 @@ namespace XCharts
var inStartDegree = roundCap ? realStartDegree : (startAngle - spaceInAngle) * Mathf.Rad2Deg;
var inToDegree = roundCap ? realToDegree : (toAngle + spaceInAngle) * Mathf.Rad2Deg;
if (inToDegree > inStartDegree) inToDegree = inStartDegree;
if (isInAngleFixed) DrawDoughnut(vh, p, insideRadius - borderWidth, insideRadius, borderColor, Color.clear,
if (isInAngleFixed) DrawDoughnut(vh, p, insideRadius - borderWidth, insideRadius, borderColor, s_Color32Clear,
inStartDegree, inToDegree, smoothness);
DrawDoughnut(vh, p, outsideRadius, outsideRadius + borderWidth, borderColor, Color.clear,
DrawDoughnut(vh, p, outsideRadius, outsideRadius + borderWidth, borderColor, s_Color32Clear,
realStartDegree, realToDegree, smoothness);
}
}
@@ -1276,7 +1277,7 @@ namespace XCharts
/// <param name="lineWidth">曲线宽</param>
/// <param name="lineColor">曲线颜色</param>
public static void DrawCurves(VertexHelper vh, Vector3 sp, Vector3 ep, Vector3 cp1, Vector3 cp2,
float lineWidth, Color lineColor, float smoothness)
float lineWidth, Color32 lineColor, float smoothness)
{
var dist = Vector3.Distance(sp, ep);
var segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness));
@@ -1304,8 +1305,8 @@ namespace XCharts
}
public static void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
float tickness, Vector3 pos, Color color, Color toColor, float gap, float[] cornerRadius,
Color backgroundColor, float smoothness)
float tickness, Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius,
Color32 backgroundColor, float smoothness)
{
switch (type)
{
@@ -1370,7 +1371,7 @@ namespace XCharts
}
public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle,
Vector3 startPos, Vector3 endPos, Color color)
Vector3 startPos, Vector3 endPos, Color32 color)
{
var type = lineStyle.type;
var width = lineStyle.width;

View File

@@ -406,6 +406,14 @@ namespace XCharts
color1.r == color2.r;
}
public static bool IsValueEqualsColor(Color color1, Color color2)
{
return color1.a == color2.a &&
color1.b == color2.b &&
color1.g == color2.g &&
color1.r == color2.r;
}
public static bool IsValueEqualsString(string str1, string str2)
{
if (str1 == null && str2 == null) return true;
@@ -819,5 +827,23 @@ namespace XCharts
if (list.Count <= 0) return Vector3.zero;
else return list[list.Count - 1];
}
public static void SetColorOpacity(ref Color32 color, float opacity)
{
if (color.a != 0 && opacity != 1)
{
color.a = (byte)(color.a * opacity);
}
}
public static Color32 GetHighlightColor(Color32 color)
{
var newColor = color;
var rate = 0.8f;
newColor.r = (byte)(color.r * rate);
newColor.g = (byte)(color.g * rate);
newColor.b = (byte)(color.b * rate);
return newColor;
}
}
}

View File

@@ -232,8 +232,8 @@ namespace XCharts
{
var colorMin = cenPos.y - radius;
var colorMax = startY + serie.waveHeight;
var tcolor1 = Color.Lerp(color, toColor, 1 - (lup.y - colorMin) / (colorMax - colorMin));
var tcolor2 = Color.Lerp(color, toColor, 1 - (ldp.y - colorMin) / (colorMax - colorMin));
var tcolor1 = Color32.Lerp(color, toColor, 1 - (lup.y - colorMin) / (colorMax - colorMin));
var tcolor2 = Color32.Lerp(color, toColor, 1 - (ldp.y - colorMin) / (colorMax - colorMin));
ChartDrawer.DrawPolygon(vh, lup, nup, ndp, ldp, tcolor1, tcolor2);
}
else