Skip to content

Fixing ohlc showing wrong color when opening equals closing - #1619

Closed
noway wants to merge 3 commits into
plotly:masterfrom
noway:fix-open-equals-close
Closed

Fixing ohlc showing wrong color when opening equals closing#1619
noway wants to merge 3 commits into
plotly:masterfrom
noway:fix-open-equals-close

Conversation

@noway

@noway noway commented Apr 22, 2017

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

noway commented Apr 26, 2017

Copy link
Copy Markdown
Contributor Author

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)

Comment thread src/traces/ohlc/helpers.js Outdated
switch(direction) {
case 'increasing':
return function(o, c) { return o <= c; };
return function(o, c, isPrevThisDirection, oprev, cprev) {

@etpinard etpinard Apr 27, 2017

Copy link
Copy Markdown
Contributor

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

noway commented Apr 28, 2017

Copy link
Copy Markdown
Contributor Author

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

@etpinard

Copy link
Copy Markdown
Contributor

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

@noway

noway commented Apr 30, 2017

Copy link
Copy Markdown
Contributor Author

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

@etpinard

etpinard commented May 8, 2017

Copy link
Copy Markdown
Contributor

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