Compare commits

...

11 Commits

Author SHA1 Message Date
monitor1394
9349900ea5 v2.2.2 2021-06-18 06:48:11 +08:00
monitor1394
0ae9be9c63 v2.2.1 2021-06-13 12:10:50 +08:00
monitor1394
953bea6962 完善对多屏幕的支持 2021-06-13 11:50:41 +08:00
monitor1394
1f676c431a 增加IconStylealign参数设置图标的水平对齐 2021-06-12 19:46:57 +08:00
monitor1394
f953a069cb 优化主题Theme的导入和字体自动刷新 (#148) 2021-06-12 14:32:23 +08:00
monitor1394
442206dad8 修复Unity版本兼容问题 (#154) 2021-06-10 12:54:13 +08:00
monitor1394
8dd3ef2a63 增加runtimeSortedData用于排序数据 2021-06-09 07:26:03 +08:00
monitor1394
44110feaaf Improved Candlestickchart support for inverse (#152) 2021-06-05 09:56:40 +08:00
monitor1394
a42c1845d6 优化自定义主题Theme的自动刷新 (#148) 2021-06-05 09:56:00 +08:00
monitor1394
d233f64a68 修复Gauge在最小值为负数时指针指示位置异常的问题 2021-06-04 23:08:34 +08:00
monitor1394
055d3806d8 默认关闭TextLimit 2021-06-04 07:56:01 +08:00
34 changed files with 481 additions and 150 deletions

View File

@@ -2,6 +2,8 @@
# 更新日志
[master](#master)
[v2.2.2](#v2.2.2)
[v2.2.1](#v2.2.1)
[v2.2.0](#v2.2.0)
[v2.1.1](#v2.1.1)
[v2.1.0](#v2.1.0)
@@ -35,6 +37,24 @@
## master
## v2.2.2
* (2021.06.18) Release `v2.2.2` version
* (2021.06.18) Optimize `Axis` to automatically hide `Icon` when `Label` is empty
* (2021.06.17) Fixed an issue where `maxCache` was set to one more number of actual data
* (2021.06.17) Fixed an issue where `TextMeshPro` could not be opened and closed in time to refresh
* (2021.06.17) Fixed an issue where `XCharts` always pops up when importing `XCharts`
## v2.2.1
* (2021.06.13) Release `v2.2.1` version
* (2021.06.13) Improved support for multiple screens
* (2021.06.12) Add `iconStyle` `align` parameter to set the horizontal alignment of the icon
* (2021.06.12) Improve `Theme` import (#148)
* (2021.06.10) Fixed compatibility issues with `Unity` version (#154)
* (2021.06.05) Improved Candlestickchart support for inverse (#152)
* (2021.06.04) Fixed `Gauge` having an abnormal pointer position when the minimum value is negative (#153)
## v2.2.0
* (2021.05.30) Release `v2.2.0` version

View File

@@ -2,6 +2,8 @@
# 更新日志
[master](#master)
[v2.2.2](#v2.2.2)
[v2.2.1](#v2.2.1)
[v2.2.0](#v2.2.0)
[v2.1.1](#v2.1.1)
[v2.1.0](#v2.1.0)
@@ -35,9 +37,27 @@
## master
## v2.2.2
* (2021.06.18) 发布`v2.2.2`版本
* (2021.06.18) 优化`Axis``Label`为空时自动隐藏`Icon`
* (2021.06.17) 修复`maxCache`设置时实际数据个数多一个的问题
* (2021.06.17) 修复`TextMeshPro`的开启和关闭不及时刷新的问题
* (2021.06.17) 修复`XCharts`导入时总是弹出`XCharts Importer`的问题
## v2.2.1
* (2021.06.13) 发布`v2.2.1`版本
* (2021.06.13) 完善对多屏幕的支持
* (2021.06.12) 增加`IconStyle``align`参数设置图标的水平对齐
* (2021.06.12) 完善`Theme`主题导入 (#148)
* (2021.06.10) 修复`Unity`版本兼容问题 (#154)
* (2021.06.05) 完善`CandlestickChart``inverse`的支持 (#152)
* (2021.06.04) 修复`Gauge`在最小值为负数时指针指示位置异常的问题 (#153)
## v2.2.0
* (2021.05.30) 发布`v2.0.0`版本
* (2021.05.30) 发布`v2.2.0`版本
* (2021.05.25) 完善`TextStyle``alignment`的支持 (#150)
* (2021.05.24) 修复`PieChart`数据全为`0``Label`无法正常显示的问题
* (2021.05.24) 修复`Add Serie`面板上`Serie Name`不生效的问题 (#149)

View File

@@ -22,6 +22,7 @@ namespace XCharts
{
++EditorGUI.indentLevel;
PropertyField(prop, "m_Layer");
PropertyField(prop, "m_Align");
PropertyField(prop, "m_Sprite");
PropertyField(prop, "m_Color");
PropertyField(prop, "m_Width");

View File

@@ -31,10 +31,6 @@ namespace XCharts
btnRect.y = m_DrawRect.y - EditorGUIUtility.singleLineHeight - 3;
btnRect.width = btnWidth;
var chart = prop.serializedObject.targetObject as BaseChart;
var lastFont = chart.theme.font;
#if dUI_TextMeshPro
var lastTMPFont = chart.theme.tmpFont;
#endif
if (GUI.Button(btnRect, new GUIContent("Reset", "Reset to theme default color")))
{
chart.theme.ResetTheme();
@@ -60,8 +56,18 @@ namespace XCharts
}
#if dUI_TextMeshPro
PropertyField(prop, "m_TMPFont");
if(chart.theme.tmpFont == null && !string.IsNullOrEmpty(chart.theme.tmpFontName))
{
var msg = string.Format("Can't find theme font asset:{0} in project.", chart.theme.tmpFontName);
EditorGUILayout.HelpBox(msg, MessageType.Error);
}
#else
PropertyField(prop, "m_Font");
if (chart.theme.font == null && !string.IsNullOrEmpty(chart.theme.fontName))
{
var msg = string.Format("Can't find theme font asset:{0} in project.", chart.theme.fontName);
EditorGUILayout.HelpBox(msg, MessageType.Error);
}
#endif
PropertyField(prop, "m_ContrastColor");
PropertyField(prop, "m_BackgroundColor");

View File

@@ -1,4 +1,11 @@
using UnityEngine;
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

View File

@@ -1,3 +1,11 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.IO;
using UnityEditor;
using UnityEngine;
@@ -23,6 +31,12 @@ namespace XCharts
public static void CheckAddedAsset(string assetPath)
{
var fileName = Path.GetFileName(assetPath);
if (fileName.Equals("XChartsSettings.asset"))
{
XThemeMgr.ReloadThemeList();
return;
}
if (!IsThemeAsset(assetPath)) return;
var obj = AssetDatabase.LoadAssetAtPath<TextAsset>(assetPath);
if (obj == null || obj.text == null) return;
@@ -56,7 +70,8 @@ namespace XCharts
private static bool IsThemeAsset(string assetPath)
{
if (!assetPath.EndsWith(".json")) return false;
if (!assetPath.StartsWith("XTheme")) return false;
var assetName = Path.GetFileNameWithoutExtension(assetPath);
if (!assetName.StartsWith(XChartsSettings.THEME_ASSET_NAME_PREFIX)) return false;
return true;
}
}

View File

@@ -0,0 +1,27 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEditor;
using UnityEditor.Build;
namespace XCharts
{
[System.Obsolete]
public class XChartsBuild : IPreprocessBuild, IPostprocessBuild
{
public int callbackOrder => 1;
public void OnPostprocessBuild(BuildTarget target, string path)
{
}
public void OnPreprocessBuild(BuildTarget target, string path)
{
XThemeMgr.ExportAllCustomTheme();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: df212e63c528e40fa9e8fffcd868ab7d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -70,7 +70,6 @@ namespace XCharts
rect.anchorMin = new Vector2(0.5f, 0.5f);
rect.anchorMax = new Vector2(0.5f, 0.5f);
rect.pivot = new Vector2(0.5f, 0.5f);
GameObjectUtility.EnsureUniqueNameForSibling(chart);
Selection.activeGameObject = chart;
EditorUtility.SetDirty(chart);
}
@@ -166,13 +165,14 @@ namespace XCharts
Debug.LogError("TextMeshPro is not in the project, please import TextMeshPro package first.");
return;
}
XChartsMgr.ModifyTMPRefence();
XChartsMgr.EnableTextMeshPro();
XChartsMgr.ModifyTMPRefence();
}
[MenuItem("XCharts/TextMeshPro Disable")]
public static void DisableTextMeshPro()
{
XChartsMgr.ModifyTMPRefence(true);
XChartsMgr.DisableTextMeshPro();
}
}

View File

@@ -637,6 +637,7 @@ namespace XCharts
public void UpdateTheme(ChartTheme theme)
{
m_Theme.CopyTheme(theme);
SetAllComponentDirty();
}
/// <summary>

View File

@@ -166,6 +166,9 @@ namespace XCharts
public bool ScreenPointToChartPoint(Vector2 screenPoint, out Vector2 chartPoint)
{
#if ! UNITY_EDITOR
screenPoint = Display.RelativeMouseAt(screenPoint);
#endif
var cam = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : canvas.worldCamera;
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
screenPoint, cam, out chartPoint))

View File

@@ -570,7 +570,7 @@ namespace XCharts
{
if (maxCache > 0)
{
while (m_Data.Count > maxCache)
while (m_Data.Count >= maxCache)
{
m_NeedUpdateFilterData = true;
m_Data.RemoveAt(m_InsertDataToHead ? m_Data.Count - 1 : 0);

View File

@@ -1024,7 +1024,6 @@ namespace XCharts
var p2 = new Vector3(dataZoom.runtimeX, dataZoom.runtimeY + dataZoom.runtimeHeight);
var p3 = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth, dataZoom.runtimeY + dataZoom.runtimeHeight);
var p4 = new Vector3(dataZoom.runtimeX + dataZoom.runtimeWidth, dataZoom.runtimeY);
var xAxis = chart.GetXAxis(0);
var lineColor = dataZoom.lineStyle.GetColor(chart.theme.dataZoom.dataLineColor);
var lineWidth = dataZoom.lineStyle.GetWidth(chart.theme.dataZoom.dataLineWidth);
var borderWidth = dataZoom.borderWidth == 0 ? chart.theme.dataZoom.borderWidth : dataZoom.borderWidth;

View File

@@ -247,7 +247,7 @@ namespace XCharts
/// <summary>
/// 对齐方式
/// </summary>
public enum SerieAlign
public enum Align
{
Center,
Left,
@@ -337,7 +337,7 @@ namespace XCharts
[SerializeField] private SerieDataSortType m_DataSortType = SerieDataSortType.Descending;
[SerializeField] private Orient m_Orient = Orient.Vertical;
[SerializeField] private SerieAlign m_Align = SerieAlign.Center;
[SerializeField] private Align m_Align = Align.Center;
[SerializeField] private float m_Left;
[SerializeField] private float m_Right;
[SerializeField] private float m_Top;
@@ -359,6 +359,7 @@ namespace XCharts
[NonSerialized] internal int m_FilterMinShow;
[NonSerialized] internal bool m_NeedUpdateFilterData;
[NonSerialized] internal List<SerieData> m_FilterData = new List<SerieData>();
[NonSerialized] internal List<SerieData> m_SortedData = new List<SerieData>();
[NonSerialized] private Dictionary<int, List<Vector3>> m_UpSmoothPoints = new Dictionary<int, List<Vector3>>();
[NonSerialized] private Dictionary<int, List<Vector3>> m_DownSmoothPoints = new Dictionary<int, List<Vector3>>();
[NonSerialized] private List<Vector3> m_DataPoints = new List<Vector3>();
@@ -1044,7 +1045,7 @@ namespace XCharts
/// <summary>
/// 组件水平方向对齐方式。
/// </summary>
public SerieAlign align
public Align align
{
get { return m_Align; }
set { if (PropertyUtil.SetStruct(ref m_Align, value)) SetVerticesDirty(); }
@@ -1153,7 +1154,7 @@ namespace XCharts
public float runtimeY { get; internal set; }
public float runtimeWidth { get; internal set; }
public float runtimeHeight { get; internal set; }
public List<SerieData> runtimeFilterData { get { return m_FilterData; } }
public List<SerieData> runtimeSortedData { get { return m_SortedData; } }
public bool nameDirty { get { return m_NameDirty; } }
private void SetNameDirty()
@@ -1496,7 +1497,7 @@ namespace XCharts
private void CheckMaxCache()
{
if (m_MaxCache <= 0) return;
while (m_Data.Count > m_MaxCache)
while (m_Data.Count >= m_MaxCache)
{
m_NeedUpdateFilterData = true;
if (m_InsertDataToHead) RemoveData(m_Data.Count - 1);
@@ -1660,7 +1661,7 @@ namespace XCharts
}
else
{
return runtimeFilterData.Count > 0 ? runtimeFilterData : m_Data;
return runtimeSortedData.Count > 0 ? runtimeSortedData : m_Data;
}
}

View File

@@ -928,7 +928,6 @@ namespace XCharts
var halfWid = visualMap.itemWidth / 2;
var halfHig = visualMap.itemHeight / 2;
var splitNum = visualMap.runtimeInRange.Count;
var splitWid = visualMap.itemHeight / (splitNum - 1);
var colors = visualMap.runtimeInRange;
switch (visualMap.orient)
{

View File

@@ -20,6 +20,7 @@ namespace XCharts
}
[SerializeField] private bool m_Show;
[SerializeField] private Layer m_Layer;
[SerializeField] private Align m_Align = Align.Left;
[SerializeField] private Sprite m_Sprite;
[SerializeField] private Color m_Color = Color.white;
[SerializeField] private float m_Width = 20;
@@ -66,7 +67,10 @@ namespace XCharts
/// 图标偏移。
/// </summary>
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
/// <summary>
/// 水平方向对齐方式。
/// </summary>
public Align align { get { return m_Align; } set { m_Align = value; } }
public IconStyle Clone()
{
var iconStyle = new IconStyle();
@@ -77,6 +81,7 @@ namespace XCharts
iconStyle.width = width;
iconStyle.height = height;
iconStyle.offset = offset;
iconStyle.align = align;
return iconStyle;
}
@@ -89,6 +94,7 @@ namespace XCharts
width = iconStyle.width;
height = iconStyle.height;
offset = iconStyle.offset;
align = iconStyle.align;
}
}
}

View File

@@ -123,40 +123,7 @@ namespace XCharts
/// 是否可以显示Label
/// </summary>
public bool canShowLabel { get { return m_CanShowLabel; } set { m_CanShowLabel = value; } }
/// <summary>
/// the maxinum value.
/// 最大值。
/// </summary>
public float max
{
get
{
if (m_Data.Count == 0) return 0;
float temp = float.MinValue;
for (int i = 0; i < m_Data.Count; i++)
{
if (m_Data[i] > temp) temp = m_Data[i];
}
return temp;
}
}
/// <summary>
/// the mininum value.
/// 最小值。
/// </summary>
public float min
{
get
{
if (m_Data.Count == 0) return 0;
float temp = float.MaxValue;
for (int i = 0; i < m_Data.Count; i++)
{
if (m_Data[i] < temp) temp = m_Data[i];
}
return temp;
}
}
/// <summary>
/// 饼图数据项的开始角度(运行时自动计算)
/// </summary>
@@ -328,6 +295,38 @@ namespace XCharts
}
}
/// <summary>
/// the maxinum value.
/// 最大值。
/// </summary>
public float GetMaxData(bool inverse = false)
{
if (m_Data.Count == 0) return 0;
float temp = float.MinValue;
for (int i = 0; i < m_Data.Count; i++)
{
var value = GetData(i, inverse);
if (value > temp) temp = value;
}
return temp;
}
/// <summary>
/// the mininum value.
/// 最小值。
/// </summary>
public float GetMinData(bool inverse = false)
{
if (m_Data.Count == 0) return 0;
float temp = float.MaxValue;
for (int i = 0; i < m_Data.Count; i++)
{
var value = GetData(i, inverse);
if (value < temp) temp = value;
}
return temp;
}
public bool UpdateData(int dimension, float value, bool updateAnimation, float animationDuration = 500f)
{
if (dimension >= 0 && dimension < data.Count)

View File

@@ -20,7 +20,7 @@ namespace XCharts
[Serializable]
public class TextLimit : SubComponent
{
[SerializeField] private bool m_Enable = true;
[SerializeField] private bool m_Enable = false;
[SerializeField] private float m_MaxWidth = 0;
[SerializeField] private float m_Gap = 1;
[SerializeField] private string m_Suffix = "...";

View File

@@ -47,6 +47,10 @@ namespace XCharts
{
[SerializeField] private Theme m_Theme = Theme.Default;
[SerializeField] private string m_ThemeName = Theme.Default.ToString();
[SerializeField] private string m_FontName;
[SerializeField] private string m_TMPFontName;
[SerializeField] private int m_FontInstacneId;
[SerializeField] private int m_TMPFontInstanceId;
[SerializeField] private Font m_Font;
#if dUI_TextMeshPro
[SerializeField] private TMP_FontAsset m_TMPFont;
@@ -75,6 +79,12 @@ namespace XCharts
[SerializeField] private VisualMapTheme m_VisualMap;
[SerializeField] private SerieTheme m_Serie;
private ChartTheme()
{
m_FontName = "Arial";
m_TMPFontName = "LiberationSans SDF";
}
/// <summary>
/// the theme of chart.
/// 主题类型。
@@ -110,6 +120,27 @@ namespace XCharts
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
public string fontName
{
get { return m_FontName; }
set { if (PropertyUtil.SetClass(ref m_FontName, value)) SetComponentDirty(); }
}
public int fontInstanceId
{
get { return m_FontInstacneId; }
set { if (PropertyUtil.SetStruct(ref m_FontInstacneId, value)) SetComponentDirty(); }
}
public string tmpFontName
{
get { return m_TMPFontName; }
set { if (PropertyUtil.SetClass(ref m_TMPFontName, value)) SetComponentDirty(); }
}
public int tmpFontInstanceId
{
get { return m_TMPFontInstanceId; }
set { if (PropertyUtil.SetStruct(ref m_TMPFontInstanceId, value)) SetComponentDirty(); }
}
/// <summary>
/// The color list of palette. If no color is set in series, the colors would be adopted sequentially and circularly from this list as the colors of series.
/// 调色盘颜色列表。如果系列没有设置颜色,则会依次循环从该列表中取颜色作为系列颜色。
@@ -139,11 +170,14 @@ namespace XCharts
get { return m_TMPFont; }
set
{
if (PropertyUtil.SetClass(ref m_TMPFont, value))
m_TMPFont = value;
if(value)
{
SetComponentDirty();
SyncTMPFontToSubComponent();
m_TMPFontName = value.name;
m_TMPFontInstanceId = value.GetInstanceID();
}
SetComponentDirty();
SyncTMPFontToSubComponent();
}
}
#endif
@@ -156,11 +190,14 @@ namespace XCharts
get { return m_Font; }
set
{
if (PropertyUtil.SetClass(ref m_Font, value))
m_Font = value;
if (value)
{
SetComponentDirty();
SyncFontToSubComponent();
m_FontName = value.name;
m_FontInstacneId = value.GetInstanceID();
}
SetComponentDirty();
SyncFontToSubComponent();
}
}
@@ -262,9 +299,13 @@ namespace XCharts
m_Theme = theme.theme;
m_ThemeName = theme.themeName;
#if dUI_TextMeshPro
m_TMPFont = theme.tmpFont;
tmpFont = theme.tmpFont;
#endif
m_Font = theme.m_Font;
font = theme.font;
m_FontName = theme.fontName;
m_FontInstacneId = theme.fontInstanceId;
m_TMPFontName = theme.tmpFontName;
m_TMPFontInstanceId = theme.tmpFontInstanceId;
m_ContrastColor = theme.contrastColor;
m_BackgroundColor = theme.m_BackgroundColor;
m_Common.Copy(theme.common);
@@ -438,6 +479,22 @@ namespace XCharts
}
}
public void SyncFontName()
{
if (font)
{
m_FontName = font.name;
m_FontInstacneId = font.GetInstanceID();
}
#if dUI_TextMeshPro
if (tmpFont)
{
m_TMPFontName = tmpFont.name;
m_TMPFontInstanceId = tmpFont.GetInstanceID();
}
#endif
}
public void SyncFontToSubComponent()
{
common.font = font;

View File

@@ -25,13 +25,13 @@ namespace XCharts
#endif
/// <summary>
/// the font of text
/// the font of text.
/// 字体。
/// </summary>
public Font font
{
get { return m_Font; }
set { if (PropertyUtil.SetClass(ref m_Font, value)) SetComponentDirty(); }
set { m_Font = value; SetComponentDirty(); }
}
/// <summary>
/// the color of text.
@@ -69,7 +69,7 @@ namespace XCharts
public TMP_FontAsset tmpFont
{
get { return m_TMPFont; }
set { if (PropertyUtil.SetClass(ref m_TMPFont, value)) SetComponentDirty(); }
set { m_TMPFont = value; SetComponentDirty(); }
}
#endif

View File

@@ -12,7 +12,7 @@ namespace XCharts
{
public static DataZoom GetDataZoom(Serie serie, List<DataZoom> dataZooms)
{
if(serie == null) return null;
if (serie == null) return null;
foreach (var dataZoom in dataZooms)
{
if (!dataZoom.enable) continue;
@@ -25,13 +25,36 @@ namespace XCharts
return null;
}
public static void UpdateDataZoomRuntimeStartEndValue(DataZoom dataZoom, Serie serie){
if(dataZoom == null || serie == null) return;
public static void UpdateDataZoomRuntimeStartEndValue(DataZoom dataZoom, Serie serie)
{
if (dataZoom == null || serie == null) return;
float min = 0;
float max = 0;
SerieHelper.GetMinMaxData(serie, out min, out max, null);
dataZoom.runtimeStartValue = min + (max-min) * dataZoom.start / 100;
dataZoom.runtimeEndValue = min +(max-min) * dataZoom.end / 100;
dataZoom.runtimeStartValue = min + (max - min) * dataZoom.start / 100;
dataZoom.runtimeEndValue = min + (max - min) * dataZoom.end / 100;
}
public static void UpdateDataZoomRuntimeStartEndValue(List<DataZoom> dataZooms, Series series, SerieType serieType)
{
foreach (var dataZoom in dataZooms)
{
if (!dataZoom.enable) continue;
float min = float.MaxValue;
float max = float.MinValue;
foreach (var serie in series.list)
{
if (!serie.show || serie.type != serieType) continue;
if (!dataZoom.IsXAxisIndexValue(serie.xAxisIndex)) continue;
var serieMinValue = 0f;
var serieMaxValue = 0f;
SerieHelper.GetMinMaxData(serie, out serieMinValue, out serieMaxValue, null, 2);
if (serieMinValue < min) min = serieMinValue;
if (serieMaxValue > max) max = serieMaxValue;
}
dataZoom.runtimeStartValue = min + (max - min) * dataZoom.start / 100;
dataZoom.runtimeEndValue = min + (max - min) * dataZoom.end / 100;
}
}
}
}

View File

@@ -48,7 +48,7 @@ namespace XCharts
/// <param name="min"></param>
/// <param name="max"></param>
/// <param name="dataZoom"></param>
public static void GetMinMaxData(Serie serie, out float min, out float max, DataZoom dataZoom = null)
public static void GetMinMaxData(Serie serie, out float min, out float max, DataZoom dataZoom = null, int dimension = 0)
{
max = float.MinValue;
min = float.MaxValue;
@@ -58,7 +58,9 @@ namespace XCharts
var serieData = dataList[i];
if (serieData.show)
{
var count = serie.showDataDimension > serieData.data.Count
var count = 0;
if (dimension > 0) count = dimension;
else count = serie.showDataDimension > serieData.data.Count
? serieData.data.Count
: serie.showDataDimension;
for (int j = 0; j < count; j++)
@@ -543,16 +545,16 @@ namespace XCharts
public static void UpdateSerieRuntimeFilterData(Serie serie, bool filterInvisible = true)
{
serie.runtimeFilterData.Clear();
serie.runtimeSortedData.Clear();
foreach (var serieData in serie.data)
{
if (!filterInvisible || (filterInvisible && serieData.show))
serie.runtimeFilterData.Add(serieData);
serie.runtimeSortedData.Add(serieData);
}
switch (serie.dataSortType)
{
case SerieDataSortType.Ascending:
serie.runtimeFilterData.Sort(delegate (SerieData data1, SerieData data2)
serie.runtimeSortedData.Sort(delegate (SerieData data1, SerieData data2)
{
var value1 = data1.GetData(1);
var value2 = data2.GetData(1);
@@ -562,7 +564,7 @@ namespace XCharts
});
break;
case SerieDataSortType.Descending:
serie.runtimeFilterData.Sort(delegate (SerieData data1, SerieData data2)
serie.runtimeSortedData.Sort(delegate (SerieData data1, SerieData data2)
{
var value1 = data1.GetData(1);
var value2 = data2.GetData(1);

View File

@@ -457,8 +457,8 @@ namespace XCharts
{
if (serie.type == SerieType.Candlestick)
{
var dataMin = data.min;
var dataMax = data.max;
var dataMin = data.GetMinData(inverse);
var dataMax = data.GetMaxData(inverse);
if (dataMax > max) max = dataMax;
if (dataMin < min) min = dataMin;
}
@@ -502,7 +502,7 @@ namespace XCharts
var currData = 0f;
if (serie.type == SerieType.Candlestick)
{
currData = showData[j].max;
currData = showData[j].GetMaxData(false);
}
else
{

View File

@@ -216,10 +216,6 @@ namespace XCharts
}
else
{
if (m_Theme.font == null)
{
m_Theme.font = XChartsSettings.font;
}
if (m_Theme.colorPalette.Count == 0)
{
m_Theme.ResetTheme();

View File

@@ -50,7 +50,7 @@ namespace XCharts
var close = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var lowest = serieData.GetCurrData(2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var heighest = serieData.GetCurrData(3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var isRise = close > open;
var isRise = yAxis.inverse ? close < open : close > open;
var borderWidth = open == 0 ? 0f
: (itemStyle.runtimeBorderWidth == 0 ? m_Theme.serie.candlestickBorderWidth
: itemStyle.runtimeBorderWidth);

View File

@@ -341,7 +341,7 @@ namespace XCharts
}
if (rangeValue > 0)
{
angle += rangeAngle * value / rangeValue;
angle += rangeAngle * (value - serie.min) / rangeValue;
}
return angle;
}

View File

@@ -12,6 +12,7 @@ namespace XCharts
{
public class ChartLabel : ChartObject
{
private bool m_EmptyStringHideIcon = false;
private bool m_LabelAutoSize = true;
private float m_LabelPaddingLeftRight = 3f;
private float m_LabelPaddingTopBottom = 3f;
@@ -20,6 +21,7 @@ namespace XCharts
private RectTransform m_IconRect;
private RectTransform m_ObjectRect;
private Vector3 m_IconOffest;
private Align m_Align = Align.Left;
private Image m_IconImage;
@@ -47,6 +49,8 @@ namespace XCharts
}
}
public bool emptyStringHideIcon { set { m_EmptyStringHideIcon = value; } }
public ChartLabel()
{
}
@@ -60,6 +64,7 @@ namespace XCharts
m_LabelText = new ChartText(labelObj);
m_LabelRect = m_LabelText.gameObject.GetComponent<RectTransform>();
m_ObjectRect = labelObj.GetComponent<RectTransform>();
m_Align = Align.Left;
}
public void SetAutoSize(bool flag)
@@ -96,6 +101,7 @@ namespace XCharts
m_IconImage.color = iconStyle.color;
m_IconRect.sizeDelta = new Vector2(iconStyle.width, iconStyle.height);
m_IconOffest = iconStyle.offset;
m_Align = iconStyle.align;
AdjustIconPos();
if (iconStyle.layer == IconStyle.Layer.UnderLabel)
m_IconRect.SetSiblingIndex(0);
@@ -176,6 +182,10 @@ namespace XCharts
return sizeChange;
}
AdjustIconPos();
if (m_EmptyStringHideIcon)
{
ChartHelper.SetActive(m_IconImage.gameObject, !string.IsNullOrEmpty(text));
}
}
return false;
}
@@ -185,22 +195,47 @@ namespace XCharts
if (m_IconImage && m_IconImage.sprite != null && m_IconRect)
{
var iconX = 0f;
switch (m_LabelText.text.alignment)
switch (m_Align)
{
case TextAnchor.LowerLeft:
case TextAnchor.UpperLeft:
case TextAnchor.MiddleLeft:
iconX = -m_ObjectRect.sizeDelta.x / 2 - m_IconRect.sizeDelta.x / 2;
case Align.Left:
switch (m_LabelText.text.alignment)
{
case TextAnchor.LowerLeft:
case TextAnchor.UpperLeft:
case TextAnchor.MiddleLeft:
iconX = -m_ObjectRect.sizeDelta.x / 2 - m_IconRect.sizeDelta.x / 2;
break;
case TextAnchor.LowerRight:
case TextAnchor.UpperRight:
case TextAnchor.MiddleRight:
iconX = m_ObjectRect.sizeDelta.x / 2 - m_LabelText.GetPreferredWidth() - m_IconRect.sizeDelta.x / 2;
break;
case TextAnchor.LowerCenter:
case TextAnchor.UpperCenter:
case TextAnchor.MiddleCenter:
iconX = -m_LabelText.GetPreferredWidth() / 2 - m_IconRect.sizeDelta.x / 2;
break;
}
break;
case TextAnchor.LowerRight:
case TextAnchor.UpperRight:
case TextAnchor.MiddleRight:
iconX = m_ObjectRect.sizeDelta.x / 2 - m_LabelText.GetPreferredWidth() - m_IconRect.sizeDelta.x / 2;
break;
case TextAnchor.LowerCenter:
case TextAnchor.UpperCenter:
case TextAnchor.MiddleCenter:
iconX = -m_LabelText.GetPreferredWidth() / 2 - m_IconRect.sizeDelta.x / 2;
case Align.Right:
switch (m_LabelText.text.alignment)
{
case TextAnchor.LowerLeft:
case TextAnchor.UpperLeft:
case TextAnchor.MiddleLeft:
iconX = m_ObjectRect.sizeDelta.x / 2 + m_IconRect.sizeDelta.x / 2;
break;
case TextAnchor.LowerRight:
case TextAnchor.UpperRight:
case TextAnchor.MiddleRight:
iconX = m_IconRect.sizeDelta.x / 2;
break;
case TextAnchor.LowerCenter:
case TextAnchor.UpperCenter:
case TextAnchor.MiddleCenter:
iconX = m_LabelText.GetPreferredWidth() / 2 + m_IconRect.sizeDelta.x / 2;
break;
}
break;
}
m_IconRect.anchoredPosition = m_IconOffest + new Vector3(iconX, 0);

View File

@@ -241,10 +241,6 @@ namespace XCharts
}
#if dUI_TextMeshPro
public void SetAlignment(TextAlignmentOptions alignment)
{
if (m_TMPText != null) m_TMPText.alignment = alignment;
}
public void SetFont(TMP_FontAsset font)
{

View File

@@ -405,6 +405,7 @@ namespace XCharts
var textStyle = axis.axisLabel.textStyle;
var iconStyle = axis.iconStyle;
var label = new ChartLabel();
label.emptyStringHideIcon = true;
label.gameObject = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
// TODO: 为了兼容旧版本,这里后面版本可以去掉

View File

@@ -3,21 +3,23 @@
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using System.Reflection;
#if UNITY_EDITOR
using UnityEditor;
#endif
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
public static class XThemeMgr
{
/// <summary>
/// 重新加载主题列表
/// </summary>
public static void ReloadThemeList()
{
//Debug.Log("LoadThemesFromResources");
XChartsMgr.Instance.m_ThemeDict.Clear();
XChartsMgr.Instance.m_ThemeNames.Clear();
AddTheme(ChartTheme.Default);
@@ -28,10 +30,69 @@ namespace XCharts
if (json != null && !string.IsNullOrEmpty(json.text))
{
var theme = JsonUtility.FromJson<ChartTheme>(json.text);
theme.font = GetCustomThemeFont(theme);
#if dUI_TextMeshPro
theme.tmpFont = GetCustomThemeTMPFont(theme);
#endif
AddTheme(theme);
}
}
//Debug.Log("LoadThemesFromResources DONE: theme count=" + m_ThemeDict.Keys.Count);
}
private static Font GetCustomThemeFont(ChartTheme theme)
{
Font font = null;
#if UNITY_EDITOR
if (string.IsNullOrEmpty(theme.fontName)) return null;
if (theme.fontName.Equals("Arial")) return Resources.GetBuiltinResource<Font>("Arial.ttf");
var guids = AssetDatabase.FindAssets("t:Font");
foreach (var guid in guids)
{
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
var tempFont = AssetDatabase.LoadAssetAtPath<Font>(assetPath);
if (tempFont.name.Equals(theme.fontName))
{
font = tempFont;
break;
}
}
#else
font = FindObjectByInstanceId(theme.fontInstanceId) as Font;
#endif
return font;
}
#if dUI_TextMeshPro
private static TMP_FontAsset GetCustomThemeTMPFont(ChartTheme theme)
{
TMP_FontAsset font = null;
#if UNITY_EDITOR
if (!string.IsNullOrEmpty(theme.tmpFontName)){
//TODO: how to find TMP_FontAsset asset
var guids = AssetDatabase.FindAssets("t:Texture");
foreach (var guid in guids)
{
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
if(!assetPath.EndsWith(".asset"))continue;
var tempFont = AssetDatabase.LoadAssetAtPath<TMP_FontAsset>(assetPath);
if (tempFont && tempFont.name.Equals(theme.tmpFontName))
{
font = tempFont;
break;
}
}
}
#else
font = FindObjectByInstanceId(theme.fontInstanceId) as TMP_FontAsset;
#endif
return font;
}
#endif
public static Object FindObjectByInstanceId(int instanceId)
{
return (Object)typeof(Object).GetMethod("FindObjectFromInstanceID",
BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { instanceId });
}
public static void AddTheme(ChartTheme theme)
@@ -42,10 +103,6 @@ namespace XCharts
XChartsMgr.Instance.m_ThemeDict.Add(theme.themeName, theme);
XChartsMgr.Instance.m_ThemeNames.Add(theme.themeName);
}
else
{
Debug.LogError("Theme name is exist:" + theme.themeName);
}
}
public static ChartTheme GetTheme(string themeName)
@@ -62,6 +119,16 @@ namespace XCharts
return XChartsMgr.Instance.m_ThemeNames;
}
public static List<ChartTheme> GetThemeList()
{
var list = new List<ChartTheme>();
foreach (var theme in XChartsMgr.Instance.m_ThemeDict.Values)
{
list.Add(theme);
}
return list;
}
public static bool ContainsTheme(string themeName)
{
return XChartsMgr.Instance.m_ThemeNames.Contains(themeName);
@@ -69,7 +136,6 @@ namespace XCharts
public static void SwitchTheme(BaseChart chart, string themeName)
{
Debug.Log("SwitchTheme:" + themeName);
#if UNITY_EDITOR
if (XChartsMgr.Instance.m_ThemeDict.Count == 0)
{
@@ -82,8 +148,7 @@ namespace XCharts
return;
}
var target = XChartsMgr.Instance.m_ThemeDict[themeName];
chart.theme.CopyTheme(target);
chart.RefreshAllComponent();
chart.UpdateTheme(target);
}
public static bool ExportTheme(ChartTheme theme, string themeNewName)
@@ -94,14 +159,9 @@ namespace XCharts
newtheme.theme = Theme.Custom;
newtheme.themeName = themeNewName;
var themeFileName = "XTheme-" + newtheme.themeName;
var assetPath = string.Format("Assets/XCharts/Resources/{0}", themeFileName);
var filePath = string.Format("{0}/../{1}.json", Application.dataPath, assetPath);
var json = JsonUtility.ToJson(newtheme, true);
File.WriteAllText(filePath, json);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
var obj = Resources.Load<TextAsset>(themeFileName);
ExportTheme(newtheme);
var themeAssetName = XChartsSettings.THEME_ASSET_NAME_PREFIX + theme.themeName;
var obj = Resources.Load<TextAsset>(themeAssetName);
XChartsSettings.AddJsonTheme(obj);
ReloadThemeList();
return true;
@@ -110,9 +170,47 @@ namespace XCharts
#endif
}
public static bool ExportTheme(ChartTheme theme)
{
#if UNITY_EDITOR
theme.SyncFontName();
var themeAssetName = XChartsSettings.THEME_ASSET_NAME_PREFIX + theme.themeName;
var themeAssetPath = Application.dataPath + "/../" + XChartsSettings.THEME_ASSET_FOLDER;
if (!Directory.Exists(themeAssetPath))
{
Directory.CreateDirectory(themeAssetPath);
}
var themeAssetFilePath = string.Format("{0}/{1}.json", themeAssetPath, themeAssetName);
var json = JsonUtility.ToJson(theme, true);
File.WriteAllText(themeAssetFilePath, json);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
return true;
#else
return false;
#endif
}
public static void ExportAllCustomTheme()
{
var list = new List<ChartTheme>();
foreach (var theme in XChartsMgr.Instance.m_ThemeDict.Values)
{
if (theme.theme == Theme.Custom)
{
list.Add(theme);
}
}
foreach (var theme in list)
{
ExportTheme(theme);
}
}
public static string GetThemeAssetPath(string themeName)
{
return string.Format("Assets/XCharts/Resources/XTheme-{0}.json", themeName);
return string.Format("{0}/{1}{2}.json", XChartsSettings.THEME_ASSET_FOLDER,
XChartsSettings.THEME_ASSET_NAME_PREFIX, themeName);
}
}
}

View File

@@ -30,14 +30,11 @@ namespace XCharts
public string homepage = "";
}
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
[ExecuteInEditMode]
public class XChartsMgr : MonoBehaviour
{
internal static string _version = "2.2.0";
internal static int _versionDate = 20210530;
internal static string _version = "2.2.2";
internal static int _versionDate = 20210618;
public static string version { get { return _version; } }
public static int versionDate { get { return _versionDate; } }
public static string fullVersion { get { return version + "-" + versionDate; } }
@@ -67,20 +64,6 @@ namespace XCharts
}
}
private XChartsMgr()
{
}
static XChartsMgr()
{
#if UNITY_EDITOR
EditorApplication.delayCall += () =>
{
var mgr = XChartsMgr.Instance;
};
#endif
}
private void Awake()
{
SerieLabelPool.ClearAll();
@@ -423,6 +406,7 @@ namespace XCharts
var addedTMP = false;
var removedTMP = false;
var tmpName = "\"Unity.TextMeshPro\"";
var refCount = 0;
foreach (var line in lines)
{
if (string.IsNullOrEmpty(line)) continue;
@@ -436,6 +420,12 @@ namespace XCharts
if (line.Contains("],"))
{
referencesStart = false;
if (refCount > 0)
{
var old = dest[dest.Count - 1];
if (old.EndsWith(","))
dest[dest.Count - 1] = old.Substring(0, old.Length - 1);
}
if (!removeTMP && !refs.Contains(tmpName))
{
if (refs.Count > 0)
@@ -455,8 +445,12 @@ namespace XCharts
{
if (!line.Contains(tmpName))
{
removedTMP = true;
dest.Add(line);
refCount++;
}
else
{
removedTMP = true;
}
}
else
@@ -471,7 +465,12 @@ namespace XCharts
dest.Add(line);
}
}
if (addedTMP || removedTMP) File.WriteAllText(asmdefPath, string.Join("\n", dest.ToArray()));
if (addedTMP || removedTMP)
{
File.WriteAllText(asmdefPath, string.Join("\n", dest.ToArray()));
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
return true;
}
catch (System.Exception e)

View File

@@ -11,6 +11,9 @@ using System.Collections.Generic;
#if dUI_TextMeshPro
using TMPro;
#endif
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace XCharts
{
@@ -21,6 +24,8 @@ namespace XCharts
#endif
public class XChartsSettings : ScriptableObject
{
public readonly static string THEME_ASSET_NAME_PREFIX = "XTheme-";
public readonly static string THEME_ASSET_FOLDER = "Assets/XCharts/Resources";
[SerializeField] private Font m_Font = null;
#if dUI_TextMeshPro
@@ -145,7 +150,6 @@ namespace XCharts
}
#endif
}
return s_Instance;
}
}
@@ -156,6 +160,11 @@ namespace XCharts
if (!Instance.m_CustomThemes.Contains(theme))
{
Instance.m_CustomThemes.Add(theme);
#if UNITY_EDITOR
EditorUtility.SetDirty(Instance);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
#endif
return true;
}
return false;

View File

@@ -1,9 +1,9 @@
{
"name": "com.monitor1394.xcharts",
"displayName": "XCharts",
"version": "2.2.0",
"date": "20210530",
"checkdate": "20210530",
"version": "2.2.2",
"date": "20210618",
"checkdate": "20210618",
"desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!",
"unity": "2018.3",
"description": "A charting and data visualization library for Unity.",

View File

@@ -1,7 +1,7 @@
{
"version": "2.2.0",
"date": "20210530",
"checkdate": "20210530",
"version": "2.2.2",
"date": "20210618",
"checkdate": "20210618",
"desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!",
"homepage": "https://github.com/monitor1394/unity-ugui-XCharts"
}