Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Update tests to check scale against scaleExtent
  • Loading branch information
camdecoster committed Jul 25, 2025
commit 65665fe91a0b7f7190098babb1165adbeccd279c
2 changes: 1 addition & 1 deletion src/plots/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ proto.updateFx = function(fullLayout, geoLayout) {
bgRect.node().onmousedown = null;
var zoom = createGeoZoom(_this, geoLayout)
bgRect.call(zoom);
// Trigger zoom transition to account for min/max scale values
// Trigger zoom transition to account for initial min/max scale values
if (geoLayout.projection.minscale > 0 && !d3.event) zoom.event(bgRect);
bgRect.on('dblclick.zoom', zoomReset);
if(!gd._context._scrollZoom.geo) {
Expand Down
155 changes: 77 additions & 78 deletions test/jasmine/tests/geo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2730,6 +2730,83 @@ describe('Test geo zoom/pan/drag interactions:', function() {
})
.then(done, done.fail);
});

describe('minscale and maxscale', () => {
const defaultConfig = {
layout: {
dragmode: 'pan',
geo: { projection: {} },
height: 500,
width: 700
}
}
let gd;

beforeEach(() => { gd = createGraphDiv(); });

afterEach(destroyGraphDiv);

const allTests = [
{
name: 'non-clipped',
mock: require('../../image/mocks/geo_winkel-tripel')
},
{
name: 'clipped',
mock: require('../../image/mocks/geo_orthographic')
},
{
name: 'scoped',
mock: require('../../image/mocks/geo_europe-bubbles')
}
];

allTests.forEach(({ mock, name }) => {
it(`${name} maxscale`, done => {
const fig = Lib.extendDeep({}, mock, defaultConfig);
fig.layout.geo.projection.maxscale = 1.2;

Plotly
.newPlot(gd, fig)
// Zoom in far enough to hit limit
.then(() => scroll([200, 250], [-200, -200]))
.then(() => {
const maxScale = gd._fullLayout.geo._subplot.projection.scaleExtent()[1];
expect(gd._fullLayout.geo._subplot.projection.scale()).toEqual(maxScale);
})
.then(done, done.fail);
});

it(`${name} minscale`, done => {
const fig = Lib.extendDeep({}, mock, defaultConfig);
fig.layout.geo.projection.minscale = 0.8;

Plotly
.newPlot(gd, fig)
// Zoom out far enough to hit limit
.then(() => scroll([200, 250], [1000, 1000]))
.then(() => {
const minScale = gd._fullLayout.geo._subplot.projection.scaleExtent()[0];
expect(gd._fullLayout.geo._subplot.projection.scale()).toEqual(minScale);
})
.then(done, done.fail);
});

it(`${name} minscale greater than 1`, done => {
const fig = Lib.extendDeep({}, mock, defaultConfig);
fig.layout.geo.projection.minscale = 3;

Plotly
.newPlot(gd, fig)
// The limit should already be hit during plot creation
.then(() => {
const minScale = gd._fullLayout.geo._subplot.projection.scaleExtent()[0];
expect(gd._fullLayout.geo._subplot.projection.scale()).toEqual(minScale);
})
.then(done, done.fail);
});
});
});
});

describe('Test geo interactions update marker angles:', function() {
Expand Down Expand Up @@ -2824,81 +2901,3 @@ describe('plotly_relayouting', function() {
});
});
});


describe('minscale and maxscale', function() {
function scroll(pos, delta) {
return new Promise(function(resolve) {
mouseEvent('mousemove', pos[0], pos[1]);
mouseEvent('scroll', pos[0], pos[1], {deltaX: delta[0], deltaY: delta[1]});
setTimeout(resolve, 100);
});
}

var gd;

beforeEach(function() { gd = createGraphDiv(); });

afterEach(destroyGraphDiv);

var allTests = [
{
name: 'non-clipped',
mock: require('../../image/mocks/geo_winkel-tripel')
},
{
name: 'clipped',
mock: require('../../image/mocks/geo_orthographic')
},
{
name: 'scoped',
mock: require('../../image/mocks/geo_europe-bubbles')
}
];

allTests.forEach(function(test) {
it(test.name + ' maxscale', function(done) {
var fig = Lib.extendDeep({}, test.mock);
fig.layout.width = 700;
fig.layout.height = 500;
fig.layout.dragmode = 'pan';
if(!fig.layout.geo.projection) fig.layout.geo.projection = {};
fig.layout.geo.projection.maxscale = 1.2;

var initialScale;

Plotly.newPlot(gd, fig)
.then(function() {
initialScale = gd._fullLayout.geo._subplot.projection.scale();

return scroll([200, 250], [-200, -200]);
})
.then(function() {
expect(gd._fullLayout.geo._subplot.projection.scale()).toEqual(1.2 * initialScale);
})
.then(done, done.fail);
});

it(test.name + ' minscale', function(done) {
var fig = Lib.extendDeep({}, test.mock);
fig.layout.width = 700;
fig.layout.height = 500;
fig.layout.dragmode = 'pan';
if(!fig.layout.geo.projection) fig.layout.geo.projection = {};
fig.layout.geo.projection.minscale = 0.8;

var initialScale;

Plotly.newPlot(gd, fig)
.then(function() {
initialScale = gd._fullLayout.geo._subplot.projection.scale();

return scroll([200, 250], [200, 200]);
})
.then(function() {
expect(gd._fullLayout.geo._subplot.projection.scale()).toEqual(0.8 * initialScale);
})
.then(done, done.fail);
});
});
});