123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- /**
- * Linear mapping a value from domain to range
- * @param val
- * @param domain Domain extent domain[0] can be bigger than domain[1]
- * @param range Range extent range[0] can be bigger than range[1]
- * @param clamp Default to be false
- */
- export declare function linearMap(val: number, domain: number[], range: number[], clamp?: boolean): number;
- /**
- * Convert a percent string to absolute number.
- * Returns NaN if percent is not a valid string or number
- */
- export declare function parsePercent(percent: number | string, all: number): number;
- /**
- * (1) Fix rounding error of float numbers.
- * (2) Support return string to avoid scientific notation like '3.5e-7'.
- */
- export declare function round(x: number | string, precision?: number): number;
- export declare function round(x: number | string, precision: number, returnStr: false): number;
- export declare function round(x: number | string, precision: number, returnStr: true): string;
- /**
- * Inplacd asc sort arr.
- * The input arr will be modified.
- */
- export declare function asc<T extends number[]>(arr: T): T;
- /**
- * Get precision.
- */
- export declare function getPrecision(val: string | number): number;
- /**
- * Get precision with slow but safe method
- */
- export declare function getPrecisionSafe(val: string | number): number;
- /**
- * Minimal dicernible data precisioin according to a single pixel.
- */
- export declare function getPixelPrecision(dataExtent: [number, number], pixelExtent: [number, number]): number;
- /**
- * Get a data of given precision, assuring the sum of percentages
- * in valueList is 1.
- * The largest remainer method is used.
- * https://en.wikipedia.org/wiki/Largest_remainder_method
- *
- * @param valueList a list of all data
- * @param idx index of the data to be processed in valueList
- * @param precision integer number showing digits of precision
- * @return percent ranging from 0 to 100
- */
- export declare function getPercentWithPrecision(valueList: number[], idx: number, precision: number): number;
- /**
- * Get a data of given precision, assuring the sum of percentages
- * in valueList is 1.
- * The largest remainer method is used.
- * https://en.wikipedia.org/wiki/Largest_remainder_method
- *
- * @param valueList a list of all data
- * @param precision integer number showing digits of precision
- * @return {Array<number>}
- */
- export declare function getPercentSeats(valueList: number[], precision: number): number[];
- /**
- * Solve the floating point adding problem like 0.1 + 0.2 === 0.30000000000000004
- * See <http://0.30000000000000004.com/>
- */
- export declare function addSafe(val0: number, val1: number): number;
- export declare const MAX_SAFE_INTEGER = 9007199254740991;
- /**
- * To 0 - 2 * PI, considering negative radian.
- */
- export declare function remRadian(radian: number): number;
- /**
- * @param {type} radian
- * @return {boolean}
- */
- export declare function isRadianAroundZero(val: number): boolean;
- /**
- * @param value valid type: number | string | Date, otherwise return `new Date(NaN)`
- * These values can be accepted:
- * + An instance of Date, represent a time in its own time zone.
- * + Or string in a subset of ISO 8601, only including:
- * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
- * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
- * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
- * all of which will be treated as local time if time zone is not specified
- * (see <https://momentjs.com/>).
- * + Or other string format, including (all of which will be treated as loacal time):
- * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
- * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
- * + a timestamp, which represent a time in UTC.
- * @return date Never be null/undefined. If invalid, return `new Date(NaN)`.
- */
- export declare function parseDate(value: unknown): Date;
- /**
- * Quantity of a number. e.g. 0.1, 1, 10, 100
- *
- * @param val
- * @return
- */
- export declare function quantity(val: number): number;
- /**
- * Exponent of the quantity of a number
- * e.g., 1234 equals to 1.234*10^3, so quantityExponent(1234) is 3
- *
- * @param val non-negative value
- * @return
- */
- export declare function quantityExponent(val: number): number;
- /**
- * find a “nice” number approximately equal to x. Round the number if round = true,
- * take ceiling if round = false. The primary observation is that the “nicest”
- * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
- *
- * See "Nice Numbers for Graph Labels" of Graphic Gems.
- *
- * @param val Non-negative value.
- * @param round
- * @return Niced number
- */
- export declare function nice(val: number, round?: boolean): number;
- /**
- * This code was copied from "d3.js"
- * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
- * See the license statement at the head of this file.
- * @param ascArr
- */
- export declare function quantile(ascArr: number[], p: number): number;
- declare type IntervalItem = {
- interval: [number, number];
- close: [0 | 1, 0 | 1];
- };
- /**
- * Order intervals asc, and split them when overlap.
- * expect(numberUtil.reformIntervals([
- * {interval: [18, 62], close: [1, 1]},
- * {interval: [-Infinity, -70], close: [0, 0]},
- * {interval: [-70, -26], close: [1, 1]},
- * {interval: [-26, 18], close: [1, 1]},
- * {interval: [62, 150], close: [1, 1]},
- * {interval: [106, 150], close: [1, 1]},
- * {interval: [150, Infinity], close: [0, 0]}
- * ])).toEqual([
- * {interval: [-Infinity, -70], close: [0, 0]},
- * {interval: [-70, -26], close: [1, 1]},
- * {interval: [-26, 18], close: [0, 1]},
- * {interval: [18, 62], close: [0, 1]},
- * {interval: [62, 150], close: [0, 1]},
- * {interval: [150, Infinity], close: [0, 0]}
- * ]);
- * @param list, where `close` mean open or close
- * of the interval, and Infinity can be used.
- * @return The origin list, which has been reformed.
- */
- export declare function reformIntervals(list: IntervalItem[]): IntervalItem[];
- /**
- * [Numberic is defined as]:
- * `parseFloat(val) == val`
- * For example:
- * numeric:
- * typeof number except NaN, '-123', '123', '2e3', '-2e3', '011', 'Infinity', Infinity,
- * and they rounded by white-spaces or line-terminal like ' -123 \n ' (see es spec)
- * not-numeric:
- * null, undefined, [], {}, true, false, 'NaN', NaN, '123ab',
- * empty string, string with only white-spaces or line-terminal (see es spec),
- * 0x12, '0x12', '-0x12', 012, '012', '-012',
- * non-string, ...
- *
- * @test See full test cases in `test/ut/spec/util/number.js`.
- * @return Must be a typeof number. If not numeric, return NaN.
- */
- export declare function numericToNumber(val: unknown): number;
- /**
- * Definition of "numeric": see `numericToNumber`.
- */
- export declare function isNumeric(val: unknown): val is number;
- /**
- * Use random base to prevent users hard code depending on
- * this auto generated marker id.
- * @return An positive integer.
- */
- export declare function getRandomIdBase(): number;
- /**
- * Get the greatest common dividor
- *
- * @param {number} a one number
- * @param {number} b the other number
- */
- export declare function getGreatestCommonDividor(a: number, b: number): number;
- /**
- * Get the least common multiple
- *
- * @param {number} a one number
- * @param {number} b the other number
- */
- export declare function getLeastCommonMultiple(a: number, b: number): number;
- export {};
|