增加SerieDataItemStyleEmphasis可单独配置数据项样式的支持

This commit is contained in:
monitor1394
2020-03-17 08:37:48 +08:00
parent cc065edb0f
commit b6c206c299
28 changed files with 517 additions and 293 deletions

View File

@@ -1,6 +1,9 @@
# 更新日志
* (2020.03.17) 增加`SerieData``ItemStyle``Emphasis`可单独配置数据项样式的支持
* (2020.03.15) 重构`EmptyCricle`类型的`Symbol`边宽取自`ItemStyle``borderWidth`
* (2020.03.15) 重构`SerieSymbol`,去掉`color``opacity`参数,用`ItemStyle`参数代替
* (2020.03.14) 发布`v1.3.1`版本
* (2020.03.14) 修复`LineChart`开启`ingore`时部分数据可能绘制异常的问题
* (2020.03.13) 修复`LineChart``label`偏移显示异常的问题

View File

@@ -42,14 +42,14 @@ namespace XCharts
void AddData()
{
chart.ClearData();
int count = Random.Range(5, 20);
int count = Random.Range(5, 100);
for (int i = 0; i < count; i++)
{
(chart as CoordinateChart).AddXAxisData("x" + i);
if (Random.Range(1, 3) == 2)
chart.AddData(0, Random.Range(10, 200));
chart.AddData(0, Random.Range(-110, 200));
else
chart.AddData(0, Random.Range(10, 100));
chart.AddData(0, Random.Range(-100, 100));
}
}
}

View File

@@ -22,6 +22,7 @@ namespace XCharts
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
SerializedProperty m_ToColor = prop.FindPropertyRelative("m_ToColor");
SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor");
SerializedProperty m_BackgroundWidth = prop.FindPropertyRelative("m_BackgroundWidth");
SerializedProperty m_CenterColor = prop.FindPropertyRelative("m_CenterColor");
@@ -37,6 +38,8 @@ namespace XCharts
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_ToColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BackgroundColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BackgroundWidth);
@@ -62,7 +65,7 @@ namespace XCharts
float height = 0;
if (ChartEditorHelper.IsToggle(m_ItemStyleToggle, prop))
{
height += 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
height += 11 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
}
else
{

View File

@@ -171,12 +171,8 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Clip);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
EditorGUI.PropertyField(drawRect, m_ItemStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle);
EditorGUI.PropertyField(drawRect, m_AreaStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle);
EditorGUI.PropertyField(drawRect, m_Label);
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.PropertyField(drawRect, m_Emphasis);
@@ -223,8 +219,12 @@ namespace XCharts
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
EditorGUI.PropertyField(drawRect, m_ItemStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle);
EditorGUI.PropertyField(drawRect, m_AreaStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle);
EditorGUI.PropertyField(drawRect, m_Emphasis);
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
break;
case SerieType.Scatter:
case SerieType.EffectScatter:
@@ -232,6 +232,8 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
EditorGUI.PropertyField(drawRect, m_ItemStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle);
EditorGUI.PropertyField(drawRect, m_Label);
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.PropertyField(drawRect, m_Emphasis);
@@ -292,7 +294,7 @@ namespace XCharts
{
EditorGUI.indentLevel++;
float nameWid = 42;
float nameWid = 45;
EditorGUI.PropertyField(new Rect(drawRect.x, drawRect.y, pos.width - 2 * nameWid - 2, pos.height), m_DataDimension);
var nameRect = new Rect(pos.width - 2 * nameWid + 14, drawRect.y, nameWid, pos.height);
if (GUI.Button(nameRect, new GUIContent("Name")))
@@ -300,7 +302,7 @@ namespace XCharts
m_ShowDataName.boolValue = !m_ShowDataName.boolValue;
}
var iconRect = new Rect(pos.width - nameWid + 14, drawRect.y, nameWid, pos.height);
if (GUI.Button(iconRect, new GUIContent("Other")))
if (GUI.Button(iconRect, new GUIContent("More...")))
{
m_ShowDataIcon.boolValue = !m_ShowDataIcon.boolValue;
}
@@ -421,11 +423,21 @@ namespace XCharts
var m_Icon = serieData.FindPropertyRelative("m_IconStyle");
var m_EnableLabel = serieData.FindPropertyRelative("m_EnableLabel");
var m_Label = serieData.FindPropertyRelative("m_Label");
var m_EnableItemStyle = serieData.FindPropertyRelative("m_EnableItemStyle");
var m_ItemStyle = serieData.FindPropertyRelative("m_ItemStyle");
var m_EnableEmphasis = serieData.FindPropertyRelative("m_EnableEmphasis");
var m_Emphasis = serieData.FindPropertyRelative("m_Emphasis");
EditorGUI.PropertyField(drawRect, m_Icon);
drawRect.y += EditorGUI.GetPropertyHeight(m_Icon);
EditorGUI.PropertyField(drawRect, m_Label);
ChartEditorHelper.MakeBool(ref drawRect, m_EnableLabel, 1, "(enable)");
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.PropertyField(drawRect, m_ItemStyle);
ChartEditorHelper.MakeBool(ref drawRect, m_EnableItemStyle, 1, "(enable)");
drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle);
EditorGUI.PropertyField(drawRect, m_Emphasis);
ChartEditorHelper.MakeBool(ref drawRect, m_EnableEmphasis, 1, "(enable)");
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
EditorGUI.indentLevel -= 2;
}
@@ -457,9 +469,8 @@ namespace XCharts
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
case SerieType.Bar:
height += 17 * EditorGUIUtility.singleLineHeight + 16 * EditorGUIUtility.standardVerticalSpacing;
height += 16 * EditorGUIUtility.singleLineHeight + 15 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
@@ -479,9 +490,10 @@ namespace XCharts
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
break;
case SerieType.Radar:
height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
@@ -490,6 +502,7 @@ namespace XCharts
case SerieType.EffectScatter:
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
@@ -531,9 +544,10 @@ namespace XCharts
for (int i = 0; i < num; i++)
{
var item = m_Data.GetArrayElementAtIndex(i);
//height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_IconStyle"));
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_ItemStyle"));
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_Emphasis"));
}
}
}

View File

@@ -27,8 +27,6 @@ namespace XCharts
SerializedProperty m_DataIndex = prop.FindPropertyRelative("m_DataIndex");
SerializedProperty m_DataScale = prop.FindPropertyRelative("m_DataScale");
SerializedProperty m_SelectedDataScale = prop.FindPropertyRelative("m_SelectedDataScale");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
SerializedProperty m_Opacity = prop.FindPropertyRelative("m_Opacity");
SerializedProperty m_StartIndex = prop.FindPropertyRelative("m_StartIndex");
SerializedProperty m_Interval = prop.FindPropertyRelative("m_Interval");
SerializedProperty m_ForceShowLast = prop.FindPropertyRelative("m_ForceShowLast");
@@ -64,10 +62,6 @@ namespace XCharts
case SerieSymbolSizeType.Callback:
break;
}
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Opacity);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_StartIndex);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Interval);
@@ -87,13 +81,13 @@ namespace XCharts
switch (sizeType)
{
case SerieSymbolSizeType.Custom:
return 10 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
return 8 * EditorGUIUtility.singleLineHeight + 8 * EditorGUIUtility.standardVerticalSpacing;
case SerieSymbolSizeType.FromData:
return 11 * EditorGUIUtility.singleLineHeight + 11 * EditorGUIUtility.standardVerticalSpacing;
return 9 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
case SerieSymbolSizeType.Callback:
return 10 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
return 8 * EditorGUIUtility.singleLineHeight + 8 * EditorGUIUtility.standardVerticalSpacing;
}
return 10 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
return 8 * EditorGUIUtility.singleLineHeight + 8 * EditorGUIUtility.standardVerticalSpacing;
}
else
{

View File

@@ -117,8 +117,9 @@ public class ChartEditorHelper
float defaultWidth = drawRect.width;
float defaultX = drawRect.x;
drawRect.width = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15;
drawRect.width = EditorGUIUtility.labelWidth - 5;
var displayName = string.IsNullOrEmpty(moduleName) ? prop.displayName : moduleName;
toggle = EditorGUI.Foldout(drawRect, toggle, displayName, bold ? foldoutStyle : EditorStyles.foldout);
if (moduleToggle[key] != toggle)
{

View File

@@ -1,24 +1,22 @@
# XCharts
A powerful, easy-to-use, configurable charting and data visualization library for Unity.
A powerful, easy-to-use, configurable charting and data visualization library for Unity. Support line charts, bar charts, pie charts, radar charts, scatter charts, heatmaps, gauge, ring charts and other common charts.
一款基于`UGUI`的功能强大、易用、参数可配置的数据可视化图表插件。支持折线图、柱状图、饼图、雷达图、散点图、热力图、仪表盘、环形图等常见图表。
## Features
## 特性
* Rich built-in examples and templates, parameter visualization configuration, effect real-time preview, pure code drawing.
* Support line charts, bar charts, pie charts, radar charts, scatter charts, heatmaps, gauge charts, ring charts and other common charts.
* Support line graph, curve graph, area graph, step graph, etc.
* Support parallel bar chart, stack bar chart, stack percentage bar chart, zebra bar chart, etc.
* Support for ring chart, rose chart and other pie chart.
* Support broken line graph - bar graph, scatter graph - broken line graph, etc.
* Support solid line, curve, ladder line, dotted line, dot line, dot line, double point line and other lines.
* Support custom theme, built-in theme switching.
* support custom chart content drawing, drawing points, line, curve, triangle, quadrilateral, circle, ring, sector, border, arrow and other drawing API.
* support interactive operations such as data filtering, view zooming and detail display on PC and mobile terminals.
* support 10,000-level big data rendering.
* 内置丰富示例和模板,参数可视化配置,效果实时预览,纯代码绘制。
* 支持折线图、柱状图、饼图、雷达图、散点图、热力图、仪表盘、环形图等常见图表。
* 支持直线图、曲线图、面积图、阶梯线图等折线图。
* 支持并列柱图、堆叠柱图、堆积百分比柱图、斑马柱图等柱状图。
* 支持环形图、玫瑰图等饼图。
* 支持折线图—柱状图、散点图-折线图等组合图。
* 支持实线、曲线、阶梯线、虚线、点线、点划线、双点划线等线条。
* 支持自定义主题,内置主题切换。
* 支持自定义图表内容绘制提供绘制点、直线、曲线、三角形、四边形、圆形、环形、扇形、边框、箭头等绘图API。
* 支持PC端和手机端上的数据筛选、视图缩放、细节展示等交互操作。
* 支持万级大数据绘制。
## 使用
## Usage
* 本项目在`Unity 2018.3.14f1``.Net 3.5`下开发,在 `Unity 5``Unity 2017``Unity 2019`上测试正常。理论上可运行于任何支持`UGUI``Unity`版本。
* 通过下载源码或`unitypackage`包导入到你的项目中。如果你是`2018.3`及以上版本,强烈建议通过`Package Manager``Git`来导入包:

View File

@@ -1413,72 +1413,9 @@ namespace XCharts
}
}
internal Color GetAreaColor(ThemeInfo theme, int index, bool highlight)
{
var color = areaStyle.color != Color.clear ? areaStyle.color : (Color)theme.GetColor(index);
if (highlight)
{
if (areaStyle.highlightColor != Color.clear) color = areaStyle.highlightColor;
else color *= color;
}
color.a *= areaStyle.opacity;
return color;
}
internal Color GetAreaToColor(ThemeInfo theme, int index, bool highlight)
{
if (areaStyle.toColor != Color.clear)
{
var color = areaStyle.toColor;
if (highlight)
{
if (areaStyle.highlightToColor != Color.clear) color = areaStyle.highlightToColor;
else color *= color;
}
color.a *= areaStyle.opacity;
return color;
}
else
{
return GetAreaColor(theme, index, highlight);
}
}
internal Color GetLineColor(ThemeInfo theme, int index, bool highlight)
{
if (lineStyle.color != Color.clear)
{
var color = lineStyle.color;
if (highlight) color *= color;
color.a *= lineStyle.opacity;
return color;
}
else
{
var color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a *= lineStyle.opacity;
return color;
}
}
internal Color GetSymbolColor(ThemeInfo theme, int index, bool highlight)
{
if (symbol.color != Color.clear)
{
var color = symbol.color;
if (highlight) color *= color;
color.a *= symbol.opacity;
return color;
}
else
{
var color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a *= symbol.opacity;
return color;
}
}
internal float GetBarWidth(float categoryWidth)
{

View File

@@ -36,6 +36,7 @@ namespace XCharts
}
[SerializeField] private bool m_Show = false;
[SerializeField] private Color m_Color;
[SerializeField] private Color m_ToColor;
[SerializeField] private Color m_BackgroundColor;
[SerializeField] private float m_BackgroundWidth;
[SerializeField] private Color m_CenterColor;
@@ -62,6 +63,15 @@ namespace XCharts
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color, start color to toColor.
/// 渐变色的终点颜色。
/// </summary>
public Color toColor
{
get { return m_ToColor; }
set { if (PropertyUtility.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项背景颜色。
/// </summary>
public Color backgroundColor
@@ -138,6 +148,11 @@ namespace XCharts
return borderWidth != 0 && borderColor != Color.clear;
}
public Color GetColor()
{
var color = m_Color;
color.a *= m_Opacity;
return color;
}
}
}

View File

@@ -112,32 +112,11 @@ namespace XCharts
this.width = width;
}
public void Copy(LineStyle other)
public Color GetColor()
{
m_Show = other.show;
m_Type = other.type;
m_Color = other.color;
m_Width = other.width;
m_Opacity = other.opacity;
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (LineStyle)obj;
return m_Show == other.show &&
m_Type == other.type &&
m_Width == other.width &&
m_Opacity == other.opacity &&
ChartHelper.IsValueEqualsColor(m_Color, other.color);
}
public override int GetHashCode()
{
return base.GetHashCode();
var color = m_Color;
color.a *= m_Opacity;
return color;
}
}
}

View File

@@ -26,6 +26,10 @@ namespace XCharts
[SerializeField] private IconStyle m_IconStyle = new IconStyle();
[SerializeField] private bool m_EnableLabel = false;
[SerializeField] private SerieLabel m_Label = new SerieLabel();
[SerializeField] private bool m_EnableItemStyle = false;
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
[SerializeField] private bool m_EnableEmphasis = false;
[SerializeField] private Emphasis m_Emphasis = new Emphasis();
[SerializeField] private List<float> m_Data = new List<float>();
private bool m_Show = true;
@@ -68,6 +72,22 @@ namespace XCharts
/// </summary>
public SerieLabel label { get { return m_Label; } set { m_Label = value; } }
/// <summary>
/// 是否启用单个数据项的样式。
/// </summary>
public bool enableItemStyle { get { return m_EnableItemStyle; } set { m_EnableItemStyle = value; } }
/// <summary>
/// 单个数据项的样式设置。
/// </summary>
public ItemStyle itemStyle { get { return m_ItemStyle; } set { m_ItemStyle = value; } }
/// <summary>
/// 是否启用单个数据项的高亮样式。
/// </summary>
public bool enableEmphasis{ get { return m_EnableEmphasis; } set { m_EnableEmphasis = value; } }
/// <summary>
/// 单个数据项的高亮样式设置。
/// </summary>
public Emphasis emphasis { get { return m_Emphasis; } set { m_Emphasis = value; } }
/// <summary>
/// An arbitrary dimension data list of data item.
/// 可指定任意维数的数值列表。
/// </summary>
@@ -336,11 +356,5 @@ namespace XCharts
{
return labelText != null;
}
public SerieLabel GetSerieLabel(SerieLabel parentLabel)
{
if (enableLabel) return label;
else return parentLabel;
}
}
}

View File

@@ -98,7 +98,7 @@ namespace XCharts
[SerializeField] private float m_LineWidth = 1.0f;
[SerializeField] private float m_LineLength1 = 25f;
[SerializeField] private float m_LineLength2 = 15f;
[SerializeField] private bool m_Border = true;
[SerializeField] private bool m_Border = false;
[SerializeField] private float m_BorderWidth = 0.5f;
[SerializeField] private Color m_BorderColor = Color.grey;
[SerializeField] private bool m_ForceENotation = false;

View File

@@ -176,24 +176,6 @@ namespace XCharts
set { if (PropertyUtility.SetClass(ref m_SelectedSizeCallback, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of symbol,default from serie.
/// 标记图形的颜色,默认和系列一致。
/// </summary>
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// the opacity of color.
/// 图形标记的透明度。
/// </summary>
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// the index start to show symbol.
/// 开始显示图形标记的索引。
/// </summary>

View File

@@ -49,7 +49,7 @@ namespace XCharts
if (m_UpdateLabelText)
{
m_UpdateLabelText = false;
SerieLabelHelper.UpdateLabelText(m_Series,m_ThemeInfo);
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo);
UpdateAxisLabel();
}
}
@@ -207,6 +207,7 @@ namespace XCharts
{
if (!serie.gaugePointer.show) return;
var pointerColor = serie.gaugeAxis.GetPointerColor(m_ThemeInfo, serie.index, currAngle, serie.itemStyle);
var pointerToColor = serie.itemStyle.toColor != Color.clear ? serie.itemStyle.toColor : pointerColor;
var len = serie.gaugePointer.length < 1 && serie.gaugePointer.length > -1 ?
serie.runtimeInsideRadius * serie.gaugePointer.length :
serie.gaugePointer.length;
@@ -214,7 +215,8 @@ namespace XCharts
var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 180, serie.gaugePointer.width);
var p3 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle - 90, serie.gaugePointer.width / 2);
var p4 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 90, serie.gaugePointer.width / 2);
ChartDrawer.DrawPolygon(vh, p1, p3, p2, p4, pointerColor);
ChartDrawer.DrawTriangle(vh, p2, p3, p1, pointerColor, pointerColor, pointerToColor);
ChartDrawer.DrawTriangle(vh, p4, p2, p1, pointerColor, pointerColor, pointerToColor);
}
private void DrawLineStyle(VertexHelper vh, Serie serie)

View File

@@ -0,0 +1,15 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
internal static class SerieDataHelper
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0de4f692b6e2d4cdd9ef1946bffa895f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -11,38 +11,98 @@ namespace XCharts
{
internal static class SerieHelper
{
internal static Color GetItemBackgroundColor(Serie serie, ThemeInfo theme, int index, bool highlight)
internal static Color GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
{
if (serie.itemStyle.backgroundColor != Color.clear)
var itemStyle = GetItemStyle(serie, serieData);
var color = Color.clear;
if (highlight)
{
var color = serie.itemStyle.backgroundColor;
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && itemStyleEmphasis.backgroundColor != Color.clear)
{
color = itemStyleEmphasis.backgroundColor;
color.a *= itemStyleEmphasis.opacity;
return color;
}
}
if (itemStyle.backgroundColor != Color.clear)
{
color = itemStyle.backgroundColor;
if (highlight) color *= color;
color.a *= serie.itemStyle.opacity;
color.a *= itemStyle.opacity;
return color;
}
else
{
var color = (Color)theme.GetColor(index);
color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a = 0.2f;
return color;
}
}
internal static Color GetItemColor(Serie serie, ThemeInfo theme, int index, bool highlight)
internal static Color GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
{
if (serie.itemStyle.color != Color.clear)
var itemStyle = GetItemStyle(serie, serieData);
if (highlight)
{
var color = serie.itemStyle.color;
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && itemStyleEmphasis.color != Color.clear)
{
var color = itemStyleEmphasis.color;
color.a *= itemStyleEmphasis.opacity;
return color;
}
}
if (itemStyle.color != Color.clear)
{
var color = itemStyle.color;
if (highlight) color *= color;
color.a *= serie.itemStyle.opacity;
color.a *= itemStyle.opacity;
return color;
}
else
{
var color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a *= serie.itemStyle.opacity;
color.a *= itemStyle.opacity;
return color;
}
}
internal static Color GetItemToColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
{
var itemStyle = GetItemStyle(serie, serieData, highlight);
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && itemStyleEmphasis.toColor != Color.clear)
{
var color = itemStyleEmphasis.toColor;
color.a *= itemStyleEmphasis.opacity;
return color;
}
}
if (itemStyle == null) itemStyle = serieData.itemStyle;
if (itemStyle.toColor != Color.clear)
{
var color = itemStyle.toColor;
if (highlight) color *= color;
color.a *= itemStyle.opacity;
return color;
}
if (itemStyle.color != Color.clear)
{
var color = itemStyle.color;
if (highlight) color *= color;
color.a *= itemStyle.opacity;
return color;
}
else
{
var color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a *= itemStyle.opacity;
return color;
}
}
@@ -72,5 +132,105 @@ namespace XCharts
return false;
}
}
public static ItemStyle GetItemStyle(Serie serie, SerieData serieData, bool highlight = false)
{
if (highlight)
{
var style = GetItemStyleEmphasis(serie, serieData);
if (style == null) return GetItemStyle(serie, serieData, false);
else return style;
}
else if (serieData.enableItemStyle) return serieData.itemStyle;
else return serie.itemStyle;
}
public static ItemStyle GetItemStyleEmphasis(Serie serie, SerieData serieData)
{
if (serieData != null && serieData.enableEmphasis && serieData.emphasis.show)
return serieData.emphasis.itemStyle;
else if (serie.emphasis.show) return serie.emphasis.itemStyle;
else return null;
}
public static SerieLabel GetSerieLabel(Serie serie, SerieData serieData, bool highlight = false)
{
if (highlight)
{
if (serieData.enableEmphasis && serieData.emphasis.show) return serieData.emphasis.label;
else if (serie.emphasis.show) return serie.emphasis.label;
else return serie.label;
}
else
{
if (serieData.enableLabel) return serieData.label;
else return serie.label;
}
}
public static Color GetAreaColor(Serie serie, ThemeInfo theme, int index, bool highlight)
{
var areaStyle = serie.areaStyle;
var color = areaStyle.color != Color.clear ? areaStyle.color : (Color)theme.GetColor(index);
if (highlight)
{
if (areaStyle.highlightColor != Color.clear) color = areaStyle.highlightColor;
else color *= color;
}
color.a *= areaStyle.opacity;
return color;
}
public static Color GetAreaToColor(Serie serie, ThemeInfo theme, int index, bool highlight)
{
var areaStyle = serie.areaStyle;
if (areaStyle.toColor != Color.clear)
{
var color = areaStyle.toColor;
if (highlight)
{
if (areaStyle.highlightToColor != Color.clear) color = areaStyle.highlightToColor;
else color *= color;
}
color.a *= areaStyle.opacity;
return color;
}
else
{
return GetAreaColor(serie, theme, index, highlight);
}
}
public static Color GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight)
{
var color = Color.clear;
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, null);
if (itemStyleEmphasis != null && itemStyleEmphasis.color != Color.clear)
{
color = itemStyleEmphasis.color;
color.a *= itemStyleEmphasis.opacity;
return color;
}
}
if (serie.lineStyle.color != Color.clear) color = serie.lineStyle.GetColor();
else if (serie.itemStyle.color != Color.clear) color = serie.itemStyle.GetColor();
if (color == Color.clear)
{
color = (Color)theme.GetColor(index);
color.a = serie.lineStyle.opacity;
}
if (highlight) color *= color;
return color;
}
public static float GetSymbolBorder(Serie serie, SerieData serieData, bool highlight)
{
var itemStyle = GetItemStyle(serie, serieData, highlight);
if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth;
else if (serie.lineStyle.width != 0) return serie.lineStyle.width;
else return 1;
}
}
}

View File

@@ -70,6 +70,20 @@ namespace XCharts
}
}
public static void ResetLabel(SerieData serieData, SerieLabel label, ThemeInfo themeInfo, int colorIndex)
{
if (serieData.labelText)
{
serieData.labelText.color = label.color != Color.clear ? label.color :
(Color)themeInfo.GetColor(colorIndex);
serieData.labelText.fontSize = label.fontSize;
serieData.labelText.fontStyle = label.fontStyle;
}
}
private static void SetGaugeLabelText(Serie serie)
{
var serieData = serie.GetSerieData(0);
@@ -95,7 +109,8 @@ namespace XCharts
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.data[i];
if (serieData.IsInitLabel())
var serieLabel = SerieHelper.GetSerieLabel(serie,serieData,serieData.highlighted);
if (serieLabel.show && serieData.IsInitLabel())
{
if (!serie.show || !serieData.show)
{

View File

@@ -371,7 +371,7 @@ namespace XCharts
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
var serieLabel = serieData.GetSerieLabel(serie.label);
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
if (!serieLabel.show && j > 100) continue;
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j);
var color = Color.grey;
@@ -726,7 +726,7 @@ namespace XCharts
}
protected void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
float tickness, Vector3 pos, Color color, float gap)
float tickness, Vector3 pos, Color color, Color toColor, float gap)
{
var backgroundColor = m_ThemeInfo.backgroundColor;
var smoothness = m_Settings.cicleSmoothness;
@@ -737,55 +737,55 @@ namespace XCharts
case SerieSymbolType.Circle:
if (gap > 0)
{
ChartDrawer.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, color, smoothness);
ChartDrawer.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, color, toColor, smoothness);
}
else
{
ChartDrawer.DrawCricle(vh, pos, symbolSize, color, smoothness);
ChartDrawer.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness);
}
break;
case SerieSymbolType.EmptyCircle:
if (gap > 0)
{
ChartDrawer.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness);
ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, backgroundColor, smoothness);
ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, toColor, backgroundColor, smoothness);
}
else
{
ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, backgroundColor, smoothness);
ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, toColor, backgroundColor, smoothness);
}
break;
case SerieSymbolType.Rect:
if (gap > 0)
{
ChartDrawer.DrawPolygon(vh, pos, symbolSize + gap, backgroundColor);
ChartDrawer.DrawPolygon(vh, pos, symbolSize, color);
ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor);
}
else
{
ChartDrawer.DrawPolygon(vh, pos, symbolSize, color);
ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor);
}
break;
case SerieSymbolType.Triangle:
if (gap > 0)
{
ChartDrawer.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor);
ChartDrawer.DrawTriangle(vh, pos, symbolSize, color);
ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor);
}
else
{
ChartDrawer.DrawTriangle(vh, pos, symbolSize, color);
ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor);
}
break;
case SerieSymbolType.Diamond:
if (gap > 0)
{
ChartDrawer.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor);
ChartDrawer.DrawDiamond(vh, pos, symbolSize, color);
ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor);
}
else
{
ChartDrawer.DrawDiamond(vh, pos, symbolSize, color);
ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor);
}
break;
}
@@ -818,13 +818,14 @@ namespace XCharts
protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)
{
var labelHalfWid = serieData.GetLabelWidth() / 2;
var labelHalfHig = serieData.GetLabelHeight() / 2;
var serieLabel = serieData.GetSerieLabel(serie.label);
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
if (!serieLabel.show) return;
var invert = serie.type == SerieType.Line
&& SerieHelper.IsDownPoint(serie, serieData.index)
&& !serie.areaStyle.show;
var centerPos = serieData.labelPosition + serieLabel.offset * (invert ? -1 : 1);
var labelHalfWid = serieData.GetLabelWidth() / 2;
var labelHalfHig = serieData.GetLabelHeight() / 2;
var p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
var p2 = new Vector3(centerPos.x + labelHalfWid, centerPos.y + labelHalfHig);
var p3 = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig);

View File

@@ -1426,32 +1426,16 @@ namespace XCharts
{
var serie = m_Series.GetSerie(n);
if (!serie.show) continue;
var zeroPos = Vector3.zero;
var lastStackSerie = m_Series.GetLastStackSerie(n);
if (serie.type == SerieType.Bar)
{
if (serie.label.position == SerieLabel.Position.Bottom || serie.label.position == SerieLabel.Position.Center)
{
if (isYAxis)
{
var xAxis = m_XAxises[serie.axisIndex];
zeroPos = new Vector3(coordinateX + xAxis.runtimeZeroXOffset, coordinateY);
}
else
{
var yAxis = m_YAxises[serie.axisIndex];
zeroPos = new Vector3(coordinateX, coordinateY + yAxis.runtimeZeroYOffset);
}
}
}
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
var serieLabel = SerieHelper.GetSerieLabel(serie,serieData,serieData.highlighted);
serieData.index = j;
if ((serie.label.show || serieData.iconStyle.show))
if ((serieLabel.show || serieData.iconStyle.show))
{
var pos = serie.dataPoints[j];
var isIngore = ChartHelper.IsIngore(pos);
if (isIngore)
{
@@ -1465,8 +1449,26 @@ namespace XCharts
case SerieType.Line:
break;
case SerieType.Bar:
var zeroPos = Vector3.zero;
var lastStackSerie = m_Series.GetLastStackSerie(n);
if (serie.type == SerieType.Bar)
{
if (serieLabel.position == SerieLabel.Position.Bottom || serieLabel.position == SerieLabel.Position.Center)
{
if (isYAxis)
{
var xAxis = m_XAxises[serie.axisIndex];
zeroPos = new Vector3(coordinateX + xAxis.runtimeZeroXOffset, coordinateY);
}
else
{
var yAxis = m_YAxises[serie.axisIndex];
zeroPos = new Vector3(coordinateX, coordinateY + yAxis.runtimeZeroYOffset);
}
}
}
var bottomPos = lastStackSerie == null ? zeroPos : lastStackSerie.dataPoints[j];
switch (serie.label.position)
switch (serieLabel.position)
{
case SerieLabel.Position.Center:
@@ -1481,7 +1483,7 @@ namespace XCharts
}
m_RefreshLabel = true;
serieData.labelPosition = pos;
if (serie.label.show) DrawLabelBackground(vh, serie, serieData);
if (serieLabel.show) DrawLabelBackground(vh, serie, serieData);
}
}
else
@@ -1505,9 +1507,10 @@ namespace XCharts
if (j >= serie.dataPoints.Count) break;
var serieData = serie.data[j];
var pos = serie.dataPoints[j];
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
serieData.SetGameObjectPosition(serieData.labelPosition);
serieData.UpdateIcon();
if (serie.show && serie.label.show && serieData.canShowLabel)
if (serie.show && serieLabel.show && serieData.canShowLabel)
{
float value = 0f;
var dimension = 1;
@@ -1516,20 +1519,23 @@ namespace XCharts
dimension = m_VisualMap.enable && m_VisualMap.dimension > 0 ? m_VisualMap.dimension - 1 :
serieData.data.Count - 1;
}
SerieLabelHelper.ResetLabel(serieData, serieLabel, themeInfo, i);
value = serieData.data[dimension];
var content = "";
if (anyPercentStack && isPercentStack)
{
var tempTotal = GetSameStackTotalValue(serie.stack, j);
content = serie.label.GetFormatterContent(serie.name, serieData.name, value, tempTotal);
content = serieLabel.GetFormatterContent(serie.name, serieData.name, value, tempTotal);
}
else
{
content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
content = serieLabel.GetFormatterContent(serie.name, serieData.name, value, total);
}
serieData.SetLabelActive(value != 0 && serieData.labelPosition != Vector3.zero);
var invert = serie.type == SerieType.Line && SerieHelper.IsDownPoint(serie, j) && !serie.areaStyle.show;
serieData.SetLabelPosition(invert ? -serie.label.offset : serie.label.offset);
serieData.SetLabelPosition(invert ? -serieLabel.offset : serieLabel.offset);
if (serieData.SetLabelText(content)) RefreshChart();
}
else
@@ -1822,11 +1828,11 @@ namespace XCharts
}
protected void CheckClipAndDrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
float tickness, Vector3 pos, Color color, float gap, bool clip)
float tickness, Vector3 pos, Color color, Color toColor, float gap, bool clip)
{
if (!IsInChart(pos)) return;
if (!clip || (clip && (IsInCooridate(pos))))
DrawSymbol(vh, type, symbolSize, tickness, pos, color, gap);
DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, gap);
}
protected void CheckClipAndDrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size,

View File

@@ -48,7 +48,7 @@ namespace XCharts
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
float borderWidth = serie.itemStyle.runtimeBorderWidth;
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
@@ -56,6 +56,11 @@ namespace XCharts
seriesHig.Add(0);
}
var serieData = showData[i];
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|| serie.data[i].highlighted
|| serie.highlighted;
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight);
var borderWidth = itemStyle.runtimeBorderWidth;
serieData.canShowLabel = true;
float value = showData[i].GetCurrData(1, dataChangeDuration);
if (showData[i].IsDataChanged()) dataChanging = true;
@@ -93,13 +98,11 @@ namespace XCharts
p4 = ClampInCoordinate(p4);
top = ClampInCoordinate(top);
serie.dataPoints.Add(top);
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|| serie.data[i].highlighted
|| serie.highlighted;
if (serie.show)
{
Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
Color areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
if (serie.barType == BarType.Zebra)
{
p1 = (p4 + p1) / 2;
@@ -112,7 +115,7 @@ namespace XCharts
CheckClipAndDrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor, serie.clip);
if (borderWidth > 0)
{
var borderColor = serie.itemStyle.borderColor;
var borderColor = 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);
@@ -175,15 +178,20 @@ namespace XCharts
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
float borderWidth = serie.itemStyle.runtimeBorderWidth;
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
{
seriesHig.Add(0);
}
float value = showData[i].GetCurrData(1, dataChangeDuration);
if (showData[i].IsDataChanged()) dataChanging = true;
var serieData = showData[i];
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|| serie.data[i].highlighted
|| serie.highlighted;
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight);
var borderWidth = itemStyle.runtimeBorderWidth;
float value = serieData.GetCurrData(1, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true;
float pX = coordinateX + i * categoryWidth;
float zeroY = coordinateY + yAxis.runtimeZeroYOffset;
if (!xAxis.boundaryGap) pX -= categoryWidth / 2;
@@ -218,13 +226,11 @@ namespace XCharts
p4 = ClampInCoordinate(p4);
top = ClampInCoordinate(top);
serie.dataPoints.Add(top);
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|| serie.data[i].highlighted
|| serie.highlighted;
if (serie.show)
{
Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
Color areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
if (serie.barType == BarType.Zebra)
{
p1 = (p4 + p1) / 2;
@@ -237,7 +243,7 @@ namespace XCharts
CheckClipAndDrawPolygon(vh, ref p4, ref p1, ref p2, ref p3, areaColor, areaToColor, serie.clip);
if (borderWidth > 0)
{
var borderColor = serie.itemStyle.borderColor;
var borderColor = 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);

View File

@@ -33,14 +33,17 @@ namespace XCharts
if (serie.lineArrow.position == LineArrow.Position.End && i == count - 1) continue;
}
Vector3 p = serie.dataPoints[i];
var serieData = serie.GetSerieData(i);
if (ChartHelper.IsIngore(p)) continue;
bool highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|| serie.data[i].highlighted || serie.highlighted;
float symbolSize = highlight ? serie.symbol.selectedSize : serie.symbol.size;
var symbolColor = serie.GetSymbolColor(m_ThemeInfo, n, highlight);
var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, n, highlight);
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, n, highlight);
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, highlight);
symbolSize = serie.animation.GetSysmbolSize(symbolSize);
CheckClipAndDrawSymbol(vh, serie.symbol.type, symbolSize, serie.lineStyle.width, p, symbolColor,
serie.symbol.gap, clip);
CheckClipAndDrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, p, symbolColor,
symbolToColor, serie.symbol.gap, clip);
}
}
}
@@ -53,7 +56,7 @@ namespace XCharts
if (serie.type != SerieType.Line) continue;
if (!serie.show || !serie.lineArrow.show) continue;
if (serie.dataPoints.Count < 2) return;
Color lineColor = serie.GetLineColor(m_ThemeInfo, n, false);
Color lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, n, false);
switch (serie.lineArrow.position)
{
@@ -83,11 +86,11 @@ namespace XCharts
if (serie.animation.HasFadeOut()) return;
var showData = serie.GetDataList(m_DataZoom);
if (showData.Count <= 0) return;
Color lineColor = serie.GetLineColor(m_ThemeInfo, colorIndex, false);
Color srcAreaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, false);
Color srcAreaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, false);
Color highlightAreaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, true);
Color highlightAreaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, true);
Color lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, colorIndex, serie.highlighted);
Color srcAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, false);
Color srcAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, false);
Color highlightAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, true);
Color highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, true);
Color areaColor, areaToColor;
Vector3 lp = Vector3.zero, np = Vector3.zero, llp = Vector3.zero, nnp = Vector3.zero;
var yAxis = m_YAxises[serie.axisIndex];
@@ -475,11 +478,11 @@ namespace XCharts
Vector3 np = Vector3.zero;
Vector3 llp = Vector3.zero;
Vector3 nnp = Vector3.zero;
Color lineColor = serie.GetLineColor(m_ThemeInfo, colorIndex, false);
Color srcAreaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, false);
Color srcAreaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, false);
Color highlightAreaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, true);
Color highlightAreaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, true);
Color lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, colorIndex, serie.highlighted);
Color srcAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, false);
Color srcAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, false);
Color highlightAreaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, colorIndex, true);
Color highlightAreaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, colorIndex, true);
Color areaColor, areaToColor;
var xAxis = m_XAxises[serie.axisIndex];
var yAxis = m_YAxises[serie.axisIndex];
@@ -715,7 +718,7 @@ namespace XCharts
isStart = true;
if (stPos2 != Vector3.zero)
{
CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip);
}
}
@@ -769,7 +772,7 @@ namespace XCharts
isStart = true;
if (stPos2 != Vector3.zero)
{
CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip);
}
}

View File

@@ -17,8 +17,6 @@ namespace XCharts
if (serie.animation.HasFadeOut()) return;
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
var color = serie.symbol.color != Color.clear ? serie.symbol.color : (Color)m_ThemeInfo.GetColor(colorIndex);
color.a *= serie.symbol.opacity;
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
: serie.dataCount;
@@ -29,6 +27,10 @@ namespace XCharts
for (int n = serie.minShow; n < maxCount; n++)
{
var serieData = serie.GetDataList(m_DataZoom)[n];
var highlight = serie.highlighted || serieData.highlighted;
var color = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var toColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, highlight);
float xValue = serieData.GetCurrData(0, dataChangeDuration);
float yValue = serieData.GetCurrData(1, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true;
@@ -37,7 +39,7 @@ namespace XCharts
float xDataHig = (xValue - xAxis.runtimeMinValue) / (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * coordinateWidth;
float yDataHig = (yValue - yAxis.runtimeMinValue) / (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * coordinateHeight;
var pos = new Vector3(pX + xDataHig, pY + yDataHig);
serie.dataPoints.Add(pos);
var datas = serie.data[n].data;
float symbolSize = 0;
if (serie.highlighted || serieData.highlighted)
@@ -56,13 +58,13 @@ namespace XCharts
{
var nowSize = serie.symbol.animationSize[count];
color.a = (symbolSize - nowSize) / symbolSize;
DrawSymbol(vh, serie.symbol.type, nowSize, 3, pos, color, serie.symbol.gap);
DrawSymbol(vh, serie.symbol.type, nowSize, symbolBorder, pos, color, toColor, serie.symbol.gap);
}
RefreshChart();
}
else
{
DrawSymbol(vh, serie.symbol.type, symbolSize, 3, pos, color, serie.symbol.gap);
DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, pos, color, toColor, serie.symbol.gap);
}
}
if (!serie.animation.IsFinish())

View File

@@ -82,11 +82,13 @@ namespace XCharts
for (int n = 0; n < data.Count; n++)
{
var serieData = data[n];
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
serieData.index = n;
float value = serieData.GetCurrData(1, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true;
serieNameCount = m_LegendRealShowName.IndexOf(serieData.legendName);
Color color = m_ThemeInfo.GetColor(serieNameCount);
var color = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieNameCount, serieData.highlighted);
var toColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieNameCount, serieData.highlighted);
serieData.runtimePieStartAngle = startDegree;
serieData.runtimePieToAngle = startDegree;
serieData.runtimePieHalfAngle = startDegree;
@@ -105,7 +107,6 @@ namespace XCharts
if (serieData.highlighted)
{
isDataHighlight = true;
color *= 1.2f;
serieData.runtimePieOutsideRadius += m_Settings.pieTooltipExtraRadius;
}
var offset = serie.pieSpace;
@@ -146,7 +147,7 @@ namespace XCharts
var drawEndDegree = serieData.runtimePieCurrAngle - serie.pieSpace;
DrawRoundCap(vh, serie, serieData, serieData.runtiemPieOffsetCenter, color, ref drawStartDegree, ref drawEndDegree);
ChartDrawer.DrawDoughnut(vh, serieData.runtiemPieOffsetCenter, serieData.runtimePieInsideRadius, serieData.runtimePieOutsideRadius,
color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, drawStartDegree, drawEndDegree);
color, toColor, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, drawStartDegree, drawEndDegree);
}
else
{
@@ -154,7 +155,8 @@ namespace XCharts
var drawEndDegree = serieData.runtimePieCurrAngle - serie.pieSpace;
DrawRoundCap(vh, serie, serieData, center, color, ref drawStartDegree, ref drawEndDegree);
ChartDrawer.DrawDoughnut(vh, center, serieData.runtimePieInsideRadius, serieData.runtimePieOutsideRadius,
color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, drawStartDegree, drawEndDegree);
color, toColor, Color.clear, m_Settings.cicleSmoothness, drawStartDegree, drawEndDegree);
DrawCenter(vh, serie, itemStyle, serieData.runtimePieInsideRadius);
}
serieData.canShowLabel = serieData.runtimePieCurrAngle >= serieData.runtimePieHalfAngle;
isDrawPie = true;
@@ -178,6 +180,15 @@ namespace XCharts
raycastTarget = isClickOffset && isDataHighlight;
}
private void DrawCenter(VertexHelper vh, Serie serie, ItemStyle itemStyle, float insideRadius)
{
if (itemStyle.centerColor != Color.clear)
{
var radius = insideRadius - itemStyle.centerGap;
ChartDrawer.DrawCricle(vh, serie.runtimeCenterPos, radius, itemStyle.centerColor, m_Settings.cicleSmoothness);
}
}
private void DrawRoundCap(VertexHelper vh, Serie serie, SerieData serieData, Vector3 centerPos,
Color color, ref float drawStartDegree, ref float drawEndDegree)
{
@@ -202,7 +213,7 @@ namespace XCharts
{
foreach (var serieData in serie.data)
{
var serieLabel = serieData.GetSerieLabel(serie.label);
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
if (serieLabel.show && serieData.canShowLabel)
{
int colorIndex = m_LegendRealShowName.IndexOf(serieData.name);
@@ -222,7 +233,7 @@ namespace XCharts
{
foreach (var serieData in serie.data)
{
var serieLabel = serieData.GetSerieLabel(serie.label);
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
if (serieLabel.show && serieData.canShowLabel)
{
UpdateLabelPostion(serie, serieData);
@@ -235,7 +246,7 @@ namespace XCharts
private void DrawLabelLine(VertexHelper vh, Serie serie, SerieData serieData, Color color)
{
var serieLabel = serieData.GetSerieLabel(serie.label);
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
if (serieLabel.show
&& serieLabel.position == SerieLabel.Position.Outside
&& serieLabel.line)
@@ -363,7 +374,7 @@ namespace XCharts
if (serieData.labelText == null) return;
var currAngle = serieData.runtimePieHalfAngle;
var isHighlight = (serieData.highlighted && serie.emphasis.label.show);
var serieLabel = serieData.GetSerieLabel(serie.label);
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
var showLabel = ((serieLabel.show || isHighlight) && serieData.canShowLabel);
if (showLabel || serieData.iconStyle.show)
{
@@ -428,7 +439,7 @@ namespace XCharts
var offsetRadius = serieData.runtimePieOffsetRadius;
var insideRadius = serieData.runtimePieInsideRadius;
var outsideRadius = serieData.runtimePieOutsideRadius;
var serieLabel = serieData.GetSerieLabel(serie.label);
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
switch (serieLabel.position)
{
case SerieLabel.Position.Center:

View File

@@ -261,8 +261,9 @@ namespace XCharts
}
var isHighlight = serie.highlighted || serieData.highlighted ||
(m_Tooltip.show && m_Tooltip.runtimeDataIndex[0] == i && m_Tooltip.runtimeDataIndex[1] == j);
var areaColor = serie.GetAreaColor(m_ThemeInfo, serieIndex, isHighlight);
var lineColor = serie.GetLineColor(m_ThemeInfo, serieIndex, isHighlight);
var areaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, serieIndex, isHighlight);
var areaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, serieIndex, isHighlight);
var lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, serieIndex, isHighlight);
int dataCount = radar.indicatorList.Count;
List<Vector3> pointList = radar.runtimeDataPosList[key];
for (int n = 0; n < dataCount; n++)
@@ -293,7 +294,7 @@ namespace XCharts
p.y + radius * Mathf.Cos(currAngle));
if (serie.areaStyle.show)
{
ChartDrawer.DrawTriangle(vh, p, startPoint, toPoint, areaColor);
ChartDrawer.DrawTriangle(vh, startPoint, toPoint, p, areaColor, areaColor, areaToColor);
}
if (serie.lineStyle.show)
{
@@ -305,7 +306,7 @@ namespace XCharts
}
if (serie.areaStyle.show)
{
ChartDrawer.DrawTriangle(vh, p, startPoint, firstPoint, areaColor);
ChartDrawer.DrawTriangle(vh, startPoint, firstPoint, p, areaColor, areaColor, areaToColor);
}
if (serie.lineStyle.show)
{
@@ -314,12 +315,13 @@ namespace XCharts
if (serie.symbol.type != SerieSymbolType.None)
{
var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size);
var symbolColor = serie.symbol.color != Color.clear ? serie.symbol.color : lineColor;
symbolColor.a *= serie.symbol.opacity;
var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight);
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight);
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, isHighlight);
foreach (var point in pointList)
{
DrawSymbol(vh, serie.symbol.type, symbolSize, serie.lineStyle.width, point, symbolColor,
serie.symbol.gap);
DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor,
symbolToColor, serie.symbol.gap);
}
}
}

View File

@@ -89,7 +89,7 @@ namespace XCharts
var degree = 360 * value / max;
var startDegree = GetStartAngle(serie);
var toDegree = GetToAngle(serie, degree);
var itemColor = SerieHelper.GetItemColor(serie, m_ThemeInfo, j, serieData.highlighted);
var itemColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, j, serieData.highlighted);
var outsideRadius = serie.runtimeOutsideRadius - j * (ringWidth + serie.ringGap);
var insideRadius = outsideRadius - ringWidth;
var centerRadius = (outsideRadius + insideRadius) / 2;
@@ -99,14 +99,14 @@ namespace XCharts
serieData.runtimePieInsideRadius = insideRadius;
serieData.runtimePieOutsideRadius = outsideRadius;
DrawBackground(vh, serie, j, insideRadius, outsideRadius);
DrawBackground(vh, serie, serieData, j, insideRadius, outsideRadius);
DrawRoundCap(vh, serie, serie.runtimeCenterPos, itemColor, insideRadius, outsideRadius,
ref startDegree, ref toDegree);
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius,
outsideRadius, itemColor, Color.clear, m_Settings.cicleSmoothness,
startDegree, toDegree);
DrawBorder(vh, serie, insideRadius, outsideRadius);
DrawCenter(vh, serie, insideRadius, j == data.Count - 1);
DrawBorder(vh, serie, serieData, insideRadius, outsideRadius);
DrawCenter(vh, serie, serieData, insideRadius, j == data.Count - 1);
UpateLabelPosition(serie, serieData, j, startDegree, toDegree, centerRadius);
}
if (!serie.animation.IsFinish())
@@ -149,12 +149,14 @@ namespace XCharts
return toAngle;
}
private void DrawCenter(VertexHelper vh, Serie serie, float insideRadius, bool last)
private void DrawCenter(VertexHelper vh, Serie serie, SerieData serieData, float insideRadius, bool last)
{
if (serie.itemStyle.centerColor != Color.clear && last)
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
if (itemStyle.centerColor != Color.clear && last)
{
var radius = insideRadius - serie.itemStyle.centerGap;
ChartDrawer.DrawCricle(vh, serie.runtimeCenterPos, radius, serie.itemStyle.centerColor);
var radius = insideRadius - itemStyle.centerGap;
var smoothness = m_Settings.cicleSmoothness;
ChartDrawer.DrawCricle(vh, serie.runtimeCenterPos, radius, itemStyle.centerColor, smoothness);
}
}
@@ -183,14 +185,15 @@ namespace XCharts
}
}
private void DrawBackground(VertexHelper vh, Serie serie, int index, float insideRadius, float outsideRadius)
private void DrawBackground(VertexHelper vh, Serie serie, SerieData serieData, int index, float insideRadius, float outsideRadius)
{
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, m_ThemeInfo, index, false);
if (serie.itemStyle.backgroundWidth != 0)
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, m_ThemeInfo, index, false);
if (itemStyle.backgroundWidth != 0)
{
var centerRadius = (outsideRadius + insideRadius) / 2;
var inradius = centerRadius - serie.itemStyle.backgroundWidth / 2;
var outradius = centerRadius + serie.itemStyle.backgroundWidth / 2;
var inradius = centerRadius - itemStyle.backgroundWidth / 2;
var outradius = centerRadius + itemStyle.backgroundWidth / 2;
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, inradius,
outradius, backgroundColor, Color.clear, m_Settings.cicleSmoothness);
}
@@ -201,15 +204,16 @@ namespace XCharts
}
}
private void DrawBorder(VertexHelper vh, Serie serie, float insideRadius, float outsideRadius)
private void DrawBorder(VertexHelper vh, Serie serie, SerieData serieData, float insideRadius, float outsideRadius)
{
if (serie.itemStyle.show && serie.itemStyle.borderWidth > 0 && serie.itemStyle.borderColor != Color.clear)
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
if (itemStyle.show && itemStyle.borderWidth > 0 && itemStyle.borderColor != Color.clear)
{
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, outsideRadius,
outsideRadius + serie.itemStyle.borderWidth, serie.itemStyle.borderColor,
outsideRadius + itemStyle.borderWidth, itemStyle.borderColor,
Color.clear, m_Settings.cicleSmoothness);
ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius,
insideRadius + serie.itemStyle.borderWidth, serie.itemStyle.borderColor,
insideRadius + itemStyle.borderWidth, itemStyle.borderColor,
Color.clear, m_Settings.cicleSmoothness);
}
}

View File

@@ -30,7 +30,9 @@ namespace XCharts
m_YAxises[1].type = Axis.AxisType.Value;
m_XAxises[1].boundaryGap = false;
RemoveData();
AddSerie(SerieType.Scatter, "serie1");
var serie = AddSerie(SerieType.Scatter, "serie1");
serie.itemStyle.opacity = 0.8f;
serie.clip = false;
for (int i = 0; i < 10; i++)
{
AddData(0, Random.Range(10, 100), Random.Range(10, 100));

View File

@@ -153,16 +153,28 @@ namespace XCharts
}
public static void DrawDiamond(VertexHelper vh, Vector3 pos, float size, Color32 color)
{
DrawDiamond(vh, pos, size, color, color);
}
public static void DrawDiamond(VertexHelper vh, Vector3 pos, float size, Color32 color, Color32 toColor)
{
var p1 = new Vector2(pos.x - size, pos.y);
var p2 = new Vector2(pos.x, pos.y + size);
var p3 = new Vector2(pos.x + size, pos.y);
var p4 = new Vector2(pos.x, pos.y - size);
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, color);
DrawTriangle(vh, p4, p1, p2, color, color, toColor);
DrawTriangle(vh, p3, p4, p2, color, color, toColor);
}
public static void DrawPolygon(VertexHelper vh, Vector3 p, float radius, Color32 color,
bool vertical = true)
{
DrawPolygon(vh, p, radius, color, color, vertical);
}
public static void DrawPolygon(VertexHelper vh, Vector3 p, float radius, Color32 color, Color32 toColor,
bool vertical = true)
{
Vector3 p1, p2, p3, p4;
if (vertical)
@@ -179,7 +191,7 @@ namespace XCharts
p3 = new Vector3(p.x + radius, p.y + radius);
p4 = new Vector3(p.x + radius, p.y - radius);
}
DrawPolygon(vh, p1, p2, p3, p4, color, color);
DrawPolygon(vh, p1, p2, p3, p4, color, toColor);
}
public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, float radius, Color32 color)
@@ -285,13 +297,18 @@ namespace XCharts
}
public static void DrawTriangle(VertexHelper vh, Vector3 pos, float size, Color32 color)
{
DrawTriangle(vh, pos, size, color, color);
}
public static void DrawTriangle(VertexHelper vh, Vector3 pos, float size, Color32 color, Color32 toColor)
{
var x = size * Mathf.Cos(30 * Mathf.PI / 180);
var y = size * Mathf.Sin(30 * Mathf.PI / 180);
var p1 = new Vector2(pos.x - x, pos.y - y);
var p2 = new Vector2(pos.x, pos.y + size);
var p3 = new Vector2(pos.x + x, pos.y - y);
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color, toColor, color);
}
public static void DrawTriangle(VertexHelper vh, Vector3 p1,
@@ -316,20 +333,38 @@ namespace XCharts
vh.AddTriangle(startIndex, startIndex + 1, startIndex + 2);
}
public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color,
Color32 toColor, float smoothness = 2f)
{
DrawSector(vh, p, radius, color, toColor, 0, 360, smoothness);
}
public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color,
float smoothness = 2f)
{
DrawSector(vh, p, radius, color, 0, 360, smoothness);
DrawCricle(vh, p, radius, color, color, smoothness);
}
public static void DrawEmptyCricle(VertexHelper vh, Vector3 p, float radius, float tickness,
Color32 color, Color emptyColor, float smoothness = 2f)
{
DrawDoughnut(vh, p, radius - tickness, radius, color, emptyColor, smoothness);
DrawDoughnut(vh, p, radius - tickness, radius, color, color, emptyColor, smoothness);
}
public static void DrawEmptyCricle(VertexHelper vh, Vector3 p, float radius, float tickness,
Color32 color, Color32 toColor, Color emptyColor, float smoothness = 2f)
{
DrawDoughnut(vh, p, radius - tickness, radius, color, toColor, emptyColor, smoothness);
}
public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color,
float startDegree, float toDegree, float smoothness = 2f)
{
DrawSector(vh, p, radius, color, color, startDegree, toDegree, smoothness);
}
public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color,
Color32 toColor, float startDegree, float toDegree, float smoothness = 2f)
{
int segments = (int)((2 * Mathf.PI * radius) / (smoothness < 0 ? 2f : smoothness));
Vector3 p2, p3;
@@ -341,7 +376,7 @@ namespace XCharts
float currAngle = startAngle + i * angle;
p3 = new Vector3(p.x + radius * Mathf.Sin(currAngle),
p.y + radius * Mathf.Cos(currAngle));
DrawTriangle(vh, p, p2, p3, color);
DrawTriangle(vh, p, p2, p3, toColor, color, color);
p2 = p3;
}
}
@@ -370,10 +405,18 @@ namespace XCharts
public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius,
Color32 color, Color emptyColor, float smoothness = 2f, float startDegree = 0, float toDegree = 360)
{
DrawDoughnut(vh, p, insideRadius, outsideRadius, color, color, emptyColor, smoothness,
startDegree, toDegree);
}
public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius,
Color32 color, Color32 toColor, Color emptyColor, float smoothness = 2f, float startDegree = 0,
float toDegree = 360)
{
if (insideRadius <= 0)
{
DrawSector(vh, p, outsideRadius, color, startDegree, toDegree, smoothness);
DrawSector(vh, p, outsideRadius, color, toColor, startDegree, toDegree, smoothness);
return;
}
Vector3 p1, p2, p3, p4;
@@ -392,7 +435,8 @@ namespace XCharts
p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle),
p.y + insideRadius * Mathf.Cos(currAngle));
if (emptyColor != Color.clear) DrawTriangle(vh, p, p1, p4, emptyColor);
DrawPolygon(vh, p1, p2, p3, p4, color);
//DrawPolygon(vh, p1, p2, p3, p4, color,Color.blue);
DrawPolygon(vh, p2, p3, p4, p1, color, toColor);
p1 = p4;
p2 = p3;
}