Highcharts Demo

author(s): Torstein Hønsi

by Black Label

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container"></div>

CSS

#container {
    height: 300px;
    width: 250px;
}

JavaScript

(function(H) {
  const {
    isString,
    correctFloat
  } = H;
  H.Axis.prototype.renderUnsquish = function() {
    const chart = this.chart,
      renderer = chart.renderer,
      tickPositions = this.tickPositions,
      ticks = this.ticks,
      labelOptions = this.options.labels,
      labelStyleOptions = labelOptions.style,
      horiz = this.horiz,
      slotWidth = this.getSlotWidth(),
      innerWidth = Math.max(1, Math.round(slotWidth - 2 * labelOptions.padding)),
      attr = {},
      labelMetrics = this.labelMetrics(),
      textOverflowOption = labelStyleOptions.textOverflow;
    let commonWidth, commonTextOverflow, maxLabelLength = 0,
      label, i, pos;
    // Set rotation option unless it is "auto", like in gauges
    if (!isString(labelOptions.rotation)) {
      // #4443
      attr.rotation = labelOptions.rotation || 0;
    }
    // Get the longest label length
    tickPositions.forEach(function(tickPosition) {
      const tick = ticks[tickPosition];
      // Replace label - sorting animation
      if (tick.movedLabel) {
        tick.replaceMovedLabel();
      }
      if (tick &&
        tick.label &&
        tick.label.textPxLength > maxLabelLength) {
        maxLabelLength = tick.label.textPxLength;
      }
    });
    this.maxLabelLength = maxLabelLength;
    // Handle auto rotation on horizontal axis
    if (this.autoRotation) {
      // Apply rotation only if the label is too wide for the slot, and
      // the label is wider than its height.
      if (maxLabelLength > innerWidth &&
        maxLabelLength > labelMetrics.h) {
        attr.rotation = this.labelRotation;
      } else {
        this.labelRotation = 0;



        // --- FIX ---
        const tickInterval = this.tickInterval,
          slotSize = this.len / (((this.categories ? 1 : 0) +
              this.max -
              this.min) /
            tickInterval),
          range = Math.max(this.max - this.min, 0),
          // Return the multiple of tickInterval that is needed...