提交 fdecbddc 编写于 作者: E erik

little optimize

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