I've got things to work. I now have panning, zooming and yAxis scale extents.
But, My scaling is slow and works kind of bad. Any idea on how to improve this?
Ex code functions.
Code: Select all
// Scale yAxis
(function (H) {
Highcharts.Chart.prototype.callbacks.push(function (chart) {
var chart = this,
isDragging = false,
yAxis = chart.yAxis[0],
yAxisContainer = chart.yAxis[0].labelGroup.element;
H.addEvent(yAxisContainer, "mousedown", function (e) {
isDragging = true;
var y = e.pageY
H.addEvent(document, 'mousemove', function (e) {
if (isDragging) {
var step = 50;
var min = yAxis.getExtremes().min;
var max = yAxis.getExtremes().max;
if (y < e.pageY) {
yAxis.setExtremes(min - (max - min) / step, max + (max - min) / step)
} else {
yAxis.setExtremes(min + (max - min) / step, max - (max - min) / step)
}
}
});
});
H.addEvent(document, 'mouseup', function () {
if (isDragging) {
isDragging = false;
}
});
});
})(Highcharts);
// Panning XY
(function (H) {
Highcharts.Chart.prototype.callbacks.push(function (chart) {
var chart = this,
container = chart.chartBackground.element,
yAxis = chart.yAxis[0],
downYPixels,
downYValue,
isDragging = false,
hasDragged = 0;
H.addEvent(container, "mousedown", function (e) {
downYPixels = chart.pointer.normalize(e).chartY;
downYValue = yAxis.toValue(downYPixels);
isDragging = true;
H.addEvent(document, 'mousemove', function (e) {
if (isDragging) {
var dragYPixels = chart.pointer.normalize(e).chartY,
dragYValue = yAxis.toValue(dragYPixels),
yExtremes = yAxis.getExtremes(),
yUserMin = yExtremes.userMin,
yUserMax = yExtremes.userMax,
yDataMin = yExtremes.dataMin,
yDataMax = yExtremes.dataMax,
yMin = yUserMin !== undefined ? yUserMin : yDataMin,
yMax = yUserMax !== undefined ? yUserMax : yDataMax,
newMinY,
newMaxY;
hasDragged = Math.abs(downYPixels - dragYPixels);
if (hasDragged > 10) {
newMinY = yMin - (dragYValue - downYValue);
newMaxY = yMax - (dragYValue - downYValue);
yAxis.setExtremes(newMinY, newMaxY, true, false);
}
}
});
});
H.addEvent(document, 'mouseup', function () {
if (isDragging) {
isDragging = false;
}
});
});
})(Highcharts);
Best / F