variwide.src.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /**
  2. * @license Highcharts JS v9.1.1 (2021-06-04)
  3. *
  4. * Highcharts variwide module
  5. *
  6. * (c) 2010-2021 Torstein Honsi
  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/variwide', ['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/Variwide/VariwidePoint.js', [_modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (SeriesRegistry, U) {
  32. /* *
  33. *
  34. * Highcharts variwide module
  35. *
  36. * (c) 2010-2021 Torstein Honsi
  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. var isNumber = U.isNumber;
  61. /* *
  62. *
  63. * Class
  64. *
  65. * */
  66. var VariwidePoint = /** @class */ (function (_super) {
  67. __extends(VariwidePoint, _super);
  68. function VariwidePoint() {
  69. var _this = _super !== null && _super.apply(this,
  70. arguments) || this;
  71. /* *
  72. *
  73. * Properites
  74. *
  75. * */
  76. _this.crosshairWidth = void 0;
  77. _this.options = void 0;
  78. _this.series = void 0;
  79. return _this;
  80. }
  81. /* *
  82. *
  83. * Functions
  84. *
  85. * */
  86. VariwidePoint.prototype.isValid = function () {
  87. return isNumber(this.y) && isNumber(this.z);
  88. };
  89. return VariwidePoint;
  90. }(ColumnSeries.prototype.pointClass));
  91. /* *
  92. *
  93. * Export
  94. *
  95. * */
  96. return VariwidePoint;
  97. });
  98. _registerModule(_modules, 'Series/Variwide/VariwideComposition.js', [_modules['Core/Axis/Tick.js'], _modules['Core/Axis/Axis.js'], _modules['Core/Utilities.js']], function (Tick, Axis, U) {
  99. /* *
  100. *
  101. * Highcharts variwide module
  102. *
  103. * (c) 2010-2021 Torstein Honsi
  104. *
  105. * License: www.highcharts.com/license
  106. *
  107. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  108. *
  109. * */
  110. var addEvent = U.addEvent,
  111. wrap = U.wrap;
  112. /* *
  113. *
  114. * Composition
  115. *
  116. * */
  117. Tick.prototype.postTranslate = function (xy, xOrY, index) {
  118. var axis = this.axis;
  119. var pos = xy[xOrY] - axis.pos;
  120. if (!axis.horiz) {
  121. pos = axis.len - pos;
  122. }
  123. pos = axis.series[0].postTranslate(index, pos);
  124. if (!axis.horiz) {
  125. pos = axis.len - pos;
  126. }
  127. xy[xOrY] = axis.pos + pos;
  128. };
  129. /* eslint-disable no-invalid-this */
  130. // Same width as the category (#8083)
  131. addEvent(Axis, 'afterDrawCrosshair', function (e) {
  132. if (this.variwide && this.cross) {
  133. this.cross.attr('stroke-width', (e.point && e.point.crosshairWidth));
  134. }
  135. });
  136. // On a vertical axis, apply anti-collision logic to the labels.
  137. addEvent(Axis, 'afterRender', function () {
  138. var axis = this;
  139. if (!this.horiz && this.variwide) {
  140. this.chart.labelCollectors.push(function () {
  141. return axis.tickPositions
  142. .filter(function (pos) {
  143. return axis.ticks[pos].label;
  144. })
  145. .map(function (pos, i) {
  146. var label = axis.ticks[pos].label;
  147. label.labelrank = axis.zData[i];
  148. return label;
  149. });
  150. });
  151. }
  152. });
  153. addEvent(Tick, 'afterGetPosition', function (e) {
  154. var axis = this.axis,
  155. xOrY = axis.horiz ? 'x' : 'y';
  156. if (axis.variwide) {
  157. this[xOrY + 'Orig'] = e.pos[xOrY];
  158. this.postTranslate(e.pos, xOrY, this.pos);
  159. }
  160. });
  161. wrap(Tick.prototype, 'getLabelPosition', function (proceed, x, y, label, horiz, labelOptions, tickmarkOffset, index) {
  162. var args = Array.prototype.slice.call(arguments, 1),
  163. xy,
  164. xOrY = horiz ? 'x' : 'y';
  165. // Replace the x with the original x
  166. if (this.axis.variwide &&
  167. typeof this[xOrY + 'Orig'] === 'number') {
  168. args[horiz ? 0 : 1] = this[xOrY + 'Orig'];
  169. }
  170. xy = proceed.apply(this, args);
  171. // Post-translate
  172. if (this.axis.variwide && this.axis.categories) {
  173. this.postTranslate(xy, xOrY, this.pos);
  174. }
  175. return xy;
  176. });
  177. });
  178. _registerModule(_modules, 'Series/Variwide/VariwideSeries.js', [_modules['Core/Series/SeriesRegistry.js'], _modules['Series/Variwide/VariwidePoint.js'], _modules['Core/Utilities.js']], function (SeriesRegistry, VariwidePoint, U) {
  179. /* *
  180. *
  181. * Highcharts variwide module
  182. *
  183. * (c) 2010-2021 Torstein Honsi
  184. *
  185. * License: www.highcharts.com/license
  186. *
  187. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  188. *
  189. * */
  190. var __extends = (this && this.__extends) || (function () {
  191. var extendStatics = function (d,
  192. b) {
  193. extendStatics = Object.setPrototypeOf ||
  194. ({ __proto__: [] } instanceof Array && function (d,
  195. b) { d.__proto__ = b; }) ||
  196. function (d,
  197. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  198. return extendStatics(d, b);
  199. };
  200. return function (d, b) {
  201. extendStatics(d, b);
  202. function __() { this.constructor = d; }
  203. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  204. };
  205. })();
  206. var ColumnSeries = SeriesRegistry.seriesTypes.column;
  207. var extend = U.extend,
  208. merge = U.merge,
  209. pick = U.pick;
  210. /* *
  211. *
  212. * Class
  213. *
  214. * */
  215. /**
  216. * @private
  217. * @class
  218. * @name Highcharts.seriesTypes.variwide
  219. *
  220. * @augments Highcharts.Series
  221. */
  222. var VariwideSeries = /** @class */ (function (_super) {
  223. __extends(VariwideSeries, _super);
  224. function VariwideSeries() {
  225. var _this = _super !== null && _super.apply(this,
  226. arguments) || this;
  227. /* *
  228. *
  229. * Properties
  230. *
  231. * */
  232. _this.data = void 0;
  233. _this.options = void 0;
  234. _this.points = void 0;
  235. _this.relZ = void 0;
  236. _this.totalZ = void 0;
  237. _this.zData = void 0;
  238. return _this;
  239. }
  240. /* *
  241. *
  242. * Functions
  243. *
  244. * */
  245. VariwideSeries.prototype.processData = function (force) {
  246. this.totalZ = 0;
  247. this.relZ = [];
  248. SeriesRegistry.seriesTypes.column.prototype.processData.call(this, force);
  249. (this.xAxis.reversed ?
  250. this.zData.slice().reverse() :
  251. this.zData).forEach(function (z, i) {
  252. this.relZ[i] = this.totalZ;
  253. this.totalZ += z;
  254. }, this);
  255. if (this.xAxis.categories) {
  256. this.xAxis.variwide = true;
  257. this.xAxis.zData = this.zData; // Used for label rank
  258. }
  259. return;
  260. };
  261. /* eslint-disable valid-jsdoc */
  262. /**
  263. * Translate an x value inside a given category index into the distorted
  264. * axis translation.
  265. *
  266. * @private
  267. * @function Highcharts.Series#postTranslate
  268. *
  269. * @param {number} index
  270. * The category index
  271. *
  272. * @param {number} x
  273. * The X pixel position in undistorted axis pixels
  274. *
  275. * @param {Highcharts.Point} point
  276. * For crosshairWidth for every point
  277. *
  278. * @return {number}
  279. * Distorted X position
  280. */
  281. VariwideSeries.prototype.postTranslate = function (index, x, point) {
  282. var axis = this.xAxis,
  283. relZ = this.relZ,
  284. i = axis.reversed ? relZ.length - index : index,
  285. goRight = axis.reversed ? -1 : 1,
  286. minPx = axis.toPixels(axis.reversed ? (axis.dataMax || 0) + axis.pointRange : (axis.dataMin || 0)),
  287. maxPx = axis.toPixels(axis.reversed ? (axis.dataMin || 0) : (axis.dataMax || 0) + axis.pointRange),
  288. len = Math.abs(maxPx - minPx),
  289. totalZ = this.totalZ,
  290. left = this.chart.inverted ?
  291. maxPx - (this.chart.plotTop - goRight * axis.minPixelPadding) :
  292. minPx - this.chart.plotLeft - goRight * axis.minPixelPadding,
  293. linearSlotLeft = i / relZ.length * len,
  294. linearSlotRight = (i + goRight) / relZ.length * len,
  295. slotLeft = (pick(relZ[i],
  296. totalZ) / totalZ) * len,
  297. slotRight = (pick(relZ[i + goRight],
  298. totalZ) / totalZ) * len,
  299. xInsideLinearSlot = (x - (left + linearSlotLeft));
  300. // Set crosshairWidth for every point (#8173)
  301. if (point) {
  302. point.crosshairWidth = slotRight - slotLeft;
  303. }
  304. return left + slotLeft +
  305. xInsideLinearSlot * (slotRight - slotLeft) /
  306. (linearSlotRight - linearSlotLeft);
  307. };
  308. /* eslint-enable valid-jsdoc */
  309. // Extend translation by distoring X position based on Z.
  310. VariwideSeries.prototype.translate = function () {
  311. // Temporarily disable crisping when computing original shapeArgs
  312. var crispOption = this.options.crisp,
  313. xAxis = this.xAxis;
  314. this.options.crisp = false;
  315. SeriesRegistry.seriesTypes.column.prototype.translate.call(this);
  316. // Reset option
  317. this.options.crisp = crispOption;
  318. var inverted = this.chart.inverted,
  319. crisp = this.borderWidth % 2 / 2;
  320. // Distort the points to reflect z dimension
  321. this.points.forEach(function (point, i) {
  322. var left,
  323. right;
  324. if (xAxis.variwide) {
  325. left = this.postTranslate(i, point.shapeArgs.x, point);
  326. right = this.postTranslate(i, point.shapeArgs.x +
  327. point.shapeArgs.width);
  328. // For linear or datetime axes, the variwide column should
  329. // start with X and extend Z units, without modifying the
  330. // axis.
  331. }
  332. else {
  333. left = point.plotX;
  334. right = xAxis.translate(point.x + point.z, 0, 0, 0, 1);
  335. }
  336. if (this.options.crisp) {
  337. left = Math.round(left) - crisp;
  338. right = Math.round(right) - crisp;
  339. }
  340. point.shapeArgs.x = left;
  341. point.shapeArgs.width = Math.max(right - left, 1);
  342. // Crosshair position (#8083)
  343. point.plotX = (left + right) / 2;
  344. // Adjust the tooltip position
  345. if (!inverted) {
  346. point.tooltipPos[0] =
  347. point.shapeArgs.x +
  348. point.shapeArgs.width / 2;
  349. }
  350. else {
  351. point.tooltipPos[1] =
  352. xAxis.len - point.shapeArgs.x -
  353. point.shapeArgs.width / 2;
  354. }
  355. }, this);
  356. if (this.options.stacking) {
  357. this.correctStackLabels();
  358. }
  359. };
  360. // Function that corrects stack labels positions
  361. VariwideSeries.prototype.correctStackLabels = function () {
  362. var series = this,
  363. options = series.options,
  364. yAxis = series.yAxis,
  365. pointStack,
  366. pointWidth,
  367. stack,
  368. xValue;
  369. series.points.forEach(function (point) {
  370. xValue = point.x;
  371. pointWidth = point.shapeArgs.width;
  372. stack = yAxis.stacking.stacks[(series.negStacks &&
  373. point.y < (options.startFromThreshold ?
  374. 0 :
  375. options.threshold) ?
  376. '-' :
  377. '') + series.stackKey];
  378. if (stack) {
  379. pointStack = stack[xValue];
  380. if (pointStack && !point.isNull) {
  381. pointStack.setOffset(-(pointWidth / 2) || 0, pointWidth || 0, void 0, void 0, point.plotX);
  382. }
  383. }
  384. });
  385. };
  386. /* *
  387. *
  388. * Static properties
  389. *
  390. * */
  391. /**
  392. * A variwide chart (related to marimekko chart) is a column chart with a
  393. * variable width expressing a third dimension.
  394. *
  395. * @sample {highcharts} highcharts/demo/variwide/
  396. * Variwide chart
  397. * @sample {highcharts} highcharts/series-variwide/inverted/
  398. * Inverted variwide chart
  399. * @sample {highcharts} highcharts/series-variwide/datetime/
  400. * Variwide columns on a datetime axis
  401. *
  402. * @extends plotOptions.column
  403. * @since 6.0.0
  404. * @product highcharts
  405. * @excluding boostThreshold, crisp, depth, edgeColor, edgeWidth,
  406. * groupZPadding, boostBlending
  407. * @requires modules/variwide
  408. * @optionparent plotOptions.variwide
  409. */
  410. VariwideSeries.defaultOptions = merge(ColumnSeries.defaultOptions, {
  411. /**
  412. * In a variwide chart, the point padding is 0 in order to express the
  413. * horizontal stacking of items.
  414. */
  415. pointPadding: 0,
  416. /**
  417. * In a variwide chart, the group padding is 0 in order to express the
  418. * horizontal stacking of items.
  419. */
  420. groupPadding: 0
  421. });
  422. return VariwideSeries;
  423. }(ColumnSeries));
  424. extend(VariwideSeries.prototype, {
  425. irregularWidths: true,
  426. pointArrayMap: ['y', 'z'],
  427. parallelArrays: ['x', 'y', 'z'],
  428. pointClass: VariwidePoint
  429. });
  430. SeriesRegistry.registerSeriesType('variwide', VariwideSeries);
  431. /* *
  432. *
  433. * Default export
  434. *
  435. * */
  436. /* *
  437. *
  438. * API Options
  439. *
  440. * */
  441. /**
  442. * A `variwide` series. If the [type](#series.variwide.type) option is not
  443. * specified, it is inherited from [chart.type](#chart.type).
  444. *
  445. * @extends series,plotOptions.variwide
  446. * @excluding boostThreshold, boostBlending
  447. * @product highcharts
  448. * @requires modules/variwide
  449. * @apioption series.variwide
  450. */
  451. /**
  452. * An array of data points for the series. For the `variwide` series type,
  453. * points can be given in the following ways:
  454. *
  455. * 1. An array of arrays with 3 or 2 values. In this case, the values correspond
  456. * to `x,y,z`. If the first value is a string, it is applied as the name of
  457. * the point, and the `x` value is inferred. The `x` value can also be
  458. * omitted, in which case the inner arrays should be of length 2. Then the
  459. * `x` value is automatically calculated, either starting at 0 and
  460. * incremented by 1, or from `pointStart` and `pointInterval` given in the
  461. * series options.
  462. * ```js
  463. * data: [
  464. * [0, 1, 2],
  465. * [1, 5, 5],
  466. * [2, 0, 2]
  467. * ]
  468. * ```
  469. *
  470. * 2. An array of objects with named values. The following snippet shows only a
  471. * few settings, see the complete options set below. If the total number of
  472. * data points exceeds the series'
  473. * [turboThreshold](#series.variwide.turboThreshold), this option is not
  474. * available.
  475. * ```js
  476. * data: [{
  477. * x: 1,
  478. * y: 1,
  479. * z: 1,
  480. * name: "Point2",
  481. * color: "#00FF00"
  482. * }, {
  483. * x: 1,
  484. * y: 5,
  485. * z: 4,
  486. * name: "Point1",
  487. * color: "#FF00FF"
  488. * }]
  489. * ```
  490. *
  491. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  492. * Arrays of numeric x and y
  493. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  494. * Arrays of datetime x and y
  495. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  496. * Arrays of point.name and y
  497. * @sample {highcharts} highcharts/series/data-array-of-objects/
  498. * Config objects
  499. *
  500. * @type {Array<Array<(number|string),number>|Array<(number|string),number,number>|*>}
  501. * @extends series.line.data
  502. * @excluding marker
  503. * @product highcharts
  504. * @apioption series.variwide.data
  505. */
  506. /**
  507. * The relative width for each column. On a category axis, the widths are
  508. * distributed so they sum up to the X axis length. On linear and datetime axes,
  509. * the columns will be laid out from the X value and Z units along the axis.
  510. *
  511. * @type {number}
  512. * @product highcharts
  513. * @apioption series.variwide.data.z
  514. */
  515. ''; // adds doclets above to transpiled file
  516. return VariwideSeries;
  517. });
  518. _registerModule(_modules, 'masters/modules/variwide.src.js', [], function () {
  519. });
  520. }));