11
11
12
12
var BADNUM = require ( '../../constants/numerical' ) . BADNUM ;
13
13
var segmentsIntersect = require ( '../../lib/geometry2d' ) . segmentsIntersect ;
14
+ var constants = require ( './constants' ) ;
14
15
15
16
16
17
module . exports = function linePoints ( d , opts ) {
17
- var xa = opts . xaxis ,
18
- ya = opts . yaxis ,
19
- simplify = opts . simplify ,
20
- connectGaps = opts . connectGaps ,
21
- baseTolerance = opts . baseTolerance ,
22
- linear = opts . linear ,
23
- segments = [ ] ,
24
- minTolerance = 0.2 , // fraction of tolerance "so close we don't even consider it a new point"
25
- pts = new Array ( d . length ) ,
26
- pti = 0 ,
27
- i ,
28
-
29
- // pt variables are pixel coordinates [x,y] of one point
30
- clusterStartPt , // these four are the outputs of clustering on a line
31
- clusterEndPt ,
32
- clusterHighPt ,
33
- clusterLowPt ,
34
- thisPt , // "this" is the next point we're considering adding to the cluster
35
-
36
- clusterRefDist ,
37
- clusterHighFirst , // did we encounter the high point first, then a low point, or vice versa?
38
- clusterUnitVector , // the first two points in the cluster determine its unit vector
39
- // so the second is always in the "High" direction
40
- thisVector , // the pixel delta from clusterStartPt
41
-
42
- // val variables are (signed) pixel distances along the cluster vector
43
- clusterHighVal ,
44
- clusterLowVal ,
45
- thisVal ,
46
-
47
- // deviation variables are (signed) pixel distances normal to the cluster vector
48
- clusterMinDeviation ,
49
- clusterMaxDeviation ,
50
- thisDeviation ;
18
+ var xa = opts . xaxis ;
19
+ var ya = opts . yaxis ;
20
+ var simplify = opts . simplify ;
21
+ var connectGaps = opts . connectGaps ;
22
+ var baseTolerance = opts . baseTolerance ;
23
+ var linear = opts . linear ;
24
+ var segments = [ ] ;
25
+ var minTolerance = constants . minTolerance ;
26
+ var pts = new Array ( d . length ) ;
27
+ var pti = 0 ;
28
+
29
+ var i ;
30
+
31
+ // pt variables are pixel coordinates [x,y] of one point
32
+ // these four are the outputs of clustering on a line
33
+ var clusterStartPt , clusterEndPt , clusterHighPt , clusterLowPt ;
34
+
35
+ // "this" is the next point we're considering adding to the cluster
36
+ var thisPt ;
37
+
38
+ // did we encounter the high point first, then a low point, or vice versa?
39
+ var clusterHighFirst ;
40
+
41
+ // the first two points in the cluster determine its unit vector
42
+ // so the second is always in the "High" direction
43
+ var clusterUnitVector ;
44
+
45
+ // the pixel delta from clusterStartPt
46
+ var thisVector ;
47
+
48
+ // val variables are (signed) pixel distances along the cluster vector
49
+ var clusterRefDist , clusterHighVal , clusterLowVal , thisVal ;
50
+
51
+ // deviation variables are (signed) pixel distances normal to the cluster vector
52
+ var clusterMinDeviation , clusterMaxDeviation , thisDeviation ;
51
53
52
54
if ( ! simplify ) {
53
55
baseTolerance = minTolerance = - 1 ;
54
56
}
55
57
56
58
// turn one calcdata point into pixel coordinates
57
59
function getPt ( index ) {
58
- var x = xa . c2p ( d [ index ] . x ) ,
59
- y = ya . c2p ( d [ index ] . y ) ;
60
+ var x = xa . c2p ( d [ index ] . x ) ;
61
+ var y = ya . c2p ( d [ index ] . y ) ;
60
62
if ( x === BADNUM || y === BADNUM ) return false ;
61
63
return [ x , y ] ;
62
64
}
@@ -65,20 +67,19 @@ module.exports = function linePoints(d, opts) {
65
67
function getTolerance ( pt ) {
66
68
var xFrac = pt [ 0 ] / xa . _length ;
67
69
var yFrac = pt [ 1 ] / ya . _length ;
68
- return ( 1 + 10 * Math . max ( 0 , - xFrac , xFrac - 1 , - yFrac , yFrac - 1 ) ) * baseTolerance ;
70
+ return ( 1 + constants . toleranceGrowth * Math . max ( 0 , - xFrac , xFrac - 1 , - yFrac , yFrac - 1 ) ) * baseTolerance ;
69
71
}
70
72
71
73
function ptDist ( pt1 , pt2 ) {
72
- var dx = pt1 [ 0 ] - pt2 [ 0 ] ,
73
- dy = pt1 [ 1 ] - pt2 [ 1 ] ;
74
+ var dx = pt1 [ 0 ] - pt2 [ 0 ] ;
75
+ var dy = pt1 [ 1 ] - pt2 [ 1 ] ;
74
76
return Math . sqrt ( dx * dx + dy * dy ) ;
75
77
}
76
78
77
79
// last bit of filtering: clip paths that are VERY far off-screen
78
80
// so we don't get near the browser's hard limit (+/- 2^29 px in Chrome and FF)
79
81
80
- // maximum multiple of the screen size to use
81
- var maxScreensAway = 20 ;
82
+ var maxScreensAway = constants . maxScreensAway ;
82
83
83
84
// find the intersections between the segment from pt1 to pt2
84
85
// and the large rectangle maxScreensAway around the viewport
0 commit comments