private void DrawCenter(VertexHelper vh, Serie serie, SerieData serieData, float insideRadius, bool last) { var itemStyle = SerieHelper.GetItemStyle(serie, serieData); if (!ChartHelper.IsClearColor(itemStyle.centerColor) && last) { var radius = insideRadius - itemStyle.centerGap; var smoothness = chart.settings.cicleSmoothness; UGL.DrawCricle(vh, serie.context.center, radius, itemStyle.centerColor, smoothness); } }
public static string GetItemNumericFormatter(Tooltip tooltip, Serie serie, SerieData serieData) { var itemStyle = SerieHelper.GetItemStyle(serie, serieData); if (!string.IsNullOrEmpty(itemStyle.numericFormatter)) { return(itemStyle.numericFormatter); } else { return(tooltip.numericFormatter); } }
public static string GetItemMarker(Serie serie, SerieData serieData, string defaultMarker = null) { var itemStyle = SerieHelper.GetItemStyle(serie, serieData); if (!string.IsNullOrEmpty(itemStyle.itemMarker)) { return(itemStyle.itemMarker); } else { return(defaultMarker); } }
private void DrawBorder(VertexHelper vh, Serie serie, SerieData serieData, float insideRadius, float outsideRadius) { var itemStyle = SerieHelper.GetItemStyle(serie, serieData); if (itemStyle.show && itemStyle.borderWidth > 0 && !ChartHelper.IsClearColor(itemStyle.borderColor)) { UGL.DrawDoughnut(vh, serie.context.center, outsideRadius, outsideRadius + itemStyle.borderWidth, itemStyle.borderColor, Color.clear, chart.settings.cicleSmoothness); UGL.DrawDoughnut(vh, serie.context.center, insideRadius, insideRadius + itemStyle.borderWidth, itemStyle.borderColor, Color.clear, chart.settings.cicleSmoothness); } }
private void DrawBackground(VertexHelper vh, Serie serie, SerieData serieData, int index, float insideRadius, float outsideRadius) { var itemStyle = SerieHelper.GetItemStyle(serie, serieData); var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, index, false); if (itemStyle.backgroundWidth != 0) { var centerRadius = (outsideRadius + insideRadius) / 2; var inradius = centerRadius - itemStyle.backgroundWidth / 2; var outradius = centerRadius + itemStyle.backgroundWidth / 2; UGL.DrawDoughnut(vh, serie.context.center, inradius, outradius, backgroundColor, Color.clear, chart.settings.cicleSmoothness); } else { UGL.DrawDoughnut(vh, serie.context.center, insideRadius, outsideRadius, backgroundColor, Color.clear, chart.settings.cicleSmoothness); } }
private void DrawBarSerie(VertexHelper vh, SimplifiedBar serie, int colorIndex) { if (!serie.show || serie.animation.HasFadeOut()) { return; } Axis axis; Axis relativedAxis; var isY = chart.GetSerieGridCoordAxis(serie, out axis, out relativedAxis); m_SerieGrid = chart.GetChartComponent <GridCoord>(axis.gridIndex); if (axis == null) { return; } if (relativedAxis == null) { return; } if (m_SerieGrid == null) { return; } var dataZoom = chart.GetDataZoomOfAxis(axis); var showData = serie.GetDataList(dataZoom); if (showData.Count <= 0) { return; } var axisLength = isY ? m_SerieGrid.context.height : m_SerieGrid.context.width; var axisXY = isY ? m_SerieGrid.context.y : m_SerieGrid.context.x; var barCount = chart.GetSerieBarRealCount <SimplifiedBar>(); float categoryWidth = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom); float barGap = chart.GetSerieBarGap <SimplifiedBar>(); float totalBarWidth = chart.GetSerieTotalWidth <SimplifiedBar>(categoryWidth, barGap, barCount); float barWidth = serie.GetBarWidth(categoryWidth, barCount); float offset = (categoryWidth - totalBarWidth) * 0.5f; float barGapWidth = barWidth + barWidth * barGap; float gap = serie.barGap == -1 ? offset : offset + serie.index * barGapWidth; int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); double yMinValue = relativedAxis.context.minValue; double yMaxValue = relativedAxis.context.maxValue; var areaColor = ColorUtil.clearColor32; var areaToColor = ColorUtil.clearColor32; var interacting = false; serie.containerIndex = m_SerieGrid.index; serie.containterInstanceId = m_SerieGrid.instanceId; serie.animation.InitProgress(axisXY, axisXY + axisLength); for (int i = serie.minShow; i < maxCount; i++) { var serieData = showData[i]; if (!serieData.show || serie.IsIgnoreValue(serieData)) { serie.context.dataPoints.Add(Vector3.zero); continue; } if (serieData.IsDataChanged()) { dataChanging = true; } var highlight = serieData.context.highlight || serie.highlight; var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); var value = axis.IsCategory() ? i : serieData.GetData(0, axis.inverse); var relativedValue = serieData.GetCurrData(1, dataChangeDuration, relativedAxis.inverse, yMinValue, yMaxValue); var borderWidth = relativedValue == 0 ? 0 : itemStyle.runtimeBorderWidth; if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting)) { areaColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, highlight); areaToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, highlight); serieData.interact.SetColor(ref interacting, areaColor, areaToColor); } var pX = 0f; var pY = 0f; UpdateXYPosition(m_SerieGrid, isY, axis, relativedAxis, i, categoryWidth, barWidth, value, ref pX, ref pY); var barHig = AxisHelper.GetAxisValueLength(m_SerieGrid, relativedAxis, categoryWidth, relativedValue); var currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig); Vector3 plb, plt, prt, prb, top; UpdateRectPosition(m_SerieGrid, isY, relativedValue, pX, pY, gap, borderWidth, barWidth, currHig, out plb, out plt, out prt, out prb, out top); serieData.context.stackHeight = barHig; serieData.context.position = top; serieData.context.rect = Rect.MinMaxRect(plb.x, plb.y, prb.x, prt.y); serie.context.dataPoints.Add(top); DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, pX, pY, plb, plt, prt, prb, false, m_SerieGrid, areaColor, areaToColor); if (serie.animation.CheckDetailBreak(top, isY)) { break; } } if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(); chart.RefreshPainter(serie); } if (dataChanging || interacting) { chart.RefreshPainter(serie); } }
private void DrawCandlestickSerie(VertexHelper vh, Candlestick serie) { if (!serie.show) { return; } if (serie.animation.HasFadeOut()) { return; } XAxis xAxis; YAxis yAxis; GridCoord grid; if (!chart.TryGetChartComponent <XAxis>(out xAxis, serie.xAxisIndex)) { return; } if (!chart.TryGetChartComponent <YAxis>(out yAxis, serie.yAxisIndex)) { return; } if (!chart.TryGetChartComponent <GridCoord>(out grid, xAxis.gridIndex)) { return; } var theme = chart.theme; var dataZoom = chart.GetDataZoomOfAxis(xAxis); var showData = serie.GetDataList(dataZoom); float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.context.width, showData.Count, dataZoom); float barWidth = serie.GetBarWidth(categoryWidth); float gap = (categoryWidth - barWidth) / 2; int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); double yMinValue = yAxis.context.minValue; double yMaxValue = yAxis.context.maxValue; var isYAxis = false; serie.containerIndex = grid.index; serie.containterInstanceId = grid.instanceId; for (int i = serie.minShow; i < maxCount; i++) { var serieData = showData[i]; if (serie.IsIgnoreValue(serieData)) { serie.context.dataPoints.Add(Vector3.zero); continue; } var highlight = serie.data[i].context.highlight || serie.highlight; var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); var open = serieData.GetCurrData(0, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue); var close = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue); var lowest = serieData.GetCurrData(2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue); var heighest = serieData.GetCurrData(3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue); var isRise = yAxis.inverse ? close <open : close> open; var borderWidth = open == 0 ? 0f : (itemStyle.runtimeBorderWidth == 0 ? theme.serie.candlestickBorderWidth : itemStyle.runtimeBorderWidth); if (serieData.IsDataChanged()) { dataChanging = true; } float pX = grid.context.x + i * categoryWidth; float zeroY = grid.context.y + yAxis.context.offset; if (!xAxis.boundaryGap) { pX -= categoryWidth / 2; } float pY = zeroY; var barHig = 0f; double valueTotal = yMaxValue - yMinValue; var minCut = (yMinValue > 0 ? yMinValue : 0); if (valueTotal != 0) { barHig = (float)((close - open) / valueTotal * grid.context.height); pY += (float)((open - minCut) / valueTotal * grid.context.height); } serieData.context.stackHeight = barHig; float currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig); Vector3 plb, plt, prt, prb, top; plb = new Vector3(pX + gap + borderWidth, pY + borderWidth); plt = new Vector3(pX + gap + borderWidth, pY + currHig - borderWidth); prt = new Vector3(pX + gap + barWidth - borderWidth, pY + currHig - borderWidth); prb = new Vector3(pX + gap + barWidth - borderWidth, pY + borderWidth); top = new Vector3(pX + gap + barWidth / 2, pY + currHig - borderWidth); if (serie.clip) { plb = chart.ClampInGrid(grid, plb); plt = chart.ClampInGrid(grid, plt); prt = chart.ClampInGrid(grid, prt); prb = chart.ClampInGrid(grid, prb); top = chart.ClampInGrid(grid, top); } serie.context.dataPoints.Add(top); var areaColor = isRise ? itemStyle.GetColor(theme.serie.candlestickColor) : itemStyle.GetColor0(theme.serie.candlestickColor0); var borderColor = isRise ? itemStyle.GetBorderColor(theme.serie.candlestickBorderColor) : itemStyle.GetBorderColor0(theme.serie.candlestickBorderColor0); var itemWidth = Mathf.Abs(prt.x - plb.x); var itemHeight = Mathf.Abs(plt.y - prb.y); var center = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2); var lowPos = new Vector3(center.x, zeroY + (float)((lowest - minCut) / valueTotal * grid.context.height)); var heighPos = new Vector3(center.x, zeroY + (float)((heighest - minCut) / valueTotal * grid.context.height)); var openCenterPos = new Vector3(center.x, prb.y); var closeCenterPos = new Vector3(center.x, prt.y); if (barWidth > 2f * borderWidth) { if (itemWidth > 0 && itemHeight > 0) { if (itemStyle.IsNeedCorner()) { UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaColor, 0, itemStyle.cornerRadius, isYAxis, 0.5f); } else { chart.DrawClipPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaColor, serie.clip, grid); } UGL.DrawBorder(vh, center, itemWidth, itemHeight, 2 * borderWidth, borderColor, 0, itemStyle.cornerRadius, isYAxis, 0.5f); } } else { UGL.DrawLine(vh, openCenterPos, closeCenterPos, Mathf.Max(borderWidth, barWidth / 2), borderColor); } if (isRise) { UGL.DrawLine(vh, openCenterPos, lowPos, borderWidth, borderColor); UGL.DrawLine(vh, closeCenterPos, heighPos, borderWidth, borderColor); } else { UGL.DrawLine(vh, closeCenterPos, lowPos, borderWidth, borderColor); UGL.DrawLine(vh, openCenterPos, heighPos, borderWidth, borderColor); } } if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(); } if (dataChanging) { chart.RefreshPainter(serie); } }
private void DrawPie(VertexHelper vh, Serie serie) { if (!serie.show || serie.animation.HasFadeOut()) { return; } var dataChanging = false; var interacting = false; var color = ColorUtil.clearColor32; var toColor = ColorUtil.clearColor32; var data = serie.data; serie.animation.InitProgress(0, 360); for (int n = 0; n < data.Count; n++) { var serieData = data[n]; if (!serieData.show) { continue; } if (serieData.IsDataChanged()) { dataChanging = true; } var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.context.highlight); var colorIndex = chart.GetLegendRealShowNameIndex(serieData.legendName); var outsideRadius = 0f; var borderWidth = itemStyle.borderWidth; var borderColor = itemStyle.borderColor; var progress = AnimationStyleHelper.CheckDataAnimation(chart, serie, n, 1); var insideRadius = serieData.context.insideRadius * progress; //if (!serieData.interact.TryGetValueAndColor(ref outsideRadius, ref color, ref toColor, ref interacting)) { color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, serieData.context.highlight); toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, serieData.context.highlight); outsideRadius = serieData.context.outsideRadius * progress; serieData.interact.SetValueAndColor(ref interacting, outsideRadius, color, toColor); } if (serie.pieClickOffset && serieData.selected) { var drawEndDegree = serieData.context.currentAngle; var needRoundCap = serie.roundCap && insideRadius > 0; UGL.DrawDoughnut(vh, serieData.context.offsetCenter, insideRadius, outsideRadius, color, toColor, Color.clear, serieData.context.startAngle, drawEndDegree, borderWidth, borderColor, serie.gap / 2, chart.settings.cicleSmoothness, needRoundCap, true); } else { var drawEndDegree = serieData.context.currentAngle; var needRoundCap = serie.roundCap && insideRadius > 0; UGL.DrawDoughnut(vh, serie.context.center, insideRadius, outsideRadius, color, toColor, Color.clear, serieData.context.startAngle, drawEndDegree, borderWidth, borderColor, serie.gap / 2, chart.settings.cicleSmoothness, needRoundCap, true); DrawPieCenter(vh, serie, itemStyle, insideRadius); } if (serie.animation.CheckDetailBreak(serieData.context.toAngle)) { break; } } if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(); serie.animation.CheckSymbol(serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize)); chart.RefreshPainter(serie); } if (dataChanging) { chart.RefreshPainter(serie); } }
public override void DrawSerie(VertexHelper vh) { if (!serie.show || serie.animation.HasFadeOut()) { return; } var data = serie.data; serie.animation.InitProgress(serie.startAngle, serie.startAngle + 360); SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); var ringWidth = serie.context.outsideRadius - serie.context.insideRadius; var dataChanging = false; for (int j = 0; j < data.Count; j++) { var serieData = data[j]; serieData.index = j; if (!serieData.show) { continue; } if (serieData.IsDataChanged()) { dataChanging = true; } var value = serieData.GetFirstData(dataChangeDuration); var max = serieData.GetLastData(); var degree = (float)(360 * value / max); var startDegree = GetStartAngle(serie); var toDegree = GetToAngle(serie, degree); var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.context.highlight); var colorIndex = chart.GetLegendRealShowNameIndex(serieData.legendName); var itemColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, serieData.context.highlight); var itemToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, serieData.context.highlight); var outsideRadius = serie.context.outsideRadius - j * (ringWidth + serie.gap); var insideRadius = outsideRadius - ringWidth; var borderWidth = itemStyle.borderWidth; var borderColor = itemStyle.borderColor; var roundCap = serie.roundCap && insideRadius > 0; serieData.context.startAngle = serie.clockwise ? startDegree : toDegree; serieData.context.toAngle = serie.clockwise ? toDegree : startDegree; serieData.context.insideRadius = insideRadius; serieData.context.outsideRadius = serieData.radius > 0 ? serieData.radius : outsideRadius; DrawBackground(vh, serie, serieData, j, insideRadius, outsideRadius); UGL.DrawDoughnut(vh, serie.context.center, insideRadius, outsideRadius, itemColor, itemToColor, Color.clear, startDegree, toDegree, borderWidth, borderColor, 0, chart.settings.cicleSmoothness, roundCap, serie.clockwise); DrawCenter(vh, serie, serieData, insideRadius, j == data.Count - 1); } if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(360); chart.RefreshChart(); } if (dataChanging) { chart.RefreshChart(); } }
private void DrawBarSerie(VertexHelper vh, Bar serie, int colorIndex) { if (!serie.show || serie.animation.HasFadeOut()) { return; } Axis axis; Axis relativedAxis; var isY = chart.GetSerieGridCoordAxis(serie, out axis, out relativedAxis); m_SerieGrid = chart.GetChartComponent <GridCoord>(axis.gridIndex); if (axis == null) { return; } if (relativedAxis == null) { return; } if (m_SerieGrid == null) { return; } var dataZoom = chart.GetDataZoomOfAxis(axis); var showData = serie.GetDataList(dataZoom); if (showData.Count <= 0) { return; } var axisLength = isY ? m_SerieGrid.context.height : m_SerieGrid.context.width; var relativedAxisLength = isY ? m_SerieGrid.context.width : m_SerieGrid.context.height; var axisXY = isY ? m_SerieGrid.context.y : m_SerieGrid.context.x; var isStack = SeriesHelper.IsStack <Bar>(chart.series, serie.stack); if (isStack) { SeriesHelper.UpdateStackDataList(chart.series, serie, dataZoom, m_StackSerieData); } var barCount = chart.GetSerieBarRealCount <Bar>(); float categoryWidth = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom); float barGap = chart.GetSerieBarGap <Bar>(); float totalBarWidth = chart.GetSerieTotalWidth <Bar>(categoryWidth, barGap, barCount); float barWidth = serie.GetBarWidth(categoryWidth, barCount); float offset = (categoryWidth - totalBarWidth) * 0.5f; var serieReadIndex = chart.GetSerieIndexIfStack <Bar>(serie); float gap = serie.barGap == -1 ? offset : offset + chart.GetSerieTotalGap <Bar>(categoryWidth, barGap, serieReadIndex); int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; var isPercentStack = SeriesHelper.IsPercentStack <Bar>(chart.series, serie.stack); bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); double yMinValue = relativedAxis.context.minValue; double yMaxValue = relativedAxis.context.maxValue; var areaColor = ColorUtil.clearColor32; var areaToColor = ColorUtil.clearColor32; var interacting = false; serie.containerIndex = m_SerieGrid.index; serie.containterInstanceId = m_SerieGrid.instanceId; serie.animation.InitProgress(axisXY, axisXY + axisLength); for (int i = serie.minShow; i < maxCount; i++) { var serieData = showData[i]; serieData.index = i; if (!serieData.show || serie.IsIgnoreValue(serieData)) { serie.context.dataPoints.Add(Vector3.zero); continue; } if (serieData.IsDataChanged()) { dataChanging = true; } var highlight = serieData.context.highlight || serie.highlight; var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); var value = axis.IsCategory() ? i : serieData.GetData(0, axis.inverse); var relativedValue = serieData.GetCurrData(1, dataChangeDuration, relativedAxis.inverse, yMinValue, yMaxValue); var borderWidth = relativedValue == 0 ? 0 : itemStyle.runtimeBorderWidth; var borderGap = relativedValue == 0 ? 0 : itemStyle.borderGap; var borderGapAndWidth = borderWidth + borderGap; if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting)) { areaColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, highlight); areaToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, highlight); serieData.interact.SetColor(ref interacting, areaColor, areaToColor); } var pX = 0f; var pY = 0f; UpdateXYPosition(m_SerieGrid, isY, axis, relativedAxis, i, categoryWidth, barWidth, isStack, value, ref pX, ref pY); var barHig = 0f; if (isPercentStack) { var valueTotal = chart.GetSerieSameStackTotalValue <Bar>(serie.stack, i); barHig = valueTotal != 0 ? (float)(relativedValue / valueTotal * relativedAxisLength) : 0; } else { barHig = AxisHelper.GetAxisValueLength(m_SerieGrid, relativedAxis, categoryWidth, relativedValue); } float currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig); Vector3 plb, plt, prt, prb, top; UpdateRectPosition(m_SerieGrid, isY, relativedValue, pX, pY, gap, borderWidth, barWidth, currHig, out plb, out plt, out prt, out prb, out top); serieData.context.stackHeight = barHig; serieData.context.position = top; serieData.context.rect = Rect.MinMaxRect(plb.x + borderGapAndWidth, plb.y + borderGapAndWidth, prt.x - borderGapAndWidth, prt.y - borderGapAndWidth); serieData.context.backgroundRect = isY ? Rect.MinMaxRect(m_SerieGrid.context.x, plb.y, m_SerieGrid.context.x + relativedAxisLength, prt.y) : Rect.MinMaxRect(plb.x, m_SerieGrid.context.y, prb.x, m_SerieGrid.context.y + relativedAxisLength); if (!serie.clip || (serie.clip && m_SerieGrid.Contains(top))) { serie.context.dataPoints.Add(top); } else { continue; } if (serie.show && currHig != 0 && !serie.placeHolder) { switch (serie.barType) { case BarType.Normal: case BarType.Capsule: DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor, relativedValue); break; case BarType.Zebra: DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor); break; } } if (serie.animation.CheckDetailBreak(top, isY)) { break; } } if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(); chart.RefreshPainter(serie); } if (dataChanging || interacting) { chart.RefreshPainter(serie); } }