xrange.src.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. /**
  2. * @license Highcharts JS v9.0.1 (2021-02-16)
  3. *
  4. * X-range series
  5. *
  6. * (c) 2010-2021 Torstein Honsi, Lars A. V. Cabrera
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define('highcharts/modules/xrange', ['highcharts'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'Series/XRange/XRangePoint.js', [_modules['Core/Series/Point.js'], _modules['Core/Series/SeriesRegistry.js']], function (Point, SeriesRegistry) {
  32. /* *
  33. *
  34. * X-range series module
  35. *
  36. * (c) 2010-2021 Torstein Honsi, Lars A. V. Cabrera
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. *
  42. * */
  43. var __extends = (this && this.__extends) || (function () {
  44. var extendStatics = function (d,
  45. b) {
  46. extendStatics = Object.setPrototypeOf ||
  47. ({ __proto__: [] } instanceof Array && function (d,
  48. b) { d.__proto__ = b; }) ||
  49. function (d,
  50. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  51. return extendStatics(d, b);
  52. };
  53. return function (d, b) {
  54. extendStatics(d, b);
  55. function __() { this.constructor = d; }
  56. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  57. };
  58. })();
  59. var ColumnSeries = SeriesRegistry.seriesTypes.column;
  60. /* *
  61. *
  62. * Declarations
  63. *
  64. * */
  65. var XRangePoint = /** @class */ (function (_super) {
  66. __extends(XRangePoint, _super);
  67. function XRangePoint() {
  68. var _this = _super !== null && _super.apply(this,
  69. arguments) || this;
  70. /* *
  71. *
  72. * Properties
  73. *
  74. * */
  75. _this.options = void 0;
  76. _this.series = void 0;
  77. _this.tooltipDateKeys = ['x', 'x2'];
  78. return _this;
  79. /* eslint-enable valid-jsdoc */
  80. }
  81. /* *
  82. *
  83. * Static properties
  84. *
  85. * */
  86. /**
  87. * Return color of a point based on its category.
  88. *
  89. * @private
  90. * @function getColorByCategory
  91. *
  92. * @param {object} series
  93. * The series which the point belongs to.
  94. *
  95. * @param {object} point
  96. * The point to calculate its color for.
  97. *
  98. * @return {object}
  99. * Returns an object containing the properties color and colorIndex.
  100. */
  101. XRangePoint.getColorByCategory = function (series, point) {
  102. var colors = series.options.colors || series.chart.options.colors,
  103. colorCount = colors ?
  104. colors.length :
  105. series.chart.options.chart.colorCount,
  106. colorIndex = point.y % colorCount,
  107. color = colors && colors[colorIndex];
  108. return {
  109. colorIndex: colorIndex,
  110. color: color
  111. };
  112. };
  113. /* *
  114. *
  115. * Functions
  116. *
  117. * */
  118. /**
  119. * The ending X value of the range point.
  120. * @name Highcharts.Point#x2
  121. * @type {number|undefined}
  122. * @requires modules/xrange
  123. */
  124. /**
  125. * Extend applyOptions so that `colorByPoint` for x-range means that one
  126. * color is applied per Y axis category.
  127. *
  128. * @private
  129. * @function Highcharts.Point#applyOptions
  130. *
  131. * @return {Highcharts.Series}
  132. */
  133. /* eslint-disable valid-jsdoc */
  134. /**
  135. * @private
  136. */
  137. XRangePoint.prototype.resolveColor = function () {
  138. var series = this.series,
  139. colorByPoint;
  140. if (series.options.colorByPoint && !this.options.color) {
  141. colorByPoint = XRangePoint.getColorByCategory(series, this);
  142. if (!series.chart.styledMode) {
  143. this.color = colorByPoint.color;
  144. }
  145. if (!this.options.colorIndex) {
  146. this.colorIndex = colorByPoint.colorIndex;
  147. }
  148. }
  149. else if (!this.color) {
  150. this.color = series.color;
  151. }
  152. };
  153. /**
  154. * Extend init to have y default to 0.
  155. *
  156. * @private
  157. * @function Highcharts.Point#init
  158. *
  159. * @return {Highcharts.Point}
  160. */
  161. XRangePoint.prototype.init = function () {
  162. Point.prototype.init.apply(this, arguments);
  163. if (!this.y) {
  164. this.y = 0;
  165. }
  166. return this;
  167. };
  168. /**
  169. * @private
  170. * @function Highcharts.Point#setState
  171. */
  172. XRangePoint.prototype.setState = function () {
  173. Point.prototype.setState.apply(this, arguments);
  174. this.series.drawPoint(this, this.series.getAnimationVerb());
  175. };
  176. /**
  177. * @private
  178. * @function Highcharts.Point#getLabelConfig
  179. *
  180. * @return {Highcharts.PointLabelObject}
  181. */
  182. // Add x2 and yCategory to the available properties for tooltip formats
  183. XRangePoint.prototype.getLabelConfig = function () {
  184. var point = this,
  185. cfg = Point.prototype.getLabelConfig.call(point),
  186. yCats = point.series.yAxis.categories;
  187. cfg.x2 = point.x2;
  188. cfg.yCategory = point.yCategory = yCats && yCats[point.y];
  189. return cfg;
  190. };
  191. /**
  192. * @private
  193. * @function Highcharts.Point#isValid
  194. *
  195. * @return {boolean}
  196. */
  197. XRangePoint.prototype.isValid = function () {
  198. return typeof this.x === 'number' &&
  199. typeof this.x2 === 'number';
  200. };
  201. return XRangePoint;
  202. }(ColumnSeries.prototype.pointClass));
  203. /* *
  204. *
  205. * Default Export
  206. *
  207. * */
  208. return XRangePoint;
  209. });
  210. _registerModule(_modules, 'Series/XRange/XRangeComposition.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Utilities.js']], function (Axis, U) {
  211. /* *
  212. *
  213. * X-range series module
  214. *
  215. * (c) 2010-2021 Torstein Honsi, Lars A. V. Cabrera
  216. *
  217. * License: www.highcharts.com/license
  218. *
  219. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  220. *
  221. * */
  222. /* *
  223. *
  224. * Imports
  225. *
  226. * */
  227. /* *
  228. *
  229. * Imports
  230. *
  231. * */
  232. var addEvent = U.addEvent,
  233. pick = U.pick;
  234. /**
  235. * Max x2 should be considered in xAxis extremes
  236. */
  237. addEvent(Axis, 'afterGetSeriesExtremes', function () {
  238. var axis = this, // eslint-disable-line no-invalid-this
  239. axisSeries = axis.series,
  240. dataMax,
  241. modMax;
  242. if (axis.isXAxis) {
  243. dataMax = pick(axis.dataMax, -Number.MAX_VALUE);
  244. axisSeries.forEach(function (series) {
  245. if (series.x2Data) {
  246. series.x2Data
  247. .forEach(function (val) {
  248. if (val > dataMax) {
  249. dataMax = val;
  250. modMax = true;
  251. }
  252. });
  253. }
  254. });
  255. if (modMax) {
  256. axis.dataMax = dataMax;
  257. }
  258. }
  259. });
  260. });
  261. _registerModule(_modules, 'Series/XRange/XRangeSeries.js', [_modules['Core/Globals.js'], _modules['Core/Color/Color.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js'], _modules['Series/XRange/XRangePoint.js']], function (H, Color, SeriesRegistry, U, XRangePoint) {
  262. /* *
  263. *
  264. * X-range series module
  265. *
  266. * (c) 2010-2021 Torstein Honsi, Lars A. V. Cabrera
  267. *
  268. * License: www.highcharts.com/license
  269. *
  270. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  271. *
  272. * */
  273. var __extends = (this && this.__extends) || (function () {
  274. var extendStatics = function (d,
  275. b) {
  276. extendStatics = Object.setPrototypeOf ||
  277. ({ __proto__: [] } instanceof Array && function (d,
  278. b) { d.__proto__ = b; }) ||
  279. function (d,
  280. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  281. return extendStatics(d, b);
  282. };
  283. return function (d, b) {
  284. extendStatics(d, b);
  285. function __() { this.constructor = d; }
  286. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  287. };
  288. })();
  289. var color = Color.parse;
  290. var Series = SeriesRegistry.series,
  291. ColumnSeries = SeriesRegistry.seriesTypes.column;
  292. var columnProto = ColumnSeries.prototype;
  293. var clamp = U.clamp,
  294. correctFloat = U.correctFloat,
  295. defined = U.defined,
  296. extend = U.extend,
  297. find = U.find,
  298. isNumber = U.isNumber,
  299. isObject = U.isObject,
  300. merge = U.merge,
  301. pick = U.pick;
  302. /* *
  303. * @interface Highcharts.PointOptionsObject in parts/Point.ts
  304. */ /**
  305. * The ending X value of the range point.
  306. * @name Highcharts.PointOptionsObject#x2
  307. * @type {number|undefined}
  308. * @requires modules/xrange
  309. */
  310. /**
  311. * @private
  312. * @class
  313. * @name Highcharts.seriesTypes.xrange
  314. *
  315. * @augments Highcharts.Series
  316. */
  317. var XRangeSeries = /** @class */ (function (_super) {
  318. __extends(XRangeSeries, _super);
  319. function XRangeSeries() {
  320. var _this = _super !== null && _super.apply(this,
  321. arguments) || this;
  322. /* *
  323. *
  324. * Properties
  325. *
  326. * */
  327. _this.data = void 0;
  328. _this.options = void 0;
  329. _this.points = void 0;
  330. return _this;
  331. /*
  332. // Override to remove stroke from points. For partial fill.
  333. pointAttribs: function () {
  334. var series = this,
  335. retVal = columnType.prototype.pointAttribs
  336. .apply(series,
  337. arguments);
  338. //retVal['stroke-width'] = 0;
  339. return retVal;
  340. }
  341. //*/
  342. /* eslint-enable valid-jsdoc */
  343. }
  344. /* *
  345. *
  346. * Functions
  347. *
  348. * */
  349. /* eslint-disable valid-jsdoc */
  350. /**
  351. * @private
  352. * @function Highcarts.seriesTypes.xrange#init
  353. * @return {void}
  354. */
  355. XRangeSeries.prototype.init = function () {
  356. ColumnSeries.prototype.init.apply(this, arguments);
  357. this.options.stacking = void 0; // #13161
  358. };
  359. /**
  360. * Borrow the column series metrics, but with swapped axes. This gives
  361. * free access to features like groupPadding, grouping, pointWidth etc.
  362. *
  363. * @private
  364. * @function Highcharts.Series#getColumnMetrics
  365. *
  366. * @return {Highcharts.ColumnMetricsObject}
  367. */
  368. XRangeSeries.prototype.getColumnMetrics = function () {
  369. var metrics,
  370. chart = this.chart;
  371. /**
  372. * @private
  373. */
  374. function swapAxes() {
  375. chart.series.forEach(function (s) {
  376. var xAxis = s.xAxis;
  377. s.xAxis = s.yAxis;
  378. s.yAxis = xAxis;
  379. });
  380. }
  381. swapAxes();
  382. metrics = columnProto.getColumnMetrics.call(this);
  383. swapAxes();
  384. return metrics;
  385. };
  386. /**
  387. * Override cropData to show a point where x or x2 is outside visible
  388. * range, but one of them is inside.
  389. *
  390. * @private
  391. * @function Highcharts.Series#cropData
  392. *
  393. * @param {Array<number>} xData
  394. *
  395. * @param {Array<number>} yData
  396. *
  397. * @param {number} min
  398. *
  399. * @param {number} max
  400. *
  401. * @param {number} [cropShoulder]
  402. *
  403. * @return {*}
  404. */
  405. XRangeSeries.prototype.cropData = function (xData, yData, min, max) {
  406. // Replace xData with x2Data to find the appropriate cropStart
  407. var cropData = Series.prototype.cropData,
  408. crop = cropData.call(this,
  409. this.x2Data,
  410. yData,
  411. min,
  412. max);
  413. // Re-insert the cropped xData
  414. crop.xData = xData.slice(crop.start, crop.end);
  415. return crop;
  416. };
  417. /**
  418. * Finds the index of an existing point that matches the given point
  419. * options.
  420. *
  421. * @private
  422. * @function Highcharts.Series#findPointIndex
  423. * @param {object} options The options of the point.
  424. * @returns {number|undefined} Returns index of a matching point,
  425. * returns undefined if no match is found.
  426. */
  427. XRangeSeries.prototype.findPointIndex = function (options) {
  428. var _a = this,
  429. cropped = _a.cropped,
  430. cropStart = _a.cropStart,
  431. points = _a.points;
  432. var id = options.id;
  433. var pointIndex;
  434. if (id) {
  435. var point = find(points,
  436. function (point) {
  437. return point.id === id;
  438. });
  439. pointIndex = point ? point.index : void 0;
  440. }
  441. if (typeof pointIndex === 'undefined') {
  442. var point = find(points,
  443. function (point) {
  444. return (point.x === options.x &&
  445. point.x2 === options.x2 &&
  446. !point.touched);
  447. });
  448. pointIndex = point ? point.index : void 0;
  449. }
  450. // Reduce pointIndex if data is cropped
  451. if (cropped &&
  452. isNumber(pointIndex) &&
  453. isNumber(cropStart) &&
  454. pointIndex >= cropStart) {
  455. pointIndex -= cropStart;
  456. }
  457. return pointIndex;
  458. };
  459. /**
  460. * @private
  461. * @function Highcharts.Series#translatePoint
  462. *
  463. * @param {Highcharts.Point} point
  464. */
  465. XRangeSeries.prototype.translatePoint = function (point) {
  466. var _a,
  467. _b;
  468. var series = this,
  469. xAxis = series.xAxis,
  470. yAxis = series.yAxis,
  471. metrics = series.columnMetrics,
  472. options = series.options,
  473. minPointLength = options.minPointLength || 0,
  474. oldColWidth = ((_a = point.shapeArgs) === null || _a === void 0 ? void 0 : _a.width) / 2,
  475. seriesXOffset = series.pointXOffset = metrics.offset,
  476. plotX = point.plotX,
  477. posX = pick(point.x2,
  478. point.x + (point.len || 0)),
  479. plotX2 = xAxis.translate(posX, 0, 0, 0, 1),
  480. length = Math.abs(plotX2 - plotX),
  481. widthDifference,
  482. shapeArgs,
  483. partialFill,
  484. inverted = this.chart.inverted,
  485. borderWidth = pick(options.borderWidth, 1),
  486. crisper = borderWidth % 2 / 2,
  487. yOffset = metrics.offset,
  488. pointHeight = Math.round(metrics.width),
  489. dlLeft,
  490. dlRight,
  491. dlWidth,
  492. clipRectWidth,
  493. tooltipYOffset;
  494. if (minPointLength) {
  495. widthDifference = minPointLength - length;
  496. if (widthDifference < 0) {
  497. widthDifference = 0;
  498. }
  499. plotX -= widthDifference / 2;
  500. plotX2 += widthDifference / 2;
  501. }
  502. plotX = Math.max(plotX, -10);
  503. plotX2 = clamp(plotX2, -10, xAxis.len + 10);
  504. // Handle individual pointWidth
  505. if (defined(point.options.pointWidth)) {
  506. yOffset -= ((Math.ceil(point.options.pointWidth) - pointHeight) / 2);
  507. pointHeight = Math.ceil(point.options.pointWidth);
  508. }
  509. // Apply pointPlacement to the Y axis
  510. if (options.pointPlacement &&
  511. isNumber(point.plotY) &&
  512. yAxis.categories) {
  513. point.plotY = yAxis.translate(point.y, 0, 1, 0, 1, options.pointPlacement);
  514. }
  515. point.shapeArgs = {
  516. x: Math.floor(Math.min(plotX, plotX2)) + crisper,
  517. y: Math.floor(point.plotY + yOffset) + crisper,
  518. width: Math.round(Math.abs(plotX2 - plotX)),
  519. height: pointHeight,
  520. r: series.options.borderRadius
  521. };
  522. // Move tooltip to default position
  523. if (!inverted) {
  524. point.tooltipPos[0] -= oldColWidth +
  525. seriesXOffset -
  526. ((_b = point.shapeArgs) === null || _b === void 0 ? void 0 : _b.width) / 2;
  527. }
  528. else {
  529. point.tooltipPos[1] += seriesXOffset +
  530. oldColWidth;
  531. }
  532. // Align data labels inside the shape and inside the plot area
  533. dlLeft = point.shapeArgs.x;
  534. dlRight = dlLeft + point.shapeArgs.width;
  535. if (dlLeft < 0 || dlRight > xAxis.len) {
  536. dlLeft = clamp(dlLeft, 0, xAxis.len);
  537. dlRight = clamp(dlRight, 0, xAxis.len);
  538. dlWidth = dlRight - dlLeft;
  539. point.dlBox = merge(point.shapeArgs, {
  540. x: dlLeft,
  541. width: dlRight - dlLeft,
  542. centerX: dlWidth ? dlWidth / 2 : null
  543. });
  544. }
  545. else {
  546. point.dlBox = null;
  547. }
  548. // Tooltip position
  549. var tooltipPos = point.tooltipPos;
  550. var xIndex = !inverted ? 0 : 1;
  551. var yIndex = !inverted ? 1 : 0;
  552. tooltipYOffset = series.columnMetrics ?
  553. series.columnMetrics.offset : -metrics.width / 2;
  554. // Centering tooltip position (#14147)
  555. if (!inverted) {
  556. tooltipPos[xIndex] += (xAxis.reversed ? -1 : 0) * point.shapeArgs.width;
  557. }
  558. else {
  559. tooltipPos[xIndex] += point.shapeArgs.width / 2;
  560. }
  561. tooltipPos[yIndex] = clamp(tooltipPos[yIndex] + ((inverted ? -1 : 1) * tooltipYOffset), 0, yAxis.len - 1);
  562. // Add a partShapeArgs to the point, based on the shapeArgs property
  563. partialFill = point.partialFill;
  564. if (partialFill) {
  565. // Get the partial fill amount
  566. if (isObject(partialFill)) {
  567. partialFill = partialFill.amount;
  568. }
  569. // If it was not a number, assume 0
  570. if (!isNumber(partialFill)) {
  571. partialFill = 0;
  572. }
  573. shapeArgs = point.shapeArgs;
  574. point.partShapeArgs = {
  575. x: shapeArgs.x,
  576. y: shapeArgs.y,
  577. width: shapeArgs.width,
  578. height: shapeArgs.height,
  579. r: series.options.borderRadius
  580. };
  581. clipRectWidth = Math.max(Math.round(length * partialFill + point.plotX -
  582. plotX), 0);
  583. point.clipRectArgs = {
  584. x: xAxis.reversed ? // #10717
  585. shapeArgs.x + length - clipRectWidth :
  586. shapeArgs.x,
  587. y: shapeArgs.y,
  588. width: clipRectWidth,
  589. height: shapeArgs.height
  590. };
  591. }
  592. };
  593. /**
  594. * @private
  595. * @function Highcharts.Series#translate
  596. */
  597. XRangeSeries.prototype.translate = function () {
  598. columnProto.translate.apply(this, arguments);
  599. this.points.forEach(function (point) {
  600. this.translatePoint(point);
  601. }, this);
  602. };
  603. /**
  604. * Draws a single point in the series. Needed for partial fill.
  605. *
  606. * This override turns point.graphic into a group containing the
  607. * original graphic and an overlay displaying the partial fill.
  608. *
  609. * @private
  610. * @function Highcharts.Series#drawPoint
  611. *
  612. * @param {Highcharts.Point} point
  613. * An instance of Point in the series.
  614. *
  615. * @param {"animate"|"attr"} verb
  616. * 'animate' (animates changes) or 'attr' (sets options)
  617. */
  618. XRangeSeries.prototype.drawPoint = function (point, verb) {
  619. var series = this,
  620. seriesOpts = series.options,
  621. renderer = series.chart.renderer,
  622. graphic = point.graphic,
  623. type = point.shapeType,
  624. shapeArgs = point.shapeArgs,
  625. partShapeArgs = point.partShapeArgs,
  626. clipRectArgs = point.clipRectArgs,
  627. pfOptions = point.partialFill,
  628. cutOff = seriesOpts.stacking && !seriesOpts.borderRadius,
  629. pointState = point.state,
  630. stateOpts = (seriesOpts.states[pointState || 'normal'] ||
  631. {}),
  632. pointStateVerb = typeof pointState === 'undefined' ?
  633. 'attr' : verb,
  634. pointAttr = series.pointAttribs(point,
  635. pointState),
  636. animation = pick(series.chart.options.chart.animation,
  637. stateOpts.animation),
  638. fill;
  639. if (!point.isNull && point.visible !== false) {
  640. // Original graphic
  641. if (graphic) { // update
  642. graphic.rect[verb](shapeArgs);
  643. }
  644. else {
  645. point.graphic = graphic = renderer.g('point')
  646. .addClass(point.getClassName())
  647. .add(point.group || series.group);
  648. graphic.rect = renderer[type](merge(shapeArgs))
  649. .addClass(point.getClassName())
  650. .addClass('highcharts-partfill-original')
  651. .add(graphic);
  652. }
  653. // Partial fill graphic
  654. if (partShapeArgs) {
  655. if (graphic.partRect) {
  656. graphic.partRect[verb](merge(partShapeArgs));
  657. graphic.partialClipRect[verb](merge(clipRectArgs));
  658. }
  659. else {
  660. graphic.partialClipRect = renderer.clipRect(clipRectArgs.x, clipRectArgs.y, clipRectArgs.width, clipRectArgs.height);
  661. graphic.partRect =
  662. renderer[type](partShapeArgs)
  663. .addClass('highcharts-partfill-overlay')
  664. .add(graphic)
  665. .clip(graphic.partialClipRect);
  666. }
  667. }
  668. // Presentational
  669. if (!series.chart.styledMode) {
  670. graphic
  671. .rect[verb](pointAttr, animation)
  672. .shadow(seriesOpts.shadow, null, cutOff);
  673. if (partShapeArgs) {
  674. // Ensure pfOptions is an object
  675. if (!isObject(pfOptions)) {
  676. pfOptions = {};
  677. }
  678. if (isObject(seriesOpts.partialFill)) {
  679. pfOptions = merge(seriesOpts.partialFill, pfOptions);
  680. }
  681. fill = (pfOptions.fill ||
  682. color(pointAttr.fill).brighten(-0.3).get() ||
  683. color(point.color || series.color)
  684. .brighten(-0.3).get());
  685. pointAttr.fill = fill;
  686. graphic
  687. .partRect[pointStateVerb](pointAttr, animation)
  688. .shadow(seriesOpts.shadow, null, cutOff);
  689. }
  690. }
  691. }
  692. else if (graphic) {
  693. point.graphic = graphic.destroy(); // #1269
  694. }
  695. };
  696. /**
  697. * @private
  698. * @function Highcharts.Series#drawPoints
  699. */
  700. XRangeSeries.prototype.drawPoints = function () {
  701. var series = this,
  702. verb = series.getAnimationVerb();
  703. // Draw the columns
  704. series.points.forEach(function (point) {
  705. series.drawPoint(point, verb);
  706. });
  707. };
  708. /**
  709. * Returns "animate", or "attr" if the number of points is above the
  710. * animation limit.
  711. *
  712. * @private
  713. * @function Highcharts.Series#getAnimationVerb
  714. *
  715. * @return {string}
  716. */
  717. XRangeSeries.prototype.getAnimationVerb = function () {
  718. return (this.chart.pointCount < (this.options.animationLimit || 250) ?
  719. 'animate' :
  720. 'attr');
  721. };
  722. /**
  723. * @private
  724. * @function Highcharts.XRangeSeries#isPointInside
  725. */
  726. XRangeSeries.prototype.isPointInside = function (point) {
  727. var shapeArgs = point.shapeArgs,
  728. plotX = point.plotX,
  729. plotY = point.plotY;
  730. if (!shapeArgs) {
  731. return _super.prototype.isPointInside.apply(this, arguments);
  732. }
  733. var isInside = typeof plotX !== 'undefined' &&
  734. typeof plotY !== 'undefined' &&
  735. plotY >= 0 &&
  736. plotY <= this.yAxis.len &&
  737. shapeArgs.x + shapeArgs.width >= 0 &&
  738. plotX <= this.xAxis.len;
  739. return isInside;
  740. };
  741. /* *
  742. *
  743. * Static properties
  744. *
  745. * */
  746. /**
  747. * The X-range series displays ranges on the X axis, typically time
  748. * intervals with a start and end date.
  749. *
  750. * @sample {highcharts} highcharts/demo/x-range/
  751. * X-range
  752. * @sample {highcharts} highcharts/css/x-range/
  753. * Styled mode X-range
  754. * @sample {highcharts} highcharts/chart/inverted-xrange/
  755. * Inverted X-range
  756. *
  757. * @extends plotOptions.column
  758. * @since 6.0.0
  759. * @product highcharts highstock gantt
  760. * @excluding boostThreshold, crisp, cropThreshold, depth, edgeColor,
  761. * edgeWidth, findNearestPointBy, getExtremesFromAll,
  762. * negativeColor, pointInterval, pointIntervalUnit,
  763. * pointPlacement, pointRange, pointStart, softThreshold,
  764. * stacking, threshold, data, dataSorting, boostBlending
  765. * @requires modules/xrange
  766. * @optionparent plotOptions.xrange
  767. */
  768. XRangeSeries.defaultOptions = merge(ColumnSeries.defaultOptions, {
  769. /**
  770. * A partial fill for each point, typically used to visualize how much
  771. * of a task is performed. The partial fill object can be set either on
  772. * series or point level.
  773. *
  774. * @sample {highcharts} highcharts/demo/x-range
  775. * X-range with partial fill
  776. *
  777. * @product highcharts highstock gantt
  778. * @apioption plotOptions.xrange.partialFill
  779. */
  780. /**
  781. * The fill color to be used for partial fills. Defaults to a darker
  782. * shade of the point color.
  783. *
  784. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  785. * @product highcharts highstock gantt
  786. * @apioption plotOptions.xrange.partialFill.fill
  787. */
  788. /**
  789. * A partial fill for each point, typically used to visualize how much
  790. * of a task is performed. See [completed](series.gantt.data.completed).
  791. *
  792. * @sample gantt/demo/progress-indicator
  793. * Gantt with progress indicator
  794. *
  795. * @product gantt
  796. * @apioption plotOptions.gantt.partialFill
  797. */
  798. /**
  799. * In an X-range series, this option makes all points of the same Y-axis
  800. * category the same color.
  801. */
  802. colorByPoint: true,
  803. dataLabels: {
  804. formatter: function () {
  805. var point = this.point,
  806. amount = point.partialFill;
  807. if (isObject(amount)) {
  808. amount = amount.amount;
  809. }
  810. if (isNumber(amount) && amount > 0) {
  811. return correctFloat(amount * 100) + '%';
  812. }
  813. },
  814. inside: true,
  815. verticalAlign: 'middle'
  816. },
  817. tooltip: {
  818. headerFormat: '<span style="font-size: 10px">{point.x} - {point.x2}</span><br/>',
  819. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.yCategory}</b><br/>'
  820. },
  821. borderRadius: 3,
  822. pointRange: 0
  823. });
  824. return XRangeSeries;
  825. }(ColumnSeries));
  826. extend(XRangeSeries.prototype, {
  827. type: 'xrange',
  828. parallelArrays: ['x', 'x2', 'y'],
  829. requireSorting: false,
  830. animate: Series.prototype.animate,
  831. cropShoulder: 1,
  832. getExtremesFromAll: true,
  833. autoIncrement: H.noop,
  834. buildKDTree: H.noop,
  835. pointClass: XRangePoint
  836. });
  837. SeriesRegistry.registerSeriesType('xrange', XRangeSeries);
  838. /* *
  839. *
  840. * Default Export
  841. *
  842. * */
  843. /* *
  844. *
  845. * API Options
  846. *
  847. * */
  848. /**
  849. * An `xrange` series. If the [type](#series.xrange.type) option is not
  850. * specified, it is inherited from [chart.type](#chart.type).
  851. *
  852. * @extends series,plotOptions.xrange
  853. * @excluding boostThreshold, crisp, cropThreshold, depth, edgeColor, edgeWidth,
  854. * findNearestPointBy, getExtremesFromAll, negativeColor,
  855. * pointInterval, pointIntervalUnit, pointPlacement, pointRange,
  856. * pointStart, softThreshold, stacking, threshold, dataSorting,
  857. * boostBlending
  858. * @product highcharts highstock gantt
  859. * @requires modules/xrange
  860. * @apioption series.xrange
  861. */
  862. /**
  863. * An array of data points for the series. For the `xrange` series type,
  864. * points can be given in the following ways:
  865. *
  866. * 1. An array of objects with named values. The objects are point configuration
  867. * objects as seen below.
  868. * ```js
  869. * data: [{
  870. * x: Date.UTC(2017, 0, 1),
  871. * x2: Date.UTC(2017, 0, 3),
  872. * name: "Test",
  873. * y: 0,
  874. * color: "#00FF00"
  875. * }, {
  876. * x: Date.UTC(2017, 0, 4),
  877. * x2: Date.UTC(2017, 0, 5),
  878. * name: "Deploy",
  879. * y: 1,
  880. * color: "#FF0000"
  881. * }]
  882. * ```
  883. *
  884. * @sample {highcharts} highcharts/series/data-array-of-objects/
  885. * Config objects
  886. *
  887. * @declare Highcharts.XrangePointOptionsObject
  888. * @type {Array<*>}
  889. * @extends series.line.data
  890. * @product highcharts highstock gantt
  891. * @apioption series.xrange.data
  892. */
  893. /**
  894. * The starting X value of the range point.
  895. *
  896. * @sample {highcharts} highcharts/demo/x-range
  897. * X-range
  898. *
  899. * @type {number}
  900. * @product highcharts highstock gantt
  901. * @apioption series.xrange.data.x
  902. */
  903. /**
  904. * The ending X value of the range point.
  905. *
  906. * @sample {highcharts} highcharts/demo/x-range
  907. * X-range
  908. *
  909. * @type {number}
  910. * @product highcharts highstock gantt
  911. * @apioption series.xrange.data.x2
  912. */
  913. /**
  914. * The Y value of the range point.
  915. *
  916. * @sample {highcharts} highcharts/demo/x-range
  917. * X-range
  918. *
  919. * @type {number}
  920. * @product highcharts highstock gantt
  921. * @apioption series.xrange.data.y
  922. */
  923. /**
  924. * A partial fill for each point, typically used to visualize how much of
  925. * a task is performed. The partial fill object can be set either on series
  926. * or point level.
  927. *
  928. * @sample {highcharts} highcharts/demo/x-range
  929. * X-range with partial fill
  930. *
  931. * @declare Highcharts.XrangePointPartialFillOptionsObject
  932. * @product highcharts highstock gantt
  933. * @apioption series.xrange.data.partialFill
  934. */
  935. /**
  936. * The amount of the X-range point to be filled. Values can be 0-1 and are
  937. * converted to percentages in the default data label formatter.
  938. *
  939. * @type {number}
  940. * @product highcharts highstock gantt
  941. * @apioption series.xrange.data.partialFill.amount
  942. */
  943. /**
  944. * The fill color to be used for partial fills. Defaults to a darker shade
  945. * of the point color.
  946. *
  947. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  948. * @product highcharts highstock gantt
  949. * @apioption series.xrange.data.partialFill.fill
  950. */
  951. ''; // adds doclets above to transpiled file
  952. return XRangeSeries;
  953. });
  954. _registerModule(_modules, 'masters/modules/xrange.src.js', [], function () {
  955. });
  956. }));