static-scale.src.js 4.6 KB

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