code
stringlengths 10
343k
| docstring
stringlengths 36
21.9k
| func_name
stringlengths 1
3.35k
| language
stringclasses 1
value | repo
stringlengths 7
58
| path
stringlengths 4
131
| url
stringlengths 44
195
| license
stringclasses 5
values |
---|---|---|---|---|---|---|---|
trigger: function (eventName, event) {
this.handler.trigger(eventName, event);
}, | Trigger event manually
@param {string} eventName Event name
@param {event=} event Event object | trigger ( eventName , event ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function normalizeToArray(value) {
return value instanceof Array
? value
: value == null
? []
: [value];
} | If value is not array, then translate it to array.
@param {*} value
@return {Array} [value] or value | normalizeToArray ( value ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function defaultEmphasis(opt, key, subOpts) {
// Caution: performance sensitive.
if (opt) {
opt[key] = opt[key] || {};
opt.emphasis = opt.emphasis || {};
opt.emphasis[key] = opt.emphasis[key] || {};
// Default emphasis option from normal
for (var i = 0, len = subOpts.length; i < len; i++) {
var subOptName = subOpts[i];
if (!opt.emphasis[key].hasOwnProperty(subOptName)
&& opt[key].hasOwnProperty(subOptName)
) {
opt.emphasis[key][subOptName] = opt[key][subOptName];
}
}
}
} | Sync default option between normal and emphasis like `position` and `show`
In case some one will write code like
label: {
show: false,
position: 'outside',
fontSize: 18
},
emphasis: {
label: { show: true }
}
@param {Object} opt
@param {string} key
@param {Array.<string>} subOpts | defaultEmphasis ( opt , key , subOpts ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function getDataItemValue(dataItem) {
return (isObject$2(dataItem) && !isArray$1(dataItem) && !(dataItem instanceof Date))
? dataItem.value : dataItem;
} | The method do not ensure performance.
data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
This helper method retieves value from data.
@param {string|number|Date|Array|Object} dataItem
@return {number|string|Date|Array.<number|string|Date>} | getDataItemValue ( dataItem ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function isDataItemOption(dataItem) {
return isObject$2(dataItem)
&& !(dataItem instanceof Array);
// // markLine data can be array
// && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
} | data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
This helper method determine if dataItem has extra option besides value
@param {string|number|Date|Array|Object} dataItem | isDataItemOption ( dataItem ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function mappingToExists(exists, newCptOptions) {
// Mapping by the order by original option (but not order of
// new option) in merge mode. Because we should ensure
// some specified index (like xAxisIndex) is consistent with
// original option, which is easy to understand, espatially in
// media query. And in most case, merge option is used to
// update partial option but not be expected to change order.
newCptOptions = (newCptOptions || []).slice();
var result = map(exists || [], function (obj, index) {
return {exist: obj};
});
// Mapping by id or name if specified.
each$2(newCptOptions, function (cptOption, index) {
if (!isObject$2(cptOption)) {
return;
}
// id has highest priority.
for (var i = 0; i < result.length; i++) {
if (!result[i].option // Consider name: two map to one.
&& cptOption.id != null
&& result[i].exist.id === cptOption.id + ''
) {
result[i].option = cptOption;
newCptOptions[index] = null;
return;
}
}
for (var i = 0; i < result.length; i++) {
var exist = result[i].exist;
if (!result[i].option // Consider name: two map to one.
// Can not match when both ids exist but different.
&& (exist.id == null || cptOption.id == null)
&& cptOption.name != null
&& !isIdInner(cptOption)
&& !isIdInner(exist)
&& exist.name === cptOption.name + ''
) {
result[i].option = cptOption;
newCptOptions[index] = null;
return;
}
}
});
// Otherwise mapping by index.
each$2(newCptOptions, function (cptOption, index) {
if (!isObject$2(cptOption)) {
return;
}
var i = 0;
for (; i < result.length; i++) {
var exist = result[i].exist;
if (!result[i].option
// Existing model that already has id should be able to
// mapped to (because after mapping performed model may
// be assigned with a id, whish should not affect next
// mapping), except those has inner id.
&& !isIdInner(exist)
// Caution:
// Do not overwrite id. But name can be overwritten,
// because axis use name as 'show label text'.
// 'exist' always has id and name and we dont
// need to check it.
&& cptOption.id == null
) {
result[i].option = cptOption;
break;
}
}
if (i >= result.length) {
result.push({option: cptOption});
}
});
return result;
} | Mapping to exists for merge.
@public
@param {Array.<Object>|Array.<module:echarts/model/Component>} exists
@param {Object|Array.<Object>} newCptOptions
@return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
index of which is the same as exists. | mappingToExists ( exists , newCptOptions ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function makeIdAndName(mapResult) {
// We use this id to hash component models and view instances
// in echarts. id can be specified by user, or auto generated.
// The id generation rule ensures new view instance are able
// to mapped to old instance when setOption are called in
// no-merge mode. So we generate model id by name and plus
// type in view id.
// name can be duplicated among components, which is convenient
// to specify multi components (like series) by one name.
// Ensure that each id is distinct.
var idMap = createHashMap();
each$2(mapResult, function (item, index) {
var existCpt = item.exist;
existCpt && idMap.set(existCpt.id, item);
});
each$2(mapResult, function (item, index) {
var opt = item.option;
assert$1(
!opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item,
'id duplicates: ' + (opt && opt.id)
);
opt && opt.id != null && idMap.set(opt.id, item);
!item.keyInfo && (item.keyInfo = {});
});
// Make name and id.
each$2(mapResult, function (item, index) {
var existCpt = item.exist;
var opt = item.option;
var keyInfo = item.keyInfo;
if (!isObject$2(opt)) {
return;
}
// name can be overwitten. Consider case: axis.name = '20km'.
// But id generated by name will not be changed, which affect
// only in that case: setOption with 'not merge mode' and view
// instance will be recreated, which can be accepted.
keyInfo.name = opt.name != null
? opt.name + ''
: existCpt
? existCpt.name
// Avoid diffferent series has the same name,
// because name may be used like in color pallet.
: DUMMY_COMPONENT_NAME_PREFIX + index;
if (existCpt) {
keyInfo.id = existCpt.id;
}
else if (opt.id != null) {
keyInfo.id = opt.id + '';
}
else {
// Consider this situatoin:
// optionA: [{name: 'a'}, {name: 'a'}, {..}]
// optionB [{..}, {name: 'a'}, {name: 'a'}]
// Series with the same name between optionA and optionB
// should be mapped.
var idNum = 0;
do {
keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
}
while (idMap.get(keyInfo.id));
}
idMap.set(keyInfo.id, item);
});
} | Make id and name for mapping result (result of mappingToExists)
into `keyInfo` field.
@public
@param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
which order is the same as exists.
@return {Array.<Object>} The input. | makeIdAndName ( mapResult ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function isIdInner(cptOption) {
return isObject$2(cptOption)
&& cptOption.id
&& (cptOption.id + '').indexOf('\0_ec_\0') === 0;
} | @public
@param {Object} cptOption
@return {boolean} | isIdInner ( cptOption ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function queryDataIndex(data, payload) {
if (payload.dataIndexInside != null) {
return payload.dataIndexInside;
}
else if (payload.dataIndex != null) {
return isArray(payload.dataIndex)
? map(payload.dataIndex, function (value) {
return data.indexOfRawIndex(value);
})
: data.indexOfRawIndex(payload.dataIndex);
}
else if (payload.name != null) {
return isArray(payload.name)
? map(payload.name, function (value) {
return data.indexOfName(value);
})
: data.indexOfName(payload.name);
}
} | @param {module:echarts/data/List} data
@param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
each of which can be Array or primary type.
@return {number|Array.<number>} dataIndex If not found, return undefined/null. | queryDataIndex ( data , payload ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function makeInner() {
// Consider different scope by es module import.
var key = '__\0ec_inner_' + innerUniqueIndex++ + '_' + Math.random().toFixed(5);
return function (hostObj) {
return hostObj[key] || (hostObj[key] = {});
};
} | Enable property storage to any host object.
Notice: Serialization is not supported.
For example:
var inner = zrUitl.makeInner();
function some1(hostObj) {
inner(hostObj).someProperty = 1212;
...
}
function some2() {
var fields = inner(this);
fields.someProperty1 = 1212;
fields.someProperty2 = 'xx';
...
}
@return {Function} | makeInner ( ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function parseClassType$1(componentType) {
var ret = {main: '', sub: ''};
if (componentType) {
componentType = componentType.split(TYPE_DELIMITER);
ret.main = componentType[0] || '';
ret.sub = componentType[1] || '';
}
return ret;
} | Notice, parseClassType('') should returns {main: '', sub: ''}
@public | $1 ( componentType ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function enableClassCheck(Clz) {
var classAttr = ['__\0is_clz', classBase++, Math.random().toFixed(3)].join('_');
Clz.prototype[classAttr] = true;
if (__DEV__) {
assert$1(!Clz.isInstance, 'The method "is" can not be defined.');
}
Clz.isInstance = function (obj) {
return !!(obj && obj[classAttr]);
};
} | Can not use instanceof, consider different scope by
cross domain or es module import in ec extensions.
Mount a method "isInstance()" to Clz. | enableClassCheck ( Clz ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
entity.getAllClassMainTypes = function () {
var types = [];
each$1(storage, function (obj, type) {
types.push(type);
});
return types;
}; | @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx'] | entity.getAllClassMainTypes ( ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
entity.hasSubTypes = function (componentType) {
componentType = parseClassType$1(componentType);
var obj = storage[componentType.main];
return obj && obj[IS_CONTAINER];
}; | If a main type is container and has sub types
@param {string} mainType
@return {boolean} | entity.hasSubTypes ( componentType ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function enableClassManagement(entity, options) {
options = options || {};
/**
* Component model classes
* key: componentType,
* value:
* componentClass, when componentType is 'xxx'
* or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
* @type {Object}
*/
var storage = {};
entity.registerClass = function (Clazz, componentType) {
if (componentType) {
checkClassType(componentType);
componentType = parseClassType$1(componentType);
if (!componentType.sub) {
if (__DEV__) {
if (storage[componentType.main]) {
console.warn(componentType.main + ' exists.');
}
}
storage[componentType.main] = Clazz;
}
else if (componentType.sub !== IS_CONTAINER) {
var container = makeContainer(componentType);
container[componentType.sub] = Clazz;
}
}
return Clazz;
};
entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
var Clazz = storage[componentMainType];
if (Clazz && Clazz[IS_CONTAINER]) {
Clazz = subType ? Clazz[subType] : null;
}
if (throwWhenNotFound && !Clazz) {
throw new Error(
!subType
? componentMainType + '.' + 'type should be specified.'
: 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.'
);
}
return Clazz;
};
entity.getClassesByMainType = function (componentType) {
componentType = parseClassType$1(componentType);
var result = [];
var obj = storage[componentType.main];
if (obj && obj[IS_CONTAINER]) {
each$1(obj, function (o, type) {
type !== IS_CONTAINER && result.push(o);
});
}
else {
result.push(obj);
}
return result;
};
entity.hasClass = function (componentType) {
// Just consider componentType.main.
componentType = parseClassType$1(componentType);
return !!storage[componentType.main];
};
/**
* @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
*/
entity.getAllClassMainTypes = function () {
var types = [];
each$1(storage, function (obj, type) {
types.push(type);
});
return types;
};
/**
* If a main type is container and has sub types
* @param {string} mainType
* @return {boolean}
*/
entity.hasSubTypes = function (componentType) {
componentType = parseClassType$1(componentType);
var obj = storage[componentType.main];
return obj && obj[IS_CONTAINER];
};
entity.parseClassType = parseClassType$1;
function makeContainer(componentType) {
var container = storage[componentType.main];
if (!container || !container[IS_CONTAINER]) {
container = storage[componentType.main] = {};
container[IS_CONTAINER] = true;
}
return container;
}
if (options.registerWhenExtend) {
var originalExtend = entity.extend;
if (originalExtend) {
entity.extend = function (proto) {
var ExtendedClass = originalExtend.call(this, proto);
return entity.registerClass(ExtendedClass, proto.type);
};
}
}
return entity;
} | @param {Object} entity
@param {Object} options
@param {boolean} [options.registerWhenExtend]
@public | enableClassManagement ( entity , options ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function cubicAt(p0, p1, p2, p3, t) {
var onet = 1 - t;
return onet * onet * (onet * p0 + 3 * t * p1)
+ t * t * (t * p3 + 3 * onet * p2);
} | 计算三次贝塞尔值
@memberOf module:zrender/core/curve
@param {number} p0
@param {number} p1
@param {number} p2
@param {number} p3
@param {number} t
@return {number} | cubicAt ( p0 , p1 , p2 , p3 , t ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function cubicDerivativeAt(p0, p1, p2, p3, t) {
var onet = 1 - t;
return 3 * (
((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
+ (p3 - p2) * t * t
);
} | 计算三次贝塞尔导数值
@memberOf module:zrender/core/curve
@param {number} p0
@param {number} p1
@param {number} p2
@param {number} p3
@param {number} t
@return {number} | cubicDerivativeAt ( p0 , p1 , p2 , p3 , t ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function cubicRootAt(p0, p1, p2, p3, val, roots) {
// Evaluate roots of cubic functions
var a = p3 + 3 * (p1 - p2) - p0;
var b = 3 * (p2 - p1 * 2 + p0);
var c = 3 * (p1 - p0);
var d = p0 - val;
var A = b * b - 3 * a * c;
var B = b * c - 9 * a * d;
var C = c * c - 3 * b * d;
var n = 0;
if (isAroundZero(A) && isAroundZero(B)) {
if (isAroundZero(b)) {
roots[0] = 0;
}
else {
var t1 = -c / b; //t1, t2, t3, b is not zero
if (t1 >= 0 && t1 <= 1) {
roots[n++] = t1;
}
}
}
else {
var disc = B * B - 4 * A * C;
if (isAroundZero(disc)) {
var K = B / A;
var t1 = -b / a + K; // t1, a is not zero
var t2 = -K / 2; // t2, t3
if (t1 >= 0 && t1 <= 1) {
roots[n++] = t1;
}
if (t2 >= 0 && t2 <= 1) {
roots[n++] = t2;
}
}
else if (disc > 0) {
var discSqrt = mathSqrt$2(disc);
var Y1 = A * b + 1.5 * a * (-B + discSqrt);
var Y2 = A * b + 1.5 * a * (-B - discSqrt);
if (Y1 < 0) {
Y1 = -mathPow(-Y1, ONE_THIRD);
}
else {
Y1 = mathPow(Y1, ONE_THIRD);
}
if (Y2 < 0) {
Y2 = -mathPow(-Y2, ONE_THIRD);
}
else {
Y2 = mathPow(Y2, ONE_THIRD);
}
var t1 = (-b - (Y1 + Y2)) / (3 * a);
if (t1 >= 0 && t1 <= 1) {
roots[n++] = t1;
}
}
else {
var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt$2(A * A * A));
var theta = Math.acos(T) / 3;
var ASqrt = mathSqrt$2(A);
var tmp = Math.cos(theta);
var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
if (t1 >= 0 && t1 <= 1) {
roots[n++] = t1;
}
if (t2 >= 0 && t2 <= 1) {
roots[n++] = t2;
}
if (t3 >= 0 && t3 <= 1) {
roots[n++] = t3;
}
}
}
return n;
} | 计算三次贝塞尔方程根,使用盛金公式
@memberOf module:zrender/core/curve
@param {number} p0
@param {number} p1
@param {number} p2
@param {number} p3
@param {number} val
@param {Array.<number>} roots
@return {number} 有效根数目 | cubicRootAt ( p0 , p1 , p2 , p3 , val , roots ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function cubicExtrema(p0, p1, p2, p3, extrema) {
var b = 6 * p2 - 12 * p1 + 6 * p0;
var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
var c = 3 * p1 - 3 * p0;
var n = 0;
if (isAroundZero(a)) {
if (isNotAroundZero$1(b)) {
var t1 = -c / b;
if (t1 >= 0 && t1 <= 1) {
extrema[n++] = t1;
}
}
}
else {
var disc = b * b - 4 * a * c;
if (isAroundZero(disc)) {
extrema[0] = -b / (2 * a);
}
else if (disc > 0) {
var discSqrt = mathSqrt$2(disc);
var t1 = (-b + discSqrt) / (2 * a);
var t2 = (-b - discSqrt) / (2 * a);
if (t1 >= 0 && t1 <= 1) {
extrema[n++] = t1;
}
if (t2 >= 0 && t2 <= 1) {
extrema[n++] = t2;
}
}
}
return n;
} | 计算三次贝塞尔方程极限值的位置
@memberOf module:zrender/core/curve
@param {number} p0
@param {number} p1
@param {number} p2
@param {number} p3
@param {Array.<number>} extrema
@return {number} 有效数目 | cubicExtrema ( p0 , p1 , p2 , p3 , extrema ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function cubicSubdivide(p0, p1, p2, p3, t, out) {
var p01 = (p1 - p0) * t + p0;
var p12 = (p2 - p1) * t + p1;
var p23 = (p3 - p2) * t + p2;
var p012 = (p12 - p01) * t + p01;
var p123 = (p23 - p12) * t + p12;
var p0123 = (p123 - p012) * t + p012;
// Seg0
out[0] = p0;
out[1] = p01;
out[2] = p012;
out[3] = p0123;
// Seg1
out[4] = p0123;
out[5] = p123;
out[6] = p23;
out[7] = p3;
} | 细分三次贝塞尔曲线
@memberOf module:zrender/core/curve
@param {number} p0
@param {number} p1
@param {number} p2
@param {number} p3
@param {number} t
@param {Array.<number>} out | cubicSubdivide ( p0 , p1 , p2 , p3 , t , out ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function cubicProjectPoint(
x0, y0, x1, y1, x2, y2, x3, y3,
x, y, out
) {
// http://pomax.github.io/bezierinfo/#projections
var t;
var interval = 0.005;
var d = Infinity;
var prev;
var next;
var d1;
var d2;
_v0[0] = x;
_v0[1] = y;
// 先粗略估计一下可能的最小距离的 t 值
// PENDING
for (var _t = 0; _t < 1; _t += 0.05) {
_v1[0] = cubicAt(x0, x1, x2, x3, _t);
_v1[1] = cubicAt(y0, y1, y2, y3, _t);
d1 = distSquare(_v0, _v1);
if (d1 < d) {
t = _t;
d = d1;
}
}
d = Infinity;
// At most 32 iteration
for (var i = 0; i < 32; i++) {
if (interval < EPSILON_NUMERIC) {
break;
}
prev = t - interval;
next = t + interval;
// t - interval
_v1[0] = cubicAt(x0, x1, x2, x3, prev);
_v1[1] = cubicAt(y0, y1, y2, y3, prev);
d1 = distSquare(_v1, _v0);
if (prev >= 0 && d1 < d) {
t = prev;
d = d1;
}
else {
// t + interval
_v2[0] = cubicAt(x0, x1, x2, x3, next);
_v2[1] = cubicAt(y0, y1, y2, y3, next);
d2 = distSquare(_v2, _v0);
if (next <= 1 && d2 < d) {
t = next;
d = d2;
}
else {
interval *= 0.5;
}
}
}
// t
if (out) {
out[0] = cubicAt(x0, x1, x2, x3, t);
out[1] = cubicAt(y0, y1, y2, y3, t);
}
// console.log(interval, i);
return mathSqrt$2(d);
} | 投射点到三次贝塞尔曲线上,返回投射距离。
投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
@param {number} x0
@param {number} y0
@param {number} x1
@param {number} y1
@param {number} x2
@param {number} y2
@param {number} x3
@param {number} y3
@param {number} x
@param {number} y
@param {Array.<number>} [out] 投射点
@return {number} | cubicProjectPoint ( x0 , y0 , x1 , y1 , x2 , y2 , x3 , y3 , x , y , out ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function quadraticAt(p0, p1, p2, t) {
var onet = 1 - t;
return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
} | 计算二次方贝塞尔值
@param {number} p0
@param {number} p1
@param {number} p2
@param {number} t
@return {number} | quadraticAt ( p0 , p1 , p2 , t ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function quadraticDerivativeAt(p0, p1, p2, t) {
return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
} | 计算二次方贝塞尔导数值
@param {number} p0
@param {number} p1
@param {number} p2
@param {number} t
@return {number} | quadraticDerivativeAt ( p0 , p1 , p2 , t ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function quadraticRootAt(p0, p1, p2, val, roots) {
var a = p0 - 2 * p1 + p2;
var b = 2 * (p1 - p0);
var c = p0 - val;
var n = 0;
if (isAroundZero(a)) {
if (isNotAroundZero$1(b)) {
var t1 = -c / b;
if (t1 >= 0 && t1 <= 1) {
roots[n++] = t1;
}
}
}
else {
var disc = b * b - 4 * a * c;
if (isAroundZero(disc)) {
var t1 = -b / (2 * a);
if (t1 >= 0 && t1 <= 1) {
roots[n++] = t1;
}
}
else if (disc > 0) {
var discSqrt = mathSqrt$2(disc);
var t1 = (-b + discSqrt) / (2 * a);
var t2 = (-b - discSqrt) / (2 * a);
if (t1 >= 0 && t1 <= 1) {
roots[n++] = t1;
}
if (t2 >= 0 && t2 <= 1) {
roots[n++] = t2;
}
}
}
return n;
} | 计算二次方贝塞尔方程根
@param {number} p0
@param {number} p1
@param {number} p2
@param {number} t
@param {Array.<number>} roots
@return {number} 有效根数目 | quadraticRootAt ( p0 , p1 , p2 , val , roots ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function quadraticExtremum(p0, p1, p2) {
var divider = p0 + p2 - 2 * p1;
if (divider === 0) {
// p1 is center of p0 and p2
return 0.5;
}
else {
return (p0 - p1) / divider;
}
} | 计算二次贝塞尔方程极限值
@memberOf module:zrender/core/curve
@param {number} p0
@param {number} p1
@param {number} p2
@return {number} | quadraticExtremum ( p0 , p1 , p2 ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function quadraticSubdivide(p0, p1, p2, t, out) {
var p01 = (p1 - p0) * t + p0;
var p12 = (p2 - p1) * t + p1;
var p012 = (p12 - p01) * t + p01;
// Seg0
out[0] = p0;
out[1] = p01;
out[2] = p012;
// Seg1
out[3] = p012;
out[4] = p12;
out[5] = p2;
} | 细分二次贝塞尔曲线
@memberOf module:zrender/core/curve
@param {number} p0
@param {number} p1
@param {number} p2
@param {number} t
@param {Array.<number>} out | quadraticSubdivide ( p0 , p1 , p2 , t , out ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function quadraticProjectPoint(
x0, y0, x1, y1, x2, y2,
x, y, out
) {
// http://pomax.github.io/bezierinfo/#projections
var t;
var interval = 0.005;
var d = Infinity;
_v0[0] = x;
_v0[1] = y;
// 先粗略估计一下可能的最小距离的 t 值
// PENDING
for (var _t = 0; _t < 1; _t += 0.05) {
_v1[0] = quadraticAt(x0, x1, x2, _t);
_v1[1] = quadraticAt(y0, y1, y2, _t);
var d1 = distSquare(_v0, _v1);
if (d1 < d) {
t = _t;
d = d1;
}
}
d = Infinity;
// At most 32 iteration
for (var i = 0; i < 32; i++) {
if (interval < EPSILON_NUMERIC) {
break;
}
var prev = t - interval;
var next = t + interval;
// t - interval
_v1[0] = quadraticAt(x0, x1, x2, prev);
_v1[1] = quadraticAt(y0, y1, y2, prev);
var d1 = distSquare(_v1, _v0);
if (prev >= 0 && d1 < d) {
t = prev;
d = d1;
}
else {
// t + interval
_v2[0] = quadraticAt(x0, x1, x2, next);
_v2[1] = quadraticAt(y0, y1, y2, next);
var d2 = distSquare(_v2, _v0);
if (next <= 1 && d2 < d) {
t = next;
d = d2;
}
else {
interval *= 0.5;
}
}
}
// t
if (out) {
out[0] = quadraticAt(x0, x1, x2, t);
out[1] = quadraticAt(y0, y1, y2, t);
}
// console.log(interval, i);
return mathSqrt$2(d);
} | 投射点到二次贝塞尔曲线上,返回投射距离。
投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
@param {number} x0
@param {number} y0
@param {number} x1
@param {number} y1
@param {number} x2
@param {number} y2
@param {number} x
@param {number} y
@param {Array.<number>} out 投射点
@return {number} | quadraticProjectPoint ( x0 , y0 , x1 , y1 , x2 , y2 , x , y , out ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function fromPoints(points, min$$1, max$$1) {
if (points.length === 0) {
return;
}
var p = points[0];
var left = p[0];
var right = p[0];
var top = p[1];
var bottom = p[1];
var i;
for (i = 1; i < points.length; i++) {
p = points[i];
left = mathMin$3(left, p[0]);
right = mathMax$3(right, p[0]);
top = mathMin$3(top, p[1]);
bottom = mathMax$3(bottom, p[1]);
}
min$$1[0] = left;
min$$1[1] = top;
max$$1[0] = right;
max$$1[1] = bottom;
} | 从顶点数组中计算出最小包围盒,写入`min`和`max`中
@module zrender/core/bbox
@param {Array<Object>} points 顶点数组
@param {number} min
@param {number} max | fromPoints ( points , min $ $1 , max $ $1 ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function fromLine(x0, y0, x1, y1, min$$1, max$$1) {
min$$1[0] = mathMin$3(x0, x1);
min$$1[1] = mathMin$3(y0, y1);
max$$1[0] = mathMax$3(x0, x1);
max$$1[1] = mathMax$3(y0, y1);
} | @memberOf module:zrender/core/bbox
@param {number} x0
@param {number} y0
@param {number} x1
@param {number} y1
@param {Array.<number>} min
@param {Array.<number>} max | fromLine ( x0 , y0 , x1 , y1 , min $ $1 , max $ $1 ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function fromCubic(
x0, y0, x1, y1, x2, y2, x3, y3, min$$1, max$$1
) {
var cubicExtrema$$1 = cubicExtrema;
var cubicAt$$1 = cubicAt;
var i;
var n = cubicExtrema$$1(x0, x1, x2, x3, xDim);
min$$1[0] = Infinity;
min$$1[1] = Infinity;
max$$1[0] = -Infinity;
max$$1[1] = -Infinity;
for (i = 0; i < n; i++) {
var x = cubicAt$$1(x0, x1, x2, x3, xDim[i]);
min$$1[0] = mathMin$3(x, min$$1[0]);
max$$1[0] = mathMax$3(x, max$$1[0]);
}
n = cubicExtrema$$1(y0, y1, y2, y3, yDim);
for (i = 0; i < n; i++) {
var y = cubicAt$$1(y0, y1, y2, y3, yDim[i]);
min$$1[1] = mathMin$3(y, min$$1[1]);
max$$1[1] = mathMax$3(y, max$$1[1]);
}
min$$1[0] = mathMin$3(x0, min$$1[0]);
max$$1[0] = mathMax$3(x0, max$$1[0]);
min$$1[0] = mathMin$3(x3, min$$1[0]);
max$$1[0] = mathMax$3(x3, max$$1[0]);
min$$1[1] = mathMin$3(y0, min$$1[1]);
max$$1[1] = mathMax$3(y0, max$$1[1]);
min$$1[1] = mathMin$3(y3, min$$1[1]);
max$$1[1] = mathMax$3(y3, max$$1[1]);
} | 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
@memberOf module:zrender/core/bbox
@param {number} x0
@param {number} y0
@param {number} x1
@param {number} y1
@param {number} x2
@param {number} y2
@param {number} x3
@param {number} y3
@param {Array.<number>} min
@param {Array.<number>} max | fromCubic ( x0 , y0 , x1 , y1 , x2 , y2 , x3 , y3 , min $ $1 , max $ $1 ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function fromQuadratic(x0, y0, x1, y1, x2, y2, min$$1, max$$1) {
var quadraticExtremum$$1 = quadraticExtremum;
var quadraticAt$$1 = quadraticAt;
// Find extremities, where derivative in x dim or y dim is zero
var tx =
mathMax$3(
mathMin$3(quadraticExtremum$$1(x0, x1, x2), 1), 0
);
var ty =
mathMax$3(
mathMin$3(quadraticExtremum$$1(y0, y1, y2), 1), 0
);
var x = quadraticAt$$1(x0, x1, x2, tx);
var y = quadraticAt$$1(y0, y1, y2, ty);
min$$1[0] = mathMin$3(x0, x2, x);
min$$1[1] = mathMin$3(y0, y2, y);
max$$1[0] = mathMax$3(x0, x2, x);
max$$1[1] = mathMax$3(y0, y2, y);
} | 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
@memberOf module:zrender/core/bbox
@param {number} x0
@param {number} y0
@param {number} x1
@param {number} y1
@param {number} x2
@param {number} y2
@param {Array.<number>} min
@param {Array.<number>} max | fromQuadratic ( x0 , y0 , x1 , y1 , x2 , y2 , min $ $1 , max $ $1 ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function fromArc(
x, y, rx, ry, startAngle, endAngle, anticlockwise, min$$1, max$$1
) {
var vec2Min = min;
var vec2Max = max;
var diff = Math.abs(startAngle - endAngle);
if (diff % PI2 < 1e-4 && diff > 1e-4) {
// Is a circle
min$$1[0] = x - rx;
min$$1[1] = y - ry;
max$$1[0] = x + rx;
max$$1[1] = y + ry;
return;
}
start[0] = mathCos$2(startAngle) * rx + x;
start[1] = mathSin$2(startAngle) * ry + y;
end[0] = mathCos$2(endAngle) * rx + x;
end[1] = mathSin$2(endAngle) * ry + y;
vec2Min(min$$1, start, end);
vec2Max(max$$1, start, end);
// Thresh to [0, Math.PI * 2]
startAngle = startAngle % (PI2);
if (startAngle < 0) {
startAngle = startAngle + PI2;
}
endAngle = endAngle % (PI2);
if (endAngle < 0) {
endAngle = endAngle + PI2;
}
if (startAngle > endAngle && !anticlockwise) {
endAngle += PI2;
}
else if (startAngle < endAngle && anticlockwise) {
startAngle += PI2;
}
if (anticlockwise) {
var tmp = endAngle;
endAngle = startAngle;
startAngle = tmp;
}
// var number = 0;
// var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
if (angle > startAngle) {
extremity[0] = mathCos$2(angle) * rx + x;
extremity[1] = mathSin$2(angle) * ry + y;
vec2Min(min$$1, extremity, min$$1);
vec2Max(max$$1, extremity, max$$1);
}
}
} | 从圆弧中计算出最小包围盒,写入`min`和`max`中
@method
@memberOf module:zrender/core/bbox
@param {number} x
@param {number} y
@param {number} rx
@param {number} ry
@param {number} startAngle
@param {number} endAngle
@param {number} anticlockwise
@param {Array.<number>} min
@param {Array.<number>} max | fromArc ( x , y , rx , ry , startAngle , endAngle , anticlockwise , min $ $1 , max $ $1 ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
var PathProxy = function (notSaveData) {
this._saveData = !(notSaveData || false);
if (this._saveData) {
/**
* Path data. Stored as flat array
* @type {Array.<Object>}
*/
this.data = [];
}
this._ctx = null;
}; | @alias module:zrender/core/PathProxy
@constructor | PathProxy ( notSaveData ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
beginPath: function (ctx) {
this._ctx = ctx;
ctx && ctx.beginPath();
ctx && (this.dpr = ctx.dpr);
// Reset
if (this._saveData) {
this._len = 0;
}
if (this._lineDash) {
this._lineDash = null;
this._dashOffset = 0;
}
return this;
}, | @param {CanvasRenderingContext2D} ctx
@return {module:zrender/core/PathProxy} | beginPath ( ctx ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
moveTo: function (x, y) {
this.addData(CMD.M, x, y);
this._ctx && this._ctx.moveTo(x, y);
// x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
// xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
// 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
// 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
this._x0 = x;
this._y0 = y;
this._xi = x;
this._yi = y;
return this;
}, | @param {number} x
@param {number} y
@return {module:zrender/core/PathProxy} | moveTo ( x , y ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
if (this._ctx) {
this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3)
: this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
}
this._xi = x3;
this._yi = y3;
return this;
}, | @param {number} x1
@param {number} y1
@param {number} x2
@param {number} y2
@param {number} x3
@param {number} y3
@return {module:zrender/core/PathProxy} | bezierCurveTo ( x1 , y1 , x2 , y2 , x3 , y3 ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
quadraticCurveTo: function (x1, y1, x2, y2) {
this.addData(CMD.Q, x1, y1, x2, y2);
if (this._ctx) {
this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2)
: this._ctx.quadraticCurveTo(x1, y1, x2, y2);
}
this._xi = x2;
this._yi = y2;
return this;
}, | @param {number} x1
@param {number} y1
@param {number} x2
@param {number} y2
@return {module:zrender/core/PathProxy} | quadraticCurveTo ( x1 , y1 , x2 , y2 ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function containStroke$1(x0, y0, x1, y1, lineWidth, x, y) {
if (lineWidth === 0) {
return false;
}
var _l = lineWidth;
var _a = 0;
var _b = x0;
// Quick reject
if (
(y > y0 + _l && y > y1 + _l)
|| (y < y0 - _l && y < y1 - _l)
|| (x > x0 + _l && x > x1 + _l)
|| (x < x0 - _l && x < x1 - _l)
) {
return false;
}
if (x0 !== x1) {
_a = (y0 - y1) / (x0 - x1);
_b = (x0 * y1 - x1 * y0) / (x0 - x1);
}
else {
return Math.abs(x - x0) <= _l / 2;
}
var tmp = _a * x - y + _b;
var _s = tmp * tmp / (_a * _a + 1);
return _s <= _l / 2 * _l / 2;
} | 线段包含判断
@param {number} x0
@param {number} y0
@param {number} x1
@param {number} y1
@param {number} lineWidth
@param {number} x
@param {number} y
@return {boolean} | $1 ( x0 , y0 , x1 , y1 , lineWidth , x , y ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function containStroke$2(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
if (lineWidth === 0) {
return false;
}
var _l = lineWidth;
// Quick reject
if (
(y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
|| (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
|| (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
|| (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)
) {
return false;
}
var d = cubicProjectPoint(
x0, y0, x1, y1, x2, y2, x3, y3,
x, y, null
);
return d <= _l / 2;
} | 三次贝塞尔曲线描边包含判断
@param {number} x0
@param {number} y0
@param {number} x1
@param {number} y1
@param {number} x2
@param {number} y2
@param {number} x3
@param {number} y3
@param {number} lineWidth
@param {number} x
@param {number} y
@return {boolean} | $2 ( x0 , y0 , x1 , y1 , x2 , y2 , x3 , y3 , lineWidth , x , y ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function containStroke$3(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
if (lineWidth === 0) {
return false;
}
var _l = lineWidth;
// Quick reject
if (
(y > y0 + _l && y > y1 + _l && y > y2 + _l)
|| (y < y0 - _l && y < y1 - _l && y < y2 - _l)
|| (x > x0 + _l && x > x1 + _l && x > x2 + _l)
|| (x < x0 - _l && x < x1 - _l && x < x2 - _l)
) {
return false;
}
var d = quadraticProjectPoint(
x0, y0, x1, y1, x2, y2,
x, y, null
);
return d <= _l / 2;
} | 二次贝塞尔曲线描边包含判断
@param {number} x0
@param {number} y0
@param {number} x1
@param {number} y1
@param {number} x2
@param {number} y2
@param {number} lineWidth
@param {number} x
@param {number} y
@return {boolean} | $3 ( x0 , y0 , x1 , y1 , x2 , y2 , lineWidth , x , y ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function containStroke$4(
cx, cy, r, startAngle, endAngle, anticlockwise,
lineWidth, x, y
) {
if (lineWidth === 0) {
return false;
}
var _l = lineWidth;
x -= cx;
y -= cy;
var d = Math.sqrt(x * x + y * y);
if ((d - _l > r) || (d + _l < r)) {
return false;
}
if (Math.abs(startAngle - endAngle) % PI2$2 < 1e-4) {
// Is a circle
return true;
}
if (anticlockwise) {
var tmp = startAngle;
startAngle = normalizeRadian(endAngle);
endAngle = normalizeRadian(tmp);
}
else {
startAngle = normalizeRadian(startAngle);
endAngle = normalizeRadian(endAngle);
}
if (startAngle > endAngle) {
endAngle += PI2$2;
}
var angle = Math.atan2(y, x);
if (angle < 0) {
angle += PI2$2;
}
return (angle >= startAngle && angle <= endAngle)
|| (angle + PI2$2 >= startAngle && angle + PI2$2 <= endAngle);
} | 圆弧描边包含判断
@param {number} cx
@param {number} cy
@param {number} r
@param {number} startAngle
@param {number} endAngle
@param {boolean} anticlockwise
@param {number} lineWidth
@param {number} x
@param {number} y
@return {Boolean} | $4 ( cx , cy , r , startAngle , endAngle , anticlockwise , lineWidth , x , y ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function Path(opts) {
Displayable.call(this, opts);
/**
* @type {module:zrender/core/PathProxy}
* @readOnly
*/
this.path = null;
} | @alias module:zrender/graphic/Path
@extends module:zrender/graphic/Displayable
@constructor
@param {Object} opts | Path ( opts ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
animateShape: function (loop) {
return this.animate('shape', loop);
}, | Alias for animate('shape')
@param {boolean} loop | animateShape ( loop ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
Path.extend = function (defaults$$1) {
var Sub = function (opts) {
Path.call(this, opts);
if (defaults$$1.style) {
// Extend default style
this.style.extendFrom(defaults$$1.style, false);
}
// Extend default shape
var defaultShape = defaults$$1.shape;
if (defaultShape) {
this.shape = this.shape || {};
var thisShape = this.shape;
for (var name in defaultShape) {
if (
!thisShape.hasOwnProperty(name)
&& defaultShape.hasOwnProperty(name)
) {
thisShape[name] = defaultShape[name];
}
}
}
defaults$$1.init && defaults$$1.init.call(this, opts);
};
inherits(Sub, Path);
// FIXME 不能 extend position, rotation 等引用对象
for (var name in defaults$$1) {
// Extending prototype values and methods
if (name !== 'style' && name !== 'shape') {
Sub.prototype[name] = defaults$$1[name];
}
}
return Sub;
}; | 扩展一个 Path element, 比如星形,圆等。
Extend a path element
@param {Object} props
@param {string} props.type Path type
@param {Function} props.init Initialize
@param {Function} props.buildPath Overwrite buildPath method
@param {Object} [props.style] Extended default style config
@param {Object} [props.shape] Extended default shape config | Path.extend ( defaults $ $1 ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
// TODO Style override ?
function IncrementalDisplayble(opts) {
Displayable.call(this, opts);
this._displayables = [];
this._temporaryDisplayables = [];
this._cursor = 0;
this.notClear = true; | Displayable for incremental rendering. It will be rendered in a separate layer
IncrementalDisplay have two main methods. `clearDisplayables` and `addDisplayables`
addDisplayables will render the added displayables incremetally.
It use a not clearFlag to tell the painter don't clear the layer if it's the first element. | IncrementalDisplayble ( opts ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function asc(arr) {
arr.sort(function (a, b) {
return a - b; | asc sort arr.
The input arr will be modified.
@param {Array} arr
@return {Array} The input arr. | (anonymous) ( a , b ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function reformIntervals(list) {
list.sort(function (a, b) {
return littleThan(a, b, 0) ? -1 : 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 {Array.<Object>} list, where `close` mean open or close
of the interval, and Infinity can be used.
@return {Array.<Object>} The origin list, which has been reformed. | (anonymous) ( a , b ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function toCamelCase(str, upperCaseFirst) {
str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {
return group1.toUpperCase(); | @param {string} str
@param {boolean} [upperCaseFirst=false]
@return {string} str | (anonymous) ( match , group1 ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function formatTplSimple(tpl, param, encode) {
each$1(param, function (value, key) {
tpl = tpl.replace(
'{' + key + '}',
encode ? encodeHTML(value) : value
); | simple Template formatter
@param {string} tpl
@param {Object} param
@param {boolean} [encode=false]
@return {string} | (anonymous) ( value , key ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function copyLayoutParams(target, source) {
source && target && each$3(LOCATION_PARAMS, function (name) {
source.hasOwnProperty(name) && (target[name] = source[name]); | Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
@param {Object} source
@return {Object} Result contains those props. | (anonymous) ( name ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
getRawValue: function (idx, dataType) {
return retrieveRawValue(this.getData(dataType), idx); | Get raw value in option
@param {number} idx
@param {string} [dataType]
@return {Array|number|string} | retrieveRawValue ( this . getData ( dataType ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
ComponentModel.extend({
type: 'dataset',
/**
* @protected
*/
defaultOption: {
// 'row', 'column'
seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
// null/'auto': auto detect header, see "module:echarts/data/helper/sourceHelper"
sourceHeader: null,
dimensions: null,
source: null
},
optionUpdated: function () {
detectSourceFormat(this); | This module is imported by echarts directly.
Notice:
Always keep this file exists for backward compatibility.
Because before 4.1.0, dataset is an optional component,
some users may import this module manually. | ComponentModel.extend ( { type : 'dataset' , defaultOption : { seriesLayoutBy : SERIES_LAYOUT_BY_COLUMN , sourceHeader : null , dimensions : null , source : null } , optionUpdated : function ( ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function bindRenderedEvent(zr, ecIns) {
zr.on('rendered', function () {
ecIns.trigger('rendered');
// The `finished` event should not be triggered repeatly,
// so it should only be triggered when rendering indeed happend
// in zrender. (Consider the case that dipatchAction is keep
// triggering when mouse move).
if (
// Although zr is dirty if initial animation is not finished
// and this checking is called on frame, we also check
// animation finished for robustness.
zr.animation.isFinished()
&& !ecIns[OPTION_UPDATED]
&& !ecIns._scheduler.unfinished
&& !ecIns._pendingActions.length
) {
ecIns.trigger('finished');
} | Event `rendered` is triggered when zr
rendered. It is useful for realtime
snapshot (reflect animation).
Event `finished` is triggered when:
(1) zrender rendering finished.
(2) initial animation finished.
(3) progressive rendering finished.
(4) no pending action.
(5) no delayed setOption needs to be processed. | (anonymous) ( ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
listProto.eachItemGraphicEl = function (cb, context) {
each$1(this._graphicEls, function (el, idx) {
if (el) {
cb && cb.call(context, el, idx);
} | @param {Function} cb
@param {*} context | (anonymous) ( el , idx ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
var axisValues = {};
each$1(barSeries, function (seriesModel) {
var cartesian = seriesModel.coordinateSystem;
var baseAxis = cartesian.getBaseAxis();
if (baseAxis.type !== 'time' && baseAxis.type !== 'value') {
return;
}
var data = seriesModel.getData();
var key = baseAxis.dim + '_' + baseAxis.index;
var dim = data.mapDimension(baseAxis.dim);
for (var i = 0, cnt = data.count(); i < cnt; ++i) {
var value = data.get(dim, i);
if (!axisValues[key]) {
// No previous data for the axis
axisValues[key] = [value];
}
else {
// No value in previous series
axisValues[key].push(value);
}
// Ignore duplicated time values in the same axis
} | Map from axis.index to values.
For a single time axis, axisValues is in the form like
{'x_0': [1495555200000, 1495641600000, 1495728000000]}.
Items in axisValues[x], e.g. 1495555200000, are time values of all
series. | (anonymous) ( seriesModel ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts.common.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts.common.js | Apache-2.0 |
function compressBatches(batchA, batchB) {
var mapA = {};
var mapB = {};
makeMap(batchA || [], mapA);
makeMap(batchB || [], mapB, mapA);
return [mapToArray(mapA), mapToArray(mapB)];
function makeMap(sourceBatch, map$$1, otherMap) {
for (var i = 0, len = sourceBatch.length; i < len; i++) {
var seriesId = sourceBatch[i].seriesId;
var dataIndices = normalizeToArray(sourceBatch[i].dataIndex);
var otherDataIndices = otherMap && otherMap[seriesId];
for (var j = 0, lenj = dataIndices.length; j < lenj; j++) {
var dataIndex = dataIndices[j];
if (otherDataIndices && otherDataIndices[dataIndex]) {
otherDataIndices[dataIndex] = null;
}
else {
(map$$1[seriesId] || (map$$1[seriesId] = {}))[dataIndex] = 1;
}
}
}
}
function mapToArray(map$$1, isData) {
var result = [];
for (var i in map$$1) {
if (map$$1.hasOwnProperty(i) && map$$1[i] != null) {
if (isData) {
result.push(+i);
}
else {
var dataIndices = mapToArray(map$$1[i], true);
dataIndices.length && result.push({seriesId: i, dataIndex: dataIndices});
}
}
}
return result;
}
} | A helper for removing duplicate items between batchA and batchB,
and in themselves, and categorize by series.
@param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
@param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
@return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB] | compressBatches ( batchA , batchB ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts-en.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts-en.js | Apache-2.0 |
function groupData(array, getKey) {
var buckets = createHashMap();
var keys = [];
each$1(array, function (item) {
var key = getKey(item);
(buckets.get(key)
|| (keys.push(key), buckets.set(key, []))
).push(item);
});
return {keys: keys, buckets: buckets};
} | Group a list by key.
@param {Array} array
@param {Function} getKey
param {*} Array item
return {string} key
@return {Object} Result
{Array}: keys,
{module:zrender/core/util/HashMap} buckets: {key -> Array} | groupData ( array , getKey ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/echarts-en.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/echarts-en.js | Apache-2.0 |
function parse(xml) {
var doc;
if (typeof xml === 'string') {
var parser = new DOMParser();
doc = parser.parseFromString(xml, 'text/xml');
}
else {
doc = xml;
}
if (!doc || doc.getElementsByTagName('parsererror').length) {
return null;
}
var gexfRoot = getChildByTagName(doc, 'gexf');
if (!gexfRoot) {
return null;
}
var graphRoot = getChildByTagName(gexfRoot, 'graph');
var attributes = parseAttributes(getChildByTagName(graphRoot, 'attributes'));
var attributesMap = {};
for (var i = 0; i < attributes.length; i++) {
attributesMap[attributes[i].id] = attributes[i];
}
return {
nodes: parseNodes(getChildByTagName(graphRoot, 'nodes'), attributesMap),
links: parseEdges(getChildByTagName(graphRoot, 'edges'))
};
} | This is a parse of GEXF.
The spec of GEXF:
https://gephi.org/gexf/1.2draft/gexf-12draft-primer.pdf | parse ( xml ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/extension/dataTool.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/extension/dataTool.js | Apache-2.0 |
function quantile(ascArr, p) {
var H = (ascArr.length - 1) * p + 1;
var h = Math.floor(H);
var v = +ascArr[h - 1];
var e = H - h;
return e ? v + e * (ascArr[h] - v) : v;
} | 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 {Array.<number>} ascArr | quantile ( ascArr , p ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/extension/dataTool.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/extension/dataTool.js | Apache-2.0 |
var prepareBoxplotData = function (rawData, opt) {
opt = opt || [];
var boxData = [];
var outliers = [];
var axisData = [];
var boundIQR = opt.boundIQR;
var useExtreme = boundIQR === 'none' || boundIQR === 0;
for (var i = 0; i < rawData.length; i++) {
axisData.push(i + '');
var ascList = asc(rawData[i].slice());
var Q1 = quantile(ascList, 0.25);
var Q2 = quantile(ascList, 0.5);
var Q3 = quantile(ascList, 0.75);
var min = ascList[0];
var max = ascList[ascList.length - 1];
var bound = (boundIQR == null ? 1.5 : boundIQR) * (Q3 - Q1);
var low = useExtreme
? min
: Math.max(min, Q1 - bound);
var high = useExtreme
? max
: Math.min(max, Q3 + bound);
boxData.push([low, Q1, Q2, Q3, high]);
for (var j = 0; j < ascList.length; j++) {
var dataItem = ascList[j];
if (dataItem < low || dataItem > high) {
var outlier = [i, dataItem];
opt.layout === 'vertical' && outlier.reverse();
outliers.push(outlier);
}
}
}
return {
boxData: boxData,
outliers: outliers,
axisData: axisData
};
};
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var version = '1.0.0';
// For backward compatibility, where the namespace `dataTool` will
// be mounted on `echarts` is the extension `dataTool` is imported.
// But the old version of echarts do not have `dataTool` namespace,
// so check it before mounting.
if (echarts.dataTool) {
echarts.dataTool.version = version;
echarts.dataTool.gexf = gexf;
echarts.dataTool.prepareBoxplotData = prepareBoxplotData;
}
exports.version = version;
exports.gexf = gexf;
exports.prepareBoxplotData = prepareBoxplotData;
}))); | See:
<https://en.wikipedia.org/wiki/Box_plot#cite_note-frigge_hoaglin_iglewicz-2>
<http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/boxplot.stats.html>
Helper method for preparing data.
@param {Array.<number>} rawData like
[
[12,232,443], (raw data set for the first box)
[3843,5545,1232], (raw datat set for the second box)
...
]
@param {Object} [opt]
@param {(number|string)} [opt.boundIQR=1.5] Data less than min bound is outlier.
default 1.5, means Q1 - 1.5 * (Q3 - Q1).
If 'none'/0 passed, min bound will not be used.
@param {(number|string)} [opt.layout='horizontal']
Box plot layout, can be 'horizontal' or 'vertical'
@return {Object} {
boxData: Array.<Array.<number>>
outliers: Array.<Array.<number>>
axisData: Array.<string>
} | prepareBoxplotData ( rawData , opt ) | javascript | SuperMap/iClient-JavaScript | libs/echarts/extension/dataTool.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/echarts/extension/dataTool.js | Apache-2.0 |
Event.prototype.on = function (event, callback) {
var subscribers = this._subscribers[event];
if (!subscribers) {
subscribers = [];
this._subscribers[event] = subscribers;
}
subscribers.push({
callback: callback
});
}; | Subscribe to an event, add an event listener
@param {String} event Event name. Available events: 'put', 'update',
'remove'
@param {function} callback Callback method. Called with three parameters:
{String} event
{Object | null} params
{String | Number} senderId | Event.prototype.on ( event , callback ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.js | Apache-2.0 |
Event.prototype.off = function (event, callback) {
var subscribers = this._subscribers[event];
if (subscribers) {
//this._subscribers[event] = subscribers.filter(listener => listener.callback != callback);
for (var i = 0; i < subscribers.length; i++) {
if (subscribers[i].callback == callback) {
subscribers.splice(i, 1);
i--;
}
}
}
}; | Unsubscribe from an event, remove an event listener
@param {String} event
@param {function} callback | Event.prototype.off ( event , callback ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.js | Apache-2.0 |
Event.prototype._trigger = function (event, params, senderId) {
if (event == '*') {
throw new Error('Cannot trigger event *');
}
var subscribers = [];
if (event in this._subscribers) {
subscribers = subscribers.concat(this._subscribers[event]);
}
if ('*' in this._subscribers) {
subscribers = subscribers.concat(this._subscribers['*']);
}
for (var i = 0, len = subscribers.length; i < len; i++) {
var subscriber = subscribers[i];
if (subscriber.callback) {
subscriber.callback(event, params, senderId || null);
}
}
}; | Trigger an event
@param {String} event
@param {Object | null} params
@param {String} [senderId] Optional id of the sender.
@private | Event.prototype._trigger ( event , params , senderId ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.js | Apache-2.0 |
function DataSet(data, options) {
Event.bind(this)();
this._options = options || {};
this._data = []; // map with data indexed by id
// add initial data when provided
if (data) {
this.add(data);
}
} | DataSet
A data set can:
- add/remove/update data
- gives triggers upon changes in the data
- can import/export data in various data formats
@param {Array} [data] Optional array with initial data
the field geometry is like geojson, it can be:
{
"type": "Point",
"coordinates": [125.6, 10.1]
}
{
"type": "LineString",
"coordinates": [
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
]
}
{
"type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0] ]
]
}
@param {Object} [options] Available options: | DataSet ( data , options ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.js | Apache-2.0 |
function Intensity(options) {
options = options || {};
this.gradient = options.gradient || {
0.25: "rgba(0, 0, 255, 1)",
0.55: "rgba(0, 255, 0, 1)",
0.85: "rgba(255, 255, 0, 1)",
1.0: "rgba(255, 0, 0, 1)"
};
this.maxSize = options.maxSize || 35;
this.minSize = options.minSize || 0;
this.max = options.max || 100;
this.min = options.min || 0;
this.initPalette();
} | Category
@param {Object} [options] Available options:
{Object} gradient: { 0.25: "rgb(0,0,255)", 0.55: "rgb(0,255,0)", 0.85: "yellow", 1.0: "rgb(255,0,0)"} | Intensity ( options ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.js | Apache-2.0 |
Intensity.prototype.getSize = function (value) {
var size = 0;
var max = this.max;
var min = this.min;
var maxSize = this.maxSize;
var minSize = this.minSize;
if (value > max) {
value = max;
}
if (value < min) {
value = min;
}
if (max > min) {
size = minSize + (value - min) / (max - min) * (maxSize - minSize);
} else {
return maxSize;
}
return size;
}; | @param Number value
@param Number max of value
@param Number max of size
@param Object other options | Intensity.prototype.getSize ( value ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.js | Apache-2.0 |
function Category(splitList) {
this.splitList = splitList || {
other: 1
};
} | Category
@param {Object} splitList:
{
other: 1,
1: 2,
2: 3,
3: 4,
4: 5,
5: 6,
6: 7
} | Category ( splitList ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.js | Apache-2.0 |
function Choropleth(splitList) {
this.splitList = splitList || [{
start: 0,
value: 'red'
}];
} | Choropleth
@param {Object} splitList:
[
{
start: 0,
end: 2,
value: randomColor()
},{
start: 2,
end: 4,
value: randomColor()
},{
start: 4,
value: randomColor()
}
]; | Choropleth ( splitList ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.js | Apache-2.0 |
var MapHelper = function () {
function MapHelper(id, type, opt) {
classCallCheck(this, MapHelper);
if (!id || !type) {
console.warn('id 和 type 为必填项');
return false;
}
if (type == 'baidu') {
if (!BMap) {
console.warn('请先引入百度地图JS API');
return false;
}
} else {
console.warn('暂不支持你的地图类型');
}
this.type = type;
var center = opt && opt.center ? opt.center : [106.962497, 38.208726];
var zoom = opt && opt.zoom ? opt.zoom : 5;
var map = this.map = new BMap.Map(id, {
enableMapClick: false
});
map.centerAndZoom(new BMap.Point(center[0], center[1]), zoom);
map.enableScrollWheelZoom(true);
map.setMapStyle({
style: 'light'
});
}
createClass(MapHelper, [{
key: 'addLayer',
value: function addLayer(datas, options) {
if (this.type == 'baidu') {
return new mapv.baiduMapLayer(this.map, dataSet, options);
}
}
}, {
key: 'getMap',
value: function getMap() {
return this.map;
}
}]);
return MapHelper;
}(); | @author Mofei<http://www.zhuwenlong.com> | MapHelper ( ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.js | Apache-2.0 |
function CanvasLayer(options) {
this.options = options || {};
this.paneName = this.options.paneName || 'mapPane';
this.context = this.options.context || '2d';
this.zIndex = this.options.zIndex || 0;
this.mixBlendMode = this.options.mixBlendMode || null;
this.enableMassClear = this.options.enableMassClear;
this._map = options.map;
this._lastDrawTime = null;
this.show();
} | 一直覆盖在当前地图视野的Canvas对象
@author nikai (@胖嘟嘟的骨头, [email protected])
@param
{
map 地图实例对象
} | CanvasLayer ( options ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.js | Apache-2.0 |
var TWEEN = TWEEN || function () {
var _tweens = [];
return {
getAll: function getAll() {
return _tweens;
},
removeAll: function removeAll() {
_tweens = [];
},
add: function add(tween) {
_tweens.push(tween);
},
remove: function remove(tween) {
var i = _tweens.indexOf(tween);
if (i !== -1) {
_tweens.splice(i, 1);
}
},
update: function update(time, preserve) {
if (_tweens.length === 0) {
return false;
}
var i = 0;
time = time !== undefined ? time : TWEEN.now();
while (i < _tweens.length) {
if (_tweens[i].update(time) || preserve) {
i++;
} else {
_tweens.splice(i, 1);
}
}
return true;
}
};
}(); | Tween.js - Licensed under the MIT license
https://github.com/tweenjs/tween.js
----------------------------------------------
See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
Thank you all, you're awesome! | TWEEN ( ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.js | Apache-2.0 |
function getCurveByTwoPoints(obj1, obj2) {
if (!obj1 || !obj2) {
return null;
}
var B1 = function B1(x) {
return 1 - 2 * x + x * x;
};
var B2 = function B2(x) {
return 2 * x - 2 * x * x;
};
var B3 = function B3(x) {
return x * x;
};
var curveCoordinates = [];
var count = 40; // 曲线是由一些小的线段组成的,这个表示这个曲线所有到的折线的个数
var isFuture = false;
var t, h, h2, lat3, lng3, j, t2;
var LnArray = [];
var i = 0;
var inc = 0;
if (typeof obj2 == "undefined") {
if (typeof curveCoordinates != "undefined") {
curveCoordinates = [];
}
return;
}
var lat1 = parseFloat(obj1.lat);
var lat2 = parseFloat(obj2.lat);
var lng1 = parseFloat(obj1.lng);
var lng2 = parseFloat(obj2.lng);
// 计算曲线角度的方法
if (lng2 > lng1) {
if (parseFloat(lng2 - lng1) > 180) {
if (lng1 < 0) {
lng1 = parseFloat(180 + 180 + lng1);
}
}
}
if (lng1 > lng2) {
if (parseFloat(lng1 - lng2) > 180) {
if (lng2 < 0) {
lng2 = parseFloat(180 + 180 + lng2);
}
}
}
j = 0;
t2 = 0;
if (lat2 == lat1) {
t = 0;
h = lng1 - lng2;
} else if (lng2 == lng1) {
t = Math.PI / 2;
h = lat1 - lat2;
} else {
t = Math.atan((lat2 - lat1) / (lng2 - lng1));
h = (lat2 - lat1) / Math.sin(t);
}
if (t2 == 0) {
t2 = t + Math.PI / 5;
}
h2 = h / 2;
lng3 = h2 * Math.cos(t2) + lng1;
lat3 = h2 * Math.sin(t2) + lat1;
for (i = 0; i < count + 1; i++) {
curveCoordinates.push([lng1 * B1(inc) + lng3 * B2(inc) + lng2 * B3(inc), lat1 * B1(inc) + lat3 * B2(inc) + lat2 * B3(inc)]);
inc = inc + 1 / count;
}
return curveCoordinates;
} | 根据两点获取曲线坐标点数组
@param Point 起点
@param Point 终点 | getCurveByTwoPoints ( obj1 , obj2 ) | javascript | SuperMap/iClient-JavaScript | libs/mapv/mapv.3d.js | https://github.com/SuperMap/iClient-JavaScript/blob/master/libs/mapv/mapv.3d.js | Apache-2.0 |
grunt.registerTask('setVersion', function () {
grunt.config.set('version', grunt.config.get('pkg').version);
grunt.config.set('fileVersion', '');
}); | Sets out version to the version in package.json (defaults to NEXT) | (anonymous) ( ) | javascript | CreateJS/SoundJS | build/Gruntfile.js | https://github.com/CreateJS/SoundJS/blob/master/build/Gruntfile.js | MIT |
grunt.registerTask('build', function() {
grunt.config("buildArgs", this.args || []);
getBuildArgs();
grunt.task.run(["setVersion", "coreBuild", "updatebower", "copy:docsSite", "clearBuildArgs"]);
}); | Task for exporting a release build (version based on package.json) | (anonymous) ( ) | javascript | CreateJS/SoundJS | build/Gruntfile.js | https://github.com/CreateJS/SoundJS/blob/master/build/Gruntfile.js | MIT |
writeAPIMeta: function (cb) {
Y.log('Writing API Meta Data', 'info', 'builder');
var self = this;
this.renderAPIMeta(function (js) {
fs.writeFile(path.join(self.options.outdir, 'api.js'), js, Y.charset, cb);
});
},
/**
* Render the API meta and return the Javascript
* @method renderAPIMeta
* @param {Callback} cb The callback | Write the API meta data used for the AutoComplete widget
@method writeAPIMeta
@param {Callback} cb The callback to execute when complete
@async | (anonymous) ( id ) | javascript | CreateJS/SoundJS | build/updates/builder.js | https://github.com/CreateJS/SoundJS/blob/master/build/updates/builder.js | MIT |
compile: function (cb) {
var self = this;
var starttime = (new Date()).getTime();
Y.log('Compiling Templates', 'info', 'builder');
| Compiles the templates from the meta-data provided by DocParser
@method compile
@param {Callback} cb The callback to execute after it's completed | (anonymous) ( ) | javascript | CreateJS/SoundJS | build/updates/builder.js | https://github.com/CreateJS/SoundJS/blob/master/build/updates/builder.js | MIT |
function Loader(loadItem) {
this.AbstractLoader_constructor(loadItem, true, createjs.Types.SOUND);
/**
* A Media object used to determine if src exists and to get duration
* @property _media
* @type {Media}
* @protected
*/
this._media = null;
/**
* A time counter that triggers timeout if loading takes too long
* @property _loadTime
* @type {number}
* @protected
*/
this._loadTime = 0;
/**
* The frequency to fire the loading timer until duration can be retrieved
* @property _TIMER_FREQUENCY
* @type {number}
* @protected
*/
this._TIMER_FREQUENCY = 100;
}; | Loader provides a mechanism to preload Cordova audio content via PreloadJS or internally. Instances are returned to
the preloader, and the load method is called when the asset needs to be requested.
Currently files are assumed to be local and no loading actually takes place. This class exists to more easily support
the existing architecture.
@class CordovaAudioLoader
@param {String} loadItem The item to be loaded
@extends XHRRequest
@protected | Loader ( loadItem ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
p._mediaErrorHandler = function(error) {
this._media.release();
this._sendError();
}; | Fires if audio cannot seek, indicating that src does not exist.
@method _mediaErrorHandler
@param error
@protected | p._mediaErrorHandler ( error ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
p._getMediaDuration = function() {
this._result = this._media.getDuration() * 1000;
if (this._result < 0) {
this._loadTime += this._TIMER_FREQUENCY;
if (this._loadTime > this._item.loadTimeout) {
this.handleEvent({type:"timeout"});
} else {
setTimeout(createjs.proxy(this._getMediaDuration, this), this._TIMER_FREQUENCY);
}
} else {
this._media.release();
this._sendComplete();
}
}; | will attempt to get duration of audio until successful or time passes this._item.loadTimeout
@method _getMediaDuration
@protected | p._getMediaDuration ( ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
function CordovaAudioSoundInstance(src, startTime, duration, playbackResource) {
this.AbstractSoundInstance_constructor(src, startTime, duration, playbackResource);
// Public Properties
/**
* Sets the playAudioWhenScreenIsLocked property for play calls on iOS devices.
* @property playWhenScreenLocked
* @type {boolean}
*/
this.playWhenScreenLocked = null;
// Private Properties
/**
* Used to approximate the playback position by storing the number of milliseconds elapsed since
* 1 January 1970 00:00:00 UTC when playing
* Note that if js clock is out of sync with Media playback, this will become increasingly inaccurate.
* @property _playStartTime
* @type {Number}
* @protected
*/
this._playStartTime = null;
/**
* A TimeOut used to trigger the end and possible loop of audio sprites.
* @property _audioSpriteTimeout
* @type {null}
* @protected
*/
this._audioSpriteTimeout = null;
/**
* Boolean value that indicates if we are using an audioSprite
* @property _audioSprite
* @type {boolean}
* @protected
*/
this._audioSprite = false;
// Proxies, make removing listeners easier.
this._audioSpriteEndHandler = createjs.proxy(this._handleAudioSpriteComplete, this);
this._mediaPlayFinishedHandler = createjs.proxy(this._handleSoundComplete, this);
this._mediaErrorHandler = createjs.proxy(this._handleMediaError, this);
this._mediaProgressHandler = createjs.proxy(this._handleMediaProgress, this);
this._playbackResource = new Media(src, this._mediaPlayFinishedHandler, this._mediaErrorHandler, this._mediaProgressHandler);
if (duration) {
this._audioSprite = true;
} else {
this._setDurationFromSource();
}
} | CordovaAudioSoundInstance extends the base api of {{#crossLink "AbstractSoundInstance"}}{{/crossLink}} and is used by
{{#crossLink "CordovaAudioPlugin"}}{{/crossLink}}.
@param {String} src The path to and file name of the sound.
@param {Number} startTime Audio sprite property used to apply an offset, in milliseconds.
@param {Number} duration Audio sprite property used to set the time the clip plays for, in milliseconds.
@param {Object} playbackResource Any resource needed by plugin to support audio playback.
@class CordovaAudioSoundInstance
@extends AbstractSoundInstance
@constructor | CordovaAudioSoundInstance ( src , startTime , duration , playbackResource ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
p.setMasterVolume = function (value) {
this._updateVolume();
}; | Called by {{#crossLink "Sound"}}{{/crossLink}} when plugin does not handle master volume.
undoc'd because it is not meant to be used outside of Sound
#method setMasterVolume
@param value | p.setMasterVolume ( value ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
p.setMasterMute = function (isMuted) {
this._updateVolume();
}; | Called by {{#crossLink "Sound"}}{{/crossLink}} when plugin does not handle master mute.
undoc'd because it is not meant to be used outside of Sound
#method setMasterMute
@param value | p.setMasterMute ( isMuted ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
p.getCurrentPosition = function (mediaSuccess, mediaError) {
this._playbackResource.getCurrentPosition(mediaSuccess, mediaError);
}; | Maps to <a href="http://plugins.cordova.io/#/package/org.apache.cordova.media" target="_blank">Media.getCurrentPosition</a>,
which is curiously asynchronus and requires a callback.
@method getCurrentPosition
@param {Method} mediaSuccess The callback that is passed the current position in seconds.
@param {Method} [mediaError=null] (Optional) The callback to execute if an error occurs. | p.getCurrentPosition ( mediaSuccess , mediaError ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
p._handleMediaError = function(error) {
clearTimeout(this.delayTimeoutId); // clear timeout that plays delayed sound
this.playState = createjs.Sound.PLAY_FAILED;
this._sendEvent("failed");
}; | media object has failed and likely will never work
@method _handleMediaError
@param error
@private | p._handleMediaError ( error ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
p._updatePausePos = function (pos) {
this._position = pos * 1000 - this._startTime;
if(this._playStartTime) {
this._playStartTime = Date.now();
}
}; | Synchronizes the best guess position with the actual current position.
@method _updatePausePos
@param {Number} pos The current position in seconds
@private | p._updatePausePos ( pos ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
function CordovaAudioPlugin() {
this.AbstractPlugin_constructor();
this._capabilities = s._capabilities;
this._loaderClass = createjs.CordovaAudioLoader;
this._soundInstanceClass = createjs.CordovaAudioSoundInstance;
this._srcDurationHash = {};
} | Play sounds using Cordova Media plugin, which will work with a Cordova app and tools that utilize Cordova such as PhoneGap or Ionic.
This plugin is not used by default, and must be registered manually in {{#crossLink "Sound"}}{{/crossLink}}
using the {{#crossLink "Sound/registerPlugins"}}{{/crossLink}} method.
This plugin is recommended when building a Cordova based app, but is not required.
<b>NOTE the <a href="http://plugins.cordova.io/#/package/org.apache.cordova.media" target="_blank">Cordova Media plugin</a> is required</b>
cordova plugin add org.apache.cordova.media
<h4>Known Issues</h4>
<b>Audio Position</b>
<ul>Audio position is calculated asynchronusly by Media. The SoundJS solution to this problem is two-fold:
<li>Provide {{#crossLink "CordovaAudioSoundInstance/getCurrentPosition"}}{{/crossLink}} that maps directly to media.getCurrentPosition.</li>
<li>Provide a best guess position based on elapsed time since playback started, which is synchronized with actual position when the audio is paused or stopped.
Testing showed this to be fairly reliable within 200ms.</li></ul>
<b>Cordova Media Docs</b>
<ul><li>See the <a href="http://plugins.cordova.io/#/package/org.apache.cordova.media" target="_blank">Cordova Media Docs</a> for various known OS issues.</li></ul>
<br />
@class CordovaAudioPlugin
@extends AbstractPlugin
@constructor | CordovaAudioPlugin ( ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
s.isSupported = function () {
s._generateCapabilities();
return (s._capabilities != null);
}; | Determine if the plugin can be used in the current browser/OS. Note that HTML audio is available in most modern
browsers, but is disabled in iOS because of its limitations.
@method isSupported
@return {Boolean} If the plugin can be initialized.
@static | s.isSupported ( ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
s._generateCapabilities = function () {
if (s._capabilities != null || !(window.cordova || window.PhoneGap || window.phonegap) || !window.Media) {return;}
// OJR my best guess is that Cordova will have the same limits on playback that the audio tag has, but this could be wrong
var t = document.createElement("audio");
if (t.canPlayType == null) {return null;}
s._capabilities = {
panning:false,
volume:true,
tracks:-1
};
// determine which extensions our browser supports for this plugin by iterating through Sound.SUPPORTED_EXTENSIONS
var supportedExtensions = createjs.Sound.SUPPORTED_EXTENSIONS;
var extensionMap = createjs.Sound.EXTENSION_MAP;
for (var i = 0, l = supportedExtensions.length; i < l; i++) {
var ext = supportedExtensions[i];
var playType = extensionMap[ext] || ext;
s._capabilities[ext] = (t.canPlayType("audio/" + ext) != "no" && t.canPlayType("audio/" + ext) != "") || (t.canPlayType("audio/" + playType) != "no" && t.canPlayType("audio/" + playType) != "");
} // OJR another way to do this might be canPlayType:"m4a", codex: mp4
}; | Determine the capabilities of the plugin. Used internally. Please see the Sound API {{#crossLink "Sound/capabilities:property"}}{{/crossLink}}
method for an overview of plugin capabilities.
@method _generateCapabilities
@static
@private | s._generateCapabilities ( ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
p.getSrcDuration = function(src) {
return this._srcDurationHash[src];
}; | Get the duration for a src. Intended for internal use by CordovaAudioSoundInstance.
@method getSrcDuration
@param src
@returns {Number} The duration of the src or null if it does not exist | p.getSrcDuration ( src ) | javascript | CreateJS/SoundJS | lib/cordovaaudioplugin-NEXT.js | https://github.com/CreateJS/SoundJS/blob/master/lib/cordovaaudioplugin-NEXT.js | MIT |
createjs.extend = function(subclass, superclass) {
"use strict";
function o() { this.constructor = subclass; }
o.prototype = superclass.prototype;
return (subclass.prototype = new o());
}; | Sets up the prototype chain and constructor property for a new class.
This should be called right after creating the class constructor.
function MySubClass() {}
createjs.extend(MySubClass, MySuperClass);
MySubClass.prototype.doSomething = function() { }
var foo = new MySubClass();
console.log(foo instanceof MySuperClass); // true
console.log(foo.prototype.constructor === MySubClass); // true
@method extend
@param {Function} subclass The subclass.
@param {Function} superclass The superclass to extend.
@return {Function} Returns the subclass's new prototype. | createjs.extend ( subclass , superclass ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
createjs.promote = function(subclass, prefix) {
"use strict";
var subP = subclass.prototype, supP = (Object.getPrototypeOf&&Object.getPrototypeOf(subP))||subP.__proto__;
if (supP) {
subP[(prefix+="_") + "constructor"] = supP.constructor; // constructor is not always innumerable
for (var n in supP) {
if (subP.hasOwnProperty(n) && (typeof supP[n] == "function")) { subP[prefix + n] = supP[n]; }
}
}
return subclass;
}; | Promotes any methods on the super class that were overridden, by creating an alias in the format `prefix_methodName`.
It is recommended to use the super class's name as the prefix.
An alias to the super class's constructor is always added in the format `prefix_constructor`.
This allows the subclass to call super class methods without using `function.call`, providing better performance.
For example, if `MySubClass` extends `MySuperClass`, and both define a `draw` method, then calling `promote(MySubClass, "MySuperClass")`
would add a `MySuperClass_constructor` method to MySubClass and promote the `draw` method on `MySuperClass` to the
prototype of `MySubClass` as `MySuperClass_draw`.
This should be called after the class's prototype is fully defined.
function ClassA(name) {
this.name = name;
}
ClassA.prototype.greet = function() {
return "Hello "+this.name;
}
function ClassB(name, punctuation) {
this.ClassA_constructor(name);
this.punctuation = punctuation;
}
createjs.extend(ClassB, ClassA);
ClassB.prototype.greet = function() {
return this.ClassA_greet()+this.punctuation;
}
createjs.promote(ClassB, "ClassA");
var foo = new ClassB("World", "!?!");
console.log(foo.greet()); // Hello World!?!
@method promote
@param {Function} subclass The class to promote super class methods on.
@param {String} prefix The prefix to add to the promoted method names. Usually the name of the superclass.
@return {Function} Returns the subclass. | createjs.promote ( subclass , prefix ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
createjs.deprecate = function(fallbackMethod, name) {
"use strict";
return function() {
var msg = "Deprecated property or method '"+name+"'. See docs for info.";
console && (console.warn ? console.warn(msg) : console.log(msg));
return fallbackMethod && fallbackMethod.apply(this, arguments);
}
}; | Wraps deprecated methods so they still be used, but throw warnings to developers.
obj.deprecatedMethod = createjs.deprecate("Old Method Name", obj._fallbackMethod);
The recommended approach for deprecated properties is:
try {
Obj ect.defineProperties(object, {
readyOnlyProp: { get: createjs.deprecate("readOnlyProp", function() { return this.alternateProp; }) },
readWriteProp: {
get: createjs.deprecate("readOnlyProp", function() { return this.alternateProp; }),
set: createjs.deprecate("readOnlyProp", function(val) { this.alternateProp = val; })
});
} catch (e) {}
@method deprecate
@param {Function} [fallbackMethod=null] A method to call when the deprecated method is used. See the example for how
@param {String} [name=null] The name of the method or property to display in the console warning.
to deprecate properties.
@return {Function} If a fallbackMethod is supplied, returns a closure that will call the fallback method after
logging the warning in the console. | createjs.deprecate ( fallbackMethod , name ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
createjs.indexOf = function (array, searchElement){
"use strict";
for (var i = 0,l=array.length; i < l; i++) {
if (searchElement === array[i]) {
return i;
}
}
return -1;
}; | Finds the first occurrence of a specified value searchElement in the passed in array, and returns the index of
that value. Returns -1 if value is not found.
var i = createjs.indexOf(myArray, myElementToFind);
@method indexOf
@param {Array} array Array to search for searchElement
@param searchElement Element to find in array.
@return {Number} The first index of searchElement in array. | createjs.indexOf ( array , searchElement ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
createjs.proxy = function (method, scope) {
var aArgs = Array.prototype.slice.call(arguments, 2);
return function () {
return method.apply(scope, Array.prototype.slice.call(arguments, 0).concat(aArgs));
};
} | A function proxy for methods. By default, JavaScript methods do not maintain scope, so passing a method as a
callback will result in the method getting called in the scope of the caller. Using a proxy ensures that the
method gets called in the correct scope.
Additional arguments can be passed that will be applied to the function when it is called.
<h4>Example</h4>
myObject.addEventListener("event", createjs.proxy(myHandler, this, arg1, arg2));
function myHandler(arg1, arg2) {
// This gets called when myObject.myCallback is executed.
}
@method proxy
@param {Function} method The function to call
@param {Object} scope The scope to call the method name on
@param {mixed} [arg] * Arguments that are appended to the callback for additional params.
@public
@static | createjs.proxy ( method , scope ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
(function() {
"use strict";
/**
* A function proxy for methods. By default, JavaScript methods do not maintain scope, so passing a method as a
* callback will result in the method getting called in the scope of the caller. Using a proxy ensures that the
* method gets called in the correct scope.
*
* Additional arguments can be passed that will be applied to the function when it is called.
*
* <h4>Example</h4>
*
* myObject.addEventListener("event", createjs.proxy(myHandler, this, arg1, arg2));
*
* function myHandler(arg1, arg2) {
* // This gets called when myObject.myCallback is executed.
* }
*
* @method proxy
* @param {Function} method The function to call
* @param {Object} scope The scope to call the method name on
* @param {mixed} [arg] * Arguments that are appended to the callback for additional params.
* @public
* @static
*/
createjs.proxy = function (method, scope) {
var aArgs = Array.prototype.slice.call(arguments, 2);
return function () {
return method.apply(scope, Array.prototype.slice.call(arguments, 0).concat(aArgs));
};
}
}()); | Various utilities that the CreateJS Suite uses. Utilities are created as separate files, and will be available on the
createjs namespace directly.
<h4>Example</h4>
myObject.addEventListener("change", createjs.proxy(myMethod, scope));
@class Utility Methods
@main Utility Methods | (anonymous) ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function BrowserDetect() {
throw "BrowserDetect cannot be instantiated";
}; | An object that determines the current browser, version, operating system, and other environment
variables via user agent string.
Used for audio because feature detection is unable to detect the many limitations of mobile devices.
<h4>Example</h4>
if (createjs.BrowserDetect.isIOS) { // do stuff }
@property BrowserDetect
@type {Object}
@param {Boolean} isFirefox True if our browser is Firefox.
@param {Boolean} isOpera True if our browser is opera.
@param {Boolean} isChrome True if our browser is Chrome. Note that Chrome for Android returns true, but is a
completely different browser with different abilities.
@param {Boolean} isIOS True if our browser is safari for iOS devices (iPad, iPhone, and iPod).
@param {Boolean} isAndroid True if our browser is Android.
@param {Boolean} isBlackberry True if our browser is Blackberry.
@constructor
@static | BrowserDetect ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function EventDispatcher() {
// private properties:
/**
* @protected
* @property _listeners
* @type Object
**/
this._listeners = null;
/**
* @protected
* @property _captureListeners
* @type Object
**/
this._captureListeners = null;
} | EventDispatcher provides methods for managing queues of event listeners and dispatching events.
You can either extend EventDispatcher or mix its methods into an existing prototype or instance by using the
EventDispatcher {{#crossLink "EventDispatcher/initialize"}}{{/crossLink}} method.
Together with the CreateJS Event class, EventDispatcher provides an extended event model that is based on the
DOM Level 2 event model, including addEventListener, removeEventListener, and dispatchEvent. It supports
bubbling / capture, preventDefault, stopPropagation, stopImmediatePropagation, and handleEvent.
EventDispatcher also exposes a {{#crossLink "EventDispatcher/on"}}{{/crossLink}} method, which makes it easier
to create scoped listeners, listeners that only run once, and listeners with associated arbitrary data. The
{{#crossLink "EventDispatcher/off"}}{{/crossLink}} method is merely an alias to
{{#crossLink "EventDispatcher/removeEventListener"}}{{/crossLink}}.
Another addition to the DOM Level 2 model is the {{#crossLink "EventDispatcher/removeAllEventListeners"}}{{/crossLink}}
method, which can be used to listeners for all events, or listeners for a specific event. The Event object also
includes a {{#crossLink "Event/remove"}}{{/crossLink}} method which removes the active listener.
<h4>Example</h4>
Add EventDispatcher capabilities to the "MyClass" class.
EventDispatcher.initialize(MyClass.prototype);
Add an event (see {{#crossLink "EventDispatcher/addEventListener"}}{{/crossLink}}).
instance.addEventListener("eventName", handlerMethod);
function handlerMethod(event) {
console.log(event.target + " Was Clicked");
}
<b>Maintaining proper scope</b><br />
Scope (ie. "this") can be be a challenge with events. Using the {{#crossLink "EventDispatcher/on"}}{{/crossLink}}
method to subscribe to events simplifies this.
instance.addEventListener("click", function(event) {
console.log(instance == this); // false, scope is ambiguous.
});
instance.on("click", function(event) {
console.log(instance == this); // true, "on" uses dispatcher scope by default.
});
If you want to use addEventListener instead, you may want to use function.bind() or a similar proxy to manage
scope.
<b>Browser support</b>
The event model in CreateJS can be used separately from the suite in any project, however the inheritance model
requires modern browsers (IE9+).
@class EventDispatcher
@constructor
* | EventDispatcher ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
EventDispatcher.initialize = function(target) {
target.addEventListener = p.addEventListener;
target.on = p.on;
target.removeEventListener = target.off = p.removeEventListener;
target.removeAllEventListeners = p.removeAllEventListeners;
target.hasEventListener = p.hasEventListener;
target.dispatchEvent = p.dispatchEvent;
target._dispatchEvent = p._dispatchEvent;
target.willTrigger = p.willTrigger;
}; | Static initializer to mix EventDispatcher methods into a target object or prototype.
EventDispatcher.initialize(MyClass.prototype); // add to the prototype of the class
EventDispatcher.initialize(myObject); // add to a specific instance
@method initialize
@static
@param {Object} target The target object to inject EventDispatcher methods into. This can be an instance or a
prototype.
* | EventDispatcher.initialize ( target ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.addEventListener = function(type, listener, useCapture) {
var listeners;
if (useCapture) {
listeners = this._captureListeners = this._captureListeners||{};
} else {
listeners = this._listeners = this._listeners||{};
}
var arr = listeners[type];
if (arr) { this.removeEventListener(type, listener, useCapture); }
arr = listeners[type]; // remove may have deleted the array
if (!arr) { listeners[type] = [listener]; }
else { arr.push(listener); }
return listener;
}; | Adds the specified event listener. Note that adding multiple listeners to the same function will result in
multiple callbacks getting fired.
<h4>Example</h4>
displayObject.addEventListener("click", handleClick);
function handleClick(event) {
// Click happened.
}
@method addEventListener
@param {String} type The string type of the event.
@param {Function | Object} listener An object with a handleEvent method, or a function that will be called when
the event is dispatched.
@param {Boolean} [useCapture] For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.
@return {Function | Object} Returns the listener for chaining or assignment.
* | p.addEventListener ( type , listener , useCapture ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.on = function(type, listener, scope, once, data, useCapture) {
if (listener.handleEvent) {
scope = scope||listener;
listener = listener.handleEvent;
}
scope = scope||this;
return this.addEventListener(type, function(evt) {
listener.call(scope, evt, data);
once&&evt.remove();
}, useCapture);
}; | A shortcut method for using addEventListener that makes it easier to specify an execution scope, have a listener
only run once, associate arbitrary data with the listener, and remove the listener.
This method works by creating an anonymous wrapper function and subscribing it with addEventListener.
The wrapper function is returned for use with `removeEventListener` (or `off`).
<b>IMPORTANT:</b> To remove a listener added with `on`, you must pass in the returned wrapper function as the listener, or use
{{#crossLink "Event/remove"}}{{/crossLink}}. Likewise, each time you call `on` a NEW wrapper function is subscribed, so multiple calls
to `on` with the same params will create multiple listeners.
<h4>Example</h4>
var listener = myBtn.on("click", handleClick, null, false, {count:3});
function handleClick(evt, data) {
data.count -= 1;
console.log(this == myBtn); // true - scope defaults to the dispatcher
if (data.count == 0) {
alert("clicked 3 times!");
myBtn.off("click", listener);
// alternately: evt.remove();
}
}
@method on
@param {String} type The string type of the event.
@param {Function | Object} listener An object with a handleEvent method, or a function that will be called when
the event is dispatched.
@param {Object} [scope] The scope to execute the listener in. Defaults to the dispatcher/currentTarget for function listeners, and to the listener itself for object listeners (ie. using handleEvent).
@param {Boolean} [once=false] If true, the listener will remove itself after the first time it is triggered.
@param {*} [data] Arbitrary data that will be included as the second parameter when the listener is called.
@param {Boolean} [useCapture=false] For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.
@return {Function} Returns the anonymous function that was created and assigned as the listener. This is needed to remove the listener later using .removeEventListener.
* | p.on ( type , listener , scope , once , data , useCapture ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.