1 | ;
|
2 | /*
|
3 | * Copyright 2018 Palantir Technologies, Inc. All rights reserved.
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.argMin = exports.fillValues = exports.formatPercentage = void 0;
|
19 | /** Helper function for formatting ratios as CSS percentage values. */
|
20 | function formatPercentage(ratio) {
|
21 | return "".concat((ratio * 100).toFixed(2), "%");
|
22 | }
|
23 | exports.formatPercentage = formatPercentage;
|
24 | /**
|
25 | * Mutates the values array by filling all the values between start and end index (inclusive) with the fill value.
|
26 | */
|
27 | function fillValues(values, startIndex, endIndex, fillValue) {
|
28 | var inc = startIndex < endIndex ? 1 : -1;
|
29 | for (var index = startIndex; index !== endIndex + inc; index += inc) {
|
30 | values[index] = fillValue;
|
31 | }
|
32 | }
|
33 | exports.fillValues = fillValues;
|
34 | /**
|
35 | * Returns the minimum element of an array as determined by comparing the results of calling the arg function on each
|
36 | * element of the array. The function will only be called once per element.
|
37 | */
|
38 | function argMin(values, argFn) {
|
39 | if (values.length === 0) {
|
40 | return undefined;
|
41 | }
|
42 | var minValue = values[0];
|
43 | var minArg = argFn(minValue);
|
44 | for (var index = 1; index < values.length; index++) {
|
45 | var value = values[index];
|
46 | var arg = argFn(value);
|
47 | if (arg < minArg) {
|
48 | minValue = value;
|
49 | minArg = arg;
|
50 | }
|
51 | }
|
52 | return minValue;
|
53 | }
|
54 | exports.argMin = argMin;
|
55 | //# sourceMappingURL=sliderUtils.js.map |
\ | No newline at end of file |