AntV
Search…
Util

F2.Util

Methods

upperFirst([string=''])

Converts the first character of string to upper case.
Arguments
    [string=''] (string): The string to convert.
Returns
(string): Returns the converted string.
Example
1
F2.Util.upperFirst('fred');
2
// => 'Fred'
3
4
F2.Util.upperFirst('FRED');
5
// => 'FRED
Copied!

lowerFirst([string=''])

Converts the first character of string to lower case.
Arguments
    [string=''] (string): The string to convert.
Returns
(string): Returns the converted string.
Example
1
F2.Util.lowerFirst('Fred');
2
// => 'fred'
3
4
F2.Util.lowerFirst('FRED');
5
// => 'fRED'
Copied!

isString(value)

Checks if value is classified as a String primitive or object.
Arguments
    value (*): The value to check.
Returns
(boolean): Returns true if value is a string, else false.
Example
1
F2.Util.isString('abc');
2
// => true
3
4
F2.Util.isString(1);
5
// => false
Copied!

isNumber(value)

Checks if value is classified as a Number primitive or object.
Arguments
    value (*): The value to check.
Returns
(boolean): Returns true if value is a number, else false.
Example
1
F2.Util.isNumber(3);
2
// => true
3
4
F2.Util.isNumber(Infinity);
5
// => true
6
7
F2.Util.isNumber('3');
8
// => false
Copied!

isBoolean(value)

Checks if value is classified as a boolean primitive or object.
Arguments
    value (*): The value to check.
Returns
(boolean): Returns true if value is a boolean, else false.
Example
1
F2.Util.isBoolean(false);
2
// => true
3
4
F2.Util.isBoolean(null);
5
// => false
Copied!

isFunction(value)

Checks if value is classified as a Function object.
Arguments
    value (*): The value to check.
Returns
(boolean): Returns true if value is a function, else false.
Example
1
F2.Util.isFunction(_);
2
// => true
Copied!

isPlainObject(value)

Checks if value is a plain object, that is, an object created by the Object constructor or one with a [[Prototype]] of null.
Arguments
    value (*): The value to check.
Returns
(boolean): Returns true if value is a plain object, else false.
Example
1
function Foo() {
2
this.a = 1;
3
}
4
5
F2.Util.isPlainObject(new Foo);
6
// => false
7
8
F2.Util.isPlainObject([1, 2, 3]);
9
// => false
10
11
F2.Util.isPlainObject({ 'x': 0, 'y': 0 });
12
// => true
13
14
F2.Util.isPlainObject(Object.create(null));
15
// => true
Copied!

isArray(value)

Checks if value is classified as an Array object.
Arguments
    value (*): The value to check.
Returns
(boolean): Returns true if value is an array, else false.
Example
1
F2.Util.isArray([1, 2, 3]);
2
// => true
3
4
F2.Util.isArray('abc');
5
// => false
Copied!

isDate(value)

Checks if value is classified as a Date object.
Arguments
    value (*): The value to check.
Returns
(boolean): Returns true if value is a date object, else false.
Example
1
F2.Util.isDate(new Date);
2
// => true
3
4
F2.Util.isDate('Mon April 23 2012');
5
// => false
Copied!

isNil(value)

Checks if value is null or undefined.
Arguments
    value (*): The value to check.
Returns
(boolean): Returns true if value is nullish, else false.
Example
1
F2.Util.isNil(null);
2
// => true
3
4
F2.Util.isNil(void 0);
5
// => true
6
7
F2.Util.isNil(NaN);
8
// => false
Copied!

isObject(value)

Checks if value is the language type of Object. (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))
Arguments
    value (*): The value to check.
Returns
(boolean): Returns true if value is an object, else false.
Example
1
F2.Util.isObject({});
2
// => true
3
4
F2.Util.isObject([1, 2, 3]);
5
// => true
6
7
F2.Util.isObject(null);
8
// => false
Copied!

mix(object, [sources])

Assigns own enumerable string keyed properties of source objects to the destination object. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.
Arguments
    1.
    object (Object): The destination object.
    2.
    [sources] (...Object): The source objects. Support for up to 3 objects
Returns
(Object): Returns object.
Example
1
const target = {
2
a: {
3
value: 1
4
}
5
};
6
7
const source = {
8
a: {
9
value: 2
10
},
11
b: 2
12
};
13
14
F2.Util.mix(target, source);
15
// => target will be { a: { value: 2 }, b2: 2 }
Copied!

deepMix(object, [sources])

This method is like F2.Util.mix except that it iterates over own source properties.
Arguments
    1.
    object (Object): The destination object.
    2.
    [sources] (...Object): The source objects.
Returns
(Object): Returns object.
Example
1
const target = {
2
a: {
3
type: 'a'
4
}
5
};
6
7
const source = {
8
a: {
9
value: 2
10
},
11
b: 2
12
};
13
14
F2.Util.mix(target, source);
15
// => target will be { a: { type: 'a', value: 2 }, b2: 2 }
Copied!

indexOf(array, value)

Gets the index at which the first occurrence of value is found in array.
Arguments
    1.
    array (Array): The array to inspect.
    2.
    value (*): The value to search for.
Returns
(number): Returns the index of the matched value, else -1.
Example
1
F2.Util.indexOf([1, 2, 1, 2], 2);
2
// => 1
Copied!

forEach(collection, [iteratee=_.identity])

Iterates over elements of collection and invokes iteratee for each element. The iteratee is invoked with three arguments: (value, index|key, collection). Iteratee functions may exit iteration early by explicitly returning false.
Arguments
    1.
    collection (Array|Object): The collection to iterate over.
    2.
    [iteratee=_.identity] (Function): The function invoked per iteration.
Returns
(*): Returns collection.
Example
1
F2.Util.each([1, 2], function(value) {
2
console.log(value);
3
});
4
// => Logs `1` then `2`.
5
6
F2.Util.each({ 'a': 1, 'b': 2 }, function(value, key) {
7
console.log(key);
8
});
9
// => Logs 'a' then 'b' (iteration order is not guaranteed).
10
11
F2.Util.each([1, 2, 3, 4, 5, 6], function(value) {
12
console.log(value);
13
if (value === 4) {
14
return false;
15
}
16
});
17
// => Logs `1`,`2`,`3`,`4`.
Copied!

getPixelRatio()

Get the current pixel ratio.
Returns
(number): Returns the current pixel ratio.

getRelativePosition(point, canvas)

Convert the position of the mouse to the relative coordinate of the canvas.
Arguments
    1.
    point (Object): the point need to convert.
    2.
    canvas (Canvas): the canvas instance of chart.
Returns
(object): Returns the relative coordinate of the canvas.
Example
1
const mousePoint = {
2
x: 10,
3
y:39
4
};
5
const canvas = chart.get('canvas');
6
const canvasPoint = F2.Util.getRelativePosition(mousePoint, canvas);
7
// => { x: , y: }
Copied!
Last modified 3yr ago