MCPcopy Create free account
hub / github.com/plotly/plotly.js / ordinalScaleSnap

Function ordinalScaleSnap

src/traces/parcoords/axisbrush.js:21–47  ·  view source on GitHub ↗
(isHigh, a, v, existingRanges)

Source from the content-addressed store, hash-verified

19// find the interval we're in, and snap to 1/4 the distance to the next
20// these two could be unified at a slight loss of readability / perf
21function ordinalScaleSnap(isHigh, a, v, existingRanges) {
22 if(overlappingExisting(v, existingRanges)) return v;
23
24 var dir = isHigh ? -1 : 1;
25
26 var first = 0;
27 var last = a.length - 1;
28 if(dir < 0) {
29 var tmp = first;
30 first = last;
31 last = tmp;
32 }
33
34 var aHere = a[first];
35 var aPrev = aHere;
36 for(var i = first; dir * i < dir * last; i += dir) {
37 var nextI = i + dir;
38 var aNext = a[nextI];
39
40 // very close to the previous - snap down to it
41 if(dir * v < dir * closeToCovering(aHere, aNext)) return snapOvershoot(aHere, aPrev);
42 if(dir * v < dir * aNext || nextI === last) return snapOvershoot(aNext, aHere);
43
44 aPrev = aHere;
45 aHere = aNext;
46 }
47}
48
49function overlappingExisting(v, existingRanges) {
50 for(var i = 0; i < existingRanges.length; i++) {

Callers 2

dragendFunction · 0.85
cleanRangesFunction · 0.85

Calls 3

overlappingExistingFunction · 0.85
closeToCoveringFunction · 0.85
snapOvershootFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…