mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 18:30:14 +00:00
重构代码,将与绘制相关的Color改为Color32,减少隐式转换
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user