static-scale.src.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * @license Highcharts Gantt JS v8.1.2 (2020-06-16)
  3. *
  4. * StaticScale
  5. *
  6. * (c) 2016-2019 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/static-scale', ['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, 'modules/static-scale.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  32. /* *
  33. *
  34. * (c) 2016-2020 Torstein Honsi, Lars Cabrera
  35. *
  36. * License: www.highcharts.com/license
  37. *
  38. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  39. *
  40. * */
  41. var addEvent = U.addEvent, defined = U.defined, isNumber = U.isNumber, pick = U.pick;
  42. var Chart = H.Chart;
  43. /* eslint-disable no-invalid-this */
  44. /**
  45. * For vertical axes only. Setting the static scale ensures that each tick unit
  46. * is translated into a fixed pixel height. For example, setting the static
  47. * scale to 24 results in each Y axis category taking up 24 pixels, and the
  48. * height of the chart adjusts. Adding or removing items will make the chart
  49. * resize.
  50. *
  51. * @sample gantt/xrange-series/demo/
  52. * X-range series with static scale
  53. *
  54. * @type {number}
  55. * @default 50
  56. * @since 6.2.0
  57. * @product gantt
  58. * @apioption yAxis.staticScale
  59. */
  60. addEvent(H.Axis, 'afterSetOptions', function () {
  61. var chartOptions = this.chart.options && this.chart.options.chart;
  62. if (!this.horiz &&
  63. isNumber(this.options.staticScale) &&
  64. (!chartOptions.height ||
  65. (chartOptions.scrollablePlotArea &&
  66. chartOptions.scrollablePlotArea.minHeight))) {
  67. this.staticScale = this.options.staticScale;
  68. }
  69. });
  70. Chart.prototype.adjustHeight = function () {
  71. if (this.redrawTrigger !== 'adjustHeight') {
  72. (this.axes || []).forEach(function (axis) {
  73. var chart = axis.chart, animate = !!chart.initiatedScale &&
  74. chart.options.animation, staticScale = axis.options.staticScale, height, diff;
  75. if (axis.staticScale && defined(axis.min)) {
  76. height = pick(axis.brokenAxis && axis.brokenAxis.unitLength, axis.max + axis.tickInterval - axis.min) * staticScale;
  77. // Minimum height is 1 x staticScale.
  78. height = Math.max(height, staticScale);
  79. diff = height - chart.plotHeight;
  80. if (Math.abs(diff) >= 1) {
  81. chart.plotHeight = height;
  82. chart.redrawTrigger = 'adjustHeight';
  83. chart.setSize(void 0, chart.chartHeight + diff, animate);
  84. }
  85. // Make sure clip rects have the right height before initial
  86. // animation.
  87. axis.series.forEach(function (series) {
  88. var clipRect = series.sharedClipKey &&
  89. chart[series.sharedClipKey];
  90. if (clipRect) {
  91. clipRect.attr({
  92. height: chart.plotHeight
  93. });
  94. }
  95. });
  96. }
  97. });
  98. this.initiatedScale = true;
  99. }
  100. this.redrawTrigger = null;
  101. };
  102. addEvent(Chart, 'render', Chart.prototype.adjustHeight);
  103. });
  104. _registerModule(_modules, 'masters/modules/static-scale.src.js', [], function () {
  105. });
  106. }));