public void OnPointerDown(PointerEventData eventData) { if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Pie)) { return; } if (chart.pointerPos == Vector2.zero) { return; } var refresh = false; for (int i = 0; i < chart.series.Count; i++) { var serie = chart.series.GetSerie(i); if (serie.type != SerieType.Pie) { continue; } var index = GetPiePosIndex(serie, chart.pointerPos); if (index >= 0) { refresh = true; for (int j = 0; j < serie.data.Count; j++) { if (j == index) { serie.data[j].selected = !serie.data[j].selected; } else { serie.data[j].selected = false; } } if (chart.onPointerClickPie != null) { chart.onPointerClickPie(eventData, i, index); } } } if (refresh) { chart.RefreshChart(); } }
public static Color GetIconColor(Legend legend, int readIndex, ChartTheme theme, Series series, string legendName, bool active) { if (active) { if (legend.itemAutoColor || legend.GetIcon(readIndex) == null) { return(SeriesHelper.GetNameColor(series, readIndex, legendName, theme)); } else { return(Color.white); } } else { return(theme.legend.unableColor); } }
public static Color GetIconColor(BaseChart chart, int readIndex, string legendName, bool active) { if (active) { var legend = chart.legend; if (legend.itemAutoColor || legend.GetIcon(readIndex) == null) { return(SeriesHelper.GetNameColor(chart, readIndex, legendName)); } else { return(Color.white); } } else { return(chart.theme.legend.unableColor); } }
protected void CheckRefreshLabel() { if (m_ReinitLabel) { m_ReinitLabel = false; SeriesHelper.UpdateSerieNameList(m_Series, ref m_LegendRealShowName); InitSerieLabel(); } if (m_ReinitTitle) { m_ReinitTitle = false; InitSerieTitle(); } if (m_RefreshLabel) { m_RefreshLabel = false; OnRefreshLabel(); } }
private void UpdateAxisMinMaxValue(Axis axis, bool updateChart = true) { if (axis.IsCategory() || !axis.show) { return; } double tempMinValue = 0; double tempMaxValue = 0; if (axis is RadiusAxis) { SeriesHelper.GetXMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue, out tempMaxValue, true); } else { SeriesHelper.GetYMinMaxValue(m_Series, null, axis.polarIndex, true, axis.inverse, out tempMinValue, out tempMaxValue, true); } AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true); if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue) { m_IsPlayingAnimation = true; var needCheck = !m_IsPlayingAnimation && axis.runtimeLastCheckInverse == axis.inverse; axis.UpdateMinValue(tempMinValue, needCheck); axis.UpdateMaxValue(tempMaxValue, needCheck); axis.runtimeZeroXOffset = 0; axis.runtimeZeroYOffset = 0; axis.runtimeLastCheckInverse = axis.inverse; if (updateChart) { UpdateAxisLabelText(axis); RefreshChart(); } } if (axis.IsValueChanging(500) && !m_IsPlayingAnimation) { UpdateAxisLabelText(axis); RefreshChart(); } }
private void InitAxisLabel() { if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Gauge)) { return; } var labelObject = ChartHelper.AddObject(s_AxisLabelObjectName, chart.transform, chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); labelObject.hideFlags = chart.chartHideFlags; SerieLabelPool.ReleaseAll(labelObject.transform); for (int i = 0; i < chart.series.Count; i++) { var serie = chart.series.list[i]; if (serie.type != SerieType.Gauge) { continue; } var serieLabel = serie.gaugeAxis.axisLabel; var count = serie.splitNumber > 36 ? 36 : (serie.splitNumber + 1); var startAngle = serie.startAngle; var textColor = serieLabel.textStyle.GetColor(chart.theme.gauge.textColor); serie.gaugeAxis.ClearLabelObject(); SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); for (int j = 0; j < count; j++) { var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j); var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serieLabel, textColor, 100, 100, chart.theme); var iconImage = labelObj.transform.Find("Icon").GetComponent <Image>(); var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0; var item = new ChartLabel(); item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom); item.SetIcon(iconImage); item.SetIconActive(false); serie.gaugeAxis.AddLabelObject(item); } UpdateAxisLabel(serie); } }
internal void UpdateAxisMinMaxValue(int axisIndex, Axis axis, bool updateChart = true) { if (!axis.show) { return; } if (axis.IsCategory()) { axis.context.minValue = 0; axis.context.maxValue = SeriesHelper.GetMaxSerieDataCount(chart.series) - 1; axis.context.minMaxRange = axis.context.maxValue; return; } double tempMinValue = 0; double tempMaxValue = 0; chart.GetSeriesMinMaxValue(axis, axisIndex, out tempMinValue, out tempMaxValue); if (tempMinValue != axis.context.minValue || tempMaxValue != axis.context.maxValue || m_LastInterval != axis.interval || m_LastSplitNumber != axis.splitNumber) { m_LastSplitNumber = axis.splitNumber; m_LastInterval = axis.interval; axis.UpdateMinMaxValue(tempMinValue, tempMaxValue); axis.context.offset = 0; axis.context.lastCheckInverse = axis.inverse; UpdateAxisTickValueList(axis); if (tempMinValue != 0 || tempMaxValue != 0) { var grid = chart.GetChartComponent <GridCoord>(axis.gridIndex); if (grid != null && axis is XAxis && axis.IsValue()) { axis.context.offset = axis.context.minValue > 0 ? 0 : (axis.context.maxValue < 0 ? grid.context.width : (float)(Math.Abs(axis.context.minValue) * (grid.context.width / (Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue)))) ); axis.context.x = grid.context.x; axis.context.y = GetAxisLineXOrY(); axis.context.zeroY = grid.context.y; axis.context.zeroX = grid.context.x - (float)(axis.context.minValue * grid.context.width / axis.context.minMaxRange); } if (grid != null && axis is YAxis && axis.IsValue()) { axis.context.offset = axis.context.minValue > 0 ? 0 : (axis.context.maxValue < 0 ? grid.context.height : (float)(Math.Abs(axis.context.minValue) * (grid.context.height / (Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue)))) ); axis.context.x = GetAxisLineXOrY(); axis.context.y = grid.context.y; axis.context.zeroX = grid.context.x; axis.context.zeroY = grid.context.y - (float)(axis.context.minValue * grid.context.height / axis.context.minMaxRange); } } var dataZoom = chart.GetDataZoomOfAxis(axis); if (dataZoom != null && dataZoom.enable) { if (axis is XAxis) { dataZoom.SetXAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue); } else { dataZoom.SetYAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue); } } if (updateChart) { UpdateAxisLabelText(axis); chart.RefreshChart(); } } }
private void InitRadiusAxis(RadiusAxis axis) { var m_Polar = GetPolar(axis.index); if (m_Polars == null) { return; } var m_AngleAxis = GetAngleAxis(m_Polar.index); if (m_AngleAxis == null) { return; } PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight); axis.axisLabelTextList.Clear(); var radius = m_Polar.runtimeRadius; var objName = "axis_radius" + axis.index; var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin, graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); axisObj.transform.localPosition = Vector3.zero; axisObj.SetActive(axis.show && axis.axisLabel.show); axisObj.hideFlags = chartHideFlags; ChartHelper.HideAllObject(axisObj); var textStyle = axis.axisLabel.textStyle; var splitNumber = AxisHelper.GetSplitNumber(axis, radius, null); var totalWidth = 0f; var startAngle = m_AngleAxis.runtimeStartAngle; var cenPos = m_Polar.runtimeCenterPos; var txtHig = textStyle.GetFontSize(m_Theme.axis) + 2; var dire = ChartHelper.GetDire(startAngle, true).normalized; var tickWidth = axis.axisTick.GetLength(m_Theme.radiusAxis.tickWidth); var tickVetor = ChartHelper.GetVertialDire(dire) * (tickWidth + axis.axisLabel.margin); for (int i = 0; i < splitNumber; i++) { float labelWidth = AxisHelper.GetScaleWidth(axis, radius, i, null); bool inside = axis.axisLabel.inside; var txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig), textStyle, m_Theme.axis); if (i == 0) { axis.axisLabel.SetRelatedText(txt, labelWidth); } var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue, null, isPercentStack); txt.SetAlignment(TextAnchor.MiddleCenter); txt.SetText(labelName); txt.SetActive(axis.show && (axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0)); var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVetor; txt.SetLocalPosition(pos); AxisHelper.AdjustRadiusAxisLabelPos(txt, pos, cenPos, txtHig, Vector3.zero); axis.axisLabelTextList.Add(txt); totalWidth += labelWidth; } if (tooltip.runtimeGameObject) { Vector2 privot = new Vector2(0.5f, 1); var labelParent = tooltip.runtimeGameObject.transform; var labelName = ChartCached.GetAxisTooltipLabel(objName); GameObject labelObj = ChartHelper.AddTooltipLabel(labelName, labelParent, m_Theme, privot); axis.SetTooltipLabel(labelObj); axis.SetTooltipLabelColor(m_Theme.tooltip.labelBackgroundColor, m_Theme.tooltip.labelTextColor); axis.SetTooltipLabelActive(axis.show && tooltip.show && tooltip.type == Tooltip.Type.Corss); } }
protected override void CheckComponent() { if (m_Series.anyDirty) { if (m_Series.vertsDirty) { RefreshChart(); } if (SeriesHelper.IsLabelDirty(m_Series)) { m_ReinitLabel = true; } if (SeriesHelper.IsNeedLabelUpdate(m_Series) && !m_RefreshChart) { m_RefreshLabel = true; } foreach (var serie in m_Series.list) { if (serie.titleStyle.componentDirty) { m_ReinitTitle = true; } if (serie.nameDirty) { m_Legend.SetAllDirty(); RefreshChart(); serie.ClearNameDirty(); } } m_Series.ClearDirty(); } if (m_ThemeInfo.anyDirty) { if (m_CheckTheme != m_ThemeInfo.theme) { m_CheckTheme = m_ThemeInfo.theme; m_ThemeInfo.Copy(m_CheckTheme); OnThemeChanged(); } if (m_ThemeInfo.componentDirty) { m_Title.SetAllDirty(); m_Legend.SetAllDirty(); m_Tooltip.SetAllDirty(); } if (m_ThemeInfo.vertsDirty) { RefreshChart(); } m_ThemeInfo.ClearDirty(); } if (m_Background.anyDirty) { if (m_Background.componentDirty) { InitBackground(); } if (m_Background.vertsDirty) { RefreshChart(); } m_Background.ClearDirty(); } if (m_Title.anyDirty) { if (m_Title.componentDirty) { InitTitle(); } if (m_Title.vertsDirty) { RefreshChart(); } m_Title.ClearDirty(); } if (m_Legend.anyDirty) { if (m_Legend.componentDirty) { InitLegend(); } if (m_Legend.vertsDirty) { RefreshChart(); } m_Legend.ClearDirty(); } if (m_Tooltip.anyDirty) { if (m_Tooltip.componentDirty) { InitTooltip(); } if (m_Tooltip.vertsDirty) { RefreshChart(); } m_Tooltip.ClearDirty(); } if (m_Settings.vertsDirty) { RefreshChart(); m_Settings.ClearDirty(); } }
private void InitLegend() { m_Legend.OnChanged(); var legendObject = ChartHelper.AddObject(s_LegendObjectName, transform, m_ChartMinAnchor, m_ChartMaxAnchor, m_ChartPivot, new Vector2(chartWidth, chartHeight)); legendObject.hideFlags = chartHideFlags; SeriesHelper.UpdateSerieNameList(m_Series, ref m_LegendRealShowName); List <string> datas; if (m_Legend.show && m_Legend.data.Count > 0) { datas = new List <string>(); for (int i = 0; i < m_LegendRealShowName.Count; i++) { if (m_Legend.data.Contains(m_LegendRealShowName[i])) { datas.Add(m_LegendRealShowName[i]); } } } else { datas = m_LegendRealShowName; } int totalLegend = 0; for (int i = 0; i < datas.Count; i++) { if (!SeriesHelper.IsLegalLegendName(datas[i])) { continue; } totalLegend++; } m_Legend.RemoveButton(); ChartHelper.HideAllObject(legendObject); if (!m_Legend.show) { return; } for (int i = 0; i < datas.Count; i++) { if (!SeriesHelper.IsLegalLegendName(datas[i])) { continue; } string legendName = m_Legend.GetFormatterContent(datas[i]); var readIndex = m_LegendRealShowName.IndexOf(datas[i]); var active = IsActiveByLegend(datas[i]); var bgColor = LegendHelper.GetIconColor(m_Legend, readIndex, themeInfo, active); var item = LegendHelper.AddLegendItem(m_Legend, i, datas[i], legendObject.transform, m_ThemeInfo, legendName, bgColor, active); m_Legend.SetButton(legendName, item, totalLegend); ChartHelper.ClearEventListener(item.button.gameObject); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) => { if (data.selectedObject == null || m_Legend.selectedMode == Legend.SelectedMode.None) { return; } var temp = data.selectedObject.name.Split('_'); string selectedName = temp[1]; int clickedIndex = int.Parse(temp[0]); if (m_Legend.selectedMode == Legend.SelectedMode.Multiple) { OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName)); } else { var btnList = m_Legend.buttonList.Values.ToArray(); if (btnList.Length == 1) { OnLegendButtonClick(0, selectedName, !IsActiveByLegend(selectedName)); } else { for (int n = 0; n < btnList.Length; n++) { temp = btnList[n].name.Split('_'); selectedName = btnList[n].legendName; var index = btnList[n].index; OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false); } } } }); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerEnter, (data) => { if (item.button == null) { return; } var temp = item.button.name.Split('_'); string selectedName = temp[1]; int index = int.Parse(temp[0]); OnLegendButtonEnter(index, selectedName); }); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) => { if (item.button == null) { return; } var temp = item.button.name.Split('_'); string selectedName = temp[1]; int index = int.Parse(temp[0]); OnLegendButtonExit(index, selectedName); }); } if (m_Legend.selectedMode == Legend.SelectedMode.Single) { for (int n = 0; n < m_LegendRealShowName.Count; n++) { OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false); } } LegendHelper.ResetItemPosition(m_Legend, m_ChartPosition, m_ChartWidth, m_ChartHeight); }
protected override void CheckComponent() { base.CheckComponent(); if (m_Series.anyDirty) { if (SeriesHelper.IsLabelDirty(m_Series)) { m_ReinitLabel = true; } if (SeriesHelper.IsNeedLabelUpdate(m_Series) && !m_RefreshChart) { m_RefreshLabel = true; } foreach (var serie in m_Series.list) { if (serie.titleStyle.componentDirty) { m_ReinitTitle = true; } if (serie.nameDirty) { foreach (var legend in m_Legends) { legend.SetAllDirty(); } RefreshChart(); serie.ClearNameDirty(); } if (serie.vertsDirty) { RefreshPainter(serie); } } m_Series.ClearDirty(); } if (m_Theme.anyDirty) { if (m_Theme.componentDirty) { foreach (var title in m_Titles) { title.SetAllDirty(); } foreach (var legend in m_Legends) { legend.SetAllDirty(); } tooltip.SetAllDirty(); } if (m_Theme.vertsDirty) { RefreshChart(); } m_Theme.ClearDirty(); } CheckComponentDirty(tooltip); foreach (var component in m_Titles) { CheckComponentDirty(component); } foreach (var component in m_Legends) { CheckComponentDirty(component); } foreach (var component in m_Tooltips) { CheckComponentDirty(component); } foreach (var component in m_DataZooms) { CheckComponentDirty(component); } foreach (var component in m_VisualMaps) { CheckComponentDirty(component); } foreach (var component in m_Grids) { CheckComponentDirty(component); } foreach (var component in m_XAxes) { CheckComponentDirty(component); } foreach (var component in m_YAxes) { CheckComponentDirty(component); } foreach (var component in m_Vessels) { CheckComponentDirty(component); } foreach (var component in m_Polars) { CheckComponentDirty(component); } foreach (var component in m_AngleAxes) { CheckComponentDirty(component); } foreach (var component in m_RadiusAxes) { CheckComponentDirty(component); } foreach (var component in m_Radars) { CheckComponentDirty(component); } foreach (var drawSerie in m_DrawSeries) { drawSerie.CheckComponent(); } }
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; } }
public override void ClearDirty() { base.ClearDirty(); ClearLabelDirty(); SeriesHelper.ClearNameDirty(this); }
private void InitAngleAxis(AngleAxis axis) { var m_Polar = GetPolar(axis.polarIndex); if (m_Polars == null) { return; } PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight); var radius = m_Polar.runtimeRadius; axis.axisLabelTextList.Clear(); string objName = "axis_angle" + axis.index; var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin, graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); axisObj.transform.localPosition = Vector3.zero; axisObj.SetActive(axis.show && axis.axisLabel.show); axisObj.hideFlags = chartHideFlags; ChartHelper.HideAllObject(axisObj); var splitNumber = AxisHelper.GetSplitNumber(axis, radius, null); var totalAngle = axis.runtimeStartAngle; var total = 360; var cenPos = m_Polar.runtimeCenterPos; var txtHig = axis.axisLabel.textStyle.GetFontSize(m_Theme.axis) + 2; var margin = axis.axisLabel.margin; var isCategory = axis.IsCategory(); var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); for (int i = 0; i < splitNumber; i++) { float scaleAngle = AxisHelper.GetScaleWidth(axis, total, i, null); bool inside = axis.axisLabel.inside; var txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(scaleAngle, txtHig), axis.axisLabel.textStyle, m_Theme.axis); txt.SetAlignment(TextAnchor.MiddleCenter); txt.SetText(AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue, null, isPercentStack)); txt.SetActive(axis.show && (axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0)); var pos = ChartHelper.GetPos(cenPos, radius + margin, isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true); AxisHelper.AdjustCircleLabelPos(txt, pos, cenPos, txtHig, Vector3.zero); if (i == 0) { axis.axisLabel.SetRelatedText(txt, scaleAngle); } axis.axisLabelTextList.Add(txt); totalAngle += scaleAngle; } if (tooltip.runtimeGameObject) { Vector2 privot = new Vector2(0.5f, 0.5f); var labelParent = tooltip.runtimeGameObject.transform; GameObject labelObj = ChartHelper.AddTooltipLabel(ChartCached.GetAxisTooltipLabel(objName), labelParent, m_Theme, privot, privot, privot, new Vector2(10, txtHig)); axis.SetTooltipLabel(labelObj); axis.SetTooltipLabelColor(m_Theme.tooltip.labelBackgroundColor, m_Theme.tooltip.labelTextColor); axis.SetTooltipLabelActive(axis.show && tooltip.show && tooltip.type == Tooltip.Type.Corss); } }
protected void InitAxis(Axis relativedAxis, Orient orient, float axisStartX, float axisStartY, float axisLength, float relativedLength) { Axis axis = component; chart.InitAxisRuntimeData(axis); var objName = ChartCached.GetComponentObjectName(axis); var axisObj = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); axisObj.SetActive(axis.show); axisObj.hideFlags = chart.chartHideFlags; ChartHelper.HideAllObject(axisObj); axis.gameObject = axisObj; axis.context.labelObjectList.Clear(); if (!axis.show) { return; } var axisLabelTextStyle = axis.axisLabel.textStyle; var dataZoom = chart.GetDataZoomOfAxis(axis); var splitNumber = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom); var totalWidth = 0f; var eachWidth = AxisHelper.GetEachWidth(axis, axisLength, dataZoom); var gapWidth = axis.boundaryGap ? eachWidth / 2 : 0; var textWidth = axis.axisLabel.width > 0 ? axis.axisLabel.width : (orient == Orient.Horizonal ? AxisHelper.GetScaleWidth(axis, axisLength, 0, dataZoom) : (axisStartX - chart.chartX) ); var textHeight = axis.axisLabel.height > 0 ? axis.axisLabel.height : 20f; var isPercentStack = SeriesHelper.IsPercentStack <Bar>(chart.series); var inside = axis.axisLabel.inside; var defaultAlignment = orient == Orient.Horizonal ? TextAnchor.MiddleCenter : ((inside && axis.IsLeft()) || (!inside && axis.IsRight()) ? TextAnchor.MiddleLeft : TextAnchor.MiddleRight); if (axis.IsCategory() && axis.boundaryGap) { splitNumber -= 1; } for (int i = 0; i < splitNumber; i++) { var labelWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom); var labelName = AxisHelper.GetLabelName(axis, axisLength, i, axis.context.minValue, axis.context.maxValue, dataZoom, isPercentStack); var label = ChartHelper.AddAxisLabelObject(splitNumber, i, ChartCached.GetAxisLabelName(i), axisObj.transform, new Vector2(textWidth, textHeight), axis, chart.theme.axis, labelName, Color.clear, defaultAlignment); if (i == 0) { axis.axisLabel.SetRelatedText(label.text, labelWidth); } var pos = GetLabelPosition(totalWidth + gapWidth, i); label.SetPosition(pos); CheckValueLabelActive(axis, i, label, pos); axis.context.labelObjectList.Add(label); totalWidth += labelWidth; } if (axis.axisName.show) { ChartLabel label = null; var relativedDist = (relativedAxis == null ? 0 : relativedAxis.context.offset); var zeroPos = new Vector3(axisStartX, axisStartY + relativedDist); var offset = axis.axisName.labelStyle.offset; var autoColor = axis.axisLine.GetColor(chart.theme.axis.lineColor); if (orient == Orient.Horizonal) { var grid = chart.GetChartComponent <GridCoord>(axis.gridIndex); var posY = !axis.axisName.onZero && grid != null? grid.context.y : GetAxisLineXOrY() + offset.y; switch (axis.axisName.labelStyle.position) { case LabelStyle.Position.Start: label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleRight); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Top ? new Vector2(zeroPos.x - offset.x, axisStartY + relativedLength + offset.y + axis.offset) : new Vector2(zeroPos.x - offset.x, posY)); break; case LabelStyle.Position.Middle: label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Top ? new Vector2(axisStartX + axisLength / 2 + offset.x, axisStartY + relativedLength - offset.y + axis.offset) : new Vector2(axisStartX + axisLength / 2 + offset.x, posY)); break; default: label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleLeft); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Top ? new Vector2(axisStartX + axisLength + offset.x, axisStartY + relativedLength + offset.y + axis.offset) : new Vector2(axisStartX + axisLength + offset.x, posY)); break; } } else { var grid = chart.GetChartComponent <GridCoord>(axis.gridIndex); var posX = !axis.axisName.onZero && grid != null? grid.context.x : GetAxisLineXOrY() + offset.x; switch (axis.axisName.labelStyle.position) { case LabelStyle.Position.Start: label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Right ? new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY - offset.y) : new Vector2(posX, axisStartY - offset.y)); break; case LabelStyle.Position.Middle: label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Right ? new Vector2(axisStartX + relativedLength - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y) : new Vector2(posX, axisStartY + axisLength / 2 + offset.y)); break; default: //LabelStyle.Position label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle, chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter); label.SetActive(axis.axisName.labelStyle.show); label.SetPosition(axis.position == Axis.AxisPosition.Right ? new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY + axisLength + offset.y) : new Vector2(posX, axisStartY + axisLength + offset.y)); break; } } } }
internal static void GetMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis, bool inverse, bool yValue, out float minVaule, out float maxValue) { float min = int.MaxValue; float max = int.MinValue; var isPercentStack = SeriesHelper.IsPercentStack(series, SerieType.Bar); if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue)) { for (int i = 0; i < series.list.Count; i++) { var serie = series.GetSerie(i); if (serie.axisIndex != axisIndex) { continue; } if (series.IsActive(i)) { if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar)) { if (100 > max) { max = 100; } if (0 < min) { min = 0; } } else { var showData = serie.GetDataList(dataZoom); foreach (var data in showData) { var currData = data.GetData(yValue ? 1 : 0, inverse); if (currData > max) { max = currData; } if (currData < min) { min = currData; } } } } } } else { SeriesHelper.GetStackSeries(series, ref _stackSeriesForMinMax); foreach (var ss in _stackSeriesForMinMax) { _serieTotalValueForMinMax.Clear(); for (int i = 0; i < ss.Value.Count; i++) { var serie = ss.Value[i]; if (serie.axisIndex != axisIndex || !series.IsActive(i)) { continue; } var showData = serie.GetDataList(dataZoom); if (SeriesHelper.IsPercentStack(series, serie.stack, SerieType.Bar)) { for (int j = 0; j < showData.Count; j++) { _serieTotalValueForMinMax[j] = 100; } } else { for (int j = 0; j < showData.Count; j++) { if (!_serieTotalValueForMinMax.ContainsKey(j)) { _serieTotalValueForMinMax[j] = 0; } var currData = (yValue ? showData[j].GetData(1) : showData[j].GetData(0)); if (inverse) { currData = -currData; } _serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData; } } } float tmax = int.MinValue; float tmin = int.MaxValue; foreach (var tt in _serieTotalValueForMinMax) { if (tt.Value > tmax) { tmax = tt.Value; } if (tt.Value < tmin) { tmin = tt.Value; } } if (tmax > max) { max = tmax; } if (tmin < min) { min = tmin; } } } if (max == int.MinValue && min == int.MaxValue) { minVaule = 0; maxValue = 0; } else { minVaule = min > 1 ? Mathf.FloorToInt(min) : min; maxValue = max > 1 ? Mathf.CeilToInt(max) : max; } }
public bool ContainsSerie(SerieType serieType) { return(SeriesHelper.ContainsSerie(m_Series, serieType)); }
public static void GetMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis, bool inverse, bool yValue, out double minVaule, out double maxValue, bool isPolar = false) { double min = double.MaxValue; double max = double.MinValue; var isPercentStack = SeriesHelper.IsPercentStack(series, SerieType.Bar); if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue)) { for (int i = 0; i < series.list.Count; i++) { var serie = series.GetSerie(i); if ((isPolar && serie.polarIndex != axisIndex) || (!isPolar && serie.yAxisIndex != axisIndex)) { continue; } if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar)) { if (100 > max) { max = 100; } if (0 < min) { min = 0; } } else { var showData = serie.GetDataList(dataZoom); foreach (var data in showData) { if (serie.type == SerieType.Candlestick) { var dataMin = data.GetMinData(inverse); var dataMax = data.GetMaxData(inverse); if (dataMax > max) { max = dataMax; } if (dataMin < min) { min = dataMin; } } else { var currData = data.GetData(yValue ? 1 : 0, inverse); if (!serie.IsIgnoreValue(currData)) { if (currData > max) { max = currData; } if (currData < min) { min = currData; } } } } } } } else { SeriesHelper.GetStackSeries(series, ref _stackSeriesForMinMax); foreach (var ss in _stackSeriesForMinMax) { _serieTotalValueForMinMax.Clear(); for (int i = 0; i < ss.Value.Count; i++) { var serie = ss.Value[i]; if ((isPolar && serie.polarIndex != axisIndex) || (!isPolar && serie.yAxisIndex != axisIndex)) { continue; } var showData = serie.GetDataList(dataZoom); if (SeriesHelper.IsPercentStack(series, serie.stack, SerieType.Bar)) { for (int j = 0; j < showData.Count; j++) { _serieTotalValueForMinMax[j] = 100; } } else { for (int j = 0; j < showData.Count; j++) { if (!_serieTotalValueForMinMax.ContainsKey(j)) { _serieTotalValueForMinMax[j] = 0; } double currData = 0; if (serie.type == SerieType.Candlestick) { currData = showData[j].GetMaxData(false); } else { currData = yValue ? showData[j].GetData(1) : showData[j].GetData(0); } if (inverse) { currData = -currData; } if (!serie.IsIgnoreValue(currData)) { _serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData; } } } } double tmax = double.MinValue; double tmin = double.MaxValue; foreach (var tt in _serieTotalValueForMinMax) { if (tt.Value > tmax) { tmax = tt.Value; } if (tt.Value < tmin) { tmin = tt.Value; } } if (tmax > max) { max = tmax; } if (tmin < min) { min = tmin; } } } if (max == double.MinValue && min == double.MaxValue) { minVaule = 0; maxValue = 0; } else { minVaule = min > 1 ? Math.Floor(min) : min; maxValue = max > 1 ? Math.Ceiling(max) : max; } }