Skip to content

Fixing ohlc showing wrong color when opening equals closing #1619

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

Closed
wants to merge 3 commits into from

Conversation

noway
Copy link
Contributor

@noway noway commented Apr 22, 2017

Haven't found how to contact maintainers (no irc/slack, apart from community.plot.ly which doesn't seem to be the appropriate place?) so posting the PR here.

Fixed the case when opening is equal to closing and it always showing "increasing" color. It should instead determine the color based on the relation of previous close price to close price of the new one, or, if that's equal too, on the color of the previous candle.

So that it renders correctly in the following case:
2017-04-22-200734_266x595_scrot

@etpinard
Copy link
Contributor

Haven't found how to contact maintainers

Usually, contributors first open up an issue about the problem and discuss it there. Then contributors are encouraged to make a PR to their forked repo ask for a review there. Community PRs that don't reference an issue ticket can sometimes feel a little rude to FOSS maintainers.

No need to close your PR and redo the process though. Take it as an FYI.


About

Fixed the case when opening is equal to closing and it always showing "increasing" color. It should instead determine the color based on the relation of previous close price to close price of the new one, or, if that's equal too, on the color of the previous candle.

That sounds fair. But, can you confirm that this is the official way of handling this? How does this compare to what other graphing libraries are doing?

@noway
Copy link
Contributor Author

noway commented Apr 26, 2017

bitcoinwisdom which is a really reputable example deals with it this way.
screen shot 2017-04-27 at 2 41 29 am
(in current version all of those dashes would be green)

@@ -97,13 +97,46 @@ exports.makeTransform = function(traceIn, state, direction) {
exports.getFilterFn = function(direction) {
switch(direction) {
case 'increasing':
return function(o, c) { return o <= c; };
return function(o, c, isPrevThisDirection, oprev, cprev) {
Copy link
Contributor

@etpinard etpinard Apr 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The algo looks good 👍

It might worth the time to make it a little DRYer by wrapping isPrevThisDirestion, oprev and cprev in a closure. That is, something like:

exports.getFilterFn = function(direction) {
  return new _getFilterFn(direction);
};

function _getFilterFn(directon) {
  var isPrevThisDirection = null;
  var oprev = null;
  var cprev = null;
  
  var fn;
  switch(direction) {
    case 'increasing':
      fn = function(o, c) { /* */ };
      break;
    case 'decreasing':
      fn = function(o, c) { /* */ };
      break;
  }

  return function(o, c) {
    var out = fn(o, c);
    isPrevThisDirection = !!out;
    oprev = o;
    cprev = c;
    return out;
  };
};

that way we wouldn't have to patch candlestick/transform.js and ohlc/transform.js.

@etpinard etpinard added status: in progress bug something broken labels Apr 27, 2017
@noway
Copy link
Contributor Author

noway commented Apr 28, 2017

That's a good idea. Fixed, although haven't had a chance to test it.

@etpinard
Copy link
Contributor

@noway thanks. If you're up for a challenge you can try adding a few test cases in this suite.

@noway
Copy link
Contributor Author

noway commented Apr 30, 2017

Unfortunately I'd have to pass, can't allocate enough of a chunk of time. Otherwise I'm happy to help :-)

@etpinard
Copy link
Contributor

etpinard commented May 8, 2017

Superseded by #1655

@etpinard etpinard closed this May 8, 2017
@noway noway deleted the fix-open-equals-close branch June 11, 2017 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants