提交 fdecbddc 编写于 作者: E erik

little optimize

上级 f92127bc
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
* 高精度数学运算 * 高精度数学运算
*/ */
define(function() { define(function() {
//除法函数,用来得到精确的除法结果 // 除法函数,用来得到精确的除法结果
//说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。 // 说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
//调用:accDiv(arg1,arg2) // 调用:accDiv(arg1,arg2)
//返回值:arg1除以arg2的精确结果 // 返回值:arg1除以arg2的精确结果
function accDiv(arg1, arg2) { function accDiv(arg1, arg2) {
return accMul(arg1,1 / arg2); return accMul(arg1, 1 / arg2);
} }
//乘法函数,用来得到精确的乘法结果 // 乘法函数,用来得到精确的乘法结果
//说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。 // 说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
//调用:accMul(arg1,arg2) // 调用:accMul(arg1,arg2)
//返回值:arg1乘以arg2的精确结果 // 返回值:arg1乘以arg2的精确结果
function accMul(arg1, arg2) { function accMul(arg1, arg2) {
var m = 0; var m = 0;
var s1 = arg1.toString(); var s1 = arg1.toString();
...@@ -28,34 +28,28 @@ define(function() { ...@@ -28,34 +28,28 @@ define(function() {
} }
catch(e){} catch(e){}
return Number(s1.replace('.', '')) return (s1.replace('.', '') - 0) * (s2.replace('.', '') - 0) / Math.pow(10, m);
* Number(s2.replace('.', ''))
/ Math.pow(10, m);
} }
//加法函数,用来得到精确的加法结果 // 加法函数,用来得到精确的加法结果
//说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。 // 说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
//调用:accAdd(arg1,arg2) // 调用:accAdd(arg1,arg2)
//返回值:arg1加上arg2的精确结果 // 返回值:arg1加上arg2的精确结果
function accAdd(arg1,arg2) { function accAdd(arg1, arg2) {
var r1; var r1 = 0;
var r2; var r2 = 0;
var m;
try { try {
r1 = arg1.toString().split('.')[1].length; r1 = arg1.toString().split('.')[1].length;
} }
catch(e) { catch(e) {}
r1 = 0;
}
try { try {
r2=arg2.toString().split('.')[1].length; r2 = arg2.toString().split('.')[1].length;
}
catch(e) {
r2=0;
} }
catch(e) {}
m = Math.pow(10, Math.max(r1, r2)); var m = Math.pow(10, Math.max(r1, r2));
return (Math.round(arg1 * m) + Math.round(arg2 * m)) / m; return (Math.round(arg1 * m) + Math.round(arg2 * m)) / m;
} }
......
...@@ -18,45 +18,46 @@ define(function (require) { ...@@ -18,45 +18,46 @@ define(function (require) {
* @param {tring} easing * @param {tring} easing
*/ */
function pointList(zr, oldShape, newShape, duration, easing) { function pointList(zr, oldShape, newShape, duration, easing) {
var newPointList; var newPointList = newShape.style.pointList;
var newPointListLen = newPointList.length;
var oldPointList;
if (!oldShape) { // add if (!oldShape) { // add
newPointList = []; oldPointList = [];
var len = newShape.style.pointList.length;
if (newShape._orient != 'vertical') { if (newShape._orient != 'vertical') {
var y = newShape.style.pointList[0][1]; var y = newPointList[0][1];
for (var i = 0; i < len; i++) { for (var i = 0; i < newPointListLen; i++) {
newPointList[i] = [newShape.style.pointList[i][0], y]; oldPointList[i] = [newPointList[i][0], y];
} }
} }
else { else {
var x = newShape.style.pointList[0][0]; var x = newPointList[0][0];
for (var i = 0; i < len; i++) { for (var i = 0; i < newPointListLen; i++) {
newPointList[i] = [x, newShape.style.pointList[i][1]]; oldPointList[i] = [x, newPointList[i][1]];
} }
} }
if (newShape.type == 'half-smooth-polygon') { if (newShape.type == 'half-smooth-polygon') {
newPointList[len - 1] = zrUtil.clone(newShape.style.pointList[len - 1]); oldPointList[newPointListLen - 1] = zrUtil.clone(newPointList[newPointListLen - 1]);
newPointList[len - 2] = zrUtil.clone(newShape.style.pointList[len - 2]); oldPointList[newPointListLen - 2] = zrUtil.clone(newPointList[newPointListLen - 2]);
} }
oldShape = {style : {pointList : newPointList}}; oldShape = {style : {pointList : oldPointList}};
} }
newPointList = newShape.style.pointList; oldPointList = oldShape.style.pointList;
if (oldShape.style.pointList.length == newPointList.length) { var oldPointListLen = oldPointList.length;
newShape.style.pointList = oldShape.style.pointList; if (oldPointListLen == newPointListLen) {
newShape.style.pointList = oldPointList;
} }
else if (oldShape.style.pointList.length < newPointList.length) { else if (oldPointListLen < newPointListLen) {
// 原来短,新的长,补全 // 原来短,新的长,补全
newShape.style.pointList = oldShape.style.pointList.concat( newShape.style.pointList = oldPointList.concat(newPointList.slice(oldPointListLen));
newPointList.slice(oldShape.style.pointList.length)
);
} }
else { else {
// 原来长,新的短,截断 // 原来长,新的短,截断
newShape.style.pointList = oldShape.style.pointList.slice( newShape.style.pointList = oldPointList.slice(0, newPointListLen);
0, newPointList.length
);
} }
zr.addShape(newShape); zr.addShape(newShape);
zr.animate(newShape.id, 'style') zr.animate(newShape.id, 'style')
.when( .when(
...@@ -66,6 +67,22 @@ define(function (require) { ...@@ -66,6 +67,22 @@ define(function (require) {
.start(easing); .start(easing);
} }
/**
* 复制样式
*
* @inner
* @param {Object} target 目标对象
* @param {Object} source 源对象
* @param {...string} props 复制的属性列表
*/
function cloneStyle(target, source) {
var len = arguments.length;
for (var i = 2; i < len; i++) {
var prop = arguments[i];
target.style[prop] = source.style[prop];
}
}
/** /**
* 方型动画 * 方型动画
* *
...@@ -76,29 +93,31 @@ define(function (require) { ...@@ -76,29 +93,31 @@ define(function (require) {
* @param {tring} easing * @param {tring} easing
*/ */
function rectangle(zr, oldShape, newShape, duration, easing) { function rectangle(zr, oldShape, newShape, duration, easing) {
var newShapeStyle = newShape.style;
if (!oldShape) { // add if (!oldShape) { // add
oldShape = { oldShape = {
style : { style : {
x : newShape.style.x, x : newShapeStyle.x,
y : newShape._orient == 'vertical' y : newShape._orient == 'vertical'
? newShape.style.y + newShape.style.height ? newShapeStyle.y + newShapeStyle.height
: newShape.style.y, : newShapeStyle.y,
width: newShape._orient == 'vertical' width: newShape._orient == 'vertical'
? newShape.style.width : 0, ? newShapeStyle.width : 0,
height: newShape._orient != 'vertical' height: newShape._orient != 'vertical'
? newShape.style.height : 0 ? newShapeStyle.height : 0
} }
}; };
} }
var newX = newShape.style.x; var newX = newShapeStyle.x;
var newY = newShape.style.y; var newY = newShapeStyle.y;
var newWidth = newShape.style.width; var newWidth = newShapeStyle.width;
var newHeight = newShape.style.height; var newHeight = newShapeStyle.height;
newShape.style.x = oldShape.style.x; cloneStyle(
newShape.style.y = oldShape.style.y; newShape, oldShape,
newShape.style.width = oldShape.style.width; 'x', 'y', 'width', 'height'
newShape.style.height = oldShape.style.height; );
zr.addShape(newShape); zr.addShape(newShape);
zr.animate(newShape.id, 'style') zr.animate(newShape.id, 'style')
.when( .when(
...@@ -218,8 +237,10 @@ define(function (require) { ...@@ -218,8 +237,10 @@ define(function (require) {
var startAngle = newShape.style.startAngle; var startAngle = newShape.style.startAngle;
var endAngle = newShape.style.endAngle; var endAngle = newShape.style.endAngle;
newShape.style.startAngle = oldShape.style.startAngle; cloneStyle(
newShape.style.endAngle = oldShape.style.endAngle; newShape, oldShape,
'startAngle', 'endAngle'
);
zr.addShape(newShape); zr.addShape(newShape);
zr.animate(newShape.id, 'style') zr.animate(newShape.id, 'style')
...@@ -257,8 +278,10 @@ define(function (require) { ...@@ -257,8 +278,10 @@ define(function (require) {
var x = newShape.style.x; var x = newShape.style.x;
var y = newShape.style.y; var y = newShape.style.y;
newShape.style.x = oldShape.style.x; cloneStyle(
newShape.style.y = oldShape.style.y; newShape, oldShape,
'x', 'y'
);
zr.addShape(newShape); zr.addShape(newShape);
zr.animate(newShape.id, 'style') zr.animate(newShape.id, 'style')
...@@ -325,10 +348,10 @@ define(function (require) { ...@@ -325,10 +348,10 @@ define(function (require) {
var target1 = newShape.style.target1; var target1 = newShape.style.target1;
if (oldShape.style) { if (oldShape.style) {
newShape.style.source0 = oldShape.style.source0; cloneStyle(
newShape.style.source1 = oldShape.style.source1; newShape, oldShape,
newShape.style.target0 = oldShape.style.target0; 'source0', 'source1', 'target0', 'target1'
newShape.style.target1 = oldShape.style.target1; );
} }
zr.addShape(newShape); zr.addShape(newShape);
...@@ -391,6 +414,7 @@ define(function (require) { ...@@ -391,6 +414,7 @@ define(function (require) {
newShape.style._y = newShape.style.y; newShape.style._y = newShape.style.y;
newShape.style._width = newShape.style.width; newShape.style._width = newShape.style.width;
newShape.style._height = newShape.style.height; newShape.style._height = newShape.style.height;
if (!oldShape) { // add if (!oldShape) { // add
var x = newShape._x || 0; var x = newShape._x || 0;
var y = newShape._y || 0; var y = newShape._y || 0;
...@@ -431,10 +455,12 @@ define(function (require) { ...@@ -431,10 +455,12 @@ define(function (require) {
var xEnd = newShape.style.xEnd; var xEnd = newShape.style.xEnd;
var yStart = newShape.style.yStart; var yStart = newShape.style.yStart;
var yEnd = newShape.style.yEnd; var yEnd = newShape.style.yEnd;
newShape.style.xStart = oldShape.style.xStart;
newShape.style.xEnd = oldShape.style.xEnd; cloneStyle(
newShape.style.yStart = oldShape.style.yStart; newShape, oldShape,
newShape.style.yEnd = oldShape.style.yEnd; 'xStart', 'xEnd', 'yStart', 'yEnd'
);
zr.addShape(newShape); zr.addShape(newShape);
zr.animate(newShape.id, 'style') zr.animate(newShape.id, 'style')
.when( .when(
......
...@@ -22,12 +22,9 @@ define(function() { ...@@ -22,12 +22,9 @@ define(function() {
) { ) {
var value; var value;
if (typeof data != 'undefined') { if (typeof data != 'undefined') {
if (typeof data.value != 'undefined') { value = data.value == null
value = data.value; ? data
} : data.value;
else {
value = data;
}
} }
shape._echartsData = { shape._echartsData = {
...@@ -56,21 +53,14 @@ define(function() { ...@@ -56,21 +53,14 @@ define(function() {
switch (key) { switch (key) {
case 'series' : case 'series' :
return data && data._series;
case 'seriesIndex' : case 'seriesIndex' :
return data && data._seriesIndex;
case 'data' : case 'data' :
return data && data._data;
case 'dataIndex' : case 'dataIndex' :
return data && data._dataIndex;
case 'name' : case 'name' :
return data && data._name;
case 'value' : case 'value' :
return data && data._value;
case 'special' : case 'special' :
return data && data._special;
case 'special2' : case 'special2' :
return data && data._special2; return data && data['_' + key];
} }
return null; return null;
...@@ -86,28 +76,14 @@ define(function() { ...@@ -86,28 +76,14 @@ define(function() {
shape._echartsData = shape._echartsData || {}; shape._echartsData = shape._echartsData || {};
switch (key) { switch (key) {
case 'series' : // 当前系列值 case 'series' : // 当前系列值
shape._echartsData._series = value;
break;
case 'seriesIndex' : // 系列数组位置索引 case 'seriesIndex' : // 系列数组位置索引
shape._echartsData._seriesIndex = value;
break;
case 'data' : // 当前数据值 case 'data' : // 当前数据值
shape._echartsData._data = value;
break;
case 'dataIndex' : // 数据数组位置索引 case 'dataIndex' : // 数据数组位置索引
shape._echartsData._dataIndex = value;
break;
case 'name' : case 'name' :
shape._echartsData._name = value;
break;
case 'value' : case 'value' :
shape._echartsData._value = value;
break;
case 'special' : case 'special' :
shape._echartsData._special = value;
break;
case 'special2' : case 'special2' :
shape._echartsData._special2 = value; shape._echartsData['_' + key] = value;
break; break;
} }
} }
......
...@@ -14,22 +14,24 @@ define(function() { ...@@ -14,22 +14,24 @@ define(function() {
*/ */
function query(optionTarget, optionLocation) { function query(optionTarget, optionLocation) {
if (typeof optionTarget == 'undefined') { if (typeof optionTarget == 'undefined') {
return undefined; return;
} }
if (!optionLocation) { if (!optionLocation) {
return optionTarget; return optionTarget;
} }
optionLocation = optionLocation.split('.');
optionLocation = optionLocation.split('.');
var length = optionLocation.length; var length = optionLocation.length;
var curIdx = 0; var curIdx = 0;
while (curIdx < length) { while (curIdx < length) {
optionTarget = optionTarget[optionLocation[curIdx]]; optionTarget = optionTarget[optionLocation[curIdx]];
if (typeof optionTarget == 'undefined') { if (typeof optionTarget == 'undefined') {
return undefined; return;
} }
curIdx++; curIdx++;
} }
return optionTarget; return optionTarget;
} }
...@@ -45,7 +47,6 @@ define(function() { ...@@ -45,7 +47,6 @@ define(function() {
return finalOption; return finalOption;
} }
} }
return undefined;
} }
/** /**
...@@ -54,10 +55,9 @@ define(function() { ...@@ -54,10 +55,9 @@ define(function() {
*/ */
function deepMerge(ctrList, optionLocation) { function deepMerge(ctrList, optionLocation) {
var finalOption; var finalOption;
var tempOption;
var len = ctrList.length; var len = ctrList.length;
while (len--) { while (len--) {
tempOption = query(ctrList[len], optionLocation); var tempOption = query(ctrList[len], optionLocation);
if (typeof tempOption != 'undefined') { if (typeof tempOption != 'undefined') {
if (typeof finalOption == 'undefined') { if (typeof finalOption == 'undefined') {
finalOption = zrUtil.clone(tempOption); finalOption = zrUtil.clone(tempOption);
...@@ -69,6 +69,7 @@ define(function() { ...@@ -69,6 +69,7 @@ define(function() {
} }
} }
} }
return finalOption; return finalOption;
} }
......
...@@ -23,7 +23,8 @@ define(function (){ ...@@ -23,7 +23,8 @@ define(function (){
// Check the existance of the kwargs // Check the existance of the kwargs
if (kwargs && kwargs.constructor === Object) { if (kwargs && kwargs.constructor === Object) {
args.pop(); args.pop();
}else{ }
else{
kwargs = {}; kwargs = {};
} }
...@@ -32,7 +33,8 @@ define(function (){ ...@@ -32,7 +33,8 @@ define(function (){
var name = names[i]; var name = names[i];
if (name in kwargs) { if (name in kwargs) {
args[i] = kwargs[name]; args[i] = kwargs[name];
}else if(name in defaults && args[i] === undefined){ }
else if(name in defaults && args[i] == null){
args[i] = defaults[name]; args[i] = defaults[name];
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册