TimelinePoint.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* *
  2. *
  3. * Timeline Series.
  4. *
  5. * (c) 2010-2021 Highsoft AS
  6. *
  7. * Author: Daniel Studencki
  8. *
  9. * License: www.highcharts.com/license
  10. *
  11. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  12. *
  13. * */
  14. 'use strict';
  15. var __extends = (this && this.__extends) || (function () {
  16. var extendStatics = function (d, b) {
  17. extendStatics = Object.setPrototypeOf ||
  18. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  19. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  20. return extendStatics(d, b);
  21. };
  22. return function (d, b) {
  23. extendStatics(d, b);
  24. function __() { this.constructor = d; }
  25. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  26. };
  27. })();
  28. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  29. var Series = SeriesRegistry.series, PiePoint = SeriesRegistry.seriesTypes.pie.prototype.pointClass;
  30. import U from '../../Core/Utilities.js';
  31. var defined = U.defined, isNumber = U.isNumber, merge = U.merge, objectEach = U.objectEach, pick = U.pick;
  32. /* *
  33. *
  34. * Class
  35. *
  36. * */
  37. var TimelinePoint = /** @class */ (function (_super) {
  38. __extends(TimelinePoint, _super);
  39. function TimelinePoint() {
  40. /* *
  41. *
  42. * Properties
  43. *
  44. * */
  45. var _this = _super !== null && _super.apply(this, arguments) || this;
  46. _this.options = void 0;
  47. _this.series = void 0;
  48. return _this;
  49. /* eslint-enable valid-jsdoc */
  50. }
  51. /* *
  52. *
  53. * Functions
  54. *
  55. * */
  56. /* eslint-disable valid-jsdoc */
  57. TimelinePoint.prototype.alignConnector = function () {
  58. var point = this, series = point.series, connector = point.connector, dl = point.dataLabel, dlOptions = point.dataLabel.options = merge(series.options.dataLabels, point.options.dataLabels), chart = point.series.chart, bBox = connector.getBBox(), plotPos = {
  59. x: bBox.x + dl.translateX,
  60. y: bBox.y + dl.translateY
  61. }, isVisible;
  62. // Include a half of connector width in order to run animation,
  63. // when connectors are aligned to the plot area edge.
  64. if (chart.inverted) {
  65. plotPos.y -= dl.options.connectorWidth / 2;
  66. }
  67. else {
  68. plotPos.x += dl.options.connectorWidth / 2;
  69. }
  70. isVisible = chart.isInsidePlot(plotPos.x, plotPos.y);
  71. connector[isVisible ? 'animate' : 'attr']({
  72. d: point.getConnectorPath()
  73. });
  74. if (!series.chart.styledMode) {
  75. connector.attr({
  76. stroke: dlOptions.connectorColor || point.color,
  77. 'stroke-width': dlOptions.connectorWidth,
  78. opacity: dl[defined(dl.newOpacity) ? 'newOpacity' : 'opacity']
  79. });
  80. }
  81. };
  82. TimelinePoint.prototype.drawConnector = function () {
  83. var point = this, series = point.series;
  84. if (!point.connector) {
  85. point.connector = series.chart.renderer
  86. .path(point.getConnectorPath())
  87. .attr({
  88. zIndex: -1
  89. })
  90. .add(point.dataLabel);
  91. }
  92. if (point.series.chart.isInsidePlot(// #10507
  93. point.dataLabel.x, point.dataLabel.y)) {
  94. point.alignConnector();
  95. }
  96. };
  97. TimelinePoint.prototype.getConnectorPath = function () {
  98. var point = this, chart = point.series.chart, xAxisLen = point.series.xAxis.len, inverted = chart.inverted, direction = inverted ? 'x2' : 'y2', dl = point.dataLabel, targetDLPos = dl.targetPosition, coords = {
  99. x1: point.plotX,
  100. y1: point.plotY,
  101. x2: point.plotX,
  102. y2: isNumber(targetDLPos.y) ? targetDLPos.y : dl.y
  103. }, negativeDistance = ((dl.alignAttr || dl)[direction[0]] <
  104. point.series.yAxis.len / 2), path;
  105. // Recalculate coords when the chart is inverted.
  106. if (inverted) {
  107. coords = {
  108. x1: point.plotY,
  109. y1: xAxisLen - point.plotX,
  110. x2: targetDLPos.x || dl.x,
  111. y2: xAxisLen - point.plotX
  112. };
  113. }
  114. // Subtract data label width or height from expected coordinate so
  115. // that the connector would start from the appropriate edge.
  116. if (negativeDistance) {
  117. coords[direction] += dl[inverted ? 'width' : 'height'];
  118. }
  119. // Change coordinates so that they will be relative to data label.
  120. objectEach(coords, function (_coord, i) {
  121. coords[i] -= (dl.alignAttr || dl)[i[0]];
  122. });
  123. path = chart.renderer.crispLine([
  124. ['M', coords.x1, coords.y1],
  125. ['L', coords.x2, coords.y2]
  126. ], dl.options.connectorWidth);
  127. return path;
  128. };
  129. TimelinePoint.prototype.init = function () {
  130. var point = _super.prototype.init.apply(this, arguments);
  131. point.name = pick(point.name, 'Event');
  132. point.y = 1;
  133. return point;
  134. };
  135. TimelinePoint.prototype.isValid = function () {
  136. return this.options.y !== null;
  137. };
  138. TimelinePoint.prototype.setState = function () {
  139. var proceed = _super.prototype.setState;
  140. // Prevent triggering the setState method on null points.
  141. if (!this.isNull) {
  142. proceed.apply(this, arguments);
  143. }
  144. };
  145. TimelinePoint.prototype.setVisible = function (visible, redraw) {
  146. var point = this, series = point.series;
  147. redraw = pick(redraw, series.options.ignoreHiddenPoint);
  148. PiePoint.prototype.setVisible.call(point, visible, false);
  149. // Process new data
  150. series.processData();
  151. if (redraw) {
  152. series.chart.redraw();
  153. }
  154. };
  155. return TimelinePoint;
  156. }(Series.prototype.pointClass));
  157. /* *
  158. *
  159. * Default Export
  160. *
  161. * */
  162. export default TimelinePoint;