14 public partial class CoordinateChart
16 protected void DrawCandlestickSerie(VertexHelper vh,
int colorIndex, Serie serie)
18 if (!IsActive(serie.index))
return;
19 if (serie.animation.HasFadeOut())
return;
20 var yAxis = m_YAxes[serie.yAxisIndex];
21 var xAxis = m_XAxes[serie.xAxisIndex];
22 var
grid = GetSerieGridOrDefault(serie);
23 var dataZoom = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, dataZooms);
24 var showData = serie.GetDataList(dataZoom);
25 float categoryWidth = AxisHelper.GetDataWidth(xAxis,
grid.runtimeWidth, showData.Count, dataZoom);
26 float barWidth = serie.GetBarWidth(categoryWidth);
27 float space = (categoryWidth - barWidth) / 2;
28 int maxCount = serie.maxShow > 0
29 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
32 bool dataChanging =
false;
33 float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
34 double yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
35 double yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
36 var isAllBarEnd =
true;
38 for (
int i = serie.minShow; i < maxCount; i++)
40 var serieData = showData[i];
41 if (serie.IsIgnoreValue(serieData))
43 serie.dataPoints.Add(Vector3.zero);
46 var highlight = (tooltip.show && tooltip.IsSelected(i))
47 || serie.data[i].highlighted
49 var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight);
50 var open = serieData.GetCurrData(0, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
51 var close = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
52 var lowest = serieData.GetCurrData(2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
53 var heighest = serieData.GetCurrData(3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
54 var isRise = yAxis.inverse ? close < open : close > open;
55 var borderWidth = open == 0 ? 0f
56 : (itemStyle.runtimeBorderWidth == 0 ? m_Theme.serie.candlestickBorderWidth
57 : itemStyle.runtimeBorderWidth);
58 if (serieData.IsDataChanged()) dataChanging =
true;
59 float pX =
grid.runtimeX + i * categoryWidth;
60 float zeroY =
grid.runtimeY + yAxis.runtimeZeroYOffset;
61 if (!xAxis.boundaryGap) pX -= categoryWidth / 2;
64 double valueTotal = yMaxValue - yMinValue;
65 var minCut = (yMinValue > 0 ? yMinValue : 0);
68 barHig = (float)((close - open) / valueTotal *
grid.runtimeHeight);
69 pY += (float)((open - minCut) / valueTotal *
grid.runtimeHeight);
71 serieData.runtimeStackHig = barHig;
73 float currHig = Internal_CheckBarAnimation(serie, i, barHig, out isBarEnd);
74 if (!isBarEnd) isAllBarEnd =
false;
75 Vector3 plb, plt, prt, prb, top;
77 plb =
new Vector3(pX + space + borderWidth, pY + borderWidth);
78 plt =
new Vector3(pX + space + borderWidth, pY + currHig - borderWidth);
79 prt =
new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth);
80 prb =
new Vector3(pX + space + barWidth - borderWidth, pY + borderWidth);
81 top =
new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth);
84 plb = ClampInGrid(
grid, plb);
85 plt = ClampInGrid(
grid, plt);
86 prt = ClampInGrid(
grid, prt);
87 prb = ClampInGrid(
grid, prb);
88 top = ClampInGrid(
grid, top);
90 serie.dataPoints.Add(top);
91 var areaColor = isRise
92 ? itemStyle.GetColor(m_Theme.serie.candlestickColor)
93 : itemStyle.GetColor0(m_Theme.serie.candlestickColor0);
94 var borderColor = isRise
95 ? itemStyle.GetBorderColor(m_Theme.serie.candlestickBorderColor)
96 : itemStyle.GetBorderColor0(m_Theme.serie.candlestickBorderColor0);
97 var itemWidth = Mathf.Abs(prt.x - plb.x);
98 var itemHeight = Mathf.Abs(plt.y - prb.y);
99 var center =
new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2);
100 var lowPos =
new Vector3(center.x, zeroY + (
float)((lowest - minCut) / valueTotal *
grid.runtimeHeight));
101 var heighPos =
new Vector3(center.x, zeroY + (
float)((heighest - minCut) / valueTotal *
grid.runtimeHeight));
102 var openCenterPos =
new Vector3(center.x, prb.y);
103 var closeCenterPos =
new Vector3(center.x, prt.y);
104 if (barWidth > 2f * borderWidth)
106 if (itemWidth > 0 && itemHeight > 0)
108 if (ItemStyleHelper.IsNeedCorner(itemStyle))
110 UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaColor, 0,
111 itemStyle.cornerRadius, isYAxis, 0.5f);
115 Internal_CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaColor,
118 UGL.DrawBorder(vh, center, itemWidth, itemHeight, 2 * borderWidth, borderColor, 0,
119 itemStyle.cornerRadius, isYAxis, 0.5f);
124 UGL.DrawLine(vh, openCenterPos, closeCenterPos, Mathf.Max(borderWidth, barWidth / 2), borderColor);
128 UGL.DrawLine(vh, openCenterPos, lowPos, borderWidth, borderColor);
129 UGL.DrawLine(vh, closeCenterPos, heighPos, borderWidth, borderColor);
133 UGL.DrawLine(vh, closeCenterPos, lowPos, borderWidth, borderColor);
134 UGL.DrawLine(vh, openCenterPos, heighPos, borderWidth, borderColor);
139 serie.animation.AllBarEnd();
143 RefreshPainter(serie);