Skip to content

Commit

Permalink
新增接口getOption/Series/DataURL/Image
Browse files Browse the repository at this point in the history
  • Loading branch information
kener committed Nov 21, 2013
1 parent ffd2f7e commit bc52c41
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/echarts.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ define(function(require) {
while (len--) {
magicOption.series[len].data = _optionBackup.series[len].data;
}

return magicOption;
}

Expand Down Expand Up @@ -838,6 +837,23 @@ define(function(require) {
return self;
}

/**
* 返回内部持有的当前显示option克隆
*/
function getOption() {
var zrUtil = require('zrender/tool/util');
if (_optionBackup.toolbox
&& _optionBackup.toolbox.show
&& _optionBackup.toolbox.feature.magicType
&& _optionBackup.toolbox.feature.magicType.length > 0
) {
return zrUtil.clone(_getMagicOption());
}
else {
return zrUtil.clone(_getMagicOption(_island.getOption()));
}
}

/**
* 数据设置快捷接口
* @param {Array} series
Expand All @@ -852,9 +868,15 @@ define(function(require) {
_option.series = series;
self.setOption(_option, notMerge);
}

return self;
}

/**
* 返回内部持有的当前显示series克隆
*/
function getSeries() {
return getOption().series;
}

/**
* 动态数据添加
Expand Down Expand Up @@ -1044,6 +1066,32 @@ define(function(require) {
return _zr;
}

/**
* 获取Base64图片dataURL
* @param {string} imgType 图片类型,支持png|jpeg,默认为png
* @return imgDataURL
*/
function getDataURL(imgType) {
imgType = imgType || 'png';
if (imgType != 'png' && imgType != 'jpeg') {
imgType = 'png';
}
return _zr.toDataURL('image/' + imgType);
}

/**
* 获取img
* @param {string} imgType 图片类型,支持png|jpeg,默认为png
* @return img dom
*/
function getImage(imgType) {
var imgDom = document.createElement('img');
imgDom.src = getDataURL(imgType);
imgDom.title = (_optionRestore.title && _optionRestore.title.text)
|| 'ECharts';
return imgDom;
}

/**
* 绑定事件
* @param {Object} eventName 事件名称
Expand Down Expand Up @@ -1148,7 +1196,11 @@ define(function(require) {
self.setOption = setOption;
self.setSeries = setSeries;
self.addData = addData;
self.getOption = getOption;
self.getSeries = getSeries;
self.getZrender = getZrender;
self.getDataURL = getDataURL;
self.getImage = getImage;
self.on = on;
self.un = un;
self.showLoading = showLoading;
Expand Down

0 comments on commit bc52c41

Please sign in to comment.