| 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 |
1×
1×
1×
1×
1×
1×
45×
45×
450×
315×
135×
45×
1×
40×
40×
400×
270×
130×
40×
1×
169×
142×
27×
10×
17×
17×
17×
1×
44×
6×
38×
9×
29×
29×
29×
155×
155×
155×
12×
143×
5×
12×
1×
4×
4×
40×
18×
22×
4×
1×
1×
1×
63×
63×
63×
63×
63×
1×
82×
1×
1×
1×
1×
1×
1×
5×
1×
1×
50×
50×
1×
11×
1×
47×
47×
40×
47×
7×
47×
1×
7×
1×
7×
1×
72×
1×
1×
1×
1×
1×
1×
1×
7×
7×
7×
41×
15×
26×
4×
3×
1×
2×
2×
2×
8×
6×
2×
1×
5×
1×
2×
2×
2×
2×
2×
2×
2×
2×
1×
2×
2×
2×
2×
2×
2×
2×
1×
1×
1×
1×
| "use strict";
var immutable_class_1 = require('immutable-class');
var plywood_1 = require('plywood');
var general_1 = require('../../../common/utils/general/general');
var NULL_COLOR = '#666666';
//const OTHERS_COLOR = '#AAAAAA';
var NORMAL_COLORS = [
'#2D95CA',
'#EFB925',
'#DA4E99',
'#4CC873',
'#745CBD',
'#EA7136',
'#E68EE0',
'#218C35',
'#B0B510',
'#904064'
];
function valuesFromJS(valuesJS) {
var values = {};
for (var i = 0; i < NORMAL_COLORS.length; i++) {
if (!general_1.hasOwnProperty(valuesJS, i))
continue;
values[i] = plywood_1.valueFromJS(valuesJS[i]);
}
return values;
}
function valuesToJS(values) {
var valuesJS = {};
for (var i = 0; i < NORMAL_COLORS.length; i++) {
if (!general_1.hasOwnProperty(values, i))
continue;
valuesJS[i] = plywood_1.valueToJS(values[i]);
}
return valuesJS;
}
function valueEquals(v1, v2) {
if (v1 === v2)
return true;
if (!v1 !== !v2)
return false;
Iif (v1.toISOString && v2.toISOString)
return v1.valueOf() === v2.valueOf();
Iif (immutable_class_1.isImmutableClass(v1))
return v1.equals(v2);
return false;
}
function valuesEqual(values1, values2) {
if (!Boolean(values1) === Boolean(values2))
return false;
if (values1 === values2)
return true;
Iif (!values1 !== !values2)
return false;
Iif (typeof values1 !== typeof values2)
return false;
for (var i = 0; i < NORMAL_COLORS.length; i++) {
var v1 = values1[i];
var v2 = values2[i];
if (general_1.hasOwnProperty(values1, i) !== general_1.hasOwnProperty(values2, i))
return false;
if (!valueEquals(v1, v2))
return false;
}
return true;
}
function cloneValues(values) {
var newValues = {};
for (var i = 0; i < NORMAL_COLORS.length; i++) {
if (!general_1.hasOwnProperty(values, i))
continue;
newValues[i] = values[i];
}
return newValues;
}
var check;
var Colors = (function () {
function Colors(parameters) {
this.dimension = parameters.dimension;
Iif (!this.dimension)
throw new Error('must have a dimension');
this.values = parameters.values;
this.limit = parameters.limit;
Iif (!this.values && !this.limit)
throw new Error('must have values or limit');
}
Colors.isColors = function (candidate) {
return immutable_class_1.isInstanceOf(candidate, Colors);
};
Colors.fromLimit = function (dimension, limit) {
return new Colors({ dimension: dimension, limit: limit });
};
Colors.fromValues = function (dimension, values) {
var valueLookup = {};
var n = Math.min(values.length, NORMAL_COLORS.length);
for (var i = 0; i < n; i++) {
valueLookup[i] = values[i];
}
return new Colors({ dimension: dimension, values: valueLookup });
};
Colors.fromJS = function (parameters) {
var value = {
dimension: parameters.dimension,
values: parameters.values ? valuesFromJS(parameters.values) : null,
limit: parameters.limit
};
return new Colors(value);
};
Colors.prototype.valueOf = function () {
return {
dimension: this.dimension,
values: this.values,
limit: this.limit
};
};
Colors.prototype.toJS = function () {
var js = {
dimension: this.dimension
};
if (this.values)
js.values = valuesToJS(this.values);
if (this.limit)
js.limit = this.limit;
return js;
};
Colors.prototype.toJSON = function () {
return this.toJS();
};
Colors.prototype.toString = function () {
return "[Colors: " + this.dimension + "]";
};
Colors.prototype.equals = function (other) {
return Colors.isColors(other) &&
valuesEqual(this.values, other.values) &&
Boolean(this.limit) === Boolean(other.limit) &&
(!this.limit || this.limit === other.limit);
};
Colors.prototype.numColors = function () {
var _a = this, values = _a.values, limit = _a.limit;
if (values) {
return Object.keys(values).length;
}
return limit;
};
Colors.prototype.toArray = function () {
var values = this.values;
if (!values)
return null;
var vs = [];
for (var i = 0; i < NORMAL_COLORS.length; i++) {
if (!general_1.hasOwnProperty(values, i))
continue;
vs.push(values[i]);
}
return vs;
};
Colors.prototype.toSet = function () {
if (!this.values)
return null;
return plywood_1.Set.fromJS(this.toArray());
};
Colors.prototype.toHavingFilter = function (segmentName) {
var _a = this, dimension = _a.dimension, values = _a.values;
if (!segmentName)
segmentName = dimension;
if (!values)
return null;
return new plywood_1.FilterAction({
expression: plywood_1.$(segmentName).in(this.toSet())
});
};
Colors.prototype.toLimitAction = function () {
return new plywood_1.LimitAction({
limit: this.numColors()
});
};
Colors.prototype.toggle = function (v) {
return this.has(v) ? this.remove(v) : this.add(v);
};
Colors.prototype.valueIndex = function (v) {
var values = this.values;
Iif (!values)
return -1;
for (var i = 0; i < NORMAL_COLORS.length; i++) {
if (!general_1.hasOwnProperty(values, i))
continue;
if (valueEquals(values[i], v))
return i;
}
return -1;
};
Colors.prototype.nextIndex = function () {
var values = this.values;
Iif (!values)
return 0;
for (var i = 0; i < NORMAL_COLORS.length; i++) {
if (general_1.hasOwnProperty(values, i))
continue;
return i;
}
return -1;
};
Colors.prototype.has = function (v) {
return this.valueIndex(v) !== -1;
};
Colors.prototype.add = function (v) {
Iif (this.has(v))
return this;
var idx = this.nextIndex();
Iif (idx === -1)
return this;
var value = this.valueOf();
value.values = value.values ? cloneValues(value.values) : {};
value.values[idx] = v;
delete value.limit;
return new Colors(value);
};
Colors.prototype.remove = function (v) {
var idx = this.valueIndex(v);
Iif (idx === -1)
return this;
var value = this.valueOf();
value.values = cloneValues(value.values);
delete value.values[idx];
delete value.limit;
return new Colors(value);
};
Colors.prototype.getColor = function (value, index) {
if (value === null)
return NULL_COLOR;
var _a = this, values = _a.values, limit = _a.limit;
if (values) {
var colorIdx = this.valueIndex(value);
return colorIdx === -1 ? null : NORMAL_COLORS[colorIdx];
}
else {
return index < limit ? NORMAL_COLORS[index] : null;
}
};
return Colors;
}());
exports.Colors = Colors;
check = Colors;
|