提交 ac7f2fd6 编写于 作者: D deqingli

Merge remote-tracking branch 'upstream/master'

...@@ -170,9 +170,12 @@ var PieSeries = echarts.extendSeriesModel({ ...@@ -170,9 +170,12 @@ var PieSeries = echarts.extendSeriesModel({
borderWidth: 1 borderWidth: 1
}, },
// Animation type canbe expansion, scale // Animation type. Valid values: expansion, scale
animationType: 'expansion', animationType: 'expansion',
// Animation type when update. Valid values: transition, expansion
animationTypeUpdate: 'transition',
animationEasing: 'cubicOut' animationEasing: 'cubicOut'
} }
}); });
......
...@@ -112,6 +112,8 @@ piePieceProto.updateData = function (data, idx, firstCreate) { ...@@ -112,6 +112,8 @@ piePieceProto.updateData = function (data, idx, firstCreate) {
var sectorShape = zrUtil.extend({}, layout); var sectorShape = zrUtil.extend({}, layout);
sectorShape.label = null; sectorShape.label = null;
var animationTypeUpdate = seriesModel.getShallow('animationTypeUpdate');
if (firstCreate) { if (firstCreate) {
sector.setShape(sectorShape); sector.setShape(sectorShape);
...@@ -136,9 +138,15 @@ piePieceProto.updateData = function (data, idx, firstCreate) { ...@@ -136,9 +138,15 @@ piePieceProto.updateData = function (data, idx, firstCreate) {
} }
else { else {
graphic.updateProps(sector, { if (animationTypeUpdate === 'expansion') {
shape: sectorShape // Sectors are set to be target shape and an overlaying clipPath is used for animation
}, seriesModel, idx); sector.setShape(sectorShape);
} else {
// Transition animation from the old shape
graphic.updateProps(sector, {
shape: sectorShape
}, seriesModel, idx);
}
} }
// Update common style // Update common style
...@@ -167,7 +175,9 @@ piePieceProto.updateData = function (data, idx, firstCreate) { ...@@ -167,7 +175,9 @@ piePieceProto.updateData = function (data, idx, firstCreate) {
seriesModel.get('animation') seriesModel.get('animation')
); );
this._updateLabel(data, idx); // Label and text animation should be applied only for transition type animation when update
var withAnimation = !firstCreate && animationTypeUpdate === 'transition';
this._updateLabel(data, idx, withAnimation);
this.highDownOnUpdate = (itemModel.get('hoverAnimation') && seriesModel.isAnimationEnabled()) this.highDownOnUpdate = (itemModel.get('hoverAnimation') && seriesModel.isAnimationEnabled())
? function (fromState, toState) { ? function (fromState, toState) {
...@@ -201,7 +211,7 @@ piePieceProto.updateData = function (data, idx, firstCreate) { ...@@ -201,7 +211,7 @@ piePieceProto.updateData = function (data, idx, firstCreate) {
graphic.setHoverStyle(this); graphic.setHoverStyle(this);
}; };
piePieceProto._updateLabel = function (data, idx) { piePieceProto._updateLabel = function (data, idx, withAnimation) {
var labelLine = this.childAt(1); var labelLine = this.childAt(1);
var labelText = this.childAt(2); var labelText = this.childAt(2);
...@@ -218,20 +228,33 @@ piePieceProto._updateLabel = function (data, idx) { ...@@ -218,20 +228,33 @@ piePieceProto._updateLabel = function (data, idx) {
return; return;
} }
graphic.updateProps(labelLine, { var targetLineShape = {
shape: { points: labelLayout.linePoints || [
points: labelLayout.linePoints || [ [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y]
[labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y] ]
] };
} var targetTextStyle = {
}, seriesModel, idx); x: labelLayout.x,
y: labelLayout.y
};
if (withAnimation) {
graphic.updateProps(labelLine, {
shape: targetLineShape
}, seriesModel, idx);
graphic.updateProps(labelText, {
style: targetTextStyle
}, seriesModel, idx);
}
else {
labelLine.attr({
shape: targetLineShape
});
labelText.attr({
style: targetTextStyle
});
}
graphic.updateProps(labelText, {
style: {
x: labelLayout.x,
y: labelLayout.y
}
}, seriesModel, idx);
labelText.attr({ labelText.attr({
rotation: labelLayout.rotation, rotation: labelLayout.rotation,
origin: [labelLayout.x, labelLayout.y], origin: [labelLayout.x, labelLayout.y],
...@@ -309,6 +332,7 @@ var PieView = ChartView.extend({ ...@@ -309,6 +332,7 @@ var PieView = ChartView.extend({
var hasAnimation = ecModel.get('animation'); var hasAnimation = ecModel.get('animation');
var isFirstRender = !oldData; var isFirstRender = !oldData;
var animationType = seriesModel.get('animationType'); var animationType = seriesModel.get('animationType');
var animationTypeUpdate = seriesModel.get('animationTypeUpdate');
var onSectorClick = zrUtil.curry( var onSectorClick = zrUtil.curry(
updateDataSelected, this.uid, seriesModel, hasAnimation, api updateDataSelected, this.uid, seriesModel, hasAnimation, api
...@@ -334,6 +358,12 @@ var PieView = ChartView.extend({ ...@@ -334,6 +358,12 @@ var PieView = ChartView.extend({
.update(function (newIdx, oldIdx) { .update(function (newIdx, oldIdx) {
var piePiece = oldData.getItemGraphicEl(oldIdx); var piePiece = oldData.getItemGraphicEl(oldIdx);
if (!isFirstRender && animationTypeUpdate !== 'transition') {
piePiece.eachChild(function (child) {
child.stopAnimation(true);
});
}
piePiece.updateData(data, newIdx); piePiece.updateData(data, newIdx);
piePiece.off('click'); piePiece.off('click');
...@@ -348,9 +378,8 @@ var PieView = ChartView.extend({ ...@@ -348,9 +378,8 @@ var PieView = ChartView.extend({
.execute(); .execute();
if ( if (
hasAnimation && isFirstRender && data.count() > 0 hasAnimation && data.count() > 0
// Default expansion animation && (isFirstRender ? animationType !== 'scale' : animationTypeUpdate !== 'transition')
&& animationType !== 'scale'
) { ) {
var shape = data.getItemLayout(0); var shape = data.getItemLayout(0);
for (var s = 1; isNaN(shape.startAngle) && s < data.count(); ++s) { for (var s = 1; isNaN(shape.startAngle) && s < data.count(); ++s) {
...@@ -361,7 +390,7 @@ var PieView = ChartView.extend({ ...@@ -361,7 +390,7 @@ var PieView = ChartView.extend({
var removeClipPath = zrUtil.bind(group.removeClipPath, group); var removeClipPath = zrUtil.bind(group.removeClipPath, group);
group.setClipPath(this._createClipPath( group.setClipPath(this._createClipPath(
shape.cx, shape.cy, r, shape.startAngle, shape.clockwise, removeClipPath, seriesModel shape.cx, shape.cy, r, shape.startAngle, shape.clockwise, removeClipPath, seriesModel, isFirstRender
)); ));
} }
else { else {
...@@ -375,7 +404,7 @@ var PieView = ChartView.extend({ ...@@ -375,7 +404,7 @@ var PieView = ChartView.extend({
dispose: function () {}, dispose: function () {},
_createClipPath: function ( _createClipPath: function (
cx, cy, r, startAngle, clockwise, cb, seriesModel cx, cy, r, startAngle, clockwise, cb, seriesModel, isFirstRender
) { ) {
var clipPath = new graphic.Sector({ var clipPath = new graphic.Sector({
shape: { shape: {
...@@ -389,7 +418,8 @@ var PieView = ChartView.extend({ ...@@ -389,7 +418,8 @@ var PieView = ChartView.extend({
} }
}); });
graphic.initProps(clipPath, { var initOrUpdate = isFirstRender ? graphic.initProps : graphic.updateProps;
initOrUpdate(clipPath, {
shape: { shape: {
endAngle: startAngle + (clockwise ? 1 : -1) * Math.PI * 2 endAngle: startAngle + (clockwise ? 1 : -1) * Math.PI * 2
} }
......
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta charset="utf-8">
<script src="lib/esl.js"></script>
<script src="lib/config.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<style>
html,
body,
#main1,
#main2 {
width: 100%;
height: 250px;
margin: 0;
}
.test-title {
background: #146402;
padding: 10px;
color: #fff;
}
button {
padding: 10px 20px;
margin: 10px;
}
</style>
<div class="test-title">Animation: Transition from previous state to new state, in 10 seconds after clicking Go</div>
<button id="btn1">Go</button>
<div id="main1"></div>
<div class="test-title">Animation: Transition all over again, in 10 seconds after clicking Go</div>
<button id="btn2">Go</button>
<div id="main2"></div>
<script>
require([
'echarts'
], function (echarts) {
var chart = echarts.init(
document.getElementById('main1'),
null,
{
renderer: 'svg'
}
);
var data = [
{"name": "a1", "value": 92386},
{"name": "b1", "value": 90611},
{"name": "c1", "value": 12596},
{"name": "d1", "value": 9438},
{"name": "e1", "value": 10049}
];
var data2 = [
{"name": "a1", "value": 120},
{"name": "b1", "value": 200},
{"name": "c1", "value": 300},
{"name": "x1", "value": 20},
{"name": "y1", "value": 30}
];
var option = {
series: [{
type: 'pie',
animationDuration: 1000,
animationDurationUpdate: 10000,
startAngle: 0,
endAngle: 360,
radius: ['50%', '80%'],
center: ['40%', '50%'],
data: data
}]
};
chart.setOption(option);
document.getElementById('btn1').addEventListener('click', function () {
option.series[0].data = data2;
chart.setOption(option, true);
});
});
</script>
<script>
require([
'echarts'
], function (echarts) {
var chart = echarts.init(
document.getElementById('main2'),
null,
{
renderer: 'svg'
}
);
var data = [
{"name": "a1", "value": 92386},
{"name": "b1", "value": 90611},
{"name": "c1", "value": 12596},
{"name": "d1", "value": 9438},
{"name": "e1", "value": 10049}
];
var data2 = [
{"name": "a1", "value": 120},
{"name": "b1", "value": 200},
{"name": "c1", "value": 300},
{"name": "x1", "value": 20},
{"name": "y1", "value": 30}
];
var option = {
series: [{
type: 'pie',
animationType: 'expansion',
animationDuration: 1000,
animationDurationUpdate: 10000,
animationTypeUpdate: 'expansion',
startAngle: 0,
endAngle: 360,
radius: ['50%', '80%'],
center: ['40%', '50%'],
data: data
}]
};
chart.setOption(option);
document.getElementById('btn2').addEventListener('click', function () {
option.series[0].data = data2;
chart.setOption(option, true);
});
});
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册