-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
148 lines (126 loc) · 3.56 KB
/
index.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
/* eslint-env commonjs */
'use strict';
var DatasaurBase = require('datasaur-base');
/**
* @constructor
*/
var DatasaurIndexed = DatasaurBase.extend('DatasaurIndexed', {
/**
* @memberOf DatasaurIndexed#
* @param y
* @returns {*}
*/
transposeY: function(y) {
return this.index ? this.index[y] : y;
},
getRowIndex: function(y) {
return this.next.getRowIndex(this.transposeY(y));
},
/**
* @memberOf DatasaurIndexed#
* @param y
* @returns {object}
*/
getRow: function(y) {
return this.next.getRow(this.transposeY(y));
},
getRowMetadata: function(y, prototype) {
return this.next.getRowMetadata(this.transposeY(y), prototype);
},
setRowMetadata: function(y, metadata) {
return this.next.setRowMetadata(this.transposeY(y), metadata);
},
/**
* @memberOf DatasaurIndexed#
* @param x
* @param y
* @returns {*|Mixed}
*/
getValue: function(x, y) {
return this.next.getValue(x, this.transposeY(y));
},
/**
* @memberOf DatasaurIndexed#
* @param {number} x
* @param {number} y
* @param {*} value
*/
setValue: function(x, y, value) {
this.next.setValue(x, this.transposeY(y), value);
},
/**
* @memberOf DatasaurIndexed#
* @returns {Number|*}
*/
getRowCount: function() {
return this.index ? this.index.length : this.next.getRowCount();
},
/**
* @memberOf DatasaurIndexed#
* @param {number[]} [index]
* @returns {undefined|number[]}
*/
setIndex: function(index) {
if (index === undefined) {
delete this.index;
} else {
this.dispatchEvent(DatasaurIndexed.preindexEventString);
this.index = index;
this.dispatchEvent(DatasaurIndexed.postindexEventString);
}
return index;
},
/**
* @memberOf DatasaurIndexed#
* @returns {undefined|number[]}
*/
clearIndex: function() {
return this.setIndex(undefined);
},
/**
* @memberOf DatasaurIndexed#
* @param {filterPredicate} [predicate]
* @returns {undefined|number[]}
*/
buildIndex: function(predicate) {
if (predicate) {
delete this.index; // free up memory before building a new index
for (var y = 0, next = this.next, Y = next.getRowCount(), index = []; y < Y; y++) {
if (predicate.call(next, y)) {
index.push(y);
}
}
if (index.length === Y) {
index = undefined;
}
}
return this.setIndex(index);
}
});
DatasaurIndexed.preindexEventString = 'fin-hypergrid-data-prereindex';
DatasaurIndexed.postindexEventString = 'fin-hypergrid-data-postreindex';
/** @typedef {function} filterPredicate
* @summary Applies filter to given row.
* @this {Datasaur}
* @param {number} y - Index of row in data source (`this.datasaur`).
* @returns {boolean} Row qualifies (passes through filter).
*/
/**
* Used by the sorters, such as `DatasaurSorter`
* @param {object} dataRow
* @param {string} columnName
* @returns {*}
*/
DatasaurIndexed.valOrFunc = function(dataRow, columnName, calculator) {
var result;
if (dataRow) {
result = dataRow[columnName];
calculator = (typeof result)[0] === 'f' && result || calculator;
if (calculator) {
result = calculator(dataRow, columnName);
}
}
return result;
};
DatasaurIndexed.version = '3.0.0';
module.exports = DatasaurIndexed;