/// <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); }
private static void DrawSerieLineNormalArea(VertexHelper vh, Serie serie, bool isY, float zero, float min, float max, Color32 areaColor, Color32 areaToColor, VisualMap visualMap, Axis axis, Axis relativedAxis, GridCoord grid) { var points = serie.context.drawPoints; var count = points.Count; if (count < 2) { return; } var isBreak = false; var lp = Vector3.zero; var isVisualMapGradient = VisualMapHelper.IsNeedAreaGradient(visualMap); var areaLerp = !ChartHelper.IsValueEqualsColor(areaColor, areaToColor); var zsp = isY ? new Vector3(zero, points[0].position.y) : new Vector3(points[0].position.x, zero); var zep = isY ? new Vector3(zero, points[count - 1].position.y) : new Vector3(points[count - 1].position.x, zero); var lastDataIsIgnore = false; for (int i = 0; i < points.Count; i++) { var tp = points[i].position; var isIgnore = points[i].isIgnoreBreak; var color = areaColor; var toColor = areaToColor; var lerp = areaLerp; if (serie.animation.CheckDetailBreak(tp, isY)) { isBreak = true; var progress = serie.animation.GetCurrDetail(); var ip = Vector3.zero; var axisStartPos = isY ? new Vector3(-10000, progress) : new Vector3(progress, -10000); var axisEndPos = isY ? new Vector3(10000, progress) : new Vector3(progress, 10000); if (UGLHelper.GetIntersection(lp, tp, axisStartPos, axisEndPos, ref ip)) { tp = ip; } } var zp = isY ? new Vector3(zero, tp.y) : new Vector3(tp.x, zero); if (isVisualMapGradient) { color = VisualMapHelper.GetLineGradientColor(visualMap, zp, grid, axis, relativedAxis, areaColor); toColor = VisualMapHelper.GetLineGradientColor(visualMap, tp, grid, axis, relativedAxis, areaToColor); lerp = true; } if (i > 0) { if ((lp.y - zero > 0 && tp.y - zero < 0) || (lp.y - zero < 0 && tp.y - zero > 0)) { var ip = Vector3.zero; if (UGLHelper.GetIntersection(lp, tp, zsp, zep, ref ip)) { if (lerp) { AddVertToVertexHelperWithLerpColor(vh, ip, ip, color, toColor, isY, min, max, i > 0); } else { if (lastDataIsIgnore) { UGL.AddVertToVertexHelper(vh, ip, ip, ColorUtil.clearColor32, true); } UGL.AddVertToVertexHelper(vh, ip, ip, toColor, color, i > 0); if (isIgnore) { UGL.AddVertToVertexHelper(vh, ip, ip, ColorUtil.clearColor32, true); } } } } } if (lerp) { AddVertToVertexHelperWithLerpColor(vh, tp, zp, color, toColor, isY, min, max, i > 0); } else { if (lastDataIsIgnore) { UGL.AddVertToVertexHelper(vh, tp, zp, ColorUtil.clearColor32, true); } UGL.AddVertToVertexHelper(vh, tp, zp, toColor, color, i > 0); if (isIgnore) { UGL.AddVertToVertexHelper(vh, tp, zp, ColorUtil.clearColor32, true); } } lp = tp; lastDataIsIgnore = isIgnore; if (isBreak) { break; } } }
private void DrawMakLineData(VertexHelper vh, MarkLineData data, AnimationStyle animation, Serie serie, GridCoord grid, Color32 serieColor, Vector3 sp, Vector3 ep) { if (!animation.IsFinish()) { ep = Vector3.Lerp(sp, ep, animation.GetCurrDetail()); } data.runtimeCurrentEndPosition = ep; if (sp != Vector3.zero || ep != Vector3.zero) { m_RefreshLabel = true; chart.ClampInChart(ref sp); chart.ClampInChart(ref ep); var theme = chart.theme.axis; var lineColor = ChartHelper.IsClearColor(data.lineStyle.color) ? serieColor : data.lineStyle.color; var lineWidth = data.lineStyle.width == 0 ? theme.lineWidth : data.lineStyle.width; ChartDrawer.DrawLineStyle(vh, data.lineStyle, sp, ep, lineWidth, LineStyle.Type.Dashed, lineColor, lineColor); if (data.startSymbol != null && data.startSymbol.show) { DrawMarkLineSymbol(vh, data.startSymbol, serie, grid, chart.theme, sp, sp, lineColor); } if (data.endSymbol != null && data.endSymbol.show) { DrawMarkLineSymbol(vh, data.endSymbol, serie, grid, chart.theme, ep, sp, lineColor); } } }
private static void DrawSerieLineStackArea(VertexHelper vh, Serie serie, Serie lastStackSerie, bool isY, float zero, float min, float max, Color32 color, Color32 toColor, VisualMap visualMap) { if (lastStackSerie == null) { return; } var upPoints = serie.context.drawPoints; var downPoints = lastStackSerie.context.drawPoints; var upCount = upPoints.Count; var downCount = downPoints.Count; if (upCount <= 0 || downCount <= 0) { return; } var lerp = !ChartHelper.IsValueEqualsColor(color, toColor); var ltp = upPoints[0].position; var lbp = downPoints[0].position; if (lerp) { AddVertToVertexHelperWithLerpColor(vh, ltp, lbp, color, toColor, isY, min, max, false); } else { UGL.AddVertToVertexHelper(vh, ltp, lbp, color, false); } int u = 1, d = 1; var isBreakTop = false; var isBreakBottom = false; while ((u < upCount || d < downCount)) { var tp = u < upCount ? upPoints[u].position : upPoints[upCount - 1].position; var bp = d < downCount ? downPoints[d].position : downPoints[downCount - 1].position; var tnp = (u + 1) < upCount ? upPoints[u + 1].position : upPoints[upCount - 1].position; var bnp = (d + 1) < downCount ? downPoints[d + 1].position : downPoints[downCount - 1].position; if (serie.animation.CheckDetailBreak(tp, isY)) { isBreakTop = true; var progress = serie.animation.GetCurrDetail(); var ip = Vector3.zero; if (UGLHelper.GetIntersection(ltp, tp, new Vector3(progress, -10000), new Vector3(progress, 10000), ref ip)) { tp = ip; } else { tp = new Vector3(progress, tp.y); } } if (serie.animation.CheckDetailBreak(bp, isY)) { isBreakBottom = true; var progress = serie.animation.GetCurrDetail(); var ip = Vector3.zero; if (UGLHelper.GetIntersection(lbp, bp, new Vector3(progress, -10000), new Vector3(progress, 10000), ref ip)) { bp = ip; } else { bp = new Vector3(progress, bp.y); } } if (lerp) { AddVertToVertexHelperWithLerpColor(vh, tp, bp, color, toColor, isY, min, max, true); } else { UGL.AddVertToVertexHelper(vh, tp, bp, color, true); } u++; d++; if (bp.x < tp.x && bnp.x < tp.x) { u--; } if (tp.x < bp.x && tnp.x < bp.x) { d--; } ltp = tp; lbp = bp; if (isBreakTop && isBreakBottom) { break; } } }
internal static void DrawSerieLine(VertexHelper vh, ThemeStyle theme, Serie serie, VisualMap visualMap, GridCoord grid, Axis axis, Axis relativedAxis, float lineWidth) { if (!serie.lineStyle.show || serie.lineStyle.type == LineStyle.Type.None) { return; } var datas = serie.context.drawPoints; var dataCount = datas.Count; if (dataCount < 2) { return; } var ltp = Vector3.zero; var lbp = Vector3.zero; var ntp = Vector3.zero; var nbp = Vector3.zero; var itp = Vector3.zero; var ibp = Vector3.zero; var clp = Vector3.zero; var crp = Vector3.zero; var isBreak = false; var isY = axis is YAxis; var isVisualMapGradient = VisualMapHelper.IsNeedLineGradient(visualMap); var isLineStyleGradient = serie.lineStyle.IsNeedGradient(); //var highlight = serie.highlight || serie.context.pointerEnter; var lineColor = SerieHelper.GetLineColor(serie, null, theme, serie.context.colorIndex, false); var lastDataIsIgnore = datas[0].isIgnoreBreak; var smooth = serie.lineType == LineType.Smooth; for (int i = 1; i < dataCount; i++) { var cdata = datas[i]; var isIgnore = cdata.isIgnoreBreak; var cp = cdata.position; var lp = datas[i - 1].position; var np = i == dataCount - 1 ? cp : datas[i + 1].position; if (serie.animation.CheckDetailBreak(cp, isY)) { isBreak = true; var ip = Vector3.zero; var progress = serie.animation.GetCurrDetail(); if (AnimationStyleHelper.GetAnimationPosition(serie.animation, isY, lp, cp, progress, ref ip)) { cp = np = ip; } } serie.context.lineEndPostion = cp; serie.context.lineEndValue = AxisHelper.GetAxisPositionValue(grid, relativedAxis, cp); lastDataIsIgnore = isIgnore; var handled = false; if (!smooth) { switch (serie.lineStyle.type) { case LineStyle.Type.Dashed: UGL.DrawDashLine(vh, lp, cp, lineWidth, lineColor, lineColor, 0, 0); handled = true; break; case LineStyle.Type.Dotted: UGL.DrawDotLine(vh, lp, cp, lineWidth, lineColor, lineColor, 0, 0); handled = true; break; case LineStyle.Type.DashDot: UGL.DrawDashDotLine(vh, lp, cp, lineWidth, lineColor, 0, 0, 0); handled = true; break; case LineStyle.Type.DashDotDot: UGL.DrawDashDotDotLine(vh, lp, cp, lineWidth, lineColor, 0, 0, 0); handled = true; break; case LineStyle.Type.None: handled = true; break; } } if (handled) { if (isBreak) { break; } else { continue; } } bool bitp = true, bibp = true; UGLHelper.GetLinePoints(lp, cp, np, lineWidth, ref ltp, ref lbp, ref ntp, ref nbp, ref itp, ref ibp, ref clp, ref crp, ref bitp, ref bibp, i); if (i == 1) { AddLineVertToVertexHelper(vh, ltp, lbp, lineColor, isVisualMapGradient, isLineStyleGradient, visualMap, serie.lineStyle, grid, axis, relativedAxis, false, lastDataIsIgnore, isIgnore); if (dataCount == 2 || isBreak) { AddLineVertToVertexHelper(vh, clp, crp, lineColor, isVisualMapGradient, isLineStyleGradient, visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore); serie.context.lineEndPostion = cp; serie.context.lineEndValue = AxisHelper.GetAxisPositionValue(grid, relativedAxis, cp); break; } } if (bitp == bibp) { if (bitp) { AddLineVertToVertexHelper(vh, itp, ibp, lineColor, isVisualMapGradient, isLineStyleGradient, visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore); } else { AddLineVertToVertexHelper(vh, ltp, clp, lineColor, isVisualMapGradient, isLineStyleGradient, visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore); AddLineVertToVertexHelper(vh, ltp, crp, lineColor, isVisualMapGradient, isLineStyleGradient, visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore); } } else { if (bitp) { AddLineVertToVertexHelper(vh, itp, clp, lineColor, isVisualMapGradient, isLineStyleGradient, visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore); AddLineVertToVertexHelper(vh, itp, crp, lineColor, isVisualMapGradient, isLineStyleGradient, visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore); } else if (bibp) { AddLineVertToVertexHelper(vh, clp, ibp, lineColor, isVisualMapGradient, isLineStyleGradient, visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore); AddLineVertToVertexHelper(vh, crp, ibp, lineColor, isVisualMapGradient, isLineStyleGradient, visualMap, serie.lineStyle, grid, axis, relativedAxis, true, lastDataIsIgnore, isIgnore); } } if (isBreak) { break; } } }
public Color32 GetItemColor(Serie serie, bool highlight = false) { return(SerieHelper.GetItemColor(serie, null, m_Theme, serie.context.colorIndex, highlight)); }
private void GetSerieDataIndexByAxis(Serie serie, Axis axis, GridCoord grid, int dimension = 0) { var currValue = 0d; var lastValue = 0d; var nextValue = 0d; var axisValue = axis.context.pointerValue; var isTimeAxis = axis.IsTime(); var dataCount = serie.dataCount; var themeSymbolSize = chart.theme.serie.scatterSymbolSize; var data = serie.data; if (!isTimeAxis) { serie.context.sortedData.Clear(); for (int i = 0; i < dataCount; i++) { var serieData = serie.data[i]; serieData.index = i; serie.context.sortedData.Add(serieData); } serie.context.sortedData.Sort(delegate(SerieData a, SerieData b) { return(a.GetData(dimension).CompareTo(b.GetData(dimension))); }); data = serie.context.sortedData; } serie.context.pointerAxisDataIndexs.Clear(); for (int i = 0; i < dataCount; i++) { var serieData = data[i]; currValue = serieData.GetData(dimension); if (i == 0) { nextValue = data[i + 1].GetData(dimension); if (axisValue <= currValue + (nextValue - currValue) / 2) { serie.context.pointerAxisDataIndexs.Add(serieData.index); break; } } else if (i == dataCount - 1) { if (axisValue > lastValue + (currValue - lastValue) / 2) { serie.context.pointerAxisDataIndexs.Add(serieData.index); break; } } else { nextValue = data[i + 1].GetData(dimension); if (axisValue > (currValue - (currValue - lastValue) / 2) && axisValue <= currValue + (nextValue - currValue) / 2) { serie.context.pointerAxisDataIndexs.Add(serieData.index); break; } } lastValue = currValue; } if (serie.context.pointerAxisDataIndexs.Count > 0) { var index = serie.context.pointerAxisDataIndexs[0]; serie.context.pointerItemDataIndex = index; axis.context.axisTooltipValue = serie.GetSerieData(index).GetData(dimension); } else { serie.context.pointerItemDataIndex = -1; axis.context.axisTooltipValue = 0; } }
private float GetStartAngle(Serie serie) { return(serie.clockwise ? serie.startAngle : 360 - serie.startAngle); }
private static void UpdateFilterData_Category(Serie serie, DataZoom dataZoom) { var data = serie.data; var range = Mathf.RoundToInt(data.Count * (dataZoom.end - dataZoom.start) / 100); if (range <= 0) { range = 1; } int start = 0, end = 0; if (dataZoom.context.invert) { end = Mathf.CeilToInt(data.Count * dataZoom.end / 100); start = end - range; if (start < 0) { start = 0; } } else { start = Mathf.FloorToInt(data.Count * dataZoom.start / 100); end = start + range; if (end > data.Count) { end = data.Count; } } if (start != serie.m_FilterStart || end != serie.m_FilterEnd || dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData) { serie.m_FilterStart = start; serie.m_FilterEnd = end; serie.m_FilterMinShow = dataZoom.minShowNum; serie.m_NeedUpdateFilterData = false; if (data.Count > 0) { if (range < dataZoom.minShowNum) { if (dataZoom.minShowNum > data.Count) { range = data.Count; } else { range = dataZoom.minShowNum; } } if (range > data.Count - start - 1) { start = data.Count - range - 1; } if (start >= 0) { serie.context.dataZoomStartIndex = start; serie.m_FilterData = data.GetRange(start, range); } else { serie.context.dataZoomStartIndex = 0; serie.m_FilterData = data; } } else { serie.context.dataZoomStartIndex = 0; serie.m_FilterData = data; } } else if (end == 0) { serie.context.dataZoomStartIndex = 0; serie.m_FilterData = emptyFilter; } }
public bool CovertSerie <T>(Serie serie) where T : Serie { return(CovertSerie(serie, typeof(T))); }
private void AddSerieAfterDeserialize(Serie serie) { serie.OnAfterDeserialize(); m_Series.Add(serie); }
public static SimplifiedCandlestick CovertSerie(Serie serie) { var newSerie = serie.Clone <SimplifiedCandlestick>(); return(newSerie); }