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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
"url": "https://github.com/chartjs/chartjs-plugin-zoom.git"
},
"scripts": {
"autobuild": "rollup -c -w",
"build": "rollup -c",
"dev": "karma start --auto-watch --no-single-run --browsers chrome",
"dev:ff": "karma start --auto-watch --no-single-run --browsers firefox",
"docs": "npm run build && vuepress build docs --no-cache",
"docs:dev": "npm run build && vuepress dev docs --no-cache",
"docs:dev": "concurrently \"npm run autobuild\" \"vuepress dev docs --no-cache\"",
"lint-js": "eslint \"samples/**/*.html\" \"test/**/*.js\" \"src/**/*.js\"",
"lint-md": "eslint \"**/*.md\"",
"lint-tsc": "tsc",
Expand Down
9 changes: 8 additions & 1 deletion src/scale.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ export function updateRange(scale, {min, max}, limits, zoom = false) {
return true;
}

const range = zoom ? Math.max(max - min, minRange) : scale.max - scale.min;
const scaleRange = scale.max - scale.min;
const range = zoom ? Math.max(max - min, minRange) : scaleRange;

if (zoom && range === minRange && scaleRange <= minRange) {
// At range limit: No change but return true to indicate no need to store the delta.
return true;
}

const offset = (range - max + min) / 2;
min -= offset;
max += offset;
Expand Down
42 changes: 42 additions & 0 deletions test/specs/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,48 @@ describe('api', function() {
expect(chart.scales.x.max).toBe(100);
});

it('should no-op whan laready at limit', function() {
const chart = window.acquireChart({
type: 'scatter',
options: {
scales: {
x: {
min: 0,
max: 100
},
y: {
min: 0,
max: 100
}
},
plugins: {
zoom: {
mode: 'x',
limits: {
x: {
min: 0,
max: 100,
minRange: 50
}
}
}
}
}
});

chart.zoom({x: 1.5, focalPoint: {x: chart.scales.x.getPixelForValue(100)}});
expect(chart.scales.x.min).toBe(50);
expect(chart.scales.x.max).toBe(100);

chart.zoom({x: 1.5, focalPoint: {x: chart.scales.x.getPixelForValue(100)}});
expect(chart.scales.x.min).toBe(50);
expect(chart.scales.x.max).toBe(100);

chart.zoom({x: 1.5, focalPoint: {x: chart.scales.x.getPixelForValue(50)}});
expect(chart.scales.x.min).toBe(50);
expect(chart.scales.x.max).toBe(100);
});

it('should honor zoom changes against a limit', function() {
const chart = window.acquireChart({
type: 'scatter',
Expand Down