Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/hammer.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ function handlePinch(chart, state, e) {
function startPinch(chart, state, event) {
if (state.options.zoom.pinch.enabled) {
const point = getRelativePosition(event, chart);
call(state.options.zoom.onZoomStart, [{chart, event, point}]);
state.scale = 1;
if (call(state.options.zoom.onZoomStart, [{chart, event, point}]) === false) {
state.scale = null;
call(state.options.zoom.onZoomRejected, [{chart, event}]);
} else {
state.scale = 1;
}
}
}

Expand Down
98 changes: 98 additions & 0 deletions test/specs/zoom.pinch.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
describe('pinch', () => {
const data = {
datasets: [{
data: [{
x: 1,
y: 3
}, {
x: 2,
y: 2
}, {
x: 3,
y: 1
}]
}]
};

describe('events', () => {
it('should call onZoomStart', function(done) {
const startSpy = jasmine.createSpy('started');
const chart = window.acquireChart({
type: 'scatter',
data,
options: {
plugins: {
zoom: {
zoom: {
mode: 'xy',
onZoomStart: startSpy,
pinch: {
enabled: true,
},
},
}
}
}
});

Simulator.gestures.pinch(chart.canvas, {pos: [chart.width / 2, chart.height / 2]}, function() {
expect(startSpy).toHaveBeenCalled();
expect(chart.scales.x.min).not.toBe(1);
done();
});
});

it('should call onZoomRejected when onStartZoom returns false', function(done) {
const rejectSpy = jasmine.createSpy('rejected');
const chart = window.acquireChart({
type: 'scatter',
data,
options: {
plugins: {
zoom: {
zoom: {
mode: 'xy',
onZoomStart: () => false,
onZoomRejected: rejectSpy,
pinch: {
enabled: true,
}
}
}
}
}
});

Simulator.gestures.pinch(chart.canvas, {}, function() {
expect(rejectSpy).toHaveBeenCalled();
expect(chart.scales.x.min).toBe(1);
done();
});
});

it('should call onZoomComplete', function(done) {
const chart = window.acquireChart({
type: 'scatter',
data,
options: {
plugins: {
zoom: {
zoom: {
mode: 'xy',
onZoomComplete(ctx) {
expect(ctx.chart.scales.x.min).not.toBe(1);
done();
},
pinch: {
enabled: true,
},
},
}
}
}
});
Simulator.gestures.pinch(chart.canvas, {});
});

});
});