Skip to content

Commit

Permalink
correct logic for reversed ranges and add tests for some period scena…
Browse files Browse the repository at this point in the history
…rios
  • Loading branch information
archmoj committed Jul 24, 2020
1 parent 66a98be commit 83f5cdd
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,10 @@ axes.calcTicks = function calcTicks(ax, opts) {
var isPeriod = ax.ticklabelmode === 'period';
if(isPeriod) {
// add one label to show pre tick0 period
tickVals = [{
tickVals.unshift({
minor: false,
value: axes.tickIncrement(tickVals[0].value, ax.dtick, !axrev, ax.caldendar)
}].concat(tickVals);
});
}

if(ax.rangebreaks) {
Expand Down Expand Up @@ -745,12 +745,13 @@ axes.calcTicks = function calcTicks(ax, opts) {
var B = tickVals[b].value;

var delta = definedDelta || Math.abs(B - A);
var half = axrev ? -0.5 : 0.5;
if(delta >= ONEDAY * 365) { // Years could have days less than ONEAVGYEAR period
v += ONEAVGYEAR / 2;
v += half * ONEAVGYEAR;
} else if(delta >= ONEDAY * 28) { // Months could have days less than ONEAVGMONTH period
v += ONEAVGMONTH / 2;
v += half * ONEAVGMONTH;
} else if(delta >= ONEDAY) {
v += ONEDAY / 2;
v += half * ONEDAY;
}

ticksOut[i].periodX = v;
Expand Down
Binary file added test/image/baselines/date_axes_period2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
189 changes: 189 additions & 0 deletions test/image/mocks/date_axes_period2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"data": [
{
"x": [
"2017-01-01",
"2023-01-01"
],
"y": [
0,
1
]
},
{
"x": [
"2017-01-01",
"2023-01-01"
],
"y": [
0,
1
],
"xaxis": "x2",
"yaxis": "y2"
},
{
"x": [
"2017-01-01",
"2023-01-01"
],
"y": [
0,
1
],
"xaxis": "x3",
"yaxis": "y3"
},
{
"x": [
"2017-01-01",
"2023-01-01"
],
"y": [
0,
1
],
"xaxis": "x4",
"yaxis": "y4"
},
{
"x": [
"2017-01-01",
"2023-01-01"
],
"y": [
0,
1
],
"xaxis": "x5",
"yaxis": "y5"
},
{
"x": [
"2017-01-01",
"2023-01-01"
],
"y": [
0,
1
],
"xaxis": "x6",
"yaxis": "y6"
},
{
"x": [
"2017-01-01",
"2023-01-01"
],
"y": [
0,
1
],
"xaxis": "x7",
"yaxis": "y7"
}
],
"layout": {
"showlegend": false,
"width": 600,
"height": 500,
"yaxis": {
"domain": [
0,
0.04
]
},
"yaxis2": {
"domain": [
0.16,
0.2
]
},
"yaxis3": {
"domain": [
0.32,
0.36
]
},
"yaxis4": {
"domain": [
0.48,
0.52
]
},
"yaxis5": {
"domain": [
0.64,
0.68
]
},
"yaxis6": {
"domain": [
0.80,
0.84
]
},
"yaxis7": {
"domain": [
0.96,
1
]
},
"xaxis": {
"range": [
"2019-12-24",
"2020-01-06"
],
"ticklabelmode": "period",
"tickformat": "%b %d, %Y"
},
"xaxis2": {
"range": [
"2019-12-29",
"2020-01-04"
],
"ticklabelmode": "period",
"anchor": "y2"
},
"xaxis3": {
"range": [
"2020-01-03",
"2019-12-28"
],
"ticklabelmode": "period",
"anchor": "y3"
},
"xaxis4": {
"range": [
"2020-03-01",
"2020-11-01"
],
"ticklabelmode": "period",
"anchor": "y4"
},
"xaxis5": {
"range": [
"2016-09-01",
"2017-06-01"
],
"ticklabelmode": "period",
"anchor": "y5"
},
"xaxis6": {
"range": [
"2016-05-01",
"2019-09-01"
],
"ticklabelmode": "period",
"anchor": "y6"
},
"xaxis7": {
"range": [
"2016-05-01",
"2021-09-01"
],
"ticklabelmode": "period",
"anchor": "y7"
}
}
}
2 changes: 2 additions & 0 deletions test/jasmine/tests/mock_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ var list = [
'custom_size_subplot',
'date_axes',
'date_axes_period',
'date_axes_period2',
'date_histogram',
'dendrogram',
'display-text_zero-number',
Expand Down Expand Up @@ -1298,6 +1299,7 @@ figs['custom_colorscale'] = require('@mocks/custom_colorscale');
figs['custom_size_subplot'] = require('@mocks/custom_size_subplot');
figs['date_axes'] = require('@mocks/date_axes');
figs['date_axes_period'] = require('@mocks/date_axes_period');
figs['date_axes_period2'] = require('@mocks/date_axes_period2');
figs['date_histogram'] = require('@mocks/date_histogram');
// figs['dendrogram'] = require('@mocks/dendrogram');
figs['display-text_zero-number'] = require('@mocks/display-text_zero-number');
Expand Down

0 comments on commit 83f5cdd

Please sign in to comment.