-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
OHLC equal open close cases fix #1655
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
Changes from 5 commits
af277b6
20494db
c4f7703
961fed4
ca3fa4d
9575ab6
597adf9
dd1f770
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,14 +95,65 @@ exports.makeTransform = function(traceIn, state, direction) { | |
}; | ||
|
||
exports.getFilterFn = function(direction) { | ||
return new _getFilterFn(direction); | ||
}; | ||
|
||
function _getFilterFn(direction) { | ||
var isPrevThisDirection = null; | ||
var cPrev = null; | ||
var fn; | ||
|
||
switch(direction) { | ||
case 'increasing': | ||
return function(o, c) { return o <= c; }; | ||
fn = function(o, c) { | ||
if(o === c) { | ||
if(c > cPrev) { | ||
return true; // increasing | ||
} else if(c < cPrev) { | ||
return false; // decreasing | ||
} else { | ||
if(isPrevThisDirection === true) { | ||
return true; // determine by last candle | ||
} else if(isPrevThisDirection === false) { | ||
return false; // determine by last candle | ||
} else { | ||
return true; // If we don't have previous data, assume it was increasing | ||
} | ||
} | ||
} | ||
return o < c; | ||
}; | ||
break; | ||
|
||
case 'decreasing': | ||
return function(o, c) { return o > c; }; | ||
fn = function(o, c) { | ||
if(o === c) { | ||
if(c > cPrev) { | ||
return false; // increasing | ||
} else if(c < cPrev) { | ||
return true; // decreasing | ||
} else { | ||
if(isPrevThisDirection === true) { | ||
return true; // determine by last candle | ||
} else if(isPrevThisDirection === false) { | ||
return false; // determine by last candle | ||
} else { | ||
return false; // If we don't have previous data, assume it was increasing | ||
} | ||
} | ||
} | ||
return o > c; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a lot of duplication with just a few
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexcjohnson I vaguely remember you mentioning on slack that you had a commit implementing your solution on a branch. If that's not case, I'll try to push something up to get this PR in this week's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simplified these filters (even more than ^^) in 9575ab6 |
||
break; | ||
} | ||
}; | ||
|
||
return function(o, c) { | ||
var out = fn(o, c); | ||
isPrevThisDirection = !!out; | ||
cPrev = c; | ||
return out; | ||
}; | ||
} | ||
|
||
exports.addRangeSlider = function(data, layout) { | ||
var hasOneVisibleTrace = false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We haven't cast to numbers, have we? Looks like this will break if we mix strings and numbers (or use different string representations of the same number, like
'2.0'
and'2.00'
I guess a point should get dropped if any of o, h, l, c is not numeric?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checked all to ensure they're numeric in 597adf9