public static void AddChart(BaseChart chart) { var sameNameChart = GetChart(chart.chartName); if (sameNameChart != null) { var path = ChartHelper.GetFullName(sameNameChart.transform); Debug.LogError("A chart named `" + chart.chartName + "` already exists:" + path); RemoveChart(chart.chartName); } if (!ContainsChart(chart)) { chartList.Add(chart); } }
public static Serie AddDefaultSerie(BaseChart chart, string serieName) { var serie = chart.AddSerie <Candlestick>(serieName); var defaultDataCount = 5; for (int i = 0; i < defaultDataCount; i++) { var open = Random.Range(20, 60); var close = Random.Range(40, 90); var lowest = Random.Range(0, 50); var heighest = Random.Range(50, 100); chart.AddData(serie.index, open, close, lowest, heighest); } return(serie); }
public static Serie AddDefaultSerie(BaseChart chart, string serieName) { var serie = chart.AddSerie <Heatmap>(serieName); serie.itemStyle.show = true; serie.itemStyle.borderWidth = 1; serie.itemStyle.borderColor = Color.clear; var emphasis = serie.AddExtraComponent <EmphasisItemStyle>(); emphasis.show = true; emphasis.borderWidth = 1; emphasis.borderColor = Color.black; return(serie); }
public static void SwitchTheme(BaseChart chart, string themeName) { #if UNITY_EDITOR if (XChartsMgr.themes.Count == 0) { ReloadThemeList(); } #endif if (!XChartsMgr.themes.ContainsKey(themeName)) { Debug.LogError("SwitchTheme ERROR: not exist theme:" + themeName); return; } var target = XChartsMgr.themes[themeName]; chart.UpdateTheme(target); }
public static Serie AddDefaultSerie(BaseChart chart, string serieName) { var serie = chart.AddSerie <SimplifiedCandlestick>(serieName); var lastValue = 50d; for (int i = 0; i < 50; i++) { lastValue += UnityEngine.Random.Range(-10, 20); var open = lastValue + Random.Range(-10, 5); var close = lastValue + Random.Range(-5, 10); var lowest = lastValue + Random.Range(-15, -10); var heighest = lastValue + Random.Range(10, 20); chart.AddData(serie.index, open, close, lowest, heighest); } return(serie); }
public static string GetRepeatChartNameInfo(BaseChart chart, string chartName) { if (string.IsNullOrEmpty(chartName)) { return(string.Empty); } string result = ""; foreach (var temp in chartList) { if (temp != chart && chartName.Equals(temp.chartName)) { result += ChartHelper.GetFullName(temp.transform) + "\n"; } } return(result); }
internal static void ResetTooltipParamsByItemFormatter(Tooltip tooltip, BaseChart chart) { if (!string.IsNullOrEmpty(tooltip.titleFormatter)) { if (IsIgnoreFormatter(tooltip.titleFormatter)) { tooltip.context.data.title = string.Empty; } else { tooltip.context.data.title = tooltip.titleFormatter; FormatterHelper.ReplaceContent(ref tooltip.context.data.title, 0, tooltip.numericFormatter, null, chart); } } for (int i = tooltip.context.data.param.Count - 1; i >= 0; i--) { var param = tooltip.context.data.param[i]; if (IsIgnoreFormatter(param.itemFormatter)) { tooltip.context.data.param.RemoveAt(i); } } foreach (var param in tooltip.context.data.param) { if (!string.IsNullOrEmpty(param.itemFormatter)) { param.columns.Clear(); var content = param.itemFormatter; FormatterHelper.ReplaceSerieLabelContent(ref content, param.numericFormatter, param.dataCount, param.value, param.total, param.serieName, param.category, param.serieData.name, param.color, param.serieData); foreach (var item in content.Split('|')) { param.columns.Add(item); } } } }
public static Serie AddDefaultSerie(BaseChart chart, string serieName) { chart.AddChartComponentWhenNoExist <RadarCoord>(); var serie = chart.AddSerie <Radar>(serieName); serie.symbol.show = true; serie.symbol.type = SymbolType.Circle; serie.showDataName = true; List <double> data = new List <double>(); for (int i = 0; i < 5; i++) { data.Add(Random.Range(20, 90)); } chart.AddData(serie.index, data, "legendName"); return(serie); }
public static Color GetIconColor(BaseChart chart, Legend legend, int readIndex, string legendName, bool active) { if (active) { if (legend.itemAutoColor) { return(SeriesHelper.GetNameColor(chart, readIndex, legendName)); } else { return(legend.GetColor(readIndex)); } } else { return(chart.theme.legend.unableColor); } }
public static LegendItem AddLegendItem(BaseChart chart, Legend legend, int i, string legendName, Transform parent, ThemeStyle theme, string content, Color itemColor, bool active, int legendIndex) { var objName = i + "_" + legendName; var anchorMin = new Vector2(0, 0.5f); var anchorMax = new Vector2(0, 0.5f); var pivot = new Vector2(0, 0.5f); var sizeDelta = new Vector2(100, 30); var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight); var textStyle = legend.labelStyle.textStyle; var contentColor = GetContentColor(chart, legendIndex, legendName, legend, theme, active); var objAnchorMin = new Vector2(0, 1); var objAnchorMax = new Vector2(0, 1); var objPivot = new Vector2(0, 1); var btnObj = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta); var iconObj = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta); var img = ChartHelper.GetOrAddComponent <Image>(btnObj); img.color = Color.clear; img.raycastTarget = true; ChartHelper.GetOrAddComponent <Button>(btnObj); ChartHelper.GetOrAddComponent <Image>(iconObj); var label = ChartHelper.AddChartLabel("content", btnObj.transform, legend.labelStyle, theme.legend, content, contentColor, TextAnchor.MiddleLeft); label.SetActive(true); var item = new LegendItem(); item.index = i; item.name = objName; item.legendName = legendName; item.SetObject(btnObj); item.SetIconSize(legend.itemWidth, legend.itemHeight); item.SetIconColor(itemColor); item.SetIconImage(legend.GetIcon(i)); item.SetContentPosition(legend.labelStyle.offset); item.SetContent(content); //item.SetBackground(legend.background); return(item); }
public static bool IsRepeatChartName(BaseChart chart, string chartName = null) { if (chartName == null) { chartName = chart.chartName; } if (string.IsNullOrEmpty(chartName)) { return(false); } foreach (var temp in chartList) { if (temp != chart && chartName.Equals(temp.chartName)) { return(true); } } return(false); }
/// <summary> /// 获得所有系列名,不包含空名字。 /// </summary> /// <returns></returns> public static void UpdateSerieNameList(BaseChart chart, ref List <string> serieNameList) { serieNameList.Clear(); for (int n = 0; n < chart.series.Count; n++) { var serie = chart.series[n]; if (serie.placeHolder) { continue; } if (serie.useDataNameForColor) { for (int i = 0; i < serie.data.Count; i++) { var serieData = serie.data[i]; if (serie is Pie && serie.IsIgnoreValue(serieData)) { continue; } if (string.IsNullOrEmpty(serieData.name)) { serieNameList.Add(ChartCached.IntToStr(i)); } else if (!serieNameList.Contains(serieData.name)) { serieNameList.Add(serieData.name); } } } else { if (string.IsNullOrEmpty(serie.serieName)) { serieNameList.Add(ChartCached.IntToStr(n)); } else if (!serieNameList.Contains(serie.serieName)) { serieNameList.Add(serie.serieName); } } } }
public static Color GetContentColor(BaseChart chart, int legendIndex, string legendName, Legend legend, ThemeStyle theme, bool active) { var textStyle = legend.labelStyle.textStyle; if (active) { if (legend.labelStyle.textStyle.autoColor) { return(SeriesHelper.GetNameColor(chart, legendIndex, legendName)); } else { return(!ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor); } } else { return(theme.legend.unableColor); } }
public static Serie AddDefaultSerie(BaseChart chart, string serieName) { var serie = chart.AddSerie <SimplifiedBar>(serieName); serie.symbol.show = false; var lastValue = 0d; for (int i = 0; i < 50; i++) { if (i < 20) { lastValue += UnityEngine.Random.Range(0, 5); } else { lastValue += UnityEngine.Random.Range(-3, 5); } chart.AddData(serie.index, lastValue); } return(serie); }
public static Serie AddDefaultSerie(BaseChart chart, string serieName) { var serie = chart.AddSerie <Parallel>(serieName); serie.lineStyle.width = 0.8f; serie.lineStyle.opacity = 0.6f; for (int i = 0; i < 100; i++) { var data = new List <double>() { Random.Range(0f, 50f), Random.Range(0f, 100f), Random.Range(0f, 1000f), Random.Range(0, 5), }; serie.AddData(data, "data" + i); } chart.RefreshChart(); return(serie); }
public static float CheckDataAnimation(BaseChart chart, Serie serie, int dataIndex, float destProgress, float startPorgress = 0) { if (!serie.animation.IsItemAnimation()) { serie.animation.context.isAllItemAnimationEnd = false; return(destProgress); } if (serie.animation.IsFinish()) { serie.animation.context.isAllItemAnimationEnd = false; return(destProgress); } var isDataAnimationEnd = true; var currHig = serie.animation.CheckItemProgress(dataIndex, destProgress, ref isDataAnimationEnd, startPorgress); if (!isDataAnimationEnd) { serie.animation.context.isAllItemAnimationEnd = false; } return(currHig); }
public static Color GetNameColor(BaseChart chart, int index, string name) { Serie destSerie = null; SerieData destSerieData = null; var series = chart.series; for (int n = 0; n < series.Count; n++) { var serie = series[n]; if (serie.placeHolder) { continue; } if (serie.useDataNameForColor) { bool found = false; for (int i = 0; i < serie.data.Count; i++) { if (name.Equals(serie.data[i].name)) { destSerie = serie; destSerieData = serie.data[i]; found = true; break; } } if (found) { break; } } if (name.Equals(serie.serieName)) { destSerie = serie; destSerieData = null; break; } } return(SerieHelper.GetItemColor(destSerie, destSerieData, chart.theme, index, false)); }
private static void CheckSerie(BaseChart chart, StringBuilder sb) { var allDataIsEmpty = true; var allDataIsZero = true; var allSerieIsHide = true; foreach (var serie in chart.series) { if (serie.show) { allSerieIsHide = false; } if (serie.dataCount > 0) { allDataIsEmpty = false; for (int i = 0; i < serie.dataCount; i++) { var serieData = serie.GetSerieData(i); for (int j = 1; j < serieData.data.Count; j++) { if (serieData.GetData(j) != 0) { allDataIsZero = false; break; } } } var dataCount = serie.GetSerieData(0).data.Count; if (serie.showDataDimension > 1 && serie.showDataDimension != dataCount) { sb.AppendFormat("warning:serie {0} serieData.data.count[{1}] not match showDataDimension[{2}]\n", serie.index, dataCount, serie.showDataDimension); } } else { sb.AppendFormat("warning:serie {0} no data\n", serie.index); } if (IsColorAlphaZero(serie.itemStyle.color)) { sb.AppendFormat("warning:serie {0} itemStyle->color alpha is 0\n", serie.index); } if (serie.itemStyle.opacity == 0) { sb.AppendFormat("warning:serie {0} itemStyle->opacity is 0\n", serie.index); } if (serie.itemStyle.borderWidth != 0 && IsColorAlphaZero(serie.itemStyle.borderColor)) { sb.AppendFormat("warning:serie {0} itemStyle->borderColor alpha is 0\n", serie.index); } if (serie is Line) { if (serie.lineStyle.opacity == 0) { sb.AppendFormat("warning:serie {0} lineStyle->opacity is 0\n", serie.index); } if (IsColorAlphaZero(serie.lineStyle.color)) { sb.AppendFormat("warning:serie {0} lineStyle->color alpha is 0\n", serie.index); } } else if (serie is Pie) { if (serie.radius.Length >= 2 && serie.radius[1] == 0) { sb.AppendFormat("warning:serie {0} radius[1] is 0\n", serie.index); } } else if (serie is Scatter || serie is EffectScatter) { if (!serie.symbol.show) { sb.AppendFormat("warning:serie {0} symbol type is None\n", serie.index); } } } if (allDataIsEmpty) { sb.Append("warning:all serie data is empty\n"); } if (!allDataIsEmpty && allDataIsZero) { sb.Append("warning:all serie data is 0\n"); } if (allSerieIsHide) { sb.Append("warning:all serie is hide\n"); } }
private static void CheckGrid(BaseChart chart, StringBuilder sb) { }
private static void CheckTheme(BaseChart chart, StringBuilder sb) { var theme = chart.theme; theme.CheckWarning(sb); }
public static bool ContainsChart(BaseChart chart) { return(chartList.Contains(chart)); }
public void Init(BaseChart chart) { m_Chart = chart; m_Label = AddDebugInfoObject("debug", chart.transform, m_LabelStyle, chart.theme); }
/// <summary> /// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。 /// </summary> /// <param name="content">要替换的字符串</param> /// <param name="dataIndex">选中的数据项serieData索引</param> /// <param name="numericFormatter">默认的数字格式化</param> /// <param name="serie">选中的serie</param> /// <param name="series">所有serie</param> /// <param name="theme">用来获取指定index的颜色</param> /// <param name="category">选中的类目,一般用在折线图和柱状图</param> /// <param name="dataZoom">dataZoom</param> /// <returns></returns> public static bool ReplaceContent(ref string content, int dataIndex, string numericFormatter, Serie serie, BaseChart chart, DataZoom dataZoom = null) { var foundDot = false; var mc = s_Regex.Matches(content); foreach (var m in mc) { var old = m.ToString(); var args = s_RegexSub.Matches(m.ToString()); var argsCount = args.Count; if (argsCount <= 0) { continue; } int targetIndex = 0; char p = GetSerieIndex(args[0].ToString(), ref targetIndex); if (targetIndex >= 0) { serie = chart.GetSerie(targetIndex); if (serie == null) { continue; } } else if (serie != null) { targetIndex = serie.index; } else { serie = chart.GetSerie(0); targetIndex = 0; } if (serie == null) { continue; } if (p == '.') { var bIndex = targetIndex; if (argsCount >= 2) { var args1Str = args[1].ToString(); if (s_RegexN.IsMatch(args1Str)) { bIndex = int.Parse(args1Str); } } content = content.Replace(old, ChartCached.ColorToDotStr(chart.theme.GetColor(bIndex))); foundDot = true; } else if (p == 'a' || p == 'A') { if (argsCount == 1) { content = content.Replace(old, serie.serieName); } } else if (p == 'b' || p == 'B' || p == 'e' || p == 'E') { var bIndex = dataIndex; if (argsCount >= 2) { var args1Str = args[1].ToString(); if (s_RegexN.IsMatch(args1Str)) { bIndex = int.Parse(args1Str); } } var needCategory = (p != 'e' && p != 'E') && (serie is Line || serie is Bar); if (needCategory) { var category = chart.GetTooltipCategory(dataIndex, serie, dataZoom); content = content.Replace(old, category); } else { var serieData = serie.GetSerieData(bIndex, dataZoom); content = content.Replace(old, serieData.name); } } else if (p == 'g' || p == 'G') { content = content.Replace(old, ChartCached.NumberToStr(serie.dataCount, "")); } else if (p == 'c' || p == 'C' || p == 'd' || p == 'D' || p == 'f' || p == 'f') { var isPercent = p == 'd' || p == 'D'; var isTotal = p == 'f' || p == 'f'; var bIndex = dataIndex; var dimensionIndex = -1; if (argsCount >= 2) { var args1Str = args[1].ToString(); if (s_RegexFn.IsMatch(args1Str)) { numericFormatter = args1Str; } else if (s_RegexN_N.IsMatch(args1Str)) { var temp = args1Str.Split('-'); bIndex = int.Parse(temp[0]); dimensionIndex = int.Parse(temp[1]); } else if (s_RegexN.IsMatch(args1Str)) { dimensionIndex = int.Parse(args1Str); } else { Debug.LogError("unmatch:" + args1Str); continue; } } if (argsCount >= 3) { numericFormatter = args[2].ToString(); } if (dimensionIndex == -1) { dimensionIndex = 1; } if (numericFormatter == string.Empty) { numericFormatter = SerieHelper.GetNumericFormatter(serie, serie.GetSerieData(bIndex), ""); } var value = serie.GetData(bIndex, dimensionIndex, dataZoom); if (isPercent) { var total = serie.GetDataTotal(dimensionIndex, serie.GetSerieData(bIndex)); var percent = total == 0 ? 0 : value / serie.yTotal * 100; content = content.Replace(old, ChartCached.FloatToStr(percent, numericFormatter)); } else if (isTotal) { var total = serie.GetDataTotal(dimensionIndex, serie.GetSerieData(bIndex)); content = content.Replace(old, ChartCached.FloatToStr(total, numericFormatter)); } else { content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter)); } } } content = s_RegexNewLine.Replace(content, PH_NN); return(foundDot); }
public static Color32 GetItemStyleGradientColor(ItemStyle itemStyle, Vector3 pos, BaseChart chart, Axis axis, Color32 defaultColor) { var min = axis.context.minValue; var max = axis.context.maxValue; var grid = chart.GetChartComponent <GridCoord>(axis.gridIndex); var value = min + (pos.x - grid.context.x) / grid.context.width * (max - min); var rate = (value - min) / (max - min); var color = itemStyle.GetGradientColor((float)rate, defaultColor); if (ChartHelper.IsClearColor(color)) { return(defaultColor); } else { return(color); } }