GanttSeries.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /* *
  2. *
  3. * (c) 2016-2021 Highsoft AS
  4. *
  5. * Author: Lars A. V. Cabrera
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. 'use strict';
  13. var __extends = (this && this.__extends) || (function () {
  14. var extendStatics = function (d, b) {
  15. extendStatics = Object.setPrototypeOf ||
  16. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  17. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  18. return extendStatics(d, b);
  19. };
  20. return function (d, b) {
  21. extendStatics(d, b);
  22. function __() { this.constructor = d; }
  23. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  24. };
  25. })();
  26. import GanttPoint from './GanttPoint.js';
  27. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  28. var Series = SeriesRegistry.series, XRangeSeries = SeriesRegistry.seriesTypes.xrange;
  29. import U from '../../Core/Utilities.js';
  30. var extend = U.extend, isNumber = U.isNumber, merge = U.merge, splat = U.splat;
  31. import '../../Core/Axis/TreeGridAxis.js';
  32. import '../../Extensions/CurrentDateIndication.js';
  33. import '../../Extensions/StaticScale.js';
  34. import '../../Gantt/Pathfinder.js';
  35. /* *
  36. *
  37. * Class
  38. *
  39. * */
  40. /**
  41. * @private
  42. * @class
  43. * @name Highcharts.seriesTypes.gantt
  44. *
  45. * @augments Highcharts.Series
  46. */
  47. var GanttSeries = /** @class */ (function (_super) {
  48. __extends(GanttSeries, _super);
  49. function GanttSeries() {
  50. var _this = _super !== null && _super.apply(this, arguments) || this;
  51. /* *
  52. *
  53. * Properties
  54. *
  55. * */
  56. _this.data = void 0;
  57. _this.options = void 0;
  58. _this.points = void 0;
  59. return _this;
  60. /* eslint-enable valid-jsdoc */
  61. }
  62. /* *
  63. *
  64. * Functions
  65. *
  66. * */
  67. /* eslint-disable valid-jsdoc */
  68. /**
  69. * Draws a single point in the series.
  70. *
  71. * This override draws the point as a diamond if point.options.milestone
  72. * is true, and uses the original drawPoint() if it is false or not set.
  73. *
  74. * @requires highcharts-gantt
  75. *
  76. * @private
  77. * @function Highcharts.seriesTypes.gantt#drawPoint
  78. *
  79. * @param {Highcharts.Point} point
  80. * An instance of Point in the series
  81. *
  82. * @param {"animate"|"attr"} verb
  83. * 'animate' (animates changes) or 'attr' (sets options)
  84. */
  85. GanttSeries.prototype.drawPoint = function (point, verb) {
  86. var series = this, seriesOpts = series.options, renderer = series.chart.renderer, shapeArgs = point.shapeArgs, plotY = point.plotY, graphic = point.graphic, state = point.selected && 'select', cutOff = seriesOpts.stacking && !seriesOpts.borderRadius, diamondShape;
  87. if (point.options.milestone) {
  88. if (isNumber(plotY) && point.y !== null && point.visible !== false) {
  89. diamondShape = renderer.symbols.diamond(shapeArgs.x, shapeArgs.y, shapeArgs.width, shapeArgs.height);
  90. if (graphic) {
  91. graphic[verb]({
  92. d: diamondShape
  93. });
  94. }
  95. else {
  96. point.graphic = graphic = renderer.path(diamondShape)
  97. .addClass(point.getClassName(), true)
  98. .add(point.group || series.group);
  99. }
  100. // Presentational
  101. if (!series.chart.styledMode) {
  102. point.graphic
  103. .attr(series.pointAttribs(point, state))
  104. .shadow(seriesOpts.shadow, null, cutOff);
  105. }
  106. }
  107. else if (graphic) {
  108. point.graphic = graphic.destroy(); // #1269
  109. }
  110. }
  111. else {
  112. XRangeSeries.prototype.drawPoint.call(series, point, verb);
  113. }
  114. };
  115. /**
  116. * Handle milestones, as they have no x2.
  117. * @private
  118. */
  119. GanttSeries.prototype.translatePoint = function (point) {
  120. var series = this, shapeArgs, size;
  121. XRangeSeries.prototype.translatePoint.call(series, point);
  122. if (point.options.milestone) {
  123. shapeArgs = point.shapeArgs;
  124. size = shapeArgs.height;
  125. point.shapeArgs = {
  126. x: shapeArgs.x - (size / 2),
  127. y: shapeArgs.y,
  128. width: size,
  129. height: size
  130. };
  131. }
  132. };
  133. /**
  134. * A `gantt` series. If the [type](#series.gantt.type) option is not specified,
  135. * it is inherited from [chart.type](#chart.type).
  136. *
  137. * @extends plotOptions.xrange
  138. * @product gantt
  139. * @requires highcharts-gantt
  140. * @optionparent plotOptions.gantt
  141. */
  142. GanttSeries.defaultOptions = merge(XRangeSeries.defaultOptions, {
  143. // options - default options merged with parent
  144. grouping: false,
  145. dataLabels: {
  146. enabled: true
  147. },
  148. tooltip: {
  149. headerFormat: '<span style="font-size: 10px">{series.name}</span><br/>',
  150. pointFormat: null,
  151. pointFormatter: function () {
  152. var point = this, series = point.series, tooltip = series.chart.tooltip, xAxis = series.xAxis, formats = series.tooltipOptions.dateTimeLabelFormats, startOfWeek = xAxis.options.startOfWeek, ttOptions = series.tooltipOptions, format = ttOptions.xDateFormat, start, end, milestone = point.options.milestone, retVal = '<b>' + (point.name || point.yCategory) + '</b>';
  153. if (ttOptions.pointFormat) {
  154. return point.tooltipFormatter(ttOptions.pointFormat);
  155. }
  156. if (!format) {
  157. format = splat(tooltip.getDateFormat(xAxis.closestPointRange, point.start, startOfWeek, formats))[0];
  158. }
  159. start = series.chart.time.dateFormat(format, point.start);
  160. end = series.chart.time.dateFormat(format, point.end);
  161. retVal += '<br/>';
  162. if (!milestone) {
  163. retVal += 'Start: ' + start + '<br/>';
  164. retVal += 'End: ' + end + '<br/>';
  165. }
  166. else {
  167. retVal += start + '<br/>';
  168. }
  169. return retVal;
  170. }
  171. },
  172. connectors: {
  173. type: 'simpleConnect',
  174. /**
  175. * @declare Highcharts.ConnectorsAnimationOptionsObject
  176. */
  177. animation: {
  178. reversed: true // Dependencies go from child to parent
  179. },
  180. startMarker: {
  181. enabled: true,
  182. symbol: 'arrow-filled',
  183. radius: 4,
  184. fill: '#fa0',
  185. align: 'left'
  186. },
  187. endMarker: {
  188. enabled: false,
  189. align: 'right'
  190. }
  191. }
  192. });
  193. return GanttSeries;
  194. }(XRangeSeries));
  195. extend(GanttSeries.prototype, {
  196. // Keyboard navigation, don't use nearest vertical mode
  197. keyboardMoveVertical: false,
  198. pointArrayMap: ['start', 'end', 'y'],
  199. pointClass: GanttPoint,
  200. setData: Series.prototype.setData
  201. });
  202. SeriesRegistry.registerSeriesType('gantt', GanttSeries);
  203. /* *
  204. *
  205. * Default Export
  206. *
  207. * */
  208. export default GanttSeries;
  209. /* *
  210. *
  211. * API Options
  212. *
  213. * */
  214. /**
  215. * A `gantt` series.
  216. *
  217. * @extends series,plotOptions.gantt
  218. * @excluding boostThreshold, connectors, dashStyle, findNearestPointBy,
  219. * getExtremesFromAll, marker, negativeColor, pointInterval,
  220. * pointIntervalUnit, pointPlacement, pointStart
  221. * @product gantt
  222. * @requires highcharts-gantt
  223. * @apioption series.gantt
  224. */
  225. /**
  226. * Data for a Gantt series.
  227. *
  228. * @declare Highcharts.GanttPointOptionsObject
  229. * @type {Array<*>}
  230. * @extends series.xrange.data
  231. * @excluding className, connect, dataLabels, events,
  232. * partialFill, selected, x, x2
  233. * @product gantt
  234. * @apioption series.gantt.data
  235. */
  236. /**
  237. * Whether the grid node belonging to this point should start as collapsed. Used
  238. * in axes of type treegrid.
  239. *
  240. * @sample {gantt} gantt/treegrid-axis/collapsed/
  241. * Start as collapsed
  242. *
  243. * @type {boolean}
  244. * @default false
  245. * @product gantt
  246. * @apioption series.gantt.data.collapsed
  247. */
  248. /**
  249. * The start time of a task.
  250. *
  251. * @type {number}
  252. * @product gantt
  253. * @apioption series.gantt.data.start
  254. */
  255. /**
  256. * The end time of a task.
  257. *
  258. * @type {number}
  259. * @product gantt
  260. * @apioption series.gantt.data.end
  261. */
  262. /**
  263. * The Y value of a task.
  264. *
  265. * @type {number}
  266. * @product gantt
  267. * @apioption series.gantt.data.y
  268. */
  269. /**
  270. * The name of a task. If a `treegrid` y-axis is used (default in Gantt charts),
  271. * this will be picked up automatically, and used to calculate the y-value.
  272. *
  273. * @type {string}
  274. * @product gantt
  275. * @apioption series.gantt.data.name
  276. */
  277. /**
  278. * Progress indicator, how much of the task completed. If it is a number, the
  279. * `fill` will be applied automatically.
  280. *
  281. * @sample {gantt} gantt/demo/progress-indicator
  282. * Progress indicator
  283. *
  284. * @type {number|*}
  285. * @extends series.xrange.data.partialFill
  286. * @product gantt
  287. * @apioption series.gantt.data.completed
  288. */
  289. /**
  290. * The amount of the progress indicator, ranging from 0 (not started) to 1
  291. * (finished).
  292. *
  293. * @type {number}
  294. * @default 0
  295. * @apioption series.gantt.data.completed.amount
  296. */
  297. /**
  298. * The fill of the progress indicator. Defaults to a darkened variety of the
  299. * main color.
  300. *
  301. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  302. * @apioption series.gantt.data.completed.fill
  303. */
  304. /**
  305. * The ID of the point (task) that this point depends on in Gantt charts.
  306. * Aliases [connect](series.xrange.data.connect). Can also be an object,
  307. * specifying further connecting [options](series.gantt.connectors) between the
  308. * points. Multiple connections can be specified by providing an array.
  309. *
  310. * @sample gantt/demo/project-management
  311. * Dependencies
  312. * @sample gantt/pathfinder/demo
  313. * Different connection types
  314. *
  315. * @type {string|Array<string|*>|*}
  316. * @extends series.xrange.data.connect
  317. * @since 6.2.0
  318. * @product gantt
  319. * @apioption series.gantt.data.dependency
  320. */
  321. /**
  322. * Whether this point is a milestone. If so, only the `start` option is handled,
  323. * while `end` is ignored.
  324. *
  325. * @sample gantt/gantt/milestones
  326. * Milestones
  327. *
  328. * @type {boolean}
  329. * @since 6.2.0
  330. * @product gantt
  331. * @apioption series.gantt.data.milestone
  332. */
  333. /**
  334. * The ID of the parent point (task) of this point in Gantt charts.
  335. *
  336. * @sample gantt/demo/subtasks
  337. * Gantt chart with subtasks
  338. *
  339. * @type {string}
  340. * @since 6.2.0
  341. * @product gantt
  342. * @apioption series.gantt.data.parent
  343. */
  344. /**
  345. * @excluding afterAnimate
  346. * @apioption series.gantt.events
  347. */
  348. ''; // adds doclets above to the transpiled file