diff --git a/Assets/XCharts/CHANGELOG-EN.md b/Assets/XCharts/CHANGELOG-EN.md
index 70c3c341..424960cd 100644
--- a/Assets/XCharts/CHANGELOG-EN.md
+++ b/Assets/XCharts/CHANGELOG-EN.md
@@ -34,6 +34,9 @@
## Latest
+* (2021.04.26) Added support for `Barchart` to draw gradient borders
+* (2021.04.23) Added support for custom charts
+* (2021.04.22) Fixed bug where `Gauge` `axisLabel`'s text color could not be adjusted
* (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
diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md
index 393c9b88..36d1ce1a 100644
--- a/Assets/XCharts/CHANGELOG.md
+++ b/Assets/XCharts/CHANGELOG.md
@@ -34,6 +34,9 @@
## Latest
+* (2021.04.26) 增加`BarChart`绘制渐变边框的支持
+* (2021.04.23) 增加自定义图表支持
+* (2021.04.22) 修复`Gauge`的`AxisLabel`和文字颜色无法调整的问题
* (2021.04.13) 增加`AxisTick`的`ShowStartTick`和`ShowEndTick`参数控制第一个和最后一个刻度是否显示
* (2021.04.13) 完善多坐标轴的支持 #132
diff --git a/Assets/XCharts/Editor/PropertyDrawers/ItemStyleDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/ItemStyleDrawer.cs
index b1211965..4f7ddef7 100644
--- a/Assets/XCharts/Editor/PropertyDrawers/ItemStyleDrawer.cs
+++ b/Assets/XCharts/Editor/PropertyDrawers/ItemStyleDrawer.cs
@@ -5,7 +5,6 @@
/* */
/************************************************/
-using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
@@ -33,6 +32,7 @@ namespace XCharts
PropertyField(prop, "m_BorderWidth");
PropertyField(prop, "m_BorderColor");
PropertyField(prop, "m_BorderColor0");
+ PropertyField(prop, "m_BorderToColor");
PropertyField(prop, "m_Opacity");
PropertyField(prop, "m_TooltipFormatter");
PropertyField(prop, "m_NumericFormatter");
diff --git a/Assets/XCharts/Runtime/Component/Sub/ItemStyle.cs b/Assets/XCharts/Runtime/Component/Sub/ItemStyle.cs
index df3e5c76..1aad5d7f 100644
--- a/Assets/XCharts/Runtime/Component/Sub/ItemStyle.cs
+++ b/Assets/XCharts/Runtime/Component/Sub/ItemStyle.cs
@@ -48,6 +48,7 @@ namespace XCharts
[SerializeField] private float m_BorderWidth = 0;
[SerializeField] private Color32 m_BorderColor;
[SerializeField] private Color32 m_BorderColor0;
+ [SerializeField] private Color32 m_BorderToColor;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
[SerializeField] private string m_TooltipFormatter;
[SerializeField] private string m_NumericFormatter = "";
@@ -68,6 +69,7 @@ namespace XCharts
m_BorderWidth = 0;
m_BorderColor = Color.clear;
m_BorderColor0 = Color.clear;
+ m_BorderToColor = Color.clear;
m_Opacity = 1;
m_TooltipFormatter = null;
m_NumericFormatter = "";
@@ -181,6 +183,14 @@ namespace XCharts
set { if (PropertyUtil.SetColor(ref m_BorderColor0, value)) SetVerticesDirty(); }
}
///
+ /// 边框的渐变色。
+ ///
+ public Color32 borderToColor
+ {
+ get { return m_BorderToColor; }
+ set { if (PropertyUtil.SetColor(ref m_BorderToColor, value)) SetVerticesDirty(); }
+ }
+ ///
/// 边框宽。
///
public float borderWidth
diff --git a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs
index 937980df..5ccdac71 100644
--- a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs
+++ b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs
@@ -106,8 +106,8 @@ namespace XCharts
else
{
plt = new Vector3(pX + borderWidth, pY + space + barWidth - borderWidth);
- prt = new Vector3(pX + currHig - borderWidth , pY + space + barWidth - borderWidth);
- prb = new Vector3(pX + currHig - borderWidth , pY + space + borderWidth);
+ prt = new Vector3(pX + currHig - borderWidth, pY + space + barWidth - borderWidth);
+ prb = new Vector3(pX + currHig - borderWidth, pY + space + borderWidth);
plb = new Vector3(pX + borderWidth, pY + space + borderWidth);
}
top = new Vector3(pX + currHig - borderWidth, pY + space + barWidth / 2);
@@ -301,7 +301,6 @@ namespace XCharts
plt = ClampInGrid(grid, plt);
prt = ClampInGrid(grid, prt);
}
- var borderColor = itemStyle.borderColor;
var itemWidth = Mathf.Abs(prb.x - plt.x);
var itemHeight = Mathf.Abs(prt.y - plb.y);
var center = new Vector3((plt.x + prb.x) / 2, (prt.y + plb.y) / 2);
@@ -316,8 +315,8 @@ namespace XCharts
{
CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip, grid);
}
- UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0,
- itemStyle.cornerRadius, isYAxis);
+ UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor,
+ itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis);
}
}
else
@@ -329,7 +328,6 @@ namespace XCharts
plt = ClampInGrid(grid, plt);
prt = ClampInGrid(grid, prt);
}
- var borderColor = itemStyle.borderColor;
var itemWidth = Mathf.Abs(prt.x - plb.x);
var itemHeight = Mathf.Abs(plt.y - prb.y);
var center = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2);
@@ -345,8 +343,8 @@ namespace XCharts
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor,
serie.clip, grid);
}
- UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0,
- itemStyle.cornerRadius, isYAxis);
+ UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor,
+ itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis);
}
}
}
diff --git a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawGantt.cs b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawGantt.cs
index 6c43e5d6..d62a6926 100644
--- a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawGantt.cs
+++ b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawGantt.cs
@@ -146,8 +146,8 @@ namespace XCharts
}
if (borderWidth != 0)
{
- UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor, 0,
- itemStyle.cornerRadius, true, 0.5f);
+ UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor,
+ itemStyle.borderToColor, 0, itemStyle.cornerRadius, true, 0.5f);
}
return new Rect(plb.x, plb.y, xEnd - xStart, barWidth);
}
diff --git a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawHeatmap.cs b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawHeatmap.cs
index f9278ae7..a5f0ce60 100644
--- a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawHeatmap.cs
+++ b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawHeatmap.cs
@@ -137,6 +137,8 @@ namespace XCharts
var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : ChartConst.clearColor32;
borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity);
+ var borderToColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderToColor : ChartConst.clearColor32;
+ borderToColor.a = (byte)(borderToColor.a * serie.itemStyle.opacity);
serie.dataPoints.Clear();
serie.animation.InitProgress(1, 0, xCount);
var animationIndex = serie.animation.GetCurrIndex();
@@ -175,8 +177,8 @@ namespace XCharts
}
if (animationIndex >= 0 && i > animationIndex) continue;
serieData.canShowLabel = true;
- var emphasis = (tooltip.show
- && i == (int)tooltip.runtimeXValues[0]
+ var emphasis = (tooltip.show
+ && i == (int)tooltip.runtimeXValues[0]
&& j == (int)tooltip.runtimeYValues[0])
|| visualMap.runtimeSelectedIndex > 0;
var rectWid = xWidth - 2 * borderWidth;
@@ -184,15 +186,18 @@ namespace XCharts
UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color);
if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor))
{
- UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor);
+ UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor, borderToColor);
}
- if (visualMap.hoverLink && emphasis && serie.emphasis.show
+ if (visualMap.hoverLink && emphasis && serie.emphasis.show
&& serie.emphasis.itemStyle.borderWidth > 0)
{
var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
- var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0
+ var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0
? serie.emphasis.itemStyle.borderColor : ChartConst.clearColor32;
- UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor);
+ var emphasisBorderToColor = serie.emphasis.itemStyle.opacity > 0
+ ? serie.emphasis.itemStyle.borderToColor : ChartConst.clearColor32;
+ UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor,
+ emphasisBorderToColor);
}
}
}
diff --git a/Assets/XCharts/Runtime/XUGL/UGL.cs b/Assets/XCharts/Runtime/XUGL/UGL.cs
index e2a41f6a..98de0df1 100644
--- a/Assets/XCharts/Runtime/XUGL/UGL.cs
+++ b/Assets/XCharts/Runtime/XUGL/UGL.cs
@@ -1,9 +1,9 @@
-/************************************************/
-/* */
-/* Copyright (c) 2018 - 2021 monitor1394 */
-/* https://github.com/monitor1394 */
-/* */
-/************************************************/
+/******************************************/
+/* */
+/* Copyright (c) 2020 monitor1394 */
+/* https://github.com/monitor1394 */
+/* */
+/******************************************/
using System.Collections.Generic;
using UnityEngine;
@@ -477,7 +477,7 @@ namespace XUGL
vh.AddUIVertexQuad(s_Vertex);
}
- private static void InitCornerRadius(float[] cornerRadius, float width, float height, bool isYAxis,
+ private static void InitCornerRadius(float[] cornerRadius, float width, float height, bool horizontal,
ref float brLt, ref float brRt, ref float brRb, ref float brLb, ref bool needRound)
{
if (cornerRadius == null) return;
@@ -498,7 +498,7 @@ namespace XUGL
if (brRt > 0 && brRt <= 1) brRt = brRt * min;
if (brRb > 0 && brRb <= 1) brRb = brRb * min;
if (brLb > 0 && brLb <= 1) brLb = brLb * min;
- if (isYAxis)
+ if (horizontal)
{
if (brLb + brLt >= height)
{
@@ -807,8 +807,28 @@ namespace XUGL
///
///
public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight,
- float borderWidth, Color32 color, float rotate = 0, float[] cornerRadius = null, bool isYAxis = false,
- float smoothness = 1f)
+ float borderWidth, Color32 color, float rotate = 0, float[] cornerRadius = null,
+ bool horizontal = false, float smoothness = 1f)
+ {
+ DrawBorder(vh, center, rectWidth, rectHeight, borderWidth, color, s_ClearColor32, rotate,
+ cornerRadius, horizontal, smoothness);
+ }
+
+ ///
+ /// 绘制(圆角)边框
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight,
+ float borderWidth, Color32 color, Color32 toColor, float rotate = 0, float[] cornerRadius = null,
+ bool horizontal = false, float smoothness = 1f)
{
if (borderWidth == 0 || UGLHelper.IsClearColor(color)) return;
var halfWid = rectWidth / 2;
@@ -823,9 +843,13 @@ namespace XUGL
var rbOt = new Vector3(center.x + halfWid + borderWidth, center.y - halfHig - borderWidth);
float brLt = 0, brRt = 0, brRb = 0, brLb = 0;
bool needRound = false;
- InitCornerRadius(cornerRadius, rectWidth, rectHeight, isYAxis, ref brLt, ref brRt, ref brRb,
+ InitCornerRadius(cornerRadius, rectWidth, rectHeight, horizontal, ref brLt, ref brRt, ref brRb,
ref brLb, ref needRound);
var tempCenter = Vector3.zero;
+ if (UGLHelper.IsClearColor(toColor))
+ {
+ toColor = color;
+ }
if (needRound)
{
var lbIn2 = lbIn;
@@ -839,7 +863,8 @@ namespace XUGL
if (brLt > 0)
{
tempCenter = new Vector3(center.x - halfWid + brLt, center.y + halfHig - brLt);
- DrawDoughnut(vh, tempCenter, brLt, brLt + borderWidth, color, s_ClearColor32, 270, 360, smoothness);
+ DrawDoughnut(vh, tempCenter, brLt, brLt + borderWidth, horizontal ? color : toColor, s_ClearColor32,
+ 270, 360, smoothness);
ltIn = tempCenter + brLt * Vector3.left;
ltOt = tempCenter + (brLt + borderWidth) * Vector3.left;
ltIn2 = tempCenter + brLt * Vector3.up;
@@ -848,7 +873,7 @@ namespace XUGL
if (brRt > 0)
{
tempCenter = new Vector3(center.x + halfWid - brRt, center.y + halfHig - brRt);
- DrawDoughnut(vh, tempCenter, brRt, brRt + borderWidth, color, s_ClearColor32, 0, 90, smoothness);
+ DrawDoughnut(vh, tempCenter, brRt, brRt + borderWidth, toColor, s_ClearColor32, 0, 90, smoothness);
rtIn = tempCenter + brRt * Vector3.up;
rtOt = tempCenter + (brRt + borderWidth) * Vector3.up;
rtIn2 = tempCenter + brRt * Vector3.right;
@@ -857,7 +882,8 @@ namespace XUGL
if (brRb > 0)
{
tempCenter = new Vector3(center.x + halfWid - brRb, center.y - halfHig + brRb);
- DrawDoughnut(vh, tempCenter, brRb, brRb + borderWidth, color, s_ClearColor32, 90, 180, smoothness);
+ DrawDoughnut(vh, tempCenter, brRb, brRb + borderWidth, horizontal ? toColor : color, s_ClearColor32,
+ 90, 180, smoothness);
rbIn = tempCenter + brRb * Vector3.right;
rbOt = tempCenter + (brRb + borderWidth) * Vector3.right;
rbIn2 = tempCenter + brRb * Vector3.down;
@@ -872,10 +898,20 @@ namespace XUGL
lbIn2 = tempCenter + brLb * Vector3.down;
lbOt2 = tempCenter + (brLb + borderWidth) * Vector3.down;
}
- DrawQuadrilateral(vh, lbIn, lbOt, ltOt, ltIn, color);
- DrawQuadrilateral(vh, ltIn2, ltOt2, rtOt, rtIn, color);
- DrawQuadrilateral(vh, rtIn2, rtOt2, rbOt, rbIn, color);
- DrawQuadrilateral(vh, rbIn2, rbOt2, lbOt2, lbIn2, color);
+ if (horizontal)
+ {
+ DrawQuadrilateral(vh, lbIn, lbOt, ltOt, ltIn, color, color);
+ DrawQuadrilateral(vh, ltIn2, ltOt2, rtOt, rtIn, color, toColor);
+ DrawQuadrilateral(vh, rtIn2, rtOt2, rbOt, rbIn, toColor, toColor);
+ DrawQuadrilateral(vh, rbIn2, rbOt2, lbOt2, lbIn2, toColor, color);
+ }
+ else
+ {
+ DrawQuadrilateral(vh, lbIn, lbOt, ltOt, ltIn, color, toColor);
+ DrawQuadrilateral(vh, ltIn2, ltOt2, rtOt, rtIn, toColor, toColor);
+ DrawQuadrilateral(vh, rtIn2, rtOt2, rbOt, rbIn, toColor, color);
+ DrawQuadrilateral(vh, rbIn2, rbOt2, lbOt2, lbIn2, color, color);
+ }
}
else
{
@@ -890,10 +926,20 @@ namespace XUGL
rbIn = UGLHelper.RotateRound(rbIn, center, Vector3.forward, rotate);
rbOt = UGLHelper.RotateRound(rbOt, center, Vector3.forward, rotate);
}
- DrawQuadrilateral(vh, lbIn, lbOt, ltOt, ltIn, color);
- DrawQuadrilateral(vh, ltIn, ltOt, rtOt, rtIn, color);
- DrawQuadrilateral(vh, rtIn, rtOt, rbOt, rbIn, color);
- DrawQuadrilateral(vh, rbIn, rbOt, lbOt, lbIn, color);
+ if (horizontal)
+ {
+ DrawQuadrilateral(vh, lbIn, lbOt, ltOt, ltIn, color, color);
+ DrawQuadrilateral(vh, ltIn, ltOt, rtOt, rtIn, color, toColor);
+ DrawQuadrilateral(vh, rtIn, rtOt, rbOt, rbIn, toColor, toColor);
+ DrawQuadrilateral(vh, rbIn, rbOt, lbOt, lbIn, toColor, color);
+ }
+ else
+ {
+ DrawQuadrilateral(vh, lbIn, lbOt, ltOt, ltIn, color, toColor);
+ DrawQuadrilateral(vh, ltIn, ltOt, rtOt, rtIn, toColor, toColor);
+ DrawQuadrilateral(vh, rtIn, rtOt, rbOt, rbIn, toColor, color);
+ DrawQuadrilateral(vh, rbIn, rbOt, lbOt, lbIn, color, color);
+ }
}
}
diff --git a/Assets/XCharts/Runtime/XUGL/UGLExample.cs b/Assets/XCharts/Runtime/XUGL/UGLExample.cs
index b873c04b..c04dd6b4 100644
--- a/Assets/XCharts/Runtime/XUGL/UGLExample.cs
+++ b/Assets/XCharts/Runtime/XUGL/UGLExample.cs
@@ -1,9 +1,9 @@
-/************************************************/
-/* */
-/* Copyright (c) 2018 - 2021 monitor1394 */
-/* https://github.com/monitor1394 */
-/* */
-/************************************************/
+/******************************************/
+/* */
+/* Copyright (c) 2020 monitor1394 */
+/* https://github.com/monitor1394 */
+/* */
+/******************************************/
using System.Collections.Generic;
using UnityEngine;
@@ -20,7 +20,7 @@ namespace XUGL
private Vector3 m_LeftTopPos = Vector3.zero;
private Color32 m_BackgroundColor = new Color32(224, 224, 224, 255);
private Color32 m_DrawColor = new Color32(255, 132, 142, 255);
- private float[] m_BorderRadius = new float[] { 2, 2, 2, 2 };
+ private float[] m_BorderRadius = new float[] { 5, 5, 10, 10 };
protected override void Awake()
{
@@ -41,7 +41,7 @@ namespace XUGL
//背景边框
UGL.DrawSquare(vh, m_Center, m_Width / 2, m_BackgroundColor);
- UGL.DrawBorder(vh, m_Center, m_Width, m_Height, 10, Color.green, 0, m_BorderRadius);
+ UGL.DrawBorder(vh, m_Center, m_Width, m_Height, 40, Color.green, Color.red, 0, m_BorderRadius,false,1);
//点
UGL.DrawCricle(vh, m_LeftTopPos + new Vector3(20, -20), 10, m_DrawColor);
diff --git a/Assets/XCharts/Runtime/XUGL/UGLHelper.cs b/Assets/XCharts/Runtime/XUGL/UGLHelper.cs
index b3119c0b..49be2332 100644
--- a/Assets/XCharts/Runtime/XUGL/UGLHelper.cs
+++ b/Assets/XCharts/Runtime/XUGL/UGLHelper.cs
@@ -1,9 +1,9 @@
-/************************************************/
-/* */
-/* Copyright (c) 2018 - 2021 monitor1394 */
-/* https://github.com/monitor1394 */
-/* */
-/************************************************/
+/******************************************/
+/* */
+/* Copyright (c) 2020 monitor1394 */
+/* https://github.com/monitor1394 */
+/* */
+/******************************************/
using System.Collections.Generic;
using UnityEngine;