Editor上添加第二个X轴或Y轴时自动设置位置

This commit is contained in:
monitor1394
2024-01-14 10:56:36 +08:00
parent 9a56985b3a
commit 6aa11249c5
3 changed files with 39 additions and 1 deletions

View File

@@ -133,7 +133,26 @@ namespace XCharts.Editor
public void AddChartComponent(Type type)
{
chart.AddChartComponent(type);
var component = chart.AddChartComponent(type);
if (component != null)
{
if (component is YAxis)
{
var yAxis = component as YAxis;
if (yAxis.index == 1)
{
yAxis.position = Axis.AxisPosition.Right;
}
}
else if (component is XAxis)
{
var xAxis = component as XAxis;
if (xAxis.index == 1)
{
xAxis.position = Axis.AxisPosition.Top;
}
}
}
m_ComponentsProperty = m_BaseEditor.RefreshComponent();
RefreshEditors();
EditorUtility.SetDirty(chart);

View File

@@ -83,5 +83,13 @@ namespace XCharts.Editor
var chart = AddChart<LineChart>("LineChart_Time", "Time Line");
chart.DefaultTimeLineChart();
}
[MenuItem("XCharts/LineChart/Log Line", priority = 44)]
[MenuItem("GameObject/XCharts/LineChart/Log Line", priority = 44)]
public static void AddLineChart_Log()
{
var chart = AddChart<LineChart>("LineChart_Log", "Log Line");
chart.DefaultLogLineChart();
}
}
}

View File

@@ -131,5 +131,16 @@ namespace XCharts.Runtime
var xAxis = GetChartComponent<XAxis>();
xAxis.type = Axis.AxisType.Time;
}
/// <summary>
/// default logarithmic line chart.
/// || 默认对数轴折线图。
/// </summary>
public void DefaultLogLineChart()
{
CheckChartInit();
var yAxis = GetChartComponent<YAxis>();
yAxis.type = Axis.AxisType.Log;
}
}
}