3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.chart.series.Cartesian
17 * @extends Ext.chart.series.Series
19 * Common base class for series implementations which plot values using x/y coordinates.
21 Ext.define('Ext.chart.series.Cartesian', {
23 /* Begin Definitions */
25 extend: 'Ext.chart.series.Series',
27 alternateClassName: ['Ext.chart.CartesianSeries', 'Ext.chart.CartesianChart'],
32 * The field used to access the x axis value from the items from the data
41 * The field used to access the y-axis value from the items from the data
51 * The position of the axis to bind the values to. Possible values are 'left', 'bottom', 'top' and 'right'.
52 * You must explicitly set this value to bind the values of the line series to the ones in the axis, otherwise a
53 * relative scale will be used.
57 getLegendLabels: function() {
60 combinations = me.combinations;
62 Ext.each([].concat(me.yField), function(yField, i) {
64 // Use the 'title' config if present, otherwise use the raw yField name
65 labels.push((Ext.isArray(title) ? title[i] : title) || yField);
68 // Handle yFields combined via legend drag-drop
70 Ext.each(combinations, function(combo) {
71 var label0 = labels[combo[0]],
72 label1 = labels[combo[1]];
73 labels[combo[1]] = label0 + ' & ' + label1;
74 labels.splice(combo[0], 1);
82 * @protected Iterates over a given record's values for each of this series's yFields,
83 * executing a given function for each value. Any yFields that have been combined
84 * via legend drag-drop will be treated as a single value.
85 * @param {Ext.data.Model} record
86 * @param {Function} fn
87 * @param {Object} scope
89 eachYValue: function(record, fn, scope) {
90 Ext.each(this.getYValueAccessors(), function(accessor, i) {
91 fn.call(scope, accessor(record), i);
96 * @protected Returns the number of yField values, taking into account fields combined
97 * via legend drag-drop.
100 getYValueCount: function() {
101 return this.getYValueAccessors().length;
104 combine: function(index1, index2) {
106 accessors = me.getYValueAccessors(),
107 accessor1 = accessors[index1],
108 accessor2 = accessors[index2];
110 // Combine the yValue accessors for the two indexes into a single accessor that returns their sum
111 accessors[index2] = function(record) {
112 return accessor1(record) + accessor2(record);
114 accessors.splice(index1, 1);
116 me.callParent([index1, index2]);
119 clearCombinations: function() {
120 // Clear combined accessors, they'll get regenerated on next call to getYValueAccessors
121 delete this.yValueAccessors;
126 * @protected Returns an array of functions, each of which returns the value of the yField
127 * corresponding to function's index in the array, for a given record (each function takes the
128 * record as its only argument.) If yFields have been combined by the user via legend drag-drop,
129 * this list of accessors will be kept in sync with those combinations.
130 * @return {Array} array of accessor functions
132 getYValueAccessors: function() {
134 accessors = me.yValueAccessors;
136 accessors = me.yValueAccessors = [];
137 Ext.each([].concat(me.yField), function(yField) {
138 accessors.push(function(record) {
139 return record.get(yField);
147 * Calculate the min and max values for this series's xField.
148 * @return {Array} [min, max]
150 getMinMaxXValues: function() {
155 if (me.getRecordCount() > 0) {
158 me.eachRecord(function(record) {
159 var xValue = record.get(xField);
174 * Calculate the min and max values for this series's yField(s). Takes into account yField
175 * combinations, exclusions, and stacking.
176 * @return {Array} [min, max]
178 getMinMaxYValues: function() {
180 stacked = me.stacked,
182 positiveTotal, negativeTotal;
184 function eachYValueStacked(yValue, i) {
185 if (!me.isExcluded(i)) {
187 negativeTotal += yValue;
189 positiveTotal += yValue;
194 function eachYValue(yValue, i) {
195 if (!me.isExcluded(i)) {
205 if (me.getRecordCount() > 0) {
208 me.eachRecord(function(record) {
212 me.eachYValue(record, eachYValueStacked);
213 if (positiveTotal > max) {
216 if (negativeTotal < min) {
220 me.eachYValue(record, eachYValue);
229 getAxesForXAndYFields: function() {
231 axes = me.chart.axes,
232 axis = [].concat(me.axis),
235 if (Ext.Array.indexOf(axis, 'top') > -1) {
237 } else if (Ext.Array.indexOf(axis, 'bottom') > -1) {
240 if (axes.get('top')) {
242 } else if (axes.get('bottom')) {
247 if (Ext.Array.indexOf(axis, 'left') > -1) {
249 } else if (Ext.Array.indexOf(axis, 'right') > -1) {
252 if (axes.get('left')) {
254 } else if (axes.get('right')) {