static-scale.src.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * @license Highcharts JS v7.0.2 (2019-01-17)
  3. * StaticScale
  4. *
  5. * (c) 2016-2019 Torstein Honsi, Lars A. V. Cabrera
  6. *
  7. * License: www.highcharts.com/license
  8. */
  9. 'use strict';
  10. (function (factory) {
  11. if (typeof module === 'object' && module.exports) {
  12. factory['default'] = factory;
  13. module.exports = factory;
  14. } else if (typeof define === 'function' && define.amd) {
  15. define(function () {
  16. return factory;
  17. });
  18. } else {
  19. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  20. }
  21. }(function (Highcharts) {
  22. (function (H) {
  23. /* *
  24. * (c) 2016-2019 Torstein Honsi, Lars Cabrera
  25. *
  26. * License: www.highcharts.com/license
  27. */
  28. var Chart = H.Chart,
  29. pick = H.pick;
  30. /**
  31. * For vertical axes only. Setting the static scale ensures that each tick unit
  32. * is translated into a fixed pixel height. For example, setting the static
  33. * scale to 24 results in each Y axis category taking up 24 pixels, and the
  34. * height of the chart adjusts. Adding or removing items will make the chart
  35. * resize.
  36. *
  37. * @sample gantt/xrange-series/demo/
  38. * X-range series with static scale
  39. *
  40. * @type {number}
  41. * @default 50
  42. * @since 6.2.0
  43. * @product gantt
  44. * @apioption yAxis.staticScale
  45. */
  46. H.addEvent(H.Axis, 'afterSetOptions', function () {
  47. if (
  48. !this.horiz &&
  49. H.isNumber(this.options.staticScale) &&
  50. !this.chart.options.chart.height
  51. ) {
  52. this.staticScale = this.options.staticScale;
  53. }
  54. });
  55. Chart.prototype.adjustHeight = function () {
  56. if (this.redrawTrigger !== 'adjustHeight') {
  57. (this.axes || []).forEach(function (axis) {
  58. var chart = axis.chart,
  59. animate = !!chart.initiatedScale && chart.options.animation,
  60. staticScale = axis.options.staticScale,
  61. height,
  62. diff;
  63. if (axis.staticScale && H.defined(axis.min)) {
  64. height = pick(
  65. axis.unitLength,
  66. axis.max + axis.tickInterval - axis.min
  67. ) * staticScale;
  68. // Minimum height is 1 x staticScale.
  69. height = Math.max(height, staticScale);
  70. diff = height - chart.plotHeight;
  71. if (Math.abs(diff) >= 1) {
  72. chart.plotHeight = height;
  73. chart.redrawTrigger = 'adjustHeight';
  74. chart.setSize(undefined, chart.chartHeight + diff, animate);
  75. }
  76. // Make sure clip rects have the right height before initial
  77. // animation.
  78. axis.series.forEach(function (series) {
  79. var clipRect =
  80. series.sharedClipKey && chart[series.sharedClipKey];
  81. if (clipRect) {
  82. clipRect.attr({
  83. height: chart.plotHeight
  84. });
  85. }
  86. });
  87. }
  88. });
  89. this.initiatedScale = true;
  90. }
  91. this.redrawTrigger = null;
  92. };
  93. H.addEvent(Chart, 'render', Chart.prototype.adjustHeight);
  94. }(Highcharts));
  95. return (function () {
  96. }());
  97. }));