GanttSeries.js 11 KB

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