提交 445d720b 编写于 作者: K kener

代码优化

上级 fc0259da
......@@ -28,13 +28,13 @@ define(function (require) {
* @param {Object} series 数据
* @param {Object} component 组件
*/
function Bar(ecTheme, messageCenter, zr, option, component){
function Bar(ecTheme, messageCenter, zr, option, myChart){
// 基类
ComponentBase.call(this, ecTheme, zr, option);
ComponentBase.call(this, ecTheme, messageCenter, zr, option, myChart);
// 可计算特性装饰
CalculableBase.call(this);
this.init(option, component);
this.refresh(option);
}
Bar.prototype = {
......@@ -122,9 +122,9 @@ define(function (require) {
_mapData : function (seriesArray) {
var series = this.series;
var serie; // 临时映射变量
var dataIndex = 0; // 堆数据所在位置映射
var stackMap = {}; // 堆叠数据位置映射,堆叠组在二维中的第几项
var magicStackKey = '__kener__stack__'; // 堆叠命名,非堆叠数据安单一堆叠处理
var dataIndex = 0; // 堆数据所在位置映射
var stackMap = {}; // 堆积数据位置映射,堆积组在二维中的第几项
var magicStackKey = '__kener__stack__'; // 堆积命名,非堆积数据安单一堆积处理
var stackKey; // 临时映射变量
var serieName; // 临时映射变量
var legend = this.component.legend;
......@@ -228,9 +228,9 @@ define(function (require) {
var xMarkMap = {}; // 为标注记录一些参数
var x;
var y;
var lastYP; // 正向堆处理
var lastYP; // 正向堆处理
var baseYP;
var lastYN; // 负向堆处理
var lastYN; // 负向堆处理
var baseYN;
var barShape;
var data;
......@@ -242,7 +242,7 @@ define(function (require) {
}
x = categoryAxis.getCoordByIndex(i) - gap / 2;
for (var j = 0, k = locationMap.length; j < k; j++) {
// 堆数据用第一条valueAxis
// 堆数据用第一条valueAxis
yAxisIndex = series[locationMap[j][0]].yAxisIndex || 0;
valueAxis = this.component.yAxis.getAxis(yAxisIndex);
baseYP = lastYP = baseYN = lastYN = valueAxis.getCoord(0);
......@@ -269,12 +269,12 @@ define(function (require) {
}
//y = valueAxis.getCoord(value);
if (value > 0) {
// 正向堆
// 正向堆
//barHeight = baseYP - y;
barHeight = m > 0
? valueAxis.getCoordSize(value)
: (baseYP - valueAxis.getCoord(value));
// 非堆数据最小高度有效
// 非堆数据最小高度有效
if (n == 1
&& barMinHeightMap[seriesIndex] > barHeight
) {
......@@ -284,12 +284,12 @@ define(function (require) {
y = lastYP;
}
else if (value < 0){
// 负向堆
// 负向堆
//barHeight = y - baseYN;
barHeight = m > 0
? valueAxis.getCoordSize(value)
: (valueAxis.getCoord(value) - baseYN);
// 非堆数据最小高度有效
// 非堆数据最小高度有效
if (n == 1
&& barMinHeightMap[seriesIndex] > barHeight
) {
......@@ -434,9 +434,9 @@ define(function (require) {
var xMarkMap = {}; // 为标注记录一个横向偏移
var x;
var y;
var lastXP; // 正向堆处理
var lastXP; // 正向堆处理
var baseXP;
var lastXN; // 负向堆处理
var lastXN; // 负向堆处理
var baseXN;
var barShape;
var data;
......@@ -448,7 +448,7 @@ define(function (require) {
}
y = categoryAxis.getCoordByIndex(i) + gap / 2;
for (var j = 0, k = locationMap.length; j < k; j++) {
// 堆数据用第一条valueAxis
// 堆数据用第一条valueAxis
xAxisIndex = series[locationMap[j][0]].xAxisIndex || 0;
valueAxis = this.component.xAxis.getAxis(xAxisIndex);
baseXP = lastXP = baseXN = lastXN = valueAxis.getCoord(0);
......@@ -475,12 +475,12 @@ define(function (require) {
}
//x = valueAxis.getCoord(value);
if (value > 0) {
// 正向堆
// 正向堆
//barHeight = x - baseXP;
barHeight = m > 0
? valueAxis.getCoordSize(value)
: (valueAxis.getCoord(value) - baseXP);
// 非堆数据最小高度有效
// 非堆数据最小高度有效
if (n == 1
&& barMinHeightMap[seriesIndex] > barHeight
) {
......@@ -490,12 +490,12 @@ define(function (require) {
lastXP += barHeight;
}
else if (value < 0){
// 负向堆
// 负向堆
//barHeight = baseXN - x;
barHeight = m > 0
? valueAxis.getCoordSize(value)
: (baseXN - valueAxis.getCoord(value));
// 非堆数据最小高度有效
// 非堆数据最小高度有效
if (n == 1
&& barMinHeightMap[seriesIndex] > barHeight
) {
......@@ -636,7 +636,7 @@ define(function (require) {
var interval = 1;
for (var j = 0, k = locationMap.length; j < k; j++) {
hasFound = false; // 同一堆第一个barWidth生效
hasFound = false; // 同一堆第一个barWidth生效
for (var m = 0, n = locationMap[j].length; m < n; m++) {
seriesIndex = locationMap[j][m];
queryTarget = series[seriesIndex];
......@@ -647,12 +647,12 @@ define(function (require) {
'barWidth'
);
if (typeof sBarWidth != 'undefined') {
// 同一堆第一个生效barWidth
// 同一堆第一个生效barWidth
barWidthMap[seriesIndex] = sBarWidth;
sBarWidthTotal += sBarWidth;
sBarWidthCounter++;
hasFound = true;
// 复位前面同一堆但没被定义的
// 复位前面同一堆但没被定义的
for (var ii = 0, ll = m; ii < ll; ii++) {
var pSeriesIndex = locationMap[j][ii];
barWidthMap[pSeriesIndex] = sBarWidth;
......@@ -917,17 +917,6 @@ define(function (require) {
return pos;
},
/**
* 构造函数默认执行的初始化方法,也用于创建实例后动态修改
* @param {Object} newSeries
* @param {Object} newComponent
*/
init : function (newOption, newComponent) {
this.component = newComponent || this.component;
this.refresh(newOption);
},
/**
* 刷新
*/
......
......@@ -317,13 +317,13 @@ define(function (require) {
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 + i];
newPointList[i] = [newShape.style.pointList[i][0], y];
};
}
else {
var x = newShape.style.pointList[0][0];
for (var i = 0; i < len; i++) {
newPointList[i] = [x + i, newShape.style.pointList[i][1]];
newPointList[i] = [x, newShape.style.pointList[i][1]];
};
}
if (newShape.type == 'half-smooth-polygon') {
......
......@@ -25,11 +25,13 @@ define(function (require) {
var _devicePixelRatio = window.devicePixelRatio || 1;
function Chord(ecTheme, messageCenter, zr, option, component) {
ComponentBase.call(this, ecTheme, zr, option);
function Chord(ecTheme, messageCenter, zr, option, myChart) {
// 基类
ComponentBase.call(this, ecTheme, messageCenter, zr, option, myChart);
// 可计算特性装饰
CalculableBase.call(this);
this.init(option, component);
this.refresh(option);
}
Chord.prototype = {
......@@ -636,12 +638,6 @@ define(function (require) {
return [result, unitPostfix];
},
init : function (newOption, newComponent) {
this.component = newComponent;
this.refresh(newOption);
},
refresh : function (newOption) {
if (newOption) {
this.option = newOption;
......
......@@ -41,12 +41,13 @@ define(function (require) {
* @param {Object} series 数据
* @param {Object} component 组件
*/
function Force(ecTheme, messageCenter, zr, option, component) {
function Force(ecTheme, messageCenter, zr, option, myChart) {
// 基类
ComponentBase.call(this, ecTheme, zr, option);
ComponentBase.call(this, ecTheme, messageCenter, zr, option, myChart);
// 可计算特性装饰
CalculableBase.call(this);
var component = myChart.component;
var legend;
var self = this;
self.type = ecConfig.CHART_TYPE_FORCE;
......
......@@ -23,9 +23,9 @@ define(function (require) {
* @param {ZRender} zr zrender实例
* @param {Object} option 图表选项
*/
function Island(ecTheme, messageCenter, zr) {
function Island(ecTheme, messageCenter, zr, option, myChart) {
// 基类
ComponentBase.call(this, ecTheme, zr, {});
ComponentBase.call(this, ecTheme, messageCenter, zr, {}, myChart);
// 可计算特性装饰
CalculableBase.call(this);
......
......@@ -27,13 +27,13 @@ define(function (require) {
* @param {Object} series 数据
* @param {Object} component 组件
*/
function K(ecTheme, messageCenter, zr, option, component){
function K(ecTheme, messageCenter, zr, option, myChart){
// 基类
ComponentBase.call(this, ecTheme, zr, option);
ComponentBase.call(this, ecTheme, messageCenter, zr, option, myChart);
// 可计算特性装饰
CalculableBase.call(this);
this.init(option, component);
this.refresh(option);
}
K.prototype = {
......@@ -437,17 +437,6 @@ define(function (require) {
];
},
/**
* 构造函数默认执行的初始化方法,也用于创建实例后动态修改
* @param {Object} newSeries
* @param {Object} newComponent
*/
init : function (newOption, newComponent) {
this.component = newComponent || this.component;
this.refresh(newOption);
},
/**
* 刷新
*/
......@@ -456,7 +445,7 @@ define(function (require) {
this.option = newOption;
this.series = newOption.series;
}
// this.clear();
this.backupShapeList();
this._buildShape();
},
......
......@@ -30,13 +30,13 @@ define(function (require) {
* @param {Object} series 数据
* @param {Object} component 组件
*/
function Line(ecTheme, messageCenter, zr, option, component){
function Line(ecTheme, messageCenter, zr, option, myChart){
// 基类
ComponentBase.call(this, ecTheme, zr, option);
ComponentBase.call(this, ecTheme, messageCenter, zr, option, myChart);
// 可计算特性装饰
CalculableBase.call(this);
this.init(option, component);
this.refresh(option);
}
Line.prototype = {
......@@ -48,7 +48,7 @@ define(function (require) {
var series = this.series;
this.finalPLMap = {}; // 完成的point list(PL)
this._sIndex2ColorMap = {}; // series默认颜色索引,seriesIndex索引到color
this._symbol = this.ecTheme.symbolList;
this._symbol = this.option.symbolList;
this._sIndex2ShapeMap = {}; // series拐点图形类型,seriesIndex索引到shape type
this.selectedMap = {};
......@@ -137,9 +137,9 @@ define(function (require) {
_mapData : function (seriesArray) {
var series = this.series;
var serie; // 临时映射变量
var dataIndex = 0; // 堆数据所在位置映射
var stackMap = {}; // 堆叠数据位置映射,堆叠组在二维中的第几项
var magicStackKey = '__kener__stack__'; // 堆叠命名,非堆叠数据安单一堆叠处理
var dataIndex = 0; // 堆数据所在位置映射
var stackMap = {}; // 堆积数据位置映射,堆积组在二维中的第几项
var magicStackKey = '__kener__stack__'; // 堆积命名,非堆积数据安单一堆积处理
var stackKey; // 临时映射变量
var serieName; // 临时映射变量
var legend = this.component.legend;
......@@ -232,9 +232,9 @@ define(function (require) {
var x;
var y;
var lastYP; // 正向堆处理
var lastYP; // 正向堆处理
var baseYP;
var lastYN; // 负向堆处理
var lastYN; // 负向堆处理
var baseYN;
//var this.finalPLMap = {}; // 完成的point list(PL)
var curPLMap = {}; // 正在记录的point list(PL)
......@@ -247,7 +247,7 @@ define(function (require) {
}
x = categoryAxis.getCoordByIndex(i);
for (var j = 0, k = locationMap.length; j < k; j++) {
// 堆数据用第一条valueAxis
// 堆数据用第一条valueAxis
yAxisIndex = series[locationMap[j][0]].yAxisIndex || 0;
valueAxis = this.component.yAxis.getAxis(yAxisIndex);
baseYP = lastYP = baseYN = lastYN = valueAxis.getCoord(0);
......@@ -285,14 +285,14 @@ define(function (require) {
}
//y = valueAxis.getCoord(value);
if (value >= 0) {
// 正向堆
// 正向堆
lastYP -= m > 0
? valueAxis.getCoordSize(value)
: (baseYP - valueAxis.getCoord(value));
y = lastYP;
}
else if (value < 0){
// 负向堆
// 负向堆
lastYN += m > 0
? valueAxis.getCoordSize(value)
: (valueAxis.getCoord(value) - baseYN);
......@@ -405,9 +405,9 @@ define(function (require) {
var x;
var y;
var lastXP; // 正向堆处理
var lastXP; // 正向堆处理
var baseXP;
var lastXN; // 负向堆处理
var lastXN; // 负向堆处理
var baseXN;
//var this.finalPLMap = {}; // 完成的point list(PL)
var curPLMap = {}; // 正在记录的point list(PL)
......@@ -420,7 +420,7 @@ define(function (require) {
}
y = categoryAxis.getCoordByIndex(i);
for (var j = 0, k = locationMap.length; j < k; j++) {
// 堆数据用第一条valueAxis
// 堆数据用第一条valueAxis
xAxisIndex = series[locationMap[j][0]].xAxisIndex || 0;
valueAxis = this.component.xAxis.getAxis(xAxisIndex);
baseXP = lastXP = baseXN = lastXN = valueAxis.getCoord(0);
......@@ -458,14 +458,14 @@ define(function (require) {
}
//x = valueAxis.getCoord(value);
if (value >= 0) {
// 正向堆
// 正向堆
lastXP += m > 0
? valueAxis.getCoordSize(value)
: (valueAxis.getCoord(value) - baseXP);
x = lastXP;
}
else if (value < 0){
// 负向堆
// 负向堆
lastXN -= m > 0
? valueAxis.getCoordSize(value)
: (baseXN - valueAxis.getCoord(value));
......@@ -590,7 +590,7 @@ define(function (require) {
var isLarge;
// 堆层叠需求,反顺序构建
// 堆层叠需求,反顺序构建
var seriesIndex;
for (var sIdx = seriesArray.length - 1; sIdx >= 0; sIdx--) {
seriesIndex = seriesArray[sIdx];
......@@ -863,17 +863,6 @@ define(function (require) {
];
},
/**
* 构造函数默认执行的初始化方法,也用于创建实例后动态修改
* @param {Object} newSeries
* @param {Object} newComponent
*/
init : function (newOption, newComponent) {
this.component = newComponent || this.component;
this.refresh(newOption);
},
/**
* 刷新
*/
......@@ -882,6 +871,7 @@ define(function (require) {
this.option = newOption;
this.series = newOption.series;
}
this.backupShapeList();
this._buildShape();
},
......
......@@ -33,14 +33,12 @@ define(function (require) {
* @param {Object} series 数据
* @param {Object} component 组件
*/
function Map(ecTheme, messageCenter, zr, option, component){
function Map(ecTheme, messageCenter, zr, option, myChart){
// 基类
ComponentBase.call(this, ecTheme, zr, option);
ComponentBase.call(this, ecTheme, messageCenter, zr, option, myChart);
// 可计算特性装饰
CalculableBase.call(this);
this.messageCenter = messageCenter;
var self = this;
self._onmousewheel = function(param){
return self.__onmousewheel(param);
......@@ -55,7 +53,33 @@ define(function (require) {
return self.__onmouseup(param);
};
this.init(option, component);
this._isAlive = true; // 活着标记
this._selectedMode = {}; // 选择模式
this._hoverable = {}; // 悬浮高亮模式,索引到图表
this._showLegendSymbol = {}; // 显示图例颜色标识
this._selected = {}; // 地图选择状态
this._mapTypeMap = {}; // 图例类型索引
this._mapDataMap = {}; // 根据地图类型索引bbox,transform,path
this._nameMap = {}; // 个性化地名
this._specialArea = {}; // 特殊
this._refreshDelayTicket; // 滚轮缩放时让refresh飞一会
this._mapDataRequireCounter; // 异步回调计数器
this._markAnimation = false;
// 漫游相关信息
this._roamMap = {};
this._needRoam;
this._mx;
this._my;
this._mousedown;
this._justMove; // 避免移动响应点击
this._curMapType; // 当前移动的地图类型
this.refresh(option);
if (this._needRoam) {
this.zr.on(zrConfig.EVENT.MOUSEWHEEL, this._onmousewheel);
this.zr.on(zrConfig.EVENT.MOUSEDOWN, this._onmousedown);
}
}
Map.prototype = {
......@@ -1145,46 +1169,6 @@ define(function (require) {
this.zr.refresh();
},
/**
* 构造函数默认执行的初始化方法,也用于创建实例后动态修改
* @param {Object} newSeries
* @param {Object} newComponent
*/
init : function (newOption, newComponent) {
this.component = newComponent;
this._isAlive = true; // 活着标记
this._selectedMode = {}; // 选择模式
this._hoverable = {}; // 悬浮高亮模式,索引到图表
this._showLegendSymbol = {}; // 显示图例颜色标识
this._selected = {}; // 地图选择状态
this._mapTypeMap = {}; // 图例类型索引
this._mapDataMap = {}; // 根据地图类型索引bbox,transform,path
this._nameMap = {}; // 个性化地名
this._specialArea = {}; // 特殊
this._refreshDelayTicket; // 滚轮缩放时让refresh飞一会
this._mapDataRequireCounter;
// 漫游相关信息
this._roamMap = {};
this._needRoam;
this._mx;
this._my;
this._mousedown;
this._justMove; // 避免移动响应点击
this._curMapType; // 当前移动的地图类型
this._markAnimation = false;
this.refresh(newOption);
if (this._needRoam) {
this.zr.on(zrConfig.EVENT.MOUSEWHEEL, this._onmousewheel);
this.zr.on(zrConfig.EVENT.MOUSEDOWN, this._onmousedown);
}
},
/**
* 刷新
*/
......@@ -1193,6 +1177,7 @@ define(function (require) {
this.option = newOption;
this.series = newOption.series;
}
this.clear();
this._buildShape();
this.zr.refreshHover();
......
......@@ -29,14 +29,12 @@ define(function (require) {
* @param {Object} series 数据
* @param {Object} component 组件
*/
function Pie(ecTheme, messageCenter, zr, option, component){
function Pie(ecTheme, messageCenter, zr, option, myChart){
// 基类
ComponentBase.call(this, ecTheme, zr, option);
ComponentBase.call(this, ecTheme, messageCenter, zr, option, myChart);
// 可计算特性装饰
CalculableBase.call(this);
this.messageCenter = messageCenter;
var self = this;
/**
* 输出动态视觉引导线
......@@ -74,7 +72,7 @@ define(function (require) {
}
};
this.init(option, component);
this.refresh(option);
}
Pie.prototype = {
......@@ -704,17 +702,6 @@ define(function (require) {
return opt;
},
/**
* 构造函数默认执行的初始化方法,也用于创建实例后动态修改
* @param {Object} newSeries
* @param {Object} newComponent
*/
init : function (newOption, newComponent) {
this.component = newComponent || this.component;
this.refresh(newOption);
},
/**
* 刷新
*/
......@@ -742,7 +729,7 @@ define(function (require) {
var sectorMap = {};
var textMap = {};
var lineMap = {};
var backupShapeList = zrUtil.clone(this.shapeList);
var backupShapeList = this.shapeList;
this.shapeList = [];
var seriesIndex;
......@@ -792,7 +779,7 @@ define(function (require) {
case 'text' :
textMap[key] = this.shapeList[i];
break;
case 'line' :
case 'broken-line' :
lineMap[key] = this.shapeList[i];
break;
}
......@@ -831,11 +818,11 @@ define(function (require) {
400,
deltaIdxMap[seriesIndex] < 0
? {
endAngle :
startAngle :
backupShapeList[i].style.startAngle
}
: {
startAngle :
endAngle :
backupShapeList[i].style.endAngle
}
)
......@@ -843,7 +830,7 @@ define(function (require) {
}
}
else if (backupShapeList[i].type == 'text'
|| backupShapeList[i].type == 'line'
|| backupShapeList[i].type == 'broken-line'
) {
if (targeSector == 'delete') {
// 删除逻辑一样
......@@ -851,7 +838,7 @@ define(function (require) {
}
else {
// 懒得新建变量了,借用一下
switch (backupShapeList[i].shape) {
switch (backupShapeList[i].type) {
case 'text':
targeSector = textMap[key];
this.zr.animate(backupShapeList[i].id, 'style')
......@@ -864,16 +851,13 @@ define(function (require) {
)
.start();
break;
case 'line':
case 'broken-line':
targeSector = lineMap[key];
this.zr.animate(backupShapeList[i].id, 'style')
.when(
400,
{
xStart:targeSector.style.xStart,
yStart:targeSector.style.yStart,
xEnd : targeSector.style.xEnd,
yEnd : targeSector.style.yEnd
pointList:targeSector.style.pointList
}
)
.start();
......
......@@ -27,13 +27,13 @@
* @param {Object} series 数据
* @param {Object} component 组件
*/
function Radar(ecTheme, messageCenter, zr, option, component) {
function Radar(ecTheme, messageCenter, zr, option, myChart) {
// 基类
ComponentBase.call(this, ecTheme, zr, option);
ComponentBase.call(this, ecTheme, messageCenter, zr, option, myChart);
// 可计算特性装饰
CalculableBase.call(this);
this.init(option, component);
this.refresh(option);
}
Radar.prototype = {
......@@ -43,7 +43,7 @@
*/
_buildShape : function () {
this.selectedMap = {};
this._symbol = this.ecTheme.symbolList;
this._symbol = this.option.symbolList;
this._queryTarget;
this._dropBoxList = [];
this._radarDataCounter = 0;
......@@ -390,18 +390,6 @@
return;
},
/**
* 构造函数默认执行的初始化方法,也用于创建实例后动态修改
* @param {Object} newZr
* @param {Object} newSeries
* @param {Object} newComponent
*/
init : function (newOption, newComponent) {
this.component = newComponent || this.component;
this.refresh(newOption);
},
/**
* 刷新
*/
......
......@@ -28,13 +28,13 @@ define(function (require) {
* @param {Object} series 数据
* @param {Object} component 组件
*/
function Scatter(ecTheme, messageCenter, zr, option, component){
function Scatter(ecTheme, messageCenter, zr, option, myChart){
// 基类
ComponentBase.call(this, ecTheme, zr, option);
ComponentBase.call(this, ecTheme, messageCenter, zr, option, myChart);
// 可计算特性装饰
CalculableBase.call(this);
this.init(option, component);
this.refresh(option);
}
Scatter.prototype = {
......@@ -45,7 +45,7 @@ define(function (require) {
_buildShape : function () {
var series = this.series;
this._sIndex2ColorMap = {}; // series默认颜色索引,seriesIndex索引到color
this._symbol = ecConfig.symbolList;
this._symbol = this.option.symbolList;
this._sIndex2ShapeMap = {}; // series图形类型,seriesIndex索引到_symbol
this.selectedMap = {};
......@@ -437,18 +437,6 @@ define(function (require) {
return pos;
},
/**
* 构造函数默认执行的初始化方法,也用于创建实例后动态修改
* @param {Object} newZr
* @param {Object} newSeries
* @param {Object} newComponent
*/
init : function (newOption, newComponent) {
this.component = newComponent;
this.refresh(newOption);
},
/**
* 刷新
*/
......@@ -457,6 +445,7 @@ define(function (require) {
this.option = newOption;
this.series = newOption.series;
}
this.backupShapeList();
this._buildShape();
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册