mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 17:30:10 +00:00
XCharts 2.0
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -12,10 +12,6 @@ namespace XCharts
|
||||
{
|
||||
public static class AxisHelper
|
||||
{
|
||||
public static float GetTickWidth(Axis axis)
|
||||
{
|
||||
return axis.axisTick.width != 0 ? axis.axisTick.width : axis.axisLine.width;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 包含箭头偏移的轴线长度
|
||||
@@ -24,9 +20,9 @@ namespace XCharts
|
||||
/// <returns></returns>
|
||||
public static float GetAxisLineSymbolOffset(Axis axis)
|
||||
{
|
||||
if (axis.axisLine.show && axis.axisLine.symbol && axis.axisLine.symbolOffset > 0)
|
||||
if (axis.axisLine.show && axis.axisLine.showArrow && axis.axisLine.arrow.offset > 0)
|
||||
{
|
||||
return axis.axisLine.symbolOffset;
|
||||
return axis.axisLine.arrow.offset;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -115,7 +111,7 @@ namespace XCharts
|
||||
if (axis.type == Axis.AxisType.Value)
|
||||
{
|
||||
if (minValue == 0 && maxValue == 0) return string.Empty;
|
||||
float value = 0;
|
||||
var value = 0f;
|
||||
if (forcePercent) maxValue = 100;
|
||||
if (axis.interval > 0)
|
||||
{
|
||||
@@ -124,7 +120,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (minValue + (maxValue - minValue) * index / split);
|
||||
value = minValue + (maxValue - minValue) * index / split;
|
||||
if (!axis.clockwise && value != minValue) value = maxValue - value;
|
||||
}
|
||||
if (axis.inverse)
|
||||
@@ -133,6 +129,7 @@ namespace XCharts
|
||||
minValue = -minValue;
|
||||
maxValue = -maxValue;
|
||||
}
|
||||
|
||||
if (forcePercent) return string.Format("{0}%", (int)value);
|
||||
else return axis.axisLabel.GetFormatterContent(value, minValue, maxValue);
|
||||
}
|
||||
@@ -324,11 +321,11 @@ namespace XCharts
|
||||
else return true;
|
||||
}
|
||||
|
||||
internal static void AdjustCircleLabelPos(Text txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
|
||||
internal static void AdjustCircleLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
|
||||
{
|
||||
var txtWidth = txt.preferredWidth;
|
||||
var sizeDelta = new Vector2(txtWidth, txt.preferredHeight);
|
||||
txt.GetComponent<RectTransform>().sizeDelta = sizeDelta;
|
||||
var txtWidth = txt.GetPreferredWidth();
|
||||
var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight());
|
||||
txt.SetSizeDelta(sizeDelta);
|
||||
var diff = pos.x - cenPos.x;
|
||||
if (diff < -1f) //left
|
||||
{
|
||||
@@ -343,14 +340,14 @@ namespace XCharts
|
||||
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
|
||||
pos = new Vector3(pos.x, y);
|
||||
}
|
||||
txt.transform.localPosition = pos + offset;
|
||||
txt.SetLocalPosition(pos + offset);
|
||||
}
|
||||
|
||||
internal static void AdjustRadiusAxisLabelPos(Text txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
|
||||
internal static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
|
||||
{
|
||||
var txtWidth = txt.preferredWidth;
|
||||
var sizeDelta = new Vector2(txtWidth, txt.preferredHeight);
|
||||
txt.GetComponent<RectTransform>().sizeDelta = sizeDelta;
|
||||
var txtWidth = txt.GetPreferredWidth();
|
||||
var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight());
|
||||
txt.SetSizeDelta(sizeDelta);
|
||||
var diff = pos.y - cenPos.y;
|
||||
if (diff > 20f) //left
|
||||
{
|
||||
@@ -365,7 +362,7 @@ namespace XCharts
|
||||
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
|
||||
pos = new Vector3(pos.x, y);
|
||||
}
|
||||
txt.transform.localPosition = pos;
|
||||
txt.SetLocalPosition(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -11,29 +11,29 @@ namespace XCharts
|
||||
{
|
||||
internal static class LegendHelper
|
||||
{
|
||||
public static Color GetContentColor(Legend legend, ThemeInfo themeInfo, bool active)
|
||||
public static Color GetContentColor(Legend legend, ChartTheme theme, bool active)
|
||||
{
|
||||
var textStyle = legend.textStyle;
|
||||
if (active) return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : (Color)themeInfo.legendTextColor;
|
||||
else return (Color)themeInfo.legendUnableColor;
|
||||
if (active) return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor;
|
||||
else return theme.legend.unableColor;
|
||||
}
|
||||
|
||||
public static Color GetIconColor(Legend legend, int readIndex, ThemeInfo themeInfo, Series series, string legendName, bool active)
|
||||
public static Color GetIconColor(Legend legend, int readIndex, ChartTheme theme, Series series, string legendName, bool active)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
|
||||
{
|
||||
return SeriesHelper.GetNameColor(series, readIndex, legendName, themeInfo);
|
||||
return SeriesHelper.GetNameColor(series, readIndex, legendName, theme);
|
||||
}
|
||||
else
|
||||
return Color.white;
|
||||
}
|
||||
else return (Color)themeInfo.legendUnableColor;
|
||||
else return theme.legend.unableColor;
|
||||
}
|
||||
|
||||
public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent, ThemeInfo themeInfo,
|
||||
string content, Color itemColor, bool active)
|
||||
public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent,
|
||||
ChartTheme theme, string content, Color itemColor, bool active)
|
||||
{
|
||||
var objName = i + "_" + legendName;
|
||||
var anchorMin = new Vector2(0, 0.5f);
|
||||
@@ -42,8 +42,7 @@ namespace XCharts
|
||||
var sizeDelta = new Vector2(100, 30);
|
||||
var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
|
||||
var textStyle = legend.textStyle;
|
||||
var font = textStyle.font ? textStyle.font : themeInfo.font;
|
||||
var contentColor = GetContentColor(legend, themeInfo, active);
|
||||
var contentColor = GetContentColor(legend, theme, active);
|
||||
|
||||
var objAnchorMin = new Vector2(0, 1);
|
||||
var objAnchorMax = new Vector2(0, 1);
|
||||
@@ -56,9 +55,10 @@ namespace XCharts
|
||||
ChartHelper.GetOrAddComponent<Button>(btnObj);
|
||||
ChartHelper.GetOrAddComponent<Image>(iconObj);
|
||||
ChartHelper.GetOrAddComponent<Image>(contentObj);
|
||||
ChartHelper.AddTextObject("Text", contentObj.transform, font, contentColor,
|
||||
TextAnchor.MiddleLeft, anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize,
|
||||
textStyle.rotate, textStyle.fontStyle, textStyle.lineSpacing);
|
||||
var txt = ChartHelper.AddTextObject("Text", contentObj.transform, anchorMin, anchorMax, pivot, sizeDelta,
|
||||
textStyle, theme.legend);
|
||||
txt.SetAlignment(TextAnchor.MiddleLeft);
|
||||
txt.SetColor(contentColor);
|
||||
var item = new LegendItem();
|
||||
item.index = i;
|
||||
item.name = objName;
|
||||
@@ -278,5 +278,30 @@ namespace XCharts
|
||||
}
|
||||
return show;
|
||||
}
|
||||
|
||||
public static bool IsSerieLegend(Series series, string legendName, SerieType type)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.type == type)
|
||||
{
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Pie:
|
||||
case SerieType.Radar:
|
||||
case SerieType.Ring:
|
||||
foreach (var serieData in serie.data)
|
||||
{
|
||||
if (legendName.Equals(serieData.name)) return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (legendName.Equals(serie.name)) return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace XCharts
|
||||
{
|
||||
public static partial class SerieHelper
|
||||
{
|
||||
internal static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index,
|
||||
internal static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ChartTheme theme, int index,
|
||||
bool highlight, bool useDefault = true)
|
||||
{
|
||||
var color = ChartConst.clearColor32;
|
||||
@@ -43,7 +43,7 @@ namespace XCharts
|
||||
return color;
|
||||
}
|
||||
|
||||
internal static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
|
||||
internal static Color32 GetItemColor(Serie serie, SerieData serieData, ChartTheme theme, int index, bool highlight)
|
||||
{
|
||||
if (serie == null) return ChartConst.clearColor32;
|
||||
if (highlight)
|
||||
@@ -70,7 +70,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color32 GetItemToColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
|
||||
internal static Color32 GetItemToColor(Serie serie, SerieData serieData, ChartTheme theme, int index, bool highlight)
|
||||
{
|
||||
if (highlight)
|
||||
{
|
||||
@@ -174,7 +174,7 @@ namespace XCharts
|
||||
else return serie.symbol;
|
||||
}
|
||||
|
||||
internal static Color32 GetAreaColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
internal static Color32 GetAreaColor(Serie serie, ChartTheme theme, int index, bool highlight)
|
||||
{
|
||||
var areaStyle = serie.areaStyle;
|
||||
var color = !ChartHelper.IsClearColor(areaStyle.color) ? areaStyle.color : theme.GetColor(index);
|
||||
@@ -187,7 +187,7 @@ namespace XCharts
|
||||
return color;
|
||||
}
|
||||
|
||||
internal static Color32 GetAreaToColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
internal static Color32 GetAreaToColor(Serie serie, ChartTheme theme, int index, bool highlight)
|
||||
{
|
||||
var areaStyle = serie.areaStyle;
|
||||
if (!ChartHelper.IsClearColor(areaStyle.toColor))
|
||||
@@ -207,7 +207,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color32 GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight)
|
||||
internal static Color32 GetLineColor(Serie serie, ChartTheme theme, int index, bool highlight)
|
||||
{
|
||||
Color32 color = ChartConst.clearColor32;
|
||||
if (highlight)
|
||||
@@ -231,12 +231,11 @@ namespace XCharts
|
||||
return color;
|
||||
}
|
||||
|
||||
internal static float GetSymbolBorder(Serie serie, SerieData serieData, bool highlight, bool useLineWidth = true)
|
||||
internal static float GetSymbolBorder(Serie serie, SerieData serieData, ChartTheme theme, bool highlight, bool useLineWidth = true)
|
||||
{
|
||||
var itemStyle = GetItemStyle(serie, serieData, highlight);
|
||||
if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth;
|
||||
else if (serie.lineStyle.width != 0 && useLineWidth) return serie.lineStyle.width;
|
||||
else return 0;
|
||||
else return serie.lineStyle.GetWidth(theme.serie.lineWidth);
|
||||
}
|
||||
|
||||
internal static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, bool highlight)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -42,7 +42,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateLabelText(Series series, ThemeInfo themeInfo, List<string> legendRealShowName)
|
||||
public static void UpdateLabelText(Series series, ChartTheme theme, List<string> legendRealShowName)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
@@ -54,35 +54,35 @@ namespace XCharts
|
||||
SetGaugeLabelText(serie);
|
||||
break;
|
||||
case SerieType.Ring:
|
||||
SetRingLabelText(serie, themeInfo);
|
||||
SetRingLabelText(serie, theme);
|
||||
break;
|
||||
case SerieType.Liquid:
|
||||
SetLiquidLabelText(serie, themeInfo, colorIndex);
|
||||
SetLiquidLabelText(serie, theme, colorIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetLabelColor(Serie serie, ThemeInfo themeInfo, int index)
|
||||
public static Color GetLabelColor(Serie serie, ChartTheme theme, int index)
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(serie.label.color))
|
||||
if (!ChartHelper.IsClearColor(serie.label.textStyle.color))
|
||||
{
|
||||
return serie.label.color;
|
||||
return serie.label.textStyle.color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return themeInfo.GetColor(index);
|
||||
return theme.GetColor(index);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetLabel(SerieData serieData, SerieLabel label, ThemeInfo themeInfo, int colorIndex)
|
||||
public static void ResetLabel(SerieData serieData, SerieLabel label, ChartTheme theme, int colorIndex)
|
||||
{
|
||||
if (serieData.labelObject == null) return;
|
||||
if (serieData.labelObject.label == null) return;
|
||||
serieData.labelObject.label.color = !ChartHelper.IsClearColor(label.color) ? label.color :
|
||||
(Color)themeInfo.GetColor(colorIndex);
|
||||
serieData.labelObject.label.fontSize = label.fontSize;
|
||||
serieData.labelObject.label.fontStyle = label.fontStyle;
|
||||
serieData.labelObject.label.SetColor(!ChartHelper.IsClearColor(label.textStyle.color) ? label.textStyle.color :
|
||||
(Color)theme.GetColor(colorIndex));
|
||||
serieData.labelObject.label.SetFontSize(label.textStyle.GetFontSize(theme.common));
|
||||
serieData.labelObject.label.SetFontStyle(label.textStyle.fontStyle);
|
||||
}
|
||||
|
||||
public static bool CanShowLabel(Serie serie, SerieData serieData, SerieLabel label, int dimesion)
|
||||
@@ -111,7 +111,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetGaugeLabelText(Serie serie)
|
||||
public static void SetGaugeLabelText(Serie serie)
|
||||
{
|
||||
var serieData = serie.GetSerieData(0);
|
||||
if (serieData == null) return;
|
||||
@@ -121,13 +121,13 @@ namespace XCharts
|
||||
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total);
|
||||
serieData.labelObject.SetText(content);
|
||||
serieData.labelObject.SetLabelPosition(serie.runtimeCenterPos + serie.label.offset);
|
||||
if (!ChartHelper.IsClearColor(serie.label.color))
|
||||
if (!ChartHelper.IsClearColor(serie.label.textStyle.color))
|
||||
{
|
||||
serieData.labelObject.label.color = serie.label.color;
|
||||
serieData.labelObject.label.SetColor(serie.label.textStyle.color);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetRingLabelText(Serie serie, ThemeInfo themeInfo)
|
||||
public static void SetRingLabelText(Serie serie, ChartTheme theme)
|
||||
{
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
@@ -145,7 +145,7 @@ namespace XCharts
|
||||
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total);
|
||||
serieData.SetLabelActive(true);
|
||||
serieData.labelObject.SetText(content);
|
||||
serieData.labelObject.SetLabelColor(GetLabelColor(serie, themeInfo, i));
|
||||
serieData.labelObject.SetLabelColor(GetLabelColor(serie, theme, i));
|
||||
|
||||
if (serie.label.position == SerieLabel.Position.Bottom)
|
||||
{
|
||||
@@ -163,7 +163,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetLiquidLabelText(Serie serie, ThemeInfo themeInfo, int colorIndex)
|
||||
public static void SetLiquidLabelText(Serie serie, ChartTheme theme, int colorIndex)
|
||||
{
|
||||
var serieData = serie.GetSerieData(0);
|
||||
if (serieData == null) return;
|
||||
@@ -180,7 +180,7 @@ namespace XCharts
|
||||
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total);
|
||||
serieData.SetLabelActive(true);
|
||||
serieData.labelObject.SetText(content);
|
||||
serieData.labelObject.SetLabelColor(GetLabelColor(serie, themeInfo, colorIndex));
|
||||
serieData.labelObject.SetLabelColor(GetLabelColor(serie, theme, colorIndex));
|
||||
serieData.labelObject.SetLabelPosition(serieData.labelPosition + serieLabel.offset);
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,7 @@ namespace XCharts
|
||||
}
|
||||
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
|
||||
r4 += serieLabel.lineLength1 + serieLabel.lineWidth * 4;
|
||||
r4 += serieData.labelObject.label.preferredWidth / 2;
|
||||
r4 += serieData.labelObject.label.GetPreferredWidth() / 2;
|
||||
serieData.labelPosition = pos0 + (currAngle > 180 ? Vector3.left : Vector3.right) * r4;
|
||||
}
|
||||
else
|
||||
@@ -228,7 +228,7 @@ namespace XCharts
|
||||
labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
|
||||
labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
|
||||
serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
|
||||
float labelWidth = serieData.labelObject.label.preferredWidth;
|
||||
float labelWidth = serieData.labelObject.label.GetPreferredWidth();
|
||||
serieData.labelPosition = labelCenter;
|
||||
}
|
||||
break;
|
||||
@@ -280,7 +280,7 @@ namespace XCharts
|
||||
}
|
||||
else if (serieData.labelPosition.x != 0)
|
||||
{
|
||||
float hig = serieLabel.fontSize;
|
||||
float hig = serieLabel.textStyle.fontSize;
|
||||
if (lastCheckPos.y - serieData.labelPosition.y < hig)
|
||||
{
|
||||
var labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class SeriesHelper
|
||||
public static class SeriesHelper
|
||||
{
|
||||
public static bool IsNeedLabelUpdate(Series series)
|
||||
{
|
||||
@@ -119,7 +119,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color GetNameColor(Series series, int index, string name, ThemeInfo theme)
|
||||
internal static Color GetNameColor(Series series, int index, string name, ChartTheme theme)
|
||||
{
|
||||
Serie destSerie = null;
|
||||
SerieData destSerieData = null;
|
||||
@@ -188,6 +188,15 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static bool ContainsSerie(Series series, SerieType type)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.type == type) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static bool IsAnyUpdateAnimationSerie(Series series)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
@@ -236,20 +245,6 @@ namespace XCharts
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否由系列在用指定索引的axis
|
||||
/// </summary>
|
||||
/// <param name="axisIndex"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsUsedAxisIndex(Series series, int axisIndex)
|
||||
{
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.axisIndex == axisIndex) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static HashSet<string> _setForStack = new HashSet<string>();
|
||||
/// <summary>
|
||||
/// 是否由数据堆叠
|
||||
@@ -393,6 +388,19 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UpdateStackDataList(Series series, Serie currSerie, DataZoom dataZoom, List<List<SerieData>> dataList)
|
||||
{
|
||||
dataList.Clear();
|
||||
for (int i = 0; i <= currSerie.index; i++)
|
||||
{
|
||||
var serie = series.list[i];
|
||||
if (serie.type == currSerie.type && ChartHelper.IsValueEqualsString(serie.stack, currSerie.stack))
|
||||
{
|
||||
dataList.Add(serie.GetDataList(dataZoom));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得维度X的最大最小值
|
||||
/// </summary>
|
||||
@@ -401,9 +409,9 @@ namespace XCharts
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
internal static void GetXMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, out float minVaule, out float maxValue)
|
||||
bool inverse, out float minVaule, out float maxValue, bool isPolar = false)
|
||||
{
|
||||
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue);
|
||||
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue, isPolar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -414,15 +422,15 @@ namespace XCharts
|
||||
/// <param name="minVaule"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
internal static void GetYMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, out float minVaule, out float maxValue)
|
||||
bool inverse, out float minVaule, out float maxValue, bool isPolar = false)
|
||||
{
|
||||
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue);
|
||||
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue, isPolar);
|
||||
}
|
||||
|
||||
private static Dictionary<int, List<Serie>> _stackSeriesForMinMax = new Dictionary<int, List<Serie>>();
|
||||
private static Dictionary<int, float> _serieTotalValueForMinMax = new Dictionary<int, float>();
|
||||
internal static void GetMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
|
||||
bool inverse, bool yValue, out float minVaule, out float maxValue)
|
||||
bool inverse, bool yValue, out float minVaule, out float maxValue, bool isPolar = false)
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
float max = int.MinValue;
|
||||
@@ -432,8 +440,8 @@ namespace XCharts
|
||||
for (int i = 0; i < series.list.Count; i++)
|
||||
{
|
||||
var serie = series.GetSerie(i);
|
||||
if (serie.axisIndex != axisIndex) continue;
|
||||
|
||||
if ((isPolar && serie.polarIndex != axisIndex)
|
||||
|| (!isPolar && serie.yAxisIndex != axisIndex)) continue;
|
||||
if (series.IsActive(i))
|
||||
{
|
||||
if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar))
|
||||
@@ -463,7 +471,9 @@ namespace XCharts
|
||||
for (int i = 0; i < ss.Value.Count; i++)
|
||||
{
|
||||
var serie = ss.Value[i];
|
||||
if (serie.axisIndex != axisIndex || !series.IsActive(i)) continue;
|
||||
if ((isPolar && serie.polarIndex != axisIndex)
|
||||
|| (!isPolar && serie.yAxisIndex != axisIndex)
|
||||
|| !series.IsActive(i)) continue;
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
if (SeriesHelper.IsPercentStack(series, serie.stack, SerieType.Bar))
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
@@ -11,10 +11,10 @@ namespace XCharts
|
||||
{
|
||||
internal static class ThemeHelper
|
||||
{
|
||||
public static Color32 GetBackgroundColor(ThemeInfo themeInfo, Background background)
|
||||
public static Color32 GetBackgroundColor(ChartTheme theme, Background background)
|
||||
{
|
||||
if (background.show && background.runtimeActive && background.hideThemeBackgroundColor) return ChartConst.clearColor32;
|
||||
else return themeInfo.backgroundColor;
|
||||
if (background.show && background.hideThemeBackgroundColor) return ChartConst.clearColor32;
|
||||
else return theme.backgroundColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class TitleHelper
|
||||
{
|
||||
public static Font GetTextFont(Title title, ThemeInfo themeInfo)
|
||||
{
|
||||
return (title.textStyle.font != null) ? title.textStyle.font : themeInfo.font;
|
||||
}
|
||||
|
||||
public static Color GetTextColor(Title title, ThemeInfo themeInfo)
|
||||
{
|
||||
return !ChartHelper.IsClearColor(title.textStyle.color) ? title.textStyle.color : (Color)themeInfo.titleTextColor;
|
||||
}
|
||||
|
||||
public static Font GetSubTextFont(Title title, ThemeInfo themeInfo)
|
||||
{
|
||||
return (title.subTextStyle.font != null) ? title.subTextStyle.font : themeInfo.font;
|
||||
}
|
||||
|
||||
public static Color GetSubTextColor(Title title, ThemeInfo themeInfo)
|
||||
{
|
||||
return !ChartHelper.IsClearColor(title.subTextStyle.color) ? title.subTextStyle.color : (Color)themeInfo.titleSubTextColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e22859d8021f6491f8ee08339b71e577
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,9 +1,9 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
@@ -13,7 +13,7 @@ namespace XCharts
|
||||
internal static class TooltipHelper
|
||||
{
|
||||
private static void InitScatterTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ThemeInfo themeInfo)
|
||||
ChartTheme theme)
|
||||
{
|
||||
if (!tooltip.runtimeSerieIndex.ContainsKey(serie.index)) return;
|
||||
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
|
||||
@@ -29,7 +29,7 @@ namespace XCharts
|
||||
float xValue, yValue;
|
||||
serie.GetXYData(dataIndex, null, out xValue, out yValue);
|
||||
|
||||
sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>");
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>");
|
||||
if (!string.IsNullOrEmpty(serieData.name))
|
||||
sb.Append(serieData.name).Append(": ");
|
||||
sb.AppendFormat("({0},{1})", ChartCached.FloatToStr(xValue, numericFormatter),
|
||||
@@ -43,7 +43,7 @@ namespace XCharts
|
||||
|
||||
|
||||
private static void InitPieTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ThemeInfo themeInfo)
|
||||
ChartTheme theme)
|
||||
{
|
||||
if (tooltip.runtimeDataIndex[serie.index] < 0) return;
|
||||
string key = serie.data[index].name;
|
||||
@@ -56,14 +56,14 @@ namespace XCharts
|
||||
{
|
||||
sb.Append(serie.name).Append(FormatterHelper.PH_NN);
|
||||
}
|
||||
sb.Append("<color=#").Append(themeInfo.GetColorStr(index)).Append(">● </color>");
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>");
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
sb.Append(key).Append(": ");
|
||||
sb.Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
|
||||
private static void InitRingTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ThemeInfo themeInfo)
|
||||
ChartTheme theme)
|
||||
{
|
||||
var serieData = serie.GetSerieData(index);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
@@ -71,7 +71,7 @@ namespace XCharts
|
||||
sb.Length = 0;
|
||||
if (!string.IsNullOrEmpty(serieData.name))
|
||||
{
|
||||
sb.Append("<color=#").Append(themeInfo.GetColorStr(index)).Append(">● </color>")
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>")
|
||||
.Append(serieData.name).Append(": ").Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
else
|
||||
@@ -79,11 +79,36 @@ namespace XCharts
|
||||
sb.Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
}
|
||||
private static void InitGaugeTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ChartTheme theme)
|
||||
{
|
||||
if (tooltip.runtimeGridIndex >= 0) return;
|
||||
if (serie.index != index || serie.type != SerieType.Gauge) return;
|
||||
var serieData = serie.GetSerieData(0);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float value = serieData.data[1];
|
||||
sb.Length = 0;
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
{
|
||||
sb.Append(serie.name).Append("\n");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(serieData.name))
|
||||
{
|
||||
//sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>")
|
||||
sb.Append(serieData.name).Append(": ").Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitRadarTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, Radar radar,
|
||||
ThemeInfo themeInfo)
|
||||
ChartTheme theme)
|
||||
{
|
||||
if(radar == null) return;
|
||||
if (!serie.show) return;
|
||||
if (tooltip.runtimeGridIndex >= 0) return;
|
||||
if (serie.radarIndex != radar.index) return;
|
||||
var dataIndex = tooltip.runtimeDataIndex[1];
|
||||
var serieData = serie.GetSerieData(dataIndex);
|
||||
@@ -109,7 +134,7 @@ namespace XCharts
|
||||
numericFormatter = GetItemNumericFormatter(tooltip, serie, sd);
|
||||
if (!first) sb.Append("\n");
|
||||
first = false;
|
||||
sb.Append("<color=#").Append(themeInfo.GetColorStr(i)).Append(">● </color>");
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(i)).Append(">● </color>");
|
||||
if (string.IsNullOrEmpty(itemFormatter))
|
||||
{
|
||||
if (string.IsNullOrEmpty(key)) key = radar.indicatorList[dataIndex].name;
|
||||
@@ -164,7 +189,7 @@ namespace XCharts
|
||||
}
|
||||
|
||||
private static void InitCoordinateTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
ThemeInfo themeInfo, bool isCartesian, DataZoom dataZoom = null)
|
||||
ChartTheme theme, bool isCartesian, DataZoom dataZoom = null)
|
||||
{
|
||||
string key = serie.name;
|
||||
float xValue, yValue;
|
||||
@@ -185,38 +210,39 @@ namespace XCharts
|
||||
{
|
||||
var valueTxt = isIngore ? tooltip.ignoreDataDefaultContent :
|
||||
ChartCached.FloatToStr(yValue, numericFormatter);
|
||||
sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>")
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>")
|
||||
.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "")
|
||||
.Append(valueTxt);
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitDefaultContent(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
|
||||
string category, ThemeInfo themeInfo = null, DataZoom dataZoom = null, bool isCartesian = false,
|
||||
string category, ChartTheme theme = null, DataZoom dataZoom = null, bool isCartesian = false,
|
||||
Radar radar = null)
|
||||
{
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Line:
|
||||
case SerieType.Bar:
|
||||
InitCoordinateTooltip(ref sb, tooltip, serie, index, themeInfo, isCartesian, dataZoom);
|
||||
InitCoordinateTooltip(ref sb, tooltip, serie, index, theme, isCartesian, dataZoom);
|
||||
break;
|
||||
case SerieType.Scatter:
|
||||
case SerieType.EffectScatter:
|
||||
InitScatterTooltip(ref sb, tooltip, serie, index, themeInfo);
|
||||
InitScatterTooltip(ref sb, tooltip, serie, index, theme);
|
||||
break;
|
||||
case SerieType.Radar:
|
||||
InitRadarTooltip(ref sb, tooltip, serie, radar, themeInfo);
|
||||
InitRadarTooltip(ref sb, tooltip, serie, radar, theme);
|
||||
break;
|
||||
case SerieType.Pie:
|
||||
InitPieTooltip(ref sb, tooltip, serie, index, themeInfo);
|
||||
InitPieTooltip(ref sb, tooltip, serie, index, theme);
|
||||
break;
|
||||
case SerieType.Ring:
|
||||
InitRingTooltip(ref sb, tooltip, serie, index, themeInfo);
|
||||
InitRingTooltip(ref sb, tooltip, serie, index, theme);
|
||||
break;
|
||||
case SerieType.Heatmap:
|
||||
break;
|
||||
case SerieType.Gauge:
|
||||
InitGaugeTooltip(ref sb, tooltip, serie, index, theme);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -236,7 +262,7 @@ namespace XCharts
|
||||
tooltip.UpdateContentPos(pos);
|
||||
}
|
||||
|
||||
public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ThemeInfo themeInfo, AngleAxis angleAxis)
|
||||
public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ChartTheme theme, AngleAxis angleAxis)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tooltip.formatter))
|
||||
{
|
||||
@@ -260,7 +286,7 @@ namespace XCharts
|
||||
{
|
||||
if (formatTitle)
|
||||
{
|
||||
FormatterHelper.ReplaceContent(ref title, 0, tooltip.numericFormatter, serie, series, themeInfo, null, null);
|
||||
FormatterHelper.ReplaceContent(ref title, 0, tooltip.numericFormatter, serie, series, theme, null, null);
|
||||
}
|
||||
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
|
||||
|
||||
@@ -274,7 +300,7 @@ namespace XCharts
|
||||
serie.GetXYData(dataIndex, null, out xValue, out yValue);
|
||||
if (string.IsNullOrEmpty(itemFormatter))
|
||||
{
|
||||
sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>");
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>");
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
sb.Append(serie.name).Append(": ");
|
||||
sb.AppendFormat("{0}", ChartCached.FloatToStr(xValue, numericFormatter));
|
||||
@@ -286,9 +312,9 @@ namespace XCharts
|
||||
else
|
||||
{
|
||||
string content = itemFormatter;
|
||||
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, null, null);
|
||||
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, theme, null, null);
|
||||
var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ? dataIndex : serie.index;
|
||||
sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(dotColorIndex)));
|
||||
sb.Append(ChartCached.ColorToDotStr(theme.GetColor(dotColorIndex)));
|
||||
sb.Append(content);
|
||||
}
|
||||
}
|
||||
@@ -308,12 +334,12 @@ namespace XCharts
|
||||
else
|
||||
{
|
||||
string content = tooltip.formatter;
|
||||
FormatterHelper.ReplaceContent(ref content, 0, tooltip.numericFormatter, null, series, themeInfo, null, null);
|
||||
FormatterHelper.ReplaceContent(ref content, 0, tooltip.numericFormatter, null, series, theme, null, null);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo,
|
||||
public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ChartTheme theme,
|
||||
string category = null, DataZoom dataZoom = null, bool isCartesian = false, Radar radar = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tooltip.formatter))
|
||||
@@ -335,6 +361,7 @@ namespace XCharts
|
||||
for (int i = 0; i < series.Count; i++)
|
||||
{
|
||||
var serie = series.GetSerie(i);
|
||||
if (tooltip.runtimeGridIndex >= 0 && serie.runtimeGridIndex != tooltip.runtimeGridIndex) continue;
|
||||
if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter)
|
||||
{
|
||||
if (serie.show && IsSelectedSerie(tooltip, serie.index))
|
||||
@@ -344,24 +371,24 @@ namespace XCharts
|
||||
if (string.IsNullOrEmpty(itemFormatter))
|
||||
{
|
||||
if (!first) sb.Append(FormatterHelper.PH_NN);
|
||||
InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian, radar);
|
||||
InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, theme, dataZoom, isCartesian, radar);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
var itemTitle = title;
|
||||
if (!string.IsNullOrEmpty(itemTitle))
|
||||
{
|
||||
FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
|
||||
FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom);
|
||||
sb.Append(itemTitle).Append(FormatterHelper.PH_NN);
|
||||
}
|
||||
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
|
||||
foreach (var tempIndex in dataIndexList)
|
||||
{
|
||||
string content = itemFormatter;
|
||||
var foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
|
||||
var foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom);
|
||||
if (!foundDot)
|
||||
{
|
||||
sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)));
|
||||
sb.Append(ChartCached.ColorToDotStr(theme.GetColor(serie.index)));
|
||||
}
|
||||
sb.Append(content).Append(FormatterHelper.PH_NN);
|
||||
}
|
||||
@@ -369,28 +396,38 @@ namespace XCharts
|
||||
}
|
||||
else if (IsNeedTooltipSerie(serie, tooltip))
|
||||
{
|
||||
var serieData = serie.GetSerieData(dataIndex, dataZoom);
|
||||
if (serieData == null) continue;
|
||||
var itemFormatter = GetItemFormatter(tooltip, serie, serieData);
|
||||
var itemFormatter = string.Empty;
|
||||
if (serie.type == SerieType.Gauge)
|
||||
{
|
||||
var serieData = serie.GetSerieData(0, dataZoom);
|
||||
if (serieData == null) continue;
|
||||
itemFormatter = GetItemFormatter(tooltip, serie, serieData);
|
||||
}
|
||||
else
|
||||
{
|
||||
var serieData = serie.GetSerieData(dataIndex, dataZoom);
|
||||
if (serieData == null) continue;
|
||||
itemFormatter = GetItemFormatter(tooltip, serie, serieData);
|
||||
}
|
||||
needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
|
||||
if (formatTitle)
|
||||
{
|
||||
FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
|
||||
FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom);
|
||||
}
|
||||
if (serie.show)
|
||||
{
|
||||
if (string.IsNullOrEmpty(itemFormatter) || serie.type == SerieType.Radar)
|
||||
{
|
||||
if (!first) sb.Append(FormatterHelper.PH_NN);
|
||||
InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian, radar);
|
||||
InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, theme, dataZoom, isCartesian, radar);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
string content = itemFormatter;
|
||||
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
|
||||
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom);
|
||||
if (!first) sb.Append(FormatterHelper.PH_NN);
|
||||
var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ? dataIndex : i;
|
||||
sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(dotColorIndex)));
|
||||
sb.Append(ChartCached.ColorToDotStr(theme.GetColor(dotColorIndex)));
|
||||
sb.Append(content);
|
||||
first = false;
|
||||
}
|
||||
@@ -416,7 +453,7 @@ namespace XCharts
|
||||
else
|
||||
{
|
||||
string content = tooltip.formatter;
|
||||
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, null, series, themeInfo, category, dataZoom);
|
||||
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, null, series, theme, category, dataZoom);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -426,7 +463,14 @@ namespace XCharts
|
||||
//if (serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring)
|
||||
if (serie.type == SerieType.Pie || serie.type == SerieType.Ring)
|
||||
{
|
||||
return tooltip.runtimeDataIndex[serie.index] >= 0;
|
||||
if (serie.index < tooltip.runtimeDataIndex.Count)
|
||||
return tooltip.runtimeDataIndex[serie.index] >= 0;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (serie.type == SerieType.Gauge)
|
||||
{
|
||||
return serie.index == tooltip.runtimeDataIndex[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -457,7 +501,7 @@ namespace XCharts
|
||||
else return tooltip.numericFormatter;
|
||||
}
|
||||
|
||||
public static Color32 GetLineColor(Tooltip tooltip, ThemeInfo theme)
|
||||
public static Color32 GetLineColor(Tooltip tooltip, ChartTheme theme)
|
||||
{
|
||||
var lineStyle = tooltip.lineStyle;
|
||||
if (!ChartHelper.IsClearColor(lineStyle.color))
|
||||
@@ -466,10 +510,34 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = theme.tooltipLineColor;
|
||||
var color = theme.tooltip.lineColor;
|
||||
ChartHelper.SetColorOpacity(ref color, lineStyle.opacity);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetTexColor(Tooltip tooltip, ComponentTheme theme)
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(tooltip.textStyle.color))
|
||||
{
|
||||
return tooltip.textStyle.color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return theme.textColor;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetTexBackgroundColor(Tooltip tooltip, ComponentTheme theme)
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(tooltip.textStyle.backgroundColor))
|
||||
{
|
||||
return tooltip.textStyle.backgroundColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
return theme.textBackgroundColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -12,12 +12,12 @@ namespace XCharts
|
||||
{
|
||||
public static class VesselHelper
|
||||
{
|
||||
internal static Color32 GetColor(Vessel vessel, Serie serie, ThemeInfo themeInfo, List<string> legendRealShowName)
|
||||
internal static Color32 GetColor(Vessel vessel, Serie serie, ChartTheme theme, List<string> legendRealShowName)
|
||||
{
|
||||
if (serie != null && vessel.autoColor)
|
||||
{
|
||||
var colorIndex = legendRealShowName.IndexOf(serie.name);
|
||||
return SerieHelper.GetItemColor(serie, null, themeInfo, colorIndex, false);
|
||||
return SerieHelper.GetItemColor(serie, null, theme, colorIndex, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -80,22 +80,24 @@ namespace XCharts
|
||||
case VisualMap.Direction.X:
|
||||
var min = axis.runtimeMinValue;
|
||||
var max = axis.runtimeMaxValue;
|
||||
value = min + (pos.x - chart.coordinateX) / chart.coordinateWidth * (max - min);
|
||||
var grid = chart.GetAxisGridOrDefault(axis);
|
||||
value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min);
|
||||
break;
|
||||
case VisualMap.Direction.Y:
|
||||
if (axis is YAxis)
|
||||
{
|
||||
var yAxis = chart.xAxises[axis.index];
|
||||
var yAxis = chart.xAxes[axis.index];
|
||||
min = yAxis.runtimeMinValue;
|
||||
max = yAxis.runtimeMaxValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
var yAxis = chart.yAxises[axis.index];
|
||||
var yAxis = chart.yAxes[axis.index];
|
||||
min = yAxis.runtimeMinValue;
|
||||
max = yAxis.runtimeMaxValue;
|
||||
}
|
||||
value = min + (pos.y - chart.coordinateY) / chart.coordinateHeight * (max - min);
|
||||
grid = chart.GetAxisGridOrDefault(axis);
|
||||
value = min + (pos.y - grid.runtimeY) / grid.runtimeHeight * (max - min);
|
||||
break;
|
||||
}
|
||||
var color = visualMap.GetColor(value);
|
||||
@@ -107,7 +109,8 @@ namespace XCharts
|
||||
{
|
||||
var min = axis.runtimeMinValue;
|
||||
var max = axis.runtimeMaxValue;
|
||||
var value = min + (pos.x - chart.coordinateX) / chart.coordinateWidth * (max - min);
|
||||
var grid = chart.GetAxisGridOrDefault(axis);
|
||||
var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min);
|
||||
var rate = (value - min) / (max - min);
|
||||
var color = itemStyle.GetGradientColor(rate, defaultColor);
|
||||
if (ChartHelper.IsClearColor(color)) return defaultColor;
|
||||
@@ -118,7 +121,8 @@ namespace XCharts
|
||||
{
|
||||
var min = axis.runtimeMinValue;
|
||||
var max = axis.runtimeMaxValue;
|
||||
var value = min + (pos.x - chart.coordinateX) / chart.coordinateWidth * (max - min);
|
||||
var grid = chart.GetAxisGridOrDefault(axis);
|
||||
var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min);
|
||||
var rate = (value - min) / (max - min);
|
||||
var color = lineStyle.GetGradientColor(rate, defaultColor);
|
||||
if (ChartHelper.IsClearColor(color)) return defaultColor;
|
||||
|
||||
Reference in New Issue
Block a user