/
px-heatmap-grid-table.html
1318 lines (1179 loc) · 40.8 KB
/
px-heatmap-grid-table.html
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
<!--
Copyright (c) 2018, General Electric
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
Relative paths assume component is being run from inside an app or another component, where dependencies are flat
siblings. When this component is run from its own repo (e.g. tests, examples), we assume the server is started with
'gulp serve' (or similar server setup) to enable correct finding of bower dependencies for local runs.
-->
<link rel="import" href="../polymer/polymer.html" />
<link rel="import" href="css/px-heatmap-grid-styles.html">
<link rel="import" href="../px-tooltip/px-tooltip.html">
<link rel="import" href="../px-icon-set/px-icon-set-utility.html">
<link rel="import" href="../px-icon-set/px-icon.html">
<dom-module id="px-heatmap-grid-table">
<template>
<style include="px-heatmap-grid-styles"></style>
<div class="table-container flex flex--row">
<template is="dom-if" if="{{!hideRowHeader}}">
<div class$="u-pl- u-pr- table-row-header flex flex--col flex--justify {{disabledHeader}}">
<template is="dom-if" if="{{showAggregation}}">
<div class="row-header">
<div class="row-header-text"><span>{{aggregationType}}</span></div>
</div>
</template>
<template is="dom-repeat" items="{{rows}}" as="row">
<div class="row-header flex flex--row flex--middle flex--justify" on-click="_sortRow">
<div class="row-header-text" id="row-header-{{index}}">{{_getHeader("row", index, rows)}}</div>
<px-icon class="actionable actionable--select u-ml-" icon="px-utl:chevron-left" hidden$="{{_sortingIcon(index,'row','up', heatmapData)}}"></px-icon>
<px-icon class="actionable actionable--select u-ml-" icon="px-utl:chevron-right" hidden$="{{_sortingIcon(index,'row','down', heatmapData)}}"></px-icon>
<px-tooltip smart-orientation="true" orientation="right" for="row-header-{{index}}" delay="100" tooltip-message="{{_getHeader('row', index, rows)}}">
</px-tooltip>
</div>
</template>
</div>
</template>
<div class="table-container flex flex--row flex--left flex--top">
<template is="dom-if" if="{{showRowAggregation}}">
<div class="table-column">
<div class="u-pr-- u-pb-- u-pl-- col-header" hidden$="{{hideColHeader}}">
<div class="col-header-text">{{aggregationType}}</div>
</div>
<div class="u-p-- table-empty-cell" hidden$="{{!showColAggregation}}">
<span> </span>
</div>
<template is="dom-repeat" items="{{rowAggregatedData}}">
<div class="u-p-- table-cell">
<span>{{item}}</span>
</div>
</template>
</div>
</template>
<template is="dom-repeat" items="{{heatmapData}}" as="items" id="heatmapDataRepeat">
<div class="table-column">
<template is="dom-if" if="{{!hideColHeader}}">
<div class="u-pr-- u-pb-- u-pl-- col-header flex flex--row flex--middle flex--justify" on-click="_sortCol">
<div class="col-header-text" id="col-header-{{index}}">
{{_getHeader("col", index, cols)}}
</div>
<px-icon class="actionable actionable--select u-ml-" icon="px-utl:chevron-up" hidden$="{{_sortingIcon(index,'col','up',heatmapData)}}"></px-icon>
<px-icon class="actionable actionable--select u-ml-" icon="px-utl:chevron" hidden$="{{_sortingIcon(index,'col','down',heatmapData)}}"></px-icon>
<px-tooltip smart-orientation="true" orientation="bottom" for="col-header-{{index}}" delay="100" tooltip-message="{{_getHeader('col', index, cols)}}">
</px-tooltip>
</div>
</template>
<template is="dom-if" if="{{showColAggregation}}">
<div class="u-p-- table-cell">
<span>{{_getColAggregation(index, colAggregatedData)}}</span>
</div>
</template>
<template is="dom-repeat" items="{{items}}" as="item">
<div class="u-p-- table-cell cell-values" style$="[[item.color]]">
<span hidden$="{{hideValues}}">{{item.value}}</span>
<template is="dom-if" if="{{hideValues}}">
<px-tooltip smart-orientation="true" orientation="bottom" delay="100" tooltip-message="{{item.value}}"></px-tooltip>
</template>
</div>
</template>
</div>
</template>
</div>
</div>
</template>
</dom-module>
<script>
Polymer({
is: 'px-heatmap-grid-table',
properties: {
/**
* Holds the data.
*
* @property data
*/
data: {
type: Array,
value: function () { return []; },
notify: true,
observer: '_dataChanged'
},
/**
* Holds the rendered data
*
* @property heatmapData
*/
heatmapData: {
type: Array,
value: function () { return []; }
},
/**
* Holds the config info
*
* @property config
*/
config: {
type: Object,
value: function () {
return {
minValue: 0,
maxValue: 0,
startColor: [],
endColor: [],
factors: []
};
},
observer: '_configChanged'
},
/**
* Holds the scale set by the user
*
* @property scale
*/
scale: {
type: Array,
value: function () { return [0, 100]; },
observer: '_scaleChanged'
},
/**
* Controls when to show/hide the Column Headers
*
* @property hideColHeader
*/
hideColHeader: {
type: Boolean,
value: false,
observer: '_hideColHeaderChanged',
notify: true
},
/**
* Controls when to show/hide the Row Headers
*
* @property hideRowHeader
*/
hideRowHeader: {
type: Boolean,
value: false,
observer: '_hideRowHeaderChanged',
},
/**
* Controls when to show/hide the Values in the cells
*/
hideValues: {
type: Boolean,
value: false
},
/**
* Sets the aggregation method
*
* @property aggregationType
*/
aggregationType: {
type: String,
value: "",
observer: '_calculateAggregation'
},
/**
* Controls when to show/hide the Aggregations
*
* @property showAggregation
*/
showAggregation: {
type: Boolean,
value: false,
observer: '_showAggregationChanged'
},
/**
* Contains all the available aggregation types
*
* @property availableAggregations
*/
availableAggregations: {
type: Array,
value: [
"AVERAGE",
"MAX",
"MIN",
"SUM",
"COUNT",
"STD"
]
},
/**
* Contains the Scale From color.
*
* @property scaleColorFrom
*/
scaleColorFrom: {
type: String,
observer: '_scaleColorFromChanged'
},
/**
* Contains the Scale To color.
*
* @property scaleColorTo
*/
scaleColorTo: {
type: String,
observer: '_scaleColorToChanged'
}
},
/**
* After the component is attached to the DOM calls
* _dataChanged and _configChanged.
*/
attached: function () {
this._dataChanged(this.data, []);
this._configChanged(this.config, {});
},
/**
* Add an event listener for the px-tooltip in order to
* evaluate when to hide tooltips for non ellipsed text
*/
ready: function () {
this.addEventListener('px-tooltip-request-show', this._hideTooltip);
},
detached: function () {
this.removeEventListener('px-tooltip-request-show', this._hideTooltip);
},
/**
* Observes the changes to data and creates the internal
* data structure used to render the heatmap table.
* Saves the initial column ordering in initialColsOrder.
* Saves the initial row ordering in initialRowsOrder.
* Triggers the aggregation calculation and the hide/show
* method to hide/show the titles according to the data.
*
* newData accepts 4 different data formats:
* Array<Object> (with rows and columns)
* Array<Object> (with rows or columns)
* Array<Array>
* Array<number>
*
* @param {Array<Object|Array|number>} newData The new heatmap data.
* @param {Array<Object|Array|number>} oldData The old heatmap data.
*
* @method _dataChanged
* @private
*/
_dataChanged: function (newData, oldData) {
if (newData != oldData && newData && newData.length && newData[0] !== null) {
var rows = [],
cols = [],
tableData = [],
response = {};
//Handles the case where newData is an Array<Array>
if (Array.isArray(newData[0])) {
tableData = this._processNewDataArray(newData);
}
//Handles the case where newData is an Array<number>
else if (typeof newData[0] !== "object" && typeof newData[0] !== "string") {
tableData = this._processNewDataNumber(newData)
}
//Handles the case where newData is an Array<Object> and the Object has the property values
else if (typeof newData[0] === "object" && newData[0].values) {
response = this._processNewDataObject(newData);
tableData = response['tableData'];
rows = response['rows'];
cols = response['cols'];
}
//Finally handles the last newData type where newData is an Array<Object>
else if (typeof newData[0] !== "string") {
response = this._processNewDataFullObject(newData);
tableData = response['tableData'];
rows = response['rows'];
cols = response['cols'];
}
// Force set length of array
rows.length = Object.keys(rows).length;
cols.length = Object.keys(cols).length;
// Initialize the heatmap
this.set("heatmapData", []);
this.set("rows", rows);
this.set("cols", cols);
this.set("heatmapData", tableData);
this._calculateAggregation(this.aggregationType, "");
this._hideColHeaderChanged(false, true);
this._hideRowHeaderChanged(false, true);
this._initializeRowsOrdering();
this._initializeColsOrdering();
}
},
/**
* Processes the heatmap data and creates the data model used to render the grid.
*
* Handles the case where the data is an Array<Array>
* [
* [0, 1, 2, 3, 4, 5, 6],
* [7, 8, 9, 10, 11, 12, 13],
* [14, 15, 16, 17, 18, 19, 20]
* ]
*
* @param {Array<Array>} data The heatmap data.
*
* @returns {Array<Object>} The heatmap data in the format to be rendered.
*
* @method _processNewDataArray
* @private
*/
_processNewDataArray: function (data) {
var nColor = [],
tableData = [],
stopLen = data.length;
for (var i = 0; i < stopLen; i++) {
var colArr = data[i],
stopLen2 = colArr.length;
for (var j = 0; j < stopLen2; j++) {
var value = colArr[j];
if (!tableData[j]) tableData.push([]);
nColor = this.config != undefined ? this._calculateColor(value) : [255, 255, 255];
tableData[j][i] = {
"value": value,
"color": nColor ? "background-color: rgb(" + nColor[0] + "," + nColor[1] + "," + nColor[2] + ");" : ""
};
}
}
return tableData;
},
/**
* Processes the heatmap data and creates the data model used to render the grid.
*
* Handles the case where newData is an Array<Object> and the Object has the property values
*
* [
* {
* "row": "Row Title",
* "values": [0, 1, 2, 3, 4, 5]
* }
* ]
*
* or
*
* [
* {
* "col": "Column Title",
* "values": [0, 1, 2, 3, 4, 5]
* }
* ]
*
* @param {Array<Object>} data The heatmap data.
*
* @returns {Object} The heatmap data in the format to be rendered, the list of col titles and the list of row titles.
*
* @method _processNewDataArray
* @private
*/
_processNewDataObject: function (data) {
var nColor = [],
iRow = -1,
iCol = -1,
tableData = [],
rows = [],
cols = [],
stopLen = data.length;
for (var i = 0; i < stopLen; i++) {
var cell = data[i],
stopLen2 = cell.values.length;
iRow = cell.row ? Object.keys(rows).indexOf(cell.row) : -2;
iCol = cell.col ? Object.keys(cols).indexOf(cell.col) : -2;
if (iCol === -2) {
rows[cell.row] = cell.row;
}
if (iRow === -2) {
cols[cell.col] = cell.col;
}
for (var j = 0; j < stopLen2; j++) {
var value = cell.values[j];
nColor = this.config != undefined ? this._calculateColor(value) : [255, 255, 255];
if (iCol === -2) {
if (i === 0) tableData.push([]);
tableData[j].push({
"value": value,
"color": nColor ? "background-color: rgb(" + nColor[0] + "," + nColor[1] + "," + nColor[2] + ");" : ""
});
}
else {
if (j === 0) tableData.push([]);
tableData[i].push({
"value": value,
"color": nColor ? "background-color: rgb(" + nColor[0] + "," + nColor[1] + "," + nColor[2] + ");" : ""
});
}
}
}
return {
tableData: tableData,
rows: rows,
cols: cols
};
},
/**
* Processes the heatmap data and creates the data model used to render the grid.
*
* Handles the case where newData is an Array<number>
*
* [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
*
*
* @param {Array<Array>} data The heatmap data.
*
* @returns {Array<Object>} The heatmap data in the format to be rendered.
*
* @method _processNewDataArray
* @private
*/
_processNewDataNumber: function (data) {
var nColor = [],
tableData = [],
stopLen = data.length;
for (var i = 0; i < stopLen; i++) {
var value = data[i];
nColor = this.config != undefined ? this._calculateColor(value) : [255, 255, 255];
tableData.push([{
"value": value,
"color": nColor ? "background-color: rgb(" + nColor[0] + "," + nColor[1] + "," + nColor[2] + ");" : ""
}]);
}
return tableData;
},
/**
* Processes the heatmap data and creates the data model used to render the grid.
*
* Handles the last newData type where newData is an Array<Object>
*
* [
* {
* "row": "Row Title",
* "col": "Column Title",
* "value": 10
* }
* ]
*
* @param {Array<Object>} data The heatmap data.
*
* @returns {Object} The heatmap data in the format to be rendered, the list of col titles and the list of row titles.
*
* @method _processNewDataArray
* @private
*/
_processNewDataFullObject: function (data) {
var nColor = [],
iRow = -1,
iCol = -1,
tableData = [],
rows = [],
cols = [],
stopLen = data.length;
for (var i = 0; i < stopLen; i++) {
var cell = data[i];
if (cell) {
iRow = Object.keys(rows).indexOf(cell.row);
iCol = Object.keys(cols).indexOf(cell.col);
if (iCol === -1) {
cols[cell.col] = cell.col;
tableData.push([]);
iCol = Object.keys(cols).length - 1;
};
if (iRow === -1) {
rows[cell.row] = cell.row;
iRow = Object.keys(rows).length - 1;
};
nColor = this.config != undefined ? this._calculateColor(cell.value) : [255, 255, 255];
tableData[iCol][iRow] = {
"value": cell.value,
"color": nColor ? "background-color: rgb(" + nColor[0] + "," + nColor[1] + "," + nColor[2] + ");" : ""
};
}
}
return {
tableData: tableData,
rows: rows,
cols: cols
};
},
/**
* Saves the initial Rows ordering in initialRowsOrder
*
* @method _initializeRowsOrdering
* @private
*/
_initializeRowsOrdering: function () {
var initialRowsOrder = [],
stopLen = this.rows.length;
if (this.rows && stopLen) {
for (var i = 0; i < stopLen; i++) {
initialRowsOrder.push({
index: i,
value: Object.keys(this.rows)[i]
});
}
this.initialRowsOrder = initialRowsOrder;
}
// If there's no row header titles uses the first column of data
else if (this.heatmapData && this.heatmapData.length) {
stopLen = this.heatmapData[0].length;
for (var i = 0; i < stopLen; i++) {
initialRowsOrder.push({
index: i,
value: this.heatmapData[0][i].value
});
}
this.initialRowsOrder = initialRowsOrder;
}
},
/**
* Saves the initial Columns ordering in initialColsOrder
*
* @method _initializeColsOrdering
* @private
*/
_initializeColsOrdering: function () {
var initialColsOrder = [],
stopLen = this.cols.length;
if (this.cols && stopLen) {
for (var i = 0; i < stopLen; i++) {
initialColsOrder.push({
index: i,
value: Object.keys(this.cols)[i]
});
}
this.initialColsOrder = initialColsOrder;
}
// If there's no column header titles uses the first row of data
else if (this.heatmapData && this.heatmapData.length) {
stopLen = this.heatmapData.length;
for (var i = 0; i < stopLen; i++) {
initialColsOrder.push({
index: i,
value: this.heatmapData[i][0].value
});
}
this.initialColsOrder = initialColsOrder;
}
},
/**
* Calculates the RGB color for a value based on the
* scale settings for the min and max values and the
* color from and to.
*
* @param {number} value The value to calculate the color for.
* @returns {Array} The RGB colors for the value. [R, G, B]
*
* @method _calculateColor
* @private
*/
_calculateColor: function (value) {
var config = this.config,
colors = [];
// if value is outside the range return a null
if (value < config.minValue || value > config.maxValue) {
colors = null;
}
// otherwise calculate the colors based on the color and values range
else {
var stopLen = config.factors.length;
for (var i = 0; i < stopLen; i++) {
colors.push(Math.round(config.factors[i] * (value - config.minValue)) + config.startColor[i]);
}
}
return colors;
},
/**
* Observes the changes to config and calculates the
* RGB start and end colors for the scale and the
* multiplier factor to calculate the colors for
* values within the scale.
* Only if newConfig exists and is different from
* oldConfig.
*
* @param {Object} newConfig The new configuration.
* @param {Object} oldConfig The old configuration.
*
* @method _configChanged
* @private
*/
_configChanged: function (newConfig, oldConfig) {
if (newConfig !== oldConfig && newConfig) {
var config = this.config,
temp, stopLen, nValues, data;
if (this.scaleColorFrom) {
temp = this.scaleColorFrom.replace(/[^\d,]/g, '').split(',');
config.startColor = [];
stopLen = temp.length;
for (var i = 0; i < stopLen; i++) {
config.startColor.push(Number(temp[i]));
}
}
if (this.scaleColorTo) {
temp = this.scaleColorTo.replace(/[^\d,]/g, '').split(',');
config.endColor = [];
stopLen = temp.length;
for (var i = 0; i < stopLen; i++) {
config.endColor.push(Number(temp[i]));
}
}
nValues = config.maxValue - config.minValue;
stopLen = config.endColor.length;
config.factors = [];
for (var i = 0; i < stopLen; i++) {
config.factors.push((config.endColor[i] - config.startColor[i]) / nValues);
}
data = [].concat(this.data);
this.set("data", data);
}
},
/**
* Observes the changes to scale and creates a new
* config Object with min and max values.
* Only if newScale exists and is different than
* oldScale.
*
* @param {Array<number>} newScale The new scale limits [min, max].
* @param {Array<number>} oldScale The old scale limits.
*
* @method _scaleChanged
* @private
*/
_scaleChanged: function (newScale, oldScale) {
if (newScale !== oldScale && newScale && newScale.length === 2) {
this.set("config.minValue", newScale[0]);
this.set("config.maxValue", newScale[1]);
this._configChanged(this.config, {});
}
},
/**
* Helper method to get header titles
*
* @param {string} option Either col or row
* @param {number} index The index of the column/row
* @returns {string} The header title
*
* @method _getHeader
* @private
*/
_getHeader: function (option, index) {
if (option === "col") {
return this.cols[Object.keys(this.cols)[index]];
}
else if (option === "row") {
return this.rows[Object.keys(this.rows)[index]];
}
},
/**
* Determine if the tooltip should be displayed or not
* based on the text overflow of it's sibling div
*
* @param {event} e The px-tooltip show request event
*
* @method _hideTooltip
* @private
*/
_hideTooltip: function (e) {
var tooltip = e.detail.target,
headerEl = tooltip.parentElement.querySelector('div');
if (headerEl.scrollWidth <= headerEl.clientWidth && tooltip.for != "") {
tooltip._hide();
}
},
/**
* Observes the changes to hideColHeader and hide/show
* the Column headers based on newValue and applies a css
* to the rows container to adjust it's size.
* Only if newValue exists and is different than oldValue.
* Sets the column header visibility to false if there's no
* column header titles.
*
* @param {boolean} newValue Hide or don't the Column Headers
* @param {boolean} oldValue The old value.
*
* @method _hideColHeaderChanged
* @private
*/
_hideColHeaderChanged: function (newValue, oldValue) {
if (newValue !== undefined && newValue !== oldValue) {
newValue === false ? this.disabledHeader = "" : this.disabledHeader = "disable-col-header";
}
if (newValue !== undefined && newValue === false && newValue !== oldValue && this.cols && (!this.cols.length || !Object.keys(this.cols)[0])) {
this.set('hideColHeader', undefined);
this.set('hideColHeader', true);
}
},
/**
* Sorts the column ascending, descending or resets the sort.
*
* @param {event} e The click event on the column header
*
* @method _sortCol
* @private
*/
_sortCol: function (e) {
var col = e.model.index,
order = 0,
_this = this,
temp, newData, rows, newRows, tempRowsReduced, stopLen, stopLen2;
// 0 sort ascending, 1 sort descending 2 reset sorting
if (this.sortColOrder && this.sortColOrder.index === col && this.sortColOrder.order !== 2) {
order = ++this.sortColOrder.order;
}
this.sortColOrder = {
"index": col,
"order": order
};
// Sort ascending / descending
if (order < 2) {
temp = [];
stopLen = this.heatmapData[col].length;
for (var i = 0; i < stopLen; i++) {
var el = this.heatmapData[col][i];
temp.push({
"index": i,
"value": el ? typeof el.value === "number" ? el.value : -Infinity : -Infinity
});
}
temp.sort(function (a, b) {
return order ? b.value - a.value : a.value - b.value;
});
}
// Reset sorting
else {
temp = [];
if (this.rows && this.rows.length && Object.keys(this.rows)[0]) {
stopLen = this.initialRowsOrder.length;
for (var i = 0; i < stopLen; i++) {
var r = this.initialRowsOrder[i];
temp.push({
"index": Object.keys(_this.rows).indexOf(r.value)
});
}
}
// If there's no row header titles uses the first column of data
else {
stopLen = this.heatmapData[0].length;
tempRowsReduced = [];
for (var i = 0; i < stopLen; i++) {
tempRowsReduced.push(this.heatmapData[0][i].value);
}
stopLen = this.initialRowsOrder.length;
for (var i = 0; i < stopLen; i++) {
var r = this.initialRowsOrder[i];
temp.push({
"index": tempRowsReduced.indexOf(r.value)
});
}
}
}
stopLen = this.heatmapData.length;
stopLen2 = temp.length;
newData = [];
for (var i = 0; i < stopLen; i++) {
var newSubData = [];
for (var j = 0; j < stopLen2; j++) {
newSubData.push(this.heatmapData[i][temp[j].index]);
}
newData.push(newSubData);
}
rows = this.rows;
newRows = [];
stopLen = temp.length;
if (rows.length) {
for (var i = 0; i < stopLen; i++) {
newRows[Object.keys(rows)[temp[i].index]] = rows[Object.keys(rows)[temp[i].index]];
}
// Force set length of array
newRows.length = Object.keys(newRows).length;
}
this.set("heatmapData", []);
this.set("rows", []);
this.set("heatmapData", newData);
this.set("rows", newRows);
},
/**
* Sorts the row ascending, descending or resets the sort.
*
* @param {Object} e The click event on the row header
*
* @method _sortCol
* @private
*/
_sortRow: function (e) {
var row = e.model.index,
order = 0,
_this = this,
temp, hd, newData, cols, newCols, tempColsReduced, stopLen;
// 0 sort ascending, 1 sort descending 2 reset sorting
if (this.sortRowOrder && this.sortRowOrder.index === row && this.sortRowOrder.order !== 2) {
order = ++this.sortRowOrder.order;
}
this.sortRowOrder = {
"index": row,
"order": order
};
// Sort ascending / descending
if (order < 2) {
stopLen = this.heatmapData.length;
temp = [];
for (var i = 0; i < stopLen; i++) {
var tempItem = this.heatmapData[i][row];
temp.push({
index: i,
value: tempItem ? typeof tempItem.value === "number" ? tempItem.value : -Infinity : -Infinity
});
}
temp.sort(function (a, b) {
return order ? b.value - a.value : a.value - b.value;
});
}
// Reset sorting
else {
temp = [];
if (this.cols && this.cols.length && Object.keys(this.cols)[0]) {
stopLen = this.initialColsOrder.length;
for (var i = 0; i < stopLen; i++) {
var r = this.initialColsOrder[i];
temp.push({
"index": Object.keys(_this.cols).indexOf(r.value)
});
}
}
// If there's no column header titles uses the first row of data
else {
stopLen = this.heatmapData.length;
tempColsReduced = [];
for (var i = 0; i < stopLen; i++) {
tempColsReduced.push(this.heatmapData[i][0].value);
}
stopLen = this.initialColsOrder.length;
for (var i = 0; i < stopLen; i++) {
var r = this.initialColsOrder[i];
temp.push({
"index": tempColsReduced.indexOf(r.value)
});
}
}
}
hd = this.heatmapData;
stopLen = temp.length;
newData = [];
for (var i = 0; i < stopLen; i++) {
newData.push(hd[temp[i].index]);
}
cols = this.cols;
newCols = [];
if (cols.length) {
stopLen = temp.length;
for (var i = 0; i < stopLen; i++) {
newCols[Object.keys(cols)[temp[i].index]] = cols[Object.keys(cols)[temp[i].index]];
}
//Force set length of Array
newCols.length = Object.keys(newCols).length;
}
this.set("cols", []);
this.set("heatmapData", []);
this.set("cols", newCols);
this.set("heatmapData", newData);
},
/**
* Determines whether to show the sorting icon or not
*