@@ -99,60 +99,29 @@ exports.getFilterFn = function(direction) {
99
99
} ;
100
100
101
101
function _getFilterFn ( direction ) {
102
- var isPrevThisDirection = null ;
102
+ // we're optimists - before we have any changing data, assume increasing
103
+ var isPrevIncreasing = true ;
103
104
var cPrev = null ;
104
- var fn ;
105
-
106
- switch ( direction ) {
107
- case 'increasing' :
108
- fn = function ( o , c ) {
109
- if ( o === c ) {
110
- if ( c > cPrev ) {
111
- return true ; // increasing
112
- } else if ( c < cPrev ) {
113
- return false ; // decreasing
114
- } else {
115
- if ( isPrevThisDirection === true ) {
116
- return true ; // determine by last candle
117
- } else if ( isPrevThisDirection === false ) {
118
- return false ; // determine by last candle
119
- } else {
120
- return true ; // If we don't have previous data, assume it was increasing
121
- }
122
- }
123
- }
124
- return o < c ;
125
- } ;
126
- break ;
127
105
128
- case 'decreasing' :
129
- fn = function ( o , c ) {
130
- if ( o === c ) {
131
- if ( c > cPrev ) {
132
- return false ; // increasing
133
- } else if ( c < cPrev ) {
134
- return true ; // decreasing
135
- } else {
136
- if ( isPrevThisDirection === true ) {
137
- return true ; // determine by last candle
138
- } else if ( isPrevThisDirection === false ) {
139
- return false ; // determine by last candle
140
- } else {
141
- return false ; // If we don't have previous data, assume it was increasing
142
- }
143
- }
144
- }
145
- return o > c ;
146
- } ;
147
- break ;
106
+ function isIncreasing ( o , c ) {
107
+ if ( o === c ) {
108
+ if ( c > cPrev ) {
109
+ isPrevIncreasing = true ; // increasing
110
+ } else if ( c < cPrev ) {
111
+ isPrevIncreasing = false ; // decreasing
112
+ }
113
+ // else isPrevIncreasing is not changed
114
+ }
115
+ else isPrevIncreasing = ( o < c ) ;
116
+ cPrev = c ;
117
+ return isPrevIncreasing ;
148
118
}
149
119
150
- return function ( o , c ) {
151
- var out = fn ( o , c ) ;
152
- isPrevThisDirection = ! ! out ;
153
- cPrev = c ;
154
- return out ;
155
- } ;
120
+ function isDecreasing ( o , c ) {
121
+ return ! isIncreasing ( o , c ) ;
122
+ }
123
+
124
+ return direction === 'increasing' ? isIncreasing : isDecreasing ;
156
125
}
157
126
158
127
exports . addRangeSlider = function ( data , layout ) {
0 commit comments