private void UpdateSerieContext() { if (m_SerieGrid == null) { return; } var needCheck = (chart.isPointerInChart && m_SerieGrid.IsPointerEnter() && !serie.placeHolder) || m_LegendEnter; var needInteract = false; if (!needCheck) { if (m_LastCheckContextFlag != needCheck) { m_LastCheckContextFlag = needCheck; serie.context.pointerItemDataIndex = -1; serie.context.pointerEnter = false; foreach (var serieData in serie.data) { serieData.context.highlight = false; serieData.interact.Reset(); } chart.RefreshPainter(serie); } return; } m_LastCheckContextFlag = needCheck; if (m_LegendEnter) { serie.context.pointerEnter = true; foreach (var serieData in serie.data) { var barColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, true); var barToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serie.context.colorIndex, true); serieData.interact.SetColor(ref needInteract, barColor, barToColor); } } else { serie.context.pointerItemDataIndex = -1; serie.context.pointerEnter = false; foreach (var serieData in serie.data) { if (serie.context.pointerAxisDataIndexs.Contains(serieData.index) || serieData.context.rect.Contains(chart.pointerPos)) { serie.context.pointerItemDataIndex = serieData.index; serie.context.pointerEnter = true; serieData.context.highlight = true; var barColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, true); var barToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serie.context.colorIndex, true); serieData.interact.SetColor(ref needInteract, barColor, barToColor); } else { serieData.context.highlight = false; var barColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serie.context.colorIndex, false); var barToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serie.context.colorIndex, false); serieData.interact.SetColor(ref needInteract, barColor, barToColor); } } } if (needInteract) { chart.RefreshPainter(serie); } }
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); } }