private float GetStackBarWidth(float categoryWidth, Serie now) { if (string.IsNullOrEmpty(now.stack)) { return(now.GetBarWidth(categoryWidth)); } float barWidth = 0; for (int i = 0; i < m_Series.Count; i++) { var serie = m_Series.list[i]; if (serie.type == SerieType.Bar && serie.show && now.stack.Equals(serie.stack)) { if (serie.barWidth > barWidth) { barWidth = serie.barWidth; } } } if (barWidth > 1) { return(barWidth); } else { return(barWidth * categoryWidth); } }
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); } }
protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List <float> seriesHig) { if (!IsActive(serie.name)) { return; } var xAxis = m_XAxises[serie.axisIndex]; var yAxis = m_YAxises[serie.axisIndex]; if (!yAxis.show) { yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count]; } var showData = serie.GetDataList(m_DataZoom); float categoryWidth = yAxis.GetDataWidth(coordinateHeight, 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 = m_Series.IsPercentStack(serie.stack, SerieType.Bar); for (int i = serie.minShow; i < maxCount; i++) { if (i >= seriesHig.Count) { seriesHig.Add(0); } float value = showData[i].data[1]; float pX = seriesHig[i] + coordinateX + xAxis.zeroXOffset + yAxis.axisLine.width; float pY = coordinateY + +i * categoryWidth; if (!yAxis.boundaryGap) { pY -= categoryWidth / 2; } var barHig = 0f; var valueTotal = 0f; if (isPercentStack) { valueTotal = GetSameStackTotalValue(serie.stack, i); barHig = value / valueTotal * coordinateWidth; seriesHig[i] += barHig; } else { valueTotal = xAxis.maxValue - xAxis.minValue; barHig = (xAxis.minValue > 0 ? value - xAxis.minValue : value) / valueTotal * coordinateWidth; seriesHig[i] += barHig; } float currHig = CheckAnimation(serie, i, barHig); Vector3 p1 = new Vector3(pX, pY + space + barWidth); Vector3 p2 = new Vector3(pX + currHig, pY + space + barWidth); Vector3 p3 = new Vector3(pX + currHig, pY + space); Vector3 p4 = new Vector3(pX, pY + space); serie.dataPoints.Add(new Vector3(pX + currHig, pY + space + barWidth / 2)); var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) || serie.data[i].highlighted || serie.highlighted; if (serie.show) { Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight); Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight); if (serie.barType == BarType.Zebra) { p1 = (p4 + p1) / 2; p2 = (p2 + p3) / 2; ChartDrawer.DrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, areaColor); } else { ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor); } } } if (!m_Series.IsStack(serie.stack, SerieType.Bar)) { m_BarLastOffset += barGapWidth; } }
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 DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List <float> seriesHig) { if (!IsActive(serie.name)) { 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 = xAxis.GetDataWidth(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 = m_Series.IsPercentStack(serie.stack, SerieType.Bar); bool dataChanging = false; float updateDuration = serie.animation.GetUpdateAnimationDuration(); float yMinValue = yAxis.GetCurrMinValue(updateDuration); float yMaxValue = yAxis.GetCurrMaxValue(updateDuration); for (int i = serie.minShow; i < maxCount; i++) { if (i >= seriesHig.Count) { seriesHig.Add(0); } float value = showData[i].GetCurrData(1, updateDuration); if (showData[i].IsDataChanged()) { dataChanging = true; } float pX = coordinateX + i * categoryWidth; float zeroY = coordinateY + yAxis.runtimeZeroYOffset; if (!xAxis.boundaryGap) { pX -= categoryWidth / 2; } float pY = seriesHig[i] + zeroY + xAxis.axisLine.width; var barHig = 0f; var valueTotal = 0f; if (isPercentStack) { valueTotal = GetSameStackTotalValue(serie.stack, i); barHig = valueTotal != 0 ? (value / valueTotal * coordinateHeight) : 0; seriesHig[i] += barHig; } else { valueTotal = yMaxValue - yMinValue; if (valueTotal != 0) { barHig = (yMinValue > 0 ? value - yMinValue : value) / valueTotal * coordinateHeight; } seriesHig[i] += barHig; } float currHig = CheckAnimation(serie, i, barHig); Vector3 p1 = new Vector3(pX + space, pY); Vector3 p2 = new Vector3(pX + space, pY + currHig); Vector3 p3 = new Vector3(pX + space + barWidth, pY + currHig); Vector3 p4 = new Vector3(pX + space + barWidth, pY); serie.dataPoints.Add(new Vector3(pX + space + barWidth / 2, pY + currHig)); var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) || serie.data[i].highlighted || serie.highlighted; if (serie.show) { Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight); Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight); if (serie.barType == BarType.Zebra) { p1 = (p4 + p1) / 2; p2 = (p2 + p3) / 2; CheckClipAndDrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, areaColor, serie.clip); } else { CheckClipAndDrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor, serie.clip); } } } if (dataChanging) { RefreshChart(); } if (!m_Series.IsStack(serie.stack, SerieType.Bar)) { m_BarLastOffset += barGapWidth; } }
protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List <float> seriesHig) { if (!IsActive(serie.name)) { 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 = xAxis.GetDataWidth(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 = m_Series.IsPercentStack(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); var borderWidth = itemStyle.runtimeBorderWidth; float value = serieData.GetCurrData(1, dataChangeDuration); if (serieData.IsDataChanged()) { dataChanging = true; } float pX = coordinateX + i * categoryWidth; float zeroY = coordinateY + yAxis.runtimeZeroYOffset; if (!xAxis.boundaryGap) { pX -= categoryWidth / 2; } float pY = seriesHig[i] + zeroY + xAxis.axisLine.width; var barHig = 0f; var valueTotal = 0f; if (isPercentStack) { valueTotal = GetSameStackTotalValue(serie.stack, i); barHig = valueTotal != 0 ? (value / valueTotal * coordinateHeight) : 0; seriesHig[i] += barHig; } else { valueTotal = yMaxValue - yMinValue; if (valueTotal != 0) { barHig = (yMinValue > 0 ? value - yMinValue : value) / valueTotal * coordinateHeight; } seriesHig[i] += barHig; } float currHig = CheckAnimation(serie, i, barHig); Vector3 p1 = new Vector3(pX + space + borderWidth, pY + borderWidth); Vector3 p2 = new Vector3(pX + space + borderWidth, pY + currHig - 2 * borderWidth); Vector3 p3 = new Vector3(pX + space + barWidth, pY + currHig - 2 * borderWidth); Vector3 p4 = new Vector3(pX + space + barWidth, pY + borderWidth); Vector3 top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth); p1 = ClampInCoordinate(p1); p2 = ClampInCoordinate(p2); p3 = ClampInCoordinate(p3); p4 = ClampInCoordinate(p4); top = ClampInCoordinate(top); serie.dataPoints.Add(top); if (serie.show) { Color areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight); Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight); DrawBarBackground(vh, serie, serieData, colorIndex, highlight, pX, pY, space, barWidth, false); if (serie.barType == BarType.Zebra) { p1 = (p4 + p1) / 2; p2 = (p2 + p3) / 2; CheckClipAndDrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, areaColor, serie.clip); } else { CheckClipAndDrawPolygon(vh, ref p4, ref p1, ref p2, ref p3, areaColor, areaToColor, serie.clip); if (borderWidth > 0) { var borderColor = itemStyle.borderColor; var itemWidth = Mathf.Abs(p3.x - p1.x); var itemHeight = Mathf.Abs(p2.y - p4.y); var center = new Vector3((p1.x + p3.x) / 2, (p2.y + p4.y) / 2); ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor); } } } } if (dataChanging) { RefreshChart(); } if (!m_Series.IsStack(serie.stack, SerieType.Bar)) { m_BarLastOffset += barGapWidth; } }
private void DrawYBarSerie(VertexHelper vh, int serieIndex, int stackCount, Serie serie, int colorIndex, ref List <float> seriesHig) { if (!IsActive(serie.name)) { return; } var xAxis = m_XAxises[serie.axisIndex]; var yAxis = m_YAxises[serie.axisIndex]; if (!yAxis.show) { yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count]; } float categoryWidth = yAxis.GetDataWidth(coordinateHig, 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; var showData = serie.GetDataList(m_DataZoom); int maxCount = maxShowDataNumber > 0 ? (maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber) : showData.Count; if (seriesHig.Count < minShowDataNumber) { for (int i = 0; i < minShowDataNumber; i++) { seriesHig.Add(0); } } for (int i = minShowDataNumber; i < maxCount; i++) { if (i >= seriesHig.Count) { seriesHig.Add(0); } float value = showData[i].data[1]; float pX = seriesHig[i] + coordinateX + xAxis.zeroXOffset + yAxis.axisLine.width; float pY = coordinateY + +i * categoryWidth; if (!yAxis.boundaryGap) { pY -= categoryWidth / 2; } float barHig = (xAxis.minValue > 0 ? value - xAxis.minValue : value) / (xAxis.maxValue - xAxis.minValue) * coordinateWid; seriesHig[i] += barHig; Vector3 p1 = new Vector3(pX, pY + space + barWidth); Vector3 p2 = new Vector3(pX + barHig, pY + space + barWidth); Vector3 p3 = new Vector3(pX + barHig, pY + space); Vector3 p4 = new Vector3(pX, pY + space); serie.dataPoints.Add(new Vector3(pX + barHig, pY + space + barWidth / 2)); var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) || serie.data[i].highlighted || serie.highlighted; if (serie.show) { Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight); Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight); ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, areaColor, areaToColor); } } if (!m_Series.IsStack(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 void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List <float> seriesHig) { if (!IsActive(serie.name)) { 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 = xAxis.GetDataWidth(coordinateWidth, 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); } } for (int i = serie.minShow; i < maxCount; i++) { if (i >= seriesHig.Count) { seriesHig.Add(0); } float value = showData[i].data[1]; float pX = coordinateX + i * categoryWidth; float zeroY = coordinateY + yAxis.zeroYOffset; if (!xAxis.boundaryGap) { pX -= categoryWidth / 2; } float pY = seriesHig[i] + zeroY + xAxis.axisLine.width; float barHig = (yAxis.minValue > 0 ? value - yAxis.minValue : value) / (yAxis.maxValue - yAxis.minValue) * coordinateHeight; seriesHig[i] += barHig; float currHig = CheckAnimation(serie, i, barHig); Vector3 p1 = new Vector3(pX + space, pY); Vector3 p2 = new Vector3(pX + space, pY + currHig); Vector3 p3 = new Vector3(pX + space + barWidth, pY + currHig); Vector3 p4 = new Vector3(pX + space + barWidth, pY); serie.dataPoints.Add(new Vector3(pX + space + barWidth / 2, pY + currHig)); var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) || serie.data[i].highlighted || serie.highlighted; if (serie.show) { Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight); Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight); ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor); } } if (!m_Series.IsStack(serie.stack, SerieType.Bar)) { m_BarLastOffset += barGapWidth; } }