Skip to content

Introduce cartesian axis breaks #4614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4f6ea7e
introduce axis breaks attributes
etpinard Mar 3, 2020
e9cfe04
add axis breaks default logic
etpinard Mar 3, 2020
baf753a
add ax.maskBreaks method
etpinard Mar 3, 2020
259eafa
implement axis breaks setConvert logic
etpinard Mar 3, 2020
eca3da7
adapt autorange routine for axis breaks
etpinard Mar 3, 2020
6bec94d
adapt calcTicks for axis breaks
etpinard Mar 3, 2020
fe80cad
adapt dragbox logic for axis breaks
etpinard Mar 3, 2020
d425373
do not show zeroline when it falls inside an axis break
etpinard Mar 3, 2020
5f2fbe0
add axis breaks mocks
etpinard Mar 3, 2020
b5aaf92
add TODO for better "first tick" algo on date axes
etpinard Mar 3, 2020
187c93a
fix typo in comment
etpinard Mar 3, 2020
ebca01b
fix axis breaks + rangeslider behavior
etpinard Mar 4, 2020
3957d95
during l2p(v) when v falls into breaks, pick offset closest to it
etpinard Mar 4, 2020
76a265e
fix typo in break `bounds` description
etpinard Mar 5, 2020
e00af90
Handle breaks on date axes only for now
etpinard Mar 5, 2020
53196e5
simplify logic - breaks are on date axes only
archmoj Mar 9, 2020
493bb4e
Handle axis breaks on reversed ranges
etpinard Mar 5, 2020
7080f90
replace 'spread' -> 'size' in attr descriptions
etpinard Mar 10, 2020
dcceb76
fix %H maskBreaks for values greater but on the same hour
etpinard Mar 10, 2020
28c328d
increase dtick on axes with breaks ...
etpinard Mar 11, 2020
432f0d0
Merge branch 'master' into axis-breaks
etpinard Mar 12, 2020
40d57fa
fix scale when panning on breaks
archmoj Mar 12, 2020
1b55b42
fix 'increase dtick' lgoic for cases with dtick value starting 'M'
etpinard Mar 12, 2020
49b4053
set scattergl and splom traces to visible:false on axis with breaks
etpinard Mar 12, 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
Prev Previous commit
Next Next commit
adapt autorange routine for axis breaks
... as the value-space length is reduced when axis breaks are
    present within the trial range
  • Loading branch information
etpinard committed Mar 3, 2020
commit eca3da70067e45ecac492cdfe7d6cfda4fb8ea34
16 changes: 14 additions & 2 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,26 @@ function getAutoRange(gd, ax) {
// don't allow padding to reduce the data to < 10% of the length
var minSpan = axLen / 10;

// find axis breaks in [v0,v1] and compute its length in value space
var calcBreaksLength = function(v0, v1) {
var lBreaks = 0;
if(ax.breaks) {
var breaksOut = ax.locateBreaks(v0, v1);
for(var i = 0; i < breaksOut.length; i++) {
lBreaks += (breaksOut[i].max - breaksOut[i].min);
}
}
return lBreaks;
};

var mbest = 0;
var minpt, maxpt, minbest, maxbest, dp, dv;

for(i = 0; i < minArray.length; i++) {
minpt = minArray[i];
for(j = 0; j < maxArray.length; j++) {
maxpt = maxArray[j];
dv = maxpt.val - minpt.val;
dv = maxpt.val - minpt.val - calcBreaksLength(minpt.val, maxpt.val);
if(dv > 0) {
dp = axLen - getPad(minpt) - getPad(maxpt);
if(dp > minSpan) {
Expand Down Expand Up @@ -167,7 +179,7 @@ function getAutoRange(gd, ax) {
}

// in case it changed again...
mbest = (maxbest.val - minbest.val) /
mbest = (maxbest.val - minbest.val - calcBreaksLength(minpt.val, maxpt.val)) /
(axLen - getPad(minbest) - getPad(maxbest));

newRange = [
Expand Down
68 changes: 68 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4214,6 +4214,74 @@ describe('Test axes', function() {
});
});

describe('during doAutorange', function() {
var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(destroyGraphDiv);

function _assert(msg, exp) {
expect(gd._fullLayout.xaxis.range).toEqual(exp.xrng, msg + '| x range');
expect(gd._fullLayout.xaxis._lBreaks).toBe(exp.lBreaks, msg + '| lBreaks');
}

it('should adapt padding about axis breaks length', function(done) {
Plotly.plot(gd, [{
mode: 'markers',
x: [0, 10, 50, 90, 100, 150, 190, 200]
}], {
xaxis: {
breaks: [
{bounds: [11, 89]},
{bounds: [101, 189]}
]
}
})
.then(function() {
_assert('mode:markers (i.e. with padding)', {
xrng: [-2.1849529780564265, 202.18495297805643],
lBreaks: 166
});
})
.then(function() {
gd.data[0].mode = 'lines';
return Plotly.react(gd, gd.data, gd.layout);
})
.then(function() {
_assert('mode:lines (i.e. no padding)', {
xrng: [0, 200],
lBreaks: 166
});
})
.then(function() {
gd.data[0].mode = 'markers';
gd.layout.xaxis.breaks[0].enabled = false;
return Plotly.react(gd, gd.data, gd.layout);
})
.then(function() {
_assert('mode:markers | one of two breaks enabled', {
xrng: [-7.197492163009405, 207.1974921630094],
lBreaks: 88
});
})
.then(function() {
gd.layout.xaxis.breaks[1].enabled = false;
return Plotly.react(gd, gd.data, gd.layout);
})
.then(function() {
_assert('mode:markers | no breaks enabled', {
xrng: [-12.852664576802507, 212.8526645768025],
lBreaks: 0
});
})
.catch(failTest)
.then(done);
});
});

describe('during setConvert (once range is available)', function() {
var gd;

Expand Down