]> git.proxmox.com Git - extjs.git/blame - extjs/packages/charts/src/chart/series/Line.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / charts / src / chart / series / Line.js
CommitLineData
6527f429
DM
1/**\r
2 * @class Ext.chart.series.Line\r
3 * @extends Ext.chart.series.Cartesian\r
4 *\r
5 * Creates a Line Chart. A Line Chart is a useful visualization technique to display quantitative information for different\r
6 * categories or other real values (as opposed to the bar chart), that can show some progression (or regression) in the dataset.\r
7 * As with all other series, the Line Series must be appended in the *series* Chart array configuration. See the Chart\r
8 * documentation for more information. A typical configuration object for the line series could be:\r
9 *\r
10 * @example\r
11 * Ext.create({\r
12 * xtype: 'cartesian', \r
13 * renderTo: document.body,\r
14 * width: 600,\r
15 * height: 400,\r
16 * insetPadding: 40,\r
17 * store: {\r
18 * fields: ['name', 'data1', 'data2'],\r
19 * data: [{\r
20 * 'name': 'metric one',\r
21 * 'data1': 10,\r
22 * 'data2': 14\r
23 * }, {\r
24 * 'name': 'metric two',\r
25 * 'data1': 7,\r
26 * 'data2': 16\r
27 * }, {\r
28 * 'name': 'metric three',\r
29 * 'data1': 5,\r
30 * 'data2': 14\r
31 * }, {\r
32 * 'name': 'metric four',\r
33 * 'data1': 2,\r
34 * 'data2': 6\r
35 * }, {\r
36 * 'name': 'metric five',\r
37 * 'data1': 27,\r
38 * 'data2': 36\r
39 * }]\r
40 * },\r
41 * axes: [{\r
42 * type: 'numeric',\r
43 * position: 'left',\r
44 * fields: ['data1'],\r
45 * title: {\r
46 * text: 'Sample Values',\r
47 * fontSize: 15\r
48 * },\r
49 * grid: true,\r
50 * minimum: 0\r
51 * }, {\r
52 * type: 'category',\r
53 * position: 'bottom',\r
54 * fields: ['name'],\r
55 * title: {\r
56 * text: 'Sample Values',\r
57 * fontSize: 15\r
58 * }\r
59 * }],\r
60 * series: [{\r
61 * type: 'line',\r
62 * style: {\r
63 * stroke: '#30BDA7',\r
64 * lineWidth: 2\r
65 * },\r
66 * xField: 'name',\r
67 * yField: 'data1',\r
68 * marker: {\r
69 * type: 'path',\r
70 * path: ['M', - 4, 0, 0, 4, 4, 0, 0, - 4, 'Z'],\r
71 * stroke: '#30BDA7',\r
72 * lineWidth: 2,\r
73 * fill: 'white'\r
74 * }\r
75 * }, {\r
76 * type: 'line',\r
77 * fill: true,\r
78 * style: {\r
79 * fill: '#96D4C6',\r
80 * fillOpacity: .6,\r
81 * stroke: '#0A3F50',\r
82 * strokeOpacity: .6,\r
83 * },\r
84 * xField: 'name',\r
85 * yField: 'data2',\r
86 * marker: {\r
87 * type: 'circle',\r
88 * radius: 4,\r
89 * lineWidth: 2,\r
90 * fill: 'white'\r
91 * }\r
92 * }]\r
93 * });\r
94 *\r
95 * In this configuration we're adding two series (or lines), one bound to the `data1`\r
96 * property of the store and the other to `data3`. The type for both configurations is\r
97 * `line`. The `xField` for both series is the same, the `name` property of the store.\r
98 * Both line series share the same axis, the left axis. You can set particular marker\r
99 * configuration by adding properties onto the marker object. Both series have\r
100 * an object as highlight so that markers animate smoothly to the properties in highlight\r
101 * when hovered. The second series has `fill = true` which means that the line will also\r
102 * have an area below it of the same color.\r
103 *\r
104 * **Note:** In the series definition remember to explicitly set the axis to bind the\r
105 * values of the line series to. This can be done by using the `axis` configuration property.\r
106 */\r
107Ext.define('Ext.chart.series.Line', {\r
108 extend: 'Ext.chart.series.Cartesian',\r
109 alias: 'series.line',\r
110 type: 'line',\r
111 seriesType: 'lineSeries',\r
112\r
113 requires: [\r
114 'Ext.chart.series.sprite.Line'\r
115 ],\r
116\r
117 config: {\r
118 /**\r
119 * @cfg {Number} selectionTolerance\r
120 * The offset distance from the cursor position to the line series to trigger events (then used for highlighting series, etc).\r
121 */\r
122 selectionTolerance: 20,\r
123\r
124 /**\r
125 * @cfg {Object} style\r
126 * An object containing styles for the visualization lines. These styles will override the theme styles.\r
127 * Some options contained within the style object will are described next.\r
128 */\r
129\r
130 /**\r
131 * @cfg {Boolean/Number} smooth\r
132 * If set to `true` or a non-zero number, the line will be smoothed/rounded around its points; otherwise\r
133 * straight line segments will be drawn.\r
134 *\r
135 * A numeric value is interpreted as a divisor of the horizontal distance between consecutive points in\r
136 * the line; larger numbers result in sharper curves while smaller numbers result in smoother curves.\r
137 *\r
138 * If set to `true` then a default numeric value of 3 will be used.\r
139 */\r
140 smooth: false,\r
141\r
142 /**\r
143 * @cfg {Boolean} step\r
144 * If set to `true`, the line uses steps instead of straight lines to connect the dots.\r
145 * It is ignored if `smooth` is true.\r
146 */\r
147 step: false,\r
148\r
149 /**\r
150 * @cfg {Boolean} fill\r
151 * If set to `true`, the area underneath the line is filled with the color defined as follows, listed by priority:\r
152 * - The color that is configured for this series ({@link Ext.chart.series.Series#colors}).\r
153 * - The color that is configured for this chart ({@link Ext.chart.AbstractChart#colors}).\r
154 * - The fill color that is set in the {@link #style} config.\r
155 * - The stroke color that is set in the {@link #style} config, or the same color as the line.\r
156 *\r
157 * Note: Do not confuse `series.config.fill` (which is a boolean) with `series.style.fill' (which is an alias\r
158 * for the `fillStyle` property and contains a color). For compatibility with previous versions of the API,\r
159 * if `config.fill` is undefined but a `style.fill' color is provided, `config.fill` is considered true.\r
160 * So the default value below must be undefined, not false.\r
161 */\r
162 fill: undefined,\r
163\r
164 aggregator: { strategy: 'double' }\r
165 },\r
166\r
167 /**\r
168 * @private\r
169 * Default numeric smoothing value to be used when `{@link #smooth} = true`.\r
170 */\r
171 defaultSmoothness: 3,\r
172\r
173 /**\r
174 * @private\r
175 * Size of the buffer area on either side of the viewport to provide seamless zoom/pan\r
176 * transforms. Expressed as a multiple of the viewport length, e.g. 1 will make the buffer on\r
177 * each side equal to the length of the visible axis viewport.\r
178 */\r
179 overflowBuffer: 1,\r
180\r
181 themeMarkerCount: function() {\r
182 return 1;\r
183 },\r
184\r
185 /**\r
186 * @private\r
187 * Override {@link Ext.chart.series.Series#getDefaultSpriteConfig}\r
188 */\r
189 getDefaultSpriteConfig: function () {\r
190 var me = this,\r
191 parentConfig = me.callParent(arguments),\r
192 style = Ext.apply({}, me.getStyle()),\r
193 styleWithTheme,\r
194 fillArea = false;\r
195\r
196 if (typeof me.config.fill != 'undefined') {\r
197 // If config.fill is present but there is no fillStyle, then use the\r
198 // strokeStyle to fill (and paint the area the same color as the line).\r
199 if (me.config.fill) {\r
200 fillArea = true;\r
201 if (typeof style.fillStyle == 'undefined') {\r
202 if (typeof style.strokeStyle == 'undefined') {\r
203 styleWithTheme = me.getStyleWithTheme();\r
204 style.fillStyle = styleWithTheme.fillStyle;\r
205 style.strokeStyle = styleWithTheme.strokeStyle;\r
206 } else {\r
207 style.fillStyle = style.strokeStyle;\r
208 }\r
209 }\r
210 }\r
211 } else {\r
212 // For compatibility with previous versions of the API, if config.fill\r
213 // is undefined but style.fillStyle is provided, we fill the area.\r
214 if (style.fillStyle) {\r
215 fillArea = true;\r
216 }\r
217 }\r
218\r
219 // If we don't fill, then delete the fillStyle because that's what is used by\r
220 // the Line sprite to fill below the line.\r
221 if (!fillArea) {\r
222 delete style.fillStyle;\r
223 }\r
224\r
225 style = Ext.apply(parentConfig || {}, style);\r
226\r
227 return Ext.apply(style, {\r
228 fillArea: fillArea,\r
229 step: me.config.step,\r
230 smooth: me.config.smooth,\r
231 selectionTolerance: me.config.selectionTolerance\r
232 });\r
233 },\r
234\r
235 updateStep: function (step) {\r
236 var sprite = this.getSprites()[0];\r
237 if (sprite && sprite.attr.step !== step) {\r
238 sprite.setAttributes({step: step});\r
239 }\r
240 },\r
241\r
242 updateFill: function (fill) {\r
243 var sprite = this.getSprites()[0];\r
244 if (sprite && sprite.attr.fillArea !== fill) {\r
245 sprite.setAttributes({fillArea: fill});\r
246 }\r
247 },\r
248\r
249 updateSmooth: function (smooth) {\r
250 var sprite = this.getSprites()[0];\r
251 if (sprite && sprite.attr.smooth !== smooth) {\r
252 sprite.setAttributes({smooth: smooth});\r
253 }\r
254 }\r
255\r
256});