]> git.proxmox.com Git - extjs.git/blame - extjs/packages/charts/src/chart/series/sprite/CandleStick.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / charts / src / chart / series / sprite / CandleStick.js
CommitLineData
6527f429
DM
1/**\r
2 * @class Ext.chart.series.sprite.CandleStick\r
3 * @extends Ext.chart.series.sprite.Aggregative\r
4 * \r
5 * CandleStick series sprite.\r
6 */\r
7Ext.define('Ext.chart.series.sprite.CandleStick', {\r
8 alias: 'sprite.candlestickSeries',\r
9 extend: 'Ext.chart.series.sprite.Aggregative',\r
10 inheritableStatics: {\r
11 def: {\r
12 processors: {\r
13 raiseStyle: function (n, o) {\r
14 return Ext.merge({}, o || {}, n);\r
15 },\r
16 dropStyle: function (n, o) {\r
17 return Ext.merge({}, o || {}, n);\r
18 },\r
19\r
20 /**\r
21 * @cfg {Number} [barWidth=15] The bar width of the candles.\r
22 */\r
23 barWidth: 'number',\r
24\r
25 /**\r
26 * @cfg {Number} [padding=3] The amount of padding between candles.\r
27 */\r
28 padding: 'number',\r
29\r
30 /**\r
31 * @cfg {String} [ohlcType='candlestick'] Determines whether candlestick or ohlc is used.\r
32 */\r
33 ohlcType: 'enums(candlestick,ohlc)'\r
34 },\r
35 defaults: {\r
36 raiseStyle: {\r
37 strokeStyle: 'green',\r
38 fillStyle: 'green'\r
39 },\r
40 dropStyle: {\r
41 strokeStyle: 'red',\r
42 fillStyle: 'red'\r
43 },\r
44 planar: false,\r
45 barWidth: 15,\r
46 padding: 3,\r
47 lineJoin: 'miter',\r
48 miterLimit: 5,\r
49 ohlcType: 'candlestick'\r
50 },\r
51\r
52 triggers: {\r
53 raiseStyle: 'raiseStyle',\r
54 dropStyle: 'dropStyle'\r
55 },\r
56\r
57 updaters: {\r
58 raiseStyle: function () {\r
59 this.raiseTemplate && this.raiseTemplate.setAttributes(this.attr.raiseStyle);\r
60 },\r
61 dropStyle: function () {\r
62 this.dropTemplate && this.dropTemplate.setAttributes(this.attr.dropStyle);\r
63 }\r
64 }\r
65 }\r
66 },\r
67\r
68 candlestick: function (ctx, open, high, low, close, mid, halfWidth) {\r
69 var minOC = Math.min(open, close),\r
70 maxOC = Math.max(open, close);\r
71 ctx.moveTo(mid, low);\r
72 ctx.lineTo(mid, maxOC);\r
73\r
74 ctx.moveTo(mid + halfWidth, maxOC);\r
75 ctx.lineTo(mid + halfWidth, minOC);\r
76 ctx.lineTo(mid - halfWidth, minOC);\r
77 ctx.lineTo(mid - halfWidth, maxOC);\r
78 ctx.closePath();\r
79\r
80 ctx.moveTo(mid, high);\r
81 ctx.lineTo(mid, minOC);\r
82 },\r
83\r
84 ohlc: function (ctx, open, high, low, close, mid, halfWidth) {\r
85 ctx.moveTo(mid, high);\r
86 ctx.lineTo(mid, low);\r
87 ctx.moveTo(mid, open);\r
88 ctx.lineTo(mid - halfWidth, open);\r
89 ctx.moveTo(mid, close);\r
90 ctx.lineTo(mid + halfWidth, close);\r
91 },\r
92\r
93 constructor: function () {\r
94 this.callParent(arguments);\r
95 this.raiseTemplate = new Ext.draw.sprite.Rect({parent: this});\r
96 this.dropTemplate = new Ext.draw.sprite.Rect({parent: this});\r
97 },\r
98\r
99 getGapWidth: function () {\r
100 var attr = this.attr,\r
101 barWidth = attr.barWidth,\r
102 padding = attr.padding;\r
103 return barWidth + padding;\r
104 },\r
105\r
106 renderAggregates: function (aggregates, start, end, surface, ctx, clip) {\r
107 var me = this,\r
108 attr = this.attr,\r
109 dataX = attr.dataX,\r
110 matrix = attr.matrix,\r
111 xx = matrix.getXX(),\r
112 yy = matrix.getYY(),\r
113 dx = matrix.getDX(),\r
114 dy = matrix.getDY(),\r
115 barWidth = attr.barWidth / xx,\r
116 template,\r
117 ohlcType = attr.ohlcType,\r
118 halfWidth = Math.round(barWidth * 0.5 * xx),\r
119 opens = aggregates.open,\r
120 closes = aggregates.close,\r
121 maxYs = aggregates.maxY,\r
122 minYs = aggregates.minY,\r
123 startIdxs = aggregates.startIdx,\r
124 open, high, low, close, mid,\r
125 i,\r
126 pixelAdjust = attr.lineWidth * surface.devicePixelRatio / 2;\r
127\r
128 pixelAdjust -= Math.floor(pixelAdjust);\r
129 ctx.save();\r
130 template = this.raiseTemplate;\r
131 template.useAttributes(ctx, clip);\r
132 ctx.beginPath();\r
133 for (i = start; i < end; i++) {\r
134 if (opens[i] <= closes[i]) {\r
135 open = Math.round(opens[i] * yy + dy) + pixelAdjust;\r
136 high = Math.round(maxYs[i] * yy + dy) + pixelAdjust;\r
137 low = Math.round(minYs[i] * yy + dy) + pixelAdjust;\r
138 close = Math.round(closes[i] * yy + dy) + pixelAdjust;\r
139 mid = Math.round(dataX[startIdxs[i]] * xx + dx) + pixelAdjust;\r
140 me[ohlcType](ctx, open, high, low, close, mid, halfWidth);\r
141 }\r
142 }\r
143 ctx.fillStroke(template.attr);\r
144 ctx.restore();\r
145\r
146 ctx.save();\r
147 template = this.dropTemplate;\r
148 template.useAttributes(ctx, clip);\r
149 ctx.beginPath();\r
150 for (i = start; i < end; i++) {\r
151 if (opens[i] > closes[i]) {\r
152 open = Math.round(opens[i] * yy + dy) + pixelAdjust;\r
153 high = Math.round(maxYs[i] * yy + dy) + pixelAdjust;\r
154 low = Math.round(minYs[i] * yy + dy) + pixelAdjust;\r
155 close = Math.round(closes[i] * yy + dy) + pixelAdjust;\r
156 mid = Math.round(dataX[startIdxs[i]] * xx + dx) + pixelAdjust;\r
157 me[ohlcType](ctx, open, high, low, close, mid, halfWidth);\r
158 }\r
159 }\r
160 ctx.fillStroke(template.attr);\r
161 ctx.restore();\r
162 }\r
163});