Skip to content

Relocate first tick when falls inside a rangebreak #4734

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

Closed
wants to merge 4 commits into from
Closed
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
34 changes: 27 additions & 7 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ var autorange = require('./autorange');
axes.getAutoRange = autorange.getAutoRange;
axes.findExtremes = autorange.findExtremes;

var epsilon = 0.0001;
function expandRange(range) {
var delta = (range[1] - range[0]) * epsilon;
return [
range[0] - delta,
range[1] + delta
];
}

/*
* find the list of possible axes to reference with an xref or yref attribute
* and coerce it to that list
Expand Down Expand Up @@ -566,8 +575,9 @@ axes.calcTicks = function calcTicks(ax) {
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;
var exRng = expandRange(rng);
var startTick = exRng[0];
var endTick = exRng[1];
// check for reversed axis
var axrev = (rng[1] < rng[0]);

Expand Down Expand Up @@ -691,10 +701,9 @@ function arrayTicks(ax) {
var text = ax.ticktext;
var ticksOut = new Array(vals.length);
var rng = Lib.simpleMap(ax.range, ax.r2l);
var r0expanded = rng[0] * 1.0001 - rng[1] * 0.0001;
var r1expanded = rng[1] * 1.0001 - rng[0] * 0.0001;
var tickMin = Math.min(r0expanded, r1expanded);
var tickMax = Math.max(r0expanded, r1expanded);
var exRng = expandRange(rng);
var tickMin = Math.min(exRng[0], exRng[1]);
var tickMax = Math.max(exRng[0], exRng[1]);
var j = 0;

// without a text array, just format the given values as any other ticks
Expand Down Expand Up @@ -956,10 +965,21 @@ axes.tickFirst = function(ax) {
var sRound = axrev ? Math.floor : Math.ceil;
// add a tiny extra bit to make sure we get ticks
// that may have been rounded out
var r0 = rng[0] * 1.0001 - rng[1] * 0.0001;
var r0 = expandRange(rng)[0];
var dtick = ax.dtick;
var tick0 = r2l(ax.tick0);

if(ax.rangebreaks && ax.maskBreaks(tick0) === BADNUM) {
// attempt move tick0 outside rangebreak
for(var h = 24; h > 0; h--) {
var delta = h * ONEHOUR;
if(ax.maskBreaks(tick0 - delta) !== BADNUM) {
tick0 -= delta;
break;
}
}
}

if(isNumeric(dtick)) {
var tmin = sRound((r0 - tick0) / dtick) * dtick + tick0;

Expand Down
Binary file modified test/image/baselines/axes_breaks-gridlines.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/axes_breaks-night_autorange-reversed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/axes_breaks-rangeslider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/axes_breaks-weekends-weeknights.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
218 changes: 218 additions & 0 deletions test/image/mocks/axes_breaks-tick0-position.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
{
"data": [
{
"type": "scatter",
"mode": "markers",
"x": [
"1970-01-01T09:00:00",
"1970-01-01T10:00:00",
"1970-01-01T11:00:00",
"1970-01-01T12:00:00",
"1970-01-01T13:00:00",
"1970-01-01T14:00:00",
"1970-01-01T15:00:00",
"1970-01-01T16:00:00",
"1970-01-02T09:00:00",
"1970-01-02T10:00:00",
"1970-01-02T11:00:00",
"1970-01-02T12:00:00",
"1970-01-02T13:00:00",
"1970-01-02T14:00:00",
"1970-01-02T15:00:00",
"1970-01-02T16:00:00",
"1970-01-03T09:00:00",
"1970-01-03T10:00:00",
"1970-01-03T11:00:00",
"1970-01-03T12:00:00",
"1970-01-03T13:00:00",
"1970-01-03T14:00:00",
"1970-01-03T15:00:00",
"1970-01-03T16:00:00",
"1970-01-04T09:00:00",
"1970-01-04T10:00:00",
"1970-01-04T11:00:00",
"1970-01-04T12:00:00",
"1970-01-04T13:00:00",
"1970-01-04T14:00:00",
"1970-01-04T15:00:00",
"1970-01-04T16:00:00",
"1970-01-05T09:00:00",
"1970-01-05T10:00:00",
"1970-01-05T11:00:00",
"1970-01-05T12:00:00",
"1970-01-05T13:00:00",
"1970-01-05T14:00:00",
"1970-01-05T15:00:00",
"1970-01-05T16:00:00"
],
"y": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40
]
},
{
"type": "scatter",
"mode": "markers",
"x": [
"1970-01-01T09:00:00",
"1970-01-01T10:00:00",
"1970-01-01T11:00:00",
"1970-01-01T12:00:00",
"1970-01-01T13:00:00",
"1970-01-01T14:00:00",
"1970-01-01T15:00:00",
"1970-01-01T16:00:00",
"1970-01-02T09:00:00",
"1970-01-02T10:00:00",
"1970-01-02T11:00:00",
"1970-01-02T12:00:00",
"1970-01-02T13:00:00",
"1970-01-02T14:00:00",
"1970-01-02T15:00:00",
"1970-01-02T16:00:00",
"1970-01-03T09:00:00",
"1970-01-03T10:00:00",
"1970-01-03T11:00:00",
"1970-01-03T12:00:00",
"1970-01-03T13:00:00",
"1970-01-03T14:00:00",
"1970-01-03T15:00:00",
"1970-01-03T16:00:00",
"1970-01-04T09:00:00",
"1970-01-04T10:00:00",
"1970-01-04T11:00:00",
"1970-01-04T12:00:00",
"1970-01-04T13:00:00",
"1970-01-04T14:00:00",
"1970-01-04T15:00:00",
"1970-01-04T16:00:00",
"1970-01-05T09:00:00",
"1970-01-05T10:00:00",
"1970-01-05T11:00:00",
"1970-01-05T12:00:00",
"1970-01-05T13:00:00",
"1970-01-05T14:00:00",
"1970-01-05T15:00:00",
"1970-01-05T16:00:00"
],
"y": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40
],
"xaxis": "x2",
"yaxis": "y2"
}
],
"layout": {
"width": 800,
"height": 400,
"showlegend": false,
"xaxis": {
"domain": [0, 0.45],
"dtick": 86400000,
"rangebreaks": [
{
"bounds": [
17,
9
],
"pattern": "hour"
}
]
},
"xaxis2": {
"domain": [0.55, 1],
"dtick": 86400000,
"rangebreaks": [
{
"bounds": [
17,
9
],
"pattern": "hour"
}
],
"autorange": "reversed",
"anchor": "y2"
},
"yaxis2": {
"anchor": "x2"
}
}
}