4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-chart-series-Cartesian'>/**
19 </span> * @class Ext.chart.series.Cartesian
20 * @extends Ext.chart.series.Series
22 * Common base class for series implementations which plot values using x/y coordinates.
24 Ext.define('Ext.chart.series.Cartesian', {
26 /* Begin Definitions */
28 extend: 'Ext.chart.series.Series',
30 alternateClassName: ['Ext.chart.CartesianSeries', 'Ext.chart.CartesianChart'],
34 <span id='Ext-chart-series-Cartesian-property-xField'> /**
35 </span> * The field used to access the x axis value from the items from the data
43 <span id='Ext-chart-series-Cartesian-property-yField'> /**
44 </span> * The field used to access the y-axis value from the items from the data
52 <span id='Ext-chart-series-Cartesian-cfg-axis'> /**
53 </span> * @cfg {String} axis
54 * The position of the axis to bind the values to. Possible values are 'left', 'bottom', 'top' and 'right'.
55 * You must explicitly set this value to bind the values of the line series to the ones in the axis, otherwise a
56 * relative scale will be used.
60 getLegendLabels: function() {
63 combinations = me.combinations;
65 Ext.each([].concat(me.yField), function(yField, i) {
67 // Use the 'title' config if present, otherwise use the raw yField name
68 labels.push((Ext.isArray(title) ? title[i] : title) || yField);
71 // Handle yFields combined via legend drag-drop
73 Ext.each(combinations, function(combo) {
74 var label0 = labels[combo[0]],
75 label1 = labels[combo[1]];
76 labels[combo[1]] = label0 + ' & ' + label1;
77 labels.splice(combo[0], 1);
84 <span id='Ext-chart-series-Cartesian-method-eachYValue'> /**
85 </span> * @protected Iterates over a given record's values for each of this series's yFields,
86 * executing a given function for each value. Any yFields that have been combined
87 * via legend drag-drop will be treated as a single value.
88 * @param {Ext.data.Model} record
89 * @param {Function} fn
90 * @param {Object} scope
92 eachYValue: function(record, fn, scope) {
93 Ext.each(this.getYValueAccessors(), function(accessor, i) {
94 fn.call(scope, accessor(record), i);
98 <span id='Ext-chart-series-Cartesian-method-getYValueCount'> /**
99 </span> * @protected Returns the number of yField values, taking into account fields combined
100 * via legend drag-drop.
103 getYValueCount: function() {
104 return this.getYValueAccessors().length;
107 combine: function(index1, index2) {
109 accessors = me.getYValueAccessors(),
110 accessor1 = accessors[index1],
111 accessor2 = accessors[index2];
113 // Combine the yValue accessors for the two indexes into a single accessor that returns their sum
114 accessors[index2] = function(record) {
115 return accessor1(record) + accessor2(record);
117 accessors.splice(index1, 1);
119 me.callParent([index1, index2]);
122 clearCombinations: function() {
123 // Clear combined accessors, they'll get regenerated on next call to getYValueAccessors
124 delete this.yValueAccessors;
128 <span id='Ext-chart-series-Cartesian-method-getYValueAccessors'> /**
129 </span> * @protected Returns an array of functions, each of which returns the value of the yField
130 * corresponding to function's index in the array, for a given record (each function takes the
131 * record as its only argument.) If yFields have been combined by the user via legend drag-drop,
132 * this list of accessors will be kept in sync with those combinations.
133 * @return {Array} array of accessor functions
135 getYValueAccessors: function() {
137 accessors = me.yValueAccessors;
139 accessors = me.yValueAccessors = [];
140 Ext.each([].concat(me.yField), function(yField) {
141 accessors.push(function(record) {
142 return record.get(yField);
149 <span id='Ext-chart-series-Cartesian-method-getMinMaxXValues'> /**
150 </span> * Calculate the min and max values for this series's xField.
151 * @return {Array} [min, max]
153 getMinMaxXValues: function() {
158 if (me.getRecordCount() > 0) {
161 me.eachRecord(function(record) {
162 var xValue = record.get(xField);
163 if (xValue > max) {
166 if (xValue < min) {
176 <span id='Ext-chart-series-Cartesian-method-getMinMaxYValues'> /**
177 </span> * Calculate the min and max values for this series's yField(s). Takes into account yField
178 * combinations, exclusions, and stacking.
179 * @return {Array} [min, max]
181 getMinMaxYValues: function() {
183 stacked = me.stacked,
185 positiveTotal, negativeTotal;
187 function eachYValueStacked(yValue, i) {
188 if (!me.isExcluded(i)) {
190 negativeTotal += yValue;
192 positiveTotal += yValue;
197 function eachYValue(yValue, i) {
198 if (!me.isExcluded(i)) {
199 if (yValue > max) {
202 if (yValue < min) {
208 if (me.getRecordCount() > 0) {
211 me.eachRecord(function(record) {
215 me.eachYValue(record, eachYValueStacked);
216 if (positiveTotal > max) {
219 if (negativeTotal < min) {
223 me.eachYValue(record, eachYValue);
232 getAxesForXAndYFields: function() {
234 axes = me.chart.axes,
235 axis = [].concat(me.axis),
238 if (Ext.Array.indexOf(axis, 'top') > -1) {
240 } else if (Ext.Array.indexOf(axis, 'bottom') > -1) {
243 if (axes.get('top')) {
245 } else if (axes.get('bottom')) {
250 if (Ext.Array.indexOf(axis, 'left') > -1) {
252 } else if (Ext.Array.indexOf(axis, 'right') > -1) {
255 if (axes.get('left')) {
257 } else if (axes.get('right')) {