Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ecomfe/echarts
Browse files Browse the repository at this point in the history
  • Loading branch information
100pah committed Mar 28, 2016
2 parents f730117 + 7f05cb6 commit 1ebd1f4
Show file tree
Hide file tree
Showing 7 changed files with 493 additions and 28 deletions.
23 changes: 11 additions & 12 deletions src/chart/pie/labelLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ define(function (require) {
continue;
}
var deltaY = Math.abs(list[i].y - cy);
var length = list[i].length;
var length = list[i].len;
var length2 = list[i].len2;
var deltaX = (deltaY < r + length)
? Math.sqrt(
(r + length + 20) * (r + length + 20)
- Math.pow(list[i].y - cy, 2)
(r + length + length2) * (r + length + length2)
- deltaY * deltaY
)
: Math.abs(list[i].x - cx);
if (isDownList && deltaX >= lastDeltaX) {
Expand Down Expand Up @@ -97,8 +98,8 @@ define(function (require) {
upList.push(list[i]);
}
}
changeX(downList, true, cx, cy, r, dir);
changeX(upList, false, cx, cy, r, dir);
changeX(downList, true, cx, cy, r, dir);
}

function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight) {
Expand All @@ -113,8 +114,8 @@ define(function (require) {
}
}

adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight);
adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight);
adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight);

for (var i = 0; i < labelLayoutList.length; i++) {
var linePoints = labelLayoutList[i].linePoints;
Expand Down Expand Up @@ -173,15 +174,13 @@ define(function (require) {
var x1 = (isLabelInside ? layout.r / 2 * dx : layout.r * dx) + cx;
var y1 = (isLabelInside ? layout.r / 2 * dy : layout.r * dy) + cy;

// For roseType
labelLineLen += r - layout.r;

textX = x1 + dx * 3;
textY = y1 + dy * 3;

if (!isLabelInside) {
var x2 = x1 + dx * labelLineLen;
var y2 = y1 + dy * labelLineLen;
// For roseType
var x2 = x1 + dx * (labelLineLen + r - layout.r);
var y2 = y1 + dy * (labelLineLen + r - layout.r);
var x3 = x2 + ((dx < 0 ? -1 : 1) * labelLineLen2);
var y3 = y2;

Expand All @@ -207,8 +206,8 @@ define(function (require) {
y: textY,
position: labelPosition,
height: textRect.height,
length: labelLineLen,
length2: labelLineLen2,
len: labelLineLen,
len2: labelLineLen2,
linePoints: linePoints,
textAlign: textAlign,
verticalAlign: 'middle',
Expand Down
57 changes: 42 additions & 15 deletions src/component/toolbox/feature/DataView.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ define(function (require) {
DataView.defaultOption = {
show: true,
readOnly: false,
optionToContent: null,
contentToOption: null,

icon: 'M17.5,17.3H33 M17.5,17.3H33 M45.4,29.5h-28 M11.5,2v56H51V14.8L38.4,2H11.5z M38.4,2.2v12.7H51 M45.4,41.7h-28',
title: '数据视图',
lang: ['数据视图', '关闭', '刷新'],
Expand Down Expand Up @@ -301,16 +304,33 @@ define(function (require) {
header.style.cssText = 'margin: 10px 20px;';
header.style.color = model.get('textColor');

var viewMain = document.createElement('div');
var textarea = document.createElement('textarea');
// Textarea style
textarea.style.cssText = 'display:block;width:100%;font-size:14px;line-height:1.6rem;font-family:Monaco,Consolas,Courier new,monospace';
textarea.readOnly = model.get('readOnly');
textarea.style.color = model.get('textColor');
textarea.style.borderColor = model.get('textareaBorderColor');
textarea.style.backgroundColor = model.get('textareaColor');
viewMain.style.cssText = 'display:block;width:100%;overflow:hidden;';

var optionToContent = model.get('optionToContent');
var contentToOption = model.get('contentToOption');
var result = getContentFromModel(ecModel);
textarea.value = result.value;
if (typeof optionToContent === 'function') {
var htmlOrDom = optionToContent(api.getOption());
if (typeof htmlOrDom === 'string') {
viewMain.innerHTML = htmlOrDom;
}
else if (zrUtil.isDom(htmlOrDom)) {
viewMain.appendChild(htmlOrDom);
}
}
else {
// Use default textarea
viewMain.appendChild(textarea);
textarea.readOnly = model.get('readOnly');
textarea.style.cssText = 'width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;';
textarea.style.color = model.get('textColor');
textarea.style.borderColor = model.get('textareaBorderColor');
textarea.style.backgroundColor = model.get('textareaColor');
textarea.value = result.value;
}

var blockMetaList = result.meta;

var buttonContainer = document.createElement('div');
Expand All @@ -335,16 +355,23 @@ define(function (require) {
eventTool.addEventListener(refreshButton, 'click', function () {
var newOption;
try {
newOption = parseContents(textarea.value, blockMetaList);
if (typeof contentToOption === 'function') {
newOption = contentToOption(viewMain, api.getOption());
}
else {
newOption = parseContents(textarea.value, blockMetaList);
}
}
catch (e) {
close();
throw new Error('Data view format error ' + e);
}
api.dispatchAction({
type: 'changeDataView',
newOption: newOption
});
if (newOption) {
api.dispatchAction({
type: 'changeDataView',
newOption: newOption
});
}

close();
});
Expand All @@ -354,7 +381,7 @@ define(function (require) {
refreshButton.style.cssText = buttonStyle;
closeButton.style.cssText = buttonStyle;

buttonContainer.appendChild(refreshButton);
!model.get('readOnly') && buttonContainer.appendChild(refreshButton);
buttonContainer.appendChild(closeButton);

// http://stackoverflow.com/questions/6637341/use-tab-to-indent-in-textarea
Expand All @@ -377,10 +404,10 @@ define(function (require) {
});

root.appendChild(header);
root.appendChild(textarea);
root.appendChild(viewMain);
root.appendChild(buttonContainer);

textarea.style.height = (container.clientHeight - 80) + 'px';
viewMain.style.height = (container.clientHeight - 80) + 'px';

container.appendChild(root);
this._dom = root;
Expand Down
2 changes: 1 addition & 1 deletion src/echarts.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ define(function (require) {

this._zr.dispose();

instances[this.id] = null;
delete instances[this.id];
};

zrUtil.mixin(ECharts, Eventful);
Expand Down
130 changes: 130 additions & 0 deletions test/dataView.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<html>
<head>
<meta charset="utf-8">
<script src="esl.js"></script>
<script src="config.js"></script>
<script src=""></script>
<script src="//cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="//cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<style>
html, body, #main {
width: 100%;
height: 100%;
margin: 0;
}
#main {
background: #fff;
}
</style>
<div id="main"></div>
<script>

require([
'echarts',
'echarts/chart/bar',
'echarts/chart/line',
'echarts/component/legend',
'echarts/component/grid',
'echarts/component/tooltip',
'echarts/component/toolbox',
'zrender/vml/vml'
], function (echarts) {

var chart = echarts.init(document.getElementById('main'));

var xAxisData = [];
var data1 = [];
var data2 = [];
var data3 = [];
var data4 = [];

for (var i = 0; i < 10; i++) {
xAxisData.push('类目' + i);
data1.push((Math.random() * 5).toFixed(2));
data2.push(-Math.random().toFixed(2));
data3.push((Math.random() + 0.5).toFixed(2));
data4.push((Math.random() + 0.3).toFixed(2));
}

chart.setOption({
toolbox: {
// y: 'bottom',
feature: {
dataView: {
optionToContent: function(opt) {
var axisData = opt.xAxis[0].data;
var series = opt.series;
var table = '<table style="width:100%;text-align:center"><tbody><tr>'
+ '<td>时间</td>'
+ '<td>' + series[0].name + '</td>'
+ '<td>' + series[1].name + '</td>'
+ '</tr>';
for (var i = 0, l = axisData.length; i < l; i++) {
table += '<tr>'
+ '<td>' + axisData[i] + '</td>'
+ '<td>' + series[0].data[i] + '</td>'
+ '<td>' + series[1].data[i] + '</td>'
+ '</tr>';
}
table += '</tbody></table>';
return table;
},
contentToOption: function () {
console.log(arguments);
}
},
saveAsImage: {
pixelRatio: 2
}
}
},
tooltip: {},
xAxis: {
data: xAxisData,
axisLine: {
onZero: true
},
splitLine: {
show: false
},
splitArea: {
show: false
}
},
yAxis: {
inverse: true,
splitArea: {
show: false
}
},
series: [{
name: 'bar',
type: 'bar',
stack: 'one',
data: data1
}, {
name: 'bar2',
type: 'bar',
stack: 'one',
data: data2
}, {
name: 'bar3',
type: 'bar',
stack: 'two',
data: data3
}, {
name: 'bar4',
type: 'bar',
stack: 'two',
data: data4
}]
});

window.onresize = chart.resize;
});
</script>
</body>
</html>
5 changes: 5 additions & 0 deletions test/radar.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
series: [{
name: '预算 vs 开销(Budget vs spending)',
type: 'radar',
label: {
normal: {
show: true
}
},
// areaStyle: {normal: {}},
data : [
{
Expand Down
Loading

0 comments on commit 1ebd1f4

Please sign in to comment.