重构代码,将与绘制相关的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

@@ -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;
}
}
}