mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-27 11:40:13 +00:00
增加BarChart可通过ItemStyle配置边框的支持
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
# 更新日志
|
# 更新日志
|
||||||
|
|
||||||
|
* (2020.03.09) 增加`BarChart`可通过`ItemStyle`配置边框的支持
|
||||||
* (2020.03.08) 增加`RingChart`环形图
|
* (2020.03.08) 增加`RingChart`环形图
|
||||||
* (2020.03.05) 调整`Serie`的`arcShaped`参数重命名为`roundCap`
|
* (2020.03.05) 调整`Serie`的`arcShaped`参数重命名为`roundCap`
|
||||||
* (2020.03.05) 增加运行时和非运行时参数变更自动刷新图表
|
* (2020.03.05) 增加运行时和非运行时参数变更自动刷新图表
|
||||||
|
|||||||
@@ -724,10 +724,12 @@
|
|||||||
* `color`:颜色。
|
* `color`:颜色。
|
||||||
* `backgroundColor`:背景颜色。
|
* `backgroundColor`:背景颜色。
|
||||||
* `backgroundWidth`:背景的宽。
|
* `backgroundWidth`:背景的宽。
|
||||||
|
* `centerColor`:中心区域的颜色。如环形图的中心区域。
|
||||||
|
* `centerGap`:中心区域的间隙。如环形图的中心区域于最内环的间隙。
|
||||||
* `borderType`:边框的类型。
|
* `borderType`:边框的类型。
|
||||||
* `borderColor`:边框的颜色。
|
* `borderColor`:边框的颜色。
|
||||||
* `borderWidth`:边框宽。
|
* `borderWidth`:边框宽。
|
||||||
* `borderWidth`:opacity。
|
* `opacity`:透明度。
|
||||||
|
|
||||||
## `LineArrow`
|
## `LineArrow`
|
||||||
|
|
||||||
|
|||||||
@@ -125,5 +125,19 @@ namespace XCharts
|
|||||||
get { return m_Opacity; }
|
get { return m_Opacity; }
|
||||||
set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
|
set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 实际边框宽。边框不显示时为0。
|
||||||
|
/// </summary>
|
||||||
|
public float runtimeBorderWidth { get { return NeedShowBorder() ? borderWidth : 0; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否需要显示边框。
|
||||||
|
/// </summary>
|
||||||
|
public bool NeedShowBorder()
|
||||||
|
{
|
||||||
|
return borderWidth != 0 && borderColor != Color.clear;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,7 +396,7 @@ namespace XCharts
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SerieLabelHelper.UpdateLabelText(m_Series,m_ThemeInfo);
|
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitSerieTitle()
|
private void InitSerieTitle()
|
||||||
@@ -839,30 +839,8 @@ namespace XCharts
|
|||||||
|
|
||||||
if (serieLabel.border)
|
if (serieLabel.border)
|
||||||
{
|
{
|
||||||
var borderWid = serieLabel.borderWidth;
|
ChartDrawer.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(),
|
||||||
p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig + borderWid);
|
serieLabel.borderWidth, serieLabel.borderColor, serieLabel.rotate);
|
||||||
p2 = new Vector3(centerPos.x + labelHalfWid + 2 * borderWid, centerPos.y + labelHalfHig + borderWid);
|
|
||||||
p3 = new Vector3(centerPos.x + labelHalfWid + borderWid, centerPos.y + labelHalfHig);
|
|
||||||
p4 = new Vector3(centerPos.x + labelHalfWid + borderWid, centerPos.y - labelHalfHig - 2 * borderWid);
|
|
||||||
var p5 = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig - borderWid);
|
|
||||||
var p6 = new Vector3(centerPos.x - labelHalfWid - 2 * borderWid, centerPos.y - labelHalfHig - borderWid);
|
|
||||||
var p7 = new Vector3(centerPos.x - labelHalfWid - borderWid, centerPos.y - labelHalfHig);
|
|
||||||
var p8 = new Vector3(centerPos.x - labelHalfWid - borderWid, centerPos.y + labelHalfHig + 2 * borderWid);
|
|
||||||
if (serieLabel.rotate > 0)
|
|
||||||
{
|
|
||||||
p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate);
|
|
||||||
p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate);
|
|
||||||
p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate);
|
|
||||||
p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate);
|
|
||||||
p5 = ChartHelper.RotateRound(p5, centerPos, Vector3.forward, serieLabel.rotate);
|
|
||||||
p6 = ChartHelper.RotateRound(p6, centerPos, Vector3.forward, serieLabel.rotate);
|
|
||||||
p7 = ChartHelper.RotateRound(p7, centerPos, Vector3.forward, serieLabel.rotate);
|
|
||||||
p8 = ChartHelper.RotateRound(p8, centerPos, Vector3.forward, serieLabel.rotate);
|
|
||||||
}
|
|
||||||
ChartDrawer.DrawLine(vh, p1, p2, borderWid, serieLabel.borderColor);
|
|
||||||
ChartDrawer.DrawLine(vh, p3, p4, borderWid, serieLabel.borderColor);
|
|
||||||
ChartDrawer.DrawLine(vh, p5, p6, borderWid, serieLabel.borderColor);
|
|
||||||
ChartDrawer.DrawLine(vh, p7, p8, borderWid, serieLabel.borderColor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1769,6 +1769,17 @@ namespace XCharts
|
|||||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, startColor, toColor);
|
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, startColor, toColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void CheckClipAndDrawPolygon(VertexHelper vh, ref Vector3 p1, ref Vector3 p2, ref Vector3 p3, ref Vector3 p4,
|
||||||
|
Color32 startColor, Color32 toColor, bool clip)
|
||||||
|
{
|
||||||
|
p1 = ClampInCoordinate(p1);
|
||||||
|
p2 = ClampInCoordinate(p2);
|
||||||
|
p3 = ClampInCoordinate(p3);
|
||||||
|
p4 = ClampInCoordinate(p4);
|
||||||
|
if (!clip || (clip && (IsInCooridate(p1) && IsInCooridate(p2) && IsInCooridate(p3) && IsInCooridate(p4))))
|
||||||
|
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, startColor, toColor);
|
||||||
|
}
|
||||||
|
|
||||||
protected void CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3,
|
protected void CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3,
|
||||||
Color32 color, bool clip)
|
Color32 color, bool clip)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ namespace XCharts
|
|||||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||||
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
|
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
|
||||||
float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
|
float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
|
||||||
|
float borderWidth = serie.itemStyle.runtimeBorderWidth;
|
||||||
for (int i = serie.minShow; i < maxCount; i++)
|
for (int i = serie.minShow; i < maxCount; i++)
|
||||||
{
|
{
|
||||||
if (i >= seriesHig.Count)
|
if (i >= seriesHig.Count)
|
||||||
@@ -81,11 +82,17 @@ namespace XCharts
|
|||||||
|
|
||||||
float currHig = CheckAnimation(serie, i, barHig);
|
float currHig = CheckAnimation(serie, i, barHig);
|
||||||
|
|
||||||
Vector3 p1 = new Vector3(pX, pY + space + barWidth);
|
Vector3 p1 = new Vector3(pX + borderWidth, pY + space + barWidth - borderWidth);
|
||||||
Vector3 p2 = new Vector3(pX + currHig, pY + space + barWidth);
|
Vector3 p2 = new Vector3(pX + currHig - 2 * borderWidth, pY + space + barWidth - borderWidth);
|
||||||
Vector3 p3 = new Vector3(pX + currHig, pY + space);
|
Vector3 p3 = new Vector3(pX + currHig - 2 * borderWidth, pY + space + borderWidth);
|
||||||
Vector3 p4 = new Vector3(pX, pY + space);
|
Vector3 p4 = new Vector3(pX + borderWidth, pY + space + borderWidth);
|
||||||
serie.dataPoints.Add(new Vector3(pX + currHig, pY + space + barWidth / 2));
|
Vector3 top = new Vector3(pX + currHig - borderWidth, pY + space + barWidth / 2);
|
||||||
|
p1 = ClampInCoordinate(p1);
|
||||||
|
p2 = ClampInCoordinate(p2);
|
||||||
|
p3 = ClampInCoordinate(p3);
|
||||||
|
p4 = ClampInCoordinate(p4);
|
||||||
|
top = ClampInCoordinate(top);
|
||||||
|
serie.dataPoints.Add(top);
|
||||||
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|
||||||
|| serie.data[i].highlighted
|
|| serie.data[i].highlighted
|
||||||
|| serie.highlighted;
|
|| serie.highlighted;
|
||||||
@@ -103,6 +110,14 @@ namespace XCharts
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
CheckClipAndDrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor, serie.clip);
|
CheckClipAndDrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor, serie.clip);
|
||||||
|
if (borderWidth > 0)
|
||||||
|
{
|
||||||
|
var borderColor = serie.itemStyle.borderColor;
|
||||||
|
var itemWidth = Mathf.Abs(p3.x - p1.x);
|
||||||
|
var itemHeight = Mathf.Abs(p2.y - p4.y);
|
||||||
|
var center = new Vector3((p1.x + p3.x) / 2, (p2.y + p4.y) / 2);
|
||||||
|
ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,7 +133,7 @@ namespace XCharts
|
|||||||
|
|
||||||
private float CheckAnimation(Serie serie, int dataIndex, float barHig)
|
private float CheckAnimation(Serie serie, int dataIndex, float barHig)
|
||||||
{
|
{
|
||||||
float currHig = serie.animation.CheckBarProgress(dataIndex,barHig);
|
float currHig = serie.animation.CheckBarProgress(dataIndex, barHig);
|
||||||
if (!serie.animation.IsFinish())
|
if (!serie.animation.IsFinish())
|
||||||
{
|
{
|
||||||
RefreshChart();
|
RefreshChart();
|
||||||
@@ -160,6 +175,7 @@ namespace XCharts
|
|||||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||||
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
|
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
|
||||||
float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
|
float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
|
||||||
|
float borderWidth = serie.itemStyle.runtimeBorderWidth;
|
||||||
for (int i = serie.minShow; i < maxCount; i++)
|
for (int i = serie.minShow; i < maxCount; i++)
|
||||||
{
|
{
|
||||||
if (i >= seriesHig.Count)
|
if (i >= seriesHig.Count)
|
||||||
@@ -191,16 +207,20 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
|
|
||||||
float currHig = CheckAnimation(serie, i, barHig);
|
float currHig = CheckAnimation(serie, i, barHig);
|
||||||
|
Vector3 p1 = new Vector3(pX + space + borderWidth, pY + borderWidth);
|
||||||
Vector3 p1 = new Vector3(pX + space, pY);
|
Vector3 p2 = new Vector3(pX + space + borderWidth, pY + currHig - 2 * borderWidth);
|
||||||
Vector3 p2 = new Vector3(pX + space, pY + currHig);
|
Vector3 p3 = new Vector3(pX + space + barWidth, pY + currHig - 2 * borderWidth);
|
||||||
Vector3 p3 = new Vector3(pX + space + barWidth, pY + currHig);
|
Vector3 p4 = new Vector3(pX + space + barWidth, pY + borderWidth);
|
||||||
Vector3 p4 = new Vector3(pX + space + barWidth, pY);
|
Vector3 top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth);
|
||||||
serie.dataPoints.Add(new Vector3(pX + space + barWidth / 2, pY + currHig));
|
p1 = ClampInCoordinate(p1);
|
||||||
|
p2 = ClampInCoordinate(p2);
|
||||||
|
p3 = ClampInCoordinate(p3);
|
||||||
|
p4 = ClampInCoordinate(p4);
|
||||||
|
top = ClampInCoordinate(top);
|
||||||
|
serie.dataPoints.Add(top);
|
||||||
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|
||||||
|| serie.data[i].highlighted
|
|| serie.data[i].highlighted
|
||||||
|| serie.highlighted;
|
|| serie.highlighted;
|
||||||
|
|
||||||
if (serie.show)
|
if (serie.show)
|
||||||
{
|
{
|
||||||
Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
|
Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
|
||||||
@@ -214,7 +234,15 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CheckClipAndDrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor, serie.clip);
|
CheckClipAndDrawPolygon(vh, ref p4, ref p1, ref p2, ref p3, areaColor, areaToColor, serie.clip);
|
||||||
|
if (borderWidth > 0)
|
||||||
|
{
|
||||||
|
var borderColor = serie.itemStyle.borderColor;
|
||||||
|
var itemWidth = Mathf.Abs(p3.x - p1.x);
|
||||||
|
var itemHeight = Mathf.Abs(p2.y - p4.y);
|
||||||
|
var center = new Vector3((p1.x + p3.x) / 2, (p2.y + p4.y) / 2);
|
||||||
|
ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,19 +248,30 @@ namespace XCharts
|
|||||||
vh.AddUIVertexQuad(vertex);
|
vh.AddUIVertexQuad(vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DrawBorder(VertexHelper vh, Vector3 p, float rectWidth, float rectHeight,
|
public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight,
|
||||||
float borderWidth, Color32 color)
|
float borderWidth, Color32 color, float rotate = 0)
|
||||||
{
|
{
|
||||||
var halfWid = rectWidth / 2;
|
var halfWid = rectWidth / 2;
|
||||||
var halfHig = rectHeight / 2;
|
var halfHig = rectHeight / 2;
|
||||||
var p1In = new Vector3(p.x - halfWid, p.y - halfHig);
|
var p1In = new Vector3(center.x - halfWid, center.y - halfHig);
|
||||||
var p1Ot = new Vector3(p.x - halfWid - borderWidth, p.y - halfHig - borderWidth);
|
var p1Ot = new Vector3(center.x - halfWid - borderWidth, center.y - halfHig - borderWidth);
|
||||||
var p2In = new Vector3(p.x - halfWid, p.y + halfHig);
|
var p2In = new Vector3(center.x - halfWid, center.y + halfHig);
|
||||||
var p2Ot = new Vector3(p.x - halfWid - borderWidth, p.y + halfHig + borderWidth);
|
var p2Ot = new Vector3(center.x - halfWid - borderWidth, center.y + halfHig + borderWidth);
|
||||||
var p3In = new Vector3(p.x + halfWid, p.y + halfHig);
|
var p3In = new Vector3(center.x + halfWid, center.y + halfHig);
|
||||||
var p3Ot = new Vector3(p.x + halfWid + borderWidth, p.y + halfHig + borderWidth);
|
var p3Ot = new Vector3(center.x + halfWid + borderWidth, center.y + halfHig + borderWidth);
|
||||||
var p4In = new Vector3(p.x + halfWid, p.y - halfHig);
|
var p4In = new Vector3(center.x + halfWid, center.y - halfHig);
|
||||||
var p4Ot = new Vector3(p.x + halfWid + borderWidth, p.y - halfHig - borderWidth);
|
var p4Ot = new Vector3(center.x + halfWid + borderWidth, center.y - halfHig - borderWidth);
|
||||||
|
if (rotate > 0)
|
||||||
|
{
|
||||||
|
p1In = ChartHelper.RotateRound(p1In, center, Vector3.forward, rotate);
|
||||||
|
p1Ot = ChartHelper.RotateRound(p1Ot, center, Vector3.forward, rotate);
|
||||||
|
p2In = ChartHelper.RotateRound(p2In, center, Vector3.forward, rotate);
|
||||||
|
p2Ot = ChartHelper.RotateRound(p2Ot, center, Vector3.forward, rotate);
|
||||||
|
p3In = ChartHelper.RotateRound(p3In, center, Vector3.forward, rotate);
|
||||||
|
p3Ot = ChartHelper.RotateRound(p3Ot, center, Vector3.forward, rotate);
|
||||||
|
p4In = ChartHelper.RotateRound(p4In, center, Vector3.forward, rotate);
|
||||||
|
p4Ot = ChartHelper.RotateRound(p4Ot, center, Vector3.forward, rotate);
|
||||||
|
}
|
||||||
DrawPolygon(vh, p1In, p1Ot, p2Ot, p2In, color);
|
DrawPolygon(vh, p1In, p1Ot, p2Ot, p2In, color);
|
||||||
DrawPolygon(vh, p2In, p2Ot, p3Ot, p3In, color);
|
DrawPolygon(vh, p2In, p2Ot, p3Ot, p3In, color);
|
||||||
DrawPolygon(vh, p3In, p3Ot, p4Ot, p4In, color);
|
DrawPolygon(vh, p3In, p3Ot, p4Ot, p4In, color);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user