Cartesian.html
11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-chart-series-Cartesian'>/**
</span> * @class Ext.chart.series.Cartesian
*
* Common base class for series implementations which plot values using x/y coordinates.
*/
Ext.define('Ext.chart.series.Cartesian', {
/* Begin Definitions */
extend: 'Ext.chart.series.Series',
alternateClassName: ['Ext.chart.CartesianSeries', 'Ext.chart.CartesianChart'],
/* End Definitions */
<span id='Ext-chart-series-Cartesian-property-xField'> /**
</span> * The field used to access the x axis value from the items from the data
* source.
*
* @cfg xField
* @type String
*/
xField: null,
<span id='Ext-chart-series-Cartesian-property-yField'> /**
</span> * The field used to access the y-axis value from the items from the data
* source.
*
* @cfg yField
* @type String
*/
yField: null,
<span id='Ext-chart-series-Cartesian-cfg-axis'> /**
</span> * @cfg {String/String[]} axis
* The position of the axis to bind the values to. Possible values are 'left', 'bottom', 'top' and 'right'.
* You must explicitly set this value to bind the values of the line series to the ones in the axis, otherwise a
* relative scale will be used. For example, if you're using a Scatter or Line series and you'd like to have the
* values in the chart relative to the bottom and left axes then `axis` should be `['left', 'bottom']`.
*/
axis: 'left',
getLegendLabels: function() {
var me = this,
labels = [],
fields, i, ln,
combinations = me.combinations,
title,
combo, label0, label1;
fields = [].concat(me.yField);
for (i = 0, ln = fields.length; i < ln; i++) {
title = me.title;
// Use the 'title' config if present, otherwise use the raw yField name
labels.push((Ext.isArray(title) ? title[i] : title) || fields[i]);
}
// Handle yFields combined via legend drag-drop
// TODO need to check to see if this is supported in extjs 4 branch
if (combinations) {
combinations = Ext.Array.from(combinations);
for (i = 0, ln = combinations.length; i < ln; i++) {
combo = combinations[i];
label0 = labels[combo[0]];
label1 = labels[combo[1]];
labels[combo[1]] = label0 + ' & ' + label1;
labels.splice(combo[0], 1);
}
}
return labels;
},
<span id='Ext-chart-series-Cartesian-method-eachYValue'> /**
</span> * @protected Iterates over a given record's values for each of this series's yFields,
* executing a given function for each value. Any yFields that have been combined
* via legend drag-drop will be treated as a single value.
* @param {Ext.data.Model} record
* @param {Function} fn
* @param {Object} scope
*/
eachYValue: function(record, fn, scope) {
var me = this,
yValueAccessors = me.getYValueAccessors(),
i, ln, accessor;
for (i = 0, ln = yValueAccessors.length; i < ln; i++) {
accessor = yValueAccessors[i];
fn.call(scope, accessor(record), i);
}
},
<span id='Ext-chart-series-Cartesian-method-getYValueCount'> /**
</span> * @protected Returns the number of yField values, taking into account fields combined
* via legend drag-drop.
* @return {Number}
*/
getYValueCount: function() {
return this.getYValueAccessors().length;
},
combine: function(index1, index2) {
var me = this,
accessors = me.getYValueAccessors(),
accessor1 = accessors[index1],
accessor2 = accessors[index2];
// Combine the yValue accessors for the two indexes into a single accessor that returns their sum
accessors[index2] = function(record) {
return accessor1(record) + accessor2(record);
};
accessors.splice(index1, 1);
me.callParent([index1, index2]);
},
clearCombinations: function() {
// Clear combined accessors, they'll get regenerated on next call to getYValueAccessors
delete this.yValueAccessors;
this.callParent();
},
<span id='Ext-chart-series-Cartesian-method-getYValueAccessors'> /**
</span> * @protected Returns an array of functions, each of which returns the value of the yField
* corresponding to function's index in the array, for a given record (each function takes the
* record as its only argument.) If yFields have been combined by the user via legend drag-drop,
* this list of accessors will be kept in sync with those combinations.
* @return {Array} array of accessor functions
*/
getYValueAccessors: function() {
var me = this,
accessors = me.yValueAccessors,
yFields, yField, i, ln;
if (!accessors) {
accessors = me.yValueAccessors = [];
yFields = [].concat(me.yField);
for (i = 0, ln = yFields.length; i < ln; i++) {
yField = yFields[i];
accessors.push(function(record) {
return record.get(yField);
});
}
}
return accessors;
},
<span id='Ext-chart-series-Cartesian-method-getMinMaxXValues'> /**
</span> * Calculate the min and max values for this series's xField.
* @return {Array} [min, max]
*/
getMinMaxXValues: function() {
var me = this,
chart = me.chart,
store = chart.getChartStore(),
data = store.data.items,
i, ln, record,
min, max,
xField = me.xField,
xValue;
if (me.getRecordCount() > 0) {
min = Infinity;
max = -min;
for (i = 0, ln = data.length; i < ln; i++) {
record = data[i];
xValue = record.get(xField);
if (xValue > max) {
max = xValue;
}
if (xValue < min) {
min = xValue;
}
}
} else {
min = max = 0;
}
return [min, max];
},
<span id='Ext-chart-series-Cartesian-method-getMinMaxYValues'> /**
</span> * Calculate the min and max values for this series's yField(s). Takes into account yField
* combinations, exclusions, and stacking.
* @return {Array} [min, max]
*/
getMinMaxYValues: function() {
var me = this,
chart = me.chart,
store = chart.getChartStore(),
data = store.data.items,
i, ln, record,
stacked = me.stacked,
min, max,
positiveTotal, negativeTotal;
function eachYValueStacked(yValue, i) {
if (!me.isExcluded(i)) {
if (yValue < 0) {
negativeTotal += yValue;
} else {
positiveTotal += yValue;
}
}
}
function eachYValue(yValue, i) {
if (!me.isExcluded(i)) {
if (yValue > max) {
max = yValue;
}
if (yValue < min) {
min = yValue;
}
}
}
if (me.getRecordCount() > 0) {
min = Infinity;
max = -min;
for (i = 0, ln = data.length; i < ln; i++) {
record = data[i];
if (stacked) {
positiveTotal = 0;
negativeTotal = 0;
me.eachYValue(record, eachYValueStacked);
if (positiveTotal > max) {
max = positiveTotal;
}
if (negativeTotal < min) {
min = negativeTotal;
}
} else {
me.eachYValue(record, eachYValue);
}
}
} else {
min = max = 0;
}
return [min, max];
},
getAxesForXAndYFields: function() {
var me = this,
axes = me.chart.axes,
axis = [].concat(me.axis),
yFields = {}, yFieldList = [].concat(me.yField),
xFields = {}, xFieldList = [].concat(me.xField),
fields, xAxis, yAxis, i, ln, flipXY;
flipXY = me.type === 'bar' && me.column === false;
if(flipXY) {
fields = yFieldList;
yFieldList = xFieldList;
xFieldList = fields;
}
if (Ext.Array.indexOf(axis, 'top') > -1) {
xAxis = 'top';
} else if (Ext.Array.indexOf(axis, 'bottom') > -1) {
xAxis = 'bottom';
} else {
if (axes.get('top') && axes.get('bottom')) {
for (i = 0, ln = xFieldList.length; i < ln; i++) {
xFields[xFieldList[i]] = true;
}
fields = [].concat(axes.get('bottom').fields);
for (i = 0, ln = fields.length; i < ln; i++) {
if (xFields[fields[i]]) {
xAxis = 'bottom';
break
}
}
fields = [].concat(axes.get('top').fields);
for (i = 0, ln = fields.length; i < ln; i++) {
if (xFields[fields[i]]) {
xAxis = 'top';
break
}
}
} else if (axes.get('top')) {
xAxis = 'top';
} else if (axes.get('bottom')) {
xAxis = 'bottom';
}
}
if (Ext.Array.indexOf(axis, 'left') > -1) {
yAxis = 'left';
} else if (Ext.Array.indexOf(axis, 'right') > -1) {
yAxis = 'right';
} else {
if (axes.get('left') && axes.get('right')) {
for (i = 0, ln = yFieldList.length; i < ln; i++) {
yFields[yFieldList[i]] = true;
}
fields = [].concat(axes.get('right').fields);
for (i = 0, ln = fields.length; i < ln; i++) {
if (yFields[fields[i]]) {
break
}
}
fields = [].concat(axes.get('left').fields);
for (i = 0, ln = fields.length; i < ln; i++) {
if (yFields[fields[i]]) {
yAxis = 'left';
break
}
}
} else if (axes.get('left')) {
yAxis = 'left';
} else if (axes.get('right')) {
yAxis = 'right';
}
}
return flipXY ? {
xAxis: yAxis,
yAxis: xAxis
}: {
xAxis: xAxis,
yAxis: yAxis
};
}
});
</pre>
</body>
</html>