diff --git a/src/chart/pie/PieSeries.ts b/src/chart/pie/PieSeries.ts index ed427bfff0..5d0fd4ade6 100644 --- a/src/chart/pie/PieSeries.ts +++ b/src/chart/pie/PieSeries.ts @@ -112,6 +112,7 @@ export interface PieSeriesOption extends clockwise?: boolean startAngle?: number + endAngle?: number | 'auto' minAngle?: number minShowLabelAngle?: number @@ -217,6 +218,7 @@ class PieSeriesModel extends SeriesModel { // 默认顺时针 clockwise: true, startAngle: 90, + endAngle: 'auto', // 最小角度改为0 minAngle: 0, diff --git a/src/chart/pie/pieLayout.ts b/src/chart/pie/pieLayout.ts index c5c52ccfcd..e81afae432 100644 --- a/src/chart/pie/pieLayout.ts +++ b/src/chart/pie/pieLayout.ts @@ -24,6 +24,7 @@ import GlobalModel from '../../model/Global'; import ExtensionAPI from '../../core/ExtensionAPI'; import PieSeriesModel from './PieSeries'; import { SectorShape } from 'zrender/src/graphic/shape/Sector'; +import { normalizeArcAngles } from 'zrender/src/core/PathProxy'; const PI2 = Math.PI * 2; const RADIAN = Math.PI / 180; @@ -91,7 +92,9 @@ export default function pieLayout( const { cx, cy, r, r0 } = getBasicPieLayout(seriesModel, api); - const startAngle = -seriesModel.get('startAngle') * RADIAN; + let startAngle = -seriesModel.get('startAngle') * RADIAN; + let endAngle = seriesModel.get('endAngle'); + endAngle = endAngle === 'auto' ? startAngle - PI2 : -endAngle * RADIAN; const minAngle = seriesModel.get('minAngle') * RADIAN; @@ -113,12 +116,19 @@ export default function pieLayout( const extent = data.getDataExtent(valueDim); extent[0] = 0; + const dir = clockwise ? 1 : -1; + const angles = [startAngle, endAngle]; + normalizeArcAngles(angles, !clockwise); + + [startAngle, endAngle] = angles; + + const angleRange = Math.abs(endAngle - startAngle); + // In the case some sector angle is smaller than minAngle - let restAngle = PI2; + let restAngle = angleRange; let valueSumLargerThanMinAngle = 0; let currentAngle = startAngle; - const dir = clockwise ? 1 : -1; data.setLayout({ viewRect, r }); @@ -146,7 +156,7 @@ export default function pieLayout( ? unitRadian : (value * unitRadian); } else { - angle = PI2 / validDataCount; + angle = angleRange / validDataCount; } if (angle < minAngle) { @@ -180,7 +190,7 @@ export default function pieLayout( // Average the angle if rest angle is not enough after all angles is // Constrained by minAngle if (restAngle <= 1e-3) { - const angle = PI2 / validDataCount; + const angle = angleRange / validDataCount; data.each(valueDim, function (value: number, idx: number) { if (!isNaN(value)) { const layout = data.getItemLayout(idx); diff --git a/test/pie-endAngle.html b/test/pie-endAngle.html new file mode 100644 index 0000000000..0d5ed987b0 --- /dev/null +++ b/test/pie-endAngle.html @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/test/runTest/actions/__meta__.json b/test/runTest/actions/__meta__.json index 7c9a89b242..562693a828 100644 --- a/test/runTest/actions/__meta__.json +++ b/test/runTest/actions/__meta__.json @@ -155,6 +155,7 @@ "pie-animation": 2, "pie-calculable": 1, "pie-cornerRadius": 1, + "pie-endAngle": 1, "pie-label": 2, "pie-label-extreme": 2, "pie-percent": 2, diff --git a/test/runTest/actions/pie-endAngle.json b/test/runTest/actions/pie-endAngle.json new file mode 100644 index 0000000000..8252f9f9e0 --- /dev/null +++ b/test/runTest/actions/pie-endAngle.json @@ -0,0 +1 @@ +[{"name":"Action 1","ops":[{"type":"mousemove","time":358,"x":603,"y":513},{"type":"mousemove","time":558,"x":610,"y":488},{"type":"screenshot","time":958},{"type":"mousemove","time":1083,"x":610,"y":488},{"type":"mousemove","time":1283,"x":724,"y":87},{"type":"mousemove","time":1485,"x":719,"y":79},{"type":"mousemove","time":1557,"x":719,"y":79},{"type":"mousemove","time":1759,"x":667,"y":46},{"type":"mousemove","time":1959,"x":671,"y":45},{"type":"mousemove","time":2161,"x":658,"y":58},{"type":"mousemove","time":2369,"x":634,"y":29},{"type":"mousemove","time":2574,"x":634,"y":22},{"type":"mousedown","time":2766,"x":638,"y":14},{"type":"mousemove","time":2775,"x":638,"y":14},{"type":"mouseup","time":2866,"x":638,"y":14},{"time":2867,"delay":400,"type":"screenshot-auto"},{"type":"screenshot","time":4014},{"type":"mousemove","time":4601,"x":639,"y":14},{"type":"mousemove","time":4802,"x":659,"y":25},{"type":"mousemove","time":5208,"x":659,"y":25},{"type":"mousemove","time":5408,"x":671,"y":56},{"type":"mousemove","time":5608,"x":669,"y":66},{"type":"mousemove","time":5819,"x":669,"y":67},{"type":"mousedown","time":6129,"x":669,"y":67},{"type":"mouseup","time":6287,"x":669,"y":67},{"time":6288,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":6816,"x":669,"y":67},{"type":"mousemove","time":7016,"x":669,"y":43},{"type":"mousemove","time":7216,"x":668,"y":56},{"type":"mousemove","time":7416,"x":670,"y":52},{"type":"mousemove","time":7617,"x":670,"y":44},{"type":"screenshot","time":7827},{"type":"mousemove","time":8092,"x":670,"y":44},{"type":"mousemove","time":8293,"x":636,"y":22},{"type":"mousedown","time":8494,"x":637,"y":13},{"type":"mousemove","time":8503,"x":637,"y":13},{"type":"mouseup","time":8602,"x":637,"y":13},{"time":8603,"delay":400,"type":"screenshot-auto"},{"type":"screenshot","time":9669},{"type":"mousemove","time":10116,"x":637,"y":14},{"type":"mousemove","time":10316,"x":666,"y":49},{"type":"mousemove","time":10516,"x":692,"y":42},{"type":"mousemove","time":10718,"x":692,"y":42},{"type":"mousemove","time":10935,"x":689,"y":43},{"type":"mousemove","time":11208,"x":689,"y":43},{"type":"mousedown","time":11328,"x":693,"y":41},{"type":"mousemove","time":11411,"x":693,"y":41},{"type":"mouseup","time":11420,"x":693,"y":41},{"time":11421,"delay":400,"type":"screenshot-auto"},{"type":"screenshot","time":13405},{"type":"mousemove","time":13541,"x":692,"y":41},{"type":"mousemove","time":13741,"x":657,"y":21},{"type":"mousemove","time":13947,"x":645,"y":17},{"type":"mousemove","time":14152,"x":640,"y":16},{"type":"mousedown","time":14161,"x":640,"y":16},{"type":"mouseup","time":14279,"x":640,"y":16},{"time":14280,"delay":400,"type":"screenshot-auto"},{"type":"screenshot","time":15711},{"type":"mousemove","time":16984,"x":640,"y":16},{"type":"mousemove","time":17317,"x":640,"y":16},{"type":"mousemove","time":17519,"x":640,"y":16},{"type":"mousemove","time":17701,"x":639,"y":16},{"type":"mousedown","time":19029,"x":639,"y":16},{"type":"mouseup","time":19161,"x":639,"y":16},{"time":19162,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":20342,"x":639,"y":16},{"type":"mousemove","time":20544,"x":672,"y":74},{"type":"mousemove","time":20753,"x":669,"y":75},{"type":"mousemove","time":20866,"x":668,"y":75},{"type":"mousemove","time":21068,"x":642,"y":77},{"type":"mousemove","time":21275,"x":641,"y":77},{"type":"mousemove","time":21478,"x":638,"y":77},{"type":"mousemove","time":21686,"x":633,"y":75},{"type":"mousemove","time":21808,"x":634,"y":75},{"type":"mousemove","time":22011,"x":638,"y":73},{"type":"mousemove","time":22275,"x":638,"y":73},{"type":"mousemove","time":22477,"x":632,"y":73},{"type":"mousemove","time":22686,"x":628,"y":73},{"type":"mousedown","time":22940,"x":628,"y":73},{"type":"mouseup","time":23079,"x":628,"y":73},{"time":23080,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":23475,"x":629,"y":72},{"type":"mousemove","time":23675,"x":719,"y":42},{"type":"mousemove","time":23877,"x":720,"y":42},{"type":"mousemove","time":23916,"x":720,"y":42},{"type":"mousemove","time":24118,"x":707,"y":46},{"type":"mousemove","time":24357,"x":709,"y":46},{"type":"mousedown","time":24398,"x":709,"y":46},{"type":"mousemove","time":24617,"x":709,"y":46},{"type":"mouseup","time":24756,"x":714,"y":46},{"time":24757,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":24820,"x":715,"y":46},{"type":"mousemove","time":25842,"x":712,"y":46},{"type":"screenshot","time":25847},{"type":"mousemove","time":26044,"x":666,"y":35},{"type":"mousemove","time":26252,"x":628,"y":24},{"type":"mousemove","time":26458,"x":637,"y":18},{"type":"mousedown","time":26527,"x":639,"y":15},{"type":"mouseup","time":26644,"x":639,"y":15},{"time":26645,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":26661,"x":639,"y":15},{"type":"screenshot","time":27811},{"type":"mousemove","time":28875,"x":639,"y":15},{"type":"mousemove","time":29749,"x":639,"y":15},{"type":"mousemove","time":29950,"x":642,"y":81},{"type":"mousemove","time":30152,"x":631,"y":82},{"type":"mousemove","time":30361,"x":625,"y":74},{"type":"mousedown","time":30554,"x":625,"y":74},{"type":"mousemove","time":30808,"x":625,"y":74},{"type":"mousemove","time":31011,"x":620,"y":74},{"type":"mousemove","time":31217,"x":618,"y":74},{"type":"mousemove","time":31417,"x":616,"y":74},{"type":"mouseup","time":31463,"x":615,"y":74},{"time":31464,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":31619,"x":615,"y":74},{"type":"mousemove","time":32657,"x":615,"y":74},{"type":"screenshot","time":32696},{"type":"mousemove","time":32858,"x":636,"y":24},{"type":"mousemove","time":33059,"x":637,"y":23},{"type":"mousemove","time":33259,"x":638,"y":14},{"type":"mousedown","time":33340,"x":638,"y":14},{"type":"mouseup","time":33466,"x":638,"y":14},{"time":33467,"delay":400,"type":"screenshot-auto"},{"type":"screenshot","time":34594},{"type":"mousemove","time":34766,"x":639,"y":14},{"type":"mousemove","time":34966,"x":707,"y":47},{"type":"mousemove","time":35166,"x":709,"y":47},{"type":"mousemove","time":35373,"x":711,"y":45},{"type":"mousemove","time":35499,"x":711,"y":45},{"type":"mousemove","time":35700,"x":706,"y":45},{"type":"mousemove","time":35903,"x":643,"y":46},{"type":"mousemove","time":36120,"x":624,"y":47},{"type":"mousemove","time":36333,"x":622,"y":47},{"type":"mousemove","time":36533,"x":621,"y":46},{"type":"mousemove","time":36736,"x":620,"y":46},{"type":"mousedown","time":36740,"x":620,"y":46},{"type":"mouseup","time":36889,"x":620,"y":46},{"time":36890,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":37109,"x":620,"y":46},{"type":"mousemove","time":37312,"x":620,"y":44},{"type":"mousemove","time":37418,"x":620,"y":44},{"type":"mousemove","time":37621,"x":622,"y":42},{"type":"mousedown","time":37717,"x":622,"y":42},{"type":"mouseup","time":37864,"x":622,"y":42},{"time":37865,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":38109,"x":622,"y":43},{"type":"mousemove","time":38309,"x":704,"y":85},{"type":"mousemove","time":38509,"x":710,"y":66},{"type":"mousemove","time":38711,"x":714,"y":63},{"type":"mousedown","time":38890,"x":714,"y":63},{"type":"mousemove","time":38928,"x":714,"y":63},{"type":"mouseup","time":38956,"x":714,"y":63},{"time":38957,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":39166,"x":714,"y":63},{"type":"mousemove","time":39369,"x":714,"y":67},{"type":"mousemove","time":39576,"x":712,"y":70},{"type":"mousedown","time":39830,"x":712,"y":70},{"type":"mouseup","time":39970,"x":712,"y":70},{"time":39971,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":40542,"x":712,"y":69},{"type":"mousemove","time":40744,"x":712,"y":68},{"type":"screenshot","time":40773},{"type":"mousemove","time":40791,"x":712,"y":68},{"type":"mousemove","time":40992,"x":712,"y":67},{"type":"mousemove","time":41192,"x":720,"y":81},{"type":"mousemove","time":41392,"x":719,"y":81},{"type":"mousemove","time":41593,"x":626,"y":40},{"type":"mousemove","time":41795,"x":626,"y":41},{"type":"mousedown","time":41921,"x":626,"y":41},{"type":"mousemove","time":42099,"x":626,"y":41},{"type":"mousemove","time":42300,"x":608,"y":41},{"type":"mouseup","time":42312,"x":608,"y":41},{"time":42313,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":42521,"x":608,"y":41},{"type":"mousemove","time":42618,"x":608,"y":41},{"type":"mousemove","time":42820,"x":640,"y":18},{"type":"mousemove","time":43029,"x":646,"y":14},{"type":"mousemove","time":43233,"x":709,"y":93},{"type":"mousemove","time":43437,"x":712,"y":85},{"type":"mousemove","time":43669,"x":712,"y":76},{"type":"mousemove","time":43886,"x":712,"y":75},{"type":"mousedown","time":43924,"x":712,"y":75},{"type":"mousemove","time":44067,"x":712,"y":75},{"type":"mouseup","time":44173,"x":747,"y":75},{"time":44174,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":44270,"x":749,"y":75},{"type":"mousemove","time":44483,"x":749,"y":75},{"type":"mousemove","time":44683,"x":662,"y":27},{"type":"mousemove","time":44883,"x":638,"y":17},{"type":"mousemove","time":45083,"x":637,"y":16},{"type":"mousemove","time":45293,"x":636,"y":16},{"type":"screenshot","time":45316},{"type":"mousedown","time":45700,"x":636,"y":16},{"type":"mouseup","time":45808,"x":636,"y":16},{"time":45809,"delay":400,"type":"screenshot-auto"},{"type":"screenshot","time":46896}],"scrollY":0,"scrollX":0,"timestamp":1688051759455}] \ No newline at end of file