PieSeries.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. /* *
  2. *
  3. * (c) 2010-2021 Torstein Honsi
  4. *
  5. * License: www.highcharts.com/license
  6. *
  7. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8. *
  9. * */
  10. 'use strict';
  11. var __extends = (this && this.__extends) || (function () {
  12. var extendStatics = function (d, b) {
  13. extendStatics = Object.setPrototypeOf ||
  14. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  15. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  16. return extendStatics(d, b);
  17. };
  18. return function (d, b) {
  19. extendStatics(d, b);
  20. function __() { this.constructor = d; }
  21. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  22. };
  23. })();
  24. import CenteredSeriesMixin from '../../Mixins/CenteredSeries.js';
  25. var getStartAndEndRadians = CenteredSeriesMixin.getStartAndEndRadians;
  26. import ColumnSeries from '../Column/ColumnSeries.js';
  27. import H from '../../Core/Globals.js';
  28. var noop = H.noop;
  29. import LegendSymbolMixin from '../../Mixins/LegendSymbol.js';
  30. import palette from '../../Core/Color/Palette.js';
  31. import PiePoint from './PiePoint.js';
  32. import Series from '../../Core/Series/Series.js';
  33. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  34. import SVGRenderer from '../../Core/Renderer/SVG/SVGRenderer.js';
  35. import U from '../../Core/Utilities.js';
  36. var clamp = U.clamp, extend = U.extend, fireEvent = U.fireEvent, merge = U.merge, pick = U.pick, relativeLength = U.relativeLength;
  37. import '../../Core/Options.js';
  38. /* *
  39. *
  40. * Class
  41. *
  42. * */
  43. /**
  44. * Pie series type.
  45. *
  46. * @private
  47. * @class
  48. * @name Highcharts.seriesTypes.pie
  49. *
  50. * @augments Highcharts.Series
  51. */
  52. var PieSeries = /** @class */ (function (_super) {
  53. __extends(PieSeries, _super);
  54. function PieSeries() {
  55. /* *
  56. *
  57. * Static Properties
  58. *
  59. * */
  60. var _this = _super !== null && _super.apply(this, arguments) || this;
  61. /* *
  62. *
  63. * Properties
  64. *
  65. * */
  66. _this.center = void 0;
  67. _this.data = void 0;
  68. _this.maxLabelDistance = void 0;
  69. _this.options = void 0;
  70. _this.points = void 0;
  71. return _this;
  72. /* eslint-enable valid-jsdoc */
  73. }
  74. /* *
  75. *
  76. * Functions
  77. *
  78. * */
  79. /* eslint-disable valid-jsdoc */
  80. /**
  81. * Animates the pies in.
  82. * @private
  83. */
  84. PieSeries.prototype.animate = function (init) {
  85. var series = this, points = series.points, startAngleRad = series.startAngleRad;
  86. if (!init) {
  87. points.forEach(function (point) {
  88. var graphic = point.graphic, args = point.shapeArgs;
  89. if (graphic && args) {
  90. // start values
  91. graphic.attr({
  92. // animate from inner radius (#779)
  93. r: pick(point.startR, (series.center && series.center[3] / 2)),
  94. start: startAngleRad,
  95. end: startAngleRad
  96. });
  97. // animate
  98. graphic.animate({
  99. r: args.r,
  100. start: args.start,
  101. end: args.end
  102. }, series.options.animation);
  103. }
  104. });
  105. }
  106. };
  107. /**
  108. * Called internally to draw auxiliary graph in pie-like series in
  109. * situtation when the default graph is not sufficient enough to present
  110. * the data well. Auxiliary graph is saved in the same object as
  111. * regular graph.
  112. * @private
  113. */
  114. PieSeries.prototype.drawEmpty = function () {
  115. var centerX, centerY, start = this.startAngleRad, end = this.endAngleRad, options = this.options;
  116. // Draw auxiliary graph if there're no visible points.
  117. if (this.total === 0 && this.center) {
  118. centerX = this.center[0];
  119. centerY = this.center[1];
  120. if (!this.graph) {
  121. this.graph = this.chart.renderer
  122. .arc(centerX, centerY, this.center[1] / 2, 0, start, end)
  123. .addClass('highcharts-empty-series')
  124. .add(this.group);
  125. }
  126. this.graph.attr({
  127. d: SVGRenderer.prototype.symbols.arc(centerX, centerY, this.center[2] / 2, 0, {
  128. start: start,
  129. end: end,
  130. innerR: this.center[3] / 2
  131. })
  132. });
  133. if (!this.chart.styledMode) {
  134. this.graph.attr({
  135. 'stroke-width': options.borderWidth,
  136. fill: options.fillColor || 'none',
  137. stroke: options.color ||
  138. palette.neutralColor20
  139. });
  140. }
  141. }
  142. else if (this.graph) { // Destroy the graph object.
  143. this.graph = this.graph.destroy();
  144. }
  145. };
  146. /**
  147. * Slices in pie chart are initialized in DOM, but it's shapes and
  148. * animations are normally run in `drawPoints()`.
  149. * @private
  150. */
  151. PieSeries.prototype.drawPoints = function () {
  152. var renderer = this.chart.renderer;
  153. this.points.forEach(function (point) {
  154. // When updating a series between 2d and 3d or cartesian and
  155. // polar, the shape type changes.
  156. if (point.graphic && point.hasNewShapeType()) {
  157. point.graphic = point.graphic.destroy();
  158. }
  159. if (!point.graphic) {
  160. point.graphic = renderer[point.shapeType](point.shapeArgs)
  161. .add(point.series.group);
  162. point.delayedRendering = true;
  163. }
  164. });
  165. };
  166. /**
  167. * Extend the generatePoints method by adding total and percentage
  168. * properties to each point
  169. * @private
  170. */
  171. PieSeries.prototype.generatePoints = function () {
  172. _super.prototype.generatePoints.call(this);
  173. this.updateTotals();
  174. };
  175. /**
  176. * Utility for getting the x value from a given y, used for
  177. * anticollision logic in data labels. Added point for using specific
  178. * points' label distance.
  179. * @private
  180. */
  181. PieSeries.prototype.getX = function (y, left, point) {
  182. var center = this.center,
  183. // Variable pie has individual radius
  184. radius = this.radii ?
  185. this.radii[point.index] || 0 :
  186. center[2] / 2, angle, x;
  187. angle = Math.asin(clamp((y - center[1]) / (radius + point.labelDistance), -1, 1));
  188. x = center[0] +
  189. (left ? -1 : 1) *
  190. (Math.cos(angle) * (radius + point.labelDistance)) +
  191. (point.labelDistance > 0 ?
  192. (left ? -1 : 1) * this.options.dataLabels.padding :
  193. 0);
  194. return x;
  195. };
  196. /**
  197. * Define hasData function for non-cartesian series. Returns true if the
  198. * series has points at all.
  199. * @private
  200. */
  201. PieSeries.prototype.hasData = function () {
  202. return !!this.processedXData.length; // != 0
  203. };
  204. /**
  205. * Draw the data points
  206. * @private
  207. */
  208. PieSeries.prototype.redrawPoints = function () {
  209. var series = this, chart = series.chart, renderer = chart.renderer, groupTranslation, graphic, pointAttr, shapeArgs, shadow = series.options.shadow;
  210. this.drawEmpty();
  211. if (shadow && !series.shadowGroup && !chart.styledMode) {
  212. series.shadowGroup = renderer
  213. .g('shadow')
  214. .attr({ zIndex: -1 })
  215. .add(series.group);
  216. }
  217. // draw the slices
  218. series.points.forEach(function (point) {
  219. var animateTo = {};
  220. graphic = point.graphic;
  221. if (!point.isNull && graphic) {
  222. shapeArgs = point.shapeArgs;
  223. // If the point is sliced, use special translation, else use
  224. // plot area translation
  225. groupTranslation = point.getTranslate();
  226. if (!chart.styledMode) {
  227. // Put the shadow behind all points
  228. var shadowGroup = point.shadowGroup;
  229. if (shadow && !shadowGroup) {
  230. shadowGroup = point.shadowGroup = renderer
  231. .g('shadow')
  232. .add(series.shadowGroup);
  233. }
  234. if (shadowGroup) {
  235. shadowGroup.attr(groupTranslation);
  236. }
  237. pointAttr = series.pointAttribs(point, (point.selected && 'select'));
  238. }
  239. // Draw the slice
  240. if (!point.delayedRendering) {
  241. graphic
  242. .setRadialReference(series.center);
  243. if (!chart.styledMode) {
  244. merge(true, animateTo, pointAttr);
  245. }
  246. merge(true, animateTo, shapeArgs, groupTranslation);
  247. graphic.animate(animateTo);
  248. }
  249. else {
  250. graphic
  251. .setRadialReference(series.center)
  252. .attr(shapeArgs)
  253. .attr(groupTranslation);
  254. if (!chart.styledMode) {
  255. graphic
  256. .attr(pointAttr)
  257. .attr({ 'stroke-linejoin': 'round' })
  258. .shadow(shadow, shadowGroup);
  259. }
  260. point.delayedRendering = false;
  261. }
  262. graphic.attr({
  263. visibility: point.visible ? 'inherit' : 'hidden'
  264. });
  265. graphic.addClass(point.getClassName(), true);
  266. }
  267. else if (graphic) {
  268. point.graphic = graphic.destroy();
  269. }
  270. });
  271. };
  272. /**
  273. * Utility for sorting data labels.
  274. * @private
  275. */
  276. PieSeries.prototype.sortByAngle = function (points, sign) {
  277. points.sort(function (a, b) {
  278. return ((typeof a.angle !== 'undefined') &&
  279. (b.angle - a.angle) * sign);
  280. });
  281. };
  282. /**
  283. * Do translation for pie slices
  284. * @private
  285. */
  286. PieSeries.prototype.translate = function (positions) {
  287. this.generatePoints();
  288. var series = this, cumulative = 0, precision = 1000, // issue #172
  289. options = series.options, slicedOffset = options.slicedOffset, connectorOffset = slicedOffset + (options.borderWidth || 0), finalConnectorOffset, start, end, angle, radians = getStartAndEndRadians(options.startAngle, options.endAngle), startAngleRad = series.startAngleRad = radians.start, endAngleRad = series.endAngleRad = radians.end, circ = endAngleRad - startAngleRad, // 2 * Math.PI,
  290. points = series.points,
  291. // the x component of the radius vector for a given point
  292. radiusX, radiusY, labelDistance = options.dataLabels.distance, ignoreHiddenPoint = options.ignoreHiddenPoint, i, len = points.length, point;
  293. // Get positions - either an integer or a percentage string must be
  294. // given. If positions are passed as a parameter, we're in a
  295. // recursive loop for adjusting space for data labels.
  296. if (!positions) {
  297. series.center = positions = series.getCenter();
  298. }
  299. // Calculate the geometry for each point
  300. for (i = 0; i < len; i++) {
  301. point = points[i];
  302. // set start and end angle
  303. start = startAngleRad + (cumulative * circ);
  304. if (point.isValid() &&
  305. (!ignoreHiddenPoint || point.visible)) {
  306. cumulative += point.percentage / 100;
  307. }
  308. end = startAngleRad + (cumulative * circ);
  309. // set the shape
  310. point.shapeType = 'arc';
  311. point.shapeArgs = {
  312. x: positions[0],
  313. y: positions[1],
  314. r: positions[2] / 2,
  315. innerR: positions[3] / 2,
  316. start: Math.round(start * precision) / precision,
  317. end: Math.round(end * precision) / precision
  318. };
  319. // Used for distance calculation for specific point.
  320. point.labelDistance = pick((point.options.dataLabels &&
  321. point.options.dataLabels.distance), labelDistance);
  322. // Compute point.labelDistance if it's defined as percentage
  323. // of slice radius (#8854)
  324. point.labelDistance = relativeLength(point.labelDistance, point.shapeArgs.r);
  325. // Saved for later dataLabels distance calculation.
  326. series.maxLabelDistance = Math.max(series.maxLabelDistance || 0, point.labelDistance);
  327. // The angle must stay within -90 and 270 (#2645)
  328. angle = (end + start) / 2;
  329. if (angle > 1.5 * Math.PI) {
  330. angle -= 2 * Math.PI;
  331. }
  332. else if (angle < -Math.PI / 2) {
  333. angle += 2 * Math.PI;
  334. }
  335. // Center for the sliced out slice
  336. point.slicedTranslation = {
  337. translateX: Math.round(Math.cos(angle) * slicedOffset),
  338. translateY: Math.round(Math.sin(angle) * slicedOffset)
  339. };
  340. // set the anchor point for tooltips
  341. radiusX = Math.cos(angle) * positions[2] / 2;
  342. radiusY = Math.sin(angle) * positions[2] / 2;
  343. point.tooltipPos = [
  344. positions[0] + radiusX * 0.7,
  345. positions[1] + radiusY * 0.7
  346. ];
  347. point.half = angle < -Math.PI / 2 || angle > Math.PI / 2 ?
  348. 1 :
  349. 0;
  350. point.angle = angle;
  351. // Set the anchor point for data labels. Use point.labelDistance
  352. // instead of labelDistance // #1174
  353. // finalConnectorOffset - not override connectorOffset value.
  354. finalConnectorOffset = Math.min(connectorOffset, point.labelDistance / 5); // #1678
  355. point.labelPosition = {
  356. natural: {
  357. // initial position of the data label - it's utilized for
  358. // finding the final position for the label
  359. x: positions[0] + radiusX + Math.cos(angle) *
  360. point.labelDistance,
  361. y: positions[1] + radiusY + Math.sin(angle) *
  362. point.labelDistance
  363. },
  364. 'final': {
  365. // used for generating connector path -
  366. // initialized later in drawDataLabels function
  367. // x: undefined,
  368. // y: undefined
  369. },
  370. // left - pie on the left side of the data label
  371. // right - pie on the right side of the data label
  372. // center - data label overlaps the pie
  373. alignment: point.labelDistance < 0 ?
  374. 'center' : point.half ? 'right' : 'left',
  375. connectorPosition: {
  376. breakAt: {
  377. x: positions[0] + radiusX + Math.cos(angle) *
  378. finalConnectorOffset,
  379. y: positions[1] + radiusY + Math.sin(angle) *
  380. finalConnectorOffset
  381. },
  382. touchingSliceAt: {
  383. x: positions[0] + radiusX,
  384. y: positions[1] + radiusY
  385. }
  386. }
  387. };
  388. }
  389. fireEvent(series, 'afterTranslate');
  390. };
  391. /**
  392. * Recompute total chart sum and update percentages of points.
  393. * @private
  394. */
  395. PieSeries.prototype.updateTotals = function () {
  396. var i, total = 0, points = this.points, len = points.length, point, ignoreHiddenPoint = this.options.ignoreHiddenPoint;
  397. // Get the total sum
  398. for (i = 0; i < len; i++) {
  399. point = points[i];
  400. if (point.isValid() &&
  401. (!ignoreHiddenPoint || point.visible)) {
  402. total += point.y;
  403. }
  404. }
  405. this.total = total;
  406. // Set each point's properties
  407. for (i = 0; i < len; i++) {
  408. point = points[i];
  409. point.percentage =
  410. (total > 0 && (point.visible || !ignoreHiddenPoint)) ?
  411. point.y / total * 100 :
  412. 0;
  413. point.total = total;
  414. }
  415. };
  416. /**
  417. * A pie chart is a circular graphic which is divided into slices to
  418. * illustrate numerical proportion.
  419. *
  420. * @sample highcharts/demo/pie-basic/
  421. * Pie chart
  422. *
  423. * @extends plotOptions.line
  424. * @excluding animationLimit, boostThreshold, connectEnds, connectNulls,
  425. * cropThreshold, dashStyle, dataSorting, dragDrop,
  426. * findNearestPointBy, getExtremesFromAll, label, lineWidth,
  427. * marker, negativeColor, pointInterval, pointIntervalUnit,
  428. * pointPlacement, pointStart, softThreshold, stacking, step,
  429. * threshold, turboThreshold, zoneAxis, zones, dataSorting,
  430. * boostBlending
  431. * @product highcharts
  432. * @optionparent plotOptions.pie
  433. */
  434. PieSeries.defaultOptions = merge(Series.defaultOptions, {
  435. /**
  436. * @excluding legendItemClick
  437. * @apioption plotOptions.pie.events
  438. */
  439. /**
  440. * Fires when the checkbox next to the point name in the legend is
  441. * clicked. One parameter, event, is passed to the function. The state
  442. * of the checkbox is found by event.checked. The checked item is found
  443. * by event.item. Return false to prevent the default action which is to
  444. * toggle the select state of the series.
  445. *
  446. * @sample {highcharts} highcharts/plotoptions/series-events-checkboxclick/
  447. * Alert checkbox status
  448. *
  449. * @type {Function}
  450. * @since 1.2.0
  451. * @product highcharts
  452. * @context Highcharts.Point
  453. * @apioption plotOptions.pie.events.checkboxClick
  454. */
  455. /**
  456. * Fires when the legend item belonging to the pie point (slice) is
  457. * clicked. The `this` keyword refers to the point itself. One
  458. * parameter, `event`, is passed to the function, containing common
  459. * event information. The default action is to toggle the visibility of
  460. * the point. This can be prevented by calling `event.preventDefault()`.
  461. *
  462. * @sample {highcharts} highcharts/plotoptions/pie-point-events-legenditemclick/
  463. * Confirm toggle visibility
  464. *
  465. * @type {Highcharts.PointLegendItemClickCallbackFunction}
  466. * @since 1.2.0
  467. * @product highcharts
  468. * @apioption plotOptions.pie.point.events.legendItemClick
  469. */
  470. /**
  471. * The center of the pie chart relative to the plot area. Can be
  472. * percentages or pixel values. The default behaviour (as of 3.0) is to
  473. * center the pie so that all slices and data labels are within the plot
  474. * area. As a consequence, the pie may actually jump around in a chart
  475. * with dynamic values, as the data labels move. In that case, the
  476. * center should be explicitly set, for example to `["50%", "50%"]`.
  477. *
  478. * @sample {highcharts} highcharts/plotoptions/pie-center/
  479. * Centered at 100, 100
  480. *
  481. * @type {Array<(number|string|null),(number|string|null)>}
  482. * @default [null, null]
  483. * @product highcharts
  484. *
  485. * @private
  486. */
  487. center: [null, null],
  488. /**
  489. * The color of the pie series. A pie series is represented as an empty
  490. * circle if the total sum of its values is 0. Use this property to
  491. * define the color of its border.
  492. *
  493. * In styled mode, the color can be defined by the
  494. * [colorIndex](#plotOptions.series.colorIndex) option. Also, the series
  495. * color can be set with the `.highcharts-series`,
  496. * `.highcharts-color-{n}`, `.highcharts-{type}-series` or
  497. * `.highcharts-series-{n}` class, or individual classes given by the
  498. * `className` option.
  499. *
  500. * @sample {highcharts} highcharts/plotoptions/pie-emptyseries/
  501. * Empty pie series
  502. *
  503. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  504. * @default ${palette.neutralColor20}
  505. * @apioption plotOptions.pie.color
  506. */
  507. /**
  508. * @product highcharts
  509. *
  510. * @private
  511. */
  512. clip: false,
  513. /**
  514. * @ignore-option
  515. *
  516. * @private
  517. */
  518. colorByPoint: true,
  519. /**
  520. * A series specific or series type specific color set to use instead
  521. * of the global [colors](#colors).
  522. *
  523. * @sample {highcharts} highcharts/demo/pie-monochrome/
  524. * Set default colors for all pies
  525. *
  526. * @type {Array<Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject>}
  527. * @since 3.0
  528. * @product highcharts
  529. * @apioption plotOptions.pie.colors
  530. */
  531. /**
  532. * @declare Highcharts.SeriesPieDataLabelsOptionsObject
  533. * @extends plotOptions.series.dataLabels
  534. * @excluding align, allowOverlap, inside, staggerLines, step
  535. * @private
  536. */
  537. dataLabels: {
  538. /**
  539. * Alignment method for data labels. Possible values are:
  540. *
  541. * - `toPlotEdges`: Each label touches the nearest vertical edge of
  542. * the plot area.
  543. *
  544. * - `connectors`: Connectors have the same x position and the
  545. * widest label of each half (left & right) touches the nearest
  546. * vertical edge of the plot area.
  547. *
  548. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-alignto-connectors/
  549. * alignTo: connectors
  550. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-alignto-plotedges/
  551. * alignTo: plotEdges
  552. *
  553. * @type {string}
  554. * @since 7.0.0
  555. * @product highcharts
  556. * @apioption plotOptions.pie.dataLabels.alignTo
  557. */
  558. allowOverlap: true,
  559. /**
  560. * The color of the line connecting the data label to the pie slice.
  561. * The default color is the same as the point's color.
  562. *
  563. * In styled mode, the connector stroke is given in the
  564. * `.highcharts-data-label-connector` class.
  565. *
  566. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-connectorcolor/
  567. * Blue connectors
  568. * @sample {highcharts} highcharts/css/pie-point/
  569. * Styled connectors
  570. *
  571. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  572. * @since 2.1
  573. * @product highcharts
  574. * @apioption plotOptions.pie.dataLabels.connectorColor
  575. */
  576. /**
  577. * The distance from the data label to the connector. Note that
  578. * data labels also have a default `padding`, so in order for the
  579. * connector to touch the text, the `padding` must also be 0.
  580. *
  581. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-connectorpadding/
  582. * No padding
  583. *
  584. * @since 2.1
  585. * @product highcharts
  586. */
  587. connectorPadding: 5,
  588. /**
  589. * Specifies the method that is used to generate the connector path.
  590. * Highcharts provides 3 built-in connector shapes: `'fixedOffset'`
  591. * (default), `'straight'` and `'crookedLine'`. Using
  592. * `'crookedLine'` has the most sense (in most of the cases) when
  593. * `'alignTo'` is set.
  594. *
  595. * Users can provide their own method by passing a function instead
  596. * of a String. 3 arguments are passed to the callback:
  597. *
  598. * - Object that holds the information about the coordinates of the
  599. * label (`x` & `y` properties) and how the label is located in
  600. * relation to the pie (`alignment` property). `alignment` can by
  601. * one of the following:
  602. * `'left'` (pie on the left side of the data label),
  603. * `'right'` (pie on the right side of the data label) or
  604. * `'center'` (data label overlaps the pie).
  605. *
  606. * - Object that holds the information about the position of the
  607. * connector. Its `touchingSliceAt` porperty tells the position
  608. * of the place where the connector touches the slice.
  609. *
  610. * - Data label options
  611. *
  612. * The function has to return an SVG path definition in array form
  613. * (see the example).
  614. *
  615. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-connectorshape-string/
  616. * connectorShape is a String
  617. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-connectorshape-function/
  618. * connectorShape is a function
  619. *
  620. * @type {string|Function}
  621. * @since 7.0.0
  622. * @product highcharts
  623. */
  624. connectorShape: 'fixedOffset',
  625. /**
  626. * The width of the line connecting the data label to the pie slice.
  627. *
  628. * In styled mode, the connector stroke width is given in the
  629. * `.highcharts-data-label-connector` class.
  630. *
  631. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-connectorwidth-disabled/
  632. * Disable the connector
  633. * @sample {highcharts} highcharts/css/pie-point/
  634. * Styled connectors
  635. *
  636. * @type {number}
  637. * @default 1
  638. * @since 2.1
  639. * @product highcharts
  640. * @apioption plotOptions.pie.dataLabels.connectorWidth
  641. */
  642. /**
  643. * Works only if `connectorShape` is `'crookedLine'`. It defines how
  644. * far from the vertical plot edge the coonnector path should be
  645. * crooked.
  646. *
  647. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-crookdistance/
  648. * crookDistance set to 90%
  649. *
  650. * @since 7.0.0
  651. * @product highcharts
  652. */
  653. crookDistance: '70%',
  654. /**
  655. * The distance of the data label from the pie's edge. Negative
  656. * numbers put the data label on top of the pie slices. Can also be
  657. * defined as a percentage of pie's radius. Connectors are only
  658. * shown for data labels outside the pie.
  659. *
  660. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-distance/
  661. * Data labels on top of the pie
  662. *
  663. * @type {number|string}
  664. * @since 2.1
  665. * @product highcharts
  666. */
  667. distance: 30,
  668. enabled: true,
  669. /**
  670. * A
  671. * [format string](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting)
  672. * for the data label. Available variables are the same as for
  673. * `formatter`.
  674. *
  675. * @sample {highcharts} highcharts/plotoptions/series-datalabels-format/
  676. * Add a unit
  677. *
  678. * @type {string}
  679. * @default undefined
  680. * @since 3.0
  681. * @apioption plotOptions.pie.dataLabels.format
  682. */
  683. // eslint-disable-next-line valid-jsdoc
  684. /**
  685. * Callback JavaScript function to format the data label. Note that
  686. * if a `format` is defined, the format takes precedence and the
  687. * formatter is ignored.
  688. *
  689. * @type {Highcharts.DataLabelsFormatterCallbackFunction}
  690. * @default function () { return this.point.isNull ? void 0 : this.point.name; }
  691. */
  692. formatter: function () {
  693. return this.point.isNull ? void 0 : this.point.name;
  694. },
  695. /**
  696. * Whether to render the connector as a soft arc or a line with
  697. * sharp break. Works only if `connectorShape` equals to
  698. * `fixedOffset`.
  699. *
  700. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-softconnector-true/
  701. * Soft
  702. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-softconnector-false/
  703. * Non soft
  704. *
  705. * @since 2.1.7
  706. * @product highcharts
  707. */
  708. softConnector: true,
  709. /**
  710. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-overflow
  711. * Long labels truncated with an ellipsis
  712. * @sample {highcharts} highcharts/plotoptions/pie-datalabels-overflow-wrap
  713. * Long labels are wrapped
  714. *
  715. * @type {Highcharts.CSSObject}
  716. * @apioption plotOptions.pie.dataLabels.style
  717. */
  718. x: 0
  719. },
  720. /**
  721. * If the total sum of the pie's values is 0, the series is represented
  722. * as an empty circle . The `fillColor` option defines the color of that
  723. * circle. Use [pie.borderWidth](#plotOptions.pie.borderWidth) to set
  724. * the border thickness.
  725. *
  726. * @sample {highcharts} highcharts/plotoptions/pie-emptyseries/
  727. * Empty pie series
  728. *
  729. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  730. * @private
  731. */
  732. fillColor: void 0,
  733. /**
  734. * The end angle of the pie in degrees where 0 is top and 90 is right.
  735. * Defaults to `startAngle` plus 360.
  736. *
  737. * @sample {highcharts} highcharts/demo/pie-semi-circle/
  738. * Semi-circle donut
  739. *
  740. * @type {number}
  741. * @since 1.3.6
  742. * @product highcharts
  743. * @apioption plotOptions.pie.endAngle
  744. */
  745. /**
  746. * Equivalent to [chart.ignoreHiddenSeries](#chart.ignoreHiddenSeries),
  747. * this option tells whether the series shall be redrawn as if the
  748. * hidden point were `null`.
  749. *
  750. * The default value changed from `false` to `true` with Highcharts
  751. * 3.0.
  752. *
  753. * @sample {highcharts} highcharts/plotoptions/pie-ignorehiddenpoint/
  754. * True, the hiddden point is ignored
  755. *
  756. * @since 2.3.0
  757. * @product highcharts
  758. *
  759. * @private
  760. */
  761. ignoreHiddenPoint: true,
  762. /**
  763. * @ignore-option
  764. *
  765. * @private
  766. */
  767. inactiveOtherPoints: true,
  768. /**
  769. * The size of the inner diameter for the pie. A size greater than 0
  770. * renders a donut chart. Can be a percentage or pixel value.
  771. * Percentages are relative to the pie size. Pixel values are given as
  772. * integers.
  773. *
  774. *
  775. * Note: in Highcharts < 4.1.2, the percentage was relative to the plot
  776. * area, not the pie size.
  777. *
  778. * @sample {highcharts} highcharts/plotoptions/pie-innersize-80px/
  779. * 80px inner size
  780. * @sample {highcharts} highcharts/plotoptions/pie-innersize-50percent/
  781. * 50% of the plot area
  782. * @sample {highcharts} highcharts/demo/3d-pie-donut/
  783. * 3D donut
  784. *
  785. * @type {number|string}
  786. * @default 0
  787. * @since 2.0
  788. * @product highcharts
  789. * @apioption plotOptions.pie.innerSize
  790. */
  791. /**
  792. * @ignore-option
  793. *
  794. * @private
  795. */
  796. legendType: 'point',
  797. /**
  798. * @ignore-option
  799. *
  800. * @private
  801. */
  802. marker: null,
  803. /**
  804. * The minimum size for a pie in response to auto margins. The pie will
  805. * try to shrink to make room for data labels in side the plot area,
  806. * but only to this size.
  807. *
  808. * @type {number|string}
  809. * @default 80
  810. * @since 3.0
  811. * @product highcharts
  812. * @apioption plotOptions.pie.minSize
  813. */
  814. /**
  815. * The diameter of the pie relative to the plot area. Can be a
  816. * percentage or pixel value. Pixel values are given as integers. The
  817. * default behaviour (as of 3.0) is to scale to the plot area and give
  818. * room for data labels within the plot area.
  819. * [slicedOffset](#plotOptions.pie.slicedOffset) is also included in the
  820. * default size calculation. As a consequence, the size of the pie may
  821. * vary when points are updated and data labels more around. In that
  822. * case it is best to set a fixed value, for example `"75%"`.
  823. *
  824. * @sample {highcharts} highcharts/plotoptions/pie-size/
  825. * Smaller pie
  826. *
  827. * @type {number|string|null}
  828. * @product highcharts
  829. *
  830. * @private
  831. */
  832. size: null,
  833. /**
  834. * Whether to display this particular series or series type in the
  835. * legend. Since 2.1, pies are not shown in the legend by default.
  836. *
  837. * @sample {highcharts} highcharts/plotoptions/series-showinlegend/
  838. * One series in the legend, one hidden
  839. *
  840. * @product highcharts
  841. *
  842. * @private
  843. */
  844. showInLegend: false,
  845. /**
  846. * If a point is sliced, moved out from the center, how many pixels
  847. * should it be moved?.
  848. *
  849. * @sample {highcharts} highcharts/plotoptions/pie-slicedoffset-20/
  850. * 20px offset
  851. *
  852. * @product highcharts
  853. *
  854. * @private
  855. */
  856. slicedOffset: 10,
  857. /**
  858. * The start angle of the pie slices in degrees where 0 is top and 90
  859. * right.
  860. *
  861. * @sample {highcharts} highcharts/plotoptions/pie-startangle-90/
  862. * Start from right
  863. *
  864. * @type {number}
  865. * @default 0
  866. * @since 2.3.4
  867. * @product highcharts
  868. * @apioption plotOptions.pie.startAngle
  869. */
  870. /**
  871. * Sticky tracking of mouse events. When true, the `mouseOut` event
  872. * on a series isn't triggered until the mouse moves over another
  873. * series, or out of the plot area. When false, the `mouseOut` event on
  874. * a series is triggered when the mouse leaves the area around the
  875. * series' graph or markers. This also implies the tooltip. When
  876. * `stickyTracking` is false and `tooltip.shared` is false, the tooltip
  877. * will be hidden when moving the mouse between series.
  878. *
  879. * @product highcharts
  880. *
  881. * @private
  882. */
  883. stickyTracking: false,
  884. tooltip: {
  885. followPointer: true
  886. },
  887. /**
  888. * The color of the border surrounding each slice. When `null`, the
  889. * border takes the same color as the slice fill. This can be used
  890. * together with a `borderWidth` to fill drawing gaps created by
  891. * antialiazing artefacts in borderless pies.
  892. *
  893. * In styled mode, the border stroke is given in the `.highcharts-point`
  894. * class.
  895. *
  896. * @sample {highcharts} highcharts/plotoptions/pie-bordercolor-black/
  897. * Black border
  898. *
  899. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  900. * @default #ffffff
  901. * @product highcharts
  902. *
  903. * @private
  904. */
  905. borderColor: palette.backgroundColor,
  906. /**
  907. * The width of the border surrounding each slice.
  908. *
  909. * When setting the border width to 0, there may be small gaps between
  910. * the slices due to SVG antialiasing artefacts. To work around this,
  911. * keep the border width at 0.5 or 1, but set the `borderColor` to
  912. * `null` instead.
  913. *
  914. * In styled mode, the border stroke width is given in the
  915. * `.highcharts-point` class.
  916. *
  917. * @sample {highcharts} highcharts/plotoptions/pie-borderwidth/
  918. * 3px border
  919. *
  920. * @product highcharts
  921. *
  922. * @private
  923. */
  924. borderWidth: 1,
  925. /**
  926. * @ignore-options
  927. * @private
  928. */
  929. lineWidth: void 0,
  930. states: {
  931. /**
  932. * @extends plotOptions.series.states.hover
  933. * @excluding marker, lineWidth, lineWidthPlus
  934. * @product highcharts
  935. */
  936. hover: {
  937. /**
  938. * How much to brighten the point on interaction. Requires the
  939. * main color to be defined in hex or rgb(a) format.
  940. *
  941. * In styled mode, the hover brightness is by default replaced
  942. * by a fill-opacity given in the `.highcharts-point-hover`
  943. * class.
  944. *
  945. * @sample {highcharts} highcharts/plotoptions/pie-states-hover-brightness/
  946. * Brightened by 0.5
  947. *
  948. * @product highcharts
  949. */
  950. brightness: 0.1
  951. }
  952. }
  953. });
  954. return PieSeries;
  955. }(Series));
  956. extend(PieSeries.prototype, {
  957. axisTypes: [],
  958. directTouch: true,
  959. drawGraph: null,
  960. drawLegendSymbol: LegendSymbolMixin.drawRectangle,
  961. drawTracker: ColumnSeries.prototype.drawTracker,
  962. getCenter: CenteredSeriesMixin.getCenter,
  963. getSymbol: noop,
  964. isCartesian: false,
  965. noSharedTooltip: true,
  966. pointAttribs: ColumnSeries.prototype.pointAttribs,
  967. pointClass: PiePoint,
  968. requireSorting: false,
  969. searchPoint: noop,
  970. trackerGroups: ['group', 'dataLabelsGroup']
  971. });
  972. SeriesRegistry.registerSeriesType('pie', PieSeries);
  973. /* *
  974. *
  975. * Default Export
  976. *
  977. * */
  978. export default PieSeries;
  979. /* *
  980. *
  981. * API Options
  982. *
  983. * */
  984. /**
  985. * A `pie` series. If the [type](#series.pie.type) option is not specified,
  986. * it is inherited from [chart.type](#chart.type).
  987. *
  988. * @extends series,plotOptions.pie
  989. * @excluding cropThreshold, dataParser, dataURL, stack, xAxis, yAxis,
  990. * dataSorting, step, boostThreshold, boostBlending
  991. * @product highcharts
  992. * @apioption series.pie
  993. */
  994. /**
  995. * An array of data points for the series. For the `pie` series type,
  996. * points can be given in the following ways:
  997. *
  998. * 1. An array of numerical values. In this case, the numerical values will be
  999. * interpreted as `y` options. Example:
  1000. * ```js
  1001. * data: [0, 5, 3, 5]
  1002. * ```
  1003. *
  1004. * 2. An array of objects with named values. The following snippet shows only a
  1005. * few settings, see the complete options set below. If the total number of
  1006. * data points exceeds the series'
  1007. * [turboThreshold](#series.pie.turboThreshold),
  1008. * this option is not available.
  1009. * ```js
  1010. * data: [{
  1011. * y: 1,
  1012. * name: "Point2",
  1013. * color: "#00FF00"
  1014. * }, {
  1015. * y: 7,
  1016. * name: "Point1",
  1017. * color: "#FF00FF"
  1018. * }]
  1019. * ```
  1020. *
  1021. * @sample {highcharts} highcharts/chart/reflow-true/
  1022. * Numerical values
  1023. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  1024. * Arrays of numeric x and y
  1025. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  1026. * Arrays of datetime x and y
  1027. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  1028. * Arrays of point.name and y
  1029. * @sample {highcharts} highcharts/series/data-array-of-objects/
  1030. * Config objects
  1031. *
  1032. * @type {Array<number|Array<string,(number|null)>|null|*>}
  1033. * @extends series.line.data
  1034. * @excluding marker, x
  1035. * @product highcharts
  1036. * @apioption series.pie.data
  1037. */
  1038. /**
  1039. * @type {Highcharts.SeriesPieDataLabelsOptionsObject}
  1040. * @product highcharts
  1041. * @apioption series.pie.data.dataLabels
  1042. */
  1043. /**
  1044. * The sequential index of the data point in the legend.
  1045. *
  1046. * @type {number}
  1047. * @product highcharts
  1048. * @apioption series.pie.data.legendIndex
  1049. */
  1050. /**
  1051. * Whether to display a slice offset from the center.
  1052. *
  1053. * @sample {highcharts} highcharts/point/sliced/
  1054. * One sliced point
  1055. *
  1056. * @type {boolean}
  1057. * @product highcharts
  1058. * @apioption series.pie.data.sliced
  1059. */
  1060. /**
  1061. * @extends plotOptions.pie.dataLabels
  1062. * @excluding align, allowOverlap, inside, staggerLines, step
  1063. * @product highcharts
  1064. * @apioption series.pie.dataLabels
  1065. */
  1066. /**
  1067. * @excluding legendItemClick
  1068. * @product highcharts
  1069. * @apioption series.pie.events
  1070. */
  1071. ''; // placeholder for transpiled doclets above