gantt.src.js 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  1. /**
  2. * @license Highcharts JS v6.1.0 (2018-04-13)
  3. * Gantt series
  4. *
  5. * (c) 2016 Lars A. V. Cabrera
  6. *
  7. * --- WORK IN PROGRESS ---
  8. *
  9. * License: www.highcharts.com/license
  10. */
  11. 'use strict';
  12. (function (factory) {
  13. if (typeof module === 'object' && module.exports) {
  14. module.exports = factory;
  15. } else {
  16. factory(Highcharts);
  17. }
  18. }(function (Highcharts) {
  19. (function (H) {
  20. /**
  21. * (c) 2016 Highsoft AS
  22. * Authors: Lars A. V. Cabrera
  23. *
  24. * License: www.highcharts.com/license
  25. */
  26. var each = H.each,
  27. isObject = H.isObject,
  28. pick = H.pick,
  29. wrap = H.wrap,
  30. Axis = H.Axis,
  31. Chart = H.Chart,
  32. Tick = H.Tick;
  33. // Enum for which side the axis is on.
  34. // Maps to axis.side
  35. var axisSide = {
  36. top: 0,
  37. right: 1,
  38. bottom: 2,
  39. left: 3,
  40. 0: 'top',
  41. 1: 'right',
  42. 2: 'bottom',
  43. 3: 'left'
  44. };
  45. /**
  46. * Checks if an axis is the outer axis in its dimension. Since
  47. * axes are placed outwards in order, the axis with the highest
  48. * index is the outermost axis.
  49. *
  50. * Example: If there are multiple x-axes at the top of the chart,
  51. * this function returns true if the axis supplied is the last
  52. * of the x-axes.
  53. *
  54. * @return true if the axis is the outermost axis in its dimension;
  55. * false if not
  56. */
  57. Axis.prototype.isOuterAxis = function () {
  58. var axis = this,
  59. thisIndex = -1,
  60. isOuter = true;
  61. each(this.chart.axes, function (otherAxis, index) {
  62. if (otherAxis.side === axis.side) {
  63. if (otherAxis === axis) {
  64. // Get the index of the axis in question
  65. thisIndex = index;
  66. // Check thisIndex >= 0 in case thisIndex has
  67. // not been found yet
  68. } else if (thisIndex >= 0 && index > thisIndex) {
  69. // There was an axis on the same side with a
  70. // higher index. Exit the loop.
  71. isOuter = false;
  72. return;
  73. }
  74. }
  75. });
  76. // There were either no other axes on the same side,
  77. // or the other axes were not farther from the chart
  78. return isOuter;
  79. };
  80. /**
  81. * Shortcut function to Tick.label.getBBox().width.
  82. *
  83. * @return {number} width - the width of the tick label
  84. */
  85. Tick.prototype.getLabelWidth = function () {
  86. return this.label.getBBox().width;
  87. };
  88. /**
  89. * Get the maximum label length.
  90. * This function can be used in states where the axis.maxLabelLength has not
  91. * been set.
  92. *
  93. * @param {boolean} force - Optional parameter to force a new calculation, even
  94. * if a value has already been set
  95. * @return {number} maxLabelLength - the maximum label length of the axis
  96. */
  97. Axis.prototype.getMaxLabelLength = function (force) {
  98. var tickPositions = this.tickPositions,
  99. ticks = this.ticks,
  100. maxLabelLength = 0;
  101. if (!this.maxLabelLength || force) {
  102. each(tickPositions, function (tick) {
  103. tick = ticks[tick];
  104. if (tick && tick.labelLength > maxLabelLength) {
  105. maxLabelLength = tick.labelLength;
  106. }
  107. });
  108. this.maxLabelLength = maxLabelLength;
  109. }
  110. return this.maxLabelLength;
  111. };
  112. /**
  113. * Adds the axis defined in axis.options.title
  114. */
  115. Axis.prototype.addTitle = function () {
  116. var axis = this,
  117. renderer = axis.chart.renderer,
  118. axisParent = axis.axisParent,
  119. horiz = axis.horiz,
  120. opposite = axis.opposite,
  121. options = axis.options,
  122. axisTitleOptions = options.title,
  123. hasData,
  124. showAxis,
  125. textAlign;
  126. // For reuse in Axis.render
  127. hasData = axis.hasData();
  128. axis.showAxis = showAxis = hasData || pick(options.showEmpty, true);
  129. // Disregard title generation in original Axis.getOffset()
  130. options.title = '';
  131. if (!axis.axisTitle) {
  132. textAlign = axisTitleOptions.textAlign;
  133. if (!textAlign) {
  134. textAlign = (horiz ? {
  135. low: 'left',
  136. middle: 'center',
  137. high: 'right'
  138. } : {
  139. low: opposite ? 'right' : 'left',
  140. middle: 'center',
  141. high: opposite ? 'left' : 'right'
  142. })[axisTitleOptions.align];
  143. }
  144. axis.axisTitle = renderer.text(
  145. axisTitleOptions.text,
  146. 0,
  147. 0,
  148. axisTitleOptions.useHTML
  149. )
  150. .attr({
  151. zIndex: 7,
  152. rotation: axisTitleOptions.rotation || 0,
  153. align: textAlign
  154. })
  155. .addClass('highcharts-axis-title')
  156. .css(axisTitleOptions.style)
  157. // Add to axisParent instead of axisGroup, to ignore the space
  158. // it takes
  159. .add(axisParent);
  160. axis.axisTitle.isNew = true;
  161. }
  162. // hide or show the title depending on whether showEmpty is set
  163. axis.axisTitle[showAxis ? 'show' : 'hide'](true);
  164. };
  165. /**
  166. * Add custom date formats
  167. */
  168. H.dateFormats = {
  169. // Week number
  170. W: function (timestamp) {
  171. var date = new this.Date(timestamp),
  172. day = this.get('Day', date) === 0 ? 7 : this.get('Day', date),
  173. time = date.getTime(),
  174. startOfYear = new Date(this.get('FullYear', date), 0, 1, -6),
  175. dayNumber;
  176. this.set('Date', date, this.get('Date', date) + 4 - day);
  177. dayNumber = Math.floor((time - startOfYear) / 86400000);
  178. return 1 + Math.floor(dayNumber / 7);
  179. },
  180. // First letter of the day of the week, e.g. 'M' for 'Monday'.
  181. E: function (timestamp) {
  182. return this.dateFormat('%a', timestamp, true).charAt(0);
  183. }
  184. };
  185. /**
  186. * Prevents adding the last tick label if the axis is not a category axis.
  187. *
  188. * Since numeric labels are normally placed at starts and ends of a range of
  189. * value, and this module makes the label point at the value, an "extra" label
  190. * would appear.
  191. *
  192. * @param {function} proceed - the original function
  193. */
  194. wrap(Tick.prototype, 'addLabel', function (proceed) {
  195. var axis = this.axis,
  196. isCategoryAxis = axis.options.categories !== undefined,
  197. tickPositions = axis.tickPositions,
  198. lastTick = tickPositions[tickPositions.length - 1],
  199. isLastTick = this.pos !== lastTick;
  200. if (!axis.options.grid || isCategoryAxis || isLastTick) {
  201. proceed.apply(this);
  202. }
  203. });
  204. /**
  205. * Center tick labels vertically and horizontally between ticks
  206. *
  207. * @param {function} proceed - the original function
  208. *
  209. * @return {object} object - an object containing x and y positions
  210. * for the tick
  211. */
  212. wrap(Tick.prototype, 'getLabelPosition', function (proceed, x, y, label) {
  213. var retVal = proceed.apply(this, Array.prototype.slice.call(arguments, 1)),
  214. axis = this.axis,
  215. options = axis.options,
  216. tickInterval = options.tickInterval || 1,
  217. newX,
  218. newPos,
  219. axisHeight,
  220. fontSize,
  221. labelMetrics,
  222. lblB,
  223. lblH,
  224. labelCenter;
  225. // Only center tick labels if axis has option grid: true
  226. if (options.grid) {
  227. fontSize = options.labels.style.fontSize;
  228. labelMetrics = axis.chart.renderer.fontMetrics(fontSize, label);
  229. lblB = labelMetrics.b;
  230. lblH = labelMetrics.h;
  231. if (axis.horiz && options.categories === undefined) {
  232. // Center x position
  233. axisHeight = axis.axisGroup.getBBox().height;
  234. newPos = this.pos + tickInterval / 2;
  235. retVal.x = axis.translate(newPos) + axis.left;
  236. labelCenter = (axisHeight / 2) + (lblH / 2) - Math.abs(lblH - lblB);
  237. // Center y position
  238. if (axis.side === axisSide.top) {
  239. retVal.y = y - labelCenter;
  240. } else {
  241. retVal.y = y + labelCenter;
  242. }
  243. } else {
  244. // Center y position
  245. if (options.categories === undefined) {
  246. newPos = this.pos + (tickInterval / 2);
  247. retVal.y = axis.translate(newPos) + axis.top + (lblB / 2);
  248. }
  249. // Center x position
  250. newX = (this.getLabelWidth() / 2) - (axis.maxLabelLength / 2);
  251. if (axis.side === axisSide.left) {
  252. retVal.x += newX;
  253. } else {
  254. retVal.x -= newX;
  255. }
  256. }
  257. }
  258. return retVal;
  259. });
  260. /**
  261. * Draw vertical ticks extra long to create cell floors and roofs.
  262. * Overrides the tickLength for vertical axes.
  263. *
  264. * @param {function} proceed - the original function
  265. * @returns {array} retVal -
  266. */
  267. wrap(Axis.prototype, 'tickSize', function (proceed) {
  268. var axis = this,
  269. retVal = proceed.apply(axis, Array.prototype.slice.call(arguments, 1)),
  270. labelPadding,
  271. distance;
  272. if (axis.options.grid && !axis.horiz) {
  273. labelPadding = (Math.abs(axis.defaultLeftAxisOptions.labels.x) * 2);
  274. if (!axis.maxLabelLength) {
  275. axis.maxLabelLength = axis.getMaxLabelLength();
  276. }
  277. distance = axis.maxLabelLength + labelPadding;
  278. retVal[0] = distance;
  279. }
  280. return retVal;
  281. });
  282. /**
  283. * Disregards space required by axisTitle, by adding axisTitle to axisParent
  284. * instead of axisGroup, and disregarding margins and offsets related to
  285. * axisTitle.
  286. *
  287. * @param {function} proceed - the original function
  288. */
  289. wrap(Axis.prototype, 'getOffset', function (proceed) {
  290. var axis = this,
  291. axisOffset = axis.chart.axisOffset,
  292. side = axis.side,
  293. axisHeight,
  294. tickSize,
  295. options = axis.options,
  296. axisTitleOptions = options.title,
  297. addTitle = axisTitleOptions &&
  298. axisTitleOptions.text &&
  299. axisTitleOptions.enabled !== false;
  300. if (axis.options.grid && isObject(axis.options.title)) {
  301. tickSize = axis.tickSize('tick')[0];
  302. if (axisOffset[side] && tickSize) {
  303. axisHeight = axisOffset[side] + tickSize;
  304. }
  305. if (addTitle) {
  306. // Use the custom addTitle() to add it, while preventing making room
  307. // for it
  308. axis.addTitle();
  309. }
  310. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  311. axisOffset[side] = pick(axisHeight, axisOffset[side]);
  312. // Put axis options back after original Axis.getOffset() has been called
  313. options.title = axisTitleOptions;
  314. } else {
  315. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  316. }
  317. });
  318. /**
  319. * Prevents rotation of labels when squished, as rotating them would not
  320. * help.
  321. *
  322. * @param {function} proceed - the original function
  323. */
  324. wrap(Axis.prototype, 'renderUnsquish', function (proceed) {
  325. if (this.options.grid) {
  326. this.labelRotation = 0;
  327. this.options.labels.rotation = 0;
  328. }
  329. proceed.apply(this);
  330. });
  331. /**
  332. * Places leftmost tick at the start of the axis, to create a left wall.
  333. *
  334. * @param {function} proceed - the original function
  335. */
  336. wrap(Axis.prototype, 'setOptions', function (proceed, userOptions) {
  337. var axis = this;
  338. if (userOptions.grid && axis.horiz) {
  339. userOptions.startOnTick = true;
  340. userOptions.minPadding = 0;
  341. userOptions.endOnTick = true;
  342. }
  343. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  344. });
  345. /**
  346. * Draw an extra line on the far side of the the axisLine,
  347. * creating cell roofs of a grid.
  348. *
  349. * @param {function} proceed - the original function
  350. */
  351. wrap(Axis.prototype, 'render', function (proceed) {
  352. var axis = this,
  353. options = axis.options,
  354. labelPadding,
  355. distance,
  356. lineWidth,
  357. linePath,
  358. yStartIndex,
  359. yEndIndex,
  360. xStartIndex,
  361. xEndIndex,
  362. renderer = axis.chart.renderer,
  363. axisGroupBox;
  364. if (options.grid) {
  365. labelPadding = (Math.abs(axis.defaultLeftAxisOptions.labels.x) * 2);
  366. distance = axis.maxLabelLength + labelPadding;
  367. lineWidth = options.lineWidth;
  368. // Remove right wall before rendering
  369. if (axis.rightWall) {
  370. axis.rightWall.destroy();
  371. }
  372. // Call original Axis.render() to obtain axis.axisLine and
  373. // axis.axisGroup
  374. proceed.apply(axis);
  375. axisGroupBox = axis.axisGroup.getBBox();
  376. // Add right wall on horizontal axes
  377. if (axis.horiz) {
  378. axis.rightWall = renderer.path([
  379. 'M',
  380. axisGroupBox.x + axis.width + 1, // account for left wall
  381. axisGroupBox.y,
  382. 'L',
  383. axisGroupBox.x + axis.width + 1, // account for left wall
  384. axisGroupBox.y + axisGroupBox.height
  385. ])
  386. .attr({
  387. stroke: options.tickColor || '#ccd6eb',
  388. 'stroke-width': options.tickWidth || 1,
  389. zIndex: 7,
  390. class: 'grid-wall'
  391. })
  392. .add(axis.axisGroup);
  393. }
  394. if (axis.isOuterAxis() && axis.axisLine) {
  395. if (axis.horiz) {
  396. // -1 to avoid adding distance each time the chart updates
  397. distance = axisGroupBox.height - 1;
  398. }
  399. if (lineWidth) {
  400. linePath = axis.getLinePath(lineWidth);
  401. xStartIndex = linePath.indexOf('M') + 1;
  402. xEndIndex = linePath.indexOf('L') + 1;
  403. yStartIndex = linePath.indexOf('M') + 2;
  404. yEndIndex = linePath.indexOf('L') + 2;
  405. // Negate distance if top or left axis
  406. if (axis.side === axisSide.top || axis.side === axisSide.left) {
  407. distance = -distance;
  408. }
  409. // If axis is horizontal, reposition line path vertically
  410. if (axis.horiz) {
  411. linePath[yStartIndex] = linePath[yStartIndex] + distance;
  412. linePath[yEndIndex] = linePath[yEndIndex] + distance;
  413. } else {
  414. // If axis is vertical, reposition line path horizontally
  415. linePath[xStartIndex] = linePath[xStartIndex] + distance;
  416. linePath[xEndIndex] = linePath[xEndIndex] + distance;
  417. }
  418. if (!axis.axisLineExtra) {
  419. axis.axisLineExtra = renderer.path(linePath)
  420. .attr({
  421. stroke: options.lineColor,
  422. 'stroke-width': lineWidth,
  423. zIndex: 7
  424. })
  425. .add(axis.axisGroup);
  426. } else {
  427. axis.axisLineExtra.animate({
  428. d: linePath
  429. });
  430. }
  431. // show or hide the line depending on options.showEmpty
  432. axis.axisLine[axis.showAxis ? 'show' : 'hide'](true);
  433. }
  434. }
  435. } else {
  436. proceed.apply(axis);
  437. }
  438. });
  439. /**
  440. * Wraps chart rendering with the following customizations:
  441. * 1. Prohibit timespans of multitudes of a time unit
  442. * 2. Draw cell walls on vertical axes
  443. *
  444. * @param {function} proceed - the original function
  445. */
  446. wrap(Chart.prototype, 'render', function (proceed) {
  447. // 25 is optimal height for default fontSize (11px)
  448. // 25 / 11 ≈ 2.28
  449. var fontSizeToCellHeightRatio = 25 / 11,
  450. fontMetrics,
  451. fontSize;
  452. each(this.axes, function (axis) {
  453. var options = axis.options;
  454. if (options.grid) {
  455. fontSize = options.labels.style.fontSize;
  456. fontMetrics = axis.chart.renderer.fontMetrics(fontSize);
  457. // Prohibit timespans of multitudes of a time unit,
  458. // e.g. two days, three weeks, etc.
  459. if (options.type === 'datetime') {
  460. options.units = [
  461. ['millisecond', [1]],
  462. ['second', [1]],
  463. ['minute', [1]],
  464. ['hour', [1]],
  465. ['day', [1]],
  466. ['week', [1]],
  467. ['month', [1]],
  468. ['year', null]
  469. ];
  470. }
  471. // Make tick marks taller, creating cell walls of a grid.
  472. // Use cellHeight axis option if set
  473. if (axis.horiz) {
  474. options.tickLength = options.cellHeight ||
  475. fontMetrics.h * fontSizeToCellHeightRatio;
  476. } else {
  477. options.tickWidth = 1;
  478. if (!options.lineWidth) {
  479. options.lineWidth = 1;
  480. }
  481. }
  482. }
  483. });
  484. // Call original Chart.render()
  485. proceed.apply(this);
  486. });
  487. }(Highcharts));
  488. (function (H) {
  489. /**
  490. * X-range series module
  491. *
  492. * (c) 2010-2017 Torstein Honsi, Lars A. V. Cabrera
  493. *
  494. * License: www.highcharts.com/license
  495. */
  496. var addEvent = H.addEvent,
  497. defined = H.defined,
  498. color = H.Color,
  499. columnType = H.seriesTypes.column,
  500. each = H.each,
  501. isNumber = H.isNumber,
  502. isObject = H.isObject,
  503. merge = H.merge,
  504. pick = H.pick,
  505. seriesType = H.seriesType,
  506. seriesTypes = H.seriesTypes,
  507. Axis = H.Axis,
  508. Point = H.Point,
  509. Series = H.Series;
  510. /**
  511. * The X-range series displays ranges on the X axis, typically time intervals
  512. * with a start and end date.
  513. *
  514. * @extends {plotOptions.column}
  515. * @excluding boostThreshold,crisp,cropThreshold,depth,edgeColor,edgeWidth,
  516. * findNearestPointBy,getExtremesFromAll,grouping,groupPadding,
  517. * negativeColor,pointInterval,pointIntervalUnit,pointPlacement,
  518. * pointRange,pointStart,softThreshold,stacking,threshold,data
  519. * @product highcharts highstock
  520. * @sample {highcharts} highcharts/demo/x-range/
  521. * X-range
  522. * @sample {highcharts} highcharts/css/x-range/
  523. * Styled mode X-range
  524. * @sample {highcharts} highcharts/chart/inverted-xrange/
  525. * Inverted X-range
  526. * @since 6.0.0
  527. * @optionparent plotOptions.xrange
  528. */
  529. seriesType('xrange', 'column', {
  530. /**
  531. * A partial fill for each point, typically used to visualize how much of
  532. * a task is performed. The partial fill object can be set either on series
  533. * or point level.
  534. *
  535. * @sample {highcharts} highcharts/demo/x-range
  536. * X-range with partial fill
  537. * @type {Object}
  538. * @product highcharts highstock
  539. * @apioption plotOptions.xrange.partialFill
  540. */
  541. /**
  542. * The fill color to be used for partial fills. Defaults to a darker shade
  543. * of the point color.
  544. *
  545. * @type {Color}
  546. * @product highcharts highstock
  547. * @apioption plotOptions.xrange.partialFill.fill
  548. */
  549. /**
  550. * In an X-range series, this option makes all points of the same Y-axis
  551. * category the same color.
  552. */
  553. colorByPoint: true,
  554. dataLabels: {
  555. verticalAlign: 'middle',
  556. inside: true,
  557. /**
  558. * The default formatter for X-range data labels displays the percentage
  559. * of the partial fill amount.
  560. */
  561. formatter: function () {
  562. var point = this.point,
  563. amount = point.partialFill;
  564. if (isObject(amount)) {
  565. amount = amount.amount;
  566. }
  567. if (!defined(amount)) {
  568. amount = 0;
  569. }
  570. return (amount * 100) + '%';
  571. }
  572. },
  573. tooltip: {
  574. headerFormat: '<span style="font-size: 0.85em">{point.x} - {point.x2}</span><br/>',
  575. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.yCategory}</b><br/>'
  576. },
  577. borderRadius: 3,
  578. pointRange: 0
  579. }, {
  580. type: 'xrange',
  581. parallelArrays: ['x', 'x2', 'y'],
  582. requireSorting: false,
  583. animate: seriesTypes.line.prototype.animate,
  584. cropShoulder: 1,
  585. getExtremesFromAll: true,
  586. /**
  587. * Borrow the column series metrics, but with swapped axes. This gives free
  588. * access to features like groupPadding, grouping, pointWidth etc.
  589. */
  590. getColumnMetrics: function () {
  591. var metrics,
  592. chart = this.chart;
  593. function swapAxes() {
  594. each(chart.series, function (s) {
  595. var xAxis = s.xAxis;
  596. s.xAxis = s.yAxis;
  597. s.yAxis = xAxis;
  598. });
  599. }
  600. swapAxes();
  601. metrics = columnType.prototype.getColumnMetrics.call(this);
  602. swapAxes();
  603. return metrics;
  604. },
  605. /**
  606. * Override cropData to show a point where x or x2 is outside visible range,
  607. * but one of them is inside.
  608. */
  609. cropData: function (xData, yData, min, max) {
  610. // Replace xData with x2Data to find the appropriate cropStart
  611. var cropData = Series.prototype.cropData,
  612. crop = cropData.call(this, this.x2Data, yData, min, max);
  613. // Re-insert the cropped xData
  614. crop.xData = xData.slice(crop.start, crop.end);
  615. return crop;
  616. },
  617. translatePoint: function (point) {
  618. var series = this,
  619. xAxis = series.xAxis,
  620. metrics = series.columnMetrics,
  621. minPointLength = series.options.minPointLength || 0,
  622. plotX = point.plotX,
  623. posX = pick(point.x2, point.x + (point.len || 0)),
  624. plotX2 = xAxis.translate(posX, 0, 0, 0, 1),
  625. length = plotX2 - plotX,
  626. widthDifference,
  627. shapeArgs,
  628. partialFill,
  629. inverted = this.chart.inverted,
  630. borderWidth = pick(series.options.borderWidth, 1),
  631. crisper = borderWidth % 2 / 2,
  632. dlLeft,
  633. dlRight,
  634. dlWidth;
  635. if (minPointLength) {
  636. widthDifference = minPointLength - length;
  637. if (widthDifference < 0) {
  638. widthDifference = 0;
  639. }
  640. plotX -= widthDifference / 2;
  641. plotX2 += widthDifference / 2;
  642. }
  643. plotX = Math.max(plotX, -10);
  644. plotX2 = Math.min(Math.max(plotX2, -10), xAxis.len + 10);
  645. point.shapeArgs = {
  646. x: Math.floor(Math.min(plotX, plotX2)) + crisper,
  647. y: Math.floor(point.plotY + metrics.offset) + crisper,
  648. width: Math.round(Math.abs(plotX2 - plotX)),
  649. height: Math.round(metrics.width),
  650. r: series.options.borderRadius
  651. };
  652. // Align data labels inside the shape and inside the plot area
  653. dlLeft = point.shapeArgs.x;
  654. dlRight = dlLeft + point.shapeArgs.width;
  655. if (dlLeft < 0 || dlRight > xAxis.len) {
  656. dlLeft = Math.min(xAxis.len, Math.max(0, dlLeft));
  657. dlRight = Math.max(0, Math.min(dlRight, xAxis.len));
  658. dlWidth = dlRight - dlLeft;
  659. point.dlBox = merge(point.shapeArgs, {
  660. x: dlLeft,
  661. width: dlRight - dlLeft,
  662. centerX: dlWidth ? dlWidth / 2 : null
  663. });
  664. } else {
  665. point.dlBox = null;
  666. }
  667. // Tooltip position
  668. point.tooltipPos[0] += inverted ? 0 : length / 2;
  669. point.tooltipPos[1] -= inverted ? length / 2 : metrics.width / 2;
  670. // Add a partShapeArgs to the point, based on the shapeArgs property
  671. partialFill = point.partialFill;
  672. if (partialFill) {
  673. // Get the partial fill amount
  674. if (isObject(partialFill)) {
  675. partialFill = partialFill.amount;
  676. }
  677. // If it was not a number, assume 0
  678. if (!isNumber(partialFill)) {
  679. partialFill = 0;
  680. }
  681. shapeArgs = point.shapeArgs;
  682. point.partShapeArgs = {
  683. x: shapeArgs.x,
  684. y: shapeArgs.y,
  685. width: shapeArgs.width,
  686. height: shapeArgs.height,
  687. r: series.options.borderRadius
  688. };
  689. point.clipRectArgs = {
  690. x: shapeArgs.x,
  691. y: shapeArgs.y,
  692. width: Math.max(
  693. Math.round(
  694. length * partialFill +
  695. (point.plotX - plotX)
  696. ),
  697. 0
  698. ),
  699. height: shapeArgs.height
  700. };
  701. }
  702. },
  703. translate: function () {
  704. columnType.prototype.translate.apply(this, arguments);
  705. each(this.points, function (point) {
  706. this.translatePoint(point);
  707. }, this);
  708. },
  709. /**
  710. * Draws a single point in the series. Needed for partial fill.
  711. *
  712. * This override turns point.graphic into a group containing the original
  713. * graphic and an overlay displaying the partial fill.
  714. *
  715. * @param {Object} point an instance of Point in the series
  716. * @param {string} verb 'animate' (animates changes) or 'attr' (sets
  717. * options)
  718. * @returns {void}
  719. */
  720. drawPoint: function (point, verb) {
  721. var series = this,
  722. seriesOpts = series.options,
  723. renderer = series.chart.renderer,
  724. graphic = point.graphic,
  725. type = point.shapeType,
  726. shapeArgs = point.shapeArgs,
  727. partShapeArgs = point.partShapeArgs,
  728. clipRectArgs = point.clipRectArgs,
  729. pfOptions = point.partialFill,
  730. fill,
  731. state = point.selected && 'select',
  732. cutOff = seriesOpts.stacking && !seriesOpts.borderRadius;
  733. if (!point.isNull) {
  734. // Original graphic
  735. if (graphic) { // update
  736. point.graphicOriginal[verb](
  737. merge(shapeArgs)
  738. );
  739. } else {
  740. point.graphic = graphic = renderer.g('point')
  741. .addClass(point.getClassName())
  742. .add(point.group || series.group);
  743. point.graphicOriginal = renderer[type](shapeArgs)
  744. .addClass(point.getClassName())
  745. .addClass('highcharts-partfill-original')
  746. .add(graphic);
  747. }
  748. // Partial fill graphic
  749. if (partShapeArgs) {
  750. if (point.graphicOverlay) {
  751. point.graphicOverlay[verb](
  752. merge(partShapeArgs)
  753. );
  754. point.clipRect.animate(
  755. merge(clipRectArgs)
  756. );
  757. } else {
  758. point.clipRect = renderer.clipRect(
  759. clipRectArgs.x,
  760. clipRectArgs.y,
  761. clipRectArgs.width,
  762. clipRectArgs.height
  763. );
  764. point.graphicOverlay = renderer[type](partShapeArgs)
  765. .addClass('highcharts-partfill-overlay')
  766. .add(graphic)
  767. .clip(point.clipRect);
  768. }
  769. }
  770. // Presentational
  771. point.graphicOriginal
  772. .attr(series.pointAttribs(point, state))
  773. .shadow(seriesOpts.shadow, null, cutOff);
  774. if (partShapeArgs) {
  775. // Ensure pfOptions is an object
  776. if (!isObject(pfOptions)) {
  777. pfOptions = {};
  778. }
  779. if (isObject(seriesOpts.partialFill)) {
  780. pfOptions = merge(pfOptions, seriesOpts.partialFill);
  781. }
  782. fill = (
  783. pfOptions.fill ||
  784. color(point.color || series.color).brighten(-0.3).get()
  785. );
  786. point.graphicOverlay
  787. .attr(series.pointAttribs(point, state))
  788. .attr({
  789. 'fill': fill
  790. })
  791. .shadow(seriesOpts.shadow, null, cutOff);
  792. }
  793. } else if (graphic) {
  794. point.graphic = graphic.destroy(); // #1269
  795. }
  796. },
  797. drawPoints: function () {
  798. var series = this,
  799. verb = series.getAnimationVerb();
  800. // Draw the columns
  801. each(series.points, function (point) {
  802. series.drawPoint(point, verb);
  803. });
  804. },
  805. /**
  806. * Returns "animate", or "attr" if the number of points is above the
  807. * animation limit.
  808. *
  809. * @returns {String}
  810. */
  811. getAnimationVerb: function () {
  812. return this.chart.pointCount < (this.options.animationLimit || 250) ?
  813. 'animate' : 'attr';
  814. }
  815. /**
  816. * Override to remove stroke from points.
  817. * For partial fill.
  818. * /
  819. pointAttribs: function () {
  820. var series = this,
  821. retVal = columnType.prototype.pointAttribs.apply(series, arguments);
  822. //retVal['stroke-width'] = 0;
  823. return retVal;
  824. }
  825. //*/
  826. // Point class properties
  827. }, {
  828. /**
  829. * Extend init so that `colorByPoint` for x-range means that one color is
  830. * applied per Y axis category.
  831. */
  832. init: function () {
  833. Point.prototype.init.apply(this, arguments);
  834. var colors,
  835. series = this.series,
  836. colorCount = series.chart.options.chart.colorCount;
  837. if (!this.y) {
  838. this.y = 0;
  839. }
  840. if (series.options.colorByPoint) {
  841. colors = series.options.colors || series.chart.options.colors;
  842. colorCount = colors.length;
  843. if (!this.options.color && colors[this.y % colorCount]) {
  844. this.color = colors[this.y % colorCount];
  845. }
  846. }
  847. this.colorIndex = pick(this.options.colorIndex, this.y % colorCount);
  848. return this;
  849. },
  850. setState: function () {
  851. Point.prototype.setState.apply(this, arguments);
  852. this.series.drawPoint(this, this.series.getAnimationVerb());
  853. },
  854. // Add x2 and yCategory to the available properties for tooltip formats
  855. getLabelConfig: function () {
  856. var point = this,
  857. cfg = Point.prototype.getLabelConfig.call(point),
  858. yCats = point.series.yAxis.categories;
  859. cfg.x2 = point.x2;
  860. cfg.yCategory = point.yCategory = yCats && yCats[point.y];
  861. return cfg;
  862. },
  863. tooltipDateKeys: ['x', 'x2'],
  864. isValid: function () {
  865. return typeof this.x === 'number' &&
  866. typeof this.x2 === 'number';
  867. }
  868. });
  869. /**
  870. * Max x2 should be considered in xAxis extremes
  871. */
  872. addEvent(Axis, 'afterGetSeriesExtremes', function () {
  873. var axis = this,
  874. axisSeries = axis.series,
  875. dataMax,
  876. modMax;
  877. if (axis.isXAxis) {
  878. dataMax = pick(axis.dataMax, -Number.MAX_VALUE);
  879. each(axisSeries, function (series) {
  880. if (series.x2Data) {
  881. each(series.x2Data, function (val) {
  882. if (val > dataMax) {
  883. dataMax = val;
  884. modMax = true;
  885. }
  886. });
  887. }
  888. });
  889. if (modMax) {
  890. axis.dataMax = dataMax;
  891. }
  892. }
  893. });
  894. /**
  895. * An `xrange` series. If the [type](#series.xrange.type) option is not
  896. * specified, it is inherited from [chart.type](#chart.type).
  897. *
  898. * @type {Object}
  899. * @extends series,plotOptions.xrange
  900. * @excluding boostThreshold,crisp,cropThreshold,depth,edgeColor,edgeWidth,
  901. * findNearestPointBy,getExtremesFromAll,grouping,groupPadding,
  902. * negativeColor,pointInterval,pointIntervalUnit,pointPlacement,
  903. * pointRange,pointStart,softThreshold,stacking,threshold
  904. * @product highcharts highstock
  905. * @apioption series.xrange
  906. */
  907. /**
  908. * An array of data points for the series. For the `xrange` series type,
  909. * points can be given in the following ways:
  910. *
  911. * 1. An array of objects with named values. The objects are point
  912. * configuration objects as seen below.
  913. *
  914. * ```js
  915. * data: [{
  916. * x: Date.UTC(2017, 0, 1),
  917. * x2: Date.UTC(2017, 0, 3),
  918. * name: "Test",
  919. * y: 0,
  920. * color: "#00FF00"
  921. * }, {
  922. * x: Date.UTC(2017, 0, 4),
  923. * x2: Date.UTC(2017, 0, 5),
  924. * name: "Deploy",
  925. * y: 1,
  926. * color: "#FF0000"
  927. * }]
  928. * ```
  929. *
  930. * @type {Array<Object|Array|Number>}
  931. * @extends series.line.data
  932. * @sample {highcharts} highcharts/chart/reflow-true/
  933. * Numerical values
  934. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  935. * Arrays of numeric x and y
  936. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  937. * Arrays of datetime x and y
  938. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  939. * Arrays of point.name and y
  940. * @sample {highcharts} highcharts/series/data-array-of-objects/
  941. * Config objects
  942. * @product highcharts highstock
  943. * @apioption series.xrange.data
  944. */
  945. /**
  946. * The ending X value of the range point.
  947. *
  948. * @sample {highcharts} highcharts/demo/x-range
  949. * X-range
  950. * @type {Number}
  951. * @product highcharts highstock
  952. * @apioption plotOptions.xrange.data.x2
  953. */
  954. /**
  955. * A partial fill for each point, typically used to visualize how much of
  956. * a task is performed. The partial fill object can be set either on series
  957. * or point level.
  958. *
  959. * @sample {highcharts} highcharts/demo/x-range
  960. * X-range with partial fill
  961. * @type {Object|Number}
  962. * @product highcharts highstock
  963. * @apioption plotOptions.xrange.data.partialFill
  964. */
  965. /**
  966. * The amount of the X-range point to be filled. Values can be 0-1 and are
  967. * converted to percentages in the default data label formatter.
  968. *
  969. * @type {Number}
  970. * @product highcharts highstock
  971. * @apioption plotOptions.xrange.data.partialFill.amount
  972. */
  973. /**
  974. * The fill color to be used for partial fills. Defaults to a darker shade
  975. * of the point color.
  976. *
  977. * @type {Color}
  978. * @product highcharts highstock
  979. * @apioption plotOptions.xrange.data.partialFill.fill
  980. */
  981. }(Highcharts));
  982. (function () {
  983. /**
  984. * (c) 2016 Highsoft AS
  985. * Authors: Lars A. V. Cabrera
  986. *
  987. * License: www.highcharts.com/license
  988. */
  989. //
  990. }());
  991. }));