Skip to content

add ohlc chart to TraceFactory #259

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

Merged
merged 28 commits into from
Jul 29, 2015
Merged

add ohlc chart to TraceFactory #259

merged 28 commits into from
Jul 29, 2015

Conversation

cldougl
Copy link
Member

@cldougl cldougl commented Jul 14, 2015

  • add ohlc chart as 2 TraceFactory methods so
    TraceFactory.create_ohlc_increasing() returns a trace of the
    increasing data and TraceFactory.create_ohlc_decreasing() returns a
    trace of the decreasing data. In these charts increasing and decreasing
    periods are typically represented by different colours (default green &
    red).
  • pull flatten method out of _Quiver so other charts can call it

cldougl added 2 commits July 14, 2015 18:58
- add ohlc chart as 2 TraceFactory methods so
`TraceFactory.create_ohlc_increasing()` returns a trace of the
increasing data and `TraceFactory.create_ohlc_decreasing()` returns a
trace of the decreasing data. In these charts increasing and decreasing
periods are typically represented by different colours (default green &
red).
- pull flatten method out of `_Quiver` so other charts can call it
Updates to ohlc
-make tests
-make default for kwargs so the default colours are red/green (typical
for this chart)
@cldougl
Copy link
Member Author

cldougl commented Jul 17, 2015

@chriddyp @theengineear @aneda @etpinard Hi guys, ohlc chart is ready for review/feedback

@theengineear
Copy link
Contributor

@cldougl your tests are failing (likely) due to the same things affecting @aneda . Once she's merged into master, you should be able to just merge master into this branch and be good to go. Else you can (a) cherry pick the changes or (b) merge her branch as-is and then merge master later before you merge into master.

so many options :)

reviewing now!


class TestOHLC(TestCase):

def test_unequal_o_h_l_c_length(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

🐄 As is well put, a foolish consistency is the hobgoblin of little minds. It'd be fine to call this:

test_unequal_ohlc_length

😸

@theengineear
Copy link
Contributor

@cldougl imo, having two separate calls for ohlc charts seems like a lot. I'm happy to keep them separate in tools, but maybe just create a single way to make an ohlc chart using TraceFactory? I think, as a user, I'd be more likely to remember TraceFactory.create_ohlc than the two alternatives.

Just a thought, happy to be dissuaded.

@theengineear
Copy link
Contributor

Also, unless it's really common to use op, hi, lo, cl in other languages. We usually like to error on the side of explicitness:

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
**Explicit is better than implicit.**
Simple is better than complex.
Complex is better than complicated.

... etc etc (try doing import this) to check them all out.

open, high, low, close

def validate(x, y, u, v,
scale=.1, density=1,
arrow_scale=.3, **kwargs):
def validate_shared(x, y, u, v,
Copy link
Contributor

Choose a reason for hiding this comment

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

🐄 Just a suggestion. Would this be clearer as two functions?

def validate_positive_scalars(**kwargs):
    """
    Validates that all values given in key/val pairs are positive.

    Accepts kwargs to improve Exception messages.

    :raises: (PlotlyError) If any value is < 0 or raises.
    """
    for key, val in kwargs.items():
        try:
            if val <= 0:
                raise PlotlyError('{} must be > 0, got {}'.format(key, val)
        except TypeError:
            raise PlotlyError('{} must be a number, got {}'.format(key, val)

def validate_arrays(**kwargs):
    """"
    Validates a set of named arrays.

    Accepts kwargs to improve Exception messages.

    :raises: (PlotlyError) On failure.
    """"
    # do your checks here...

I think that after the refactorings, this validate method has gotten much simpler than the docstring suggests?

Again, just a 🐄

@theengineear
Copy link
Contributor

@cldougl yowza! this is super clean! nice job. a couple of comments above and I'm going to hold off on dancing not literally of course until tests pass.

cldougl added 4 commits July 20, 2015 13:37
- combine create_ohlc_increase and create_ohlc_decrease into create_ohlc
- rename variables to open, high, low, close
- 2 pep 8 fixes
- check messages with assertRaisesRegexp
- remove create_ohlc_increase and create_ohlc_decrease
- update validate_ methods so that they can be used with multiple
traces when applicable
- check that direction is ‘increasing’ or ‘decreasing’
@cldougl
Copy link
Member Author

cldougl commented Jul 21, 2015

@theengineear @chriddyp tests are passing now, can I get another review of this

@@ -1670,6 +1722,130 @@ def create_streamline(x, y, u, v,
mode='lines', **kwargs)
return streamline

@staticmethod
def create_ohlc(open, high, low, close, direction, **kwargs):

Copy link
Contributor

Choose a reason for hiding this comment

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

🐄 I don't believe we typically leave a space between a function's call signature and the docstring.

@chriddyp
Copy link
Member

@cldougl i'll review tonight or tomorrow

@theengineear
Copy link
Contributor

only non-blocking comments from me! the interface for creating these looks good!

💃 from me, but you should also wait for a green light from @chriddyp

@cldougl
Copy link
Member Author

cldougl commented Jul 21, 2015

@theengineear @chriddyp sounds good! Thanks!!

- add candlestick chart and tests
- TF.create_candlestick uses fill and grouped legends to create the
candlestick outline and the shaded body
- (also oops forgot some :rtypes: in ohlc docs)
@cldougl
Copy link
Member Author

cldougl commented Jul 22, 2015

@chriddyp @theengineear @aneda @etpinard @jackparmer candlestick charts are ready for review too (they're pretty similar to the ohlc charts but with a shaded middle)

@cldougl
Copy link
Member Author

cldougl commented Jul 28, 2015

Yep, that sounds good

@cldougl
Copy link
Member Author

cldougl commented Jul 28, 2015

@theengineear re the Factories subclassing dict: the idea was to make it similar to Scatter
We can change it to subclassing from object if that makes more sense because we don't need update, fromkeys, clear, etc

@theengineear
Copy link
Contributor

Yup. Yeah, we'd only want to subclass dict if we're using it like that. It'd be clearer to just use object. If it's not too big a change, that'd be great! 🐒

@cldougl
Copy link
Member Author

cldougl commented Jul 28, 2015

done :)

@theengineear
Copy link
Contributor

\o/

cldougl and others added 17 commits July 28, 2015 14:42
- subclass from `object`
- separated `create_ohlc()` into `_make_increasing()` and
`make_decreasing()` so the user can pass kwargs to the ‘increasing’ and
‘decreasing’ traces by defining `direction` as increasing or
decreasing. This keeps it consistent with `create_candlestick`
- make `_make_increasing` and
`_make_decreasing` static methods for ohlc and candlestick
- set `hovermode` to closest for ohlc
add examples
(still need average line and subplots examples)
- remove candlestick width=4 (leave as default 2)
- change ohlc default to 1
- add bar gap to candlestick layout
so that you can pass in `dates=df.index` and nothing will fail with the
`datetimeindex isn’t a bool`
- set ohlc width to 1
- remove duplicate names in tests
@chriddyp
Copy link
Member

💃 when tests pass

cldougl added a commit that referenced this pull request Jul 29, 2015
add finance charts to FigureFactory
@cldougl cldougl merged commit 4640072 into master Jul 29, 2015
@theengineear
Copy link
Contributor

💥 nice!

@theengineear theengineear deleted the financecharts branch September 30, 2015 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants