完善多坐标轴的支持 #132

This commit is contained in:
monitor1394
2021-04-14 08:59:03 +08:00
parent 34e709c916
commit 4bf5d916d2
7 changed files with 66 additions and 12 deletions

View File

@@ -34,6 +34,9 @@
## Latest ## Latest
* (2021.04.13) Add the `ShowStarttick` and '`ShowEndTick` parameters of 'AxisTick' to control whether the first and last ticks are displayed
* (2021.04.13) Improved multi-axis support #132
## v2.1.1 ## v2.1.1
* (2021.04.13) Define the code and clear `Warning` * (2021.04.13) Define the code and clear `Warning`

View File

@@ -34,6 +34,9 @@
## Latest ## Latest
* (2021.04.13) 增加`AxisTick``ShowStartTick``ShowEndTick`参数控制第一个和最后一个刻度是否显示
* (2021.04.13) 完善多坐标轴的支持 #132
## v2.1.1 ## v2.1.1
* (2021.04.13) 整理代码,清除`Warning` * (2021.04.13) 整理代码,清除`Warning`

View File

@@ -879,6 +879,8 @@ K线图系列。
* `inside`:坐标轴刻度是否朝内,默认朝外。 * `inside`:坐标轴刻度是否朝内,默认朝外。
* `length`:坐标轴刻度的长度。 * `length`:坐标轴刻度的长度。
* `width`坐标轴刻度的宽度。默认为0时宽度和坐标轴一致。 * `width`坐标轴刻度的宽度。默认为0时宽度和坐标轴一致。
* `showStartTick`:是否显示第一个刻度。
* `showEndTick`:是否显示最后一个刻度。
## `Emphasis` ## `Emphasis`

View File

@@ -772,6 +772,8 @@ K线图系列。
* `inside`: 坐标轴刻度是否朝内,默认朝外。 * `inside`: 坐标轴刻度是否朝内,默认朝外。
* `length`: 坐标轴刻度的长度。 * `length`: 坐标轴刻度的长度。
* `width`: 坐标轴刻度的宽度。默认为0时宽度和坐标轴一致。 * `width`: 坐标轴刻度的宽度。默认为0时宽度和坐标轴一致。
* `showStartTick`:是否显示第一个刻度。
* `showEndTick`:是否显示最后一个刻度。
## `Emphasis` ## `Emphasis`

View File

@@ -59,6 +59,8 @@ namespace XCharts
base.DrawExtendeds(prop); base.DrawExtendeds(prop);
PropertyField(prop, "m_AlignWithLabel"); PropertyField(prop, "m_AlignWithLabel");
PropertyField(prop, "m_Inside"); PropertyField(prop, "m_Inside");
PropertyField(prop, "m_ShowStartTick");
PropertyField(prop, "m_ShowEndTick");
} }
} }

View File

@@ -19,6 +19,8 @@ namespace XCharts
{ {
[SerializeField] private bool m_AlignWithLabel; [SerializeField] private bool m_AlignWithLabel;
[SerializeField] private bool m_Inside; [SerializeField] private bool m_Inside;
[SerializeField] private bool m_ShowStartTick;
[SerializeField] private bool m_ShowEndTick;
/// <summary> /// <summary>
/// Align axis tick with label, which is available only when boundaryGap is set to be true in category axis. /// Align axis tick with label, which is available only when boundaryGap is set to be true in category axis.
@@ -38,6 +40,24 @@ namespace XCharts
get { return m_Inside; } get { return m_Inside; }
set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetVerticesDirty(); } set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetVerticesDirty(); }
} }
/// <summary>
/// Whether to display the first tick.
/// 是否显示第一个刻度。
/// </summary>
public bool showStartTick
{
get { return m_ShowStartTick; }
set { if (PropertyUtil.SetStruct(ref m_ShowStartTick, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to display the last tick.
/// 是否显示最后一个刻度。
/// </summary>
public bool showEndTick
{
get { return m_ShowEndTick; }
set { if (PropertyUtil.SetStruct(ref m_ShowEndTick, value)) SetVerticesDirty(); }
}
public static AxisTick defaultTick public static AxisTick defaultTick
{ {
@@ -48,6 +68,8 @@ namespace XCharts
m_Show = true, m_Show = true,
m_AlignWithLabel = false, m_AlignWithLabel = false,
m_Inside = false, m_Inside = false,
m_ShowStartTick = false,
m_ShowEndTick = true
}; };
return tick; return tick;
} }
@@ -59,6 +81,8 @@ namespace XCharts
axisTick.show = show; axisTick.show = show;
axisTick.alignWithLabel = alignWithLabel; axisTick.alignWithLabel = alignWithLabel;
axisTick.inside = inside; axisTick.inside = inside;
axisTick.showStartTick = showStartTick;
axisTick.showEndTick = showEndTick;
axisTick.lineStyle = lineStyle.Clone(); axisTick.lineStyle = lineStyle.Clone();
return axisTick; return axisTick;
} }
@@ -68,6 +92,8 @@ namespace XCharts
show = axisTick.show; show = axisTick.show;
alignWithLabel = axisTick.alignWithLabel; alignWithLabel = axisTick.alignWithLabel;
inside = axisTick.inside; inside = axisTick.inside;
showStartTick = axisTick.showStartTick;
showEndTick = axisTick.showEndTick;
} }
} }
} }

View File

@@ -826,13 +826,14 @@ namespace XCharts
{ {
posX = startX - yAxis.axisLabel.margin; posX = startX - yAxis.axisLabel.margin;
} }
posX += yAxis.offset;
return new Vector3(posX, grid.runtimeY + scaleWid, 0); return new Vector3(posX, grid.runtimeY + scaleWid, 0);
} }
private Vector3 GetLabelXPosition(float scaleWid, int i, int xAxisIndex, XAxis xAxis) private Vector3 GetLabelXPosition(float scaleWid, int i, int xAxisIndex, XAxis xAxis)
{ {
var grid = GetAxisGridOrDefault(xAxis); var grid = GetAxisGridOrDefault(xAxis);
var startY = grid.runtimeY + xAxis.offset + (xAxis.axisLabel.onZero ? m_YAxes[xAxisIndex].runtimeZeroYOffset : 0); var startY = grid.runtimeY + (xAxis.axisLabel.onZero ? m_YAxes[xAxisIndex].runtimeZeroYOffset : 0);
if (xAxis.IsTop()) startY += grid.runtimeHeight; if (xAxis.IsTop()) startY += grid.runtimeHeight;
var posY = 0f; var posY = 0f;
var inside = xAxis.axisLabel.inside; var inside = xAxis.axisLabel.inside;
@@ -845,6 +846,7 @@ namespace XCharts
{ {
posY = startY - xAxis.axisLabel.margin - fontSize / 2; posY = startY - xAxis.axisLabel.margin - fontSize / 2;
} }
posY += xAxis.offset;
return new Vector3(grid.runtimeX + scaleWid, posY); return new Vector3(grid.runtimeX + scaleWid, posY);
} }
@@ -1067,15 +1069,22 @@ namespace XCharts
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
var scaleWidth = AxisHelper.GetScaleWidth(yAxis, grid.runtimeHeight, i + 1, dataZoom); var scaleWidth = AxisHelper.GetScaleWidth(yAxis, grid.runtimeHeight, i + 1, dataZoom);
float pX = 0; if (i == 0 && !yAxis.axisTick.showStartTick)
float pY = totalWidth;
if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel)
{ {
pY -= scaleWidth / 2; totalWidth += scaleWidth;
continue;
} }
if (yAxis.axisTick.show && i > 0) if (i == size - 1 && !yAxis.axisTick.showEndTick)
{ {
var startX = grid.runtimeX + GetYAxisOnZeroOffset(yAxis); totalWidth += scaleWidth;
continue;
}
if (yAxis.axisTick.show)
{
float pX = 0;
float pY = totalWidth;
if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel) pY -= scaleWidth / 2;
var startX = grid.runtimeX + GetYAxisOnZeroOffset(yAxis) + yAxis.offset;
startX -= yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); startX -= yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
if (yAxis.IsValue() && yAxis.IsRight()) startX += grid.runtimeWidth; if (yAxis.IsValue() && yAxis.IsRight()) startX += grid.runtimeWidth;
bool inside = yAxis.axisTick.inside; bool inside = yAxis.axisTick.inside;
@@ -1176,14 +1185,21 @@ namespace XCharts
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
var scaleWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, i + 1, dataZoom); var scaleWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, i + 1, dataZoom);
float pX = totalWidth; if (i == 0 && !xAxis.axisTick.showStartTick)
float pY = 0;
if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel)
{ {
pX -= scaleWidth / 2; totalWidth += scaleWidth;
continue;
} }
if (xAxis.axisTick.show && i > 0) if (i == size - 1 && !xAxis.axisTick.showEndTick)
{ {
totalWidth += scaleWidth;
continue;
}
if (xAxis.axisTick.show)
{
float pX = totalWidth;
float pY = 0;
if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel) pX -= scaleWidth / 2;
var startY = grid.runtimeY + xAxis.offset - xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); var startY = grid.runtimeY + xAxis.offset - xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
if (xAxis.IsTop()) startY += grid.runtimeHeight; if (xAxis.IsTop()) startY += grid.runtimeHeight;
else startY += GetXAxisOnZeroOffset(xAxis); else startY += GetXAxisOnZeroOffset(xAxis);