static-scale.src.js 4.7 KB

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