mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 18:30:14 +00:00
增加Axis的对数轴支持子刻度
This commit is contained in:
@@ -69,6 +69,7 @@ slug: /changelog
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2023.10.21) 增加`Axis`的对数轴支持子刻度
|
||||||
* (2023.10.19) 修复`Pie`设置玫瑰图时引导线异常的问题
|
* (2023.10.19) 修复`Pie`设置玫瑰图时引导线异常的问题
|
||||||
* (2023.10.15) 修复`Line`设置`Animation`为`AlongPath`时动画异常的问题 (#281)
|
* (2023.10.15) 修复`Line`设置`Animation`为`AlongPath`时动画异常的问题 (#281)
|
||||||
* (2023.10.12) 修复`MarkLine`指定`yValue`时对数值轴无效的问题
|
* (2023.10.12) 修复`MarkLine`指定`yValue`时对数值轴无效的问题
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace XCharts
|
|||||||
|
|
||||||
internal override void SetComponent(MainComponent component)
|
internal override void SetComponent(MainComponent component)
|
||||||
{
|
{
|
||||||
this.component = (T) component;
|
this.component = (T)component;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Vector3 GetLabelPosition(float scaleWid, int i)
|
protected virtual Vector3 GetLabelPosition(float scaleWid, int i)
|
||||||
@@ -159,7 +159,6 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
m_LastSplitNumber = axis.splitNumber;
|
m_LastSplitNumber = axis.splitNumber;
|
||||||
m_LastInterval = axis.interval;
|
m_LastInterval = axis.interval;
|
||||||
|
|
||||||
axis.UpdateMinMaxValue(tempMinValue, tempMaxValue);
|
axis.UpdateMinMaxValue(tempMinValue, tempMaxValue);
|
||||||
axis.context.offset = 0;
|
axis.context.offset = 0;
|
||||||
axis.context.lastCheckInverse = axis.inverse;
|
axis.context.lastCheckInverse = axis.inverse;
|
||||||
@@ -205,7 +204,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
var lastCount = axis.context.labelValueList.Count;
|
var lastCount = axis.context.labelValueList.Count;
|
||||||
axis.context.tickValue = DateTimeUtil.UpdateTimeAxisDateTimeList(axis.context.labelValueList,
|
axis.context.tickValue = DateTimeUtil.UpdateTimeAxisDateTimeList(axis.context.labelValueList,
|
||||||
(int) axis.context.minValue, (int) axis.context.maxValue, axis.splitNumber);
|
(int)axis.context.minValue, (int)axis.context.maxValue, axis.splitNumber);
|
||||||
|
|
||||||
if (axis.context.labelValueList.Count != lastCount)
|
if (axis.context.labelValueList.Count != lastCount)
|
||||||
axis.SetAllDirty();
|
axis.SetAllDirty();
|
||||||
@@ -242,7 +241,7 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
var value = 0d;
|
var value = 0d;
|
||||||
axis.context.tickValue = tick;
|
axis.context.tickValue = tick;
|
||||||
if (Mathf.Approximately((float) (axis.context.minValue % tick), 0))
|
if (Mathf.Approximately((float)(axis.context.minValue % tick), 0))
|
||||||
{
|
{
|
||||||
value = axis.context.minValue;
|
value = axis.context.minValue;
|
||||||
}
|
}
|
||||||
@@ -411,7 +410,7 @@ namespace XCharts
|
|||||||
if (orient == Orient.Horizonal)
|
if (orient == Orient.Horizonal)
|
||||||
{
|
{
|
||||||
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
|
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
|
||||||
var posY = !axis.axisName.onZero && grid != null? grid.context.y : GetAxisLineXOrY() + offset.y;
|
var posY = !axis.axisName.onZero && grid != null ? grid.context.y : GetAxisLineXOrY() + offset.y;
|
||||||
switch (axis.axisName.labelStyle.position)
|
switch (axis.axisName.labelStyle.position)
|
||||||
{
|
{
|
||||||
case LabelStyle.Position.Start:
|
case LabelStyle.Position.Start:
|
||||||
@@ -448,7 +447,7 @@ namespace XCharts
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
|
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
|
||||||
var posX = !axis.axisName.onZero && grid != null? grid.context.x : GetAxisLineXOrY() + offset.x;
|
var posX = !axis.axisName.onZero && grid != null ? grid.context.x : GetAxisLineXOrY() + offset.x;
|
||||||
switch (axis.axisName.labelStyle.position)
|
switch (axis.axisName.labelStyle.position)
|
||||||
{
|
{
|
||||||
case LabelStyle.Position.Start:
|
case LabelStyle.Position.Start:
|
||||||
@@ -582,6 +581,7 @@ namespace XCharts
|
|||||||
var minorTickWidth = axis.minorTick.GetWidth(theme.tickWidth);
|
var minorTickWidth = axis.minorTick.GetWidth(theme.tickWidth);
|
||||||
var minorTickLength = axis.minorTick.GetLength(theme.tickLength * 0.6f);
|
var minorTickLength = axis.minorTick.GetLength(theme.tickLength * 0.6f);
|
||||||
var minorStartIndex = axis.IsTime() ? 0 : 1;
|
var minorStartIndex = axis.IsTime() ? 0 : 1;
|
||||||
|
var isLogAxis = axis.IsLog();
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom);
|
var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom);
|
||||||
@@ -616,9 +616,22 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
if (!hideTick)
|
if (!hideTick)
|
||||||
UGL.DrawLine(vh, new Vector3(pX, sY), new Vector3(pX, eY), tickWidth, tickColor);
|
UGL.DrawLine(vh, new Vector3(pX, sY), new Vector3(pX, eY), tickWidth, tickColor);
|
||||||
if (axis.minorTick.show && i >= minorStartIndex && minorTickDistance > 0)
|
if (axis.minorTick.show && i >= minorStartIndex && (minorTickDistance > 0 || isLogAxis))
|
||||||
{
|
{
|
||||||
if (lastTickX <= axis.context.zeroX || (i == minorStartIndex && pX > axis.context.zeroX))
|
if (isLogAxis)
|
||||||
|
{
|
||||||
|
var count = 0;
|
||||||
|
var logRange = (axis.logBase - 1f);
|
||||||
|
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
||||||
|
var tickTotal = lastTickX + minorTickDistance;
|
||||||
|
while (tickTotal < current && count < minorTickSplitNumber - 1)
|
||||||
|
{
|
||||||
|
UGL.DrawLine(vh, new Vector3(tickTotal, sY), new Vector3(tickTotal, mY), minorTickWidth, minorTickColor);
|
||||||
|
count++;
|
||||||
|
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
||||||
|
tickTotal = lastTickX + minorTickDistance;
|
||||||
|
}
|
||||||
|
}else if (lastTickX <= axis.context.zeroX || (i == minorStartIndex && pX > axis.context.zeroX))
|
||||||
{
|
{
|
||||||
var tickTotal = pX - minorTickDistance;
|
var tickTotal = pX - minorTickDistance;
|
||||||
while (tickTotal > lastTickX)
|
while (tickTotal > lastTickX)
|
||||||
@@ -675,9 +688,23 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
if (!hideTick)
|
if (!hideTick)
|
||||||
UGL.DrawLine(vh, new Vector3(sX, pY), new Vector3(eX, pY), tickWidth, tickColor);
|
UGL.DrawLine(vh, new Vector3(sX, pY), new Vector3(eX, pY), tickWidth, tickColor);
|
||||||
if (axis.minorTick.show && i >= minorStartIndex && minorTickDistance > 0)
|
if (axis.minorTick.show && i >= minorStartIndex && (minorTickDistance > 0 || isLogAxis))
|
||||||
{
|
{
|
||||||
if (lastTickY <= axis.context.zeroY || (i == minorStartIndex && pY > axis.context.zeroY))
|
if (isLogAxis)
|
||||||
|
{
|
||||||
|
var count = 0;
|
||||||
|
var logRange = (axis.logBase - 1f);
|
||||||
|
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
||||||
|
var tickTotal = lastTickY + minorTickDistance;
|
||||||
|
while (tickTotal < current && count < minorTickSplitNumber - 1)
|
||||||
|
{
|
||||||
|
UGL.DrawLine(vh, new Vector3(sX, tickTotal), new Vector3(mX, tickTotal), minorTickWidth, minorTickColor);
|
||||||
|
count++;
|
||||||
|
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
||||||
|
tickTotal = lastTickY + minorTickDistance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (lastTickY <= axis.context.zeroY || (i == minorStartIndex && pY > axis.context.zeroY))
|
||||||
{
|
{
|
||||||
var tickTotal = pY - minorTickDistance;
|
var tickTotal = pY - minorTickDistance;
|
||||||
while (tickTotal > lastTickY)
|
while (tickTotal > lastTickY)
|
||||||
@@ -789,6 +816,7 @@ namespace XCharts
|
|||||||
var minorLineWidth = axis.minorSplitLine.GetWidth(theme.lineWidth);
|
var minorLineWidth = axis.minorSplitLine.GetWidth(theme.lineWidth);
|
||||||
var minorLineType = axis.minorSplitLine.GetType(theme.splitLineType);
|
var minorLineType = axis.minorSplitLine.GetType(theme.splitLineType);
|
||||||
var minorStartIndex = axis.IsTime() ? 0 : 1;
|
var minorStartIndex = axis.IsTime() ? 0 : 1;
|
||||||
|
var isLogAxis = axis.IsLog();
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, axis.IsTime() ? i : i + 1, dataZoom);
|
var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, axis.IsTime() ? i : i + 1, dataZoom);
|
||||||
@@ -832,9 +860,28 @@ namespace XCharts
|
|||||||
new Vector3(current, startY + splitLength),
|
new Vector3(current, startY + splitLength),
|
||||||
lineColor);
|
lineColor);
|
||||||
}
|
}
|
||||||
if (axis.minorSplitLine.show && i >= minorStartIndex && minorTickDistance > 0)
|
if (axis.minorSplitLine.show && i >= minorStartIndex && (minorTickDistance > 0 || isLogAxis))
|
||||||
{
|
{
|
||||||
if (lastSplitX <= axis.context.zeroX || (i == minorStartIndex && current > axis.context.zeroX))
|
if (isLogAxis)
|
||||||
|
{
|
||||||
|
var count = 0;
|
||||||
|
var logRange = (axis.logBase - 1f);
|
||||||
|
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
||||||
|
var tickTotal = lastSplitX + minorTickDistance;
|
||||||
|
while (tickTotal < current && count < minorTickSplitNumber - 1)
|
||||||
|
{
|
||||||
|
ChartDrawer.DrawLineStyle(vh,
|
||||||
|
minorLineType,
|
||||||
|
minorLineWidth,
|
||||||
|
new Vector3(tickTotal, startY),
|
||||||
|
new Vector3(tickTotal, startY + splitLength),
|
||||||
|
minorSplitLineColor);
|
||||||
|
count++;
|
||||||
|
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
||||||
|
tickTotal = lastSplitX + minorTickDistance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (lastSplitX <= axis.context.zeroX || (i == minorStartIndex && current > axis.context.zeroX))
|
||||||
{
|
{
|
||||||
var tickTotal = current - minorTickDistance;
|
var tickTotal = current - minorTickDistance;
|
||||||
var count = 0;
|
var count = 0;
|
||||||
@@ -896,9 +943,28 @@ namespace XCharts
|
|||||||
new Vector3(startX + splitLength, current),
|
new Vector3(startX + splitLength, current),
|
||||||
lineColor);
|
lineColor);
|
||||||
}
|
}
|
||||||
if (axis.minorSplitLine.show && i >= minorStartIndex && minorTickDistance > 0)
|
if (axis.minorSplitLine.show && i >= minorStartIndex && (minorTickDistance > 0 || isLogAxis))
|
||||||
{
|
{
|
||||||
if (lastSplitY <= axis.context.zeroY || (i == minorStartIndex && current > axis.context.zeroY))
|
if (isLogAxis)
|
||||||
|
{
|
||||||
|
var count = 0;
|
||||||
|
var logRange = (axis.logBase - 1f);
|
||||||
|
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
||||||
|
var tickTotal = lastSplitY + minorTickDistance;
|
||||||
|
while (tickTotal < current && count < minorTickSplitNumber - 1)
|
||||||
|
{
|
||||||
|
ChartDrawer.DrawLineStyle(vh,
|
||||||
|
minorLineType,
|
||||||
|
minorLineWidth,
|
||||||
|
new Vector3(startX, tickTotal),
|
||||||
|
new Vector3(startX + splitLength, tickTotal),
|
||||||
|
minorSplitLineColor);
|
||||||
|
count++;
|
||||||
|
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
||||||
|
tickTotal = lastSplitY + minorTickDistance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (lastSplitY <= axis.context.zeroY || (i == minorStartIndex && current > axis.context.zeroY))
|
||||||
{
|
{
|
||||||
var tickTotal = current - minorTickDistance;
|
var tickTotal = current - minorTickDistance;
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user