Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix #1645 - ensure we don't draw ticks if there are none to draw #2454

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

Merged
merged 1 commit into from
Mar 8, 2018
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
17 changes: 11 additions & 6 deletions 17 src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,22 +522,27 @@ axes.calcTicks = function calcTicks(ax) {
// find the first tick
ax._tmin = axes.tickFirst(ax);

// add a tiny bit so we get ticks which may have rounded out
var startTick = rng[0] * 1.0001 - rng[1] * 0.0001;
var endTick = rng[1] * 1.0001 - rng[0] * 0.0001;
// check for reversed axis
var axrev = (rng[1] < rng[0]);

// No visible ticks? Quit.
// I've only seen this on category axes with all categories off the edge.
if((ax._tmin < startTick) !== axrev) return [];

// return the full set of tick vals
var vals = [],
// add a tiny bit so we get ticks which may have rounded out
endtick = rng[1] * 1.0001 - rng[0] * 0.0001;
var vals = [];
if(ax.type === 'category') {
endtick = (axrev) ? Math.max(-0.5, endtick) :
Math.min(ax._categories.length - 0.5, endtick);
endTick = (axrev) ? Math.max(-0.5, endTick) :
Math.min(ax._categories.length - 0.5, endTick);
}

var xPrevious = null;
var maxTicks = Math.max(1000, ax._length || 0);
for(var x = ax._tmin;
(axrev) ? (x >= endtick) : (x <= endtick);
(axrev) ? (x >= endTick) : (x <= endTick);
x = axes.tickIncrement(x, ax.dtick, axrev, ax.calendar)) {
// prevent infinite loops - no more than one tick per pixel,
// and make sure each value is different from the previous
Expand Down
29 changes: 25 additions & 4 deletions 29 test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,29 @@ describe('Test axes', function() {
expect(ax._categories).toEqual(['a', 'b', 'c', 'd']);
});

it('notices when all categories are off the edge', function() {
var ax = {
type: 'category',
_categories: ['a', 'b', 'c', 'd'],
_categoriesMap: {'a': 0, 'b': 1, 'c': 2, 'd': 3},
tickmode: 'linear',
tick0: 0,
dtick: 1,
range: [-0.5, 3.5]
};

// baseline
expect(mockCalc(ax)).toEqual(['a', 'b', 'c', 'd']);
// reversed baseline
ax.range = [3.5, -0.5];
expect(mockCalc(ax)).toEqual(['d', 'c', 'b', 'a']);

[[-5, -1], [-1, -5], [5, 10], [10, 5]].forEach(function(rng) {
ax.range = rng;
expect(mockCalc(ax).length).toBe(0, rng);
});
});

it('should always start at year for date axis hover', function() {
var ax = {
type: 'date',
Expand Down Expand Up @@ -2321,10 +2344,8 @@ describe('Test axes', function() {
range: [1e200, 2e200]
});

// This actually gives text '-Infinity' because it can't
// calculate the first tick properly, but since it's not going to
// be able to do any better with the rest, we don't much care.
expect(textOut.length).toBe(1);
// with the fix for #1645 we're not even getting the '-Infinity' we used to :tada:
expect(textOut.length).toBe(0);
});

it('truncates at the greater of 1001 ticks or one per pixel', function() {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.