LineChart增加stepType实现`阶梯线图

This commit is contained in:
monitor1394
2019-06-01 08:11:43 +08:00
parent b9a2b12c38
commit 4bddd4e7c5
6 changed files with 6026 additions and 41 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -13,6 +13,8 @@ namespace XCharts
SerializedProperty m_Smooth;
SerializedProperty m_SmoothStyle;
SerializedProperty m_Area;
SerializedProperty m_Step;
SerializedProperty m_StepType;
private bool m_LineModuleToggle = false;
@@ -24,6 +26,8 @@ namespace XCharts
m_Smooth = prop.FindPropertyRelative("m_Smooth");
m_SmoothStyle = prop.FindPropertyRelative("m_SmoothStyle");
m_Area = prop.FindPropertyRelative("m_Area");
m_Step = prop.FindPropertyRelative("m_Step");
m_StepType = prop.FindPropertyRelative("m_StepType");
}
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
@@ -72,6 +76,22 @@ namespace XCharts
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.width = EditorGUIUtility.labelWidth + 10;
EditorGUI.PropertyField(drawRect, m_Step);
if (m_Step.boolValue)
{
drawRect.x = EditorGUIUtility.labelWidth + 15;
EditorGUI.LabelField(drawRect, "Type");
drawRect.x = EditorGUIUtility.labelWidth + 65;
float tempWidth = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - 70;
if (tempWidth < 20) tempWidth = 20;
drawRect.width = tempWidth;
EditorGUI.PropertyField(drawRect, m_StepType, GUIContent.none);
drawRect.x = pos.x;
drawRect.width = pos.width;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Area);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
--EditorGUI.indentLevel;
@@ -82,7 +102,7 @@ namespace XCharts
{
if (m_LineModuleToggle)
{
return 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
return 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
}
else
{

View File

@@ -174,15 +174,15 @@ namespace XCharts
}
m_Tooltip.UpdateContentText(sb.ToString());
}
if(m_XAxis.type == Axis.AxisType.Value)
if (m_XAxis.type == Axis.AxisType.Value)
{
float hig = (maxValue - minValue) * (m_Tooltip.pointerPos.x - zeroX) / coordinateWid;
m_Tooltip.UpdateLabelText(hig.ToString("f2"),tempAxis.GetData(index));
m_Tooltip.UpdateLabelText(hig.ToString("f2"), tempAxis.GetData(index));
float splitWidth = m_YAxis.GetSplitWidth(coordinateHig);
float py = zeroY + (m_Tooltip.dataIndex - 1) * splitWidth
+ (m_YAxis.boundaryGap ? splitWidth / 2 : 0);
Vector2 xLabelPos = new Vector2(m_Tooltip.pointerPos.x,coordinateY- 4 * m_Coordinate.tickness);
Vector2 yLabelPos = new Vector2(coordinateX - 6 * m_Coordinate.tickness,py);
Vector2 xLabelPos = new Vector2(m_Tooltip.pointerPos.x, coordinateY - 4 * m_Coordinate.tickness);
Vector2 yLabelPos = new Vector2(coordinateX - 6 * m_Coordinate.tickness, py);
m_Tooltip.UpdateLabelPos(xLabelPos, yLabelPos);
}
else
@@ -196,7 +196,7 @@ namespace XCharts
Vector2 yLabelPos = new Vector2(coordinateX - 4 * m_Coordinate.tickness, m_Tooltip.pointerPos.y);
m_Tooltip.UpdateLabelPos(xLabelPos, yLabelPos);
}
var pos = m_Tooltip.GetContentPos();
if (pos.x + m_Tooltip.width > chartWidth)

View File

@@ -5,13 +5,20 @@ namespace XCharts
[System.Serializable]
public class Line
{
public enum StepType
{
Start,
Middle,
End
}
[SerializeField] private float m_Tickness;
[SerializeField] private bool m_Point;
[SerializeField] private float m_PointWidth;
[SerializeField] private bool m_Smooth;
[SerializeField] [Range(1f, 10f)] private float m_SmoothStyle;
[SerializeField] private bool m_Area;
[SerializeField] private Color m_AreaColor;
[SerializeField] private bool m_Step;
[SerializeField] private StepType m_StepType;
public float tickness { get { return m_Tickness; } set { m_Tickness = value; } }
public bool point { get { return m_Point; } set { m_Point = value; } }
@@ -19,7 +26,8 @@ namespace XCharts
public bool smooth { get { return m_Smooth; } set { m_Smooth = value; } }
public float smoothStyle { get { return m_SmoothStyle; } set { m_SmoothStyle = value; } }
public bool area { get { return m_Area; } set { m_Area = value; } }
public Color areaColor { get { return m_AreaColor; } set { m_AreaColor = value; } }
public bool step { get { return m_Step; } set { m_Step = value; } }
public StepType stepTpe { get { return m_StepType; } set { m_StepType = value; } }
public static Line defaultLine
{
@@ -32,7 +40,9 @@ namespace XCharts
m_PointWidth = 2.5f,
m_Smooth = false,
m_SmoothStyle = 2f,
m_Area = false
m_Area = false,
m_Step = false,
m_StepType = StepType.Middle
};
return line;
}

View File

@@ -104,7 +104,56 @@ namespace XCharts
if (i > 0)
{
if (m_Line.smooth)
if (m_Line.step)
{
Vector2 middle1, middle2;
switch (m_Line.stepTpe)
{
case Line.StepType.Start:
middle1 = new Vector2(lp.x, np.y + m_Line.tickness);
middle2 = new Vector2(lp.x - m_Line.tickness, np.y);
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
if (m_Line.area)
{
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
ChartHelper.DrawPolygon(vh, new Vector2(middle1.x, zeroY), middle1, np,
new Vector2(np.x, zeroY), areaColor);
}
break;
case Line.StepType.Middle:
middle1 = new Vector2((lp.x + np.x) / 2 + m_Line.tickness, lp.y);
middle2 = new Vector2((lp.x + np.x) / 2 - m_Line.tickness, np.y);
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
ChartHelper.DrawLine(vh, new Vector2(middle1.x - m_Line.tickness, middle1.y),
new Vector2(middle2.x + m_Line.tickness, middle2.y), m_Line.tickness, color);
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
if (m_Line.area)
{
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp, middle1,
new Vector2(middle1.x, zeroY), areaColor);
ChartHelper.DrawPolygon(vh, new Vector2(middle2.x + 2 * m_Line.tickness, zeroY),
new Vector2(middle2.x + 2 * m_Line.tickness, middle2.y), np,
new Vector2(np.x, zeroY), areaColor);
}
break;
case Line.StepType.End:
middle1 = new Vector2(np.x + m_Line.tickness, lp.y);
middle2 = new Vector2(np.x, lp.y);
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
if (m_Line.area)
{
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp,
new Vector2(middle1.x - m_Line.tickness, middle1.y),
new Vector2(middle1.x - m_Line.tickness, zeroY), areaColor);
}
break;
}
}
else if (m_Line.smooth)
{
var list = ChartHelper.GetBezierList(lp, np, m_Line.smoothStyle);
Vector3 start, to;
@@ -121,9 +170,9 @@ namespace XCharts
Vector3 anp = new Vector3(to.x, to.y - m_Line.tickness);
Vector3 tnp = serieCount > 0 ?
(smoothPointCount > lastSmoothPoints.Count - 1 ?
new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 1].x,
new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 1].x,
lastSmoothPoints[lastSmoothPoints.Count - 1].y + m_Line.tickness) :
new Vector3(lastSmoothPoints[smoothPointCount].x,
new Vector3(lastSmoothPoints[smoothPointCount].x,
lastSmoothPoints[smoothPointCount].y + m_Line.tickness)) :
new Vector3(to.x, zeroY + m_Coordinate.tickness);
Vector3 tlp = serieCount > 0 ?
@@ -293,7 +342,56 @@ namespace XCharts
if (i > 0)
{
if (m_Line.smooth)
if (m_Line.step)
{
Vector2 middle1, middle2;
switch (m_Line.stepTpe)
{
case Line.StepType.Start:
middle1 = new Vector2(np.x, lp.y);
middle2 = new Vector2(np.x, lp.y - m_Line.tickness);
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
if (m_Line.area)
{
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, middle1.y), middle1, np,
new Vector2(zeroX, np.y), areaColor);
}
break;
case Line.StepType.Middle:
middle1 = new Vector2(lp.x, (lp.y + np.y) / 2 + m_Line.tickness);
middle2 = new Vector2(np.x, (lp.y + np.y) / 2 - m_Line.tickness);
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
ChartHelper.DrawLine(vh, new Vector2(middle1.x, middle1.y - m_Line.tickness),
new Vector2(middle2.x, middle2.y + m_Line.tickness), m_Line.tickness, color);
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
if (m_Line.area)
{
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, lp.y), lp, middle1,
new Vector2(zeroX, middle1.y), areaColor);
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, middle2.y + 2 * m_Line.tickness),
new Vector2(middle2.x, middle2.y + 2 * m_Line.tickness), np,
new Vector2(zeroX, np.y), areaColor);
}
break;
case Line.StepType.End:
middle1 = new Vector2(np.x, lp.y);
middle2 = new Vector2(np.x, lp.y - m_Line.tickness);
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
if (m_Line.area)
{
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, lp.y), middle1,
new Vector2(np.x, np.y),
new Vector2(zeroX, np.y), areaColor);
}
break;
}
}
else if (m_Line.smooth)
{
var list = ChartHelper.GetBezierListVertical(lp, np, m_Line.smoothStyle);
Vector3 start, to;
@@ -410,8 +508,8 @@ namespace XCharts
ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipFlagAreaColor);
if (m_Tooltip.crossLabel)
{
sp = new Vector2(m_Tooltip.pointerPos.x,zeroY);
ep = new Vector2(m_Tooltip.pointerPos.x,zeroY + coordinateHig);
sp = new Vector2(m_Tooltip.pointerPos.x, zeroY);
ep = new Vector2(m_Tooltip.pointerPos.x, zeroY + coordinateHig);
DrawSplitLine(vh, false, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
}
}

View File

@@ -21,8 +21,10 @@ UGUI图表库风格参考了[`ECharts`](https://www.echartsjs.com/examples/#c
6. 折线图堆叠+图例
7. 堆叠区域图
8. 面积图
9. 动态数据
10. 大数据量面积图
9. 阶梯线图
10. 阶梯线图+区域填充
11. 动态数据
12. 大数据量面积图
* 柱状图
1. 基础柱状图
2. 负数数值轴+自定义最大最小刻度
@@ -47,6 +49,7 @@ UGUI图表库风格参考了[`ECharts`](https://www.echartsjs.com/examples/#c
# 更新日志
* 2019.06.01`LineChart`增加`stepType`实现`阶梯线图`
* 2019.05.29`BarChart`增加`InSameBar`实现非堆叠同柱
* 2019.05.29`Tooltip`增加`crossLabel`显示十字准星指示器
* 2019.05.24)增加`堆叠区域图`