Skip to content

Commit f779867

Browse files
authored
Fix pan on category scale when offsetGridLines=false (#198)
1 parent 1bd916c commit f779867

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

samples/pan-bar.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
},
7171
pan: {
7272
enabled: true,
73-
mode: 'xy',
73+
mode: 'x',
7474
speed: 10,
7575
threshold: 10
7676
},
@@ -86,7 +86,7 @@
8686
xAxes: [{
8787
ticks: {
8888
min: 'March',
89-
max: 'May'
89+
max: 'August'
9090
}
9191
}]
9292
}

src/plugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function rangeMinLimiter(zoomPanOptions, newMin) {
5959
return newMin;
6060
}
6161

62-
function zoomIndexScale(scale, zoom, center, zoomOptions) {
62+
function zoomCategoryScale(scale, zoom, center, zoomOptions) {
6363
var labels = scale.chart.data.labels;
6464
var minIndex = scale.minIndex;
6565
var lastLabelIndex = labels.length - 1;
@@ -205,10 +205,10 @@ function doZoom(chart, percentZoomX, percentZoomY, focalPoint, whichAxes) {
205205
}
206206
}
207207

208-
function panIndexScale(scale, delta, panOptions) {
208+
function panCategoryScale(scale, delta, panOptions) {
209209
var labels = scale.chart.data.labels;
210210
var lastLabelIndex = labels.length - 1;
211-
var offsetAmt = Math.max((scale.ticks.length - ((scale.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
211+
var offsetAmt = Math.max(scale.ticks.length, 1);
212212
var panSpeed = panOptions.speed;
213213
var minIndex = scale.minIndex;
214214
var step = Math.round(scale.width / (offsetAmt * panSpeed));
@@ -308,15 +308,15 @@ function getYAxis(chartInstance) {
308308
}
309309

310310
// Store these for later
311-
zoomNS.zoomFunctions.category = zoomIndexScale;
311+
zoomNS.zoomFunctions.category = zoomCategoryScale;
312312
zoomNS.zoomFunctions.time = zoomTimeScale;
313313
zoomNS.zoomFunctions.linear = zoomNumericalScale;
314314
zoomNS.zoomFunctions.logarithmic = zoomNumericalScale;
315-
zoomNS.panFunctions.category = panIndexScale;
315+
zoomNS.panFunctions.category = panCategoryScale;
316316
zoomNS.panFunctions.time = panTimeScale;
317317
zoomNS.panFunctions.linear = panNumericalScale;
318318
zoomNS.panFunctions.logarithmic = panNumericalScale;
319-
// Globals for catergory pan and zoom
319+
// Globals for category pan and zoom
320320
zoomNS.panCumulativeDelta = 0;
321321
zoomNS.zoomCumulativeDelta = 0;
322322

0 commit comments

Comments
 (0)