@@ -49,8 +49,43 @@ class HTMainDraw: NSObject, HTKLineDrawProtocol {
4949 } else {
5050 // Draw wick first (behind body)
5151 drawCandle ( high: model. high, low: model. low, maxValue: maxValue, minValue: minValue, baseY: baseY, height: height, index: index, width: configManager. candleLineWidth, color: wickColor, verticalAlignBottom: false , context: context, configManager: configManager)
52+
5253 // Draw body second (on top)
53- drawCandle ( high: findValue ( true ) , low: findValue ( false ) , maxValue: maxValue, minValue: minValue, baseY: baseY, height: height, index: index, width: configManager. candleWidth, color: color, verticalAlignBottom: false , context: context, configManager: configManager)
54+ let candleHigh = findValue ( true )
55+ let candleLow = findValue ( false )
56+
57+ // Handle case when open == close (doji candlestick)
58+ if candleHigh == candleLow {
59+ // Draw a thin horizontal line to make the doji visible, similar to Android behavior
60+ drawCandleWithMinHeight ( high: candleHigh, low: candleLow, maxValue: maxValue, minValue: minValue, baseY: baseY, height: height, index: index, width: configManager. candleWidth, color: color, context: context, configManager: configManager)
61+ } else {
62+ drawCandle ( high: candleHigh, low: candleLow, maxValue: maxValue, minValue: minValue, baseY: baseY, height: height, index: index, width: configManager. candleWidth, color: color, verticalAlignBottom: false , context: context, configManager: configManager)
63+ }
64+ }
65+ }
66+
67+ func drawCandleWithMinHeight( high: CGFloat , low: CGFloat , maxValue: CGFloat , minValue: CGFloat , baseY: CGFloat , height: CGFloat , index: Int , width: CGFloat , color: UIColor , context: CGContext , configManager: HTKLineConfigManager ) {
68+ let itemWidth = configManager. itemWidth
69+ let scale = ( maxValue - minValue) / height
70+ let paddingHorizontal = ( itemWidth - width) / 2.0
71+ let x = CGFloat ( index) * itemWidth + paddingHorizontal
72+ let y = baseY + ( maxValue - high) / scale
73+
74+ // Ensure minimum height of 1 pixel for doji candles (open == close)
75+ let minHeightInPixels : CGFloat = 1.0
76+ let candleHeight = max ( minHeightInPixels, ( high - low) / scale)
77+
78+ context. setFillColor ( color. cgColor)
79+
80+ if configManager. candleCornerRadius > 0 {
81+ // Draw rounded rectangle
82+ let rect = CGRect ( x: x, y: y, width: width, height: candleHeight)
83+ let path = UIBezierPath ( roundedRect: rect, cornerRadius: configManager. candleCornerRadius)
84+ context. addPath ( path. cgPath)
85+ context. fillPath ( )
86+ } else {
87+ // Draw regular rectangle with minimum height
88+ context. fill ( CGRect . init ( x: x, y: y, width: width, height: candleHeight) )
5489 }
5590 }
5691
0 commit comments