diff --git a/CHANGELOG.md b/CHANGELOG.md index e2b7465a..38de1e55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 更新日志 +* (2020.04.19) 增加`Serie`和`AxisLabel`的`showAsPositiveNumber`参数将负数数值显示为正数 * (2020.04.18) 增加`Covert XY Axis`互换XY轴配置 * (2020.04.17) 增加`Axis`可通过`inverse`参数设置坐标轴反转 * (2020.04.16) 修复`Check warning`在`Unity2019.3`上的显示问题 diff --git a/Documentation/XCharts配置项手册.md b/Documentation/XCharts配置项手册.md index 2a6baa41..346d39f9 100644 --- a/Documentation/XCharts配置项手册.md +++ b/Documentation/XCharts配置项手册.md @@ -470,6 +470,7 @@ * `clip`:是否裁剪超出坐标系部分的图形。 * `ignore`:是否开启忽略数据。当为 `true` 时,数据值为 `ignoreValue` 时不进行绘制。 * `ignoreValue`:忽略数据的默认值。默认值默认为0,当 `ignore` 为 `true` 才有效。 +* `showAsPositiveNumber`:将负数数值显示为正数。一般和`AxisLabel`的`showAsPositiveNumber`配合使用。仅在折线图和柱状图中有效。 * `areaStyle`:区域填充样式 [AreaStyle](#AreaStyle)。 * `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。 * `lineType`:折线图样式类型。支持以下十种类型: @@ -515,6 +516,7 @@ * `clip`:是否裁剪超出坐标系部分的图形。 * `ignore`:是否开启忽略数据。当为 `true` 时,数据值为 `ignoreValue` 时不进行绘制。 * `ignoreValue`:忽略数据的默认值。默认值默认为0,当 `ignore` 为 `true` 才有效。 +* `showAsPositiveNumber`:将负数数值显示为正数。一般和`AxisLabel`的`showAsPositiveNumber`配合使用。仅在折线图和柱状图中有效。 * `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。 * `itemStyle`:柱条样式 [ItemStyle](#ItemStyle)。 * `areaStyle`:区域填充样式 [AreaStyle](#AreaStyle)。 @@ -682,6 +684,7 @@ * `fontStyle`:文字字体的风格。 * `formatter`:图例内容字符串模版格式器。支持用 \n 换行。模板变量为图例名称 {value},支持{value:f0},{value:f1},{value:f2}。 * `forceENotation`:是否强制使用科学计数法格式化显示数值。默认为false,当小数精度大于3时才采用科学计数法。 +* `showAsPositiveNumber`:将负数数值显示为正数。一般和`Serie`的`showAsPositiveNumber`配合使用。 * `textLimit`:文本自适应 [TextLimit](#TextLimit)。只在类目轴中有效。 ## `AxisLine` diff --git a/Editor/PropertyDrawers/AxisLabelDrawer.cs b/Editor/PropertyDrawers/AxisLabelDrawer.cs index 3514b4b4..fccd7dd5 100644 --- a/Editor/PropertyDrawers/AxisLabelDrawer.cs +++ b/Editor/PropertyDrawers/AxisLabelDrawer.cs @@ -30,6 +30,7 @@ namespace XCharts SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize"); SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle"); SerializedProperty m_ForceENotation = prop.FindPropertyRelative("m_ForceENotation"); + SerializedProperty m_ShowAsPositiveNumber = prop.FindPropertyRelative("m_ShowAsPositiveNumber"); SerializedProperty m_TextLimit = prop.FindPropertyRelative("m_TextLimit"); ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLabelToggle, prop, "Axis Label", show, false); @@ -55,6 +56,8 @@ namespace XCharts drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_ForceENotation); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_ShowAsPositiveNumber); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_TextLimit); drawRect.y += EditorGUI.GetPropertyHeight(m_TextLimit); --EditorGUI.indentLevel; @@ -66,7 +69,7 @@ namespace XCharts float height = 0; if (ChartEditorHelper.IsToggle(m_AxisLabelToggle, prop)) { - height += 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing; + height += 11 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing; height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextLimit")); } return height; diff --git a/Editor/PropertyDrawers/SerieDrawer.cs b/Editor/PropertyDrawers/SerieDrawer.cs index b3cef122..255e7e38 100644 --- a/Editor/PropertyDrawers/SerieDrawer.cs +++ b/Editor/PropertyDrawers/SerieDrawer.cs @@ -74,6 +74,7 @@ namespace XCharts SerializedProperty m_Clip = prop.FindPropertyRelative("m_Clip"); SerializedProperty m_Ignore = prop.FindPropertyRelative("m_Ignore"); SerializedProperty m_IgnoreValue = prop.FindPropertyRelative("m_IgnoreValue"); + SerializedProperty m_ShowAsPositiveNumber = prop.FindPropertyRelative("m_ShowAsPositiveNumber"); SerializedProperty m_Datas = prop.FindPropertyRelative("m_Data"); int index = InitToggle(prop); @@ -131,6 +132,8 @@ namespace XCharts drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_IgnoreValue); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_ShowAsPositiveNumber); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_Symbol); drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol); EditorGUI.PropertyField(drawRect, m_LineStyle); @@ -178,6 +181,8 @@ namespace XCharts drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_IgnoreValue); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_ShowAsPositiveNumber); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_ItemStyle); drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle); EditorGUI.PropertyField(drawRect, m_Label); @@ -316,8 +321,8 @@ namespace XCharts var gap = 2; var namegap = 3; #else - var gap = 0; - var namegap = 0; + var gap = 0; + var namegap = 0; #endif 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 + gap, drawRect.y, nameWid - gap, pos.height); @@ -490,7 +495,7 @@ namespace XCharts switch (serieType) { case SerieType.Line: - height += 16 * EditorGUIUtility.singleLineHeight + 15 * EditorGUIUtility.standardVerticalSpacing; + height += 17 * EditorGUIUtility.singleLineHeight + 16 * EditorGUIUtility.standardVerticalSpacing; height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineArrow")); @@ -501,7 +506,7 @@ namespace XCharts height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation")); break; case SerieType.Bar: - height += 18 * EditorGUIUtility.singleLineHeight + 17 * EditorGUIUtility.standardVerticalSpacing; + height += 19 * EditorGUIUtility.singleLineHeight + 18 * EditorGUIUtility.standardVerticalSpacing; height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis")); diff --git a/Runtime/Component/Main/Serie.cs b/Runtime/Component/Main/Serie.cs index 5548a30a..c19deb5d 100644 --- a/Runtime/Component/Main/Serie.cs +++ b/Runtime/Component/Main/Serie.cs @@ -270,6 +270,7 @@ namespace XCharts [SerializeField] private bool m_Clip = false; [SerializeField] private bool m_Ignore = false; [SerializeField] private float m_IgnoreValue = 0; + [SerializeField] private bool m_ShowAsPositiveNumber = false; [SerializeField] private RadarType m_RadarType = RadarType.Multiple; [SerializeField] private List m_Data = new List(); @@ -743,6 +744,15 @@ namespace XCharts set { if (PropertyUtility.SetStruct(ref m_Clip, value)) SetVerticesDirty(); } } /// + /// Show negative number as positive number. + /// 将负数数值显示为正数。一般和`AxisLabel`的`showAsPositiveNumber`配合使用。仅在折线图和柱状图中有效。 + /// + public bool showAsPositiveNumber + { + get { return m_ShowAsPositiveNumber; } + set { if (PropertyUtility.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); } + } + /// /// 系列中的数据内容数组。SerieData可以设置1到n维数据。 /// public List data { get { return m_Data; } } @@ -1241,6 +1251,11 @@ namespace XCharts var serieData = showData[index]; xValue = serieData.data[0]; yVlaue = serieData.data[1]; + if (showAsPositiveNumber) + { + xValue = Mathf.Abs(xValue); + yVlaue = Mathf.Abs(yVlaue); + } } } diff --git a/Runtime/Component/Sub/AxisLabel.cs b/Runtime/Component/Sub/AxisLabel.cs index 9b3800f3..be95c128 100644 --- a/Runtime/Component/Sub/AxisLabel.cs +++ b/Runtime/Component/Sub/AxisLabel.cs @@ -28,6 +28,7 @@ namespace XCharts [SerializeField] private int m_FontSize; [SerializeField] private FontStyle m_FontStyle; [SerializeField] private bool m_ForceENotation = false; + [SerializeField] private bool m_ShowAsPositiveNumber = false; [SerializeField] private TextLimit m_TextLimit = new TextLimit(); /// @@ -119,6 +120,17 @@ namespace XCharts get { return m_ForceENotation; } set { if (PropertyUtility.SetStruct(ref m_ForceENotation, value)) SetComponentDirty(); } } + + /// + /// Show negative number as positive number. + /// 将负数数值显示为正数。一般和`Serie`的`showAsPositiveNumber`配合使用。 + /// + public bool showAsPositiveNumber + { + get { return m_ShowAsPositiveNumber; } + set { if (PropertyUtility.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); } + } + /// /// 文本限制。 /// @@ -206,6 +218,10 @@ namespace XCharts public string GetFormatterContent(float value, float minValue, float maxValue, bool isLog = false) { + if (showAsPositiveNumber && value < 0) + { + value = Mathf.Abs(value); + } if (string.IsNullOrEmpty(m_Formatter)) { if (isLog)