diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md
index 0c7e9321..ba40b0db 100644
--- a/Assets/XCharts/CHANGELOG.md
+++ b/Assets/XCharts/CHANGELOG.md
@@ -1,6 +1,7 @@
# 更新日志
+* (2020.02.26) 重构`Legend`图例,改变样式,增加自定义图标等设置
* (2020.02.23) 增加`BaseChart.AnimationFadeOut()`渐出动画,重构动画系统
* (2020.02.13) 增加`BaseChart.RefreshTooltip()`接口立即重新初始化`Tooltip`组件
* (2020.02.13) 增加`Tooltip`的`textStyle`参数配置内容文本样式,去掉`fontSize`和`fontStyle`参数
diff --git a/Assets/XCharts/Documentation/XCharts配置项手册.md b/Assets/XCharts/Documentation/XCharts配置项手册.md
index 752ec99c..72ee87b0 100644
--- a/Assets/XCharts/Documentation/XCharts配置项手册.md
+++ b/Assets/XCharts/Documentation/XCharts配置项手册.md
@@ -118,12 +118,14 @@
* `Horizonal`:水平。
* `Vertical`:垂直。
* `location`:图例的显示位置 [Location](#Location)。
-* `itemWidth`:每个图例项的宽度。
-* `itemHeight`:每个图例项的高度。
+* `itemWidth`:图例标记的图形宽度。
+* `itemHeight`:图例标记的图形高度。
* `itemGap`:图例每项之间的间隔。横向布局时为水平间隔,纵向布局时为纵向间隔。
-* `itemFontSize`:图例项的字体大小。
+* `itemAutoColor`:图例标记的图形是否自动匹配颜色。
* `formatter`:图例内容字符串模版格式器。支持用 `\n` 换行。模板变量为图例名称 `{name}`
* `data`:图例的数据数组。数组项通常为一个字符串,每一项代表一个系列的 `name`(如果是饼图,也可以是饼图单个数据的 `name`)。如果 `data` 没有被指定,会自动从当前系列中获取。指定 `data` 时里面的数据项和 `serie` 匹配时才会生效。
+* `icons`:自定义的图例标记图形。
+* `textStyle`:图例的内容文本样式 [TextStyle](#TextStyle)。
相关接口:
@@ -169,6 +171,8 @@
* `rotate`:旋转。
* `offset`:偏移。
* `color`:颜色。
+* `backgroundColor`:背景颜色。
+* `font`:字体。
* `fontSize`:字体大小。
* `fontStyle`:字体风格。
* `lineSpacing`:行间距。
diff --git a/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs
index 5a893c4e..87ec617f 100644
--- a/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs
+++ b/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs
@@ -14,7 +14,9 @@ namespace XCharts
public class LegendDrawer : PropertyDrawer
{
private bool m_DataFoldout = false;
+ private bool m_IconsFoldout = false;
private int m_DataSize = 0;
+ private int m_IconsSize = 0;
private bool m_ShowJsonDataArea = false;
private string m_JsonDataAreaText;
private bool m_LegendModuleToggle = false;
@@ -30,9 +32,11 @@ namespace XCharts
SerializedProperty itemWidth = prop.FindPropertyRelative("m_ItemWidth");
SerializedProperty itemHeight = prop.FindPropertyRelative("m_ItemHeight");
SerializedProperty itemGap = prop.FindPropertyRelative("m_ItemGap");
- SerializedProperty itemFontSize = prop.FindPropertyRelative("m_ItemFontSize");
+ SerializedProperty m_ItemAutoColor = prop.FindPropertyRelative("m_ItemAutoColor");
SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter");
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
+ SerializedProperty m_Icons = prop.FindPropertyRelative("m_Icons");
+ SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LegendModuleToggle, "Legend", show);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -45,7 +49,7 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, itemGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
- EditorGUI.PropertyField(drawRect, itemFontSize);
+ EditorGUI.PropertyField(drawRect, m_ItemAutoColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SelectedMode);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -57,12 +61,20 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.width = EditorGUIUtility.labelWidth + 10;
m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Data");
- ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop,pos.width);
+ ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop, pos.width);
drawRect.width = pos.width;
if (m_DataFoldout)
{
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data);
}
+ m_IconsFoldout = EditorGUI.Foldout(drawRect, m_IconsFoldout, "Icons");
+ drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
+ if (m_IconsFoldout)
+ {
+ ChartEditorHelper.MakeList(ref drawRect, ref m_IconsSize, m_Icons);
+ }
+ EditorGUI.PropertyField(drawRect, m_TextStyle);
+ drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
--EditorGUI.indentLevel;
}
}
@@ -73,7 +85,7 @@ namespace XCharts
if (m_LegendModuleToggle)
{
SerializedProperty location = prop.FindPropertyRelative("m_Location");
- height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
+ height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(location);
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_DataFoldout)
@@ -83,6 +95,14 @@ namespace XCharts
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUIUtility.standardVerticalSpacing;
}
+ if (m_IconsFoldout)
+ {
+ SerializedProperty m_Icons = prop.FindPropertyRelative("m_Icons");
+ int num = m_Icons.arraySize + 1;
+ height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
+ height += EditorGUIUtility.standardVerticalSpacing;
+ }
+ height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle"));
}
if (m_ShowJsonDataArea)
{
diff --git a/Assets/XCharts/Editor/PropertyDrawers/TextStyleDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/TextStyleDrawer.cs
index 3af4bb76..1aa7831c 100644
--- a/Assets/XCharts/Editor/PropertyDrawers/TextStyleDrawer.cs
+++ b/Assets/XCharts/Editor/PropertyDrawers/TextStyleDrawer.cs
@@ -20,8 +20,10 @@ namespace XCharts
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
+ SerializedProperty m_Font = prop.FindPropertyRelative("m_Font");
SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
+ SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor");
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset");
@@ -31,12 +33,16 @@ namespace XCharts
if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop))
{
++EditorGUI.indentLevel;
+ EditorGUI.PropertyField(drawRect, m_Font);
+ drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Rotate);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Offset);
drawRect.y += EditorGUI.GetPropertyHeight(m_Offset);
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
+ EditorGUI.PropertyField(drawRect, m_BackgroundColor);
+ drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontSize);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontStyle);
@@ -52,7 +58,7 @@ namespace XCharts
float height = 0;
if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop))
{
- height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
+ height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset"));
}
else
diff --git a/Assets/XCharts/Runtime/API/BaseChart_API.cs b/Assets/XCharts/Runtime/API/BaseChart_API.cs
index 6d3bc2fd..9d364671 100644
--- a/Assets/XCharts/Runtime/API/BaseChart_API.cs
+++ b/Assets/XCharts/Runtime/API/BaseChart_API.cs
@@ -21,7 +21,7 @@ namespace XCharts
///
/// The theme info.
///
- public ThemeInfo themeInfo { get { return m_ThemeInfo; } }
+ public ThemeInfo themeInfo { get { return m_ThemeInfo; } set { m_ThemeInfo = value; } }
///
/// The title setting of chart.
/// 标题组件
@@ -402,9 +402,19 @@ namespace XCharts
var serie = m_Series.GetSerie(serieIndex);
if (serie != null && !string.IsNullOrEmpty(serie.name))
{
- var legendIndex = m_LegendRealShowName.IndexOf(serie.name);
- var bgColor1 = active ? m_ThemeInfo.GetColor(legendIndex) : m_ThemeInfo.legendUnableColor;
- m_Legend.UpdateButtonColor(serie.name, bgColor1);
+ UpdateLegendColor(serie.name, active);
+ }
+ }
+
+ protected virtual void UpdateLegendColor(string legendName, bool active)
+ {
+ var legendIndex = m_LegendRealShowName.IndexOf(legendName);
+ if (legendIndex >= 0)
+ {
+ var iconColor = LegendHelper.GetIconColor(legend, legendIndex, m_ThemeInfo, active);
+ var contentColor = LegendHelper.GetContentColor(legend, m_ThemeInfo, active);
+ m_Legend.UpdateButtonColor(legendName, iconColor);
+ m_Legend.UpdateContentColor(legendName, contentColor);
}
}
diff --git a/Assets/XCharts/Runtime/Component/Main/Legend.cs b/Assets/XCharts/Runtime/Component/Main/Legend.cs
index 3eb9dc5a..2b8a2278 100644
--- a/Assets/XCharts/Runtime/Component/Main/Legend.cs
+++ b/Assets/XCharts/Runtime/Component/Main/Legend.cs
@@ -43,14 +43,16 @@ namespace XCharts
[SerializeField] private SelectedMode m_SelectedMode;
[SerializeField] private Orient m_Orient = Orient.Horizonal;
[SerializeField] private Location m_Location = Location.defaultRight;
- [SerializeField] private float m_ItemWidth = 50.0f;
- [SerializeField] private float m_ItemHeight = 20.0f;
- [SerializeField] private float m_ItemGap = 5;
- [SerializeField] private int m_ItemFontSize = 18;
+ [SerializeField] private float m_ItemWidth = 24.0f;
+ [SerializeField] private float m_ItemHeight = 12.0f;
+ [SerializeField] private float m_ItemGap = 10f;
+ [SerializeField] private bool m_ItemAutoColor = true;
[SerializeField] private string m_Formatter;
+ [SerializeField] private TextStyle m_TextStyle = new TextStyle(18);
[SerializeField] private List m_Data = new List();
+ [SerializeField] private List m_Icons = new List();
- private Dictionary m_DataBtnList = new Dictionary();
+ private Dictionary m_DataBtnList = new Dictionary();
///
/// Whether to show legend component.
@@ -74,13 +76,13 @@ namespace XCharts
///
public Location location { get { return m_Location; } set { m_Location = value; } }
///
- /// the width of legend item.
- /// 每个图例项的宽度。
+ /// Image width of legend symbol.
+ /// 图例标记的图形宽度。
///
public float itemWidth { get { return m_ItemWidth; } set { m_ItemWidth = value; } }
///
- /// the height of legend item.
- /// 每个图例项的高度。
+ /// Image height of legend symbol.
+ /// 图例标记的图形高度。
///
public float itemHeight { get { return m_ItemHeight; } set { m_ItemHeight = value; } }
///
@@ -89,16 +91,21 @@ namespace XCharts
///
public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } }
///
- /// font size of item text.
- /// 图例项的字体大小。
+ /// Whether the legend symbol matches the color automatically.
+ /// 图例标记的图形是否自动匹配颜色。
///
- public int itemFontSize { get { return m_ItemFontSize; } set { m_ItemFontSize = value; } }
+ public bool itemAutoColor { get { return m_ItemAutoColor; } set { m_ItemAutoColor = value; } }
///
/// 图例内容字符串模版格式器。支持用 \n 换行。
/// 模板变量为图例名称 {name}
///
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
///
+ /// the style of text.
+ /// 文本样式。
+ ///
+ public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } }
+ ///
/// Data array of legend. An array item is usually a name representing string. (If it is a pie chart,
/// it could also be the name of a single data in the pie chart) of a series.
/// If data is not specified, it will be auto collected from series.
@@ -107,11 +114,47 @@ namespace XCharts
///
public List data { get { return m_Data; } }
///
+ /// 自定义的图例标记图形。
+ ///
+ public List icons { get { return m_Icons; } }
+ ///
/// the button list of legend.
/// 图例按钮列表。
///
///
- public Dictionary buttonList { get { return m_DataBtnList; } }
+ public Dictionary buttonList { get { return m_DataBtnList; } }
+
+ public float runtimeWidth
+ {
+ get
+ {
+ var width = 0f;
+ foreach (var kv in buttonList)
+ {
+ if (orient == Orient.Horizonal)
+ width += kv.Value.width + m_ItemGap;
+ else if (kv.Value.width > width)
+ width = kv.Value.width;
+ }
+ return orient == Orient.Horizonal ? width - m_ItemGap : width;
+ }
+ }
+
+ public float runtimeHeight
+ {
+ get
+ {
+ var height = 0f;
+ foreach (var kv in buttonList)
+ {
+ if (orient == Orient.Vertical)
+ height += kv.Value.height + m_ItemGap;
+ else if (kv.Value.height > height)
+ height = kv.Value.height;
+ }
+ return orient == Orient.Vertical ? height - m_ItemGap : height;
+ }
+ }
///
/// 一个在顶部居中显示的默认图例。
@@ -126,12 +169,13 @@ namespace XCharts
m_SelectedMode = SelectedMode.Multiple,
m_Orient = Orient.Horizonal,
m_Location = Location.defaultTop,
- m_ItemWidth = 60.0f,
- m_ItemHeight = 20.0f,
- m_ItemGap = 5,
- m_ItemFontSize = 16
+ m_ItemWidth = 24.0f,
+ m_ItemHeight = 12.0f,
+ m_ItemGap = 10f,
};
legend.location.top = 30;
+ legend.textStyle.offset = new Vector2(2, 0);
+ legend.textStyle.fontSize = 18;
return legend;
}
}
@@ -144,9 +188,10 @@ namespace XCharts
m_ItemWidth = legend.itemWidth;
m_ItemHeight = legend.itemHeight;
m_ItemGap = legend.itemGap;
- m_ItemFontSize = legend.itemFontSize;
- m_Data.Clear();
- foreach (var d in legend.data) m_Data.Add(d);
+ itemAutoColor = legend.itemAutoColor;
+ m_TextStyle.Copy(legend.textStyle);
+ ChartHelper.CopyList(m_Data, legend.data);
+ ChartHelper.CopyList(m_Icons, legend.icons);
}
public override bool Equals(object obj)
@@ -178,8 +223,10 @@ namespace XCharts
itemWidth == other.itemWidth &&
itemHeight == other.itemHeight &&
itemGap == other.itemGap &&
- itemFontSize == other.itemFontSize &&
- ChartHelper.IsValueEqualsList(m_Data, other.data);
+ itemAutoColor == other.itemAutoColor &&
+ textStyle.Equals(other.textStyle) &&
+ ChartHelper.IsValueEqualsList(m_Data, other.data) &&
+ ChartHelper.IsValueEqualsList(m_Icons, other.icons);
}
public static bool operator ==(Legend left, Legend right)
@@ -285,13 +332,11 @@ namespace XCharts
///
///
///
- public void SetButton(string name, Button btn, int total)
+ public void SetButton(string name, LegendItem item, int total)
{
+ m_DataBtnList[name] = item;
int index = m_DataBtnList.Values.Count;
- btn.transform.localPosition = GetButtonLocationPosition(total, index);
- m_DataBtnList[name] = btn;
- btn.gameObject.SetActive(show);
- btn.GetComponentInChildren().text = name;
+ item.SetActive(show);
}
///
@@ -303,7 +348,27 @@ namespace XCharts
{
if (m_DataBtnList.ContainsKey(name))
{
- m_DataBtnList[name].GetComponent().color = color;
+ m_DataBtnList[name].SetIconColor(color);
+ }
+ }
+
+ public void UpdateContentColor(string name, Color color)
+ {
+ if (m_DataBtnList.ContainsKey(name))
+ {
+ m_DataBtnList[name].SetContentColor(color);
+ }
+ }
+
+ public Sprite GetIcon(int index)
+ {
+ if (index >= 0 && index < m_Icons.Count)
+ {
+ return m_Icons[index];
+ }
+ else
+ {
+ return null;
}
}
@@ -314,63 +379,7 @@ namespace XCharts
{
m_Location.OnChanged();
}
-
- ///
- /// 根据图例的布局和位置类型获得具体位置
- ///
- ///
- ///
- ///
- private Vector2 GetButtonLocationPosition(int size, int index)
- {
- switch (m_Orient)
- {
- case Orient.Vertical:
- switch (m_Location.align)
- {
- case Location.Align.TopCenter:
- case Location.Align.TopLeft:
- case Location.Align.TopRight:
- return new Vector2(0, -index * (itemHeight + itemGap));
-
- case Location.Align.Center:
- case Location.Align.CenterLeft:
- case Location.Align.CenterRight:
- float totalHeight = size * itemHeight + (size - 1) * itemGap;
- float startY = totalHeight / 2;
- return new Vector2(0, startY - index * (itemHeight + itemGap));
-
- case Location.Align.BottomCenter:
- case Location.Align.BottomLeft:
- case Location.Align.BottomRight:
- return new Vector2(0, (size - index - 1) * (itemHeight + itemGap));
- }
- return Vector2.zero;
-
- case Orient.Horizonal:
- switch (m_Location.align)
- {
- case Location.Align.TopLeft:
- case Location.Align.CenterLeft:
- case Location.Align.BottomLeft:
- return new Vector2(index * (itemWidth + itemGap), 0);
-
- case Location.Align.TopCenter:
- case Location.Align.Center:
- case Location.Align.BottomCenter:
- float totalWidth = size * itemWidth + (size - 1) * itemGap;
- float startX = totalWidth / 2;
- return new Vector2(-startX + itemWidth / 2 + index * (itemWidth + itemGap), 0);
- case Location.Align.TopRight:
- case Location.Align.CenterRight:
- case Location.Align.BottomRight:
- return new Vector2(-(size - index - 1) * (itemWidth + itemGap), 0);
- }
- return Vector2.zero;
- }
- return Vector2.zero;
- }
-
+
///
/// 从json字符串解析数据,json格式如:['邮件营销','联盟广告','视频广告','直接访问','搜索引擎']
///
diff --git a/Assets/XCharts/Runtime/Component/Main/Radar.cs b/Assets/XCharts/Runtime/Component/Main/Radar.cs
index 6aa3713a..7ec5f4e2 100644
--- a/Assets/XCharts/Runtime/Component/Main/Radar.cs
+++ b/Assets/XCharts/Runtime/Component/Main/Radar.cs
@@ -207,7 +207,7 @@ namespace XCharts
var radar = new Radar
{
m_Shape = Shape.Polygon,
- m_Radius = 0.4f,
+ m_Radius = 0.35f,
m_SplitNumber = 5,
m_Indicator = true,
m_IndicatorList = new List(5){
@@ -219,7 +219,7 @@ namespace XCharts
}
};
radar.center[0] = 0.5f;
- radar.center[1] = 0.45f;
+ radar.center[1] = 0.4f;
radar.splitLine.show = true;
radar.splitArea.show = true;
radar.splitLine.lineStyle.width = 0.6f;
diff --git a/Assets/XCharts/Runtime/Component/Main/Serie.cs b/Assets/XCharts/Runtime/Component/Main/Serie.cs
index 57b3b28c..4e33ab0a 100644
--- a/Assets/XCharts/Runtime/Component/Main/Serie.cs
+++ b/Assets/XCharts/Runtime/Component/Main/Serie.cs
@@ -501,6 +501,10 @@ namespace XCharts
///
public int showDataDimension { get { return m_ShowDataDimension; } }
///
+ /// 在Editor的inpsector上是否显示name参数
+ ///
+ public bool showDataName { get { return m_ShowDataName; } set { m_ShowDataName = value; } }
+ ///
/// If clip the overflow on the coordinate system.
/// 是否裁剪超出坐标系部分的图形。
///
diff --git a/Assets/XCharts/Runtime/Component/Main/Series.cs b/Assets/XCharts/Runtime/Component/Main/Series.cs
index 22a06d32..b7ba8f24 100644
--- a/Assets/XCharts/Runtime/Component/Main/Series.cs
+++ b/Assets/XCharts/Runtime/Component/Main/Series.cs
@@ -615,6 +615,8 @@ namespace XCharts
if (serie != null)
{
serie.show = active;
+ serie.animation.Reset();
+ if (active) serie.animation.FadeIn();
}
}
diff --git a/Assets/XCharts/Runtime/Component/Main/Theme.cs b/Assets/XCharts/Runtime/Component/Main/Theme.cs
index d65ac0aa..5c82bf74 100644
--- a/Assets/XCharts/Runtime/Component/Main/Theme.cs
+++ b/Assets/XCharts/Runtime/Component/Main/Theme.cs
@@ -132,6 +132,8 @@ namespace XCharts
get { return m_CustomLegendTextColor != Color.clear ? m_CustomLegendTextColor : m_LegendTextColor; }
set { m_CustomLegendTextColor = value; }
}
+
+ public Color32 defaultLegendTextColor{get{return m_LegendTextColor;}set{m_LegendTextColor=value;}}
///
/// the legend unable text color.
/// 图例变为不可用时的按钮颜色。
@@ -391,7 +393,7 @@ namespace XCharts
m_LegendUnableColor = GetColor("#cccccc"),
m_TitleTextColor = GetColor("#514D4D"),
m_TitleSubTextColor = GetColor("#514D4D"),
- m_LegendTextColor = GetColor("#eee"),
+ m_LegendTextColor = GetColor("#514D4D"),
m_AxisTextColor = GetColor("#514D4D"),
m_AxisLineColor = GetColor("#514D4D"),
m_AxisSplitLineColor = GetColor("#51515120"),
diff --git a/Assets/XCharts/Runtime/Component/Sub/TextStyle.cs b/Assets/XCharts/Runtime/Component/Sub/TextStyle.cs
index 787f0803..4837eb66 100644
--- a/Assets/XCharts/Runtime/Component/Sub/TextStyle.cs
+++ b/Assets/XCharts/Runtime/Component/Sub/TextStyle.cs
@@ -1,4 +1,3 @@
-using System.Threading;
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
@@ -18,12 +17,18 @@ namespace XCharts
[Serializable]
public class TextStyle : SubComponent, IEquatable
{
+ [SerializeField] private Font m_Font;
[SerializeField] private float m_Rotate = 0;
[SerializeField] private Vector2 m_Offset = Vector2.zero;
[SerializeField] private Color m_Color = Color.clear;
+ [SerializeField] private Color m_BackgroundColor = Color.clear;
[SerializeField] private int m_FontSize = 18;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
- [SerializeField] private float m_LineSpacing = 1;
+ [SerializeField] private float m_LineSpacing = 1f;
+ [SerializeField] private float m_PaddingLeft = 0f;
+ [SerializeField] private float m_PaddingRight = 0f;
+ [SerializeField] private float m_PaddingTop = 0f;
+ [SerializeField] private float m_PaddingBottom = 0f;
///
/// Rotation of text.
@@ -44,6 +49,16 @@ namespace XCharts
///
public Color color { get { return m_Color; } set { m_Color = value; } }
///
+ /// the color of text.
+ /// 文本的背景颜色。
+ ///
+ public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
+ ///
+ /// the font of text.
+ /// 文本字体
+ ///
+ public Font font { get { return m_Font; } set { m_Font = value; } }
+ ///
/// font size.
/// 文本字体大小。
///
@@ -94,6 +109,7 @@ namespace XCharts
this.fontSize = style.fontSize;
this.fontStyle = style.fontStyle;
this.color = style.color;
+ this.backgroundColor = style.backgroundColor;
this.rotate = style.rotate;
this.offset = style.offset;
this.lineSpacing = style.lineSpacing;
@@ -104,6 +120,7 @@ namespace XCharts
var textStyle = new TextStyle();
textStyle.rotate = rotate;
textStyle.color = color;
+ textStyle.backgroundColor = backgroundColor;
textStyle.fontSize = fontSize;
textStyle.fontStyle = fontStyle;
textStyle.offset = offset;
@@ -138,6 +155,7 @@ namespace XCharts
fontStyle == other.fontStyle &&
offset == other.offset &&
lineSpacing == other.lineSpacing &&
+ ChartHelper.IsValueEqualsColor(m_BackgroundColor, other.backgroundColor) &&
ChartHelper.IsValueEqualsColor(m_Color, other.color);
}
diff --git a/Assets/XCharts/Runtime/Helper/LegendHelper.cs b/Assets/XCharts/Runtime/Helper/LegendHelper.cs
new file mode 100644
index 00000000..96c81151
--- /dev/null
+++ b/Assets/XCharts/Runtime/Helper/LegendHelper.cs
@@ -0,0 +1,220 @@
+/******************************************/
+/* */
+/* Copyright (c) 2018 monitor1394 */
+/* https://github.com/monitor1394 */
+/* */
+/******************************************/
+using UnityEngine;
+using UnityEngine.UI;
+
+namespace XCharts
+{
+ internal static class LegendHelper
+ {
+ public static Color GetContentColor(Legend legend, ThemeInfo themeInfo, bool active)
+ {
+ var textStyle = legend.textStyle;
+ if (active) return textStyle.color != Color.clear ? textStyle.color : (Color)themeInfo.legendTextColor;
+ else return (Color)themeInfo.legendUnableColor;
+ }
+
+ public static Color GetIconColor(Legend legend, int readIndex, ThemeInfo themeInfo, bool active)
+ {
+ if (active)
+ {
+ if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
+ return (Color)themeInfo.GetColor(readIndex);
+ else
+ return Color.white;
+ }
+ else return (Color)themeInfo.legendUnableColor;
+ }
+
+ public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent, ThemeInfo themeInfo,
+ string content, Color itemColor, bool active)
+ {
+ var objName = i + "_" + legendName;
+ var anchorMin = new Vector2(0, 0.5f);
+ var anchorMax = new Vector2(0, 0.5f);
+ var pivot = new Vector2(0, 0.5f);
+ var sizeDelta = new Vector2(100, 30);
+ var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
+ var textStyle = legend.textStyle;
+ var font = textStyle.font ? textStyle.font : themeInfo.font;
+ var contentColor = GetContentColor(legend, themeInfo, active);
+
+ var objAnchorMin = legend.location.runtimeAnchorMin;
+ var objAnchorMax = legend.location.runtimeAnchorMax;
+ var objPivot = legend.location.runtimePivot;
+
+ var btnObj = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta);
+ var iconObj = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta);
+ var contentObj = ChartHelper.AddObject("content", btnObj.transform, anchorMin, anchorMax, pivot, sizeDelta);
+ var img = ChartHelper.GetOrAddComponent(btnObj);
+ img.color = Color.clear;
+ ChartHelper.GetOrAddComponent