Skip to content

Commit

Permalink
饼、雷达中心坐标百分比支持
Browse files Browse the repository at this point in the history
  • Loading branch information
kener committed Nov 1, 2013
1 parent 260a069 commit 96acd9e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 39 deletions.
2 changes: 1 addition & 1 deletion doc/example/pie1.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
name:'访问来源',
type:'pie',
radius : [0, 110],
center: [,225],
center: ['50%', 225],
data:[
{value:335, name:'直接访问'},
{value:310, name:'邮件营销'},
Expand Down
2 changes: 1 addition & 1 deletion doc/example/wormhole.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
{ text: 'Firefox', max: 400},
{ text: 'Chrome', max: 400}
],
center : [,240],
center : ['50%', 240],
radius : 150
}
],
Expand Down
2 changes: 1 addition & 1 deletion doc/slide/js/whyEcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ var optionMap = {
{ text: 'Firefox', max: 400},
{ text: 'Chrome', max: 400}
],
center : [,240],
center : ['50%', 240],
radius : 150
}
],
Expand Down
17 changes: 1 addition & 16 deletions src/chart/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,22 +589,7 @@ define(function(require) {
'recursive' : true
}
);
// 圆心坐标,无则为自适应居中
if (!opt.center
|| (opt.center && !(opt.center instanceof Array))) {
opt.center = [
Math.round(zr.getWidth() / 2),
Math.round(zr.getHeight() / 2)
];
}
else {
if (typeof opt.center[0] == 'undefined') {
opt.center[0] = Math.round(zr.getWidth() / 2);
}
if (typeof opt.center[1] == 'undefined') {
opt.center[1] = Math.round(zr.getHeight() / 2);
}
}
opt.center = self.parseCenter(opt.center);

// 传数组实现环形图,[内半径,外半径],传单个则默认为外半径为
if (typeof opt.radius == 'undefined') {
Expand Down
12 changes: 11 additions & 1 deletion src/component/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ define(function(require) {
}
}


/**
* 获取多级控制嵌套属性的基础方法
* 返回ctrList中优先级最高(最靠前)的非undefined属性,ctrList中均无定义则返回undefined
Expand Down Expand Up @@ -258,6 +257,16 @@ define(function(require) {
return value;
}
}

/**
* 获取中心坐标
*/
function parseCenter(center) {
return [
parsePercent(center[0], self.zr.getWidth()),
parsePercent(center[1], self.zr.getHeight()),
];
}

function _trim(str) {
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
Expand Down Expand Up @@ -324,6 +333,7 @@ define(function(require) {
self.getFont = getFont;
self.addLabel = addLabel;
self.parsePercent = parsePercent;
self.parseCenter = parseCenter;
self.clear = clear;
self.dispose = dispose;
self.backupAdaptiveParams = backupAdaptiveParams;
Expand Down
19 changes: 2 additions & 17 deletions src/component/polar.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,23 +765,8 @@ define(
}
);

// 圆心坐标,无则为自适应居中
if (!opt.center
|| (opt.center && !(opt.center instanceof Array))) {
opt.center = [
Math.round(zr.getWidth() / 2),
Math.round(zr.getHeight() / 2)
];
}
else {
if (typeof opt.center[0] == 'undefined') {
opt.center[0] = Math.round(zr.getWidth() / 2);
}
if (typeof opt.center[1] == 'undefined') {
opt.center[1] = Math.round(zr.getHeight() / 2);
}
}

opt.center = self.parseCenter(opt.center);

if (!opt.radius) {
opt.radius = Math.floor(
Math.min(_width, _height) / 2 - 50
Expand Down
4 changes: 2 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ define(function() {
},

polar : {
// center: null, // 默认全局居中
center : ['50%', '50%'], // 默认全局居中
// radius: [0, min(width,height) - 50],
startAngle : 90,
splitNumber : 5,
Expand Down Expand Up @@ -529,7 +529,7 @@ define(function() {

// 饼图默认参数
pie: {
// center: null, // 默认全局居中
center : ['50%', '50%'], // 默认全局居中
// radius: [0, min(width,height) - 50],
startAngle: 90,
minAngle: 5,
Expand Down

0 comments on commit 96acd9e

Please sign in to comment.