diff --git a/src/chart/pie/PieSeries.js b/src/chart/pie/PieSeries.js index a547703881e664f199da1b3a87fb2541a20427d2..63035d62d9cc5080d6ffb6044987e438d8628f0b 100644 --- a/src/chart/pie/PieSeries.js +++ b/src/chart/pie/PieSeries.js @@ -118,6 +118,11 @@ var PieSeries = echarts.extendSeriesModel({ startAngle: 90, // 最小角度改为0 minAngle: 0, + + // If the angle of a sector less than `minShowLabelAngle`, + // the label will not be displayed. + minShowLabelAngle: 0, + // 选中时扇区偏移量 selectedOffset: 10, // 高亮扇区偏移量 diff --git a/src/chart/pie/PieView.js b/src/chart/pie/PieView.js index 8a8fd54bb45cc4a813681d3b733576c2afeb9c78..2f03f0db45d2d23b1d132ab5a7b2dcb4482772ec 100644 --- a/src/chart/pie/PieView.js +++ b/src/chart/pie/PieView.js @@ -94,9 +94,6 @@ function PiePiece(data, idx) { this.add(sector); this.add(polyline); this.add(text); - - var valueDim = data.mapDimension('value'); - this._sum = data.getSum(valueDim) || 0; this.updateData(data, idx, true); } @@ -204,13 +201,6 @@ piePieceProto.updateData = function (data, idx, firstCreate) { graphic.setHoverStyle(this); }; -piePieceProto._getLabelDisplayThresholdState = function (data, idx) { - var seriesModel = data.hostModel; - var valueDim = data.mapDimension('value'); - var labelDisplayThreshold = seriesModel.get('labelDisplayThreshold'); - return this._sum * labelDisplayThreshold > data.get(valueDim, idx); -} - piePieceProto._updateLabel = function (data, idx) { var labelLine = this.childAt(1); @@ -221,7 +211,12 @@ piePieceProto._updateLabel = function (data, idx) { var layout = data.getItemLayout(idx); var labelLayout = layout.label; var visualColor = data.getItemVisual(idx, 'color'); - var filterLabelIgnore = this._getLabelDisplayThresholdState(data, idx); + + if (!labelLayout) { + labelText.ignore = labelText.normalIgnore = labelText.hoverIgnore = + labelLine.ignore = labelLine.normalIgnore = labelLine.hoverIgnore = true; + return; + } graphic.updateProps(labelLine, { shape: { @@ -265,11 +260,11 @@ piePieceProto._updateLabel = function (data, idx) { } ); - labelText.ignore = labelText.normalIgnore = !labelModel.get('show') || filterLabelIgnore; - labelText.hoverIgnore = !labelHoverModel.get('show') || filterLabelIgnore; + labelText.ignore = labelText.normalIgnore = !labelModel.get('show'); + labelText.hoverIgnore = !labelHoverModel.get('show'); - labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show') || filterLabelIgnore; - labelLine.hoverIgnore = !labelLineHoverModel.get('show') || filterLabelIgnore; + labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show'); + labelLine.hoverIgnore = !labelLineHoverModel.get('show'); // Default use item visual color labelLine.setStyle({ diff --git a/src/chart/pie/labelLayout.js b/src/chart/pie/labelLayout.js index 324467363b0028ae731d7e5e237d58394d12fff3..69298d828573eb3f8744564529651bc2afa97e60 100644 --- a/src/chart/pie/labelLayout.js +++ b/src/chart/pie/labelLayout.js @@ -21,6 +21,8 @@ import * as textContain from 'zrender/src/contain/text'; +var RADIAN = Math.PI / 180; + function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight) { list.sort(function (a, b) { return a.y - b.y; @@ -154,12 +156,13 @@ function isPositionCenter(layout) { return layout.position === 'center'; } -export default function (seriesModel, r, viewWidth, viewHeight) { +export default function (seriesModel, r, viewWidth, viewHeight, sum) { var data = seriesModel.getData(); var labelLayoutList = []; var cx; var cy; var hasLabelRotate = false; + var minShowLabelRadian = (seriesModel.get('minShowLabelAngle') || 0) * RADIAN; data.each(function (idx) { var layout = data.getItemLayout(idx); @@ -173,6 +176,10 @@ export default function (seriesModel, r, viewWidth, viewHeight) { var labelLineLen = labelLineModel.get('length'); var labelLineLen2 = labelLineModel.get('length2'); + if (layout.angle < minShowLabelRadian) { + return; + } + var midAngle = (layout.startAngle + layout.endAngle) / 2; var dx = Math.cos(midAngle); var dy = Math.sin(midAngle); diff --git a/test/pie-label.html b/test/pie-label.html index 332b53ea8b87b3a9e639f891ad8db445683eb352..8df2a00750ebc6d7c494e0dbad4bc7b21a9b8065 100644 --- a/test/pie-label.html +++ b/test/pie-label.html @@ -41,6 +41,7 @@ under the License.
+ + + + + + + + + + +