protected void DrawGanttSerie(VertexHelper vh, int colorIndex, Serie serie) { if (!IsActive(serie.index)) { return; } if (serie.animation.HasFadeOut()) { return; } var showData = serie.GetDataList(null); var yAxis = m_YAxes[serie.yAxisIndex]; var xAxis = m_XAxes[serie.xAxisIndex]; var grid = GetSerieGridOrDefault(serie); var xCategoryWidth = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, showData.Count, dataZoom); var yCategoryWidth = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, showData.Count, dataZoom); var barGap = GetBarGap(); var barWidth = serie.GetBarWidth(yCategoryWidth); var space = (yCategoryWidth - barWidth) / 2; var dataChanging = false; var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); var minValue = xAxis.GetCurrMinValue(dataChangeDuration); var maxValue = xAxis.GetCurrMaxValue(dataChangeDuration); var pX = grid.runtimeX + (xAxis.boundaryGap ? xCategoryWidth / 2 : 0); var pY = 0f; var startY = grid.runtimeY - (yAxis.boundaryGap ? 0 : yCategoryWidth / 2); var isTime = xAxis.type == Axis.AxisType.Time; var categoryIndex = GetGanttSerieCategoryIndex(serie, grid.index); var dataCount = serie.data.Count; for (int i = 0; i < dataCount; i++) { var serieData = serie.data[i]; pY = startY + (categoryIndex - 1 - i) * yCategoryWidth; DrawSerieData(vh, grid, serie, serieData, colorIndex, pX, pY, space, barWidth, isTime, minValue, maxValue, xCategoryWidth); } if (dataChanging) { RefreshPainter(serie); } }
public static float GetAxisPosition(Grid grid, Axis axis, double value, int dataCount = 0, DataZoom dataZoom = null) { var gridHeight = axis is YAxis ? grid.runtimeHeight : grid.runtimeWidth; var gridXY = axis is YAxis ? grid.runtimeY : grid.runtimeX; if (axis.IsCategory()) { if (dataCount == 0) { dataCount = axis.data.Count; } var categoryIndex = (int)value; var scaleWid = AxisHelper.GetDataWidth(axis, grid.runtimeHeight, dataCount, dataZoom); float startY = gridXY + (axis.boundaryGap ? scaleWid / 2 : 0); return(startY + scaleWid * categoryIndex); } else { var yDataHig = (axis.runtimeMinMaxRange == 0) ? 0f : (float)((value - axis.runtimeMinValue) / axis.runtimeMinMaxRange * gridHeight); return(gridXY + yDataHig); } }
protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex) { if (!IsActive(serie.name)) { return; } if (serie.animation.HasFadeOut()) { return; } var xAxis = m_XAxes[serie.xAxisIndex]; var yAxis = m_YAxes[serie.yAxisIndex]; var grid = GetSerieGridOrDefault(serie); var showData = serie.GetDataList(dataZoom); float categoryWidth = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, showData.Count, dataZoom); float barGap = Internal_GetBarGap(SerieType.Bar); float totalBarWidth = Internal_GetBarTotalWidth(categoryWidth, barGap, SerieType.Bar); float barWidth = serie.GetBarWidth(categoryWidth); float offset = (categoryWidth - totalBarWidth) / 2; float barGapWidth = barWidth + barWidth * barGap; float space = serie.barGap == -1 ? offset : offset + Internal_GetBarIndex(serie, SerieType.Bar) * barGapWidth; var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar); m_StackSerieData.Clear(); if (isStack) { SeriesHelper.UpdateStackDataList(m_Series, serie, dataZoom, m_StackSerieData); } int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar); bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration); float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration); var isAllBarEnd = true; for (int i = serie.minShow; i < maxCount; i++) { var serieData = showData[i]; if (serie.IsIgnoreValue(serieData)) { serie.dataPoints.Add(Vector3.zero); continue; } var highlight = (tooltip.show && tooltip.IsSelected(i)) || serie.data[i].highlighted || serie.highlighted; var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); serieData.canShowLabel = true; float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xMinValue, xMaxValue); float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth; if (showData[i].IsDataChanged()) { dataChanging = true; } float axisLineWidth = value == 0 ? 0 : ((value < 0 ? -1 : 1) * yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth)); float pY = grid.runtimeY + i * categoryWidth; if (!yAxis.boundaryGap) { pY -= categoryWidth / 2; } float pX = grid.runtimeX + xAxis.runtimeZeroXOffset + axisLineWidth; if (isStack) { for (int n = 0; n < m_StackSerieData.Count - 1; n++) { pX += m_StackSerieData[n][i].runtimeStackHig; } } var barHig = 0f; var valueTotal = 0f; if (isPercentStack) { valueTotal = Internal_GetBarSameStackTotalValue(serie.stack, i, SerieType.Bar); barHig = valueTotal != 0 ? (value / valueTotal * grid.runtimeWidth) : 0; } else { if (yAxis.IsLog()) { int minIndex = xAxis.runtimeMinLogIndex; float nowIndex = xAxis.GetLogValue(value); barHig = (nowIndex - minIndex) / xAxis.splitNumber * grid.runtimeWidth; } else { valueTotal = xMaxValue - xMinValue; if (valueTotal != 0) { barHig = (xMinValue > 0 ? value - xMinValue : value) / valueTotal * grid.runtimeWidth; } } } serieData.runtimeStackHig = barHig; var isBarEnd = false; float currHig = Internal_CheckBarAnimation(serie, i, barHig, out isBarEnd); if (!isBarEnd) { isAllBarEnd = false; } Vector3 plt, prt, prb, plb, top; if (value < 0) { plt = new Vector3(pX - borderWidth, pY + space + barWidth - borderWidth); prt = new Vector3(pX + currHig + borderWidth, pY + space + barWidth - borderWidth); prb = new Vector3(pX + currHig + borderWidth, pY + space + borderWidth); plb = new Vector3(pX - borderWidth, pY + space + borderWidth); } else { plt = new Vector3(pX + borderWidth, pY + space + barWidth - borderWidth); prt = new Vector3(pX + currHig - borderWidth, pY + space + barWidth - borderWidth); prb = new Vector3(pX + currHig - borderWidth, pY + space + borderWidth); plb = new Vector3(pX + borderWidth, pY + space + borderWidth); } top = new Vector3(pX + currHig - borderWidth, pY + space + barWidth / 2); if (serie.clip) { plt = ClampInGrid(grid, plt); prt = ClampInGrid(grid, prt); prb = ClampInGrid(grid, prb); plb = ClampInGrid(grid, plb); top = ClampInGrid(grid, top); } serie.dataPoints.Add(top); if (serie.show) { switch (serie.barType) { case BarType.Normal: DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, pX, pY, plb, plt, prt, prb, true, grid); break; case BarType.Zebra: DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, pX, pY, plb, plt, prt, prb, true, grid); break; case BarType.Capsule: DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, pX, pY, plb, plt, prt, prb, true, grid); break; } } } if (isAllBarEnd) { serie.animation.AllBarEnd(); } if (dataChanging) { RefreshPainter(serie); } }
protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List <float> seriesHig) { if (!IsActive(serie.index)) { return; } if (serie.animation.HasFadeOut()) { return; } var showData = serie.GetDataList(m_DataZoom); var yAxis = m_YAxises[serie.axisIndex]; var xAxis = m_XAxises[serie.axisIndex]; if (!xAxis.show) { xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count]; } float categoryWidth = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, showData.Count, m_DataZoom); float barGap = GetBarGap(); float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap); float barWidth = serie.GetBarWidth(categoryWidth); float offset = (categoryWidth - totalBarWidth) / 2; float barGapWidth = barWidth + barWidth * barGap; float space = serie.barGap == -1 ? offset : offset + m_BarLastOffset; int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) : showData.Count; if (seriesHig.Count < serie.minShow) { for (int i = 0; i < serie.minShow; i++) { seriesHig.Add(0); } } var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar); bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration); float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration); for (int i = serie.minShow; i < maxCount; i++) { if (i >= seriesHig.Count) { seriesHig.Add(0); } var serieData = showData[i]; if (serie.IsIgnoreValue(serieData.GetData(1))) { serie.dataPoints.Add(Vector3.zero); continue; } var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) || serie.data[i].highlighted || serie.highlighted; var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); float value = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse); float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth; if (serieData.IsDataChanged()) { dataChanging = true; } float pX = m_CoordinateX + i * categoryWidth; float zeroY = m_CoordinateY + yAxis.runtimeZeroYOffset; if (!xAxis.boundaryGap) { pX -= categoryWidth / 2; } float axisLineWidth = (value < 0 ? -1 : 1) * xAxis.axisLine.width; float pY = seriesHig[i] + zeroY + axisLineWidth; var barHig = 0f; var valueTotal = 0f; if (isPercentStack) { valueTotal = GetSameStackTotalValue(serie.stack, i); barHig = valueTotal != 0 ? (value / valueTotal * m_CoordinateHeight) : 0; seriesHig[i] += barHig; } else { valueTotal = yMaxValue - yMinValue; if (valueTotal != 0) { barHig = (yMinValue > 0 ? value - yMinValue : value) / valueTotal * m_CoordinateHeight; } seriesHig[i] += barHig; } float currHig = CheckAnimation(serie, i, barHig); Vector3 plb, plt, prt, prb, top; if (value < 0) { plb = new Vector3(pX + space + borderWidth, pY - borderWidth); plt = new Vector3(pX + space + borderWidth, pY + currHig + borderWidth - axisLineWidth); prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig + borderWidth - axisLineWidth); prb = new Vector3(pX + space + barWidth - borderWidth, pY - borderWidth); } else { plb = new Vector3(pX + space + borderWidth, pY + borderWidth); plt = new Vector3(pX + space + borderWidth, pY + currHig - borderWidth - axisLineWidth); prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth - axisLineWidth); prb = new Vector3(pX + space + barWidth - borderWidth, pY + borderWidth); } top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth); if (serie.clip) { plb = ClampInCoordinate(plb); plt = ClampInCoordinate(plt); prt = ClampInCoordinate(prt); prb = ClampInCoordinate(prb); top = ClampInCoordinate(top); } serie.dataPoints.Add(top); if (serie.show) { switch (serie.barType) { case BarType.Normal: DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, pX, pY, plb, plt, prt, prb, false); break; case BarType.Zebra: DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, pX, pY, plb, plt, prt, prb, false); break; case BarType.Capsule: DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, pX, pY, plb, plt, prt, prb, false); break; } } } if (dataChanging) { RefreshChart(); } if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar)) { m_BarLastOffset += barGapWidth; } }
protected void DrawCandlestickSerie(VertexHelper vh, int colorIndex, Serie serie) { if (!IsActive(serie.index)) { return; } if (serie.animation.HasFadeOut()) { return; } var showData = serie.GetDataList(dataZoom); var yAxis = m_YAxes[serie.yAxisIndex]; var xAxis = m_XAxes[serie.xAxisIndex]; var grid = GetSerieGridOrDefault(serie); float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, showData.Count, dataZoom); float barWidth = serie.GetBarWidth(categoryWidth); float space = (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(); float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration); float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration); var isAllBarEnd = true; var isYAxis = false; for (int i = serie.minShow; i < maxCount; i++) { var serieData = showData[i]; if (serie.IsIgnoreValue(serieData.GetData(1))) { serie.dataPoints.Add(Vector3.zero); continue; } var highlight = (tooltip.show && tooltip.IsSelected(i)) || serie.data[i].highlighted || serie.highlighted; 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 = close > open; var borderWidth = open == 0 ? 0f : (itemStyle.runtimeBorderWidth == 0 ? m_Theme.serie.candlestickBorderWidth : itemStyle.runtimeBorderWidth); if (serieData.IsDataChanged()) { dataChanging = true; } float pX = grid.runtimeX + i * categoryWidth; float zeroY = grid.runtimeY + yAxis.runtimeZeroYOffset; if (!xAxis.boundaryGap) { pX -= categoryWidth / 2; } float pY = zeroY; var barHig = 0f; var valueTotal = yMaxValue - yMinValue; var minCut = (yMinValue > 0 ? yMinValue : 0); if (valueTotal != 0) { barHig = (close - open) / valueTotal * grid.runtimeHeight; pY += (open - minCut) / valueTotal * grid.runtimeHeight; } serieData.runtimeStackHig = barHig; var isBarEnd = false; float currHig = CheckAnimation(serie, i, barHig, out isBarEnd); if (!isBarEnd) { isAllBarEnd = false; } Vector3 plb, plt, prt, prb, top; plb = new Vector3(pX + space + borderWidth, pY + borderWidth); plt = new Vector3(pX + space + borderWidth, pY + currHig - borderWidth); prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth); prb = new Vector3(pX + space + barWidth - borderWidth, pY + borderWidth); top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth); if (serie.clip) { plb = ClampInGrid(grid, plb); plt = ClampInGrid(grid, plt); prt = ClampInGrid(grid, prt); prb = ClampInGrid(grid, prb); top = ClampInGrid(grid, top); } serie.dataPoints.Add(top); var areaColor = isRise ? itemStyle.GetColor(m_Theme.serie.candlestickColor) : itemStyle.GetColor0(m_Theme.serie.candlestickColor0); var borderColor = isRise ? itemStyle.GetBorderColor(m_Theme.serie.candlestickBorderColor) : itemStyle.GetBorderColor0(m_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 + (lowest - minCut) / valueTotal * grid.runtimeHeight); var heighPos = new Vector3(center.x, zeroY + (heighest - minCut) / valueTotal * grid.runtimeHeight); 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 (ItemStyleHelper.IsNeedCorner(itemStyle)) { UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaColor, 0, itemStyle.cornerRadius, isYAxis, 0.5f); } else { CheckClipAndDrawPolygon(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 (isAllBarEnd) { serie.animation.AllBarEnd(); } if (dataChanging) { RefreshPainter(serie); } }
protected virtual void UpdatePointerValue(Axis axis) { var grid = chart.GetChartComponent <GridCoord>(axis.gridIndex); if (grid == null) { return; } if (!grid.context.isPointerEnter) { axis.context.pointerValue = double.PositiveInfinity; } else { var lastPointerValue = axis.context.pointerValue; if (axis.IsCategory()) { var dataZoom = chart.GetDataZoomOfAxis(axis); var dataCount = chart.series.Count > 0 ? chart.series[0].GetDataList(dataZoom).Count : 0; var local = chart.pointerPos; if (axis is YAxis) { float splitWid = AxisHelper.GetDataWidth(axis, grid.context.height, dataCount, dataZoom); for (int j = 0; j < axis.GetDataCount(dataZoom); j++) { float pY = grid.context.y + j * splitWid; if ((axis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) || (!axis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2))) { axis.context.pointerValue = j; axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j); if (j != lastPointerValue) { if (chart.onAxisPointerValueChanged != null) { chart.onAxisPointerValueChanged(axis, j); } } break; } } } else { float splitWid = AxisHelper.GetDataWidth(axis, grid.context.width, dataCount, dataZoom); for (int j = 0; j < axis.GetDataCount(dataZoom); j++) { float pX = grid.context.x + j * splitWid; if ((axis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) || (!axis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2))) { axis.context.pointerValue = j; axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j); if (j != lastPointerValue) { if (chart.onAxisPointerValueChanged != null) { chart.onAxisPointerValueChanged(axis, j); } } break; } } } } else { if (axis is YAxis) { var yRate = axis.context.minMaxRange / grid.context.height; var yValue = yRate * (chart.pointerPos.y - grid.context.y - axis.context.offset); if (axis.context.minValue > 0) { yValue += axis.context.minValue; } var labelX = axis.GetLabelObjectPosition(0).x; axis.context.pointerValue = yValue; axis.context.pointerLabelPosition = new Vector3(labelX, chart.pointerPos.y); if (yValue != lastPointerValue) { if (chart.onAxisPointerValueChanged != null) { chart.onAxisPointerValueChanged(axis, yValue); } } } else { var xRate = axis.context.minMaxRange / grid.context.width; var xValue = xRate * (chart.pointerPos.x - grid.context.x - axis.context.offset); if (axis.context.minValue > 0) { xValue += axis.context.minValue; } var labelY = axis.GetLabelObjectPosition(0).y; axis.context.pointerValue = xValue; axis.context.pointerLabelPosition = new Vector3(chart.pointerPos.x, labelY); if (xValue != lastPointerValue) { if (chart.onAxisPointerValueChanged != null) { chart.onAxisPointerValueChanged(axis, xValue); } } } } } }