-
Notifications
You must be signed in to change notification settings - Fork 22
/
HighChart.js
1326 lines (1162 loc) · 38.4 KB
/
HighChart.js
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
/**
* @author Joe Kuan (much improved & ported from ExtJs 3 highchart adapter)
* @email kuan.joe@gmail.com
* @version 2.1
* @date 28 Sept 2012
*
* You are not permitted to remove the author section from this file.
*/
if(!Array.prototype.indexOf) {
Array.prototype.indexOf = function(elt /*, from*/) {
var len = this.length;
var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if(from < 0)
from += len;
for(; from < len; from++) {
if( from in this && this[from] === elt)
return from;
}
return -1;
};
}
Ext.define("Chart.ux.HighChart", {
extend : 'Ext.Component',
alias : ['widget.highchart'],
debug: false,
debugOn : function() {
this.debug = true;
},
log: function(msg) {
(typeof console !== 'undefined' && this.debug) && console.log(msg);
},
/**
* @cfg {Object} defaultSerieType
* Sets styles for this chart. This contains default styling, so modifying this
* property will <b>override</b>
* the built in styles of the chart. Use {@link #extraStyle} to add
* customizations to the default styling.
*/
defaultSerieType : null,
/**
* @cfg {Boolean} resizable
* True to allow resizing, false to disable resizing (defaults to true).
*/
resizable : true,
/**
* @cfg {Integer} updateDelay
* (defaults to 0)
*/
updateDelay : 0,
/**
* @cfg {Object} loadMask An {@link Ext.LoadMask} config or true to mask the
* chart while
* loading. Defaults to false.
*/
loadMask : false,
/**
* @cfg {Boolean} refreshOnChange
* chart refresh data when store datachanged event is triggered,
* i.e. records are added, removed, or updated.
* If your application is just purely showing data from store load,
* then you don't need this, make sure refreshOnLoad is true.
* (default: false)
*/
refreshOnChange: false,
refreshOnLoad: true,
/**
* @cfg {Boolean}
* this config enable or disable chart init animation even Highcharts
* chart.animation is true. If set to true, then the extension will
* try to build chart configuration with store series data.
* The initial animation is only on display:
* 1. store data is already loaded
* 2. chart.animation is not manually set to false
* (default: false)
*/
animation: true,
initAnim: true,
updateAnim: true,
/**
* The line shift is achieved by comparing the existing x values in the chart
* and x values from the store record and work out the extra record.
* Then append the new records with shift. Hence, any old records with updated
* y values are ignored
* updateAnim: true
*/
lineShift: false,
/**
* @cfg {Boolean}
* This option will defer initially chart create until the store is loaded
* This option must be used with initAnim: true
* (default: true)
*/
initAnimAfterLoad: true,
/**
* @cfg {Function} afterChartRendered - callback for after the Highcharts
* is rendered.
* afterChartRendered: function (Highcharts chart)
*/
afterChartRendered: null,
// Create getter and setter function
config : {
title : '',
subTitle : ''
},
constructor: function(config) {
config.listeners && (this.afterChartRendered = config.listeners.afterChartRendered);
this.afterChartRendered && (this.afterChartRendered = Ext.bind(this.afterChartRendered, this));
if (config.animation == false) {
this.animation = false;
this.initAnim = false;
this.updateAnim = false;
this.initAnimAfterLoad = false;
}
this.callParent(arguments);
},
initComponent : function() {
if(this.store) {
this.store = Ext.data.StoreManager.lookup(this.store);
}
if (this.animation == false) {
this.initAnim = false;
this.updateAnim = false;
this.initAnimAfterLoad = false;
}
this.callParent(arguments);
},
/**
* Add one or more series to the chart
* @param {Array} series An array of series
* @param {Boolean} append the serie. Defaults to true
*/
addSeries : function(series, append) {
append = (append === null || append === true) ? true : false;
var n = new Array(), c = new Array(), cls, serieObject;
// Add empty data to the serie or just leave it normal. Bug in HighCharts?
for(var i = 0; i < series.length; i++) {
var serie = series[i];
if(!serie.serieCls) {
if(serie.type != null || this.defaultSerieType != null) {
cls = Chart.ux.HighChart.Series.get(serie.type != null ? serie.type : this.defaultSerieType);
} else {
cls = Chart.ux.HighChart.Serie;
}
serieObject = Ext.create(cls, serie);
} else {
serieObject = serie;
}
c.push(serieObject.config);
n.push(serieObject);
}
// Show in chart
if(this.chart) {
if(!append) {
this.removeAllSeries();
this.series = n;
this.chartConfig.series = c;
} else {
this.chartConfig.series = this.chartConfig.series ? this.chartConfig.series.concat(c) : c;
this.series = this.series ? this.series.concat(n) : n;
}
for(var i = 0; i < c.length; i++) {
this.chart.addSeries(c[i], true);
}
this.refresh();
// Set the data in the config.
} else {
if(append) {
this.chartConfig.series = this.chartConfig.series ? this.chartConfig.series.concat(c) : c;
this.series = this.series ? this.series.concat(n) : n;
} else {
this.chartConfig.series = c;
this.series = n;
}
}
},
/**
*
*/
removeSerie : function(id, redraw) {
redraw = redraw || true;
if(this.chart) {
this.chart.series[id].remove(redraw);
this.chartConfig.series.splice(id, 1);
}
this.series.splice(id, 1);
},
/**
* Remove all series
*/
removeAllSeries : function() {
var sc = this.series.length;
for(var i = 0; i < sc; i++) {
this.removeSerie(0);
}
},
/**
* Set the title of the chart
* @param {String} title Text to set the subtitle
*/
setTitle : function(title) {
if(this.chartConfig.title)
this.chartConfig.title.text = title;
else
this.chartConfig.title = {
text : title
};
if(this.chart && this.chart.container)
this.draw();
},
/**
* Set the subtitle of the chart
* @param {String} title Text to set the subtitle
*/
setSubTitle : function(title) {
if(this.chartConfig.subtitle)
this.chartConfig.subtitle.text = title;
else
this.chartConfig.subtitle = {
text : title
};
if(this.chart && this.chart.container)
this.draw();
},
initEvents : function() {
if(this.loadMask) {
this.loadMask = new Ext.LoadMask(this.el, Ext.apply({
store : this.store
}, this.loadMask));
}
},
afterRender : function() {
if(this.store)
this.bindStore(this.store, true);
this.callParent(arguments);
this.bindComponent(true);
// Ext.applyIf causes problem in 4.1.x but works fine with
// 4.0.x
Ext.apply(this.chartConfig.chart, {
renderTo : this.el.dom
});
Ext.applyIf(this.chartConfig, {
xAxis : [{}]
});
if(this.xField && this.store) {
this.updatexAxisData();
}
if(this.series) {
this.addSeries(this.series, false);
} else
this.series = [];
this.initEvents();
// Make a delayed call to update the chart.
this.update(0);
},
onMove : function() {
},
/***
* Build the initial data set if there are data already
* inside the store.
*/
buildInitData : function() {
if (!this.store || this.store.isLoading() || !this.chartConfig || this.initAnim === false ||
this.chartConfig.chart.animation === false) {
return;
}
var data = new Array(), seriesCount = this.series.length, i;
var items = this.store.data.items;
for( i = 0; i < seriesCount; i++) {
this.chartConfig.series[i].data = [];
// Sort out the type for this series
var seriesType = this.series[i].type || this.chartConfig.chart.defaultSeriesType;
var data = this.chartConfig.series[i].data = this.chartConfig.series[i].data || {};
// Check any series type we don't support here
if (!seriesType) {
continue;
}
switch(seriesType) {
case 'line':
case 'spline':
case 'area':
case 'areaspline':
case 'scatter':
case 'bar':
case 'column':
var yField = this.series[i].yField || this.series[i].dataIndex;
// Check whether series itself has its own xField defined,
// If so, then expect this is a numeric field.
if (this.series[i].xField) {
var xField = this.series[i].xField;
for (var x = 0; x < items.length; x++) {
var record = items[x];
data.push([ record.data[xField], record.data[yField] ]);
}
// This make sure the series has no manual data, rely on store record
} else if (this.series[i].yField || this.series[i].dataIndex) {
for (var x = 0; x < items.length; x++) {
var record = items[x];
data.push(record.data[yField]);
}
var xAxis = (Ext.isArray(this.chartConfig.xAxis)) ? this.chartConfig.xAxis[0] : this.chartConfig.xAxis;
// Build the first x-axis categories
if (this.xField && (!xAxis.categories || xAxis.categories.length < items.length)) {
xAxis.categories = xAxis.categories || [];
for (var x = 0; x < items.length; x++) {
xAxis.categories.push(items[x].data[this.xField]);
}
}
}
break;
case 'pie':
// Summed up the category among the series data
var categorieField = this.series[i].categorieField;
var dataField = this.series[i].dataField;
var colorField = this.series[i].colorField;
if(this.series[i].totalDataField) {
var found = null;
var totData = {};
for (var x = 0; x < items.length; x++) {
var record = items[x];
var categoryName = record.data[categorieField];
// See whether this category name is already define in totData
totData[categoryName] = totData[categoryName] || { total: 0 };
totData[categoryName].total += record.data[dataField];
colorField && (totData[categoryName].color = record.data[colorField]);
}
for (var y in totData) {
var ptObject = {
name: y,
y: totData[y].total
};
totData[y].color && (ptObject.color = totData[y].color);
data.push(ptObject);
}
} else {
for (var x = 0; x < items.length; x++) {
var record = items[x];
var ptObject = {
name: record.data[categorieField],
y: record.data[dataField]
};
colorField && (ptObject.color = record.data[colorField]);
data.push(ptObject);
}
}
break;
case 'columnrange':
case 'arearange':
case 'areasplinerange':
var xField = this.series[i].xField;
if (Ext.isArray(this.series[i].dataIndex)) {
var f1 = this.series[i].dataIndex[0],
f2 = this.series[i].dataIndex[1];
for (var x = 0; x < items.length; x++) {
var record = items[x];
var y1 = record.data[f1], y2 = record.data[f2];
if (xField) {
if (y1 > y2)
data.push([ record.data[xField], y2, y1 ]);
else
data.push([ record.data[xField], y1, y2 ]);
} else {
if (y1 > y2)
data.push([ y2, y1 ]);
else
data.push([ y1, y2 ]);
}
}
} else if (this.series[i].minDataIndex && this.series[i].maxDataIndex) {
var f1 = this.series[i].minDataIndex,
f2 = this.series[i].maxDataIndex;
for (var x = 0; x < items.length; x++) {
var record = items[x];
var y1 = record.data[f1], y2 = record.data[f2];
if (xField) {
data.push([ record.data[xField], y1, y2 ]);
} else {
data.push([ y1, y2 ]);
}
}
}
var xAxis = (Ext.isArray(this.chartConfig.xAxis)) ? this.chartConfig.xAxis[0] : this.chartConfig.xAxis;
// Build the first x-axis categories
if (this.xField && !xField && (!xAxis.categories || xAxis.categories.length < items.length)) {
xAxis.categories = xAxis.categories || [];
for (var x = 0; x < items.length; x++) {
xAxis.categories.push(items[x].data[this.xField]);
}
}
break;
}
}
},
draw : function() {
/**
* Redraw the chart
*/
this.log("call draw");
if(this.chart && this.rendered) {
if(this.resizable) {
for(var i = 0; i < this.series.length; i++) {
this.series[i].visible = this.chart.series[i].visible;
}
// Redraw the highchart means recreate the highchart
// inside this component
// Destroy
this.chart.destroy();
delete this.chart;
this.buildInitData();
// Create a new chart
this.chart = new Highcharts.Chart(this.chartConfig, this.afterChartRendered);
}
/**
* Create the chart
*/
} else if(this.rendered) {
// Create the chart from fresh
if (!this.initAnimAfterLoad) {
this.buildInitData();
this.chart = new Highcharts.Chart(this.chartConfig, this.afterChartRendered);
this.log("initAnimAfterLoad is off, creating chart from fresh");
} else {
this.log("initAnimAfterLoad is on, defer creating chart");
return;
}
}
for( i = 0; i < this.series.length; i++) {
if(!this.series[i].visible)
this.chart.series[i].hide();
}
// Refresh the data only if it is not loading
// no point doing this, as onLoad will pick it up
if (!this.store.isLoading()) {
this.log("Call refresh from draw");
this.refresh();
}
},
//@deprecated
onContainerResize : function() {
this.draw();
},
//private
updatexAxisData : function() {
var data = [], items = this.store.data.items;
if(this.xField && this.store) {
for(var i = 0; i < items.length; i++) {
data.push(items[i].data[this.xField]);
}
if(this.chart)
this.chart.xAxis[0].setCategories(data, true);
else if (Ext.isArray(this.chartConfig.xAxis)) {
this.chartConfig.xAxis[0].categories = data;
} else {
this.chartConfig.xAxis.categories = data;
}
}
},
bindComponent : function(bind) {
/**
* Make the chart update the positions
* positions are based on the window object and not on the
* owner object.
*/
var getWindow = function(parent) {
if(parent.ownerCt)
return getWindow(parent.ownerCt);
else
return parent;
};
var w = getWindow(this);
if(bind) {
w.on('move', this.onMove, this);
w.on('resize', this.onResize, this);
if(this.ownerCt)
this.ownerCt.on('render', this.update, this);
} else {
if(this.ownerCt)
this.ownerCt.un('render', this.update, this);
w.un('move', this.onMove, this);
}
},
/**
* Changes the data store bound to this chart and refreshes it.
* @param {Store} store The store to bind to this chart
*/
bindStore : function(store, initial) {
if(!initial && this.store) {
if(store !== this.store && this.store.autoDestroy) {
this.store.destroy();
} else {
this.store.un("datachanged", this.onDataChange, this);
this.store.un("load", this.onLoad, this);
this.store.un("add", this.onAdd, this);
this.store.un("remove", this.onRemove, this);
this.store.un("update", this.onUpdate, this);
this.store.un("clear", this.onClear, this);
}
}
if(store) {
store = Ext.StoreMgr.lookup(store);
store.on({
scope : this,
load : this.onLoad,
datachanged : this.onDataChange,
add : this.onAdd,
remove : this.onRemove,
update : this.onUpdate,
clear : this.onClear
});
}
this.store = store;
if(store && !initial) {
this.refresh();
}
},
/**
* Complete refresh of the chart
*/
refresh : function() {
this.log("Call refresh ");
if(this.store && this.chart) {
var data = new Array(), seriesCount = this.series.length, i;
for( i = 0; i < seriesCount; i++)
data.push(new Array());
// We only want to go true the data once.
// So we need to have all columns that we use in line.
// But we need to create a point.
var items = this.store.data.items;
var xFieldData = [];
for(var x = 0; x < items.length; x++) {
var record = items[x];
if(this.xField) {
xFieldData.push(record.data[this.xField]);
}
for( i = 0; i < seriesCount; i++) {
var serie = this.series[i], point;
if (serie.dataIndex || serie.yField || serie.minDataIndex) {
point = serie.getData(record, x);
data[i].push(point);
} else if (serie.type == 'pie') {
if (serie.useTotals) {
if(x == 0)
serie.clear();
point = serie.getData(record, x);
} else if (serie.totalDataField) {
serie.getData(record, data[i]);
} else {
point = serie.getData(record, x);
data[i].push(point);
}
} else if (serie.type == 'gauge') {
// Gauge is a dial type chart, so the data can only
// have one value
data[i][0] = serie.getData(record, x);
} else if (serie.data && serie.data.length) {
// This means the series is added within its own data
// not from the store
if (serie.data[x] !== undefined) {
data[i].push(serie.data[x]);
} else {
data[i].push(null);
}
}
}
}
// Update the series
if (!this.updateAnim) {
for( i = 0; i < seriesCount; i++) {
if(this.series[i].useTotals) {
this.chart.series[i].setData(this.series[i].getTotals());
} else if(data[i].length > 0) {
this.chart.series[i].setData(data[i], i == (seriesCount - 1));
// true == redraw.
}
}
if(this.xField) {
//this.updatexAxisData();
this.chart.xAxis[0].setCategories(xFieldData, true);
}
} else {
var xCatStartIdx = -1;
for( i = 0; i < seriesCount; i++) {
if (this.series[i].useTotals) {
this.chart.series[i].setData(this.series[i].getTotals());
} else if (data[i].length > 0) {
if (!this.lineShift) {
// Need to work out the length between the store dataset and
// the current series data set
var chartSeriesLength = this.chart.series[i].points.length;
var storeSeriesLength = items.length;
for (var x = 0; x < Math.min(chartSeriesLength, storeSeriesLength); x++) {
if (Ext.isObject(data[i][x])) {
this.chart.series[i].points[x].update(data[i][x], false, true);
} else {
this.chart.series[i].points[x].update({ y: data[i][x] }, false, true);
}
}
// Append the rest of the points from store to chart
if (storeSeriesLength > chartSeriesLength) {
for (var y = 0; y < (storeSeriesLength - chartSeriesLength); y++, x++) {
this.chart.series[i].addPoint(data[i][x], false, false, true);
}
}
// Remove the excessive points from the chart
else if (chartSeriesLength > storeSeriesLength) {
for (var y = 0; y < (chartSeriesLength - storeSeriesLength); y++) {
var last = this.chart.series[i].points.length - 1;
this.chart.series[i].points[last].remove(false, true);
}
}
} else {
var xAxis = Ext.isArray(this.chart.xAxis) ? this.chart.xAxis[0] : this.chart.xAxis;
// We need to see whether compare through xAxis categories or data points x axis value
var startIdx = -1;
if (xAxis.categories) {
// Since this is categories, it means multiple series share the common
// categories. Hence we only do it once to find the startIdx position
if (i == 0) {
for (var x = 0 ; x < xFieldData.length; x++) {
var found = false;
for (var y = 0; y < xAxis.categories.length; y++) {
if (xFieldData[x] == xAxis.categories[y]) {
found = true
break;
}
}
if (!found) {
xCatStartIdx = startIdx = x;
break;
}
}
var categories = xAxis.categories.slice(0);
categories.push(xFieldData[x]);
xAxis.setCategories(categories, false);
} else {
// Reset the startIdx
startIdx = xCatStartIdx;
}
this.log("startIdx " + startIdx);
// Start shifting
if (startIdx !== -1 && startIdx < xFieldData.length) {
for (var x = startIdx; x < xFieldData.length; x++) {
this.chart.series[i].addPoint(data[i][x],
false, true, true);
}
}
} else {
var chartSeries = this.chart.series[i].points;
for (var x = 0 ; x < data[i].length; x++) {
var found = false;
for (var y = 0; y < chartSeries.length; y++) {
if (data[i][x][0] == chartSeries[y].x) {
found = true
break;
}
}
if (!found) {
startIdx = x;
break;
}
}
this.log("startIdx " + startIdx);
// Start shifting
if (startIdx !== -1 && startIdx < data[i].length) {
for (var x = startIdx; x < data[i].length; x++) {
this.chart.series[i].addPoint(data[i][x], false, true, true);
}
}
}
}
}
}
// For Line Shift it has to be setCategories before addPoint
if(this.xField && !this.lineShift) {
//this.updatexAxisData();
this.chart.xAxis[0].setCategories(xFieldData, true);
}
this.chart.redraw();
}
}
},
/**
* Update a selected row.
*/
refreshRow : function(record) {
var index = this.store.indexOf(record);
if(this.chart) {
for(var i = 0; i < this.chart.series.length; i++) {
var serie = this.chart.series[i];
var point = this.series[i].getData(record, index);
if(this.series[i].type == 'pie' && this.series[i].useTotals) {
this.series[i].update(record);
this.chart.series[i].setData(this.series[i].getTotals());
} else
serie.data[index].update(point);
}
if(this.xField) {
this.updatexAxisData();
}
}
},
/**
* A function to delay the updates
* @param {Integer} delay Set a custom delay
*/
update : function(delay) {
var cdelay = delay || this.updateDelay;
if(!this.updateTask) {
this.updateTask = new Ext.util.DelayedTask(this.draw, this);
}
this.updateTask.delay(cdelay);
},
// private
onDataChange : function() {
this.refreshOnChange && (this.refresh() && this.log("onDataChange"));
},
// private
onClear : function() {
this.refresh();
},
// private
onUpdate : function(ds, record) {
this.refreshRow(record);
},
// private
onAdd : function(ds, records, index) {
var redraw = false, xFieldData = [];
for(var i = 0; i < records.length; i++) {
var record = records[i];
if(i == records.length - 1)
redraw = true;
if(this.xField) {
xFieldData.push(record.data[this.xField]);
}
for(var x = 0; x < this.chart.series.length; x++) {
var serie = this.chart.series[x], s = this.series[x];
var point = s.getData(record, index + i);
if(!(s.type == 'pie' && s.useTotals)) {
serie.addPoint(point, redraw);
}
}
}
if(this.xField) {
this.chart.xAxis[0].setCategories(xFieldData, true);
}
},
//private
onResize : function() {
this.callParent(arguments);
this.update();
},
// private
onRemove : function(ds, record, index, isUpdate) {
for(var i = 0; i < this.series.length; i++) {
var s = this.series[i];
if(s.type == 'pie' && s.useTotals) {
s.removeData(record, index);
this.chart.series[i].setData(s.getTotals());
} else {
this.chart.series[i].data[index].remove(true);
}
}
Ext.each(this.chart.series, function(serie) {
serie.data[index].remove(true);
});
if(this.xField) {
this.updatexAxisData();
}
},
// private
onLoad : function() {
if (!this.chart && this.initAnimAfterLoad) {
this.log("Call refresh from onLoad for initAnim");
this.buildInitData();
this.chart = new Highcharts.Chart(this.chartConfig, this.afterChartRendered);
return;
}
this.log("Call refresh from onLoad");
this.refreshOnLoad && this.refresh();
},
destroy : function() {
delete this.series;
if(this.chart) {
this.chart.destroy();
delete this.chart;
}
this.bindStore(null);
this.bindComponent(null);
this.callParent(arguments);
}
});
/**
* @class Ext.ux.HighChart.Series
* This class registers all available series, and provide backward compatibility
* @constructor
*/
Chart.ux.HighChart.Series = function() {
var items = new Array(), values = new Array();
return {
reg : function(id, cls) {
items.push(cls);
values.push(id);
},
get : function(id) {
return items[values.indexOf(id)];
}
};
}();
/**
* @class Ext.ux.HighChart.Serie
* Series class for the highcharts widget.
* @constructor
*/
Ext.define('Chart.ux.HighChart.Serie', {
type : null,
/**
* The default action for series point data is to use array instead of point object
* unless desired to set point particular field. This changes the default behaviour
* of getData template method
* Default: false
*
* @type Boolean
*/
pointObject: false,
/**
* The field used to access the x-axis value from the items from the data
* source.
*
* @property xField
* @type String
*/
xField : null,
/**
* The field used to access the y-axis value from the items from the data
* source.
*
* @property yField
* @type String
*/
yField : null,
/**
* The field used to hide the serie initial. Defaults to true.
*
* @property visible
* @type boolean
*/
visible : true,
clear : Ext.emptyFn,
obj_getData : function(record, index) {
var yField = this.yField || this.dataIndex, point = {
data : record.data,
y : record.data[yField]
};
this.xField && (point.x = record.data[this.xField]);
this.colorField && (point.color = record.data[this.colorField]);
return point;
},
arr_getDataSingle: function(record, index) {
return record.data[this.yField];
},
arr_getDataPair: function(record, index) {
return [ record.data[ this.xField ], record.data[ this.yField ] ];
},
serieCls : true,
constructor : function(config) {
config.type = this.type;
if(!config.data) {
config.data = [];
}
Ext.apply(this, config);
this.config = config;
this.yField = this.yField || this.dataIndex;