Tooltip under transform scale

by kzoon

HTML

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

<div style="transform: scale(1.5); width:500px; height500px;">
  <div id="container"></div>
</div>

CSS

.highcharts-tooltip-container {
  transform: scale(1.5);
}

JavaScript

function getScale(element) {
  return element.getBoundingClientRect().width / element.offsetWidth;
}

(function(H) {

  H.wrap(H.Pointer.prototype, 'normalize', function(proceed, e) {
    var e = proceed.call(this, e),
      scale = getScale(this.chart.container);

    e.chartX /= scale;
    e.chartY /= scale;

    return e;
  });
}(Highcharts));

Highcharts.chart('container', {
  tooltip: {
    outside: true,
    shape: 'rect',
    positioner: function(w, h, point) {
      var position = this.getPosition(w, h, point),
        scale = getScale(this.chart.container);

      return {
        x: (position.x + w / 2) * scale,
        y: (position.y) * scale
      }
    }
  },
  series: [{
      data: [1, 4, 3, 5, 6, 7, 4, 3, 5, 2, 3, 4, 6, 5, 4],
      type: 'line',
    },
    {
      data: [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
      type: 'column'
    }
  ]
});