Skip to content

Fix2950 parcoords cannot select first enum #3915

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 2 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 21 additions & 27 deletions src/traces/parcoords/axisbrush.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,31 @@ function closeToCovering(v, vAdjacent) { return v * (1 - snapClose) + vAdjacent
// so it's clear we're covering it
// find the interval we're in, and snap to 1/4 the distance to the next
// these two could be unified at a slight loss of readability / perf
function ordinalScaleSnapLo(a, v, existingRanges) {
function ordinalScaleSnap(isHigh, a, v, existingRanges) {
if(overlappingExisting(v, existingRanges)) return v;

var aPrev = a[0];
var aPrevPrev = aPrev;
for(var i = 1; i < a.length; i++) {
var aNext = a[i];
var dir = isHigh ? -1 : 1;

// very close to the previous - snap down to it
if(v < closeToCovering(aPrev, aNext)) return snapOvershoot(aPrev, aPrevPrev);
if(v < aNext || i === a.length - 1) return snapOvershoot(aNext, aPrev);

aPrevPrev = aPrev;
aPrev = aNext;
var first = 0;
var last = a.length - 1;
if(dir < 0) {
var tmp = first;
first = last;
last = tmp;
}
}

function ordinalScaleSnapHi(a, v, existingRanges) {
if(overlappingExisting(v, existingRanges)) return v;

var aPrev = a[a.length - 1];
var aPrevPrev = aPrev;
for(var i = a.length - 2; i >= 0; i--) {
var aNext = a[i];
var aHere = a[first];
var aPrev = aHere;
for(var i = first; dir * i < dir * last; i += dir) {
var nextI = i + dir;
var aNext = a[nextI];

// very close to the previous - snap down to it
if(v > closeToCovering(aPrev, aNext)) return snapOvershoot(aPrev, aPrevPrev);
if(v > aNext || i === a.length - 1) return snapOvershoot(aNext, aPrev);
if(dir * v < dir * closeToCovering(aHere, aNext)) return snapOvershoot(aHere, aPrev);
if(dir * v < dir * aNext || nextI === last) return snapOvershoot(aNext, aHere);

aPrevPrev = aPrev;
aPrev = aNext;
aPrev = aHere;
aHere = aNext;
}
}

Expand Down Expand Up @@ -333,8 +327,8 @@ function attachDragBehavior(selection) {
var a = d.unitTickvals;
if(a[a.length - 1] < a[0]) a.reverse();
s.newExtent = [
ordinalScaleSnapLo(a, s.newExtent[0], s.stayingIntervals),
ordinalScaleSnapHi(a, s.newExtent[1], s.stayingIntervals)
ordinalScaleSnap(0, a, s.newExtent[0], s.stayingIntervals),
ordinalScaleSnap(1, a, s.newExtent[1], s.stayingIntervals)
];
var hasNewExtent = s.newExtent[1] > s.newExtent[0];
s.extent = s.stayingIntervals.concat(hasNewExtent ? [s.newExtent] : []);
Expand Down Expand Up @@ -505,8 +499,8 @@ function cleanRanges(ranges, dimension) {
var sortedTickVals = dimension.tickvals.slice().sort(sortAsc);
ranges = ranges.map(function(ri) {
var rSnapped = [
ordinalScaleSnapLo(sortedTickVals, ri[0], []),
ordinalScaleSnapHi(sortedTickVals, ri[1], [])
ordinalScaleSnap(0, sortedTickVals, ri[0], []),
ordinalScaleSnap(1, sortedTickVals, ri[1], [])
];
if(rSnapped[1] > rSnapped[0]) return rSnapped;
})
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions test/image/mocks/gl2d_parcoords_select_first_last_enum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"data": [
{
"type": "parcoords",
"line": {
"colorscale": "Portland",
"showscale": true,
"reversescale": true,
"color": [
1,
2,
3,
4,
5,
6,
7,
8
]
},
"dimensions": [
{
"label": "A",
"values": [
1,
2,
3,
4,
5,
6,
7,
8
],
"tickvals": [
1,
2,
3,
4,
5,
6,
7,
8
],
"constraintrange": [
[
1,
1
],
[
3,
3
],
[
5,
6
],
[
8,
8
]
]
},
{
"label": "B",
"values": [
1,
2,
3,
5,
8,
13,
22,
35
]
}
]
}
],
"layout": {
"width": 400,
"height": 400,
"title": {
"text": "should select first and last enum"
}
}
}