Skip to content
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

Support string types (datetimes) in Trace x or y axis #10

Open
jrenner opened this issue May 25, 2018 · 3 comments
Open

Support string types (datetimes) in Trace x or y axis #10

jrenner opened this issue May 25, 2018 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@jrenner
Copy link

jrenner commented May 25, 2018

currently they are restricted to one type of SomeNumber. I hacked together a version that adds a second generic type to Trace, not restricted to SomeNumber, and use that for the x axis, and I was able to make a nice looking datetimes plot. Here is what it looked like:

  Trace*[T: SomeNumber, R] = ref object                                                                                 
    xs*: seq[R]                                                                                                         
    ys*: seq[T]                                                                                                         
    xs_err*: ErrorBar[R]                                                                                                
    ys_err*: ErrorBar[T]                                                                                                
    marker*: Marker[T]                                                                                                  
    text*: seq[string]                                                                                                  
    opacity*: float                                                                                                     
    mode*: PlotMode                                                                                                     
    `type`*: PlotType                                                                                                   
    fill*: PlotFill                                                                                                     
    name*: string                                                                                                       
    yaxis*: string  

It makes the code a bit uglier and I had to modify the Plot type and functions as well. it Also doesn't allow for strings in the y-axis.

@brentp
Copy link
Collaborator

brentp commented May 26, 2018

I tried to support this but there is a bug that limits having multiple generic types in some cases, e.g.: nim-lang/Nim#7794

You can get around this by not setting xs and setting text instead. E.g. this works:

import plotly

var t = Trace[int](text: @["a", "b", "c"], ys: @[5, 10, 2],  `type`: PlotType.Bar)
Plot[int](traces: @[t]).show()

This is cheating since you may want the text to be a longer phrase for the hover.

Maybe your setup works because you don't have a type constraint on R which I guess is fine. I don't like having to specify, e.g. Plot[int,string](), but I guess that might be the best way forward. Thoughts?

@Stromberg90
Copy link
Contributor

I would also like this to be supported, in my case I want a times on the y axis and dates on the x axis, which I'm guessing is not possible right now.

@brentp
Copy link
Collaborator

brentp commented Jun 28, 2018

anyone want to make a PR for this?

@brentp brentp added the help wanted Extra attention is needed label Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants