Chart.html
36.2 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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
<!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-Chart'>/**
</span> * Charts provide a flexible way to achieve a wide range of data visualization capablitities.
* Each Chart gets its data directly from a {@link Ext.data.Store Store}, and automatically
* updates its display whenever data in the Store changes. In addition, the look and feel
* of a Chart can be customized using {@link Ext.chart.theme.Theme Theme}s.
*
* ## Creating a Simple Chart
*
* Every Chart has three key parts - a {@link Ext.data.Store Store} that contains the data,
* an array of {@link Ext.chart.axis.Axis Axes} which define the boundaries of the Chart,
* and one or more {@link Ext.chart.series.Series Series} to handle the visual rendering of the data points.
*
* ### 1. Creating a Store
*
* The first step is to create a {@link Ext.data.Model Model} that represents the type of
* data that will be displayed in the Chart. For example the data for a chart that displays
* a weather forecast could be represented as a series of "WeatherPoint" data points with
* two fields - "temperature", and "date":
*
* Ext.define('WeatherPoint', {
* extend: 'Ext.data.Model',
* fields: ['temperature', 'date']
* });
*
* Next a {@link Ext.data.Store Store} must be created. The store contains a collection of "WeatherPoint" Model instances.
* The data could be loaded dynamically, but for sake of ease this example uses inline data:
*
* var store = Ext.create('Ext.data.Store', {
* model: 'WeatherPoint',
* data: [
* { temperature: 58, date: new Date(2011, 1, 1, 8) },
* { temperature: 63, date: new Date(2011, 1, 1, 9) },
* { temperature: 73, date: new Date(2011, 1, 1, 10) },
* { temperature: 78, date: new Date(2011, 1, 1, 11) },
* { temperature: 81, date: new Date(2011, 1, 1, 12) }
* ]
* });
*
* For additional information on Models and Stores please refer to the [Data Guide](#/guide/data).
*
* ### 2. Creating the Chart object
*
* Now that a Store has been created it can be used in a Chart:
*
* Ext.create('Ext.chart.Chart', {
* renderTo: Ext.getBody(),
* width: 400,
* height: 300,
* store: store
* });
*
* That's all it takes to create a Chart instance that is backed by a Store.
* However, if the above code is run in a browser, a blank screen will be displayed.
* This is because the two pieces that are responsible for the visual display,
* the Chart's {@link #cfg-axes axes} and {@link #cfg-series series}, have not yet been defined.
*
* ### 3. Configuring the Axes
*
* {@link Ext.chart.axis.Axis Axes} are the lines that define the boundaries of the data points that a Chart can display.
* This example uses one of the most common Axes configurations - a horizontal "x" axis, and a vertical "y" axis:
*
* Ext.create('Ext.chart.Chart', {
* ...
* axes: [
* {
* title: 'Temperature',
* type: 'Numeric',
* position: 'left',
* fields: ['temperature'],
* minimum: 0,
* maximum: 100
* },
* {
* title: 'Time',
* type: 'Time',
* position: 'bottom',
* fields: ['date'],
* dateFormat: 'ga'
* }
* ]
* });
*
* The "Temperature" axis is a vertical {@link Ext.chart.axis.Numeric Numeric Axis} and is positioned on the left edge of the Chart.
* It represents the bounds of the data contained in the "WeatherPoint" Model's "temperature" field that was
* defined above. The minimum value for this axis is "0", and the maximum is "100".
*
* The horizontal axis is a {@link Ext.chart.axis.Time Time Axis} and is positioned on the bottom edge of the Chart.
* It represents the bounds of the data contained in the "WeatherPoint" Model's "date" field.
* The {@link Ext.chart.axis.Time#cfg-dateFormat dateFormat}
* configuration tells the Time Axis how to format it's labels.
*
* Here's what the Chart looks like now that it has its Axes configured:
*
* {@img Ext.chart.Chart/Ext.chart.Chart1.png Chart Axes}
*
* ### 4. Configuring the Series
*
* The final step in creating a simple Chart is to configure one or more {@link Ext.chart.series.Series Series}.
* Series are responsible for the visual representation of the data points contained in the Store.
* This example only has one Series:
*
* Ext.create('Ext.chart.Chart', {
* ...
* axes: [
* ...
* ],
* series: [
* {
* type: 'line',
* xField: 'date',
* yField: 'temperature'
* }
* ]
* });
*
* This Series is a {@link Ext.chart.series.Line Line Series}, and it uses the "date" and "temperature" fields
* from the "WeatherPoint" Models in the Store to plot its data points:
*
* {@img Ext.chart.Chart/Ext.chart.Chart2.png Line Series}
*
* See the [Line Charts Example](#!/example/charts/Charts.html) for a live demo.
*
* ## Themes
*
* The color scheme for a Chart can be easily changed using the {@link #cfg-theme theme} configuration option:
*
* Ext.create('Ext.chart.Chart', {
* ...
* theme: 'Green',
* ...
* });
*
* {@img Ext.chart.Chart/Ext.chart.Chart3.png Green Theme}
*
* For more information on Charts please refer to the [Drawing and Charting Guide](#/guide/drawing_and_charting).
*
*/
Ext.define('Ext.chart.Chart', {
/* Begin Definitions */
alias: 'widget.chart',
extend: 'Ext.draw.Component',
mixins: {
themeManager: 'Ext.chart.theme.Theme',
mask: 'Ext.chart.Mask',
navigation: 'Ext.chart.Navigation',
bindable: 'Ext.util.Bindable',
observable: 'Ext.util.Observable'
},
uses: [
'Ext.chart.series.Series'
],
requires: [
'Ext.util.MixedCollection',
'Ext.data.StoreManager',
'Ext.chart.Legend',
'Ext.chart.theme.Base',
'Ext.chart.theme.Theme',
'Ext.util.DelayedTask'
],
/* End Definitions */
// @private
viewBox: false,
<span id='Ext-chart-Chart-cfg-theme'> /**
</span> * @cfg {String} theme
* The name of the theme to be used. A theme defines the colors and other visual displays of tick marks
* on axis, text, title text, line colors, marker colors and styles, etc. Possible theme values are 'Base', 'Green',
* 'Sky', 'Red', 'Purple', 'Blue', 'Yellow' and also six category themes 'Category1' to 'Category6'. Default value
* is 'Base'.
*/
<span id='Ext-chart-Chart-cfg-animate'> /**
</span> * @cfg {Boolean/Object} animate
* True for the default animation (easing: 'ease' and duration: 500) or a standard animation config
* object to be used for default chart animations. Defaults to false.
*/
animate: false,
<span id='Ext-chart-Chart-cfg-legend'> /**
</span> * @cfg {Boolean/Object} legend
* True for the default legend display or a legend config object. Defaults to false.
*/
legend: false,
<span id='Ext-chart-Chart-cfg-insetPadding'> /**
</span> * @cfg {Number} insetPadding
* The amount of inset padding in pixels for the chart. Defaults to 10.
*/
insetPadding: 10,
<span id='Ext-chart-Chart-cfg-enginePriority'> /**
</span> * @cfg {String[]} enginePriority
* Defines the priority order for which Surface implementation to use. The first one supported by the current
* environment will be used. Defaults to `['Svg', 'Vml']`.
*/
enginePriority: ['Svg', 'Vml'],
<span id='Ext-chart-Chart-cfg-background'> /**
</span> * @cfg {Object/Boolean} background
* The chart background. This can be a gradient object, image, or color. Defaults to false for no
* background. For example, if `background` were to be a color we could set the object as
*
* background: {
* //color string
* fill: '#ccc'
* }
*
* You can specify an image by using:
*
* background: {
* image: 'http://path.to.image/'
* }
*
* Also you can specify a gradient by using the gradient object syntax:
*
* background: {
* gradient: {
* id: 'gradientId',
* angle: 45,
* stops: {
* 0: {
* color: '#555'
* }
* 100: {
* color: '#ddd'
* }
* }
* }
* }
*/
background: false,
<span id='Ext-chart-Chart-cfg-gradients'> /**
</span> * @cfg {Object[]} gradients
* Define a set of gradients that can be used as `fill` property in sprites. The gradients array is an
* array of objects with the following properties:
*
* - **id** - string - The unique name of the gradient.
* - **angle** - number, optional - The angle of the gradient in degrees.
* - **stops** - object - An object with numbers as keys (from 0 to 100) and style objects as values
*
* For example:
*
* gradients: [{
* id: 'gradientId',
* angle: 45,
* stops: {
* 0: {
* color: '#555'
* },
* 100: {
* color: '#ddd'
* }
* }
* }, {
* id: 'gradientId2',
* angle: 0,
* stops: {
* 0: {
* color: '#590'
* },
* 20: {
* color: '#599'
* },
* 100: {
* color: '#ddd'
* }
* }
* }]
*
* Then the sprites can use `gradientId` and `gradientId2` by setting the fill attributes to those ids, for example:
*
* sprite.setAttributes({
* fill: 'url(#gradientId)'
* }, true);
*/
<span id='Ext-chart-Chart-cfg-store'> /**
</span> * @cfg {Ext.data.Store} store
* The store that supplies data to this chart.
*/
<span id='Ext-chart-Chart-cfg-series'> /**
</span> * @cfg {Ext.chart.series.Series[]} series
* Array of {@link Ext.chart.series.Series Series} instances or config objects. For example:
*
* series: [{
* type: 'column',
* axis: 'left',
* listeners: {
* 'afterrender': function() {
* console('afterrender');
* }
* },
* xField: 'category',
* yField: 'data1'
* }]
*/
<span id='Ext-chart-Chart-cfg-axes'> /**
</span> * @cfg {Ext.chart.axis.Axis[]} axes
* Array of {@link Ext.chart.axis.Axis Axis} instances or config objects. For example:
*
* axes: [{
* type: 'Numeric',
* position: 'left',
* fields: ['data1'],
* title: 'Number of Hits',
* minimum: 0,
* //one minor tick between two major ticks
* minorTickSteps: 1
* }, {
* type: 'Category',
* position: 'bottom',
* fields: ['name'],
* title: 'Month of the Year'
* }]
*/
constructor: function(config) {
var me = this,
defaultAnim;
config = Ext.apply({}, config);
me.initTheme(config.theme || me.theme);
if (me.gradients) {
Ext.apply(config, { gradients: me.gradients });
}
if (me.background) {
Ext.apply(config, { background: me.background });
}
if (config.animate) {
defaultAnim = {
easing: 'ease',
duration: 500
};
if (Ext.isObject(config.animate)) {
config.animate = Ext.applyIf(config.animate, defaultAnim);
}
else {
config.animate = defaultAnim;
}
}
me.mixins.observable.constructor.call(me, config);
if (config.enableMask) {
me.mixins.mask.constructor.call(me);
}
me.mixins.navigation.constructor.call(me);
me.callParent([config]);
},
getChartStore: function(){
return this.substore || this.store;
},
initComponent: function() {
var me = this,
axes,
series;
me.callParent();
me.addEvents(
'itemmousedown',
'itemmouseup',
'itemmouseover',
'itemmouseout',
'itemclick',
'itemdblclick',
'itemdragstart',
'itemdrag',
'itemdragend',
<span id='Ext-chart-Chart-event-beforerefresh'> /**
</span> * @event beforerefresh
* Fires before a refresh to the chart data is called. If the beforerefresh handler returns false the
* {@link #event-refresh} action will be cancelled.
* @param {Ext.chart.Chart} this
*/
'beforerefresh',
<span id='Ext-chart-Chart-event-refresh'> /**
</span> * @event refresh
* Fires after the chart data has been refreshed.
* @param {Ext.chart.Chart} this
*/
'refresh'
);
Ext.applyIf(me, {
zoom: {
width: 1,
height: 1,
x: 0,
y: 0
}
});
me.maxGutter = [0, 0];
me.store = Ext.data.StoreManager.lookup(me.store);
axes = me.axes;
me.axes = new Ext.util.MixedCollection(false, function(a) { return a.position; });
if (axes) {
me.axes.addAll(axes);
}
series = me.series;
me.series = new Ext.util.MixedCollection(false, function(a) { return a.seriesId || (a.seriesId = Ext.id(null, 'ext-chart-series-')); });
if (series) {
me.series.addAll(series);
}
if (me.legend !== false) {
me.legend = new Ext.chart.Legend(Ext.applyIf({chart:me}, me.legend));
}
me.on({
mousemove: me.onMouseMove,
mouseleave: me.onMouseLeave,
mousedown: me.onMouseDown,
mouseup: me.onMouseUp,
click: me.onClick,
dblclick: me.onDblClick,
scope: me
});
},
// @private overrides the component method to set the correct dimensions to the chart.
afterComponentLayout: function(width, height) {
var me = this;
if (Ext.isNumber(width) && Ext.isNumber(height)) {
if (width !== me.curWidth || height !== me.curHeight) {
me.curWidth = width;
me.curHeight = height;
me.redraw(true);
} else if (me.needsRedraw) {
delete me.needsRedraw;
me.redraw();
}
}
this.callParent(arguments);
},
<span id='Ext-chart-Chart-method-redraw'> /**
</span> * Redraws the chart. If animations are set this will animate the chart too.
* @param {Boolean} resize (optional) flag which changes the default origin points of the chart for animations.
*/
redraw: function(resize) {
var me = this,
seriesItems = me.series.items,
seriesLen = seriesItems.length,
axesItems = me.axes.items,
axesLen = axesItems.length,
i,
chartBBox = me.chartBBox = {
x: 0,
y: 0,
height: me.curHeight,
width: me.curWidth
},
legend = me.legend;
me.surface.setSize(chartBBox.width, chartBBox.height);
// Instantiate Series and Axes
for (i = 0; i < seriesLen; i++) {
me.initializeSeries(seriesItems[i],i);
}
for (i = 0; i < axesLen; i++) {
me.initializeAxis(axesItems[i]);
}
//process all views (aggregated data etc) on stores
//before rendering.
for (i = 0; i < axesLen; i++) {
axesItems[i].processView();
}
for (i = 0; i < axesLen; i++) {
axesItems[i].drawAxis(true);
}
// Create legend if not already created
if (legend !== false && legend.visible) {
if (legend.update || !legend.created) {
legend.create();
}
}
// Place axes properly, including influence from each other
me.alignAxes();
// Reposition legend based on new axis alignment
if (legend !== false && legend.visible) {
legend.updatePosition();
}
// Find the max gutter
me.getMaxGutter();
// Draw axes and series
me.resizing = !!resize;
for (i = 0; i < axesLen; i++) {
axesItems[i].drawAxis();
}
for (i = 0; i < seriesLen; i++) {
me.drawCharts(seriesItems[i]);
}
me.resizing = false;
},
// @private set the store after rendering the chart.
afterRender: function() {
var ref,
me = this;
this.callParent();
if (me.categoryNames) {
me.setCategoryNames(me.categoryNames);
}
if (me.tipRenderer) {
ref = me.getFunctionRef(me.tipRenderer);
me.setTipRenderer(ref.fn, ref.scope);
}
me.bindStore(me.store, true);
me.refresh();
if (me.surface.engine === 'Vml') {
me.on('added', me.onAddedVml, me);
me.mon(Ext.container.Container.hierarchyEventSource, 'added', me.onContainerAddedVml, me);
}
},
// When using a vml surface we need to redraw when this chart or one of its ancestors
// is moved to a new container after render, because moving the vml chart causes the
// vml elements to go haywire, some displaing incorrectly or not displaying at all.
// This appears to be caused by the component being moved to the detached body element
// before being added to the new container.
onAddedVml: function() {
this.needsRedraw = true; // redraw after component layout
},
onContainerAddedVml: function(container) {
if (this.isDescendantOf(container)) {
this.needsRedraw = true; // redraw after component layout
}
},
// @private get x and y position of the mouse cursor.
getEventXY: function(e) {
var me = this,
box = this.surface.getRegion(),
pageXY = e.getXY(),
x = pageXY[0] - box.left,
y = pageXY[1] - box.top;
return [x, y];
},
onClick: function(e) {
this.handleClick('itemclick', e);
},
onDblClick: function(e) {
this.handleClick('itemdblclick', e);
},
// @private wrap the mouse down position to delegate the event to the series.
handleClick: function(name, e) {
var me = this,
position = me.getEventXY(e),
seriesItems = me.series.items,
i, ln, series,
item;
// Ask each series if it has an item corresponding to (not necessarily exactly
// on top of) the current mouse coords. Fire itemclick event.
for (i = 0, ln = seriesItems.length; i < ln; i++) {
series = seriesItems[i];
if (Ext.draw.Draw.withinBox(position[0], position[1], series.bbox)) {
if (series.getItemForPoint) {
item = series.getItemForPoint(position[0], position[1]);
if (item) {
series.fireEvent(name, item);
}
}
}
}
},
// @private wrap the mouse down position to delegate the event to the series.
onMouseDown: function(e) {
var me = this,
position = me.getEventXY(e),
seriesItems = me.series.items,
i, ln, series,
item;
if (me.enableMask) {
me.mixins.mask.onMouseDown.call(me, e);
}
// Ask each series if it has an item corresponding to (not necessarily exactly
// on top of) the current mouse coords. Fire itemmousedown event.
for (i = 0, ln = seriesItems.length; i < ln; i++) {
series = seriesItems[i];
if (Ext.draw.Draw.withinBox(position[0], position[1], series.bbox)) {
if (series.getItemForPoint) {
item = series.getItemForPoint(position[0], position[1]);
if (item) {
series.fireEvent('itemmousedown', item);
}
}
}
}
},
// @private wrap the mouse up event to delegate it to the series.
onMouseUp: function(e) {
var me = this,
position = me.getEventXY(e),
seriesItems = me.series.items,
i, ln, series,
item;
if (me.enableMask) {
me.mixins.mask.onMouseUp.call(me, e);
}
// Ask each series if it has an item corresponding to (not necessarily exactly
// on top of) the current mouse coords. Fire itemmouseup event.
for (i = 0, ln = seriesItems.length; i < ln; i++) {
series = seriesItems[i];
if (Ext.draw.Draw.withinBox(position[0], position[1], series.bbox)) {
if (series.getItemForPoint) {
item = series.getItemForPoint(position[0], position[1]);
if (item) {
series.fireEvent('itemmouseup', item);
}
}
}
}
},
// @private wrap the mouse move event so it can be delegated to the series.
onMouseMove: function(e) {
var me = this,
position = me.getEventXY(e),
seriesItems = me.series.items,
i, ln, series,
item, last, storeItem, storeField;
if (me.enableMask) {
me.mixins.mask.onMouseMove.call(me, e);
}
// Ask each series if it has an item corresponding to (not necessarily exactly
// on top of) the current mouse coords. Fire itemmouseover/out events.
for (i = 0, ln = seriesItems.length; i < ln; i++) {
series = seriesItems[i];
if (Ext.draw.Draw.withinBox(position[0], position[1], series.bbox)) {
if (series.getItemForPoint) {
item = series.getItemForPoint(position[0], position[1]);
last = series._lastItemForPoint;
storeItem = series._lastStoreItem;
storeField = series._lastStoreField;
if (item !== last || item && (item.storeItem != storeItem || item.storeField != storeField)) {
if (last) {
series.fireEvent('itemmouseout', last);
delete series._lastItemForPoint;
delete series._lastStoreField;
delete series._lastStoreItem;
}
if (item) {
series.fireEvent('itemmouseover', item);
series._lastItemForPoint = item;
series._lastStoreItem = item.storeItem;
series._lastStoreField = item.storeField;
}
}
}
} else {
last = series._lastItemForPoint;
if (last) {
series.fireEvent('itemmouseout', last);
delete series._lastItemForPoint;
delete series._lastStoreField;
delete series._lastStoreItem;
}
}
}
},
// @private handle mouse leave event.
onMouseLeave: function(e) {
var me = this,
seriesItems = me.series.items,
i, ln, series;
if (me.enableMask) {
me.mixins.mask.onMouseLeave.call(me, e);
}
for (i = 0, ln = seriesItems.length; i < ln; i++) {
series = seriesItems[i];
delete series._lastItemForPoint;
}
},
// @private buffered refresh for when we update the store
delayRefresh: function() {
var me = this;
if (!me.refreshTask) {
me.refreshTask = new Ext.util.DelayedTask(me.refresh, me);
}
me.refreshTask.delay(me.refreshBuffer);
},
// @private
refresh: function() {
var me = this;
if (me.rendered && me.curWidth !== undefined && me.curHeight !== undefined) {
if (!me.isVisible(true) && !me.refreshPending) {
me.setShowListeners('mon');
me.refreshPending = true;
return;
}
if (me.fireEvent('beforerefresh', me) !== false) {
me.redraw();
me.fireEvent('refresh', me);
}
}
},
onShow: function(){
var me = this;
me.callParent(arguments);
if (me.refreshPending) {
me.delayRefresh();
me.setShowListeners('mun');
}
delete me.refreshPending;
},
setShowListeners: function(method){
var me = this;
me[method](Ext.container.Container.hierarchyEventSource, {
scope: me,
single: true,
show: me.forceRefresh,
expand: me.forceRefresh
});
},
forceRefresh: function(container) {
var me = this;
if (me.isDescendantOf(container) && me.refreshPending) {
// Add unbind here, because either expand/show could be fired,
// so be sure to unbind the listener that didn't
me.setShowListeners('mun');
me.delayRefresh();
}
delete me.refreshPending;
},
bindStore: function(store, initial) {
var me = this;
me.mixins.bindable.bindStore.apply(me, arguments);
if (me.store && !initial) {
me.refresh();
}
},
getStoreListeners: function() {
var refresh = this.refresh,
delayRefresh = this.delayRefresh;
return {
refresh: refresh,
add: delayRefresh,
remove: delayRefresh,
update: delayRefresh,
clear: refresh
};
},
// @private Create Axis
initializeAxis: function(axis) {
var me = this,
chartBBox = me.chartBBox,
w = chartBBox.width,
h = chartBBox.height,
x = chartBBox.x,
y = chartBBox.y,
themeAttrs = me.themeAttrs,
config = {
chart: me
};
if (themeAttrs) {
config.axisStyle = Ext.apply({}, themeAttrs.axis);
config.axisLabelLeftStyle = Ext.apply({}, themeAttrs.axisLabelLeft);
config.axisLabelRightStyle = Ext.apply({}, themeAttrs.axisLabelRight);
config.axisLabelTopStyle = Ext.apply({}, themeAttrs.axisLabelTop);
config.axisLabelBottomStyle = Ext.apply({}, themeAttrs.axisLabelBottom);
config.axisTitleLeftStyle = Ext.apply({}, themeAttrs.axisTitleLeft);
config.axisTitleRightStyle = Ext.apply({}, themeAttrs.axisTitleRight);
config.axisTitleTopStyle = Ext.apply({}, themeAttrs.axisTitleTop);
config.axisTitleBottomStyle = Ext.apply({}, themeAttrs.axisTitleBottom);
}
switch (axis.position) {
case 'top':
Ext.apply(config, {
length: w,
width: h,
x: x,
y: y
});
break;
case 'bottom':
Ext.apply(config, {
length: w,
width: h,
x: x,
y: h
});
break;
case 'left':
Ext.apply(config, {
length: h,
width: w,
x: x,
y: h
});
break;
case 'right':
Ext.apply(config, {
length: h,
width: w,
x: w,
y: h
});
break;
}
if (!axis.chart) {
Ext.apply(config, axis);
axis = me.axes.replace(Ext.createByAlias('axis.' + axis.type.toLowerCase(), config));
}
else {
Ext.apply(axis, config);
}
},
<span id='Ext-chart-Chart-method-alignAxes'> /**
</span> * @private Adjust the dimensions and positions of each axis and the chart body area after accounting
* for the space taken up on each side by the axes and legend.
*/
alignAxes: function() {
var me = this,
axes = me.axes,
axesItems = axes.items,
axis,
legend = me.legend,
edges = ['top', 'right', 'bottom', 'left'],
edge,
i, ln,
chartBBox,
insetPadding = me.insetPadding,
insets = {
top: insetPadding,
right: insetPadding,
bottom: insetPadding,
left: insetPadding
},
isVertical, bbox, pos;
function getAxis(edge) {
var i = axes.findIndex('position', edge);
return (i < 0) ? null : axes.getAt(i);
}
// Find the space needed by axes and legend as a positive inset from each edge
for (i = 0, ln = edges.length; i < ln; i++) {
edge = edges[i];
isVertical = (edge === 'left' || edge === 'right');
axis = getAxis(edge);
// Add legend size if it's on this edge
if (legend !== false) {
if (legend.position === edge) {
bbox = legend.getBBox();
insets[edge] += (isVertical ? bbox.width : bbox.height) + insets[edge];
}
}
// Add axis size if there's one on this edge only if it has been
//drawn before.
if (axis && axis.bbox) {
bbox = axis.bbox;
insets[edge] += (isVertical ? bbox.width : bbox.height);
}
}
// Build the chart bbox based on the collected inset values
chartBBox = {
x: insets.left,
y: insets.top,
width: me.curWidth - insets.left - insets.right,
height: me.curHeight - insets.top - insets.bottom
};
me.chartBBox = chartBBox;
// Go back through each axis and set its length and position based on the
// corresponding edge of the chartBBox
for (i = 0, ln = axesItems.length; i < ln; i++) {
axis = axesItems[i];
pos = axis.position;
isVertical = (pos === 'left' || pos === 'right');
axis.x = (pos === 'right' ? chartBBox.x + chartBBox.width : chartBBox.x);
axis.y = (pos === 'top' ? chartBBox.y : chartBBox.y + chartBBox.height);
axis.width = (isVertical ? chartBBox.width : chartBBox.height);
axis.length = (isVertical ? chartBBox.height : chartBBox.width);
}
},
// @private initialize the series.
initializeSeries: function(series, idx) {
var me = this,
themeAttrs = me.themeAttrs,
seriesObj, markerObj, seriesThemes, st,
markerThemes, colorArrayStyle = [],
i = 0, l,
config = {
chart: me,
seriesId: series.seriesId
};
if (themeAttrs) {
seriesThemes = themeAttrs.seriesThemes;
markerThemes = themeAttrs.markerThemes;
seriesObj = Ext.apply({}, themeAttrs.series);
markerObj = Ext.apply({}, themeAttrs.marker);
config.seriesStyle = Ext.apply(seriesObj, seriesThemes[idx % seriesThemes.length]);
config.seriesLabelStyle = Ext.apply({}, themeAttrs.seriesLabel);
config.markerStyle = Ext.apply(markerObj, markerThemes[idx % markerThemes.length]);
if (themeAttrs.colors) {
config.colorArrayStyle = themeAttrs.colors;
} else {
colorArrayStyle = [];
for (l = seriesThemes.length; i < l; i++) {
st = seriesThemes[i];
if (st.fill || st.stroke) {
colorArrayStyle.push(st.fill || st.stroke);
}
}
if (colorArrayStyle.length) {
config.colorArrayStyle = colorArrayStyle;
}
}
config.seriesIdx = idx;
}
if (series instanceof Ext.chart.series.Series) {
Ext.apply(series, config);
} else {
Ext.applyIf(config, series);
series = me.series.replace(Ext.createByAlias('series.' + series.type.toLowerCase(), config));
}
if (series.initialize) {
series.initialize();
}
},
// @private
getMaxGutter: function() {
var me = this,
seriesItems = me.series.items,
i, ln, series,
maxGutter = [0, 0],
gutter;
for (i = 0, ln = seriesItems.length; i < ln; i++) {
series = seriesItems[i];
gutter = series.getGutters && series.getGutters() || [0, 0];
maxGutter[0] = Math.max(maxGutter[0], gutter[0]);
maxGutter[1] = Math.max(maxGutter[1], gutter[1]);
}
me.maxGutter = maxGutter;
},
// @private draw axis.
drawAxis: function(axis) {
axis.drawAxis();
},
// @private draw series.
drawCharts: function(series) {
series.triggerafterrender = false;
series.drawSeries();
if (!this.animate) {
series.fireEvent('afterrender');
}
},
<span id='Ext-chart-Chart-method-save'> /**
</span> * Saves the chart by either triggering a download or returning a string containing the chart data
* as SVG. The action depends on the export type specified in the passed configuration. The chart
* will be exported using either the {@link Ext.draw.engine.SvgExporter} or the {@link Ext.draw.engine.ImageExporter}
* classes.
*
* Possible export types:
*
* - 'image/png'
* - 'image/jpeg',
* - 'image/svg+xml'
*
* If 'image/svg+xml' is specified, the SvgExporter will be used.
* If 'image/png' or 'image/jpeg' are specified, the ImageExporter will be used. This exporter
* must post the SVG data to a remote server to have the data processed, see the {@link Ext.draw.engine.ImageExporter}
* for more details.
*
* Example usage:
*
* chart.save({
* type: 'image/png'
* });
*
* @param {Object} [config] The configuration to be passed to the exporter.
* See the export method for the appropriate exporter for the relevant
* configuration options
* @return {Object} See the return types for the appropriate exporter
*/
save: function(config){
return Ext.draw.Surface.save(this.surface, config);
},
// @private remove gently.
destroy: function() {
Ext.destroy(this.surface);
this.bindStore(null);
this.callParent(arguments);
}
});
</pre>
</body>
</html>