Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c28d0e5
centralize & refactor range expansions
archmoj Apr 6, 2020
1e63bfc
add rangebreaks tests with hourly and auto dticks
archmoj May 13, 2020
3baed24
revise tick positioning - fix dtick hourly - move tick0 outside the b…
archmoj May 13, 2020
4eab137
drop endpoint ticks that fall inside breaks
archmoj May 14, 2020
a7633c3
move last tick on rangebreaks to the start of break instead of removi…
archmoj May 15, 2020
d2d8e6e
revisit ticks on axes with rangebreaks
archmoj May 19, 2020
ca193eb
reject last tick that may include decimals
archmoj May 19, 2020
6b77b31
refactor - no need for else ifs in axes tickIncrement
archmoj May 19, 2020
ef14d60
add jasmine tests for axes with rangebreaks and set dtick
archmoj May 19, 2020
a0d4d0d
improve auto ticks on axes with rangebreaks
archmoj May 20, 2020
0fb92d4
attempt improving ticks on rangebreaks
archmoj Jun 1, 2020
5c8055b
fix issue 4879
archmoj Jun 1, 2020
0a782d8
invert if statement
archmoj Jun 2, 2020
6cd55b5
drop extra function for hour rangebreaks
archmoj Jun 2, 2020
db7d47d
drop extra logic for dayRatio
archmoj Jun 2, 2020
8c8c928
drop extra logic for dynamic oneDay
archmoj Jun 2, 2020
21f4284
drop extra logic for startHour
archmoj Jun 2, 2020
9e7b80e
drop extra logic for dayHours
archmoj Jun 2, 2020
22e5658
avoid too tick overlaps on x axes with rangebreaks and now only when …
archmoj Jun 2, 2020
b38688d
reverse loop order
archmoj Jun 2, 2020
c5cf45a
fixups to avoid single tick
archmoj Jun 2, 2020
9241578
reduce roughDTick by total length of breaks
archmoj Jun 3, 2020
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
94 changes: 59 additions & 35 deletions src/plots/cartesian/axes.js
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand Up@@ -612,39 +622,42 @@ axes.calcTicks = function calcTicks(ax) {

if(ax.rangebreaks) {
// replace ticks inside breaks that would get a tick
if(ax.tickmode === 'auto') {
for(var t = 0; t < tickVals.length; t++) {
var value = tickVals[t].value;
if(ax.maskBreaks(value) === BADNUM) {
// find which break we are in
for(var k = 0; k < ax._rangebreaks.length; k++) {
var brk = ax._rangebreaks[k];
if(value >= brk.min && value < brk.max) {
tickVals[t].value = brk.max; // replace with break end
break;
}
}
}
}
}

// reduce ticks
// and reduce ticks
var len = tickVals.length;
if(len > 2) {
var tf2 = 2 * (ax.tickfont ? ax.tickfont.size : 12);
if(len) {
var tf = 0;
if(ax.tickmode === 'auto') {
tf =
(ax._id.charAt(0) === 'y' ? 2 : 6) *
(ax.tickfont ? ax.tickfont.size : 12);
}

var newTickVals = [];
var prevPos;

var dir = axrev ? 1 : -1;
var first = axrev ? 0 : len - 1;
var last = axrev ? len - 1 : 0;
for(var q = first; dir * q <= dir * last; q += dir) { // apply reverse loop to pick greater values in breaks first
var pos = ax.c2p(tickVals[q].value);
for(var q = first; dir * q <= dir * last; q += dir) {
var tickVal = tickVals[q];
if(ax.maskBreaks(tickVal.value) === BADNUM) {
tickVal.value = moveOutsideBreak(tickVal.value, ax);

if(ax._rl && (
ax._rl[0] === tickVal.value ||
ax._rl[1] === tickVal.value
)) continue;
}

if(prevPos === undefined || Math.abs(pos - prevPos) > tf2) {
var pos = ax.c2p(tickVal.value);

if(pos === prevPos) {
if(newTickVals[newTickVals.length - 1].value < tickVal.value) {
newTickVals[newTickVals.length - 1] = tickVal;
}
} else if(prevPos === undefined || Math.abs(pos - prevPos) > tf) {
prevPos = pos;
newTickVals.push(tickVals[q]);
newTickVals.push(tickVal);
}
}
tickVals = newTickVals.reverse();
Expand DownExpand Up@@ -691,10 +704,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 DownExpand Up@@ -785,8 +797,7 @@ axes.autoTicks = function(ax, roughDTick) {
roughDTick /= ONEAVGMONTH;
ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24);
} else if(roughX2 > ONEDAY) {
ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 7, 14] : roundDays);

ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 2, 7, 14] : roundDays);
// get week ticks on sunday
// this will also move the base tick off 2000-01-01 if dtick is
// 2 or 3 days... but that's a weird enough case that we'll ignore it.
Expand DownExpand Up@@ -934,18 +945,20 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) {
if(tType === 'M') return Lib.incrementMonth(x, dtSigned, calendar);

// Log scales: Linear, Digits
else if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;
if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;

// log10 of 2,5,10, or all digits (logs just have to be
// close enough to round)
else if(tType === 'D') {
if(tType === 'D') {
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1;
var x2 = x + axSign * 0.01;
var frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev);

return Math.floor(x2) +
Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
} else throw 'unrecognized dtick ' + String(dtick);
}

throw 'unrecognized dtick ' + String(dtick);
};

// calculate the first tick on an axis
Expand All@@ -956,7 +969,7 @@ 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);

Expand DownExpand Up@@ -3158,3 +3171,14 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {
function isAngular(ax) {
return ax._id === 'angularaxis';
}

function moveOutsideBreak(v, ax) {
var len = ax._rangebreaks.length;
for(var k = 0; k < len; k++) {
var brk = ax._rangebreaks[k];
if(v >= brk.min && v < brk.max) {
return brk.max;
}
}
return v;
}
4 changes: 1 addition & 3 deletions src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -686,9 +686,7 @@ module.exports = function setConvert(ax, fullLayout) {
var isNewBreak = true;
for(var j = 0; j < rangebreaksOut.length; j++) {
var brkj = rangebreaksOut[j];
if(min > brkj.max || max < brkj.min) {
// potentially a new break
} else {
if(min < brkj.max && max >= brkj.min) {
if(min < brkj.min) {
brkj.min = min;
}
Expand Down
Binary file modifiedtest/image/baselines/axes_breaks-candlestick2.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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modifiedtest/image/baselines/axes_breaks-finance.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 addedtest/image/baselines/axes_breaks-overlap.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 modifiedtest/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 modifiedtest/image/baselines/axes_breaks-round-weekdays.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 modifiedtest/image/baselines/axes_breaks-values.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 modifiedtest/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.
Binary file modifiedtest/image/baselines/axes_breaks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions test/image/mocks/axes_breaks-dtick_auto.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
{
"data": [
{
"type": "scatter",
"mode": "markers",
"x": [
"2020-04-06T09:00:00",
"2020-04-06T10:00:00",
"2020-04-06T11:00:00",
"2020-04-06T12:00:00",
"2020-04-06T13:00:00",
"2020-04-06T14:00:00",
"2020-04-06T15:00:00",
"2020-04-06T16:00:00",
"2020-04-07T09:00:00",
"2020-04-07T10:00:00",
"2020-04-07T11:00:00",
"2020-04-07T12:00:00",
"2020-04-07T13:00:00",
"2020-04-07T14:00:00",
"2020-04-07T15:00:00",
"2020-04-07T16:00:00",
"2020-04-08T09:00:00",
"2020-04-08T10:00:00",
"2020-04-08T11:00:00",
"2020-04-08T12:00:00",
"2020-04-08T13:00:00",
"2020-04-08T14:00:00",
"2020-04-08T15:00:00",
"2020-04-08T16:00:00",
"2020-04-09T09:00:00",
"2020-04-09T10:00:00",
"2020-04-09T11:00:00",
"2020-04-09T12:00:00",
"2020-04-09T13:00:00",
"2020-04-09T14:00:00",
"2020-04-09T15:00:00",
"2020-04-09T16:00:00",
"2020-04-10T09:00:00",
"2020-04-10T10:00:00",
"2020-04-10T11:00:00",
"2020-04-10T12:00:00",
"2020-04-10T13:00:00",
"2020-04-10T14:00:00",
"2020-04-10T15:00:00",
"2020-04-10T16:00:00"
],
"y": [
0.19742877314456364,
0.1509714558226325,
0.3730270552929804,
0.7394093812216096,
1.2149308862244954,
1.5707342286171064,
1.0824483128021085,
0.9424263772804724,
1.1724169397045303,
0.8440466169659708,
0.8650832231701001,
0.41942121150935374,
0.11941773640575382,
-0.3620604691336322,
-0.06836276577621159,
-0.34443807771583146,
-0.49908639701892876,
-0.07100510355333789,
0.13340929837019488,
-0.33475177209849727,
-0.6700576156005845,
-0.548579214100821,
-0.4713506254966534,
-0.7334578041221448,
-0.299243806197351,
-0.18527785023145504,
-0.14964504720649674,
-0.05973507085192575,
0.17038695866484388,
-0.01766804585555426,
-0.11944698363946238,
-0.40960323466434023,
-0.7234102287840041,
-0.2790378388000705,
-0.039487043750782935,
-0.04902823513321586,
-0.3216136071598926,
-0.5672571253894997,
-1.009227965065624,
-1.0748113395075032
]
}
],
"layout": {
"width": 800,
"height": 600,
"xaxis": {
"rangebreaks": [
{
"bounds": [
17,
9
],
"pattern": "hour"
}
],
"title": {
"text": "time"
}
},
"yaxis": {
"title": {
"text": "values"
}
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Fix rangebreaks overlapping and tick positions by archmoj · Pull Request #4831 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c28d0e5
centralize & refactor range expansions
archmoj Apr 6, 2020
1e63bfc
add rangebreaks tests with hourly and auto dticks
archmoj May 13, 2020
3baed24
revise tick positioning - fix dtick hourly - move tick0 outside the b…
archmoj May 13, 2020
4eab137
drop endpoint ticks that fall inside breaks
archmoj May 14, 2020
a7633c3
move last tick on rangebreaks to the start of break instead of removi…
archmoj May 15, 2020
d2d8e6e
revisit ticks on axes with rangebreaks
archmoj May 19, 2020
ca193eb
reject last tick that may include decimals
archmoj May 19, 2020
6b77b31
refactor - no need for else ifs in axes tickIncrement
archmoj May 19, 2020
ef14d60
add jasmine tests for axes with rangebreaks and set dtick
archmoj May 19, 2020
a0d4d0d
improve auto ticks on axes with rangebreaks
archmoj May 20, 2020
0fb92d4
attempt improving ticks on rangebreaks
archmoj Jun 1, 2020
5c8055b
fix issue 4879
archmoj Jun 1, 2020
0a782d8
invert if statement
archmoj Jun 2, 2020
6cd55b5
drop extra function for hour rangebreaks
archmoj Jun 2, 2020
db7d47d
drop extra logic for dayRatio
archmoj Jun 2, 2020
8c8c928
drop extra logic for dynamic oneDay
archmoj Jun 2, 2020
21f4284
drop extra logic for startHour
archmoj Jun 2, 2020
9e7b80e
drop extra logic for dayHours
archmoj Jun 2, 2020
22e5658
avoid too tick overlaps on x axes with rangebreaks and now only when …
archmoj Jun 2, 2020
b38688d
reverse loop order
archmoj Jun 2, 2020
c5cf45a
fixups to avoid single tick
archmoj Jun 2, 2020
9241578
reduce roughDTick by total length of breaks
archmoj Jun 3, 2020
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
94 changes: 59 additions & 35 deletions src/plots/cartesian/axes.js
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand Up@@ -612,39 +622,42 @@ axes.calcTicks = function calcTicks(ax) {

if(ax.rangebreaks) {
// replace ticks inside breaks that would get a tick
if(ax.tickmode === 'auto') {
for(var t = 0; t < tickVals.length; t++) {
var value = tickVals[t].value;
if(ax.maskBreaks(value) === BADNUM) {
// find which break we are in
for(var k = 0; k < ax._rangebreaks.length; k++) {
var brk = ax._rangebreaks[k];
if(value >= brk.min && value < brk.max) {
tickVals[t].value = brk.max; // replace with break end
break;
}
}
}
}
}

// reduce ticks
// and reduce ticks
var len = tickVals.length;
if(len > 2) {
var tf2 = 2 * (ax.tickfont ? ax.tickfont.size : 12);
if(len) {
var tf = 0;
if(ax.tickmode === 'auto') {
tf =
(ax._id.charAt(0) === 'y' ? 2 : 6) *
(ax.tickfont ? ax.tickfont.size : 12);
}

var newTickVals = [];
var prevPos;

var dir = axrev ? 1 : -1;
var first = axrev ? 0 : len - 1;
var last = axrev ? len - 1 : 0;
for(var q = first; dir * q <= dir * last; q += dir) { // apply reverse loop to pick greater values in breaks first
var pos = ax.c2p(tickVals[q].value);
for(var q = first; dir * q <= dir * last; q += dir) {
var tickVal = tickVals[q];
if(ax.maskBreaks(tickVal.value) === BADNUM) {
tickVal.value = moveOutsideBreak(tickVal.value, ax);

if(ax._rl && (
ax._rl[0] === tickVal.value ||
ax._rl[1] === tickVal.value
)) continue;
}

if(prevPos === undefined || Math.abs(pos - prevPos) > tf2) {
var pos = ax.c2p(tickVal.value);

if(pos === prevPos) {
if(newTickVals[newTickVals.length - 1].value < tickVal.value) {
newTickVals[newTickVals.length - 1] = tickVal;
}
} else if(prevPos === undefined || Math.abs(pos - prevPos) > tf) {
prevPos = pos;
newTickVals.push(tickVals[q]);
newTickVals.push(tickVal);
}
}
tickVals = newTickVals.reverse();
Expand DownExpand Up@@ -691,10 +704,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 DownExpand Up@@ -785,8 +797,7 @@ axes.autoTicks = function(ax, roughDTick) {
roughDTick /= ONEAVGMONTH;
ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24);
} else if(roughX2 > ONEDAY) {
ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 7, 14] : roundDays);

ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 2, 7, 14] : roundDays);
// get week ticks on sunday
// this will also move the base tick off 2000-01-01 if dtick is
// 2 or 3 days... but that's a weird enough case that we'll ignore it.
Expand DownExpand Up@@ -934,18 +945,20 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) {
if(tType === 'M') return Lib.incrementMonth(x, dtSigned, calendar);

// Log scales: Linear, Digits
else if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;
if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;

// log10 of 2,5,10, or all digits (logs just have to be
// close enough to round)
else if(tType === 'D') {
if(tType === 'D') {
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1;
var x2 = x + axSign * 0.01;
var frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev);

return Math.floor(x2) +
Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
} else throw 'unrecognized dtick ' + String(dtick);
}

throw 'unrecognized dtick ' + String(dtick);
};

// calculate the first tick on an axis
Expand All@@ -956,7 +969,7 @@ 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);

Expand DownExpand Up@@ -3158,3 +3171,14 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {
function isAngular(ax) {
return ax._id === 'angularaxis';
}

function moveOutsideBreak(v, ax) {
var len = ax._rangebreaks.length;
for(var k = 0; k < len; k++) {
var brk = ax._rangebreaks[k];
if(v >= brk.min && v < brk.max) {
return brk.max;
}
}
return v;
}
4 changes: 1 addition & 3 deletions src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -686,9 +686,7 @@ module.exports = function setConvert(ax, fullLayout) {
var isNewBreak = true;
for(var j = 0; j < rangebreaksOut.length; j++) {
var brkj = rangebreaksOut[j];
if(min > brkj.max || max < brkj.min) {
// potentially a new break
} else {
if(min < brkj.max && max >= brkj.min) {
if(min < brkj.min) {
brkj.min = min;
}
Expand Down
Binary file modifiedtest/image/baselines/axes_breaks-candlestick2.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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modifiedtest/image/baselines/axes_breaks-finance.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 addedtest/image/baselines/axes_breaks-overlap.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 modifiedtest/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 modifiedtest/image/baselines/axes_breaks-round-weekdays.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 modifiedtest/image/baselines/axes_breaks-values.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 modifiedtest/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.
Binary file modifiedtest/image/baselines/axes_breaks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions test/image/mocks/axes_breaks-dtick_auto.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
{
"data": [
{
"type": "scatter",
"mode": "markers",
"x": [
"2020-04-06T09:00:00",
"2020-04-06T10:00:00",
"2020-04-06T11:00:00",
"2020-04-06T12:00:00",
"2020-04-06T13:00:00",
"2020-04-06T14:00:00",
"2020-04-06T15:00:00",
"2020-04-06T16:00:00",
"2020-04-07T09:00:00",
"2020-04-07T10:00:00",
"2020-04-07T11:00:00",
"2020-04-07T12:00:00",
"2020-04-07T13:00:00",
"2020-04-07T14:00:00",
"2020-04-07T15:00:00",
"2020-04-07T16:00:00",
"2020-04-08T09:00:00",
"2020-04-08T10:00:00",
"2020-04-08T11:00:00",
"2020-04-08T12:00:00",
"2020-04-08T13:00:00",
"2020-04-08T14:00:00",
"2020-04-08T15:00:00",
"2020-04-08T16:00:00",
"2020-04-09T09:00:00",
"2020-04-09T10:00:00",
"2020-04-09T11:00:00",
"2020-04-09T12:00:00",
"2020-04-09T13:00:00",
"2020-04-09T14:00:00",
"2020-04-09T15:00:00",
"2020-04-09T16:00:00",
"2020-04-10T09:00:00",
"2020-04-10T10:00:00",
"2020-04-10T11:00:00",
"2020-04-10T12:00:00",
"2020-04-10T13:00:00",
"2020-04-10T14:00:00",
"2020-04-10T15:00:00",
"2020-04-10T16:00:00"
],
"y": [
0.19742877314456364,
0.1509714558226325,
0.3730270552929804,
0.7394093812216096,
1.2149308862244954,
1.5707342286171064,
1.0824483128021085,
0.9424263772804724,
1.1724169397045303,
0.8440466169659708,
0.8650832231701001,
0.41942121150935374,
0.11941773640575382,
-0.3620604691336322,
-0.06836276577621159,
-0.34443807771583146,
-0.49908639701892876,
-0.07100510355333789,
0.13340929837019488,
-0.33475177209849727,
-0.6700576156005845,
-0.548579214100821,
-0.4713506254966534,
-0.7334578041221448,
-0.299243806197351,
-0.18527785023145504,
-0.14964504720649674,
-0.05973507085192575,
0.17038695866484388,
-0.01766804585555426,
-0.11944698363946238,
-0.40960323466434023,
-0.7234102287840041,
-0.2790378388000705,
-0.039487043750782935,
-0.04902823513321586,
-0.3216136071598926,
-0.5672571253894997,
-1.009227965065624,
-1.0748113395075032
]
}
],
"layout": {
"width": 800,
"height": 600,
"xaxis": {
"rangebreaks": [
{
"bounds": [
17,
9
],
"pattern": "hour"
}
],
"title": {
"text": "time"
}
},
"yaxis": {
"title": {
"text": "values"
}
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Fix rangebreaks overlapping and tick positions by archmoj · Pull Request #4831 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c28d0e5
centralize & refactor range expansions
archmoj Apr 6, 2020
1e63bfc
add rangebreaks tests with hourly and auto dticks
archmoj May 13, 2020
3baed24
revise tick positioning - fix dtick hourly - move tick0 outside the b…
archmoj May 13, 2020
4eab137
drop endpoint ticks that fall inside breaks
archmoj May 14, 2020
a7633c3
move last tick on rangebreaks to the start of break instead of removi…
archmoj May 15, 2020
d2d8e6e
revisit ticks on axes with rangebreaks
archmoj May 19, 2020
ca193eb
reject last tick that may include decimals
archmoj May 19, 2020
6b77b31
refactor - no need for else ifs in axes tickIncrement
archmoj May 19, 2020
ef14d60
add jasmine tests for axes with rangebreaks and set dtick
archmoj May 19, 2020
a0d4d0d
improve auto ticks on axes with rangebreaks
archmoj May 20, 2020
0fb92d4
attempt improving ticks on rangebreaks
archmoj Jun 1, 2020
5c8055b
fix issue 4879
archmoj Jun 1, 2020
0a782d8
invert if statement
archmoj Jun 2, 2020
6cd55b5
drop extra function for hour rangebreaks
archmoj Jun 2, 2020
db7d47d
drop extra logic for dayRatio
archmoj Jun 2, 2020
8c8c928
drop extra logic for dynamic oneDay
archmoj Jun 2, 2020
21f4284
drop extra logic for startHour
archmoj Jun 2, 2020
9e7b80e
drop extra logic for dayHours
archmoj Jun 2, 2020
22e5658
avoid too tick overlaps on x axes with rangebreaks and now only when …
archmoj Jun 2, 2020
b38688d
reverse loop order
archmoj Jun 2, 2020
c5cf45a
fixups to avoid single tick
archmoj Jun 2, 2020
9241578
reduce roughDTick by total length of breaks
archmoj Jun 3, 2020
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
94 changes: 59 additions & 35 deletions src/plots/cartesian/axes.js
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand Up@@ -612,39 +622,42 @@ axes.calcTicks = function calcTicks(ax) {

if(ax.rangebreaks) {
// replace ticks inside breaks that would get a tick
if(ax.tickmode === 'auto') {
for(var t = 0; t < tickVals.length; t++) {
var value = tickVals[t].value;
if(ax.maskBreaks(value) === BADNUM) {
// find which break we are in
for(var k = 0; k < ax._rangebreaks.length; k++) {
var brk = ax._rangebreaks[k];
if(value >= brk.min && value < brk.max) {
tickVals[t].value = brk.max; // replace with break end
break;
}
}
}
}
}

// reduce ticks
// and reduce ticks
var len = tickVals.length;
if(len > 2) {
var tf2 = 2 * (ax.tickfont ? ax.tickfont.size : 12);
if(len) {
var tf = 0;
if(ax.tickmode === 'auto') {
tf =
(ax._id.charAt(0) === 'y' ? 2 : 6) *
(ax.tickfont ? ax.tickfont.size : 12);
}

var newTickVals = [];
var prevPos;

var dir = axrev ? 1 : -1;
var first = axrev ? 0 : len - 1;
var last = axrev ? len - 1 : 0;
for(var q = first; dir * q <= dir * last; q += dir) { // apply reverse loop to pick greater values in breaks first
var pos = ax.c2p(tickVals[q].value);
for(var q = first; dir * q <= dir * last; q += dir) {
var tickVal = tickVals[q];
if(ax.maskBreaks(tickVal.value) === BADNUM) {
tickVal.value = moveOutsideBreak(tickVal.value, ax);

if(ax._rl && (
ax._rl[0] === tickVal.value ||
ax._rl[1] === tickVal.value
)) continue;
}

if(prevPos === undefined || Math.abs(pos - prevPos) > tf2) {
var pos = ax.c2p(tickVal.value);

if(pos === prevPos) {
if(newTickVals[newTickVals.length - 1].value < tickVal.value) {
newTickVals[newTickVals.length - 1] = tickVal;
}
} else if(prevPos === undefined || Math.abs(pos - prevPos) > tf) {
prevPos = pos;
newTickVals.push(tickVals[q]);
newTickVals.push(tickVal);
}
}
tickVals = newTickVals.reverse();
Expand DownExpand Up@@ -691,10 +704,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 DownExpand Up@@ -785,8 +797,7 @@ axes.autoTicks = function(ax, roughDTick) {
roughDTick /= ONEAVGMONTH;
ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24);
} else if(roughX2 > ONEDAY) {
ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 7, 14] : roundDays);

ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 2, 7, 14] : roundDays);
// get week ticks on sunday
// this will also move the base tick off 2000-01-01 if dtick is
// 2 or 3 days... but that's a weird enough case that we'll ignore it.
Expand DownExpand Up@@ -934,18 +945,20 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) {
if(tType === 'M') return Lib.incrementMonth(x, dtSigned, calendar);

// Log scales: Linear, Digits
else if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;
if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;

// log10 of 2,5,10, or all digits (logs just have to be
// close enough to round)
else if(tType === 'D') {
if(tType === 'D') {
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1;
var x2 = x + axSign * 0.01;
var frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev);

return Math.floor(x2) +
Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
} else throw 'unrecognized dtick ' + String(dtick);
}

throw 'unrecognized dtick ' + String(dtick);
};

// calculate the first tick on an axis
Expand All@@ -956,7 +969,7 @@ 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);

Expand DownExpand Up@@ -3158,3 +3171,14 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {
function isAngular(ax) {
return ax._id === 'angularaxis';
}

function moveOutsideBreak(v, ax) {
var len = ax._rangebreaks.length;
for(var k = 0; k < len; k++) {
var brk = ax._rangebreaks[k];
if(v >= brk.min && v < brk.max) {
return brk.max;
}
}
return v;
}
4 changes: 1 addition & 3 deletions src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -686,9 +686,7 @@ module.exports = function setConvert(ax, fullLayout) {
var isNewBreak = true;
for(var j = 0; j < rangebreaksOut.length; j++) {
var brkj = rangebreaksOut[j];
if(min > brkj.max || max < brkj.min) {
// potentially a new break
} else {
if(min < brkj.max && max >= brkj.min) {
if(min < brkj.min) {
brkj.min = min;
}
Expand Down
Binary file modifiedtest/image/baselines/axes_breaks-candlestick2.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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modifiedtest/image/baselines/axes_breaks-finance.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 addedtest/image/baselines/axes_breaks-overlap.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 modifiedtest/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 modifiedtest/image/baselines/axes_breaks-round-weekdays.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 modifiedtest/image/baselines/axes_breaks-values.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 modifiedtest/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.
Binary file modifiedtest/image/baselines/axes_breaks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions test/image/mocks/axes_breaks-dtick_auto.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
{
"data": [
{
"type": "scatter",
"mode": "markers",
"x": [
"2020-04-06T09:00:00",
"2020-04-06T10:00:00",
"2020-04-06T11:00:00",
"2020-04-06T12:00:00",
"2020-04-06T13:00:00",
"2020-04-06T14:00:00",
"2020-04-06T15:00:00",
"2020-04-06T16:00:00",
"2020-04-07T09:00:00",
"2020-04-07T10:00:00",
"2020-04-07T11:00:00",
"2020-04-07T12:00:00",
"2020-04-07T13:00:00",
"2020-04-07T14:00:00",
"2020-04-07T15:00:00",
"2020-04-07T16:00:00",
"2020-04-08T09:00:00",
"2020-04-08T10:00:00",
"2020-04-08T11:00:00",
"2020-04-08T12:00:00",
"2020-04-08T13:00:00",
"2020-04-08T14:00:00",
"2020-04-08T15:00:00",
"2020-04-08T16:00:00",
"2020-04-09T09:00:00",
"2020-04-09T10:00:00",
"2020-04-09T11:00:00",
"2020-04-09T12:00:00",
"2020-04-09T13:00:00",
"2020-04-09T14:00:00",
"2020-04-09T15:00:00",
"2020-04-09T16:00:00",
"2020-04-10T09:00:00",
"2020-04-10T10:00:00",
"2020-04-10T11:00:00",
"2020-04-10T12:00:00",
"2020-04-10T13:00:00",
"2020-04-10T14:00:00",
"2020-04-10T15:00:00",
"2020-04-10T16:00:00"
],
"y": [
0.19742877314456364,
0.1509714558226325,
0.3730270552929804,
0.7394093812216096,
1.2149308862244954,
1.5707342286171064,
1.0824483128021085,
0.9424263772804724,
1.1724169397045303,
0.8440466169659708,
0.8650832231701001,
0.41942121150935374,
0.11941773640575382,
-0.3620604691336322,
-0.06836276577621159,
-0.34443807771583146,
-0.49908639701892876,
-0.07100510355333789,
0.13340929837019488,
-0.33475177209849727,
-0.6700576156005845,
-0.548579214100821,
-0.4713506254966534,
-0.7334578041221448,
-0.299243806197351,
-0.18527785023145504,
-0.14964504720649674,
-0.05973507085192575,
0.17038695866484388,
-0.01766804585555426,
-0.11944698363946238,
-0.40960323466434023,
-0.7234102287840041,
-0.2790378388000705,
-0.039487043750782935,
-0.04902823513321586,
-0.3216136071598926,
-0.5672571253894997,
-1.009227965065624,
-1.0748113395075032
]
}
],
"layout": {
"width": 800,
"height": 600,
"xaxis": {
"rangebreaks": [
{
"bounds": [
17,
9
],
"pattern": "hour"
}
],
"title": {
"text": "time"
}
},
"yaxis": {
"title": {
"text": "values"
}
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Fix rangebreaks overlapping and tick positions by archmoj · Pull Request #4831 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c28d0e5
centralize & refactor range expansions
archmoj Apr 6, 2020
1e63bfc
add rangebreaks tests with hourly and auto dticks
archmoj May 13, 2020
3baed24
revise tick positioning - fix dtick hourly - move tick0 outside the b…
archmoj May 13, 2020
4eab137
drop endpoint ticks that fall inside breaks
archmoj May 14, 2020
a7633c3
move last tick on rangebreaks to the start of break instead of removi…
archmoj May 15, 2020
d2d8e6e
revisit ticks on axes with rangebreaks
archmoj May 19, 2020
ca193eb
reject last tick that may include decimals
archmoj May 19, 2020
6b77b31
refactor - no need for else ifs in axes tickIncrement
archmoj May 19, 2020
ef14d60
add jasmine tests for axes with rangebreaks and set dtick
archmoj May 19, 2020
a0d4d0d
improve auto ticks on axes with rangebreaks
archmoj May 20, 2020
0fb92d4
attempt improving ticks on rangebreaks
archmoj Jun 1, 2020
5c8055b
fix issue 4879
archmoj Jun 1, 2020
0a782d8
invert if statement
archmoj Jun 2, 2020
6cd55b5
drop extra function for hour rangebreaks
archmoj Jun 2, 2020
db7d47d
drop extra logic for dayRatio
archmoj Jun 2, 2020
8c8c928
drop extra logic for dynamic oneDay
archmoj Jun 2, 2020
21f4284
drop extra logic for startHour
archmoj Jun 2, 2020
9e7b80e
drop extra logic for dayHours
archmoj Jun 2, 2020
22e5658
avoid too tick overlaps on x axes with rangebreaks and now only when …
archmoj Jun 2, 2020
b38688d
reverse loop order
archmoj Jun 2, 2020
c5cf45a
fixups to avoid single tick
archmoj Jun 2, 2020
9241578
reduce roughDTick by total length of breaks
archmoj Jun 3, 2020
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
94 changes: 59 additions & 35 deletions src/plots/cartesian/axes.js
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand Up@@ -612,39 +622,42 @@ axes.calcTicks = function calcTicks(ax) {

if(ax.rangebreaks) {
// replace ticks inside breaks that would get a tick
if(ax.tickmode === 'auto') {
for(var t = 0; t < tickVals.length; t++) {
var value = tickVals[t].value;
if(ax.maskBreaks(value) === BADNUM) {
// find which break we are in
for(var k = 0; k < ax._rangebreaks.length; k++) {
var brk = ax._rangebreaks[k];
if(value >= brk.min && value < brk.max) {
tickVals[t].value = brk.max; // replace with break end
break;
}
}
}
}
}

// reduce ticks
// and reduce ticks
var len = tickVals.length;
if(len > 2) {
var tf2 = 2 * (ax.tickfont ? ax.tickfont.size : 12);
if(len) {
var tf = 0;
if(ax.tickmode === 'auto') {
tf =
(ax._id.charAt(0) === 'y' ? 2 : 6) *
(ax.tickfont ? ax.tickfont.size : 12);
}

var newTickVals = [];
var prevPos;

var dir = axrev ? 1 : -1;
var first = axrev ? 0 : len - 1;
var last = axrev ? len - 1 : 0;
for(var q = first; dir * q <= dir * last; q += dir) { // apply reverse loop to pick greater values in breaks first
var pos = ax.c2p(tickVals[q].value);
for(var q = first; dir * q <= dir * last; q += dir) {
var tickVal = tickVals[q];
if(ax.maskBreaks(tickVal.value) === BADNUM) {
tickVal.value = moveOutsideBreak(tickVal.value, ax);

if(ax._rl && (
ax._rl[0] === tickVal.value ||
ax._rl[1] === tickVal.value
)) continue;
}

if(prevPos === undefined || Math.abs(pos - prevPos) > tf2) {
var pos = ax.c2p(tickVal.value);

if(pos === prevPos) {
if(newTickVals[newTickVals.length - 1].value < tickVal.value) {
newTickVals[newTickVals.length - 1] = tickVal;
}
} else if(prevPos === undefined || Math.abs(pos - prevPos) > tf) {
prevPos = pos;
newTickVals.push(tickVals[q]);
newTickVals.push(tickVal);
}
}
tickVals = newTickVals.reverse();
Expand DownExpand Up@@ -691,10 +704,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 DownExpand Up@@ -785,8 +797,7 @@ axes.autoTicks = function(ax, roughDTick) {
roughDTick /= ONEAVGMONTH;
ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24);
} else if(roughX2 > ONEDAY) {
ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 7, 14] : roundDays);

ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 2, 7, 14] : roundDays);
// get week ticks on sunday
// this will also move the base tick off 2000-01-01 if dtick is
// 2 or 3 days... but that's a weird enough case that we'll ignore it.
Expand DownExpand Up@@ -934,18 +945,20 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) {
if(tType === 'M') return Lib.incrementMonth(x, dtSigned, calendar);

// Log scales: Linear, Digits
else if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;
if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;

// log10 of 2,5,10, or all digits (logs just have to be
// close enough to round)
else if(tType === 'D') {
if(tType === 'D') {
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1;
var x2 = x + axSign * 0.01;
var frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev);

return Math.floor(x2) +
Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
} else throw 'unrecognized dtick ' + String(dtick);
}

throw 'unrecognized dtick ' + String(dtick);
};

// calculate the first tick on an axis
Expand All@@ -956,7 +969,7 @@ 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);

Expand DownExpand Up@@ -3158,3 +3171,14 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {
function isAngular(ax) {
return ax._id === 'angularaxis';
}

function moveOutsideBreak(v, ax) {
var len = ax._rangebreaks.length;
for(var k = 0; k < len; k++) {
var brk = ax._rangebreaks[k];
if(v >= brk.min && v < brk.max) {
return brk.max;
}
}
return v;
}
4 changes: 1 addition & 3 deletions src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -686,9 +686,7 @@ module.exports = function setConvert(ax, fullLayout) {
var isNewBreak = true;
for(var j = 0; j < rangebreaksOut.length; j++) {
var brkj = rangebreaksOut[j];
if(min > brkj.max || max < brkj.min) {
// potentially a new break
} else {
if(min < brkj.max && max >= brkj.min) {
if(min < brkj.min) {
brkj.min = min;
}
Expand Down
Binary file modifiedtest/image/baselines/axes_breaks-candlestick2.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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modifiedtest/image/baselines/axes_breaks-finance.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 addedtest/image/baselines/axes_breaks-overlap.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 modifiedtest/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 modifiedtest/image/baselines/axes_breaks-round-weekdays.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 modifiedtest/image/baselines/axes_breaks-values.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 modifiedtest/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.
Binary file modifiedtest/image/baselines/axes_breaks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions test/image/mocks/axes_breaks-dtick_auto.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
{
"data": [
{
"type": "scatter",
"mode": "markers",
"x": [
"2020-04-06T09:00:00",
"2020-04-06T10:00:00",
"2020-04-06T11:00:00",
"2020-04-06T12:00:00",
"2020-04-06T13:00:00",
"2020-04-06T14:00:00",
"2020-04-06T15:00:00",
"2020-04-06T16:00:00",
"2020-04-07T09:00:00",
"2020-04-07T10:00:00",
"2020-04-07T11:00:00",
"2020-04-07T12:00:00",
"2020-04-07T13:00:00",
"2020-04-07T14:00:00",
"2020-04-07T15:00:00",
"2020-04-07T16:00:00",
"2020-04-08T09:00:00",
"2020-04-08T10:00:00",
"2020-04-08T11:00:00",
"2020-04-08T12:00:00",
"2020-04-08T13:00:00",
"2020-04-08T14:00:00",
"2020-04-08T15:00:00",
"2020-04-08T16:00:00",
"2020-04-09T09:00:00",
"2020-04-09T10:00:00",
"2020-04-09T11:00:00",
"2020-04-09T12:00:00",
"2020-04-09T13:00:00",
"2020-04-09T14:00:00",
"2020-04-09T15:00:00",
"2020-04-09T16:00:00",
"2020-04-10T09:00:00",
"2020-04-10T10:00:00",
"2020-04-10T11:00:00",
"2020-04-10T12:00:00",
"2020-04-10T13:00:00",
"2020-04-10T14:00:00",
"2020-04-10T15:00:00",
"2020-04-10T16:00:00"
],
"y": [
0.19742877314456364,
0.1509714558226325,
0.3730270552929804,
0.7394093812216096,
1.2149308862244954,
1.5707342286171064,
1.0824483128021085,
0.9424263772804724,
1.1724169397045303,
0.8440466169659708,
0.8650832231701001,
0.41942121150935374,
0.11941773640575382,
-0.3620604691336322,
-0.06836276577621159,
-0.34443807771583146,
-0.49908639701892876,
-0.07100510355333789,
0.13340929837019488,
-0.33475177209849727,
-0.6700576156005845,
-0.548579214100821,
-0.4713506254966534,
-0.7334578041221448,
-0.299243806197351,
-0.18527785023145504,
-0.14964504720649674,
-0.05973507085192575,
0.17038695866484388,
-0.01766804585555426,
-0.11944698363946238,
-0.40960323466434023,
-0.7234102287840041,
-0.2790378388000705,
-0.039487043750782935,
-0.04902823513321586,
-0.3216136071598926,
-0.5672571253894997,
-1.009227965065624,
-1.0748113395075032
]
}
],
"layout": {
"width": 800,
"height": 600,
"xaxis": {
"rangebreaks": [
{
"bounds": [
17,
9
],
"pattern": "hour"
}
],
"title": {
"text": "time"
}
},
"yaxis": {
"title": {
"text": "values"
}
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Fix rangebreaks overlapping and tick positions by archmoj · Pull Request #4831 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c28d0e5
centralize & refactor range expansions
archmoj Apr 6, 2020
1e63bfc
add rangebreaks tests with hourly and auto dticks
archmoj May 13, 2020
3baed24
revise tick positioning - fix dtick hourly - move tick0 outside the b…
archmoj May 13, 2020
4eab137
drop endpoint ticks that fall inside breaks
archmoj May 14, 2020
a7633c3
move last tick on rangebreaks to the start of break instead of removi…
archmoj May 15, 2020
d2d8e6e
revisit ticks on axes with rangebreaks
archmoj May 19, 2020
ca193eb
reject last tick that may include decimals
archmoj May 19, 2020
6b77b31
refactor - no need for else ifs in axes tickIncrement
archmoj May 19, 2020
ef14d60
add jasmine tests for axes with rangebreaks and set dtick
archmoj May 19, 2020
a0d4d0d
improve auto ticks on axes with rangebreaks
archmoj May 20, 2020
0fb92d4
attempt improving ticks on rangebreaks
archmoj Jun 1, 2020
5c8055b
fix issue 4879
archmoj Jun 1, 2020
0a782d8
invert if statement
archmoj Jun 2, 2020
6cd55b5
drop extra function for hour rangebreaks
archmoj Jun 2, 2020
db7d47d
drop extra logic for dayRatio
archmoj Jun 2, 2020
8c8c928
drop extra logic for dynamic oneDay
archmoj Jun 2, 2020
21f4284
drop extra logic for startHour
archmoj Jun 2, 2020
9e7b80e
drop extra logic for dayHours
archmoj Jun 2, 2020
22e5658
avoid too tick overlaps on x axes with rangebreaks and now only when …
archmoj Jun 2, 2020
b38688d
reverse loop order
archmoj Jun 2, 2020
c5cf45a
fixups to avoid single tick
archmoj Jun 2, 2020
9241578
reduce roughDTick by total length of breaks
archmoj Jun 3, 2020
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
94 changes: 59 additions & 35 deletions src/plots/cartesian/axes.js
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand Up@@ -612,39 +622,42 @@ axes.calcTicks = function calcTicks(ax) {

if(ax.rangebreaks) {
// replace ticks inside breaks that would get a tick
if(ax.tickmode === 'auto') {
for(var t = 0; t < tickVals.length; t++) {
var value = tickVals[t].value;
if(ax.maskBreaks(value) === BADNUM) {
// find which break we are in
for(var k = 0; k < ax._rangebreaks.length; k++) {
var brk = ax._rangebreaks[k];
if(value >= brk.min && value < brk.max) {
tickVals[t].value = brk.max; // replace with break end
break;
}
}
}
}
}

// reduce ticks
// and reduce ticks
var len = tickVals.length;
if(len > 2) {
var tf2 = 2 * (ax.tickfont ? ax.tickfont.size : 12);
if(len) {
var tf = 0;
if(ax.tickmode === 'auto') {
tf =
(ax._id.charAt(0) === 'y' ? 2 : 6) *
(ax.tickfont ? ax.tickfont.size : 12);
}

var newTickVals = [];
var prevPos;

var dir = axrev ? 1 : -1;
var first = axrev ? 0 : len - 1;
var last = axrev ? len - 1 : 0;
for(var q = first; dir * q <= dir * last; q += dir) { // apply reverse loop to pick greater values in breaks first
var pos = ax.c2p(tickVals[q].value);
for(var q = first; dir * q <= dir * last; q += dir) {
var tickVal = tickVals[q];
if(ax.maskBreaks(tickVal.value) === BADNUM) {
tickVal.value = moveOutsideBreak(tickVal.value, ax);

if(ax._rl && (
ax._rl[0] === tickVal.value ||
ax._rl[1] === tickVal.value
)) continue;
}

if(prevPos === undefined || Math.abs(pos - prevPos) > tf2) {
var pos = ax.c2p(tickVal.value);

if(pos === prevPos) {
if(newTickVals[newTickVals.length - 1].value < tickVal.value) {
newTickVals[newTickVals.length - 1] = tickVal;
}
} else if(prevPos === undefined || Math.abs(pos - prevPos) > tf) {
prevPos = pos;
newTickVals.push(tickVals[q]);
newTickVals.push(tickVal);
}
}
tickVals = newTickVals.reverse();
Expand DownExpand Up@@ -691,10 +704,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 DownExpand Up@@ -785,8 +797,7 @@ axes.autoTicks = function(ax, roughDTick) {
roughDTick /= ONEAVGMONTH;
ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24);
} else if(roughX2 > ONEDAY) {
ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 7, 14] : roundDays);

ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 2, 7, 14] : roundDays);
// get week ticks on sunday
// this will also move the base tick off 2000-01-01 if dtick is
// 2 or 3 days... but that's a weird enough case that we'll ignore it.
Expand DownExpand Up@@ -934,18 +945,20 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) {
if(tType === 'M') return Lib.incrementMonth(x, dtSigned, calendar);

// Log scales: Linear, Digits
else if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;
if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;

// log10 of 2,5,10, or all digits (logs just have to be
// close enough to round)
else if(tType === 'D') {
if(tType === 'D') {
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1;
var x2 = x + axSign * 0.01;
var frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev);

return Math.floor(x2) +
Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
} else throw 'unrecognized dtick ' + String(dtick);
}

throw 'unrecognized dtick ' + String(dtick);
};

// calculate the first tick on an axis
Expand All@@ -956,7 +969,7 @@ 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);

Expand DownExpand Up@@ -3158,3 +3171,14 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {
function isAngular(ax) {
return ax._id === 'angularaxis';
}

function moveOutsideBreak(v, ax) {
var len = ax._rangebreaks.length;
for(var k = 0; k < len; k++) {
var brk = ax._rangebreaks[k];
if(v >= brk.min && v < brk.max) {
return brk.max;
}
}
return v;
}
4 changes: 1 addition & 3 deletions src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -686,9 +686,7 @@ module.exports = function setConvert(ax, fullLayout) {
var isNewBreak = true;
for(var j = 0; j < rangebreaksOut.length; j++) {
var brkj = rangebreaksOut[j];
if(min > brkj.max || max < brkj.min) {
// potentially a new break
} else {
if(min < brkj.max && max >= brkj.min) {
if(min < brkj.min) {
brkj.min = min;
}
Expand Down
Binary file modifiedtest/image/baselines/axes_breaks-candlestick2.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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modifiedtest/image/baselines/axes_breaks-finance.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 addedtest/image/baselines/axes_breaks-overlap.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 modifiedtest/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 modifiedtest/image/baselines/axes_breaks-round-weekdays.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 modifiedtest/image/baselines/axes_breaks-values.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 modifiedtest/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.
Binary file modifiedtest/image/baselines/axes_breaks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions test/image/mocks/axes_breaks-dtick_auto.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
{
"data": [
{
"type": "scatter",
"mode": "markers",
"x": [
"2020-04-06T09:00:00",
"2020-04-06T10:00:00",
"2020-04-06T11:00:00",
"2020-04-06T12:00:00",
"2020-04-06T13:00:00",
"2020-04-06T14:00:00",
"2020-04-06T15:00:00",
"2020-04-06T16:00:00",
"2020-04-07T09:00:00",
"2020-04-07T10:00:00",
"2020-04-07T11:00:00",
"2020-04-07T12:00:00",
"2020-04-07T13:00:00",
"2020-04-07T14:00:00",
"2020-04-07T15:00:00",
"2020-04-07T16:00:00",
"2020-04-08T09:00:00",
"2020-04-08T10:00:00",
"2020-04-08T11:00:00",
"2020-04-08T12:00:00",
"2020-04-08T13:00:00",
"2020-04-08T14:00:00",
"2020-04-08T15:00:00",
"2020-04-08T16:00:00",
"2020-04-09T09:00:00",
"2020-04-09T10:00:00",
"2020-04-09T11:00:00",
"2020-04-09T12:00:00",
"2020-04-09T13:00:00",
"2020-04-09T14:00:00",
"2020-04-09T15:00:00",
"2020-04-09T16:00:00",
"2020-04-10T09:00:00",
"2020-04-10T10:00:00",
"2020-04-10T11:00:00",
"2020-04-10T12:00:00",
"2020-04-10T13:00:00",
"2020-04-10T14:00:00",
"2020-04-10T15:00:00",
"2020-04-10T16:00:00"
],
"y": [
0.19742877314456364,
0.1509714558226325,
0.3730270552929804,
0.7394093812216096,
1.2149308862244954,
1.5707342286171064,
1.0824483128021085,
0.9424263772804724,
1.1724169397045303,
0.8440466169659708,
0.8650832231701001,
0.41942121150935374,
0.11941773640575382,
-0.3620604691336322,
-0.06836276577621159,
-0.34443807771583146,
-0.49908639701892876,
-0.07100510355333789,
0.13340929837019488,
-0.33475177209849727,
-0.6700576156005845,
-0.548579214100821,
-0.4713506254966534,
-0.7334578041221448,
-0.299243806197351,
-0.18527785023145504,
-0.14964504720649674,
-0.05973507085192575,
0.17038695866484388,
-0.01766804585555426,
-0.11944698363946238,
-0.40960323466434023,
-0.7234102287840041,
-0.2790378388000705,
-0.039487043750782935,
-0.04902823513321586,
-0.3216136071598926,
-0.5672571253894997,
-1.009227965065624,
-1.0748113395075032
]
}
],
"layout": {
"width": 800,
"height": 600,
"xaxis": {
"rangebreaks": [
{
"bounds": [
17,
9
],
"pattern": "hour"
}
],
"title": {
"text": "time"
}
},
"yaxis": {
"title": {
"text": "values"
}
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Fix rangebreaks overlapping and tick positions by archmoj · Pull Request #4831 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c28d0e5
centralize & refactor range expansions
archmoj Apr 6, 2020
1e63bfc
add rangebreaks tests with hourly and auto dticks
archmoj May 13, 2020
3baed24
revise tick positioning - fix dtick hourly - move tick0 outside the b…
archmoj May 13, 2020
4eab137
drop endpoint ticks that fall inside breaks
archmoj May 14, 2020
a7633c3
move last tick on rangebreaks to the start of break instead of removi…
archmoj May 15, 2020
d2d8e6e
revisit ticks on axes with rangebreaks
archmoj May 19, 2020
ca193eb
reject last tick that may include decimals
archmoj May 19, 2020
6b77b31
refactor - no need for else ifs in axes tickIncrement
archmoj May 19, 2020
ef14d60
add jasmine tests for axes with rangebreaks and set dtick
archmoj May 19, 2020
a0d4d0d
improve auto ticks on axes with rangebreaks
archmoj May 20, 2020
0fb92d4
attempt improving ticks on rangebreaks
archmoj Jun 1, 2020
5c8055b
fix issue 4879
archmoj Jun 1, 2020
0a782d8
invert if statement
archmoj Jun 2, 2020
6cd55b5
drop extra function for hour rangebreaks
archmoj Jun 2, 2020
db7d47d
drop extra logic for dayRatio
archmoj Jun 2, 2020
8c8c928
drop extra logic for dynamic oneDay
archmoj Jun 2, 2020
21f4284
drop extra logic for startHour
archmoj Jun 2, 2020
9e7b80e
drop extra logic for dayHours
archmoj Jun 2, 2020
22e5658
avoid too tick overlaps on x axes with rangebreaks and now only when …
archmoj Jun 2, 2020
b38688d
reverse loop order
archmoj Jun 2, 2020
c5cf45a
fixups to avoid single tick
archmoj Jun 2, 2020
9241578
reduce roughDTick by total length of breaks
archmoj Jun 3, 2020
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
94 changes: 59 additions & 35 deletions src/plots/cartesian/axes.js
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand Up@@ -612,39 +622,42 @@ axes.calcTicks = function calcTicks(ax) {

if(ax.rangebreaks) {
// replace ticks inside breaks that would get a tick
if(ax.tickmode === 'auto') {
for(var t = 0; t < tickVals.length; t++) {
var value = tickVals[t].value;
if(ax.maskBreaks(value) === BADNUM) {
// find which break we are in
for(var k = 0; k < ax._rangebreaks.length; k++) {
var brk = ax._rangebreaks[k];
if(value >= brk.min && value < brk.max) {
tickVals[t].value = brk.max; // replace with break end
break;
}
}
}
}
}

// reduce ticks
// and reduce ticks
var len = tickVals.length;
if(len > 2) {
var tf2 = 2 * (ax.tickfont ? ax.tickfont.size : 12);
if(len) {
var tf = 0;
if(ax.tickmode === 'auto') {
tf =
(ax._id.charAt(0) === 'y' ? 2 : 6) *
(ax.tickfont ? ax.tickfont.size : 12);
}

var newTickVals = [];
var prevPos;

var dir = axrev ? 1 : -1;
var first = axrev ? 0 : len - 1;
var last = axrev ? len - 1 : 0;
for(var q = first; dir * q <= dir * last; q += dir) { // apply reverse loop to pick greater values in breaks first
var pos = ax.c2p(tickVals[q].value);
for(var q = first; dir * q <= dir * last; q += dir) {
var tickVal = tickVals[q];
if(ax.maskBreaks(tickVal.value) === BADNUM) {
tickVal.value = moveOutsideBreak(tickVal.value, ax);

if(ax._rl && (
ax._rl[0] === tickVal.value ||
ax._rl[1] === tickVal.value
)) continue;
}

if(prevPos === undefined || Math.abs(pos - prevPos) > tf2) {
var pos = ax.c2p(tickVal.value);

if(pos === prevPos) {
if(newTickVals[newTickVals.length - 1].value < tickVal.value) {
newTickVals[newTickVals.length - 1] = tickVal;
}
} else if(prevPos === undefined || Math.abs(pos - prevPos) > tf) {
prevPos = pos;
newTickVals.push(tickVals[q]);
newTickVals.push(tickVal);
}
}
tickVals = newTickVals.reverse();
Expand DownExpand Up@@ -691,10 +704,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 DownExpand Up@@ -785,8 +797,7 @@ axes.autoTicks = function(ax, roughDTick) {
roughDTick /= ONEAVGMONTH;
ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24);
} else if(roughX2 > ONEDAY) {
ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 7, 14] : roundDays);

ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 2, 7, 14] : roundDays);
// get week ticks on sunday
// this will also move the base tick off 2000-01-01 if dtick is
// 2 or 3 days... but that's a weird enough case that we'll ignore it.
Expand DownExpand Up@@ -934,18 +945,20 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) {
if(tType === 'M') return Lib.incrementMonth(x, dtSigned, calendar);

// Log scales: Linear, Digits
else if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;
if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;

// log10 of 2,5,10, or all digits (logs just have to be
// close enough to round)
else if(tType === 'D') {
if(tType === 'D') {
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1;
var x2 = x + axSign * 0.01;
var frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev);

return Math.floor(x2) +
Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
} else throw 'unrecognized dtick ' + String(dtick);
}

throw 'unrecognized dtick ' + String(dtick);
};

// calculate the first tick on an axis
Expand All@@ -956,7 +969,7 @@ 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);

Expand DownExpand Up@@ -3158,3 +3171,14 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {
function isAngular(ax) {
return ax._id === 'angularaxis';
}

function moveOutsideBreak(v, ax) {
var len = ax._rangebreaks.length;
for(var k = 0; k < len; k++) {
var brk = ax._rangebreaks[k];
if(v >= brk.min && v < brk.max) {
return brk.max;
}
}
return v;
}
4 changes: 1 addition & 3 deletions src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -686,9 +686,7 @@ module.exports = function setConvert(ax, fullLayout) {
var isNewBreak = true;
for(var j = 0; j < rangebreaksOut.length; j++) {
var brkj = rangebreaksOut[j];
if(min > brkj.max || max < brkj.min) {
// potentially a new break
} else {
if(min < brkj.max && max >= brkj.min) {
if(min < brkj.min) {
brkj.min = min;
}
Expand Down
Binary file modifiedtest/image/baselines/axes_breaks-candlestick2.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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modifiedtest/image/baselines/axes_breaks-finance.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 addedtest/image/baselines/axes_breaks-overlap.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 modifiedtest/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 modifiedtest/image/baselines/axes_breaks-round-weekdays.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 modifiedtest/image/baselines/axes_breaks-values.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 modifiedtest/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.
Binary file modifiedtest/image/baselines/axes_breaks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions test/image/mocks/axes_breaks-dtick_auto.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
{
"data": [
{
"type": "scatter",
"mode": "markers",
"x": [
"2020-04-06T09:00:00",
"2020-04-06T10:00:00",
"2020-04-06T11:00:00",
"2020-04-06T12:00:00",
"2020-04-06T13:00:00",
"2020-04-06T14:00:00",
"2020-04-06T15:00:00",
"2020-04-06T16:00:00",
"2020-04-07T09:00:00",
"2020-04-07T10:00:00",
"2020-04-07T11:00:00",
"2020-04-07T12:00:00",
"2020-04-07T13:00:00",
"2020-04-07T14:00:00",
"2020-04-07T15:00:00",
"2020-04-07T16:00:00",
"2020-04-08T09:00:00",
"2020-04-08T10:00:00",
"2020-04-08T11:00:00",
"2020-04-08T12:00:00",
"2020-04-08T13:00:00",
"2020-04-08T14:00:00",
"2020-04-08T15:00:00",
"2020-04-08T16:00:00",
"2020-04-09T09:00:00",
"2020-04-09T10:00:00",
"2020-04-09T11:00:00",
"2020-04-09T12:00:00",
"2020-04-09T13:00:00",
"2020-04-09T14:00:00",
"2020-04-09T15:00:00",
"2020-04-09T16:00:00",
"2020-04-10T09:00:00",
"2020-04-10T10:00:00",
"2020-04-10T11:00:00",
"2020-04-10T12:00:00",
"2020-04-10T13:00:00",
"2020-04-10T14:00:00",
"2020-04-10T15:00:00",
"2020-04-10T16:00:00"
],
"y": [
0.19742877314456364,
0.1509714558226325,
0.3730270552929804,
0.7394093812216096,
1.2149308862244954,
1.5707342286171064,
1.0824483128021085,
0.9424263772804724,
1.1724169397045303,
0.8440466169659708,
0.8650832231701001,
0.41942121150935374,
0.11941773640575382,
-0.3620604691336322,
-0.06836276577621159,
-0.34443807771583146,
-0.49908639701892876,
-0.07100510355333789,
0.13340929837019488,
-0.33475177209849727,
-0.6700576156005845,
-0.548579214100821,
-0.4713506254966534,
-0.7334578041221448,
-0.299243806197351,
-0.18527785023145504,
-0.14964504720649674,
-0.05973507085192575,
0.17038695866484388,
-0.01766804585555426,
-0.11944698363946238,
-0.40960323466434023,
-0.7234102287840041,
-0.2790378388000705,
-0.039487043750782935,
-0.04902823513321586,
-0.3216136071598926,
-0.5672571253894997,
-1.009227965065624,
-1.0748113395075032
]
}
],
"layout": {
"width": 800,
"height": 600,
"xaxis": {
"rangebreaks": [
{
"bounds": [
17,
9
],
"pattern": "hour"
}
],
"title": {
"text": "time"
}
},
"yaxis": {
"title": {
"text": "values"
}
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Fix rangebreaks overlapping and tick positions by archmoj · Pull Request #4831 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c28d0e5
centralize & refactor range expansions
archmoj Apr 6, 2020
1e63bfc
add rangebreaks tests with hourly and auto dticks
archmoj May 13, 2020
3baed24
revise tick positioning - fix dtick hourly - move tick0 outside the b…
archmoj May 13, 2020
4eab137
drop endpoint ticks that fall inside breaks
archmoj May 14, 2020
a7633c3
move last tick on rangebreaks to the start of break instead of removi…
archmoj May 15, 2020
d2d8e6e
revisit ticks on axes with rangebreaks
archmoj May 19, 2020
ca193eb
reject last tick that may include decimals
archmoj May 19, 2020
6b77b31
refactor - no need for else ifs in axes tickIncrement
archmoj May 19, 2020
ef14d60
add jasmine tests for axes with rangebreaks and set dtick
archmoj May 19, 2020
a0d4d0d
improve auto ticks on axes with rangebreaks
archmoj May 20, 2020
0fb92d4
attempt improving ticks on rangebreaks
archmoj Jun 1, 2020
5c8055b
fix issue 4879
archmoj Jun 1, 2020
0a782d8
invert if statement
archmoj Jun 2, 2020
6cd55b5
drop extra function for hour rangebreaks
archmoj Jun 2, 2020
db7d47d
drop extra logic for dayRatio
archmoj Jun 2, 2020
8c8c928
drop extra logic for dynamic oneDay
archmoj Jun 2, 2020
21f4284
drop extra logic for startHour
archmoj Jun 2, 2020
9e7b80e
drop extra logic for dayHours
archmoj Jun 2, 2020
22e5658
avoid too tick overlaps on x axes with rangebreaks and now only when …
archmoj Jun 2, 2020
b38688d
reverse loop order
archmoj Jun 2, 2020
c5cf45a
fixups to avoid single tick
archmoj Jun 2, 2020
9241578
reduce roughDTick by total length of breaks
archmoj Jun 3, 2020
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
94 changes: 59 additions & 35 deletions src/plots/cartesian/axes.js
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand Up@@ -612,39 +622,42 @@ axes.calcTicks = function calcTicks(ax) {

if(ax.rangebreaks) {
// replace ticks inside breaks that would get a tick
if(ax.tickmode === 'auto') {
for(var t = 0; t < tickVals.length; t++) {
var value = tickVals[t].value;
if(ax.maskBreaks(value) === BADNUM) {
// find which break we are in
for(var k = 0; k < ax._rangebreaks.length; k++) {
var brk = ax._rangebreaks[k];
if(value >= brk.min && value < brk.max) {
tickVals[t].value = brk.max; // replace with break end
break;
}
}
}
}
}

// reduce ticks
// and reduce ticks
var len = tickVals.length;
if(len > 2) {
var tf2 = 2 * (ax.tickfont ? ax.tickfont.size : 12);
if(len) {
var tf = 0;
if(ax.tickmode === 'auto') {
tf =
(ax._id.charAt(0) === 'y' ? 2 : 6) *
(ax.tickfont ? ax.tickfont.size : 12);
}

var newTickVals = [];
var prevPos;

var dir = axrev ? 1 : -1;
var first = axrev ? 0 : len - 1;
var last = axrev ? len - 1 : 0;
for(var q = first; dir * q <= dir * last; q += dir) { // apply reverse loop to pick greater values in breaks first
var pos = ax.c2p(tickVals[q].value);
for(var q = first; dir * q <= dir * last; q += dir) {
var tickVal = tickVals[q];
if(ax.maskBreaks(tickVal.value) === BADNUM) {
tickVal.value = moveOutsideBreak(tickVal.value, ax);

if(ax._rl && (
ax._rl[0] === tickVal.value ||
ax._rl[1] === tickVal.value
)) continue;
}

if(prevPos === undefined || Math.abs(pos - prevPos) > tf2) {
var pos = ax.c2p(tickVal.value);

if(pos === prevPos) {
if(newTickVals[newTickVals.length - 1].value < tickVal.value) {
newTickVals[newTickVals.length - 1] = tickVal;
}
} else if(prevPos === undefined || Math.abs(pos - prevPos) > tf) {
prevPos = pos;
newTickVals.push(tickVals[q]);
newTickVals.push(tickVal);
}
}
tickVals = newTickVals.reverse();
Expand DownExpand Up@@ -691,10 +704,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 DownExpand Up@@ -785,8 +797,7 @@ axes.autoTicks = function(ax, roughDTick) {
roughDTick /= ONEAVGMONTH;
ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24);
} else if(roughX2 > ONEDAY) {
ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 7, 14] : roundDays);

ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 2, 7, 14] : roundDays);
// get week ticks on sunday
// this will also move the base tick off 2000-01-01 if dtick is
// 2 or 3 days... but that's a weird enough case that we'll ignore it.
Expand DownExpand Up@@ -934,18 +945,20 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) {
if(tType === 'M') return Lib.incrementMonth(x, dtSigned, calendar);

// Log scales: Linear, Digits
else if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;
if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;

// log10 of 2,5,10, or all digits (logs just have to be
// close enough to round)
else if(tType === 'D') {
if(tType === 'D') {
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1;
var x2 = x + axSign * 0.01;
var frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev);

return Math.floor(x2) +
Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
} else throw 'unrecognized dtick ' + String(dtick);
}

throw 'unrecognized dtick ' + String(dtick);
};

// calculate the first tick on an axis
Expand All@@ -956,7 +969,7 @@ 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);

Expand DownExpand Up@@ -3158,3 +3171,14 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {
function isAngular(ax) {
return ax._id === 'angularaxis';
}

function moveOutsideBreak(v, ax) {
var len = ax._rangebreaks.length;
for(var k = 0; k < len; k++) {
var brk = ax._rangebreaks[k];
if(v >= brk.min && v < brk.max) {
return brk.max;
}
}
return v;
}
4 changes: 1 addition & 3 deletions src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -686,9 +686,7 @@ module.exports = function setConvert(ax, fullLayout) {
var isNewBreak = true;
for(var j = 0; j < rangebreaksOut.length; j++) {
var brkj = rangebreaksOut[j];
if(min > brkj.max || max < brkj.min) {
// potentially a new break
} else {
if(min < brkj.max && max >= brkj.min) {
if(min < brkj.min) {
brkj.min = min;
}
Expand Down
Binary file modifiedtest/image/baselines/axes_breaks-candlestick2.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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modifiedtest/image/baselines/axes_breaks-finance.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 addedtest/image/baselines/axes_breaks-overlap.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 modifiedtest/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 modifiedtest/image/baselines/axes_breaks-round-weekdays.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 modifiedtest/image/baselines/axes_breaks-values.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 modifiedtest/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.
Binary file modifiedtest/image/baselines/axes_breaks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions test/image/mocks/axes_breaks-dtick_auto.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
{
"data": [
{
"type": "scatter",
"mode": "markers",
"x": [
"2020-04-06T09:00:00",
"2020-04-06T10:00:00",
"2020-04-06T11:00:00",
"2020-04-06T12:00:00",
"2020-04-06T13:00:00",
"2020-04-06T14:00:00",
"2020-04-06T15:00:00",
"2020-04-06T16:00:00",
"2020-04-07T09:00:00",
"2020-04-07T10:00:00",
"2020-04-07T11:00:00",
"2020-04-07T12:00:00",
"2020-04-07T13:00:00",
"2020-04-07T14:00:00",
"2020-04-07T15:00:00",
"2020-04-07T16:00:00",
"2020-04-08T09:00:00",
"2020-04-08T10:00:00",
"2020-04-08T11:00:00",
"2020-04-08T12:00:00",
"2020-04-08T13:00:00",
"2020-04-08T14:00:00",
"2020-04-08T15:00:00",
"2020-04-08T16:00:00",
"2020-04-09T09:00:00",
"2020-04-09T10:00:00",
"2020-04-09T11:00:00",
"2020-04-09T12:00:00",
"2020-04-09T13:00:00",
"2020-04-09T14:00:00",
"2020-04-09T15:00:00",
"2020-04-09T16:00:00",
"2020-04-10T09:00:00",
"2020-04-10T10:00:00",
"2020-04-10T11:00:00",
"2020-04-10T12:00:00",
"2020-04-10T13:00:00",
"2020-04-10T14:00:00",
"2020-04-10T15:00:00",
"2020-04-10T16:00:00"
],
"y": [
0.19742877314456364,
0.1509714558226325,
0.3730270552929804,
0.7394093812216096,
1.2149308862244954,
1.5707342286171064,
1.0824483128021085,
0.9424263772804724,
1.1724169397045303,
0.8440466169659708,
0.8650832231701001,
0.41942121150935374,
0.11941773640575382,
-0.3620604691336322,
-0.06836276577621159,
-0.34443807771583146,
-0.49908639701892876,
-0.07100510355333789,
0.13340929837019488,
-0.33475177209849727,
-0.6700576156005845,
-0.548579214100821,
-0.4713506254966534,
-0.7334578041221448,
-0.299243806197351,
-0.18527785023145504,
-0.14964504720649674,
-0.05973507085192575,
0.17038695866484388,
-0.01766804585555426,
-0.11944698363946238,
-0.40960323466434023,
-0.7234102287840041,
-0.2790378388000705,
-0.039487043750782935,
-0.04902823513321586,
-0.3216136071598926,
-0.5672571253894997,
-1.009227965065624,
-1.0748113395075032
]
}
],
"layout": {
"width": 800,
"height": 600,
"xaxis": {
"rangebreaks": [
{
"bounds": [
17,
9
],
"pattern": "hour"
}
],
"title": {
"text": "time"
}
},
"yaxis": {
"title": {
"text": "values"
}
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Fix rangebreaks overlapping and tick positions by archmoj · Pull Request #4831 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c28d0e5
centralize & refactor range expansions
archmoj Apr 6, 2020
1e63bfc
add rangebreaks tests with hourly and auto dticks
archmoj May 13, 2020
3baed24
revise tick positioning - fix dtick hourly - move tick0 outside the b…
archmoj May 13, 2020
4eab137
drop endpoint ticks that fall inside breaks
archmoj May 14, 2020
a7633c3
move last tick on rangebreaks to the start of break instead of removi…
archmoj May 15, 2020
d2d8e6e
revisit ticks on axes with rangebreaks
archmoj May 19, 2020
ca193eb
reject last tick that may include decimals
archmoj May 19, 2020
6b77b31
refactor - no need for else ifs in axes tickIncrement
archmoj May 19, 2020
ef14d60
add jasmine tests for axes with rangebreaks and set dtick
archmoj May 19, 2020
a0d4d0d
improve auto ticks on axes with rangebreaks
archmoj May 20, 2020
0fb92d4
attempt improving ticks on rangebreaks
archmoj Jun 1, 2020
5c8055b
fix issue 4879
archmoj Jun 1, 2020
0a782d8
invert if statement
archmoj Jun 2, 2020
6cd55b5
drop extra function for hour rangebreaks
archmoj Jun 2, 2020
db7d47d
drop extra logic for dayRatio
archmoj Jun 2, 2020
8c8c928
drop extra logic for dynamic oneDay
archmoj Jun 2, 2020
21f4284
drop extra logic for startHour
archmoj Jun 2, 2020
9e7b80e
drop extra logic for dayHours
archmoj Jun 2, 2020
22e5658
avoid too tick overlaps on x axes with rangebreaks and now only when …
archmoj Jun 2, 2020
b38688d
reverse loop order
archmoj Jun 2, 2020
c5cf45a
fixups to avoid single tick
archmoj Jun 2, 2020
9241578
reduce roughDTick by total length of breaks
archmoj Jun 3, 2020
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
94 changes: 59 additions & 35 deletions src/plots/cartesian/axes.js
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand Up@@ -612,39 +622,42 @@ axes.calcTicks = function calcTicks(ax) {

if(ax.rangebreaks) {
// replace ticks inside breaks that would get a tick
if(ax.tickmode === 'auto') {
for(var t = 0; t < tickVals.length; t++) {
var value = tickVals[t].value;
if(ax.maskBreaks(value) === BADNUM) {
// find which break we are in
for(var k = 0; k < ax._rangebreaks.length; k++) {
var brk = ax._rangebreaks[k];
if(value >= brk.min && value < brk.max) {
tickVals[t].value = brk.max; // replace with break end
break;
}
}
}
}
}

// reduce ticks
// and reduce ticks
var len = tickVals.length;
if(len > 2) {
var tf2 = 2 * (ax.tickfont ? ax.tickfont.size : 12);
if(len) {
var tf = 0;
if(ax.tickmode === 'auto') {
tf =
(ax._id.charAt(0) === 'y' ? 2 : 6) *
(ax.tickfont ? ax.tickfont.size : 12);
}

var newTickVals = [];
var prevPos;

var dir = axrev ? 1 : -1;
var first = axrev ? 0 : len - 1;
var last = axrev ? len - 1 : 0;
for(var q = first; dir * q <= dir * last; q += dir) { // apply reverse loop to pick greater values in breaks first
var pos = ax.c2p(tickVals[q].value);
for(var q = first; dir * q <= dir * last; q += dir) {
var tickVal = tickVals[q];
if(ax.maskBreaks(tickVal.value) === BADNUM) {
tickVal.value = moveOutsideBreak(tickVal.value, ax);

if(ax._rl && (
ax._rl[0] === tickVal.value ||
ax._rl[1] === tickVal.value
)) continue;
}

if(prevPos === undefined || Math.abs(pos - prevPos) > tf2) {
var pos = ax.c2p(tickVal.value);

if(pos === prevPos) {
if(newTickVals[newTickVals.length - 1].value < tickVal.value) {
newTickVals[newTickVals.length - 1] = tickVal;
}
} else if(prevPos === undefined || Math.abs(pos - prevPos) > tf) {
prevPos = pos;
newTickVals.push(tickVals[q]);
newTickVals.push(tickVal);
}
}
tickVals = newTickVals.reverse();
Expand DownExpand Up@@ -691,10 +704,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 DownExpand Up@@ -785,8 +797,7 @@ axes.autoTicks = function(ax, roughDTick) {
roughDTick /= ONEAVGMONTH;
ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24);
} else if(roughX2 > ONEDAY) {
ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 7, 14] : roundDays);

ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 2, 7, 14] : roundDays);
// get week ticks on sunday
// this will also move the base tick off 2000-01-01 if dtick is
// 2 or 3 days... but that's a weird enough case that we'll ignore it.
Expand DownExpand Up@@ -934,18 +945,20 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) {
if(tType === 'M') return Lib.incrementMonth(x, dtSigned, calendar);

// Log scales: Linear, Digits
else if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;
if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;

// log10 of 2,5,10, or all digits (logs just have to be
// close enough to round)
else if(tType === 'D') {
if(tType === 'D') {
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1;
var x2 = x + axSign * 0.01;
var frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev);

return Math.floor(x2) +
Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
} else throw 'unrecognized dtick ' + String(dtick);
}

throw 'unrecognized dtick ' + String(dtick);
};

// calculate the first tick on an axis
Expand All@@ -956,7 +969,7 @@ 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);

Expand DownExpand Up@@ -3158,3 +3171,14 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {
function isAngular(ax) {
return ax._id === 'angularaxis';
}

function moveOutsideBreak(v, ax) {
var len = ax._rangebreaks.length;
for(var k = 0; k < len; k++) {
var brk = ax._rangebreaks[k];
if(v >= brk.min && v < brk.max) {
return brk.max;
}
}
return v;
}
4 changes: 1 addition & 3 deletions src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -686,9 +686,7 @@ module.exports = function setConvert(ax, fullLayout) {
var isNewBreak = true;
for(var j = 0; j < rangebreaksOut.length; j++) {
var brkj = rangebreaksOut[j];
if(min > brkj.max || max < brkj.min) {
// potentially a new break
} else {
if(min < brkj.max && max >= brkj.min) {
if(min < brkj.min) {
brkj.min = min;
}
Expand Down
Binary file modifiedtest/image/baselines/axes_breaks-candlestick2.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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modifiedtest/image/baselines/axes_breaks-finance.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 addedtest/image/baselines/axes_breaks-overlap.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 modifiedtest/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 modifiedtest/image/baselines/axes_breaks-round-weekdays.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 modifiedtest/image/baselines/axes_breaks-values.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 modifiedtest/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.
Binary file modifiedtest/image/baselines/axes_breaks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions test/image/mocks/axes_breaks-dtick_auto.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
{
"data": [
{
"type": "scatter",
"mode": "markers",
"x": [
"2020-04-06T09:00:00",
"2020-04-06T10:00:00",
"2020-04-06T11:00:00",
"2020-04-06T12:00:00",
"2020-04-06T13:00:00",
"2020-04-06T14:00:00",
"2020-04-06T15:00:00",
"2020-04-06T16:00:00",
"2020-04-07T09:00:00",
"2020-04-07T10:00:00",
"2020-04-07T11:00:00",
"2020-04-07T12:00:00",
"2020-04-07T13:00:00",
"2020-04-07T14:00:00",
"2020-04-07T15:00:00",
"2020-04-07T16:00:00",
"2020-04-08T09:00:00",
"2020-04-08T10:00:00",
"2020-04-08T11:00:00",
"2020-04-08T12:00:00",
"2020-04-08T13:00:00",
"2020-04-08T14:00:00",
"2020-04-08T15:00:00",
"2020-04-08T16:00:00",
"2020-04-09T09:00:00",
"2020-04-09T10:00:00",
"2020-04-09T11:00:00",
"2020-04-09T12:00:00",
"2020-04-09T13:00:00",
"2020-04-09T14:00:00",
"2020-04-09T15:00:00",
"2020-04-09T16:00:00",
"2020-04-10T09:00:00",
"2020-04-10T10:00:00",
"2020-04-10T11:00:00",
"2020-04-10T12:00:00",
"2020-04-10T13:00:00",
"2020-04-10T14:00:00",
"2020-04-10T15:00:00",
"2020-04-10T16:00:00"
],
"y": [
0.19742877314456364,
0.1509714558226325,
0.3730270552929804,
0.7394093812216096,
1.2149308862244954,
1.5707342286171064,
1.0824483128021085,
0.9424263772804724,
1.1724169397045303,
0.8440466169659708,
0.8650832231701001,
0.41942121150935374,
0.11941773640575382,
-0.3620604691336322,
-0.06836276577621159,
-0.34443807771583146,
-0.49908639701892876,
-0.07100510355333789,
0.13340929837019488,
-0.33475177209849727,
-0.6700576156005845,
-0.548579214100821,
-0.4713506254966534,
-0.7334578041221448,
-0.299243806197351,
-0.18527785023145504,
-0.14964504720649674,
-0.05973507085192575,
0.17038695866484388,
-0.01766804585555426,
-0.11944698363946238,
-0.40960323466434023,
-0.7234102287840041,
-0.2790378388000705,
-0.039487043750782935,
-0.04902823513321586,
-0.3216136071598926,
-0.5672571253894997,
-1.009227965065624,
-1.0748113395075032
]
}
],
"layout": {
"width": 800,
"height": 600,
"xaxis": {
"rangebreaks": [
{
"bounds": [
17,
9
],
"pattern": "hour"
}
],
"title": {
"text": "time"
}
},
"yaxis": {
"title": {
"text": "values"
}
}
}
}
Loading