mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 09:50:15 +00:00
增加SerieData的ItemStyle和Emphasis可单独配置数据项样式的支持
This commit is contained in:
15
Runtime/Helper/SerieDataHelper.cs
Normal file
15
Runtime/Helper/SerieDataHelper.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class SerieDataHelper
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Runtime/Helper/SerieDataHelper.cs.meta
Normal file
11
Runtime/Helper/SerieDataHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0de4f692b6e2d4cdd9ef1946bffa895f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -11,38 +11,98 @@ namespace XCharts
|
||||
{
|
||||
internal static class SerieHelper
|
||||
{
|
||||
internal static Color GetItemBackgroundColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
internal static Color GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
if (serie.itemStyle.backgroundColor != Color.clear)
|
||||
var itemStyle = GetItemStyle(serie, serieData);
|
||||
var color = Color.clear;
|
||||
if (highlight)
|
||||
{
|
||||
var color = serie.itemStyle.backgroundColor;
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
|
||||
if (itemStyleEmphasis != null && itemStyleEmphasis.backgroundColor != Color.clear)
|
||||
{
|
||||
color = itemStyleEmphasis.backgroundColor;
|
||||
color.a *= itemStyleEmphasis.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
if (itemStyle.backgroundColor != Color.clear)
|
||||
{
|
||||
color = itemStyle.backgroundColor;
|
||||
if (highlight) color *= color;
|
||||
color.a *= serie.itemStyle.opacity;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a = 0.2f;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color GetItemColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
internal static Color GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
if (serie.itemStyle.color != Color.clear)
|
||||
var itemStyle = GetItemStyle(serie, serieData);
|
||||
if (highlight)
|
||||
{
|
||||
var color = serie.itemStyle.color;
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
|
||||
if (itemStyleEmphasis != null && itemStyleEmphasis.color != Color.clear)
|
||||
{
|
||||
var color = itemStyleEmphasis.color;
|
||||
color.a *= itemStyleEmphasis.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
if (itemStyle.color != Color.clear)
|
||||
{
|
||||
var color = itemStyle.color;
|
||||
if (highlight) color *= color;
|
||||
color.a *= serie.itemStyle.opacity;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a *= serie.itemStyle.opacity;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color GetItemToColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
var itemStyle = GetItemStyle(serie, serieData, highlight);
|
||||
if (highlight)
|
||||
{
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
|
||||
if (itemStyleEmphasis != null && itemStyleEmphasis.toColor != Color.clear)
|
||||
{
|
||||
var color = itemStyleEmphasis.toColor;
|
||||
color.a *= itemStyleEmphasis.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
if (itemStyle == null) itemStyle = serieData.itemStyle;
|
||||
if (itemStyle.toColor != Color.clear)
|
||||
{
|
||||
var color = itemStyle.toColor;
|
||||
if (highlight) color *= color;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
if (itemStyle.color != Color.clear)
|
||||
{
|
||||
var color = itemStyle.color;
|
||||
if (highlight) color *= color;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -72,5 +132,105 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStyle GetItemStyle(Serie serie, SerieData serieData, bool highlight = false)
|
||||
{
|
||||
if (highlight)
|
||||
{
|
||||
var style = GetItemStyleEmphasis(serie, serieData);
|
||||
if (style == null) return GetItemStyle(serie, serieData, false);
|
||||
else return style;
|
||||
}
|
||||
else if (serieData.enableItemStyle) return serieData.itemStyle;
|
||||
else return serie.itemStyle;
|
||||
}
|
||||
|
||||
public static ItemStyle GetItemStyleEmphasis(Serie serie, SerieData serieData)
|
||||
{
|
||||
if (serieData != null && serieData.enableEmphasis && serieData.emphasis.show)
|
||||
return serieData.emphasis.itemStyle;
|
||||
else if (serie.emphasis.show) return serie.emphasis.itemStyle;
|
||||
else return null;
|
||||
}
|
||||
|
||||
public static SerieLabel GetSerieLabel(Serie serie, SerieData serieData, bool highlight = false)
|
||||
{
|
||||
if (highlight)
|
||||
{
|
||||
if (serieData.enableEmphasis && serieData.emphasis.show) return serieData.emphasis.label;
|
||||
else if (serie.emphasis.show) return serie.emphasis.label;
|
||||
else return serie.label;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (serieData.enableLabel) return serieData.label;
|
||||
else return serie.label;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetAreaColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
var areaStyle = serie.areaStyle;
|
||||
var color = areaStyle.color != Color.clear ? areaStyle.color : (Color)theme.GetColor(index);
|
||||
if (highlight)
|
||||
{
|
||||
if (areaStyle.highlightColor != Color.clear) color = areaStyle.highlightColor;
|
||||
else color *= color;
|
||||
}
|
||||
color.a *= areaStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
|
||||
public static Color GetAreaToColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
var areaStyle = serie.areaStyle;
|
||||
if (areaStyle.toColor != Color.clear)
|
||||
{
|
||||
var color = areaStyle.toColor;
|
||||
if (highlight)
|
||||
{
|
||||
if (areaStyle.highlightToColor != Color.clear) color = areaStyle.highlightToColor;
|
||||
else color *= color;
|
||||
}
|
||||
color.a *= areaStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetAreaColor(serie, theme, index, highlight);
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
var color = Color.clear;
|
||||
if (highlight)
|
||||
{
|
||||
var itemStyleEmphasis = GetItemStyleEmphasis(serie, null);
|
||||
if (itemStyleEmphasis != null && itemStyleEmphasis.color != Color.clear)
|
||||
{
|
||||
color = itemStyleEmphasis.color;
|
||||
color.a *= itemStyleEmphasis.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
if (serie.lineStyle.color != Color.clear) color = serie.lineStyle.GetColor();
|
||||
else if (serie.itemStyle.color != Color.clear) color = serie.itemStyle.GetColor();
|
||||
if (color == Color.clear)
|
||||
{
|
||||
color = (Color)theme.GetColor(index);
|
||||
color.a = serie.lineStyle.opacity;
|
||||
}
|
||||
if (highlight) color *= color;
|
||||
return color;
|
||||
}
|
||||
|
||||
public static float GetSymbolBorder(Serie serie, SerieData serieData, bool highlight)
|
||||
{
|
||||
var itemStyle = GetItemStyle(serie, serieData, highlight);
|
||||
if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth;
|
||||
else if (serie.lineStyle.width != 0) return serie.lineStyle.width;
|
||||
else return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,20 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void ResetLabel(SerieData serieData, SerieLabel label, ThemeInfo themeInfo, int colorIndex)
|
||||
{
|
||||
if (serieData.labelText)
|
||||
{
|
||||
serieData.labelText.color = label.color != Color.clear ? label.color :
|
||||
(Color)themeInfo.GetColor(colorIndex);
|
||||
serieData.labelText.fontSize = label.fontSize;
|
||||
serieData.labelText.fontStyle = label.fontStyle;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void SetGaugeLabelText(Serie serie)
|
||||
{
|
||||
var serieData = serie.GetSerieData(0);
|
||||
@@ -95,7 +109,8 @@ namespace XCharts
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
if (serieData.IsInitLabel())
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie,serieData,serieData.highlighted);
|
||||
if (serieLabel.show && serieData.IsInitLabel())
|
||||
{
|
||||
if (!serie.show || !serieData.show)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user