diff --git a/Scripts/Editor/PropertyDrawers/AreaStyleDrawer.cs b/Scripts/Editor/PropertyDrawers/AreaStyleDrawer.cs index a2a28485..1fc79feb 100644 --- a/Scripts/Editor/PropertyDrawers/AreaStyleDrawer.cs +++ b/Scripts/Editor/PropertyDrawers/AreaStyleDrawer.cs @@ -17,7 +17,10 @@ namespace XCharts SerializedProperty m_Origin = prop.FindPropertyRelative("m_Origin"); SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); SerializedProperty m_ToColor = prop.FindPropertyRelative("m_ToColor"); + SerializedProperty m_HighlightColor = prop.FindPropertyRelative("m_HighlightColor"); + SerializedProperty m_HighlightToColor = prop.FindPropertyRelative("m_HighlightToColor"); SerializedProperty m_Opacity = prop.FindPropertyRelative("m_Opacity"); + SerializedProperty m_TooltipHighlight = prop.FindPropertyRelative("m_TooltipHighlight"); ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AreaStyleToggle, prop, "Area Style", show, false); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; @@ -30,8 +33,14 @@ namespace XCharts drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_ToColor); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_HighlightColor); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_HighlightToColor); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_Opacity); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_TooltipHighlight); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; --EditorGUI.indentLevel; } } @@ -41,7 +50,7 @@ namespace XCharts float height = 0; if (ChartEditorHelper.IsToggle(m_AreaStyleToggle, prop)) { - height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing; + height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing; } else { diff --git a/Scripts/UI/Component/Serie.cs b/Scripts/UI/Component/Serie.cs index ad9d38a6..19d3191e 100644 --- a/Scripts/UI/Component/Serie.cs +++ b/Scripts/UI/Component/Serie.cs @@ -886,20 +886,14 @@ namespace XCharts public Color GetAreaColor(ThemeInfo theme, int index, bool highlight) { - if (areaStyle.color != Color.clear) + var color = areaStyle.color != Color.clear ? areaStyle.color : (Color)theme.GetColor(index); + if (highlight) { - var color = areaStyle.color; - if (highlight) color *= color; - color.a *= areaStyle.opacity; - return color; - } - else - { - var color = (Color)theme.GetColor(index); - if (highlight) color *= color; - color.a *= areaStyle.opacity; - return color; + if (areaStyle.highlightColor != Color.clear) color = areaStyle.highlightColor; + else color *= color; } + color.a *= areaStyle.opacity; + return color; } public Color GetAreaToColor(ThemeInfo theme, int index, bool highlight) @@ -907,7 +901,11 @@ namespace XCharts if (areaStyle.toColor != Color.clear) { var color = areaStyle.toColor; - if (highlight) color *= color; + if (highlight) + { + if (areaStyle.highlightToColor != Color.clear) color = areaStyle.highlightToColor; + else color *= color; + } color.a *= areaStyle.opacity; return color; } diff --git a/Scripts/UI/Internal/AreaStyle.cs b/Scripts/UI/Internal/AreaStyle.cs index 9fd4bac9..3f10ea97 100644 --- a/Scripts/UI/Internal/AreaStyle.cs +++ b/Scripts/UI/Internal/AreaStyle.cs @@ -36,7 +36,10 @@ namespace XCharts [SerializeField] private AreaOrigin m_Origin; [SerializeField] private Color m_Color; [SerializeField] private Color m_ToColor; - [SerializeField][Range(0,1)] private float m_Opacity; + [SerializeField] [Range(0, 1)] private float m_Opacity; + [SerializeField] private bool m_TooltipHighlight; + [SerializeField] private Color m_HighlightColor; + [SerializeField] private Color m_HighlightToColor; /// /// Set this to false to prevent the areafrom showing. @@ -57,13 +60,26 @@ namespace XCharts /// Gradient color, start color to toColor. /// 渐变色的终点颜色。 /// - /// public Color toColor { get { return m_ToColor; } set { m_ToColor = value; } } /// /// Opacity of the component. Supports value from 0 to 1, and the component will not be drawn when set to 0. /// 图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。 /// public float opacity { get { return m_Opacity; } set { m_Opacity = value; } } + /// + /// 鼠标悬浮时是否高亮之前的区域 + /// + public bool tooltipHighlight { get { return m_TooltipHighlight; } set { m_TooltipHighlight = value; } } + /// + /// the color of area,default use serie color. + /// 高亮时区域填充的颜色,如果highlightToColor不是默认值,则表示渐变色的起点颜色。 + /// + public Color highlightColor { get { return m_HighlightColor; } set { m_HighlightColor = value; } } + /// + /// Gradient color, start highlightColor to highlightToColor. + /// 高亮时渐变色的终点颜色。 + /// + public Color highlightToColor { get { return m_HighlightToColor; } set { m_HighlightToColor = value; } } public static AreaStyle defaultAreaStyle { diff --git a/Scripts/UI/Internal/CoordinateChart_DrawLine.cs b/Scripts/UI/Internal/CoordinateChart_DrawLine.cs index 6298124f..f9ec1250 100644 --- a/Scripts/UI/Internal/CoordinateChart_DrawLine.cs +++ b/Scripts/UI/Internal/CoordinateChart_DrawLine.cs @@ -73,8 +73,11 @@ namespace XCharts var showData = serie.GetDataList(m_DataZoom); if (showData.Count <= 0) return; Color lineColor = serie.GetLineColor(m_ThemeInfo, colorIndex, false); - Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, false); - Color areaToColor = serie.GetAreaToColor(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 areaColor, areaToColor; Vector3 lp = Vector3.zero, np = Vector3.zero, llp = Vector3.zero, nnp = Vector3.zero; var yAxis = m_YAxises[serie.axisIndex]; var xAxis = m_XAxises[serie.axisIndex]; @@ -158,6 +161,16 @@ namespace XCharts serie.ClearSmoothList(i); if (!serie.animation.NeedAnimation(i)) break; bool isFinish = true; + if (serie.areaStyle.tooltipHighlight && m_Tooltip.show && i <= m_Tooltip.dataIndex[0]) + { + areaColor = highlightAreaColor; + areaToColor = highlightAreaToColor; + } + else + { + areaColor = srcAreaColor; + areaToColor = srcAreaToColor; + } switch (serie.lineType) { case LineType.Normal: @@ -351,8 +364,11 @@ namespace XCharts Vector3 llp = Vector3.zero; Vector3 nnp = Vector3.zero; Color lineColor = serie.GetLineColor(m_ThemeInfo, colorIndex, false); - Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, false); - Color areaToColor = serie.GetAreaToColor(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 areaColor, areaToColor; var xAxis = m_XAxises[serie.axisIndex]; var yAxis = m_YAxises[serie.axisIndex]; var zeroPos = new Vector3(coordinateX + xAxis.zeroXOffset, coordinateY); @@ -412,6 +428,16 @@ namespace XCharts serie.ClearSmoothList(i); if (!serie.animation.NeedAnimation(i)) break; bool isFinish = true; + if (serie.areaStyle.tooltipHighlight && m_Tooltip.show && i < m_Tooltip.dataIndex[0]) + { + areaColor = highlightAreaColor; + areaToColor = highlightAreaToColor; + } + else + { + areaColor = srcAreaToColor; + areaToColor = srcAreaToColor; + } switch (serie.lineType) { case LineType.Normal: