mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 23:10:06 +00:00
增加设置图表Size支持
This commit is contained in:
@@ -12,6 +12,8 @@ namespace XCharts
|
||||
{
|
||||
protected BaseChart m_Target;
|
||||
protected SerializedProperty m_Script;
|
||||
protected SerializedProperty m_ChartWidth;
|
||||
protected SerializedProperty m_ChartHeight;
|
||||
protected SerializedProperty m_Theme;
|
||||
protected SerializedProperty m_ThemeInfo;
|
||||
protected SerializedProperty m_Title;
|
||||
@@ -39,6 +41,8 @@ namespace XCharts
|
||||
{
|
||||
m_Target = (BaseChart)target;
|
||||
m_Script = serializedObject.FindProperty("m_Script");
|
||||
m_ChartWidth = serializedObject.FindProperty("m_ChartWidth");
|
||||
m_ChartHeight = serializedObject.FindProperty("m_ChartHeight");
|
||||
m_Theme = serializedObject.FindProperty("m_Theme");
|
||||
m_ThemeInfo = serializedObject.FindProperty("m_ThemeInfo");
|
||||
m_Title = serializedObject.FindProperty("m_Title");
|
||||
@@ -74,12 +78,23 @@ namespace XCharts
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_Script);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUIUtility.labelWidth = 20;
|
||||
EditorGUILayout.LabelField("Size");
|
||||
EditorGUIUtility.fieldWidth = 1;
|
||||
m_ChartWidth.floatValue = EditorGUILayout.FloatField(m_ChartWidth.floatValue);
|
||||
m_ChartHeight.floatValue = EditorGUILayout.FloatField(m_ChartHeight.floatValue);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUIUtility.labelWidth = m_DefaultLabelWidth;
|
||||
EditorGUIUtility.fieldWidth = EditorGUIUtility.labelWidth - 5;
|
||||
m_ThemeModuleToggle = EditorGUILayout.Foldout(m_ThemeModuleToggle,
|
||||
new GUIContent("Theme","the theme of chart\n主题"),
|
||||
new GUIContent("Theme", "the theme of chart\n主题"),
|
||||
ChartEditorHelper.foldoutStyle);
|
||||
EditorGUILayout.PropertyField(m_Theme, GUIContent.none);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUIUtility.labelWidth = m_DefaultLabelWidth;
|
||||
EditorGUIUtility.fieldWidth = m_DefaultFieldWidth;
|
||||
if (m_ThemeModuleToggle)
|
||||
@@ -95,13 +110,13 @@ namespace XCharts
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_Series, true);
|
||||
m_BaseModuleToggle = EditorGUILayout.Foldout(m_BaseModuleToggle,
|
||||
new GUIContent("Base","基础配置"),
|
||||
new GUIContent("Base", "基础配置"),
|
||||
ChartEditorHelper.foldoutStyle);
|
||||
if (m_BaseModuleToggle)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
var largeTip = "Whether to enable the optimization of large-scale graph. \n是否启用大规模线图的优化,在数据图形特别多的时候(>=5k)可以开启。";
|
||||
EditorGUILayout.PropertyField(m_Large, new GUIContent("Large",largeTip));
|
||||
EditorGUILayout.PropertyField(m_Large, new GUIContent("Large", largeTip));
|
||||
EditorGUILayout.PropertyField(m_MinShowDataNumber, true);
|
||||
EditorGUILayout.PropertyField(m_MaxShowDataNumber, true);
|
||||
EditorGUILayout.PropertyField(m_MaxCacheDataNumber, true);
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace XCharts
|
||||
get{
|
||||
return new Bar(){
|
||||
m_InSameBar = false,
|
||||
m_BarWidth = 0.7f,
|
||||
m_BarWidth = 0.6f,
|
||||
m_Space = 10
|
||||
};
|
||||
}
|
||||
@@ -41,8 +41,9 @@ namespace XCharts
|
||||
{
|
||||
base.Reset();
|
||||
m_Bar = Bar.defaultBar;
|
||||
m_Title.text = "BarChart";
|
||||
RemoveData();
|
||||
AddSerie("bar1", SerieType.Line);
|
||||
AddSerie("serie1", SerieType.Line);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
AddXAxisData("x" + (i + 1));
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace XCharts
|
||||
private static readonly string s_TitleObjectName = "title";
|
||||
private static readonly string s_LegendObjectName = "legend";
|
||||
|
||||
[SerializeField] protected float m_ChartWidth;
|
||||
[SerializeField] protected float m_ChartHeight;
|
||||
[SerializeField] protected Theme m_Theme = Theme.Default;
|
||||
[SerializeField] protected ThemeInfo m_ThemeInfo;
|
||||
[SerializeField] protected Title m_Title = Title.defaultTitle;
|
||||
@@ -39,8 +41,6 @@ namespace XCharts
|
||||
[NonSerialized] private bool m_RefreshChart = false;
|
||||
[NonSerialized] protected List<Text> m_LegendTextList = new List<Text>();
|
||||
|
||||
protected float chartWidth { get { return rectTransform.sizeDelta.x; } }
|
||||
protected float chartHeight { get { return rectTransform.sizeDelta.y; } }
|
||||
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
|
||||
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
|
||||
protected Vector2 chartPivot { get { return rectTransform.pivot; } }
|
||||
@@ -50,6 +50,9 @@ namespace XCharts
|
||||
public Tooltip tooltip { get { return m_Tooltip; } }
|
||||
public Series series { get { return m_Series; } }
|
||||
|
||||
public float chartWidth { get { return m_ChartWidth; } }
|
||||
public float chartHeight { get { return m_ChartHeight; } }
|
||||
|
||||
/// <summary>
|
||||
/// The min number of data to show in chart.
|
||||
/// </summary>
|
||||
@@ -79,6 +82,21 @@ namespace XCharts
|
||||
set { m_MaxCacheDataNumber = value; if (m_MaxCacheDataNumber < 0) m_MaxCacheDataNumber = 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the size of chart.
|
||||
/// </summary>
|
||||
/// <param name="width">width</param>
|
||||
/// <param name="height">height</param>
|
||||
public virtual void SetSize(float width, float height)
|
||||
{
|
||||
m_ChartWidth = width;
|
||||
m_ChartHeight = height;
|
||||
m_CheckWidth = width;
|
||||
m_CheckHeight = height;
|
||||
rectTransform.sizeDelta = new Vector2(m_ChartWidth, m_ChartHeight);
|
||||
OnSizeChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all series and legend data.
|
||||
/// It just emptying all of serie's data without emptying the list of series.
|
||||
@@ -246,8 +264,10 @@ namespace XCharts
|
||||
rectTransform.anchorMax = Vector2.zero;
|
||||
rectTransform.anchorMin = Vector2.zero;
|
||||
rectTransform.pivot = Vector2.zero;
|
||||
m_CheckWidth = chartWidth;
|
||||
m_CheckHeight = chartHeight;
|
||||
m_ChartWidth = rectTransform.sizeDelta.x;
|
||||
m_ChartHeight = rectTransform.sizeDelta.y;
|
||||
m_CheckWidth = m_ChartWidth;
|
||||
m_CheckHeight = m_ChartHeight;
|
||||
m_CheckTheme = m_Theme;
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
@@ -267,6 +287,11 @@ namespace XCharts
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
var sizeDelta = rectTransform.sizeDelta;
|
||||
if (sizeDelta.x < 580 && sizeDelta.y < 300)
|
||||
{
|
||||
rectTransform.sizeDelta = new Vector2(580, 300);
|
||||
}
|
||||
ChartHelper.DestoryAllChilds(transform);
|
||||
m_ThemeInfo = ThemeInfo.Default;
|
||||
m_Title = Title.defaultTitle;
|
||||
@@ -388,9 +413,12 @@ namespace XCharts
|
||||
{
|
||||
if (m_CheckWidth != chartWidth || m_CheckHeight != chartHeight)
|
||||
{
|
||||
m_CheckWidth = chartWidth;
|
||||
m_CheckHeight = chartHeight;
|
||||
OnSizeChanged();
|
||||
SetSize(chartWidth, chartHeight);
|
||||
}
|
||||
var sizeDelta = rectTransform.sizeDelta;
|
||||
if (m_CheckWidth != sizeDelta.x || m_CheckHeight != sizeDelta.y)
|
||||
{
|
||||
SetSize(sizeDelta.x, sizeDelta.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace XCharts
|
||||
{
|
||||
m_Left = 50,
|
||||
m_Right = 30,
|
||||
m_Top = 60,
|
||||
m_Top = 50,
|
||||
m_Bottom = 30,
|
||||
m_Tickness = 0.6f,
|
||||
m_FontSize = 16,
|
||||
|
||||
@@ -330,7 +330,7 @@ namespace XCharts
|
||||
var axis1 = YAxis.defaultYAxis;
|
||||
var axis2 = YAxis.defaultYAxis;
|
||||
axis1.show = true;
|
||||
axis1.splitNumber = 6;
|
||||
axis1.splitNumber = 5;
|
||||
axis1.boundaryGap = false;
|
||||
axis2.show = false;
|
||||
m_YAxises.Add(axis1);
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace XCharts
|
||||
{
|
||||
var legend = new Legend
|
||||
{
|
||||
m_Show = true,
|
||||
m_Show = false,
|
||||
m_Orient = Orient.Horizonal,
|
||||
m_Location = Location.defaultTop,
|
||||
m_ItemWidth = 60.0f,
|
||||
|
||||
@@ -19,8 +19,9 @@ namespace XCharts
|
||||
{
|
||||
base.Reset();
|
||||
m_Line = Line.defaultLine;
|
||||
m_Title.text = "LineChart";
|
||||
RemoveData();
|
||||
AddSerie("line1", SerieType.Line);
|
||||
AddSerie("serie1", SerieType.Line);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
AddXAxisData("x" + (i + 1));
|
||||
|
||||
@@ -74,9 +74,10 @@ namespace XCharts
|
||||
{
|
||||
base.Reset();
|
||||
m_Pie = Pie.defaultPie;
|
||||
m_Title.text = "PieChart";
|
||||
RemoveData();
|
||||
AddData("Pie1", 80);
|
||||
AddData("Pie2", 20);
|
||||
AddData("serie1", 80);
|
||||
AddData("serie2", 20);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ namespace XCharts
|
||||
base.Reset();
|
||||
RemoveData();
|
||||
m_Radar = Radar.defaultRadar;
|
||||
AddSerie("Radar", SerieType.Radar);
|
||||
m_Title.text = "RadarChart";
|
||||
AddSerie("serie1", SerieType.Radar);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
AddData(0, Random.Range(20, 90));
|
||||
|
||||
Reference in New Issue
Block a user