-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
image: improve layout defaults #4307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
5c42db8
8184a8d
d71c3b3
97a8d24
2053c58
2b0d3c3
2306880
6ad80ab
8ef17c3
d1eca2c
31dbc8e
29cf98f
4233619
408b46b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ var failTest = require('../assets/fail_test'); | |
|
|
||
| var customAssertions = require('../assets/custom_assertions'); | ||
| var assertHoverLabelContent = customAssertions.assertHoverLabelContent; | ||
| var supplyAllDefaults = require('../assets/supply_defaults'); | ||
| var Fx = require('@src/components/fx'); | ||
|
|
||
| describe('image supplyDefaults', function() { | ||
|
|
@@ -100,6 +101,82 @@ describe('image supplyDefaults', function() { | |
| }); | ||
| }); | ||
|
|
||
| describe('image smart layout defaults', function() { | ||
| var gd; | ||
| beforeEach(function() { | ||
| gd = createGraphDiv(); | ||
| }); | ||
|
|
||
| afterEach(destroyGraphDiv); | ||
|
|
||
| it('should reverse yaxis if only images are present', function() { | ||
|
||
| gd = {}; | ||
| gd.data = [{type: 'image', z: [[[255, 0, 0]]]}]; | ||
| supplyAllDefaults(gd); | ||
| expect(gd._fullLayout.yaxis.autorange).toBe('reversed'); | ||
| }); | ||
|
|
||
| it('should reverse yaxis even if another trace is present', function() { | ||
| gd = {}; | ||
| gd.data = [{type: 'image', z: [[[255, 0, 0]]]}, {type: 'scatter', y: [5, 3, 2]}]; | ||
| supplyAllDefaults(gd); | ||
| expect(gd._fullLayout.yaxis.autorange).toBe('reversed'); | ||
| }); | ||
|
|
||
| it('should NOT reverse yaxis if it\'s already defined', function() { | ||
| gd = {}; | ||
| gd.data = [{type: 'image', z: [[[255, 0, 0]]]}]; | ||
| gd.layout = {yaxis: {autorange: false}}; | ||
| supplyAllDefaults(gd); | ||
| expect(gd._fullLayout.yaxis.autorange).toBe(false); | ||
| }); | ||
|
|
||
| it('should set scaleanchor to make square pixels if only images are present', function() { | ||
|
||
| gd = {}; | ||
| gd.data = [{type: 'image', z: [[[255, 0, 0]]]}]; | ||
| supplyAllDefaults(gd); | ||
| expect(gd._fullLayout.yaxis.scaleanchor).toBe('x'); | ||
| }); | ||
|
|
||
| it('should set scaleanchor even if another trace is present', function() { | ||
| gd = {}; | ||
| gd.data = [{type: 'image', z: [[[255, 0, 0]]]}, {type: 'scatter', y: [5, 3, 2]}]; | ||
| supplyAllDefaults(gd); | ||
| expect(gd._fullLayout.yaxis.scaleanchor).toBe('x'); | ||
| }); | ||
|
|
||
| it('should NOT set scaleanchor if it\'s already defined', function() { | ||
| gd.data = [{type: 'image', z: [[[255, 0, 0]]]}]; | ||
| gd.layout = {yaxis: {scaleanchor: 'x3'}}; | ||
| supplyAllDefaults(gd); | ||
| expect(gd._fullLayout.yaxis.scaleanchor).toBe(undefined); | ||
| }); | ||
|
|
||
| it('should constrain axes to domain if only images are present', function() { | ||
|
||
| gd = {}; | ||
| gd.data = [{type: 'image', z: [[[255, 0, 0]]]}]; | ||
| supplyAllDefaults(gd); | ||
| expect(gd._fullLayout.xaxis.constrain).toBe('domain'); | ||
| expect(gd._fullLayout.yaxis.constrain).toBe('domain'); | ||
| }); | ||
|
|
||
| it('should constrain axes to domain even if another trace is present', function() { | ||
| gd = {}; | ||
| gd.data = [{type: 'image', z: [[[255, 0, 0]]]}, {type: 'scatter', y: [5, 3, 2]}]; | ||
| supplyAllDefaults(gd); | ||
| expect(gd._fullLayout.xaxis.constrain).toBe('domain'); | ||
| expect(gd._fullLayout.yaxis.constrain).toBe('domain'); | ||
| }); | ||
|
|
||
| it('should NOT constrain axes to domain if it\'s already defined', function() { | ||
| gd.data = [{type: 'image', z: [[[255, 0, 0]]]}]; | ||
| gd.layout = {yaxis: {constrain: false}, xaxis: {constrain: false}}; | ||
| supplyAllDefaults(gd); | ||
| expect(gd._fullLayout.xaxis.constrain).toBe('range'); | ||
| expect(gd._fullLayout.yaxis.constrain).toBe('range'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('image plot', function() { | ||
| 'use strict'; | ||
|
|
||
|
|
@@ -444,10 +521,10 @@ describe('image hover:', function() { | |
| zmax: [1, 1, 1], | ||
| text: [['A', 'B', 'C'], ['D', 'E', 'F']], | ||
| hovertemplate: '%{text}<extra></extra>' | ||
| }], layout: {width: 400, height: 400}}; | ||
| }], layout: {width: 400, height: 400, yaxis: {constrain: 'range'}}}; | ||
|
|
||
| Plotly.newPlot(gd, mockCopy) | ||
| .then(function() {_hover(140, 200);}) | ||
| .then(function() {_hover(140, 180);}) | ||
| .then(function() { | ||
| assertHoverLabelContent({ | ||
| nums: 'E', | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.