提交 e5cffa84 编写于 作者: L lang

Merge branch 'dev-3.0.0' of https://github.com/ecomfe/echarts into dev-3.0.0

......@@ -82,26 +82,11 @@ define(function(require) {
* @override
*/
mergeOption: function (newOption) {
newOption && zrUtil.merge(this.option, newOption);
newOption && zrUtil.merge(this.option, newOption, true);
this._initData();
},
/**
* @public
*/
infectOption: function (timelineOption) {
var thisOption = this.option;
if (zrUtil.isArray(timelineOption)) {
timelineOption = timelineOption[0];
}
if (timelineOption) {
timelineOption.currentIndex = thisOption.currentIndex;
timelineOption.autoPlay = thisOption.autoPlay;
}
},
/**
* @param {number} [currentIndex]
*/
......
......@@ -141,7 +141,7 @@ define(function (require) {
// and ComponentModel.getAllClassMainTypes
each(componentsMap[mainType], function (cpt) {
cpt.mergeOption({}, this);
});
}, this);
}
function handleNew(mainType, newCptOptionList, dependencies) {
......
......@@ -35,7 +35,7 @@ define(function (require) {
* An object input to echarts.setOption. 'rawOption' may be an
* 'option', or may be an object contains multi-options. For example:
* var option = {
* base: {
* baseOption: {
* title: {...},
* legend: {...},
* series: [
......@@ -132,7 +132,7 @@ define(function (require) {
rawOption = clone(rawOption, true);
// FIXME
// 如果 timeline options 或者 media 中设置了某个属性,而base中没有设置,则进行警告。
// 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。
this._optionBackup = parseRawOption.call(
this, rawOption, optionPreprocessorFuncs
......@@ -188,22 +188,23 @@ define(function (require) {
var ecHeight = this._api.getHeight();
var mediaList = this._mediaList;
var index;
var result;
for (var i = 0, len = mediaList.length; i < len; i++) {
var query = mediaList[i].query;
if (applyMediaQuery(query, ecWidth, ecHeight)) {
if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
index = i;
break;
}
}
if (this._mediaDefault) {
// FIXME
// 是否mediaDefault应该强制用户设置,否则可能修改不能回归。
if (index == null && this._mediaDefault) {
index = -1;
}
if (index != null && index !== this._currentMediaIndex) {
this._currentMediaIndex = index;
return clone(
result = clone(
index === -1
? this._mediaDefault.option
: mediaList[index].option,
......@@ -211,6 +212,10 @@ define(function (require) {
);
}
// Otherwise return nothing.
this._currentMediaIndex = index;
return result;
}
};
......@@ -218,17 +223,19 @@ define(function (require) {
var timelineOptions = [];
var mediaList = [];
var mediaDefault;
var timelineOpt = rawOption.timeline;
var baseOption;
// Compatible with ec2.
var timelineOpt = rawOption.timeline;
// For timeline
if (timelineOpt || rawOption.options) {
baseOption = rawOption.base || {};
baseOption = rawOption.baseOption || {};
timelineOptions = (rawOption.options || []).slice();
}
// For media query
if (rawOption.media) {
baseOption = rawOption.base || {};
baseOption = rawOption.baseOption || {};
var media = rawOption.media;
each(media, function (singleMedia) {
if (singleMedia && singleMedia.option) {
......@@ -247,8 +254,11 @@ define(function (require) {
baseOption = rawOption;
}
// Set timelineOpt to baseOption for convenience.
baseOption.timeline = timelineOpt;
// Set timelineOpt to baseOption in ec3,
// which is convenient for merge option.
if (!baseOption.timeline) {
baseOption.timeline = timelineOpt;
}
// Preprocess.
each([baseOption].concat(timelineOptions), function (option) {
......@@ -299,10 +309,10 @@ define(function (require) {
function compare(real, expect, operator) {
if (operator === 'min') {
return real <= expect;
return real >= expect;
}
else if (operator === 'max') {
return real >= expect;
return real <= expect;
}
else { // Equals
return real === expect;
......
......@@ -18,6 +18,9 @@ define(function () {
// 默认需要 Grid 配置项
grid: {},
// Grid 依赖 xAxis 和 yAxis
xAxis: {},
yAxis: {},
// 主题,主题
textStyle: {
......
/**
* Simple draggable tool, just for demo or testing.
* Use jquery.
*/
(function (global) {
var BORDER_WIDTH = 3;
global.draggable = {
init: function (mainEl, chart) {
var mainEl = $(mainEl);
var controlEl = $(
'<div class="draggable-control">DRAG<span class="draggable-label"></span></div>'
);
controlEl.css({
'position': 'absolute',
'border-radius': '30px',
'width': '60px',
'height': '60px',
'line-height': '60px',
'text-align': 'center',
'background': '#333',
'color': '#fff',
'cursor': 'pointer',
'font-size': '18px',
'-webkit-user-select': 'none',
'user-select': 'none'
});
var label = controlEl.find('.draggable-label');
label.css({
'display': 'block',
'position': 'absolute',
'color': '#000',
'font-size': '12px',
'text-align': 'center',
'left': 0,
'top': '65px',
'width': '60px',
'line-height': 1
});
mainEl.css({
'position': 'absolute',
'left': mainEl[0].offsetLeft + 'px',
'top': mainEl[0].offsetTop + 'px',
'width': mainEl[0].offsetWidth + 'px',
'height': mainEl[0].offsetHeight + 'px',
'border-style': 'solid',
'border-color': '#777',
'border-width': BORDER_WIDTH + 'px',
'padding': 0,
'margin': 0
});
mainEl.parent().append(controlEl);
var controlSize = controlEl[0].offsetWidth;
var mainElWidth = mainEl[0].offsetWidth - 2 * BORDER_WIDTH;
var mainElHeight = mainEl[0].offsetHeight - 2 * BORDER_WIDTH;
controlEl.css({
left: mainEl[0].offsetLeft + mainElWidth - controlSize / 2,
top: mainEl[0].offsetTop + mainElHeight - controlSize / 2
});
label.text(mainElWidth + ' x ' + mainElHeight);
var dragging = false;
controlEl.on('mousedown', function () {
dragging = true;
});
$(document).on('mousemove', function (e) {
if (dragging) {
resize(e.pageX, e.pageY);
}
});
$(document).on('mouseup', function () {
dragging = false;
});
function resize(x, y) {
controlEl.css({left: x - controlSize / 2, top: y - controlSize / 2});
var mainElWidth = x - mainEl[0].offsetLeft;
var mainElHeight = y - mainEl[0].offsetTop;
mainEl.css({width: mainElWidth, height: mainElHeight});
label.text(mainElWidth + ' x ' + mainElHeight)
if (chart) {
chart.resize();
}
}
}
};
})(window);
\ No newline at end of file
<html>
<head>
<meta charset="utf-8">
<script src="esl.js"></script>
<script src="config.js"></script>
<script src="lib/jquery.min.js"></script>
<script src="lib/draggable.js"></script>
<link rel="stylesheet" href="reset.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<style>
#main {
position: absolute;
top: 10px;
left: 10px;
width: 900px;
height: 500px;
background: #fff;
}
</style>
<div id="main"></div>
<script src="data/timelineGDP.js"></script>
<script>
// markLine: {
// symbol: ['arrow','none'],
// symbolSize: [4, 2],
// itemStyle: {
// normal: {
// lineStyle: {color:'orange'},
// barBorderColor:'orange',
// label: {
// position:'left',
// formatter:function(params){
// return Math.round(params.value);
// },
// textStyle:{color:'orange'}
// }
// }
// },
// data: [{type: 'average', name: '平均值'}]
// }
require([
'echarts',
'echarts/chart/bar',
'echarts/chart/pie',
'echarts/component/title',
'echarts/component/legend',
'echarts/component/grid',
'echarts/component/tooltip',
'echarts/component/timeline'
], function (echarts) {
chart = echarts.init(document.getElementById('main'), null, {
renderer: 'canvas'
});
draggable.init(document.getElementById('main'), chart);
var categoryData = [
'北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江',
'上海','江苏','浙江','安徽','福建','江西','山东','河南',
'湖北','湖南','广东','广西','海南','重庆','四川','贵州',
'云南','西藏','陕西','甘肃','青海','宁夏','新疆'
];
var categoryDataWithReturn = [];
for (var i = 0; i < categoryData.length; i++) {
var word = categoryData[i];
if (i % 2 === 0) {
word = '\n' + word;
}
categoryDataWithReturn.push(word);
}
var categoryAxis = {
id: 'categoryAxis',
type: 'category',
axisLabel: {interval: 0},
data: categoryDataWithReturn,
splitLine: {show: false}
};
var valueAxis = {
id: 'valueAxis',
type: 'value',
name: 'GDP(亿元)',
// max: 53500
max: 30000
}
var option = {
baseOption: {
timeline: {
// y: 0,
axisType: 'category',
// realtime: false,
// loop: false,
autoPlay: true,
// currentIndex: 2,
playInterval: 1000,
// controlStyle: {
// position: 'left'
// },
data: [
'2002-01-01','2003-01-01','2004-01-01',
{
value: '2005-01-01',
tooltip: {
formatter: '{b} GDP达到一个高度'
},
itemStyle: {
normal: {
symbol: 'diamond',
symbolSize: 16
}
}
},
'2006-01-01', '2007-01-01','2008-01-01','2009-01-01','2010-01-01',
{
value: '2011-01-01',
tooltip: {
formatter: function (params) {
return params.name + 'GDP达到又一个高度';
}
},
itemStyle: {
normal: {
symbol: 'diamond',
symbolSize: 18
}
}
},
],
label: {
formatter : function(s) {
return (new Date(s)).getFullYear();
}
}
},
title: {
subtext: '数据来自国家统计局'
},
tooltip: {
trigger:'axis',
axisPointer: {
type: 'shadow'
}
},
xAxis: categoryAxis,
yAxis: valueAxis,
legend: {
data: ['第一产业', '第二产业', '第三产业', 'GDP', '金融', '房地产'],
selected: {
'GDP': false, '金融': false, '房地产': false
}
},
calculable : true,
series: [
{name: 'GDP', type: 'bar'},
{name: '金融', type: 'bar'},
{name: '房地产', type: 'bar'},
{name: '第一产业', type: 'bar'},
{name: '第二产业', type: 'bar'},
{name: '第三产业', type: 'bar'},
{name: 'GDP占比', type: 'pie'}
]
},
media: [
{
option: {
legend: {
orient: 'horizontal',
// align: 'right',
x: 'right',
width: null,
itemGap: 10
},
grid: {
x: '10%',
y:80,
x2: 50,
y2: 100
},
xAxis: {
axisLabel: {interval: 0},
data: categoryDataWithReturn
},
// yAxis: valueAxis,
timeline: {
orient: 'horizontal',
inverse: false,
x: '20%',
x2: '20%',
y: null,
y2: 10,
width: null,
height: 40
},
series: [
{name: 'GDP占比', center: ['75%', '35%'], radius: '28%'}
]
}
},
{
query: {maxWidth: 700, minWidth: 550},
option: {
legend: {
orient: 'horizontal',
align: 'right',
x: 200,
itemGap: 5
},
grid: {
x: '10%',
y:80,
x2: 50,
y2: 100
},
xAxis: {
axisLabel: {interval: 0},
data: categoryDataWithReturn
},
timeline: {
orient: 'horizontal',
inverse: false,
x: '20%',
x2: '20%',
y: null,
y2: 10,
width: null,
height: 40
},
series: [
{name: 'GDP占比', center: ['75%', '35%'], radius: '28%'}
]
}
},
{
query: {maxWidth: 550},
option: {
legend: {
orient: 'vertical',
align: 'right',
x: 'right',
itemGap: 5
},
grid: {
x: 55,
y: '50%',
x2: 100,
y2: 50
},
xAxis: {
axisLabel: {interval: 'auto'},
data: categoryData
},
timeline: {
orient: 'vertical',
inverse: true,
x: null,
x2: 10,
y: 150,
y2: 10,
width: 55,
height: null
},
series: [
{name: 'GDP占比', center: ['45%', '30%'], radius: '28%'}
]
}
}
],
options: [
{
title: {text: '2002全国宏观经济指标'},
series: [
{data: dataMap.dataGDP['2002']},
{data: dataMap.dataFinancial['2002']},
{data: dataMap.dataEstate['2002']},
{data: dataMap.dataPI['2002']},
{data: dataMap.dataSI['2002']},
{data: dataMap.dataTI['2002']},
{data: [
{name: '第一产业', value: dataMap.dataPI['2002sum']},
{name: '第二产业', value: dataMap.dataSI['2002sum']},
{name: '第三产业', value: dataMap.dataTI['2002sum']}
]}
]
},
{
title : {text: '2003全国宏观经济指标'},
series : [
{data: dataMap.dataGDP['2003']},
{data: dataMap.dataFinancial['2003']},
{data: dataMap.dataEstate['2003']},
{data: dataMap.dataPI['2003']},
{data: dataMap.dataSI['2003']},
{data: dataMap.dataTI['2003']},
{data: [
{name: '第一产业', value: dataMap.dataPI['2003sum']},
{name: '第二产业', value: dataMap.dataSI['2003sum']},
{name: '第三产业', value: dataMap.dataTI['2003sum']}
]}
]
},
{
title : {text: '2004全国宏观经济指标'},
series : [
{data: dataMap.dataGDP['2004']},
{data: dataMap.dataFinancial['2004']},
{data: dataMap.dataEstate['2004']},
{data: dataMap.dataPI['2004']},
{data: dataMap.dataSI['2004']},
{data: dataMap.dataTI['2004']},
{data: [
{name: '第一产业', value: dataMap.dataPI['2004sum']},
{name: '第二产业', value: dataMap.dataSI['2004sum']},
{name: '第三产业', value: dataMap.dataTI['2004sum']}
]}
]
},
{
title : {text: '2005全国宏观经济指标'},
series : [
{data: dataMap.dataGDP['2005']},
{data: dataMap.dataFinancial['2005']},
{data: dataMap.dataEstate['2005']},
{data: dataMap.dataPI['2005']},
{data: dataMap.dataSI['2005']},
{data: dataMap.dataTI['2005']},
{data: [
{name: '第一产业', value: dataMap.dataPI['2005sum']},
{name: '第二产业', value: dataMap.dataSI['2005sum']},
{name: '第三产业', value: dataMap.dataTI['2005sum']}
]}
]
},
{
title : {text: '2006全国宏观经济指标'},
series : [
{data: dataMap.dataGDP['2006']},
{data: dataMap.dataFinancial['2006']},
{data: dataMap.dataEstate['2006']},
{data: dataMap.dataPI['2006']},
{data: dataMap.dataSI['2006']},
{data: dataMap.dataTI['2006']},
{data: [
{name: '第一产业', value: dataMap.dataPI['2006sum']},
{name: '第二产业', value: dataMap.dataSI['2006sum']},
{name: '第三产业', value: dataMap.dataTI['2006sum']}
]}
]
},
{
title : {text: '2007全国宏观经济指标'},
series : [
{data: dataMap.dataGDP['2007']},
{data: dataMap.dataFinancial['2007']},
{data: dataMap.dataEstate['2007']},
{data: dataMap.dataPI['2007']},
{data: dataMap.dataSI['2007']},
{data: dataMap.dataTI['2007']},
{data: [
{name: '第一产业', value: dataMap.dataPI['2007sum']},
{name: '第二产业', value: dataMap.dataSI['2007sum']},
{name: '第三产业', value: dataMap.dataTI['2007sum']}
]}
]
},
{
title : {text: '2008全国宏观经济指标'},
series : [
{data: dataMap.dataGDP['2008']},
{data: dataMap.dataFinancial['2008']},
{data: dataMap.dataEstate['2008']},
{data: dataMap.dataPI['2008']},
{data: dataMap.dataSI['2008']},
{data: dataMap.dataTI['2008']},
{data: [
{name: '第一产业', value: dataMap.dataPI['2008sum']},
{name: '第二产业', value: dataMap.dataSI['2008sum']},
{name: '第三产业', value: dataMap.dataTI['2008sum']}
]}
]
},
{
title : {text: '2009全国宏观经济指标'},
series : [
{data: dataMap.dataGDP['2009']},
{data: dataMap.dataFinancial['2009']},
{data: dataMap.dataEstate['2009']},
{data: dataMap.dataPI['2009']},
{data: dataMap.dataSI['2009']},
{data: dataMap.dataTI['2009']},
{data: [
{name: '第一产业', value: dataMap.dataPI['2009sum']},
{name: '第二产业', value: dataMap.dataSI['2009sum']},
{name: '第三产业', value: dataMap.dataTI['2009sum']}
]}
]
},
{
title : {text: '2010全国宏观经济指标'},
series : [
{data: dataMap.dataGDP['2010']},
{data: dataMap.dataFinancial['2010']},
{data: dataMap.dataEstate['2010']},
{data: dataMap.dataPI['2010']},
{data: dataMap.dataSI['2010']},
{data: dataMap.dataTI['2010']},
{data: [
{name: '第一产业', value: dataMap.dataPI['2010sum']},
{name: '第二产业', value: dataMap.dataSI['2010sum']},
{name: '第三产业', value: dataMap.dataTI['2010sum']}
]}
]
},
{
title : {text: '2011全国宏观经济指标'},
series : [
{data: dataMap.dataGDP['2011']},
{data: dataMap.dataFinancial['2011']},
{data: dataMap.dataEstate['2011']},
{data: dataMap.dataPI['2011']},
{data: dataMap.dataSI['2011']},
{data: dataMap.dataTI['2011']},
{data: [
{name: '第一产业', value: dataMap.dataPI['2011sum']},
{name: '第二产业', value: dataMap.dataSI['2011sum']},
{name: '第三产业', value: dataMap.dataTI['2011sum']}
]}
]
}
]
};
chart.setOption(option);
chart.on('legendSelected', function () {
});
window.onresize = chart.resize;
});
</script>
</body>
</html>
\ No newline at end of file
......@@ -57,54 +57,54 @@
});
var option = {
timeline: {
// y: 0,
axisType: 'category',
// realtime: false,
// loop: false,
autoPlay: true,
// currentIndex: 2,
playInterval: 1000,
// controlStyle: {
// position: 'left'
// },
data: [
'2002-01-01','2003-01-01','2004-01-01',
{
value: '2005-01-01',
tooltip: {
formatter: '{b} GDP达到一个高度'
},
itemStyle: {
normal: {
symbol: 'diamond',
symbolSize: 16
}
}
},
'2006-01-01', '2007-01-01','2008-01-01','2009-01-01','2010-01-01',
{
value: '2011-01-01',
tooltip: {
formatter: function (params) {
return params.name + 'GDP达到又一个高度';
baseOption: {
timeline: {
// y: 0,
axisType: 'category',
// realtime: false,
// loop: false,
autoPlay: true,
// currentIndex: 2,
playInterval: 1000,
// controlStyle: {
// position: 'left'
// },
data: [
'2002-01-01','2003-01-01','2004-01-01',
{
value: '2005-01-01',
tooltip: {
formatter: '{b} GDP达到一个高度'
},
itemStyle: {
normal: {
symbol: 'diamond',
symbolSize: 16
}
}
},
itemStyle: {
normal: {
symbol: 'diamond',
symbolSize: 18
'2006-01-01', '2007-01-01','2008-01-01','2009-01-01','2010-01-01',
{
value: '2011-01-01',
tooltip: {
formatter: function (params) {
return params.name + 'GDP达到又一个高度';
}
},
itemStyle: {
normal: {
symbol: 'diamond',
symbolSize: 18
}
}
},
],
label: {
formatter : function(s) {
return (new Date(s)).getFullYear();
}
},
],
label: {
formatter : function(s) {
return (new Date(s)).getFullYear();
}
}
},
base: {
},
title: {
subtext: '数据来自国家统计局'
},
......@@ -122,7 +122,7 @@ var option = {
'GDP': false, '金融': false, '房地产': false
}
},
calculable : true,
calculable: true,
grid: {y:80, y2: 100},
xAxis: {
'type':'category',
......
......@@ -149,7 +149,7 @@
// normal: {symbolSize: 1}
}
},
base: {
baseOption: {
backgroundColor: '#fff',
title: {
'subtext':'数据来自国家统计局'
......@@ -206,7 +206,7 @@
},
'data':[{'type':'average','name':'平均值'}]
}
},
}
// {type: 'bar'},
// {type: 'bar'},
// {type: 'bar'},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册